HASHKIT_SET_CUSTOM_FUNCTION(3)

πŸ’– NAME πŸ’–

hashkit_set_custom_function β€” libhashkit Documentation ✨

okay bestie, pull up a chair 🫢 this is the libhashkit page for setting your own hash function, and honestly? it's giving main character energy. no cap. πŸ’…


πŸ¦‹ SYNOPSIS πŸ¦‹

#include <libhashkit-1.0/hashkit.h>

Compile and link with -lhashkit

🌸 the custom hash function type 🌸

typedef uint32_t (*hashkit_hash_fn)(const char *key, size_t key_length,
void *context)
  • Param key β€” the key to generate a hash of πŸ”‘
  • Param key_length β€” the length of the key without any terminating zero byte πŸ“
  • Param context β€” the custom hash function context set through hashkit_set_custom_function() or hashkit_set_custom_distribution_function() πŸŽ€
  • Returns β€” the custom hash function should return a hash value for key as an unsigned 32bit integer πŸ”’

πŸ’œ the return type πŸ’œ

typedef enum hashkit_return_t hashkit_return_t

enum hashkit_return_t

  • enumerator HASHKIT_SUCCESS β€” Operation succeeded. πŸŽ‰
  • enumerator HASHKIT_FAILURE β€” Operation failed. πŸ’€
  • enumerator HASHKIT_MEMORY_ALLOCATION_FAILURE β€” Memory allocation failed. 😭
  • enumerator HASHKIT_INVALID_HASH β€” Invalid hashkit_hash_algorithm_t passed. πŸ™ˆ
  • enumerator HASHKIT_INVALID_ARGUMENT β€” Invalid argument passed. 🚫

🧚 the algorithm enum 🧚

typedef enum hashkit_hash_algorithm_t hashkit_hash_algorithm_t

enum hashkit_hash_algorithm_t

  • enumerator HASHKIT_HASH_DEFAULT β€” Default hash algorithm (one_at_a_time). the classic, the blueprint ✨
  • enumerator HASHKIT_HASH_MD5
  • enumerator HASHKIT_HASH_CRC
  • enumerator HASHKIT_HASH_FNV1_64
  • enumerator HASHKIT_HASH_FNV1A_64
  • enumerator HASHKIT_HASH_FNV1_32
  • enumerator HASHKIT_HASH_FNV1A_32
  • enumerator HASHKIT_HASH_HSIEH β€” Only available if libhashkit hash been built with HSIEH support. (that typo is theirs, not mine, i'm just the messenger πŸ’…)
  • enumerator HASHKIT_HASH_MURMUR β€” Only available if libhashkit has been built with MURMUR support.
  • enumerator HASHKIT_HASH_MURMUR3 β€” Only available if libhashkit has been built with MURMUR support.
  • enumerator HASHKIT_HASH_JENKINS
  • enumerator HASHKIT_HASH_CUSTOM β€” Use custom hashkit_hash_fn function set through hashkit_set_custom_function() or hashkit_set_custom_distribution_function(). this is the one, the moment, the icon πŸ‘‘

πŸ”₯ the actual functions πŸ”₯

hashkit_return_t hashkit_set_function(hashkit_st *hash,
hashkit_hash_algorithm_t hash_algorithm)

Parameters

  • hash β€” pointer to an initialized hashkit_st struct
  • hash_algorithm β€” valid hashkit_hash_algorithm_t constant

Returns β€” hashkit_return_t indicating success or failure

hashkit_return_t hashkit_set_custom_function(hashkit_st *hash,
hashkit_hash_fn function, void *context)

Parameters

  • hash β€” pointer to initialized hashkit_st struct
  • function β€” hashkit_hash_fn function pointer to use as hash function for HASHKIT_HASH_CUSTOM
  • context β€” pointer to an opaque user managed context for the custom hash function

Returns β€” hashkit_return_t indicating success or failure

hashkit_hash_algorithm_t hashkit_get_function(const hashkit_st *hash)

Parameters

  • hash β€” pointer to an initialized hashkit_st struct

Returns β€” hashkit_hash_algorithm_t indicating the currently set hash algorithm to use

hashkit_return_t hashkit_set_distribution_function(hashkit_st *hash,
hashkit_hash_algorithm_t hash_algorithm)

Parameters

  • hash β€” pointer to an initialized hashkit_st struct
  • hash_algorithm β€” valid hashkit_hash_algrothm_t constant

Returns β€” hashkit_return_t indicating success or failure

hashkit_return_t hashkit_set_custom_distribution_function(hashkit_st
*hash, hashkit_hash_fn function, void *context)

Parameters

  • hash β€” pointer to initialized hashkit_st struct
  • function β€” hashkit_hash_fn function pointer to use as distribution hash function for HASHKIT_HASH_CUSTOM
  • context β€” pointer to an opaque user managed context for the custom distribution hash function
hashkit_hash_algorithm_t hashkit_get_distribution_function(const
hashkit_st *hash)

Parameters

  • hash β€” pointer to an initialized hashkit_st struct

Returns β€” hashkit_hash_algorithm_t indicating the currently set distribution hash algorithm to use


✨ DESCRIPTION ✨

These functions are used to set and retrieve the key and distribution hash functions. that's it, that's the whole vibe β€” you put a function in, you get a function out, slay 🫢


🌈 RETURN VALUE 🌈

hashkit_set_function(), hashkit_set_custom_function() and the distribution equivalents return hashkit_return_t::HASHKIT_SUCCESS on success. πŸŽ€

hashkit_get_function() and hashkit_get_distribution_function() return hashkit_hash_algorithm_t indicating the hash function used. πŸ”


πŸ‘‘ SEE ALSO πŸ‘‘


okay bestie that's the whole page, no cap, go forth and hash πŸ’–

this one's from libmemcached-awesome, version 1.1, dated Jul 24, 2025 β€” periodt. πŸ’…πŸŒΈ
πŸ“¦ where this page comes from