6 Module HASH_TABLE
gullradriel edited this page 2026-10-29 20:54:40 +01:00

HASH TABLES: classic or trie tree hash_tables

Structures

Name
struct HASH_TABLE
structure of a hash table
struct HASH_NODE
structure of a hash table node
union HASH_DATA
union of the possibles data values of a node

Types

Name
typedef size_t HASH_VALUE
type of a HASH_VALUE

Functions

Name
size_t next_prime(size_t nb)
return the next prime number greater than or equal to nb
HASH_TABLE * new_ht_trie(size_t alphabet_size, size_t alphabet_offset)
create a new trie hash table with the given alphabet size and offset
HASH_TABLE * new_ht(size_t size)
create a new classic hash table of the given size
int is_prime(size_t nb)
check if a number is prime
LIST * ht_search(HASH_TABLE * table, int(*)(HASH_NODE *node) node_is_matching)
search the hash table for nodes matching a predicate
int ht_resize(HASH_TABLE ** table, size_t size)
resize a hash table to the given size
int ht_remove_ex(HASH_TABLE * table, HASH_VALUE hash_value)
remove a node by numeric hash value
int ht_remove(HASH_TABLE * table, const char * key)
remove a node from the hash table by key
int ht_put_string_ptr(HASH_TABLE * table, const char * key, char * string)
put a string pointer into the hash table without copying
int ht_put_string(HASH_TABLE * table, const char * key, char * string)
put a string value (duplicated) into the hash table
int ht_put_ptr_ex(HASH_TABLE * table, HASH_VALUE hash_value, void * val, void(*)(void *ptr) destructor, void ()(void *ptr) duplicator)
put a pointer value by numeric hash value
int ht_put_ptr(HASH_TABLE * table, const char * key, void * ptr, void(*)(void *ptr) destructor, void ()(void *ptr) duplicator)
put a pointer value into the hash table with destructor and duplicator
int ht_put_int(HASH_TABLE * table, const char * key, int64_t value)
put an integer value into the hash table
int ht_put_double(HASH_TABLE * table, const char * key, double value)
put a double value into the hash table
void ht_print(HASH_TABLE * table)
print the contents of a hash table
int ht_optimize(HASH_TABLE ** table)
optimize a hash table by resizing to the optimal size
char * ht_node_type(const HASH_NODE * node)
return the type of a hash node as a string
int ht_get_table_collision_percentage(HASH_TABLE * table)
get the collision percentage of the hash table
int ht_get_string(HASH_TABLE * table, const char * key, char ** val)
get a string value from the hash table by key
int ht_get_ptr_ex(HASH_TABLE * table, HASH_VALUE hash_value, void ** val)
get a pointer value by numeric hash value
int ht_get_ptr(HASH_TABLE * table, const char * key, void ** val)
get a pointer value from the hash table by key
size_t ht_get_optimal_size(HASH_TABLE * table)
compute the optimal size for the hash table
HASH_NODE * ht_get_node_ex(HASH_TABLE * table, HASH_VALUE hash_value)
get a HASH_NODE by numeric hash value
HASH_NODE * ht_get_node(HASH_TABLE * table, const char * key)
get the HASH_NODE associated with the given key
int ht_get_int(HASH_TABLE * table, const char * key, int64_t * val)
get an integer value from the hash table by key
int ht_get_double(HASH_TABLE * table, const char * key, double * val)
get a double value from the hash table by key
LIST * ht_get_completion_list(HASH_TABLE * table, const char * keybud, size_t max_results)
get a list of key completions matching the given prefix
HASH_TABLE * ht_duplicate(HASH_TABLE * table)
duplicate a hash table
int empty_ht(HASH_TABLE * table)
empty a hash table, freeing all nodes
int destroy_ht(HASH_TABLE ** table)
destroy a hash table and free all resources
void MurmurHash3_x86_32(const void * key, const size_t len, const uint32_t seed, void * out)
compute a 32-bit MurmurHash3 hash
void MurmurHash3_x86_128(const void * key, const size_t len, const uint32_t seed, void * out)
compute a 128-bit MurmurHash3 hash for x86
void MurmurHash3_x64_128(const void * key, const size_t len, const uint64_t seed, void * out)
compute a 128-bit MurmurHash3 hash for x64

