Enumerations | |
enum | hash_type_t { HASH_INTPTR, HASH_STRING, HASH_STRING_NOCASE, HASH_CUSTOM } |
Functions | |
bool | stri_eq (const char *s1, const char *s2) |
void | hashtable_global_config (void *(*alloc_func)(size_t), void(*free_func)(void *, size_t), void(*assert_fail_func)(const char *)) |
void | hashtable_init (hashtable_t *table, uint num_bits, hash_type_t hashtype, bool str_dup) |
void | hashtable_init_ex (hashtable_t *table, uint num_bits, hash_type_t hashtype, bool str_dup, bool synch, void(*free_payload_func)(void *), uint(*hash_key_func)(void *), bool(*cmp_key_func)(void *, void *)) |
void * | hashtable_lookup (hashtable_t *table, void *key) |
void * | hashtable_lookup_keep_locked (hashtable_t *table, void *key) |
bool | hashtable_add (hashtable_t *table, void *key, void *payload) |
void * | hashtable_add_replace (hashtable_t *table, void *key, void *payload) |
bool | hashtable_remove (hashtable_t *table, void *key) |
void | hashtable_delete (hashtable_t *table) |
void | hashtable_lock (hashtable_t *table) |
void | hashtable_unlock (hashtable_t *table) |
enum hash_type_t |
bool hashtable_add | ( | hashtable_t * | table, | |
void * | key, | |||
void * | payload | |||
) |
Adds a new entry. Returns false if an entry for key
already exists.
void* hashtable_add_replace | ( | hashtable_t * | table, | |
void * | key, | |||
void * | payload | |||
) |
Adds a new entry, replacing an existing entry if any.
void hashtable_delete | ( | hashtable_t * | table | ) |
Destroys all storage for the table. If free_payload_func was specified calls it for each payload.
void hashtable_global_config | ( | void *(*)(size_t) | alloc_func, | |
void(*)(void *, size_t) | free_func, | |||
void(*)(const char *) | assert_fail_func | |||
) |
The hashtable has parametrized heap and assert routines for flexibility. This routine must be called BEFORE any other hashtable_ routine; else, the defaults will be used.
void hashtable_init | ( | hashtable_t * | table, | |
uint | num_bits, | |||
hash_type_t | hashtype, | |||
bool | str_dup | |||
) |
Initializes a hashtable with the given size, hash type, and whether to duplicate string keys. All operations are synchronized by default.
void hashtable_init_ex | ( | hashtable_t * | table, | |
uint | num_bits, | |||
hash_type_t | hashtype, | |||
bool | str_dup, | |||
bool | synch, | |||
void(*)(void *) | free_payload_func, | |||
uint(*)(void *) | hash_key_func, | |||
bool(*)(void *, void *) | cmp_key_func | |||
) |
Initializes a hashtable with the given size, hash type, whether to duplicate string keys, whether to synchronize each operation, a callback for freeing each payload, a callback for hashing a key, and a callback for comparing two keys. Even when synch
is false, the hashtable's lock is initialized and can be used via hashtable_lock and hashtable_unlock, allowing the caller to extend synchronization beyond just the operation in question, to include accessing a looked-up payload, e.g.
void hashtable_lock | ( | hashtable_t * | table | ) |
Acquires the hashtable lock.
void* hashtable_lookup | ( | hashtable_t * | table, | |
void * | key | |||
) |
Returns the payload for the given key, or NULL if the key is not found
void* hashtable_lookup_keep_locked | ( | hashtable_t * | table, | |
void * | key | |||
) |
Like hashtable_lookup but does not unlock the hashtable lock
bool hashtable_remove | ( | hashtable_t * | table, | |
void * | key | |||
) |
Removes the entry for key. If free_payload_func was specified calls it for the payload being removed. Returns false if no such entry exists.
void hashtable_unlock | ( | hashtable_t * | table | ) |
Releases the hashtable lock.
bool stri_eq | ( | const char * | s1, | |
const char * | s2 | |||
) |
Caseless string compare