28#ifndef LIBDICT_HASHTABLE2_H__
29#define LIBDICT_HASHTABLE2_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.
bool hashtable2_verify(const hashtable2 *table)
Check the internal invariants of the table and return true if they hold, or print the first failed ch...
hashtable2_itor * hashtable2_itor_new(hashtable2 *table)
Create an iterator over |table| that is not positioned on any element yet.
dict_itor * hashtable2_dict_itor_new(hashtable2 *table)
Like hashtable2_itor_new(), but wrapped in a generic dict_itor for use with the dict_itor_* macros.
void ** hashtable2_search(hashtable2 *table, const void *key)
Return the address of the datum stored for |key|, or NULL if |key| is not present.
bool hashtable2_itor_nextn(hashtable2_itor *itor, size_t count)
Move |itor| |count| elements forward and return whether it is still positioned.
size_t hashtable2_free(hashtable2 *table, dict_delete_func delete_func)
Remove every element, calling |delete_func|(key, datum) for each unless |delete_func| is NULL,...
bool hashtable2_itor_valid(const hashtable2_itor *itor)
Return whether |itor| is positioned on an element.
bool hashtable2_itor_prev(hashtable2_itor *itor)
Move |itor| to the previous element in table order (unspecified) and return true, or unposition it an...
void ** hashtable2_itor_datum(hashtable2_itor *itor)
Return the address of the datum |itor| is positioned on, through which it can be read or replaced,...
bool hashtable2_itor_remove(hashtable2_itor *itor)
Remove the element |itor| is positioned on and unposition |itor|; return false if it was not position...
size_t hashtable2_clear(hashtable2 *table, dict_delete_func delete_func)
Remove every element, calling |delete_func|(key, datum) for each unless |delete_func| is NULL.
dict_insert_result hashtable2_insert(hashtable2 *table, void *key)
Insert |key| unless an equal key is present.
void hashtable2_itor_invalidate(hashtable2_itor *itor)
Unposition |itor|, so that it is not positioned on any element.
hashtable2 * hashtable2_new(dict_compare_func cmp_func, dict_hash_func hash_func, unsigned initial_size)
Create an empty hash table that compares keys with |cmp_func| and hashes them with |hash_func| (neith...
size_t hashtable2_count(const hashtable2 *table)
Return the number of elements.
size_t hashtable2_slots_used(const hashtable2 *table)
Return the number of occupied slots, which for open addressing equals the number of elements.
size_t hashtable2_size(const hashtable2 *table)
Return the current number of slots in the table.
void hashtable2_itor_free(hashtable2_itor *itor)
Free an iterator.
bool hashtable2_itor_prevn(hashtable2_itor *itor, size_t count)
Move |itor| |count| elements back and return whether it is still positioned.
bool hashtable2_itor_first(hashtable2_itor *itor)
Position |itor| on the first element in table order (unspecified) and return true,...
const void * hashtable2_itor_key(const hashtable2_itor *itor)
Return the key |itor| is positioned on, or NULL if it is not positioned.
bool hashtable2_resize(hashtable2 *table, unsigned size)
Rehash the table into at least |size| slots, rounded up as in hashtable2_new().
bool hashtable2_itor_next(hashtable2_itor *itor)
Move |itor| to the next element in table order (unspecified) and return true, or unposition it and re...
dict_remove_result hashtable2_remove(hashtable2 *table, const void *key)
Remove the element with key |key|.
size_t hashtable2_traverse(hashtable2 *table, dict_visit_func visit, void *user_data)
Call |visit|(key, datum, |user_data|) for each element in table order (unspecified),...
bool hashtable2_itor_search(hashtable2_itor *itor, const void *key)
Position |itor| on |key| and return true, or unposition it and return false if |key| is not present.
bool hashtable2_itor_last(hashtable2_itor *itor)
Position |itor| on the last element in table order (unspecified) and return true, or unposition it an...
dict * hashtable2_dict_new(dict_compare_func cmp_func, dict_hash_func hash_func, unsigned initial_size)
Like hashtable2_new(), but wrapped in a generic dict for use with the dict_* macros.
dict_compare_func cmp_func