|
| vl_memsize_t | vl_HashTableGrow (vl_hashtable *table) |
| |
| void | vlHashTableInit (vl_hashtable *table, vl_hash_function hashFunc) |
| | Initializes the specified table with a hash function.
|
| |
| void | vlHashTableFree (vl_hashtable *table) |
| | De-initializes and frees the internal resources of the specified table.
|
| |
| vl_hashtable * | vlHashTableNew (vl_hash_function func) |
| | Allocates on the heap, initializes, and returns a new hash table instance.
|
| |
| void | vlHashTableDelete (vl_hashtable *table) |
| | De-initializes and deletes the specified table and its resources.
|
| |
| 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_hash_iter | vlHashTableFind (vl_hashtable *table, const void *key, vl_memsize_t keySize) |
| | Searches the hashtable for an element with the specified key.
|
| |
| void | vlHashTableRemoveKey (vl_hashtable *table, const void *key, vl_memsize_t keyLen) |
| | Removes the element represented by the specified key.
|
| |
| void | vlHashTableRemoveIter (vl_hashtable *table, vl_hash_iter iter) |
| | Removes the hash element represented by the specified iterator.
|
| |
| void | vlHashTableClear (vl_hashtable *table) |
| | Clears the specified hash table so it can be used as if it was just created.
|
| |
| vl_hashtable * | vlHashTableClone (const vl_hashtable *src, vl_hashtable *dest) |
| | Clones the specified hashtable to another.
|
| |
| 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.
|
| |
| int | vlHashTableCopy (vl_hashtable *src, vl_hashtable *dest) |
| | Copies the entirety of one hashtable to another.
|
| |
| void | vlHashTableReserve (vl_hashtable *table, vl_memsize_t buckets, vl_memsize_t heapSize) |
| | Reserves memory in the hashtable before requiring it.
|
| |
| const vl_transient * | vlHashTableSampleKey (vl_hashtable *table, vl_hash_iter iter, vl_memsize_t *outSize) |
| | Samples the key of the key-value pair indicated by the specified iterator.
|
| |
| vl_transient * | vlHashTableSampleValue (vl_hashtable *table, vl_hash_iter iter, vl_memsize_t *outSize) |
| | Samples the value of the key-value pair indicated by the specified iterator.
|
| |
| vl_hash_iter | vlHashTableFront (vl_hashtable *table) |
| | Returns the "first" iterator for the specified table.
|
| |
| vl_hash_iter | vlHashTableNext (vl_hashtable *table, vl_hash_iter iter) |
| | Returns the "next" iterator relative to the specified iterator.
|
| |
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.
Contract
- Ownership: If
dest is NULL, the caller owns the returned vl_hashtable. If dest is provided, ownership remains with the caller.
- Lifetime: The cloned table remains valid until deleted or freed.
- Thread Safety: Not thread-safe.
- Nullability:
src must not be NULL. dest can be NULL.
- Error Conditions: Returns
NULL on allocation failure.
- Undefined Behavior: Passing an uninitialized table.
- Memory Allocation Expectations: May allocate a new table struct and expansion of its internal resources.
- Return-value Semantics: Returns the pointer to the cloned table, or
NULL on failure.
- See also
- vlHashTableNew
- Parameters
-
- Returns
- pointer to table that was copied to or created.
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.
Contract
- Ownership:
dest maintains copies of the key and data.
- Lifetime: Unchanged.
- Thread Safety: Not thread-safe.
- Nullability:
src and dest must not be NULL.
- Error Conditions: Returns
VL_HASHTABLE_ITER_INVALID if hash functions don't match or if insertion fails.
- Undefined Behavior: Passing an invalid iterator.
- Memory Allocation Expectations: May trigger expansion of the destination table and its arena.
- Return-value Semantics: Returns the
vl_hash_iter of the element in the destination table, or VL_HASHTABLE_ITER_INVALID on failure.
- Parameters
-
| src | pointer |
| iter | element to copy |
| dest | pointer |
- Returns
- iterator to element inserted into dest table, or VL_HASHTABLE_ITER_INVALID.
| 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.
Contract
- Ownership: Unchanged.
- Lifetime: Unchanged.
- Thread Safety: Not thread-safe.
- Nullability:
table must not be NULL.
- Error Conditions: Allocation failure during reservation.
- Undefined Behavior: Passing an uninitialized table.
- Memory Allocation Expectations: Triggers reallocation of the bucket array and the internal data arena.
- Return-value Semantics: None (void).
- Parameters
-
| table | pointer |
| buckets | total buckets to reserve (spots in the table) |
| heapSize | total bytes to reserve for element and key data |
- Complexity of O(1) constant.