---
name: "hashkit_set_custom_function"
section: "3"
platform: "linux"
package: "libmemcached-awesome"
version: "1.1.4-4"
release: "Arch Linux 2026-11-01"
platforms: ["linux"]
url: "https://new.carta.tech/hashkit_set_custom_function"
---

# hashkit\_set\_custom\_function(3)

libhashkit Documentation

## NAME

hashkit\_set\_custom\_function - libhashkit Documentation

## 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)**

  - **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

- **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.

- **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).

  - **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.

  - **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()**.

- **hashkit\_return\_t hashkit\_set\_function(hashkit\_st \<#\_CPPv410hashkit\_st\> \*hash, hashkit\_hash\_algorithm\_t hash\_algorithm)**

  - **Parameters**

    - •

      **hash** -- pointer to an initialized **hashkit\_st** \<#\_CPPv410hashkit\_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 \<#\_CPPv410hashkit\_st\> \*hash, hashkit\_hash\_fn function, void \*context)**

  - **Parameters**

    - •

      **hash** -- pointer to initialized **hashkit\_st** \<#\_CPPv410hashkit\_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 \<#\_CPPv410hashkit\_st\> \*hash)**

  - **Parameters**

    **hash** -- pointer to an initialized **hashkit\_st** \<#\_CPPv410hashkit\_st\> struct

  - **Returns**

    **hashkit\_hash\_algorithm\_t** indicating the currently set hash algorithm to use

- **hashkit\_return\_t hashkit\_set\_distribution\_function(hashkit\_st \<#\_CPPv410hashkit\_st\> \*hash, hashkit\_hash\_algorithm\_t hash\_algorithm)**

  - **Parameters**

    - •

      **hash** -- pointer to an initialized **hashkit\_st** \<#\_CPPv410hashkit\_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 \<#\_CPPv410hashkit\_st\> \*hash, hashkit\_hash\_fn function, void \*context)**

  - **Parameters**

    - •

      **hash** -- pointer to initialized **hashkit\_st** \<#\_CPPv410hashkit\_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 \<#\_CPPv410hashkit\_st\> \*hash)**

  - **Parameters**

    **hash** -- pointer to an initialized **hashkit\_st** \<#\_CPPv410hashkit\_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.

## 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)](/libhashkit/3.md) \<https://linux.die.net/man/3/libhashkit\>** **[hashkit\_create(3)](/hashkit_create/3.md) \<https://linux.die.net/man/3/hashkit\_create\>** **[hashkit\_functions(3)](/hashkit_functions/3.md) \<https://linux.die.net/man/3/hashkit\_functions\>**