Defines

Name
ht_foreach_r(_ITEM, _HASH, _ITERATOR)
ForEach macro helper, reentrant (classic / old).
ht_foreach(_ITEM, _HASH)
ForEach macro helper (classic / old).
hash_val(node, type)
Cast a HASH_NODE element.
MurmurHash(__key, __len, __seed, __out)
Murmur hash macro helper 64 bits.
HT_FOREACH_R(_ITEM, _HASH, __ITERATOR, ...)
ForEach macro helper.
HT_FOREACH(_ITEM, _HASH, ...)
ForEach macro helper.
HASH_VAL(node, type)
Cast a HASH_NODE element.
HASH_UNKNOWN
value of unknow type inside the hash node
HASH_TRIE
TRIE tree using hash key string.
HASH_STRING
value of char * type inside the hash node
HASH_PTR
value of pointer type inside the hash node
HASH_INT_TYPE
type of a HASH_INT in 64 bits
HASH_INT
compatibility with existing rot func
HASH_DOUBLE
value of double type inside the hash node
HASH_CLASSIC
Murmur hash using hash key string, hash key numeric value, index table with lists of elements.

Types Documentation

typedef HASH_VALUE

typedef size_t HASH_VALUE;

type of a HASH_VALUE

Functions Documentation

function next_prime

size_t next_prime(
    size_t nb
)

return the next prime number greater than or equal to nb

Parameters:

  • nb number to test

Return: next prime number after nb or FALSE

compute next prime number after nb

return the next prime number greater than or equal to nb

function new_ht_trie

HASH_TABLE * new_ht_trie(
    size_t alphabet_size,
    size_t alphabet_offset
)

create a new trie hash table with the given alphabet size and offset

