28#ifndef LIBDICT_HASHTABLE_H__
29#define LIBDICT_HASHTABLE_H__
int(* dict_compare_func)(const void *, const void *)
A pointer to a function that compares two keys.
void(* dict_delete_func)(void *, void *)
A pointer to a function that is called when a key-value pair gets removed from a dictionary.
unsigned(* dict_hash_func)(const void *)
A pointer to a function that returns the hash value of a key.
bool(* dict_visit_func)(const void *, void *, void *)
A pointer to a function used for iterating over dictionary contents.
size_t hashtable_free(hashtable *table, dict_delete_func delete_func)
Remove every element, calling |delete_func|(key, datum) for each unless |delete_func| is NULL,...
bool hashtable_resize(hashtable *table, unsigned size)
Rehash the table into at least |size| slots, rounded up as in hashtable_new().
bool hashtable_itor_search(hashtable_itor *itor, const void *key)
Position |itor| on |key| and return true, or unposition it and return false if |key| is not present.
dict_remove_result hashtable_remove(hashtable *table, const void *key)
Remove the element with key |key|.
dict_itor * hashtable_dict_itor_new(hashtable *table)
Like hashtable_itor_new(), but wrapped in a generic dict_itor for use with the dict_itor_* macros.
hashtable_itor * hashtable_itor_new(hashtable *table)
Create an iterator over |table| that is not positioned on any element yet.
bool hashtable_verify(const hashtable *table)
Check the internal invariants of the table and return true if they hold, or print the first failed ch...
bool hashtable_itor_last(hashtable_itor *itor)
Position |itor| on the last element in table order (unspecified) and return true, or unposition it an...
bool hashtable_itor_next(hashtable_itor *itor)
Move |itor| to the next element in table order (unspecified) and return true, or unposition it and re...
bool hashtable_itor_first(hashtable_itor *itor)
Position |itor| on the first element in table order (unspecified) and return true,...
size_t hashtable_count(const hashtable *table)
Return the number of elements.
bool hashtable_itor_prevn(hashtable_itor *itor, size_t count)
Move |itor| |count| elements back and return whether it is still positioned.
dict_insert_result hashtable_insert(hashtable *table, void *key)
Insert |key| unless an equal key is present.
void ** hashtable_itor_datum(hashtable_itor *itor)
Return the address of the datum |itor| is positioned on, through which it can be read or replaced,...
bool hashtable_itor_remove(hashtable_itor *itor)
Remove the element |itor| is positioned on and unposition |itor|; return false if it was not position...
void hashtable_itor_free(hashtable_itor *itor)
Free an iterator.
bool hashtable_itor_nextn(hashtable_itor *itor, size_t count)
Move |itor| |count| elements forward and return whether it is still positioned.
size_t hashtable_clear(hashtable *table, dict_delete_func delete_func)
Remove every element, calling |delete_func|(key, datum) for each unless |delete_func| is NULL.
bool hashtable_itor_prev(hashtable_itor *itor)
Move |itor| to the previous element in table order (unspecified) and return true, or unposition it an...
void hashtable_itor_invalidate(hashtable_itor *itor)
Unposition |itor|, so that it is not positioned on any element.
size_t hashtable_traverse(hashtable *table, dict_visit_func visit, void *user_data)
Call |visit|(key, datum, |user_data|) for each element in table order (unspecified),...
dict * hashtable_dict_new(dict_compare_func cmp_func, dict_hash_func hash_func, unsigned size)
Like hashtable_new(), but wrapped in a generic dict for use with the dict_* macros.
bool hashtable_itor_valid(const hashtable_itor *itor)
Return whether |itor| is positioned on an element.
void ** hashtable_search(hashtable *table, const void *key)
Return the address of the datum stored for |key|, or NULL if |key| is not present.
size_t hashtable_size(const hashtable *table)
Return the current number of slots in the table.
size_t hashtable_slots_used(const hashtable *table)
Return the number of slots whose chain is not empty.
const void * hashtable_itor_key(const hashtable_itor *itor)
Return the key |itor| is positioned on, or NULL if it is not positioned.
hashtable * hashtable_new(dict_compare_func cmp_func, dict_hash_func hash_func, unsigned size)
Create an empty hash table that compares keys with |cmp_func| and hashes them with |hash_func| (neith...
dict_compare_func cmp_func