HASHKIT_FUNCTION(3)

πŸ’– HASHKIT_FUNCTION πŸ’–

okay so this is HASHKIT_FUNCTION(3), straight outta libmemcached-awesome, and bestie it's giving "libhashkit's greatest hits". we're talking hash functions, distribution functions, custom callbacks, the whole vibe. grab a boba, we're doing this πŸ§‹βœ¨


✨ NAME ✨

hashkit_function β€” libhashkit Documentation. that's it, that's the name, short and iconic πŸ‘‘


🌸 SYNOPSIS 🌸

#include <libhashkit-1.0/hashkit.h>

Compile and link with -lhashkit.


πŸ¦‹ the custom hash function typedef

typedef uint32_t (*hashkit_hash_fn)(const char *key, size_t key_length,
void *context)

Param key β€” the key you wanna generate a hash of. the raw material, the moment, the it-girl 🌟

Param key_length β€” the length of the key, and no, it does not count any terminating zero byte. don't include the null, she's not invited πŸ’…

Param context β€” the custom hash function context that got set through hashkit_set_custom_function() or hashkit_set_custom_distribution_function(). it's your lil suitcase of extra info πŸŽ€

Returns β€” your custom hash function should hand back a hash value for key as an unsigned 32bit integer. no cap, that's the contract πŸ”₯


πŸ’œ the return type

typedef enum hashkit_return_t hashkit_return_t
enum hashkit_return_t
  • enumerator HASHKIT_SUCCESS β€” operation succeeded. slay πŸŽ‰
  • enumerator HASHKIT_FAILURE β€” operation failed. it's giving flop 😭
  • enumerator HASHKIT_MEMORY_ALLOCATION_FAILURE β€” memory allocation failed. the malloc said no πŸ’€
  • enumerator HASHKIT_INVALID_HASH β€” an invalid hashkit_hash_algorithm_t got passed. wrong algorithm bestie πŸ™ˆ
  • enumerator HASHKIT_INVALID_ARGUMENT β€” an invalid argument got passed. ma'am that's not a valid argument 🫠

🌈 the hash algorithm type

typedef enum hashkit_hash_algorithm_t hashkit_hash_algorithm_t
enum hashkit_hash_algorithm_t
  • enumerator HASHKIT_HASH_DEFAULT β€” the default hash algorithm, which is one_at_a_time. the og, the blueprint, the moment ⭐
  • 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 has been built with HSIEH support. so if she's not compiled in, she's simply not there, no hard feelings ✨
  • enumerator HASHKIT_HASH_MURMUR β€” only available if libhashkit has been built with MURMUR support. same deal πŸŒ€
  • enumerator HASHKIT_HASH_MURMUR3 β€” only available if libhashkit has been built with MURMUR support. yes, again, build flags decide everything πŸ’«
  • enumerator HASHKIT_HASH_JENKINS
  • enumerator HASHKIT_HASH_CUSTOM β€” use the custom hashkit_hash_fn function that got set through hashkit_set_custom_function() or hashkit_set_custom_distribution_function(). this one's your girl, you wrote her πŸ’–

πŸŽ€ the 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 🫢

so like, these functions are the ones you use to set and retrieve the key and distribution hash functions. that's the whole job. set them, get them, live your truth πŸ¦‹βœ¨


πŸ‘‘ RETURN VALUE πŸ‘‘

hashkit_set_function(), hashkit_set_custom_function() and the distribution equivalents all return hashkit_return_t::HASHKIT_SUCCESS on success. green flags only bestie πŸ’š

hashkit_get_function() and hashkit_get_distribution_function() return hashkit_hash_algorithm_t, indicating the hash function that's in use. they're just telling you who's currently holding the aux 🎧


πŸ”₯ SEE ALSO πŸ”₯


and that's the whole page, bestie, you ate πŸ’…βœ¨ this was HASHKIT_FUNCTION(3) from libmemcached-awesome, version 1.1, dated Jul 24, 2025 β€” go forth and hash responsibly, ily, mwah πŸŽ€πŸ’–πŸ¦‹

πŸ“¦ where this page comes from