Parameters:

  • alphabet_length of the alphabet
  • alphabet_offset offset of each character in a key (i.e: to have 'a->z' with 'a' starting at zero, offset must be 32.

Return: NULL or the new allocated hash table

create a TRIE hash table with the alphabet_size, each key value beeing decreased by alphabet_offset

create a new trie hash table with the given alphabet size and offset

function new_ht

HASH_TABLE * new_ht(
    size_t size
)

create a new classic hash table of the given size

Parameters:

  • size Size of the root hash node table

Return: NULL or the new allocated hash table

Create a hash table with the given size.

create a new classic hash table of the given size

function is_prime

int is_prime(
    size_t nb
)

check if a number is prime

Parameters:

  • nb number to test

Return: TRUE or FALSE

test if number is a prime number or not

check if a number is prime

LIST * ht_search(
    HASH_TABLE * table,
    int(*)(HASH_NODE *node) node_is_matching
)

search the hash table for nodes matching a predicate

Parameters:

  • table targeted hash table
  • node_is_matching matching function

Return: NULL or a LIST *list of HASH_NODE *nodes

seach table for matching nodes

search the hash table for nodes matching a predicate

function ht_resize

int ht_resize(
    HASH_TABLE ** table,
    size_t size
)

resize a hash table to the given size

Parameters:

  • table targeted table
  • size new hash table size

Return: TRUE or FALSE

rehash table according to size (HASH_CLASSIC mode only)

resize a hash table to the given size

function ht_remove_ex

int ht_remove_ex(
    HASH_TABLE * table,
    HASH_VALUE hash_value
)

remove a node by numeric hash value

Parameters:

  • table Targeted hash table
  • hash_value key pre computed numeric hash value

Return: TRUE or FALSE.

Remove a key from a hash table (HASH_CLASSIC only).

remove a node by numeric hash value

function ht_remove

int ht_remove(
    HASH_TABLE * table,
    const char * key
)

remove a node from the hash table by key

Parameters:

  • table targeted hash table
  • key key of node to destroy

Return: TRUE or FALSE

remove and delete node at key in table

remove a node from the hash table by key

function ht_put_string_ptr

int ht_put_string_ptr(
    HASH_TABLE * table,
    const char * key,
    char * string
)

put a string pointer into the hash table without copying

Parameters:

  • table targeted hash table
  • key associated value's key
  • string string value to put (pointer)

Return: TRUE or FALSE

put a string value (pointer) with given key in the targeted hash table

put a string pointer into the hash table without copying

function ht_put_string

int ht_put_string(
    HASH_TABLE * table,
    const char * key,
    char * string
)

put a string value (duplicated) into the hash table

Parameters:

  • table targeted hash table
  • key associated value's key
  • string string value to put (copy)

Return: TRUE or FALSE

put a string value (copy/dup) with given key in the targeted hash table

put a string value (duplicated) into the hash table

function ht_put_ptr_ex

int ht_put_ptr_ex(
    HASH_TABLE * table,
    HASH_VALUE hash_value,
    void * val,
    void(*)(void *ptr) destructor,
    void *(*)(void *ptr) duplicator
)

put a pointer value by numeric hash value

Parameters:

  • table targeted hash table
  • hash_value precomputed hash value for the key
  • val pointer value to put
  • destructor Pointer to the ptr type destructor function. Leave to NULL if there isn't
  • duplicator Pointer to the ptr type duplicator function. Leave to NULL if there isn't

Return: TRUE or FALSE

put a pointer value with given key in the targeted hash table (HASH_CLASSIC only)

put a pointer value by numeric hash value

function ht_put_ptr

int ht_put_ptr(
    HASH_TABLE * table,
    const char * key,
    void * ptr,
    void(*)(void *ptr) destructor,
    void *(*)(void *ptr) duplicator
)

put a pointer value into the hash table with destructor and duplicator

Parameters:

  • table targeted hash table
  • key key of the entry
  • ptr pointer value to put
  • destructor Pointer to the ptr type destructor function. Leave to NULL if there isn't
  • duplicator Pointer to the ptr type duplicator function. Leave to NULL if there isn't

Return: TRUE or FALSE

put an arbitrary pointer value with given key in the targeted hash table

put a pointer value into the hash table with destructor and duplicator

function ht_put_int

int ht_put_int(
    HASH_TABLE * table,
    const char * key,
    int64_t value
)

put an integer value into the hash table

Parameters:

  • table targeted hash table
  • key associated value's key
  • value integral value to put

Return: TRUE or FALSE

put an integral value with given key in the targeted hash table

put an integer value into the hash table

function ht_put_double

int ht_put_double(
    HASH_TABLE * table,
    const char * key,
    double value
)

put a double value into the hash table

Parameters:

  • table targeted table
  • key key to retrieve
  • value double value to put

Return: TRUE or FALSE

put a double value with given key in the targeted hash table

put a double value into the hash table

function ht_print

void ht_print(
    HASH_TABLE * table
)

print the contents of a hash table

Parameters:

  • table targeted hash table

print contents of table

print the contents of a hash table

function ht_optimize

int ht_optimize(
    HASH_TABLE ** table
)

optimize a hash table by resizing to the optimal size

Parameters:

  • table targeted table

Return: TRUE or FALSE and set table to NULL

try an automatic optimization of the table (HASH_CLASSIC mode only)

optimize a hash table by resizing to the optimal size

function ht_node_type

char * ht_node_type(
    const HASH_NODE * node
)

return the type of a hash node as a string

Parameters:

  • node node to check

Return: "HASH_INT", "HASH_DOUBLE", "HASH_STRING", "HASH_PTR", "HASH_UNKNOWN", "NULL_NODE"

get the type of a node , text version

return the type of a hash node as a string

function ht_get_table_collision_percentage

int ht_get_table_collision_percentage(
    HASH_TABLE * table
)

get the collision percentage of the hash table

Parameters:

  • table targeted table

Return: table collision percentage or FALSE

get table collision percentage (HASH_CLASSIC mode only)

get the collision percentage of the hash table

function ht_get_string

int ht_get_string(
    HASH_TABLE * table,
    const char * key,
    char ** val
)

get a string value from the hash table by key

Parameters:

  • table targeted table
  • key key to retrieve
  • val pointer to string storage

Return: TRUE if found, else FALSE. 'val' value is preserved if no key is matching.

get string at 'key' from 'table'

get a string value from the hash table by key

function ht_get_ptr_ex

int ht_get_ptr_ex(
    HASH_TABLE * table,
    HASH_VALUE hash_value,
    void ** val
)

get a pointer value by numeric hash value

Parameters:

  • table Targeted hash table
  • hash_value key pre computed numeric hash value
  • val A pointer to an empty pointer store

Return: TRUE or FALSE.

Retrieve a pointer value in the hash table, at the given key.

get a pointer value by numeric hash value

Leave val untouched if key is not found. (HASH_CLASSIC only)

function ht_get_ptr

int ht_get_ptr(
    HASH_TABLE * table,
    const char * key,
    void ** val
)

get a pointer value from the hash table by key

Parameters:

  • table targeted table
  • key key to retrieve
  • val pointer to pointer storage

Return: TRUE if found, else FALSE. 'val' value is preserved if no key is matching.

get pointer at 'key' from 'table'

get a pointer value from the hash table by key

function ht_get_optimal_size

size_t ht_get_optimal_size(
    HASH_TABLE * table
)

compute the optimal size for the hash table

Parameters:

  • table targeted table

Return: 0 or optimal table size

get optimal array size based on nb=(number_of_key*1.3) && if( !isprime(nb) )nb=nextprime(nb) (HASH_CLASSIC mode only)

compute the optimal size for the hash table

function ht_get_node_ex

HASH_NODE * ht_get_node_ex(
    HASH_TABLE * table,
    HASH_VALUE hash_value
)

get a HASH_NODE by numeric hash value

Parameters:

  • table Targeted hash table
  • hash_value Associated hash_value

Return: The found node, or NULL

return the associated key's node inside the hash_table (HASH_CLASSIC only)

get a HASH_NODE by numeric hash value

function ht_get_node

HASH_NODE * ht_get_node(
    HASH_TABLE * table,
    const char * key
)

get the HASH_NODE associated with the given key

Parameters:

  • table targeted table
  • key key to retrieve

Return: NULL or the matching HASH_NODE *node

get node at 'key' from 'table'

get the HASH_NODE associated with the given key

function ht_get_int

int ht_get_int(
    HASH_TABLE * table,
    const char * key,
    int64_t * val
)

get an integer value from the hash table by key

Parameters:

  • table targeted table
  • key key to retrieve
  • val pointer to int storage

Return: TRUE if found, else FALSE. 'val' value is preserved if no key is matching.

get node at 'key' from 'table'

get an integer value from the hash table by key

function ht_get_double

int ht_get_double(
    HASH_TABLE * table,
    const char * key,
    double * val
)

get a double value from the hash table by key

Parameters:

  • table targeted table
  • key key to retrieve
  • val pointer to double storage

Return: TRUE if found, else FALSE. 'val' value is preserved if no key is matching.

get double at 'key' from 'table'

get a double value from the hash table by key

function ht_get_completion_list

LIST * ht_get_completion_list(
    HASH_TABLE * table,
    const char * keybud,
    size_t max_results
)

get a list of key completions matching the given prefix

Parameters:

  • table targeted hash table
  • keybud starting characters of the keys we want
  • max_results maximum number of matching keys in list. From UNLIMITED_LIST_ITEMS (0) to MAX_LIST_ITEMS (SIZE_MAX).

Return: NULL or a LIST *list of matching HASH_NODE *nodes

get next matching keys in table tree

get a list of key completions matching the given prefix

function ht_duplicate

HASH_TABLE * ht_duplicate(
    HASH_TABLE * table
)

duplicate a hash table

Parameters:

Return: NULL or and allocated duplicated HASH_TABLE

duplicate a hash table (all pointers should have a duplicator func set)

duplicate a hash table

function empty_ht

int empty_ht(
    HASH_TABLE * table
)

empty a hash table, freeing all nodes

Parameters:

  • table targeted hash table

Return: TRUE or FALSE

empty a table

empty a hash table, freeing all nodes

function destroy_ht

int destroy_ht(
    HASH_TABLE ** table
)

destroy a hash table and free all resources

Parameters:

  • table targeted hash table

Return: TRUE or FALSE

empty a table and destroy it

destroy a hash table and free all resources

function MurmurHash3_x86_32

void MurmurHash3_x86_32(
    const void * key,
    const size_t len,
    const uint32_t seed,
    void * out
)

compute a 32-bit MurmurHash3 hash

Parameters:

  • key char *string as the key
  • len size of the key
  • seed seed value for murmur hash
  • out generated hash

MurmurHash3 was written by Austin Appleby, and is placed in the public domain.

compute a 32-bit MurmurHash3 hash

The author hereby disclaims copyright to this source code. Note - The x86 and x64 versions do not produce the same results, as the algorithms are optimized for their respective platforms. You can still compile and run any of them on any platform, but your performance with the non-native version will be less than optimal.

function MurmurHash3_x86_128

void MurmurHash3_x86_128(
    const void * key,
    const size_t len,
    const uint32_t seed,
    void * out
)

compute a 128-bit MurmurHash3 hash for x86

Parameters:

  • key char *string as the key
  • len size of the key
  • seed seed value for murmur hash
  • out generated hash

MurmurHash3 was written by Austin Appleby, and is placed in the public domain.

compute a 128-bit MurmurHash3 hash for x86

The author hereby disclaims copyright to this source code. Note - The x86 and x64 versions do not produce the same results, as the algorithms are optimized for their respective platforms. You can still compile and run any of them on any platform, but your performance with the non-native version will be less than optimal.

function MurmurHash3_x64_128

void MurmurHash3_x64_128(
    const void * key,
    const size_t len,
    const uint64_t seed,
    void * out
)

compute a 128-bit MurmurHash3 hash for x64

Parameters:

  • key char *string as the key
  • len size of the key
  • seed seed value for murmur hash
  • out generated hash

MurmurHash3 was written by Austin Appleby, and is placed in the public domain.

compute a 128-bit MurmurHash3 hash for x64

The author hereby disclaims copyright to this source code. Note - The x86 and x64 versions do not produce the same results, as the algorithms are optimized for their respective platforms. You can still compile and run any of them on any platform, but your performance with the non-native version will be less than optimal.

Macros Documentation

define ht_foreach_r

#define ht_foreach_r(
    __ITEM_,
    __HASH_,
    __ITERATOR_
)
if (!__HASH_) {                                                                      \
    n_log(LOG_ERR, "Error in ht_foreach, %s is NULL", #__HASH_);                     \
} else if (__HASH_->mode != HASH_CLASSIC) {                                          \
    n_log(LOG_ERR, "Error in ht_foreach, %d is an unsupported mode", __HASH_->mode); \
} else                                                                               \
    for (size_t __ITERATOR_ = 0; __ITERATOR_ < __HASH_->size; __ITERATOR_++)         \
        for (LIST_NODE* __ITEM_ = __HASH_->hash_table[__ITERATOR_]->start; __ITEM_ != NULL; __ITEM_ = __ITEM_->next)

ForEach macro helper, reentrant (classic / old).

define ht_foreach

#define ht_foreach(
    __ITEM_,
    __HASH_
)
if (!__HASH_) {                                                                                               \
    n_log(LOG_ERR, "Error in ht_foreach, %s is NULL", #__HASH_);                                              \
} else if (__HASH_->mode != HASH_CLASSIC) {                                                                   \
    n_log(LOG_ERR, "Error in ht_foreach( %s , %s ) unsupportted mode %d", #__ITEM_, #__HASH_, __HASH_->mode); \
} else                                                                                                        \
    for (size_t __hash_it = 0; __hash_it < __HASH_->size; __hash_it++)                                        \
        for (LIST_NODE* __ITEM_ = __HASH_->hash_table[__hash_it]->start; __ITEM_ != NULL; __ITEM_ = __ITEM_->next)

ForEach macro helper (classic / old).

define hash_val

#define hash_val(
    node,
    type
)
((node && node->ptr) ? ((type*)(((HASH_NODE*)node->ptr)->data.ptr)) : NULL)

Cast a HASH_NODE element.

define MurmurHash

#define MurmurHash(
    __key,
    __len,
    __seed,
    __out
)
MurmurHash3_x64_128(__key, __len, __seed, __out)

