Methods for hash table creation, insertion, deletion, and lookup.
More...
|
sys_hashtable_t * | sys_hashtable_init (size_t size, sys_hashtable_keyequals_t keyequals) |
| Initialize a new hash table. More...
|
|
void | sys_hashtable_finalize (sys_hashtable_t *table) |
| Free all the hash tables in the chain. More...
|
|
sys_hashtable_entry_t * | sys_hashtable_get_key (sys_hashtable_t *table, uintptr_t hash, void *keyptr) |
| Search for an entry in the hash table by hash key. More...
|
|
sys_hashtable_entry_t * | sys_hashtable_get_value (sys_hashtable_t *table, uintptr_t value) |
| Search for an entry in the hash table by hash value. More...
|
|
sys_hashtable_entry_t * | sys_hashtable_put (sys_hashtable_t *table, uintptr_t hash, void *keyptr, bool *samekey) |
| Return a has table entry in which to put the value, and perhaps the key. More...
|
|
sys_hashtable_entry_t * | sys_hashtable_delete_key (sys_hashtable_t *table, uintptr_t hash, void *keyptr) |
| Delete an entry into the hash table by key. More...
|
|
sys_hashtable_entry_t * | sys_hashtable_delete_value (sys_hashtable_t *table, uintptr_t value) |
| Delete an entry from the hash table by value. More...
|
|
sys_hashtable_entry_t * | sys_hashtable_iterator_next (sys_hashtable_t *table, sys_hashtable_iterator_t **iterator) |
| Get the next entry from the iterator. More...
|
|
size_t | sys_hashtable_count (sys_hashtable_t *table) |
| Get the number of active entries in the hash table chain. More...
|
|
size_t | sys_hashtable_capacity (sys_hashtable_t *table) |
| Get the total capacity of all tables in the chain. More...
|
|
Methods for hash table creation, insertion, deletion, and lookup.
This file declares types and functions for creating and managing hash tables. Hash tables are a data structure that implements an associative array abstract data type, a structure that can map keys to values.
◆ sys_hashtable_iterator_t
Iterator state for hash table traversal.
This structure is used to maintain the state of an iterator while traversing a hash table. To initialize an iterator, set the table
field to NULL.
◆ sys_hashtable_keyequals_t
typedef bool(* sys_hashtable_keyequals_t) (void *keyptr, void *other_keyptr) |
Compare entry with a key.
This callback function is used to compare a key with another key from the hash table. It should return true if the keys match, false otherwise.
Definition at line 67 of file hashtable.h.
◆ sys_hashtable_t
Opaque type for hash table.
This type represents a hash table that can store key-value pairs.
Definition at line 24 of file hashtable.h.
◆ sys_hashtable_capacity()
Get the total capacity of all tables in the chain.
- Parameters
-
table | The hash table to get capacity for |
- Returns
- The total capacity (size) of all tables in the chain
◆ sys_hashtable_count()
Get the number of active entries in the hash table chain.
- Parameters
-
table | The hash table to count entries in |
- Returns
- The total number of active (non-deleted) entries across all tables in the chain
◆ sys_hashtable_delete_key()
Delete an entry into the hash table by key.
- Parameters
-
table | The hash table to delete from |
hash | The hash key for the entry |
keyptr | Pointer to the key data for comparison |
- Returns
- Pointer to the deleted entry, or NULL if not found
◆ sys_hashtable_delete_value()
Delete an entry from the hash table by value.
- Parameters
-
table | The hash table to delete from |
value | The value to delete |
- Returns
- The deleted entry, or NULL if not found
◆ sys_hashtable_finalize()
Free all the hash tables in the chain.
- Parameters
-
table | First hash table in the chain to free |
◆ sys_hashtable_get_key()
Search for an entry in the hash table by hash key.
- Parameters
-
table | The hash table to search in |
hash | The hash key for the entry |
keyptr | Pointer to the key data for comparison |
- Returns
- Pointer to the found entry, or NULL if not found
◆ sys_hashtable_get_value()
Search for an entry in the hash table by hash value.
- Parameters
-
table | The hash table to search in |
value | The value to search for |
- Returns
- Pointer to the found entry, or NULL if not found
◆ sys_hashtable_init()
Initialize a new hash table.
- Parameters
-
size | Number of entries in the hash table (must be > 0) |
keyequals | Function to compare a key pointer to an entry for equality |
- Returns
- Pointer to new hash table, or NULL if allocation failed
◆ sys_hashtable_iterator_next()
Get the next entry from the iterator.
- Parameters
-
table | The hash table being iterated |
iterator | Pointer to the iterator state (will be updated) |
- Returns
- Pointer to the next entry, or NULL if no more entries
◆ sys_hashtable_put()
Return a has table entry in which to put the value, and perhaps the key.
- Parameters
-
table | The hash table to insert into |
hash | The hash key for the entry |
keyptr | Pointer to the key data |
samekey | Optional pointer to a boolean, indicating if the entry has the same key |
- Returns
- Pointer to an entry, or NULL if allocation failed
The entry returned by this function can be used to insert or update a value in the hash table. If an entry with the same hash and key already exists, the value should be replaced.