157#ifndef TOMMY_HASHDYN_H
158#define TOMMY_HASHDYN_H
170#define TOMMY_HASHDYN_BIT 4
331 if (i->
index == hash && cmp(cmp_arg, i->
data) == 0)
353 return node ? node->
data : 0;
490 return hashdyn->
count;
501 return hashdyn->
count == 0;
Hashtable container type.
Definition: tommyhashdyn.h:182
tommy_size_t count
Number of elements.
Definition: tommyhashdyn.h:186
tommy_uint_t bucket_bit
Bits used in the bit mask.
Definition: tommyhashdyn.h:187
tommy_hashdyn_node ** bucket
Hash buckets.
Definition: tommyhashdyn.h:183
tommy_size_t bucket_mask
Bit mask to access the buckets.
Definition: tommyhashdyn.h:185
tommy_size_t bucket_max
Number of buckets.
Definition: tommyhashdyn.h:184
Data structure node.
Definition: tommytypes.h:242
tommy_size_t index
Index of the node.
Definition: tommytypes.h:269
struct tommy_node_struct * next
Next node.
Definition: tommytypes.h:247
void * data
Pointer to the element containing the node.
Definition: tommytypes.h:260
Hash functions for use with tommy_hashtable, tommy_hashdyn and tommy_hashlin.
void * tommy_hashdyn_search(tommy_hashdyn *hashdyn, tommy_search_func *cmp, const void *cmp_arg, tommy_hash_t hash)
Searches an element in the hashtable.
Definition: tommyhashdyn.h:349
TOMMY_API void * tommy_hashdyn_remove(tommy_hashdyn *hashdyn, tommy_search_func *cmp, const void *cmp_arg, tommy_hash_t hash)
Searches and removes an element from the hashtable.
TOMMY_API tommy_hashdyn_node * tommy_hashdyn_head(tommy_hashdyn *hashdyn)
Gets the first node in iteration order, or 0 if empty.
TOMMY_API tommy_hashdyn_node * tommy_hashdyn_tail(tommy_hashdyn *hashdyn)
Gets the last node in iteration order, or 0 if empty.
TOMMY_API void tommy_hashdyn_foreach_arg(tommy_hashdyn *hashdyn, tommy_foreach_arg_func *func, void *arg)
Calls the specified function with an argument for each element in the hashtable.
void tommy_hashdyn_swap(tommy_hashdyn *first, tommy_hashdyn *second)
Exchanges the complete state of two initialized hashtables, including bucket allocations.
Definition: tommyhashdyn.h:214
TOMMY_API void tommy_hashdyn_shrink(tommy_hashdyn *hashdyn)
Shrinks the allocated buckets to fit the current number of elements.
TOMMY_API tommy_hashdyn_node * tommy_hashdyn_prev(tommy_hashdyn *hashdyn, tommy_hashdyn_node *node)
Gets the preceding node in iteration order, or 0 for the head.
TOMMY_API tommy_size_t tommy_hashdyn_memory_usage(const tommy_hashdyn *hashdyn)
Gets the size of allocated memory.
tommy_bool_t tommy_hashdyn_empty(const tommy_hashdyn *hashdyn)
Checks whether the hashtable is empty.
Definition: tommyhashdyn.h:499
TOMMY_API void tommy_hashdyn_to_list(tommy_hashdyn *hashdyn, tommy_list *list)
Transfers all elements from the hashtable into a tommy_list.
tommy_hashdyn_node * tommy_hashdyn_bucket(tommy_hashdyn *hashdyn, tommy_hash_t hash)
Gets the bucket of the specified hash.
Definition: tommyhashdyn.h:309
TOMMY_API void tommy_hashdyn_clear(tommy_hashdyn *hashdyn)
Removes all elements, preserving the allocated buckets.
TOMMY_API void tommy_hashdyn_foreach(tommy_hashdyn *hashdyn, tommy_foreach_func *func)
Calls the specified function for each element in the hashtable.
TOMMY_API void tommy_hashdyn_done(tommy_hashdyn *hashdyn)
Deinitializes the hashtable.
TOMMY_API void tommy_hashdyn_rehash_existing(tommy_hashdyn *hashdyn, tommy_hashdyn_node *node, tommy_hash_t hash)
Updates the hash of an element already contained in the hashtable.
TOMMY_API tommy_hashdyn_node * tommy_hashdyn_next(tommy_hashdyn *hashdyn, tommy_hashdyn_node *node)
Gets the following node in iteration order, or 0 for the tail.
tommy_size_t tommy_hashdyn_count(const tommy_hashdyn *hashdyn)
Gets the number of elements.
Definition: tommyhashdyn.h:488
TOMMY_API void * tommy_hashdyn_remove_existing(tommy_hashdyn *hashdyn, tommy_hashdyn_node *node)
Removes an element from the hashtable.
TOMMY_API void * tommy_hashdyn_insert_unique(tommy_hashdyn *hashdyn, tommy_hashdyn_node *node, void *data, tommy_search_func *cmp, const void *cmp_arg, tommy_hash_t hash)
Inserts an element only if no equal element is already contained.
tommy_node tommy_hashdyn_node
Hashtable node.
Definition: tommyhashdyn.h:176
TOMMY_API void tommy_hashdyn_reserve(tommy_hashdyn *hashdyn, tommy_size_t count)
Pre-allocates buckets for the specified number of elements.
struct tommy_hashdyn_struct tommy_hashdyn
Hashtable container type.
TOMMY_API void tommy_hashdyn_init(tommy_hashdyn *hashdyn)
Initializes the hashtable.
tommy_size_t tommy_hashdyn_bucket_count(const tommy_hashdyn *hashdyn)
Gets the number of buckets.
Definition: tommyhashdyn.h:510
TOMMY_API void tommy_hashdyn_insert(tommy_hashdyn *hashdyn, tommy_hashdyn_node *node, void *data, tommy_hash_t hash)
Inserts an element in the hashtable.
tommy_hashdyn_node * tommy_hashdyn_find(tommy_hashdyn *hashdyn, tommy_search_func *cmp, const void *cmp_arg, tommy_hash_t hash)
Finds a node in the hashtable.
Definition: tommyhashdyn.h:325
Doubly linked list for collisions into hashtables.
void tommy_foreach_func(void *elem)
Foreach function.
Definition: tommytypes.h:346
int tommy_search_func(const void *arg, const void *elem)
Search function for elements.
Definition: tommytypes.h:334
uint64_t tommy_size_t
Generic size_t type.
Definition: tommytypes.h:40
void tommy_foreach_arg_func(void *arg, void *elem)
Foreach function with an argument.
Definition: tommytypes.h:353
tommy_size_t tommy_hash_t
Type used in hashtables to store the hash of an element.
Definition: tommytypes.h:224
tommy_uint32_t tommy_uint_t
Generic unsigned integer type.
Definition: tommytypes.h:61
int tommy_bool_t
Generic boolean type.
Definition: tommytypes.h:53