HASHKIT_SET...ON_FUNCTION(3)
ok bestie, sit DOWN π we're doingHASHKIT_SET...ON_FUNCTION(3)fromlibmemcached-awesomeand it's literally all about picking which hash function your hashkit is gonna use. no cap. let's get into it π«Ά
β¨ NAME β¨
hashkit_set_custom_distribution_function β libhashkit Documentation πΈ
β¨ SYNOPSIS β¨
First things first, plug it in:
#include <libhashkit-1.0/hashkit.h>
Compile and link with -lhashkit
Okay so here's the function pointer type you'll be passing around like it's a hall pass:
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 throughhashkit_set_custom_function()orhashkit_set_custom_distribution_function() - Returns β the custom hash function should return a hash value for
keyas an unsigned 32bit integer
Then the return type, iconic, no notes:
typedef enum hashkit_return_t hashkit_return_t
enum hashkit_return_t
enumeratorHASHKIT_SUCCESSβ Operation succeeded. πenumeratorHASHKIT_FAILUREβ Operation failed. πenumeratorHASHKIT_MEMORY_ALLOCATION_FAILUREβ Memory allocation failed.enumeratorHASHKIT_INVALID_HASHβ Invalidhashkit_hash_algorithm_tpassed.enumeratorHASHKIT_INVALID_ARGUMENTβ Invalid argument passed.
And now the algorithm menu, the whole vibe:
typedef enum hashkit_hash_algorithm_t hashkit_hash_algorithm_t
enum hashkit_hash_algorithm_t
enumeratorHASHKIT_HASH_DEFAULTβ Default hash algorithm (one_at_a_time). the main character tbhenumeratorHASHKIT_HASH_MD5enumeratorHASHKIT_HASH_CRCenumeratorHASHKIT_HASH_FNV1_64enumeratorHASHKIT_HASH_FNV1A_64enumeratorHASHKIT_HASH_FNV1_32enumeratorHASHKIT_HASH_FNV1A_32enumeratorHASHKIT_HASH_HSIEHβ Only available if libhashkit hash been built with HSIEH support.enumeratorHASHKIT_HASH_MURMURβ Only available if libhashkit has been built with MURMUR support.enumeratorHASHKIT_HASH_MURMUR3β Only available if libhashkit has been built with MURMUR support.enumeratorHASHKIT_HASH_JENKINSenumeratorHASHKIT_HASH_CUSTOMβ Use customhashkit_hash_fnfunction set throughhashkit_set_custom_function()orhashkit_set_custom_distribution_function().
okay now the actual functions, one by one, bestie, don't scroll π§
hashkit_return_t hashkit_set_function(hashkit_st *hash,
hashkit_hash_algorithm_t hash_algorithm)
Parameters
hash-- pointer to an initializedhashkit_ststructhash_algorithm-- validhashkit_hash_algorithm_tconstant
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 initializedhashkit_ststructfunction--hashkit_hash_fnfunction pointer to use as hash function forHASHKIT_HASH_CUSTOMcontext-- 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 initializedhashkit_ststruct
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 initializedhashkit_ststructhash_algorithm-- validhashkit_hash_algrothm_tconstant
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 initializedhashkit_ststructfunction--hashkit_hash_fnfunction pointer to use as distribution hash function forHASHKIT_HASH_CUSTOMcontext-- 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 initializedhashkit_ststruct
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 thing π you set 'em, you get 'em.
β¨ 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 β¨
libhashkit(3) hashkit_create(3) hashkit_functions(3) β go read these next bestie, fr fr π
and that's the whole page!! this was version 1.1, dated Jul 24, 2025, straight from the libmemcached-awesome girlies π slay, go hash something responsibly π
π¦ where this page comes from
- fedora 43: libmemcached-awesome-devel 1.1.4-7.fc43 Β· BSD-3-Clause
- fedora 43: libmemcached-awesome-devel 1.1.4-7.fc43 Β· BSD-3-Clause
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms