![]() |
Nilorea Library
C utilities for networking, threading, graphics
|
Hash functions and table. More...
#include "nilorea/n_common.h"#include "nilorea/n_log.h"#include "nilorea/n_hash.h"#include "nilorea/n_str.h"#include <fcntl.h>#include <pthread.h>#include <string.h>#include <strings.h>#include <time.h>#include <unistd.h>#include <arpa/inet.h>Go to the source code of this file.
Macros | |
| #define | BIG_CONSTANT(x) |
| max unsigned long long | |
| #define | BYTESWAP32(x) |
| 32 bits bytes swap | |
| #define | BYTESWAP64(x) |
| 32 bits bytes swap | |
| #define | ROTL32(x, r) |
| 32 bit rotate left | |
| #define | ROTL64(x, r) |
| 64 bit rotate left | |
Functions | |
| int | _destroy_ht (HASH_TABLE **table) |
| Free and set the table to NULL. | |
| int | _destroy_ht_trie (HASH_TABLE **table) |
| Free and set the table to NULL (TRIE mode). | |
| int | _empty_ht (HASH_TABLE *table) |
| Empty a hash table (CLASSIC mode). | |
| int | _empty_ht_trie (HASH_TABLE *table) |
| Empty a TRIE hash table. | |
| size_t | _ht_check_trie_divergence (HASH_TABLE *table, const char *key) |
| check and return branching index in key if any | |
| int | _ht_depth_first_search (HASH_NODE *node, LIST *results) |
| recursive, helper for ht_get_completion_list, get the list of leaf starting from node | |
| char * | _ht_find_longest_prefix_trie (HASH_TABLE *table, const char *key) |
| find the longest prefix string that is not the current key | |
| int | _ht_get_double (HASH_TABLE *table, const char *key, double *val) |
| Retrieve a double value in the hash table, at the given key. | |
| int | _ht_get_double_trie (HASH_TABLE *table, const char *key, double *val) |
| Retrieve an double value in the hash table, at the given key. | |
| int | _ht_get_int (HASH_TABLE *table, const char *key, int64_t *val) |
| Retrieve an integral value in the hash table, at the given key. | |
| int | _ht_get_int_trie (HASH_TABLE *table, const char *key, int64_t *val) |
| Retrieve an integral value in the hash table, at the given key. | |
| HASH_NODE * | _ht_get_node (HASH_TABLE *table, const char *key) |
| return the associated key's node inside the hash_table | |
| HASH_NODE * | _ht_get_node_trie (HASH_TABLE *table, const char *key) |
| retrieve a HASH_NODE at key from table | |
| int | _ht_get_ptr (HASH_TABLE *table, const char *key, void **val) |
| Retrieve a pointer value in the hash table, at the given key. | |
| int | _ht_get_ptr_trie (HASH_TABLE *table, const char *key, void **val) |
| Retrieve a pointer value in the hash table, at the given key. | |
| int | _ht_get_string (HASH_TABLE *table, const char *key, char **val) |
| Retrieve a char *string value in the hash table, at the given key. | |
| int | _ht_get_string_trie (HASH_TABLE *table, const char *key, char **val) |
| Retrieve an char *string value in the hash table, at the given key. | |
| static HASH_VALUE | _ht_hash_value (const HASH_TABLE *table, const char *key, size_t key_len) |
| compute a key's hash value with a correctly sized output buffer | |
| int | _ht_is_leaf_node_trie (HASH_TABLE *table, const char *key) |
| Search a key and tell if it's holding a value (leaf). | |
| static void | _ht_key_init (void) |
| static uint64_t | _ht_mix (uint64_t x) |
| HASH_NODE * | _ht_new_double_node (HASH_TABLE *table, const char *key, double value) |
| node creation, HASH_CLASSIC mode | |
| HASH_NODE * | _ht_new_int_node (HASH_TABLE *table, const char *key, int64_t value) |
| node creation, HASH_CLASSIC mode | |
| HASH_NODE * | _ht_new_node (const HASH_TABLE *table, const char *key) |
| node creation, HASH_CLASSIC mode | |
| HASH_NODE * | _ht_new_node_trie (HASH_TABLE *table, const char key) |
| node creation, HASH_CLASSIC mode | |
| HASH_NODE * | _ht_new_ptr_node (HASH_TABLE *table, const char *key, void *value, void(*destructor)(void *ptr), void *(*duplicator)(void *ptr)) |
| node creation, HASH_CLASSIC mode, pointer to string value | |
| static size_t | _ht_new_seed (void) |
| HASH_NODE * | _ht_new_string_node (HASH_TABLE *table, const char *key, const char *value) |
| node creation, HASH_CLASSIC mode, strdup of value | |
| HASH_NODE * | _ht_new_string_ptr_node (HASH_TABLE *table, const char *key, char *value) |
| node creation, HASH_CLASSIC mode, pointer to string value | |
| void | _ht_node_destroy (void *node) |
| destroy a HASH_NODE by first calling the HASH_NODE destructor | |
| void | _ht_print (HASH_TABLE *table) |
| Generic print func call for classic hash tables. | |
| void | _ht_print_trie (HASH_TABLE *table) |
| Generic print func call for trie trees. | |
| void | _ht_print_trie_helper (HASH_TABLE *table, HASH_NODE *node) |
| Recursive function to print trie tree's keys and values. | |
| int | _ht_put_double (HASH_TABLE *table, const char *key, double value) |
| put a double value with given key in the targeted hash table | |
| int | _ht_put_double_trie (HASH_TABLE *table, const char *key, double value) |
| put a double value with given key in the targeted hash table [TRIE HASH TABLE) | |
| int | _ht_put_int (HASH_TABLE *table, const char *key, int64_t value) |
| put an integral value with given key in the targeted hash table [CLASSIC HASH TABLE) | |
| int | _ht_put_int_trie (HASH_TABLE *table, const char *key, int64_t value) |
| put an integral value with given key in the targeted hash table [TRIE HASH TABLE) | |
| int | _ht_put_ptr (HASH_TABLE *table, const char *key, void *ptr, void(*destructor)(void *ptr), void *(*duplicator)(void *ptr)) |
| put a pointer value with given key in the targeted hash table | |
| int | _ht_put_ptr_trie (HASH_TABLE *table, const char *key, void *ptr, void(*destructor)(void *ptr), void *(*duplicator)(void *ptr)) |
| put a pointer to the string value with given key in the targeted hash table [TRIE HASH TABLE) | |
| int | _ht_put_string (HASH_TABLE *table, const char *key, char *string) |
| put a null terminated char *string with given key in the targeted hash table (copy of string) | |
| int | _ht_put_string_ptr (HASH_TABLE *table, const char *key, char *string) |
| put a null terminated char *string with given key in the targeted hash table (pointer) | |
| int | _ht_put_string_ptr_trie (HASH_TABLE *table, const char *key, char *string) |
| put a pointer to the string value with given key in the targeted hash table [TRIE HASH TABLE) | |
| int | _ht_put_string_trie (HASH_TABLE *table, const char *key, char *string) |
| put a duplicate of the string value with given key in the targeted hash table [TRIE HASH TABLE) | |
| int | _ht_remove (HASH_TABLE *table, const char *key) |
| Remove a key from a hash table. | |
| int | _ht_remove_trie (HASH_TABLE *table, const char *key) |
| Remove a key from a trie table and destroy the node. | |
| LIST * | _ht_search (HASH_TABLE *table, int(*node_is_matching)(HASH_NODE *node)) |
| Search hash table's keys and apply a matching func to put results in the list. | |
| LIST * | _ht_search_trie (HASH_TABLE *table, int(*node_is_matching)(HASH_NODE *node)) |
| Search tree's keys and apply a matching func to put results in the list. | |
| void | _ht_search_trie_helper (LIST *results, HASH_NODE *node, int(*node_is_matching)(HASH_NODE *node)) |
| Recursive function to search tree's keys and apply a matching func to put results in the list. | |
| int | destroy_ht (HASH_TABLE **table) |
| empty a table and destroy it | |
| int | empty_ht (HASH_TABLE *table) |
| empty a table | |
| uint32_t | fmix32 (uint32_t h) |
| Finalization mix - force all bits of a hash block to avalanche (from murmur's author). | |
| uint64_t | fmix64 (uint64_t k) |
| Finalization mix - force all bits of a hash block to avalanche (from murmur's author). | |
| uint32_t | getblock32 (const uint32_t *p, const size_t i) |
| Block read - modified from murmur's author, ajusted byte endianess. | |
| uint64_t | getblock64 (const uint64_t *p, const size_t i) |
| Block read - modified from murmur's author, ajusted byte endianess. | |
| HASH_TABLE * | ht_duplicate (HASH_TABLE *table) |
| duplicate a hash table (all pointers should have a duplicator func set) | |
| LIST * | ht_get_completion_list (HASH_TABLE *table, const char *keybud, size_t max_results) |
| get next matching keys in table tree | |
| int | ht_get_double (HASH_TABLE *table, const char *key, double *val) |
| get double at 'key' from 'table' | |
| int | ht_get_int (HASH_TABLE *table, const char *key, int64_t *val) |
| get node at 'key' from 'table' | |
| HASH_NODE * | ht_get_node (HASH_TABLE *table, const char *key) |
| get node at 'key' from 'table' | |
| HASH_NODE * | ht_get_node_ex (HASH_TABLE *table, HASH_VALUE hash_value) |
| return the associated key's node inside the hash_table (HASH_CLASSIC only) | |
| size_t | ht_get_optimal_size (HASH_TABLE *table) |
| get optimal array size based on nb=(number_of_key*1.3) && if( !isprime(nb) )nb=nextprime(nb) (HASH_CLASSIC mode only) | |
| int | ht_get_ptr (HASH_TABLE *table, const char *key, void **val) |
| get pointer at 'key' from 'table' | |
| int | ht_get_ptr_ex (HASH_TABLE *table, HASH_VALUE hash_value, void **val) |
| Retrieve a pointer value in the hash table, at the given key. | |
| int | ht_get_string (HASH_TABLE *table, const char *key, char **val) |
| get string at 'key' from 'table' | |
| int | ht_get_table_collision_percentage (HASH_TABLE *table) |
| get table collision percentage (HASH_CLASSIC mode only) | |
| char * | ht_node_type (const HASH_NODE *node) |
| get the type of a node , text version | |
| int | ht_optimize (HASH_TABLE **table) |
| try an automatic optimization of the table (HASH_CLASSIC mode only) | |
| void | ht_print (HASH_TABLE *table) |
| print contents of table | |
| int | ht_put_double (HASH_TABLE *table, const char *key, double value) |
| put a double value with given key in the targeted hash table | |
| int | ht_put_int (HASH_TABLE *table, const char *key, int64_t value) |
| put an integral value with given key in the targeted hash table | |
| int | ht_put_ptr (HASH_TABLE *table, const char *key, void *ptr, void(*destructor)(void *ptr), void *(*duplicator)(void *ptr)) |
| put an arbitrary pointer value with given key in the targeted hash table | |
| int | ht_put_ptr_ex (HASH_TABLE *table, HASH_VALUE hash_value, void *val, void(*destructor)(void *ptr), void *(*duplicator)(void *ptr)) |
| put a pointer value with given key in the targeted hash table (HASH_CLASSIC only) | |
| int | ht_put_string (HASH_TABLE *table, const char *key, char *string) |
| put a string value (copy/dup) with given key in the targeted hash table | |
| int | ht_put_string_ptr (HASH_TABLE *table, const char *key, char *string) |
| put a string value (pointer) with given key in the targeted hash table | |
| int | ht_remove (HASH_TABLE *table, const char *key) |
| remove and delete node at key in table | |
| int | ht_remove_ex (HASH_TABLE *table, HASH_VALUE hash_value) |
| Remove a key from a hash table (HASH_CLASSIC only). | |
| int | ht_resize (HASH_TABLE **table, size_t size) |
| rehash table according to size (HASH_CLASSIC mode only) | |
| LIST * | ht_search (HASH_TABLE *table, int(*node_is_matching)(HASH_NODE *node)) |
| seach table for matching nodes | |
| int | is_prime (size_t nb) |
| test if number is a prime number or not | |
| void | MurmurHash3_x64_128 (const void *key, const size_t len, const uint64_t seed, void *out) |
| MurmurHash3 was written by Austin Appleby, and is placed in the public domain. | |
| void | MurmurHash3_x86_128 (const void *key, const size_t len, const uint32_t seed, void *out) |
| MurmurHash3 was written by Austin Appleby, and is placed in the public domain. | |
| void | MurmurHash3_x86_32 (const void *key, const size_t len, const uint32_t seed, void *out) |
| MurmurHash3 was written by Austin Appleby, and is placed in the public domain. | |
| HASH_TABLE * | new_ht (size_t size) |
| Create a hash table with the given size. | |
| HASH_TABLE * | new_ht_trie (size_t alphabet_length, size_t alphabet_offset) |
| create a TRIE hash table with the alphabet_size, each key value beeing decreased by alphabet_offset | |
| size_t | next_prime (size_t nb) |
| compute next prime number after nb | |
Variables | |
| static pthread_mutex_t | _ht_counter_lock = PTHREAD_MUTEX_INITIALIZER |
| static pthread_once_t | _ht_key_once = PTHREAD_ONCE_INIT |
| static uint64_t | _ht_process_key = 0 |
| static uint64_t | _ht_table_counter = 0 |
| #define BIG_CONSTANT | ( | x | ) |
| #define BYTESWAP32 | ( | x | ) |
32 bits bytes swap
Definition at line 907 of file n_hash.c.
Referenced by getblock32().
| #define BYTESWAP64 | ( | x | ) |
32 bits bytes swap
Definition at line 911 of file n_hash.c.
Referenced by getblock64().
| #define ROTL32 | ( | x, | |
| r ) |
32 bit rotate left
Definition at line 878 of file n_hash.c.
Referenced by MurmurHash3_x86_128(), and MurmurHash3_x86_32().
| #define ROTL64 | ( | x, | |
| r ) |
64 bit rotate left
Definition at line 876 of file n_hash.c.
Referenced by MurmurHash3_x64_128().
| int _destroy_ht | ( | HASH_TABLE ** | table | ) |
Free and set the table to NULL.
| table | targeted hash table |
Definition at line 1947 of file n_hash.c.
References __n_assert, Free, list_destroy(), LOG_ERR, and n_log.
Referenced by new_ht().
| int _destroy_ht_trie | ( | HASH_TABLE ** | table | ) |
Free and set the table to NULL (TRIE mode).
| table | targeted hash table |
Definition at line 750 of file n_hash.c.
References __n_assert, _ht_node_destroy(), Free, LOG_ERR, and n_log.
Referenced by new_ht_trie().
| int _empty_ht | ( | HASH_TABLE * | table | ) |
Empty a hash table (CLASSIC mode).
| table | targeted hash table |
Definition at line 1928 of file n_hash.c.
References __n_assert, _ht_node_destroy(), HASH_TABLE::hash_table, HASH_TABLE::nb_keys, remove_list_node, HASH_TABLE::size, and LIST::start.
Referenced by new_ht().
| int _empty_ht_trie | ( | HASH_TABLE * | table | ) |
Empty a TRIE hash table.
| table | targeted hash table |
Definition at line 734 of file n_hash.c.
References __n_assert, _ht_new_node_trie(), _ht_node_destroy(), HASH_TABLE::nb_keys, and HASH_TABLE::root.
Referenced by new_ht_trie().
| size_t _ht_check_trie_divergence | ( | HASH_TABLE * | table, |
| const char * | key ) |
check and return branching index in key if any
| table | targeted hash table |
| key | associated value's key |
Definition at line 155 of file n_hash.c.
References __n_assert, HASH_TABLE::alphabet_length, HASH_TABLE::alphabet_offset, HASH_NODE::children, key, LOG_ERR, n_log, and HASH_TABLE::root.
Referenced by _ht_find_longest_prefix_trie().
recursive, helper for ht_get_completion_list, get the list of leaf starting from node
| node | starting node |
| results | initialized LIST * for the matching NODES |
Definition at line 856 of file n_hash.c.
References __n_assert, _ht_depth_first_search(), HASH_NODE::alphabet_length, HASH_NODE::children, HASH_NODE::is_leaf, HASH_NODE::key, list_push(), LIST::nb_items, and LIST::nb_max_items.
Referenced by _ht_depth_first_search(), and ht_get_completion_list().
| char * _ht_find_longest_prefix_trie | ( | HASH_TABLE * | table, |
| const char * | key ) |
find the longest prefix string that is not the current key
| table | targeted hash table |
| key | key to search prefix for |
Definition at line 199 of file n_hash.c.
References __n_assert, _ht_check_trie_divergence(), key, Malloc, and Realloc.
Referenced by _ht_remove_trie().
| int _ht_get_double | ( | HASH_TABLE * | table, |
| const char * | key, | ||
| double * | val ) |
Retrieve a double value in the hash table, at the given key.
Leave val untouched if key is not found.
| table | targeted hash table |
| key | associated value's key |
| val | A pointer to a destination double |
Definition at line 1801 of file n_hash.c.
References __n_assert, _ht_get_node(), HASH_NODE::data, HASH_DATA::fval, HASH_DOUBLE, ht_node_type(), key, LOG_ERR, n_log, and HASH_NODE::type.
Referenced by new_ht().
| int _ht_get_double_trie | ( | HASH_TABLE * | table, |
| const char * | key, | ||
| double * | val ) |
Retrieve an double value in the hash table, at the given key.
Leave val untouched if key is not found.
| table | targeted hash table |
| key | associated value's key |
| val | a pointer to a destination double |
Definition at line 652 of file n_hash.c.
References __n_assert, _ht_get_node_trie(), HASH_NODE::data, HASH_DATA::fval, HASH_DOUBLE, ht_node_type(), HASH_NODE::is_leaf, key, LOG_ERR, n_log, and HASH_NODE::type.
Referenced by new_ht_trie().
| int _ht_get_int | ( | HASH_TABLE * | table, |
| const char * | key, | ||
| int64_t * | val ) |
Retrieve an integral value in the hash table, at the given key.
Leave val untouched if key is not found.
| table | targeted hash table |
| key | associated value's key |
| val | A pointer to a destination integer |
Definition at line 1773 of file n_hash.c.
References __n_assert, _ht_get_node(), HASH_NODE::data, HASH_INT, HASH_INT_TYPE, ht_node_type(), HASH_DATA::ival, key, LOG_ERR, n_log, and HASH_NODE::type.
Referenced by new_ht().
| int _ht_get_int_trie | ( | HASH_TABLE * | table, |
| const char * | key, | ||
| int64_t * | val ) |
Retrieve an integral value in the hash table, at the given key.
Leave val untouched if key is not found.
| table | targeted hash table |
| key | associated value's key |
| val | a pointer to a destination integer |
Definition at line 624 of file n_hash.c.
References __n_assert, _ht_get_node_trie(), HASH_NODE::data, HASH_INT, HASH_INT_TYPE, ht_node_type(), HASH_NODE::is_leaf, HASH_DATA::ival, key, LOG_ERR, n_log, and HASH_NODE::type.
Referenced by new_ht_trie().
| HASH_NODE * _ht_get_node | ( | HASH_TABLE * | table, |
| const char * | key ) |
return the associated key's node inside the hash_table
| table | targeted table |
| key | Associated value's key |
Definition at line 1397 of file n_hash.c.
References __n_assert, _ht_hash_value(), HASH_TABLE::hash_table, HASH_NODE::key, key, list_foreach, HASH_TABLE::size, and LIST::start.
Referenced by _ht_get_double(), _ht_get_int(), _ht_get_ptr(), _ht_get_string(), _ht_put_double(), _ht_put_int(), _ht_put_ptr(), _ht_put_string(), _ht_put_string_ptr(), and new_ht().
| HASH_NODE * _ht_get_node_trie | ( | HASH_TABLE * | table, |
| const char * | key ) |
retrieve a HASH_NODE at key from table
| table | targeted hash table |
| key | associated value's key |
Definition at line 591 of file n_hash.c.
References __n_assert, HASH_TABLE::alphabet_length, HASH_TABLE::alphabet_offset, HASH_NODE::children, key, LOG_DEBUG, n_log, and HASH_TABLE::root.
Referenced by _ht_get_double_trie(), _ht_get_int_trie(), _ht_get_ptr_trie(), _ht_get_string_trie(), and ht_get_completion_list().
| int _ht_get_ptr | ( | HASH_TABLE * | table, |
| const char * | key, | ||
| void ** | val ) |
Retrieve a pointer value in the hash table, at the given key.
Leave val untouched if key is not found.
| table | targeted hash table |
| key | associated value's key |
| val | A pointer to an empty pointer store |
Definition at line 1830 of file n_hash.c.
References __n_assert, _ht_get_node(), HASH_NODE::data, HASH_PTR, ht_node_type(), key, LOG_ERR, n_log, HASH_DATA::ptr, and HASH_NODE::type.
Referenced by new_ht().
| int _ht_get_ptr_trie | ( | HASH_TABLE * | table, |
| const char * | key, | ||
| void ** | val ) |
Retrieve a pointer value in the hash table, at the given key.
Leave val untouched if key is not found.
| table | targeted hash table |
| key | associated value's key |
| val | a pointer to a destination pointer |
Definition at line 708 of file n_hash.c.
References __n_assert, _ht_get_node_trie(), HASH_NODE::data, HASH_PTR, ht_node_type(), HASH_NODE::is_leaf, key, LOG_ERR, n_log, HASH_DATA::ptr, and HASH_NODE::type.
Referenced by new_ht_trie().
| int _ht_get_string | ( | HASH_TABLE * | table, |
| const char * | key, | ||
| char ** | val ) |
Retrieve a char *string value in the hash table, at the given key.
Leave val untouched if key is not found.
| table | targeted hash table |
| key | associated value's key |
| val | A pointer to an empty destination char *string |
Definition at line 1857 of file n_hash.c.
References __n_assert, _ht_get_node(), HASH_NODE::data, HASH_STRING, ht_node_type(), key, LOG_ERR, n_log, HASH_DATA::string, and HASH_NODE::type.
Referenced by new_ht().
| int _ht_get_string_trie | ( | HASH_TABLE * | table, |
| const char * | key, | ||
| char ** | val ) |
Retrieve an char *string value in the hash table, at the given key.
Leave val untouched if key is not found.
| table | targeted hash table |
| key | associated value's key |
| val | a pointer to a destination char *string |
Definition at line 680 of file n_hash.c.
References __n_assert, _ht_get_node_trie(), HASH_NODE::data, HASH_STRING, ht_node_type(), HASH_NODE::is_leaf, key, LOG_ERR, n_log, HASH_DATA::string, and HASH_NODE::type.
Referenced by new_ht_trie().
|
static |
compute a key's hash value with a correctly sized output buffer
Both MurmurHash 128-bit variants write exactly 16 bytes, whatever HASH_VALUE happens to measure:
64-bit: MurmurHash3_x64_128 -> 2 x uint64_t, and HASH_VALUE[2] is 16 bytes 32-bit: MurmurHash3_x86_128 -> 4 x uint32_t, but HASH_VALUE is size_t, so a HASH_VALUE[2] is only 8 bytes
Passing a HASH_VALUE[2] therefore overflowed the stack by 8 bytes on every hash insert, lookup and remove of every 32-bit build, while 64-bit builds fitted exactly and never showed it. Found as a SIGSEGV at startup in an Android armeabi-v7a build of DarkChan (_ht_new_node <- _ht_put_ptr <- n_gui_add_label), 2026-08-19.
Owning the buffer in one place is the point: the callers only ever wanted the first HASH_VALUE of the digest, and none of them can now get the size wrong. memcpy rather than a cast keeps it free of aliasing assumptions, and takes the same leading bytes the callers used before, so hash values are unchanged on 64-bit.
| table | targeted table, for its seed |
| key | the key to hash |
| key_len | length of key |
Definition at line 1381 of file n_hash.c.
References key, MurmurHash, and HASH_TABLE::seed.
Referenced by _ht_get_node(), _ht_new_node(), and _ht_remove().
| int _ht_is_leaf_node_trie | ( | HASH_TABLE * | table, |
| const char * | key ) |
Search a key and tell if it's holding a value (leaf).
| table | targeted hash table |
| key | key verify |
Definition at line 96 of file n_hash.c.
References __n_assert, HASH_TABLE::alphabet_length, HASH_TABLE::alphabet_offset, HASH_NODE::children, HASH_NODE::is_leaf, key, LOG_ERR, n_log, and HASH_TABLE::root.
Referenced by _ht_remove_trie().
|
static |
Definition at line 2065 of file n_hash.c.
References _ht_process_key.
Referenced by _ht_new_seed().
|
static |
Definition at line 2094 of file n_hash.c.
Referenced by _ht_new_seed().
| HASH_NODE * _ht_new_double_node | ( | HASH_TABLE * | table, |
| const char * | key, | ||
| double | value ) |
node creation, HASH_CLASSIC mode
| table | targeted table |
| key | key of new node |
| value | double value of key |
Definition at line 1486 of file n_hash.c.
References __n_assert, _ht_new_node(), HASH_NODE::data, HASH_DATA::fval, HASH_DOUBLE, key, LOG_ERR, n_log, and HASH_NODE::type.
Referenced by _ht_put_double().
| HASH_NODE * _ht_new_int_node | ( | HASH_TABLE * | table, |
| const char * | key, | ||
| int64_t | value ) |
node creation, HASH_CLASSIC mode
| table | targeted table |
| key | key of new node |
| value | int value of key |
Definition at line 1464 of file n_hash.c.
References __n_assert, _ht_new_node(), HASH_NODE::data, HASH_INT, HASH_INT_TYPE, HASH_DATA::ival, key, LOG_ERR, n_log, and HASH_NODE::type.
Referenced by _ht_put_int().
| HASH_NODE * _ht_new_node | ( | const HASH_TABLE * | table, |
| const char * | key ) |
node creation, HASH_CLASSIC mode
| table | targeted table |
| key | key of new node |
Definition at line 1428 of file n_hash.c.
References __n_assert, _ht_hash_value(), HASH_NODE::alphabet_length, HASH_NODE::children, HASH_NODE::data, HASH_NODE::destroy_func, Free, HASH_NODE::hash_value, HASH_NODE::is_leaf, HASH_NODE::key, key, HASH_NODE::key_id, LOG_ERR, Malloc, n_log, HASH_NODE::need_rehash, and HASH_DATA::ptr.
Referenced by _ht_new_double_node(), _ht_new_int_node(), _ht_new_ptr_node(), _ht_new_string_node(), and _ht_new_string_ptr_node().
| HASH_NODE * _ht_new_node_trie | ( | HASH_TABLE * | table, |
| const char | key ) |
node creation, HASH_CLASSIC mode
| table | targeted table |
| key | key of new node |
Definition at line 62 of file n_hash.c.
References __n_assert, HASH_NODE::alphabet_length, HASH_TABLE::alphabet_length, HASH_NODE::children, HASH_NODE::data, HASH_NODE::destroy_func, Free, HASH_NODE::hash_value, HASH_NODE::is_leaf, HASH_NODE::key, key, HASH_NODE::key_id, LOG_ERR, Malloc, n_log, HASH_NODE::need_rehash, and HASH_DATA::ptr.
Referenced by _empty_ht_trie(), _ht_put_double_trie(), _ht_put_int_trie(), _ht_put_ptr_trie(), _ht_put_string_ptr_trie(), _ht_put_string_trie(), and new_ht_trie().
| HASH_NODE * _ht_new_ptr_node | ( | HASH_TABLE * | table, |
| const char * | key, | ||
| void * | value, | ||
| void(* | destructor )(void *ptr), | ||
| void *(* | duplicator )(void *ptr) ) |
node creation, HASH_CLASSIC mode, pointer to string value
| table | targeted table |
| key | key of new node |
| value | pointer data of key |
| destructor | function pointer to a destructor of value type |
| duplicator | function pointer to a duplicator of value type (or NULL) |
Definition at line 1557 of file n_hash.c.
References __n_assert, _ht_new_node(), HASH_NODE::data, HASH_NODE::destroy_func, HASH_NODE::duplicate_func, HASH_PTR, key, LOG_ERR, n_log, HASH_DATA::ptr, and HASH_NODE::type.
Referenced by _ht_put_ptr().
|
static |
Definition at line 2102 of file n_hash.c.
References _ht_counter_lock, _ht_key_init(), _ht_key_once, _ht_mix(), _ht_process_key, and _ht_table_counter.
Referenced by new_ht().
| HASH_NODE * _ht_new_string_node | ( | HASH_TABLE * | table, |
| const char * | key, | ||
| const char * | value ) |
node creation, HASH_CLASSIC mode, strdup of value
| table | targeted table |
| key | key of new node |
| value | char *value of key |
Definition at line 1508 of file n_hash.c.
References __n_assert, _ht_new_node(), HASH_NODE::data, HASH_STRING, key, LOG_ERR, n_log, HASH_DATA::string, and HASH_NODE::type.
Referenced by _ht_put_string().
| HASH_NODE * _ht_new_string_ptr_node | ( | HASH_TABLE * | table, |
| const char * | key, | ||
| char * | value ) |
node creation, HASH_CLASSIC mode, pointer to string value
| table | targeted table |
| key | key of new node |
| value | char *value of key |
Definition at line 1533 of file n_hash.c.
References __n_assert, _ht_new_node(), HASH_NODE::data, HASH_STRING, key, LOG_ERR, n_log, HASH_DATA::string, and HASH_NODE::type.
Referenced by _ht_put_string_ptr().
| void _ht_node_destroy | ( | void * | node | ) |
destroy a HASH_NODE by first calling the HASH_NODE destructor
| node | The node to kill |
Definition at line 120 of file n_hash.c.
References __n_assert, _ht_node_destroy(), HASH_NODE::alphabet_length, HASH_NODE::children, HASH_NODE::data, HASH_NODE::destroy_func, Free, FreeNoLog, HASH_PTR, HASH_STRING, HASH_NODE::key, HASH_DATA::ptr, HASH_DATA::string, and HASH_NODE::type.
Referenced by _destroy_ht_trie(), _empty_ht(), _empty_ht_trie(), _ht_node_destroy(), _ht_put_double(), _ht_put_int(), _ht_put_ptr(), _ht_put_string(), _ht_put_string_ptr(), _ht_remove(), _ht_remove_trie(), ht_put_ptr_ex(), and ht_remove_ex().
| void _ht_print | ( | HASH_TABLE * | table | ) |
Generic print func call for classic hash tables.
| table | targeted hash table |
Definition at line 1968 of file n_hash.c.
References __n_assert, HASH_TABLE::hash_table, ht_foreach, and HASH_NODE::key.
Referenced by new_ht().
| void _ht_print_trie | ( | HASH_TABLE * | table | ) |
Generic print func call for trie trees.
| table | targeted hash table |
Definition at line 799 of file n_hash.c.
References __n_assert, _ht_print_trie_helper(), and HASH_TABLE::root.
Referenced by new_ht_trie().
| void _ht_print_trie_helper | ( | HASH_TABLE * | table, |
| HASH_NODE * | node ) |
Recursive function to print trie tree's keys and values.
| table | targeted hash table |
| node | current node |
Definition at line 765 of file n_hash.c.
References _ht_print_trie_helper(), HASH_TABLE::alphabet_length, HASH_NODE::children, HASH_NODE::data, HASH_DATA::fval, HASH_DOUBLE, HASH_INT, HASH_PTR, HASH_STRING, HASH_NODE::is_leaf, HASH_DATA::ival, HASH_NODE::key, HASH_DATA::ptr, HASH_DATA::string, and HASH_NODE::type.
Referenced by _ht_print_trie(), and _ht_print_trie_helper().
| int _ht_put_double | ( | HASH_TABLE * | table, |
| const char * | key, | ||
| double | value ) |
put a double value with given key in the targeted hash table
| table | targeted hash table |
| key | associated value's key |
| value | double value to put |
Definition at line 1615 of file n_hash.c.
References __n_assert, _ht_get_node(), _ht_new_double_node(), _ht_node_destroy(), HASH_NODE::data, HASH_DATA::fval, HASH_DOUBLE, HASH_TABLE::hash_table, HASH_NODE::hash_value, ht_node_type(), HASH_NODE::key, key, list_push(), LOG_ERR, n_log, HASH_TABLE::nb_keys, HASH_TABLE::size, and HASH_NODE::type.
Referenced by new_ht().
| int _ht_put_double_trie | ( | HASH_TABLE * | table, |
| const char * | key, | ||
| double | value ) |
put a double value with given key in the targeted hash table [TRIE HASH TABLE)
| table | targeted hash table |
| key | associated value's key |
| value | double value to put |
Definition at line 353 of file n_hash.c.
References __n_assert, _ht_new_node_trie(), _ht_remove_trie(), HASH_TABLE::alphabet_length, HASH_TABLE::alphabet_offset, HASH_NODE::children, HASH_NODE::data, FreeNoLog, HASH_DATA::fval, HASH_DOUBLE, HASH_NODE::is_leaf, HASH_NODE::key, key, LOG_ERR, n_log, HASH_TABLE::nb_keys, HASH_TABLE::root, and HASH_NODE::type.
Referenced by new_ht_trie().
| int _ht_put_int | ( | HASH_TABLE * | table, |
| const char * | key, | ||
| int64_t | value ) |
put an integral value with given key in the targeted hash table [CLASSIC HASH TABLE)
| table | targeted table |
| key | associated value's key |
| value | integral value to put |
Definition at line 1581 of file n_hash.c.
References __n_assert, _ht_get_node(), _ht_new_int_node(), _ht_node_destroy(), HASH_NODE::data, HASH_INT, HASH_INT_TYPE, HASH_TABLE::hash_table, HASH_NODE::hash_value, ht_node_type(), HASH_DATA::ival, HASH_NODE::key, key, list_push(), LOG_ERR, n_log, HASH_TABLE::nb_keys, HASH_TABLE::size, and HASH_NODE::type.
Referenced by new_ht().
| int _ht_put_int_trie | ( | HASH_TABLE * | table, |
| const char * | key, | ||
| int64_t | value ) |
put an integral value with given key in the targeted hash table [TRIE HASH TABLE)
| table | targeted hash table |
| key | associated value's key |
| value | integral value to put |
Definition at line 298 of file n_hash.c.
References __n_assert, _ht_new_node_trie(), _ht_remove_trie(), HASH_TABLE::alphabet_length, HASH_TABLE::alphabet_offset, HASH_NODE::children, HASH_NODE::data, FreeNoLog, HASH_INT, HASH_INT_TYPE, HASH_NODE::is_leaf, HASH_DATA::ival, HASH_NODE::key, key, LOG_ERR, n_log, HASH_TABLE::nb_keys, HASH_TABLE::root, and HASH_NODE::type.
Referenced by new_ht_trie().
| int _ht_put_ptr | ( | HASH_TABLE * | table, |
| const char * | key, | ||
| void * | ptr, | ||
| void(* | destructor )(void *ptr), | ||
| void *(* | duplicator )(void *ptr) ) |
put a pointer value with given key in the targeted hash table
| table | targeted hash table |
| key | Associated value's key |
| 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 |
Definition at line 1651 of file n_hash.c.
References __n_assert, _ht_get_node(), _ht_new_ptr_node(), _ht_node_destroy(), HASH_NODE::data, HASH_NODE::destroy_func, HASH_NODE::duplicate_func, HASH_PTR, HASH_TABLE::hash_table, HASH_NODE::hash_value, ht_node_type(), HASH_NODE::key, key, list_push(), LOG_ERR, n_log, HASH_TABLE::nb_keys, HASH_DATA::ptr, HASH_TABLE::size, and HASH_NODE::type.
Referenced by new_ht().
| int _ht_put_ptr_trie | ( | HASH_TABLE * | table, |
| const char * | key, | ||
| void * | ptr, | ||
| void(* | destructor )(void *ptr), | ||
| void *(* | duplicator )(void *ptr) ) |
put a pointer to the string value with given key in the targeted hash table [TRIE HASH TABLE)
| table | targeted hash table |
| key | associated value's key |
| ptr | pointer value to put |
| destructor | the destructor func for ptr or NULL |
| duplicator | the duplicate func for ptr or NULL |
Definition at line 532 of file n_hash.c.
References __n_assert, _ht_new_node_trie(), _ht_remove_trie(), HASH_TABLE::alphabet_length, HASH_TABLE::alphabet_offset, HASH_NODE::children, HASH_NODE::data, HASH_NODE::destroy_func, HASH_NODE::duplicate_func, FreeNoLog, HASH_PTR, HASH_NODE::is_leaf, HASH_NODE::key, key, LOG_ERR, n_log, HASH_TABLE::nb_keys, HASH_DATA::ptr, HASH_TABLE::root, and HASH_NODE::type.
Referenced by new_ht_trie().
| int _ht_put_string | ( | HASH_TABLE * | table, |
| const char * | key, | ||
| char * | string ) |
put a null terminated char *string with given key in the targeted hash table (copy of string)
| table | targeted hash table |
| key | Associated value's key |
| string | string value to put (will be strdup'ed) |
Definition at line 1693 of file n_hash.c.
References __n_assert, _ht_get_node(), _ht_new_string_node(), _ht_node_destroy(), HASH_NODE::data, Free, HASH_STRING, HASH_TABLE::hash_table, HASH_NODE::hash_value, ht_node_type(), HASH_NODE::key, key, list_push(), LOG_ERR, n_log, HASH_TABLE::nb_keys, HASH_TABLE::size, HASH_DATA::string, and HASH_NODE::type.
Referenced by new_ht().
| int _ht_put_string_ptr | ( | HASH_TABLE * | table, |
| const char * | key, | ||
| char * | string ) |
put a null terminated char *string with given key in the targeted hash table (pointer)
| table | targeted hash table |
| key | Associated value's key |
| string | The string to put |
Definition at line 1737 of file n_hash.c.
References __n_assert, _ht_get_node(), _ht_new_string_ptr_node(), _ht_node_destroy(), HASH_NODE::data, Free, HASH_STRING, HASH_TABLE::hash_table, HASH_NODE::hash_value, ht_node_type(), HASH_NODE::key, key, list_push(), LOG_ERR, n_log, HASH_TABLE::nb_keys, HASH_TABLE::size, HASH_DATA::string, and HASH_NODE::type.
Referenced by new_ht().
| int _ht_put_string_ptr_trie | ( | HASH_TABLE * | table, |
| const char * | key, | ||
| char * | string ) |
put a pointer to the string value with given key in the targeted hash table [TRIE HASH TABLE)
| table | targeted hash table |
| key | associated value's key |
| string | string value to put (pointer) |
Definition at line 475 of file n_hash.c.
References __n_assert, _ht_new_node_trie(), _ht_remove_trie(), HASH_TABLE::alphabet_length, HASH_TABLE::alphabet_offset, HASH_NODE::children, HASH_NODE::data, FreeNoLog, HASH_STRING, HASH_NODE::is_leaf, HASH_NODE::key, key, LOG_ERR, n_log, HASH_TABLE::nb_keys, HASH_TABLE::root, HASH_DATA::string, and HASH_NODE::type.
Referenced by new_ht_trie().
| int _ht_put_string_trie | ( | HASH_TABLE * | table, |
| const char * | key, | ||
| char * | string ) |
put a duplicate of the string value with given key in the targeted hash table [TRIE HASH TABLE)
| table | targeted hash table |
| key | associated value's key |
| string | string value to put (copy) |
Definition at line 408 of file n_hash.c.
References __n_assert, _ht_new_node_trie(), _ht_remove_trie(), HASH_TABLE::alphabet_length, HASH_TABLE::alphabet_offset, HASH_NODE::children, HASH_NODE::data, Free, FreeNoLog, HASH_STRING, HASH_NODE::is_leaf, HASH_NODE::key, key, LOG_ERR, n_log, HASH_TABLE::nb_keys, HASH_TABLE::root, HASH_DATA::string, and HASH_NODE::type.
Referenced by new_ht_trie().
| int _ht_remove | ( | HASH_TABLE * | table, |
| const char * | key ) |
Remove a key from a hash table.
| table | targeted hash table |
| key | Key to remove |
Definition at line 1883 of file n_hash.c.
References __n_assert, _ht_hash_value(), _ht_node_destroy(), HASH_TABLE::hash_table, HASH_NODE::key, key, list_foreach, LOG_ERR, n_log, HASH_TABLE::nb_keys, remove_list_node, HASH_TABLE::size, and LIST::start.
Referenced by new_ht().
| int _ht_remove_trie | ( | HASH_TABLE * | table, |
| const char * | key ) |
Remove a key from a trie table and destroy the node.
| table | targeted tabled |
| key | the node key to kill |
Definition at line 231 of file n_hash.c.
References __n_assert, _ht_find_longest_prefix_trie(), _ht_is_leaf_node_trie(), _ht_node_destroy(), HASH_TABLE::alphabet_length, HASH_TABLE::alphabet_offset, HASH_NODE::children, Free, key, LOG_ERR, n_log, HASH_TABLE::nb_keys, and HASH_TABLE::root.
Referenced by _ht_put_double_trie(), _ht_put_int_trie(), _ht_put_ptr_trie(), _ht_put_string_ptr_trie(), _ht_put_string_trie(), and new_ht_trie().
| LIST * _ht_search | ( | HASH_TABLE * | table, |
| int(* | node_is_matching )(HASH_NODE *node) ) |
Search hash table's keys and apply a matching func to put results in the list.
| table | targeted table |
| node_is_matching | pointer to a matching function to use |
Definition at line 1986 of file n_hash.c.
References __n_assert, ht_foreach, HASH_NODE::key, list_destroy(), list_push(), MAX_LIST_ITEMS, LIST::nb_items, and new_generic_list().
Referenced by new_ht().
| LIST * _ht_search_trie | ( | HASH_TABLE * | table, |
| int(* | node_is_matching )(HASH_NODE *node) ) |
Search tree's keys and apply a matching func to put results in the list.
| table | targeted table |
| node_is_matching | pointer to a matching function to use |
Definition at line 836 of file n_hash.c.
References __n_assert, _ht_search_trie_helper(), list_destroy(), MAX_LIST_ITEMS, LIST::nb_items, new_generic_list(), and HASH_TABLE::root.
Referenced by new_ht_trie().
| void _ht_search_trie_helper | ( | LIST * | results, |
| HASH_NODE * | node, | ||
| int(* | node_is_matching )(HASH_NODE *node) ) |
Recursive function to search tree's keys and apply a matching func to put results in the list.
| results | targeted and initialized LIST in which the matching nodes will be put |
| node | targeted starting trie node |
| node_is_matching | pointer to a matching function to use |
Definition at line 816 of file n_hash.c.
References _ht_search_trie_helper(), HASH_NODE::alphabet_length, HASH_NODE::children, HASH_NODE::is_leaf, HASH_NODE::key, and list_push().
Referenced by _ht_search_trie(), and _ht_search_trie_helper().
| uint32_t fmix32 | ( | uint32_t | h | ) |
Finalization mix - force all bits of a hash block to avalanche (from murmur's author).
| h | value |
Definition at line 951 of file n_hash.c.
References FORCE_INLINE, and h().
Referenced by MurmurHash3_x86_128(), and MurmurHash3_x86_32().
| uint64_t fmix64 | ( | uint64_t | k | ) |
Finalization mix - force all bits of a hash block to avalanche (from murmur's author).
| k | value |
Definition at line 966 of file n_hash.c.
References BIG_CONSTANT, and FORCE_INLINE.
Referenced by MurmurHash3_x64_128().
| uint32_t getblock32 | ( | const uint32_t * | p, |
| const size_t | i ) |
Block read - modified from murmur's author, ajusted byte endianess.
| p | value |
| i | position |
Definition at line 928 of file n_hash.c.
References BYTESWAP32, and FORCE_INLINE.
Referenced by MurmurHash3_x86_128(), and MurmurHash3_x86_32().
| uint64_t getblock64 | ( | const uint64_t * | p, |
| const size_t | i ) |
Block read - modified from murmur's author, ajusted byte endianess.
| p | value |
| i | position |
Definition at line 940 of file n_hash.c.
References BYTESWAP64, and FORCE_INLINE.
Referenced by MurmurHash3_x64_128().
|
static |
Definition at line 2063 of file n_hash.c.
Referenced by _ht_new_seed().
|
static |
Definition at line 2062 of file n_hash.c.
Referenced by _ht_new_seed().
|
static |
Definition at line 2060 of file n_hash.c.
Referenced by _ht_key_init(), and _ht_new_seed().
|
static |
Definition at line 2061 of file n_hash.c.
Referenced by _ht_new_seed().