Murmur hash macro helper 64 bits.

define HT_FOREACH_R

#define HT_FOREACH_R(
    __ITEM_,
    __HASH_,
    __ITERATOR,
    ...
)
{                                                                                                                                                                                                                                  \
    do {                                                                                                                                                                                                                           \
        if (!__HASH_) {                                                                                                                                                                                                            \
            n_log(LOG_ERR, "Error in ht_foreach, %s is NULL", #__HASH_);                                                                                                                                                           \
        } else {                                                                                                                                                                                                                   \
            if (__HASH_->mode == HASH_CLASSIC) {                                                                                                                                                                                   \
                int CONCAT(__ht_node_trie_func_macro_break_flag_classic, __LINE__) = 0;                                                                                                                                            \
                LIST_NODE* CONCAT(__ht_list_node_r, __LINE__) = NULL;                                                                                                                                                              \
                for (size_t __ITERATOR = 0; __ITERATOR < __HASH_->size; __ITERATOR++) {                                                                                                                                            \
                    for (CONCAT(__ht_list_node_r, __LINE__) = __HASH_->hash_table[__ITERATOR]->start; CONCAT(__ht_list_node_r, __LINE__) != NULL; CONCAT(__ht_list_node_r, __LINE__) = CONCAT(__ht_list_node_r, __LINE__)->next) { \
                        HASH_NODE* __ITEM_ = (HASH_NODE*)CONCAT(__ht_list_node_r, __LINE__)->ptr;                                                                                                                                  \
                        CONCAT(__ht_node_trie_func_macro_break_flag_classic, __LINE__) = 1;                                                                                                                                        \
                        __VA_ARGS__                                                                                                                                                                                                \
                        CONCAT(__ht_node_trie_func_macro_break_flag_classic, __LINE__) = 0;                                                                                                                                        \
                    }                                                                                                                                                                                                              \
                    if (CONCAT(__ht_node_trie_func_macro_break_flag_classic, __LINE__) == 1)                                                                                                                                       \
                        break;                                                                                                                                                                                                     \
                }                                                                                                                                                                                                                  \
            } else if (__HASH_->mode == HASH_TRIE) {                                                                                                                                                                               \
                int CONCAT(__ht_node_trie_func_macro, __LINE__)(HASH_NODE * __ITEM_) {                                                                                                                                             \
                    if (!__ITEM_) return TRUE;                                                                                                                                                                                     \
                    int CONCAT(__ht_node_trie_func_macro_break_flag, __LINE__) = 1;                                                                                                                                                \
                    if (__ITEM_->is_leaf) {                                                                                                                                                                                        \
                        do {                                                                                                                                                                                                       \
                            __VA_ARGS__                                                                                                                                                                                            \
                            CONCAT(__ht_node_trie_func_macro_break_flag, __LINE__) = 0;                                                                                                                                            \
                        } while (0);                                                                                                                                                                                               \
                    }                                                                                                                                                                                                              \
                    if (CONCAT(__ht_node_trie_func_macro_break_flag, __LINE__) == 1) return FALSE;                                                                                                                                 \
                    for (size_t it = 0; it < __ITEM_->alphabet_length; it++) {                                                                                                                                                     \
                        if (CONCAT(__ht_node_trie_func_macro, __LINE__)(__ITEM_->children[it]) == FALSE)                                                                                                                           \
                            return FALSE;                                                                                                                                                                                          \
                    }                                                                                                                                                                                                              \
                    return TRUE;                                                                                                                                                                                                   \
                }                                                                                                                                                                                                                  \
                CONCAT(__ht_node_trie_func_macro, __LINE__)                                                                                                                                                                        \
                (__HASH_->root);                                                                                                                                                                                                   \
            } else {                                                                                                                                                                                                               \
                n_log(LOG_ERR, "Error in ht_foreach, %d is an unsupported mode", __HASH_->mode);                                                                                                                                   \
                break;                                                                                                                                                                                                             \
            }                                                                                                                                                                                                                      \
        }                                                                                                                                                                                                                          \
    } while (0);                                                                                                                                                                                                                   \
}

ForEach macro helper.

define HT_FOREACH

#define HT_FOREACH(
    __ITEM_,
    __HASH_,
    ...
)
{                                                                                                                                                                                                \
    do {                                                                                                                                                                                         \
        if (!__HASH_) {                                                                                                                                                                          \
            n_log(LOG_ERR, "Error in ht_foreach, %s is NULL", #__HASH_);                                                                                                                         \
        } else {                                                                                                                                                                                 \
            if (__HASH_->mode == HASH_CLASSIC) {                                                                                                                                                 \
                int CONCAT(__ht_node_trie_func_macro_break_flag_classic, __LINE__) = 0;                                                                                                          \
                for (size_t __hash_it = 0; __hash_it < __HASH_->size; __hash_it++) {                                                                                                             \
                    for (LIST_NODE* __ht_list_node = __HASH_->hash_table[__hash_it]->start; __ht_list_node != NULL; __ht_list_node = __ht_list_node->next) {                                     \
                        HASH_NODE* __ITEM_ = (HASH_NODE*)__ht_list_node->ptr;                                                                                                                    \
                        CONCAT(__ht_node_trie_func_macro_break_flag_classic, __LINE__) = 1;                                                                                                      \
                        __VA_ARGS__                                                                                                                                                              \
                        CONCAT(__ht_node_trie_func_macro_break_flag_classic, __LINE__) = 0;                                                                                                      \
                    }                                                                                                                                                                            \
                    if (CONCAT(__ht_node_trie_func_macro_break_flag_classic, __LINE__) == 1)                                                                                                     \
                        break;                                                                                                                                                                   \
                }                                                                                                                                                                                \
            } else if (__HASH_->mode == HASH_TRIE) {                                                                                                                                             \
                int CONCAT(__ht_node_trie_func_macro, __LINE__)(HASH_NODE * __ITEM_) {                                                                                                           \
                    if (!__ITEM_) return TRUE;                                                                                                                                                   \
                    int CONCAT(__ht_node_trie_func_macro_break_flag, __LINE__) = 1;                                                                                                              \
                    if (__ITEM_->is_leaf) {                                                                                                                                                      \
                        do {                                                                                                                                                                     \
                            __VA_ARGS__                                                                                                                                                          \
                            CONCAT(__ht_node_trie_func_macro_break_flag, __LINE__) = 0;                                                                                                          \
                        } while (0);                                                                                                                                                             \
                    }                                                                                                                                                                            \
                    if (CONCAT(__ht_node_trie_func_macro_break_flag, __LINE__) == 1) return FALSE;                                                                                               \
                    for (size_t CONCAT(__ht_node_trie_func_it, __LINE__) = 0; CONCAT(__ht_node_trie_func_it, __LINE__) < __ITEM_->alphabet_length; CONCAT(__ht_node_trie_func_it, __LINE__)++) { \
                        if (CONCAT(__ht_node_trie_func_macro, __LINE__)(__ITEM_->children[CONCAT(__ht_node_trie_func_it, __LINE__)]) == FALSE)                                                   \
                            return FALSE;                                                                                                                                                        \
                    }                                                                                                                                                                            \
                    return TRUE;                                                                                                                                                                 \
                }                                                                                                                                                                                \
                CONCAT(__ht_node_trie_func_macro, __LINE__)                                                                                                                                      \
                (__HASH_->root);                                                                                                                                                                 \
            } else {                                                                                                                                                                             \
                n_log(LOG_ERR, "Error in ht_foreach, %d is an unsupported mode", __HASH_->mode);                                                                                                 \
                break;                                                                                                                                                                           \
            }                                                                                                                                                                                    \
        }                                                                                                                                                                                        \
    } while (0);                                                                                                                                                                                 \
}

ForEach macro helper.

define HASH_VAL

#define HASH_VAL(
    node,
    type
)
((node && node->data.ptr) ? ((type*)node->data.ptr) : NULL)

Cast a HASH_NODE element.

define HASH_UNKNOWN

#define HASH_UNKNOWN 16

value of unknow type inside the hash node

define HASH_TRIE

#define HASH_TRIE 256

TRIE tree using hash key string.

define HASH_STRING

#define HASH_STRING 4

value of char * type inside the hash node

define HASH_PTR

#define HASH_PTR 8

value of pointer type inside the hash node

define HASH_INT_TYPE

#define HASH_INT_TYPE int64_t

type of a HASH_INT in 64 bits

define HASH_INT

#define HASH_INT 1

compatibility with existing rot func

compatibility with existing rot func

compatibility with existing func

missing ROTL fix 32bit

missing ROTL fix 64bit

missing ROTL constant

value of integral type inside the hash node

define HASH_DOUBLE

#define HASH_DOUBLE 2

value of double type inside the hash node

define HASH_CLASSIC

#define HASH_CLASSIC 128

Murmur hash using hash key string, hash key numeric value, index table with lists of elements.