---
name: "libhashkit"
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/libhashkit"
---

# libhashkit(3)

libhashkit Documentation

## NAME

libhashkit - libhashkit Documentation

## SYNOPSIS

- **#include \<libhashkit-1.0/hashkit.h\>**

  Compile and link with -lhashkit.

## DESCRIPTION

**libhashkit** is a small and thread-safe client library that provides a collection of useful hashing algorithms.

**libhashkit** is distributed with **libmemcached**.

### Creating a hashkit structure

### SYNOPSIS

- **#include \<libhashkit-1.0/hashkit.h\>**

  Compile and link with -lhashkit

- **typedef struct hashkit\_st \<#\_CPPv410hashkit\_st\> hashkit\_st**

  - **hashkit\_st \<#\_CPPv410hashkit\_st\> \*hashkit\_create(hashkit\_st \<#\_CPPv410hashkit\_st\> \*hash)**

  - **Parameters**

    **hash** -- memory address of a **hashkit\_st** struct; if a nullptr is passed, the struct will be dynamically allocated by libhashkit

  - **Returns**

    pointer to initialized **hashkit\_st** structure

- **hashkit\_st \<#\_CPPv410hashkit\_st\> \*hashkit\_clone(hashkit\_st \<#\_CPPv410hashkit\_st\> \*destination, const hashkit\_st \<#\_CPPv410hashkit\_st\> \*ptr)**

  - **Parameters**

    - •

      **destination** -- memory address of a **hashkit\_st** struct; if a nullptr is passed, the struct will be dynamically allocated by libhashkit

    - •

      **ptr** -- pointer of the **hashkit\_st** struct to copy

  - **Returns**

    pointer to a **hashkit\_st** structure (**destination**, if not nullptr), initialized from **ptr**

