|
Veritable Lasagna
An Allocator & Data Structure Library for C.
|
Include dependency graph for vl_hashtable.h:
This graph shows which files directly or indirectly include this file:Go to the source code of this file.
Data Structures | |
| struct | vl_hashtable |
| A dynamically-sized hash table with variable-sized keys and values. More... | |
Macros | |
| #define | VL_HASHTABLE_ITER_INVALID 0 |
| #define | VL_HASHTABLE_RESIZE_FACTOR 0.8 |
| #define | VL_HASHTABLE_DEFAULT_SIZE 128 |
| #define | VL_HASHTABLE_FOREACH(table, trackVar) |
Typedefs | |
| typedef vl_arena_ptr | vl_hash_iter |
Functions | |
| VL_API void | vlHashTableInit (vl_hashtable *table, vl_hash_function hashFunc) |
| Initializes the specified table with a hash function. | |
| VL_API void | vlHashTableFree (vl_hashtable *table) |
| De-initializes and frees the internal resources of the specified table. | |
| VL_API vl_hashtable * | vlHashTableNew (vl_hash_function func) |
| Allocates on the heap, initializes, and returns a new hash table instance. | |
| VL_API void | vlHashTableDelete (vl_hashtable *table) |
| De-initializes and deletes the specified table and its resources. | |
| VL_API vl_hash_iter | vlHashTableInsert (vl_hashtable *table, const void *key, vl_memsize_t keySize, vl_memsize_t dataSize) |
| Claims a chunk of memory associated with the specified key. If the key already exists, the associated chunk is reallocated to match the specified size. | |
| VL_API void | vlHashTableRemoveKey (vl_hashtable *table, const void *key, vl_memsize_t keyLen) |
| Removes the element represented by the specified key. | |
| VL_API void | vlHashTableRemoveIter (vl_hashtable *table, vl_hash_iter iter) |
| Removes the hash element represented by the specified iterator. | |
| VL_API void | vlHashTableClear (vl_hashtable *table) |
| Clears the specified hash table so it can be used as if it was just created. | |
| VL_API vl_hashtable * | vlHashTableClone (const vl_hashtable *table, vl_hashtable *dest) |
| Clones the specified hashtable to another. | |
| VL_API vl_hash_iter | vlHashTableCopyElement (vl_hashtable *src, vl_hash_iter iter, vl_hashtable *dest) |
| Copies a single element of a hashtable from one table to another. | |
| VL_API int | vlHashTableCopy (vl_hashtable *src, vl_hashtable *dest) |
| Copies the entirety of one hashtable to another. | |
| VL_API void | vlHashTableReserve (vl_hashtable *table, vl_memsize_t buckets, vl_memsize_t heapSize) |
| Reserves memory in the hashtable before requiring it. | |
| VL_API vl_hash_iter | vlHashTableFind (vl_hashtable *table, const void *key, vl_memsize_t keySize) |
| Searches the hashtable for an element with the specified key. | |
| VL_API const vl_transient * | vlHashTableSampleKey (vl_hashtable *table, vl_hash_iter iter, vl_memsize_t *size) |
| Samples the key of the key-value pair indicated by the specified iterator. | |
| VL_API vl_transient * | vlHashTableSampleValue (vl_hashtable *table, vl_hash_iter iter, vl_memsize_t *size) |
| Samples the value of the key-value pair indicated by the specified iterator. | |
| VL_API vl_hash_iter | vlHashTableFront (vl_hashtable *table) |
| Returns the "first" iterator for the specified table. | |
| VL_API vl_hash_iter | vlHashTableNext (vl_hashtable *table, vl_hash_iter iter) |
| Returns the "next" iterator relative to the specified iterator. | |
| struct vl_hashtable |
A dynamically-sized hash table with variable-sized keys and values.
A generic hash table implementation that supports:
Implementation details:
Performance characteristics:
Memory considerations:
Usage notes:
Collaboration diagram for vl_hashtable:| Data Fields | ||
|---|---|---|
| vl_arena | data | |
| vl_hash_function | hashFunc | |
| vl_memory * | table | |
| vl_dsidx_t | totalElements | |
| #define VL_HASHTABLE_DEFAULT_SIZE 128 |
| #define VL_HASHTABLE_FOREACH | ( | table, | |
| trackVar | |||
| ) |
This is a convenience macro for iterating over the entirety of a hashtable.
| table | table pointer |
| trackVar | name of the variable used as the iterator. |
| #define VL_HASHTABLE_ITER_INVALID 0 |
██ ██ ██ █████ ███████ █████ ██████ ███ ██ █████ ██ ██ ██ ██ ██ ██ ██ ██ ██ ████ ██ ██ ██ ██ ██ ██ ███████ ███████ ███████ ██ ███ ██ ██ ██ ███████ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ████ ███████ ██ ██ ███████ ██ ██ ██████ ██ ████ ██ ██ ====—: A Data Structure and Algorithms library for C11. :—====
Copyright 2026 Jesse Walker, released under the MIT license. Git Repository: https://github.com/walkerje/veritable_lasagna
| #define VL_HASHTABLE_RESIZE_FACTOR 0.8 |
| typedef vl_arena_ptr vl_hash_iter |
| VL_API void vlHashTableClear | ( | vl_hashtable * | table | ) |
Clears the specified hash table so it can be used as if it was just created.
No data in the underlying virtual arena allocator is touched. Rather, book-keeping variables are reset to their initial state.
table must not be NULL.| table | pointer |
Here is the call graph for this function:
Here is the caller graph for this function:| VL_API vl_hashtable * vlHashTableClone | ( | const vl_hashtable * | table, |
| vl_hashtable * | dest | ||
| ) |
Clones the specified hashtable to another.
Clones the entirety of the src table to the dest table, including all elements and their data.
The 'src' table must be non-null and initialized. The 'dest' table may be null, but if it is not null it must be initialized.
If the 'dest' table pointer is null, a new list is created via vlHashTableNew.
dest is NULL, the caller owns the returned vl_hashtable. If dest is provided, ownership remains with the caller.src must not be NULL. dest can be NULL.NULL on allocation failure.NULL on failure.| src | pointer |
| dest | pointer |
Here is the call graph for this function:
Here is the caller graph for this function:| VL_API int vlHashTableCopy | ( | vl_hashtable * | src, |
| vl_hashtable * | dest | ||
| ) |
Copies the entirety of one hashtable to another.
Both tables must have the same hash function, otherwise this is a no-op. If any elements with matching keys exist between the two maps, they are overwritten by the contents of the element in the source table.
dest maintains copies of all keys and data.src and dest must not be NULL.| src | pointer |
| dest | pointer |
Here is the call graph for this function:| VL_API vl_hash_iter vlHashTableCopyElement | ( | vl_hashtable * | src, |
| vl_hash_iter | iter, | ||
| vl_hashtable * | dest | ||
| ) |
Copies a single element of a hashtable from one table to another.
Both tables must have the same hash function, otherwise this is a no-op and will return VL_HASHTABLE_ITER_INVALID.
If an element by the key specified by the iterator already exists in the dest table, its element data is overwritten by the contents of the element in the source table.
dest maintains copies of the key and data.src and dest must not be NULL.VL_HASHTABLE_ITER_INVALID if hash functions don't match or if insertion fails.vl_hash_iter of the element in the destination table, or VL_HASHTABLE_ITER_INVALID on failure.| src | pointer |
| iter | element to copy |
| dest | pointer |
Here is the call graph for this function:| VL_API void vlHashTableDelete | ( | vl_hashtable * | table | ) |
De-initializes and deletes the specified table and its resources.
vl_hashtable struct.table is NULL.| table | pointer |
Here is the call graph for this function:| VL_API vl_hash_iter vlHashTableFind | ( | vl_hashtable * | table, |
| const void * | key, | ||
| vl_memsize_t | keySize | ||
| ) |
Searches the hashtable for an element with the specified key.
table must not be NULL. key must not be NULL.VL_HASHTABLE_ITER_INVALID if the key is not found.vl_hash_iter to the found element, or VL_HASHTABLE_ITER_INVALID if not found.| table | pointer |
| key | |
| keySize |
Here is the call graph for this function:
Here is the caller graph for this function:| VL_API void vlHashTableFree | ( | vl_hashtable * | table | ) |
De-initializes and frees the internal resources of the specified table.
table struct itself.table must not be NULL.vlMemFree.| table | pointer |
Here is the call graph for this function:
Here is the caller graph for this function:| VL_API vl_hash_iter vlHashTableFront | ( | vl_hashtable * | table | ) |
Returns the "first" iterator for the specified table.
VL_HASHTABLE_ITER_INVALID if the table is empty.vl_hash_iter to some "first" element in the table.| table | pointer |
Here is the call graph for this function:| VL_API void vlHashTableInit | ( | vl_hashtable * | table, |
| vl_hash_function | hashFunc | ||
| ) |
Initializes the specified table with a hash function.
table struct. The function initializes the internal arena and bucket table.vlHashTableFree or vlHashTableDelete.table must not be NULL. hashFunc must not be NULL.vlHashTableFree (causes memory leak).| table | pointer |
| hashFunc | hash function pointer |
Here is the call graph for this function:
Here is the caller graph for this function:| VL_API vl_hash_iter vlHashTableInsert | ( | vl_hashtable * | table, |
| const void * | key, | ||
| vl_memsize_t | keySize, | ||
| vl_memsize_t | dataSize | ||
| ) |
Claims a chunk of memory associated with the specified key. If the key already exists, the associated chunk is reallocated to match the specified size.
key and dataSize is the amount of memory reserved for the caller to own within the table.table must not be NULL. key must not be NULL.VL_HASHTABLE_ITER_INVALID if node allocation or expansion fails.vl_hash_iter handle to the element, or VL_HASHTABLE_ITER_INVALID on failure.| table | pointer |
| key | pointer to key data |
| keySize | size of key data, in bytes |
| dataSize | size of element data, in bytes |
Here is the call graph for this function:
Here is the caller graph for this function:| VL_API vl_hashtable * vlHashTableNew | ( | vl_hash_function | func | ) |
Allocates on the heap, initializes, and returns a new hash table instance.
vl_hashtable pointer and is responsible for calling vlHashTableDelete.vlHashTableDelete.NULL if heap allocation for the table struct fails.NULL on allocation failure.vl_hashtable struct and its internal resources.NULL.| func |
Here is the call graph for this function:
Here is the caller graph for this function:| VL_API vl_hash_iter vlHashTableNext | ( | vl_hashtable * | table, |
| vl_hash_iter | iter | ||
| ) |
Returns the "next" iterator relative to the specified iterator.
vlHashTableFront.vlHashTableFront.VL_HASHTABLE_ITER_INVALID if no more elements exist.vl_hash_iter in the sequence.| table | pointer |
| iter |
Here is the call graph for this function:| VL_API void vlHashTableRemoveIter | ( | vl_hashtable * | table, |
| vl_hash_iter | iter | ||
| ) |
Removes the hash element represented by the specified iterator.
table must not be NULL. iter should not be VL_HASHTABLE_ITER_INVALID.| table | pointer |
| iter |
Here is the call graph for this function:
Here is the caller graph for this function:| VL_API void vlHashTableRemoveKey | ( | vl_hashtable * | table, |
| const void * | key, | ||
| vl_memsize_t | keyLen | ||
| ) |
Removes the element represented by the specified key.
table must not be NULL. key must not be NULL.| table | pointer |
| key | pointer to key data |
| keyLen | length of key data, in bytes. |
Here is the call graph for this function:| VL_API void vlHashTableReserve | ( | vl_hashtable * | table, |
| vl_memsize_t | buckets, | ||
| vl_memsize_t | heapSize | ||
| ) |
Reserves memory in the hashtable before requiring it.
This function will reserve memory for buckets, element, and key data.
This is used to avoid resizing the underlying virtual heap and bucket allocations. Resizing is a costly operation which can noticeably harm the efficiency of the table if done frequently.
table must not be NULL.| table | pointer |
| buckets | total buckets to reserve (spots in the table) |
| heapSize | total bytes to reserve for element and key data |
Here is the call graph for this function:| VL_API const vl_transient * vlHashTableSampleKey | ( | vl_hashtable * | table, |
| vl_hash_iter | iter, | ||
| vl_memsize_t * | size | ||
| ) |
Samples the key of the key-value pair indicated by the specified iterator.
NULL if iter is VL_HASHTABLE_ITER_INVALID.| table | pointer |
| iter | |
| size | output pointer representing size of the key, in bytes. may be null. |
Here is the call graph for this function:
Here is the caller graph for this function:| VL_API vl_transient * vlHashTableSampleValue | ( | vl_hashtable * | table, |
| vl_hash_iter | iter, | ||
| vl_memsize_t * | size | ||
| ) |
Samples the value of the key-value pair indicated by the specified iterator.
NULL if iter is VL_HASHTABLE_ITER_INVALID.| table | pointer |
| iter | |
| size | output pointer representing the size of the value, in bytes. may be null. |
Here is the call graph for this function:
Here is the caller graph for this function: