Entries may be added to and removed from the table using the ht_add() and ht_remove() functions. Additionally, the key on a given entry may be changed using the ht_move() function. Of course, any given entry may be looked up using the ht_find() function, and ht_iter() will execute a user-defined function for each entry in the hash table (in an unspecified order). The ht_flush() function will remove all entries from the hash table, optionally executing a user-specified clean-up function.
Data Structures | |
struct | _hash_table_s |
Hash table structure. More... | |
struct | _hash_entry_s |
Hash table entry structure. More... | |
Defines | |
#define | MAX_PRIME |
Largest prime. | |
#define | HASH_TABLE_MAGIC |
Hash table magic number. | |
#define | HASH_FLAG_AUTOGROW |
Flag permitting a hash table to automatically grow. | |
#define | HASH_FLAG_AUTOSHRINK |
Flag permitting a hash table to automatically shrink. | |
#define | HASH_FLAG_MASK |
Hash table flags that may be set by the user. | |
#define | HASH_TABLE_INIT(flags, func, comp, resize, extra) |
Hash table static initializer. | |
#define | ht_verify(table) |
Hash table verification macro. | |
#define | ht_flags(table) |
Hash table flags. | |
#define | ht_frozen(table) |
Determine if a hash table is frozen. | |
#define | ht_modulus(table) |
Hash table modulus. | |
#define | ht_count(table) |
Hash table count. | |
#define | ht_func(table) |
Hash table hash function. | |
#define | ht_comp(table) |
Hash table comparison function. | |
#define | ht_rsize(table) |
Hash table resize callback function. | |
#define | ht_extra(table) |
Extra pointer data in a hash table. | |
#define | ht_size(table) |
Hash table memory size. | |
#define | HASH_ENTRY_MAGIC |
Hash table entry magic number. | |
#define | HASH_ENTRY_INIT(value) |
Hash table entry static initializer. | |
#define | he_verify(entry) |
Hash table entry verification macro. | |
#define | he_link(entry) |
Hash table entry linked list element. | |
#define | he_flags(entry) |
Hash table entry flags. | |
#define | he_table(entry) |
Hash table entry table pointer. | |
#define | he_hash(entry) |
Hash table entry hash value. | |
#define | he_key(entry) |
Hash table entry key pointer. | |
#define | he_value(entry) |
Hash table entry value pointer. | |
#define | st_rsize(table) |
Sparse matrix table resize callback function. | |
#define | _hash_rollover(mod) |
Select hash table roll over size. | |
#define | _hash_rollunder(mod) |
Select hash table roll under size. | |
#define | _hash_fuzz(mod) |
Fuzz the initial hash table size. | |
#define | HASH_FNV_OFFSET |
FNV offset basis parameter. | |
#define | HASH_FNV_PRIME |
FNV prime parameter. | |
Typedefs | |
typedef _hash_table_s | hash_table_t |
Hash table. | |
typedef _hash_entry_s | hash_entry_t |
Hash table entry. | |
typedef unsigned long(* | hash_iter_t )(hash_table_t *table, hash_entry_t *ent, void *extra) |
Hash table iteration callback. | |
typedef unsigned long(* | hash_func_t )(hash_table_t *table, db_key_t *key) |
Hash function callback. | |
typedef unsigned long(* | hash_comp_t )(hash_table_t *table, db_key_t *key1, db_key_t *key2) |
Hash table comparison callback. | |
typedef unsigned long(* | hash_resize_t )(hash_table_t *table, unsigned long new_mod) |
Hash table resize callback. | |
Functions | |
unsigned long | hash_fnv1 (hash_table_t *table, db_key_t *key) |
FNV-1 hash function. | |
unsigned long | hash_fnv1a (hash_table_t *table, db_key_t *key) |
FNV-1a hash function. | |
unsigned long | hash_comp (hash_table_t *table, db_key_t *key1, db_key_t *key2) |
Hash comparison function. | |
unsigned long | ht_init (hash_table_t *table, unsigned long flags, hash_func_t func, hash_comp_t comp, hash_resize_t resize, void *extra, unsigned long init_mod) |
Dynamically initialize a hash table. | |
unsigned long | ht_add (hash_table_t *table, hash_entry_t *entry, db_key_t *key) |
Add an entry to a hash table. | |
unsigned long | ht_move (hash_table_t *table, hash_entry_t *entry, db_key_t *key) |
Move an entry in the hash table. | |
unsigned long | ht_remove (hash_table_t *table, hash_entry_t *entry) |
Remove an element from a hash table. | |
unsigned long | ht_find (hash_table_t *table, hash_entry_t **entry_p, db_key_t *key) |
Find an entry in a hash table. | |
unsigned long | ht_iter (hash_table_t *table, hash_iter_t iter_func, void *extra) |
Iterate over each entry in a hash table. | |
unsigned long | ht_flush (hash_table_t *table, hash_iter_t flush_func, void *extra) |
Flush a hash table. | |
unsigned long | ht_resize (hash_table_t *table, unsigned long new_size) |
Resize a hash table. | |
unsigned long | ht_free (hash_table_t *table) |
Free memory used by an empty hash table. | |
unsigned long | he_init (hash_entry_t *entry, void *value) |
Dynamically initialize a hash table entry. | |
unsigned long | _hash_prime (unsigned long start) |
Select a prime number. | |
Variables | |
static unsigned long | primes [] |
Table of primes. |
|
For internal use only. This macro is used to apply a fudge factor to a user-supplied size for the hash table, causing a slightly larger bucket to be allocated.
Definition at line 107 of file dbprim_int.h. Referenced by ht_add(), and ht_resize(). |
|
For internal use only. This macro is used to compute the "roll over" size--the size at which the hash table will be grown (assuming that the table has HASH_FLAG_AUTOGROW set).
Definition at line 79 of file dbprim_int.h. Referenced by ht_init(), and ht_resize(). |
|
For internal use only. This macro is used to compute the "roll under" size--the size at which the hash table will be shrunk (assuming that the table has HASH_FLAG_AUTOSHRINK set).
Definition at line 93 of file dbprim_int.h. Referenced by ht_init(), and ht_resize(). |
|
This macro statically initializes a hash_entry_t.
|
|
For internal use only. This is the magic number used for the hash table entry structure. Definition at line 1502 of file dbprim.h. Referenced by he_init(). |
|
If passed in to HASH_TABLE_INIT() or ht_init(), allows the hash table to grow automatically. |
|
If passed in to HASH_TABLE_INIT() or ht_init(), allows the hash table to shrink automatically. Definition at line 1108 of file dbprim.h. Referenced by ht_flush(), ht_init(), and ht_remove(). |
|
This flag mask may be used to obtain flags that the hash table user may set on a hash table. |
|
For internal use only. This is the 32-bit offset basis for the FNV hash algorithm. See http://www.isthe.com/chongo/tech/comp/fnv/ for more information about the FNV hash algorithm. Definition at line 117 of file dbprim_int.h. Referenced by hash_fnv1(), and hash_fnv1a(). |
|
For internal use only. This is the 32-bit multiplication prime for the FNV hash algorithm. See http://www.isthe.com/chongo/tech/comp/fnv/ for more information about the FNV hash algorithm. Definition at line 127 of file dbprim_int.h. Referenced by hash_fnv1(), and hash_fnv1a(). |
|
This macro statically initializes a hash_table_t.
|
|
For internal use only. This is the magic number used for the hash table structure. Definition at line 1092 of file dbprim.h. Referenced by ht_init(). |
|
This macro retrieves a set of user-defined flags associated with the entry. It may be used as an lvalue to set those flags.
|
|
This macro retrieves the hash value of the given hash entry. If the hash table has been resized, this value may not be the same as a previous value.
|
|
This macro retrieves the key associated with the hash table entry.
Definition at line 1592 of file dbprim.h. Referenced by ht_find(). |
|
This macro provides access to the linked list element buried in the hash table entry. It should *not* be used on entries currently in a hash table. The purpose of this macro is to allow an object containing a hash table entry to be placed upon a free list.
|
|
This macro retrieves a pointer to the hash table the entry is in.
|
|
This macro retrieves the value associated with the hash table entry. It may be treated as an lvalue to change that value. Care should be taken when using this option.
Definition at line 1606 of file dbprim.h. Referenced by _st_flush_iter(), _st_iter_iter(), and st_find(). |
|
This macro verifies that a given pointer actually does point to a hash table entry.
Definition at line 1528 of file dbprim.h. Referenced by ht_add(), ht_move(), and ht_remove(). |
|
This macro retrieves the comparison function pointer.
|
|
This macro retrieves the total number of items actually in the hash table.
|
|
This macro retrieves the extra pointer data associated with a particular hash table.
Definition at line 1266 of file dbprim.h. Referenced by _smat_resize(). |
|
This macro retrieves the flags associated with the hash table. Only HASH_FLAG_AUTOGROW and HASH_FLAG_AUTOSHRINK have any meaning to the application; all other bits are reserved for use in the library. This macro may be used as an lvalue, but care must be taken to avoid modifying the library-specific bits.
|
|
This macro returns a non-zero value if the table is currently frozen. The hash table may be frozen if there is an iteration in progress.
|
|
This macro retrieves the hash function pointer.
|
|
This macro retrieves the number of buckets allocated for the hash table. An application may wish to save this value between invocations to avoid the overhead of growing the table while filling it with data.
Definition at line 1208 of file dbprim.h. Referenced by ht_flush(), ht_init(), ht_iter(), and ht_resize(). |
|
This macro retrieves the resize callback function pointer.
|
|
This macro returns the physical size of the bucket array allocated by the library for this hash table.
|
|
This macro verifies that a given pointer actually does point to a hash table.
Definition at line 1162 of file dbprim.h. Referenced by ht_add(), ht_find(), ht_flush(), ht_free(), ht_iter(), ht_move(), ht_remove(), and ht_resize(). |
|
For internal use only. This is the largest prime number that can be handled by the _hash_prime() function. Definition at line 41 of file _hash_prime.c. Referenced by _hash_prime(). |
|
This macro retrieves the resize callback function pointer.
|
|
This function pointer references a callback used to compare entries in a hash table. It should return 0 for identical entries and non-zero otherwise. No assumptions should be made about the order in which the two keys are passed to this function.
|
|
This structure represents a single entry of a hash table. |
|
This function is associated with a hash table, and is responsible for generating a hash value. The full 32-bit range of an
|
|
This function pointer references a callback used by ht_iter() and ht_flush(). It should return 0 for success. A non-zero return value will terminate the operation and will become the return value of the ht_iter() or ht_flush() call.
|
|
This function pointer references a callback that will be called with both the old and new hash table sizes whenever a hash table is resized. It should return non-zero only when the resize should be inhibited.
|
|
This structure is the basis of all hash tables maintained by this library. |
|
For internal use only.
This function is used by the hash table system to find the first prime number larger than
Definition at line 781 of file _hash_prime.c. References MAX_PRIME, and primes. Referenced by ht_init(), and ht_resize(). |
|
This is a hash comparison function, compatible with hash_comp_t, based around memcmp().
Definition at line 36 of file hash_comp.c. References dk_key, and dk_len. Referenced by st_init(). |
|
This is a hash function, compatible with hash_func_t, based around the FNV-1 hash algorithm. See http://www.isthe.com/chongo/tech/comp/fnv/ for more information about FNV-1.
Definition at line 35 of file hash_fnv1.c. References dk_key, dk_len, HASH_FNV_OFFSET, and HASH_FNV_PRIME. |
|
This is a hash function, compatible with hash_func_t, based around the FNV-1a hash algorithm. See http://www.isthe.com/chongo/tech/comp/fnv/ for more information about FNV-1a.
Definition at line 35 of file hash_fnv1a.c. References dk_key, dk_len, HASH_FNV_OFFSET, and HASH_FNV_PRIME. Referenced by st_init(). |
|
This function dynamically initializes a hash table entry.
Definition at line 34 of file he_init.c. References _db_key_s::dk_key, _db_key_s::dk_len, HASH_ENTRY_MAGIC, _hash_entry_s::he_elem, _hash_entry_s::he_hash, _hash_entry_s::he_key, _hash_entry_s::he_magic, _hash_entry_s::he_table, _hash_entry_s::he_value, and le_init(). Referenced by _smat_alloc(). Here is the call graph for this function: ![]() |
|
This function adds an entry to a hash table.
Definition at line 34 of file ht_add.c. References _hash_fuzz, HASH_FLAG_AUTOGROW, HASH_FLAG_FREEZE, _hash_entry_s::he_elem, _hash_entry_s::he_hash, _hash_entry_s::he_key, _hash_entry_s::he_table, he_verify, _hash_table_s::ht_count, ht_find(), _hash_table_s::ht_flags, _hash_table_s::ht_func, _hash_table_s::ht_modulus, ht_resize(), _hash_table_s::ht_rollover, _hash_table_s::ht_table, ht_verify, le_object, LINK_LOC_HEAD, and ll_add(). Referenced by st_add(). Here is the call graph for this function: ![]() |
|
This function looks up an entry matching the given
Definition at line 34 of file ht_find.c. References he_key, _hash_table_s::ht_comp, _hash_table_s::ht_count, _hash_table_s::ht_func, _hash_table_s::ht_modulus, _hash_table_s::ht_table, ht_verify, le_next, le_object, and ll_first. |
|
This function flushes a hash table--that is, it removes each entry from the table. If a
Definition at line 36 of file ht_flush.c. References HASH_FLAG_AUTOSHRINK, HASH_FLAG_FREEZE, _hash_table_s::ht_count, _hash_table_s::ht_flags, ht_free(), ht_modulus, ht_remove(), _hash_table_s::ht_table, ht_verify, le_object, and ll_first. Referenced by st_flush(). Here is the call graph for this function: ![]() |
|
This function releases the memory used by the bucket table in an empty hash table.
Definition at line 36 of file ht_free.c. References HASH_FLAG_FREEZE, _hash_table_s::ht_count, _hash_table_s::ht_flags, _hash_table_s::ht_modulus, _hash_table_s::ht_rollover, _hash_table_s::ht_rollunder, _hash_table_s::ht_table, and ht_verify. Referenced by ht_flush(), and st_free(). |
|
This function dynamically initializes a hash table.
Definition at line 37 of file ht_init.c. References _hash_prime(), _hash_rollover, _hash_rollunder, HASH_FLAG_AUTOGROW, HASH_FLAG_AUTOSHRINK, HASH_TABLE_MAGIC, _hash_table_s::ht_comp, _hash_table_s::ht_count, _hash_table_s::ht_extra, _hash_table_s::ht_flags, _hash_table_s::ht_func, _hash_table_s::ht_magic, _hash_table_s::ht_modulus, ht_modulus, _hash_table_s::ht_resize, _hash_table_s::ht_rollover, _hash_table_s::ht_rollunder, _hash_table_s::ht_table, and ll_init(). Referenced by st_init(). Here is the call graph for this function: ![]() |
|
This function iterates over every entry in a hash table (in an unspecified order), executing the given
Definition at line 34 of file ht_iter.c. References HASH_FLAG_FREEZE, _hash_table_s::ht_flags, ht_modulus, _hash_table_s::ht_table, ht_verify, le_next, le_object, and ll_first. Referenced by st_iter(). |
|
This function moves an existing entry in the hash table to correspond to the new key.
Definition at line 34 of file ht_move.c. References HASH_FLAG_FREEZE, _hash_entry_s::he_elem, _hash_entry_s::he_hash, _hash_entry_s::he_key, _hash_entry_s::he_table, he_verify, _hash_table_s::ht_count, ht_find(), _hash_table_s::ht_flags, _hash_table_s::ht_func, _hash_table_s::ht_modulus, _hash_table_s::ht_table, ht_verify, LINK_LOC_HEAD, ll_add(), and ll_remove(). Here is the call graph for this function: ![]() |
|
This function removes the given element from the specified hash table.
Definition at line 34 of file ht_remove.c. References HASH_FLAG_AUTOSHRINK, HASH_FLAG_FREEZE, _hash_entry_s::he_elem, _hash_entry_s::he_hash, _hash_entry_s::he_table, he_verify, _hash_table_s::ht_count, _hash_table_s::ht_flags, ht_resize(), _hash_table_s::ht_rollunder, _hash_table_s::ht_table, ht_verify, and ll_remove(). Referenced by _st_remove(), ht_flush(), and st_add(). Here is the call graph for this function: ![]() |
|
This function resizes a hash table to the given
Definition at line 38 of file ht_resize.c. References _hash_fuzz, _hash_prime(), _hash_rollover, _hash_rollunder, HASH_FLAG_FREEZE, _hash_entry_s::he_hash, _hash_entry_s::he_key, _hash_table_s::ht_count, _hash_table_s::ht_flags, _hash_table_s::ht_func, ht_modulus, _hash_table_s::ht_modulus, _hash_table_s::ht_resize, _hash_table_s::ht_rollover, _hash_table_s::ht_rollunder, _hash_table_s::ht_table, ht_verify, le_object, LINK_LOC_HEAD, ll_add(), ll_first, ll_init(), and ll_remove(). Referenced by ht_add(), ht_remove(), and st_resize(). Here is the call graph for this function: ![]() |
|
For internal use only. This variable contains a table of 16-bit prime numbers, used by _hash_prime() to test the primality of potential primes. Definition at line 50 of file _hash_prime.c. Referenced by _hash_prime(). |