- **void hashkit\_free(hashkit\_st \<#\_CPPv410hashkit\_st\> \*hash)**

  - **Parameters**

    **hash** -- pointer to an initialized **hashkit\_st** struct

- **bool hashkit\_is\_allocated(const hashkit\_st \<#\_CPPv410hashkit\_st\> \*hash)**

  - **Parameters**

    **hash** -- pointer to an initialized **hashkit\_st** struct

  - **Returns**

    bool, whether the **hash** struct was dynamically allocated

### DESCRIPTION

The **hashkit\_create()** function initializes a hashkit object for use. If you pass a nullptr argument for hash, then the memory for the object is allocated. If you specify a pre-allocated piece of memory, that is initialized for use.

The **hashkit\_clone()** function initializes a hashkit object much like **hashkit\_create()**, but instead of using default settings it will use the settings of the ptr hashkit object.

The **hashkit\_free()** frees any resources being consumed by the hashkit objects that were initialized with **hashkit\_create()** or **hashkit\_clone()**.

The **hashkit\_is\_allocated()** reports whether the memory was allocated for a hashkit object.

### RETURN VALUE

**hashkit\_create()** and **hashkit\_clone()** will return nullptr on failure or pointer to **hashkit\_st** on success.

**hashkit\_is\_allocated()** returns true if the memory for the hashkit object was allocated inside of **hashkit\_create()** or **hashkit\_clone()**, otherwise it is false and was user-supplied memory.

### SEE ALSO

**[libhashkit(3)](/libhashkit/3.md) \<https://linux.die.net/man/3/libhashkit\>** **[hashkit\_value(3)](/hashkit_value/3.md) \<https://linux.die.net/man/3/hashkit\_value\>** **hashkit\_function3) \<https://linux.die.net/man//hashkit\_function3)\>**

### Set Hash Function

### 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 \<#c.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 \<#c.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 \<#\_CPPv416hashkit\_return\_t\> hashkit\_set\_function(hashkit\_st \<#\_CPPv410hashkit\_st\> \*hash, hashkit\_hash\_algorithm\_t \<#\_CPPv424hashkit\_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 \<#\_CPPv416hashkit\_return\_t\> hashkit\_set\_custom\_function(hashkit\_st \<#\_CPPv410hashkit\_st\> \*hash, hashkit\_hash\_fn \<#\_CPPv415hashkit\_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 \<#\_CPPv424hashkit\_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 \<#\_CPPv416hashkit\_return\_t\> hashkit\_set\_distribution\_function(hashkit\_st \<#\_CPPv410hashkit\_st\> \*hash, hashkit\_hash\_algorithm\_t \<#\_CPPv424hashkit\_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 \<#\_CPPv416hashkit\_return\_t\> hashkit\_set\_custom\_distribution\_function(hashkit\_st \<#\_CPPv410hashkit\_st\> \*hash, hashkit\_hash\_fn \<#\_CPPv415hashkit\_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 \<#\_CPPv424hashkit\_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\>**

### Available Hashes

### SYNOPSIS

- **#include \<libhashkit-1.0/hashkit.h\>**

  Compile and link with -lhashkit

- **uint32\_t hashkit\_default(const char \*key, size\_t key\_length)**

  - **uint32\_t hashkit\_fnv1\_64(const char \*key, size\_t key\_length)**

  - **uint32\_t hashkit\_fnv1a\_64(const char \*key, size\_t key\_length)**

  - **uint32\_t hashkit\_fnv1\_32(const char \*key, size\_t key\_length)**

  - **uint32\_t hashkit\_fnv1a\_32(const char \*key, size\_t key\_length)**

  - **uint32\_t hashkit\_crc32(const char \*key, size\_t key\_length)**

  - **uint32\_t hashkit\_hsieh(const char \*key, size\_t key\_length)**

  - **uint32\_t hashkit\_murmur(const char \*key, size\_t key\_length)**

  - **uint32\_t hashkit\_murmur3(const char \*key, size\_t key\_length)**

  - **uint32\_t hashkit\_jenkins(const char \*key, size\_t key\_length)**

  - **uint32\_t hashkit\_md5(const char \*key, size\_t key\_length)**

  ### DESCRIPTION

These functions generate hash values from a key using a variety of algorithms. These functions can be used standalone, or will be used according to the algorithm set with **hashkit\_set\_function()** \<#\_CPPv420hashkit\_set\_functionP10hashkit\_st24hashkit\_hash\_algorithm\_t\> or **hashkit\_set\_distribution\_function()** \<#\_CPPv433hashkit\_set\_distribution\_functionP10hashkit\_st24hashkit\_hash\_algorithm\_t\>.

The **hashkit\_hsieh()**, **hashkit\_murmur()** and **hashkit\_murmur3()** functions are only available if the library is built with the appropriate flag enabled.

### RETURN VALUE

A 32-bit hash value.

### 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\_function(3)](/hashkit_function/3.md) \<https://linux.die.net/man/3/hashkit\_function\>**

### Generate hash value

### SYNOPSIS

- **#include \<libhashkit-1.0/hashkit.h\>**

  Compile and link with -lhashkit

- **uint32\_t hashkit\_value(hashkit\_st \<#\_CPPv410hashkit\_st\> \*hash, const char \*key, size\_t key\_length)**

  - **Parameters**

    - •

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

    - •

      **key** -- the key to genereate a hash of

    - •

      **key\_length** -- the length of the **key** without any terminating zero byte

### DESCRIPTION

The **hashkit\_value()** function generates a 32-bit hash value from the given key and key\_length. The hash argument is an initialized hashkit object, and distribution type and hash function is used from this object while generating the value.

### RETURN VALUE

A 32-bit hash value.

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

## SEE ALSO

**[libmemcached(3)](/libmemcached/3.md) \<https://linux.die.net/man/3/libmemcached\>** **[hashkit\_create(3)](/hashkit_create/3.md) \<https://linux.die.net/man/3/hashkit\_create\>** **[hashkit\_function(3)](/hashkit_function/3.md) \<https://linux.die.net/man/3/hashkit\_function\>** **[hashkit\_functions(3)](/hashkit_functions/3.md) \<https://linux.die.net/man/3/hashkit\_functions\>** **[hashkit\_value(3)](/hashkit_value/3.md) \<https://linux.die.net/man/3/hashkit\_value\>**
