HASHKIT_SET_FUNCTION(3)

πŸ’– NAME πŸ’–

hashkit_set_function β€” libhashkit Documentation. Periodt.

Okay bestie, quick vibe check before we dive in: this is a section 3 page from the libmemcached-awesome manual, and it's your one-stop shop for telling hashkit which hash function to use and asking it which one it's using. Let's get into it πŸ’…


πŸ¦‹ SYNOPSIS πŸ¦‹

#include <libhashkit-1.0/hashkit.h>

Compile and link with -lhashkit.

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

Here's what all that means, no gatekeeping:

  • key β€” the key to generate a hash of
  • key_length β€” the length of the key without any terminating zero byte
  • 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
typedef enum hashkit_return_t hashkit_return_t
enum hashkit_return_t
  • HASHKIT_SUCCESS β€” Operation succeeded. πŸŽ‰
  • HASHKIT_FAILURE β€” Operation failed. 😭
  • HASHKIT_MEMORY_ALLOCATION_FAILURE β€” Memory allocation failed.
  • HASHKIT_INVALID_HASH β€” Invalid hashkit_hash_algorithm_t passed.
  • HASHKIT_INVALID_ARGUMENT β€” Invalid argument passed.
typedef enum hashkit_hash_algorithm_t hashkit_hash_algorithm_t
enum hashkit_hash_algorithm_t
  • HASHKIT_HASH_DEFAULT β€” Default hash algorithm (one_at_a_time).
  • HASHKIT_HASH_MD5
  • HASHKIT_HASH_CRC
  • HASHKIT_HASH_FNV1_64
  • HASHKIT_HASH_FNV1A_64
  • HASHKIT_HASH_FNV1_32
  • HASHKIT_HASH_FNV1A_32
  • HASHKIT_HASH_HSIEH β€” Only available if libhashkit hash been built with HSIEH support. (yes, "hash been", I'm just reporting the lore 🫢)
  • HASHKIT_HASH_MURMUR β€” Only available if libhashkit has been built with MURMUR support.
  • HASHKIT_HASH_MURMUR3 β€” Only available if libhashkit has been built with MURMUR support.
  • HASHKIT_HASH_JENKINS
  • HASHKIT_HASH_CUSTOM β€” Use custom hashkit_hash_fn function set through hashkit_set_custom_function() or hashkit_set_custom_distribution_function().

Now the actual functions, the main characters πŸ‘‘

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're either telling hashkit which function to use, or asking it which one it's on. Simple, iconic, we love a low-drama API 🌸


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


That's the whole page bestie, go forth and hash responsibly πŸ’–βœ¨

libmemcached-awesome, version 1.1 β€” Jul 24, 2025 β€” HASHKIT_SET_FUNCTION(3) πŸ¦‹πŸ’…

πŸ“¦ where this page comes from