28#ifndef LIBDICT_DICT_H__
29#define LIBDICT_DICT_H__
38#if defined(__cplusplus) || defined(c_plusplus)
39# define BEGIN_DECL extern "C" {
48#define DICT_VERSION_MAJOR 0
49#define DICT_VERSION_MINOR 3
50#define DICT_VERSION_PATCH 0
73extern void* (*dict_malloc_func)(size_t);
95typedef void** (*dict_search_func)(
void* obj,
const void* key);
137typedef void* (*dict_key_func)(
void* itor);
138typedef void** (*dict_datum_func)(
void* itor);
169#define dict_private(dct) ((dct)->_object)
170#define dict_insert(dct,key) ((dct)->_vtable->insert((dct)->_object, (key)))
173#define dict_search(dct,key) ((dct)->_vtable->search((dct)->_object, (key)))
174#define dict_is_sorted(dct) ((dct)->_vtable->sorted)
180#define dict_search_le(dct,key) ((dct)->_vtable->search_le ? (dct)->_vtable->search_le((dct)->_object, (key)) : NULL)
181#define dict_search_lt(dct,key) ((dct)->_vtable->search_lt ? (dct)->_vtable->search_lt((dct)->_object, (key)) : NULL)
182#define dict_search_ge(dct,key) ((dct)->_vtable->search_ge ? (dct)->_vtable->search_ge((dct)->_object, (key)) : NULL)
183#define dict_search_gt(dct,key) ((dct)->_vtable->search_gt ? (dct)->_vtable->search_gt((dct)->_object, (key)) : NULL)
184#define dict_remove(dct,key) ((dct)->_vtable->remove((dct)->_object, (key)))
185#define dict_clear(dct,func) ((dct)->_vtable->clear((dct)->_object, (func)))
186#define dict_traverse(dct,func,ud) ((dct)->_vtable->traverse((dct)->_object, (func), (ud)))
192#define dict_select(dct,n,key,d) ((dct)->_vtable->select && (dct)->_vtable->select((dct)->_object, (n), (key), (d)))
193#define dict_count(dct) ((dct)->_vtable->count((dct)->_object))
197#define dict_verify(dct) ((dct)->_vtable->verify((dct)->_object))
198#define dict_itor_new(dct) (dct)->_vtable->inew((dct)->_object)
239#define dict_itor_private(i) ((i)->_itor)
240#define dict_itor_valid(i) ((i)->_vtable->valid((i)->_itor))
241#define dict_itor_invalidate(i) ((i)->_vtable->invalid((i)->_itor))
242#define dict_itor_next(i) ((i)->_vtable->next((i)->_itor))
243#define dict_itor_prev(i) ((i)->_vtable->prev((i)->_itor))
244#define dict_itor_nextn(i,n) ((i)->_vtable->nextn((i)->_itor, (n)))
245#define dict_itor_prevn(i,n) ((i)->_vtable->prevn((i)->_itor, (n)))
246#define dict_itor_first(i) ((i)->_vtable->first((i)->_itor))
247#define dict_itor_last(i) ((i)->_vtable->last((i)->_itor))
253#define dict_itor_search(i,k) ((i)->_vtable->search((i)->_itor, (k)))
254#define dict_itor_search_le(i,k) ((i)->_vtable->search_le && (i)->_vtable->search_le((i)->_itor, (k)))
255#define dict_itor_search_lt(i,k) ((i)->_vtable->search_lt && (i)->_vtable->search_lt((i)->_itor, (k)))
256#define dict_itor_search_ge(i,k) ((i)->_vtable->search_ge && (i)->_vtable->search_ge((i)->_itor, (k)))
257#define dict_itor_search_gt(i,k) ((i)->_vtable->search_gt && (i)->_vtable->search_gt((i)->_itor, (k)))
258#define dict_itor_key(i) ((i)->_vtable->key((i)->_itor))
259#define dict_itor_datum(i) ((i)->_vtable->datum((i)->_itor))
263#define dict_itor_compare(i1,i2) ((i1)->_vtable->compare ? (i1)->_vtable->compare((i1)->_itor, (i2)->_itor) : 0)
264#define dict_itor_remove(i) ((i)->_vtable->remove && (i)->_vtable->remove((i)->_itor))
dict_remove_result(* dict_remove_func)(void *obj, const void *key)
int(* dict_compare_func)(const void *, const void *)
A pointer to a function that compares two keys.
bool(* dict_select_func)(void *obj, size_t n, const void **key, void **datum)
int dict_ptr_cmp(const void *k1, const void *k2)
void(* dict_invalidate_func)(void *itor)
unsigned dict_str_hash(const void *str)
FNV-1a hash of a NUL-terminated string, over its bytes in order, so a key hashes to the same value on...
size_t(* dict_traverse_func)(void *obj, dict_visit_func visit, void *user_data)
int dict_ulong_cmp(const void *k1, const void *k2)
size_t dict_free(dict *dct, dict_delete_func delete_func)
dict_insert_result(* dict_insert_func)(void *obj, void *key)
void(* dict_delete_func)(void *, void *)
A pointer to a function that is called when a key-value pair gets removed from a dictionary.
int dict_uint_cmp(const void *k1, const void *k2)
int(* dict_icompare_func)(void *itor1, void *itor2)
bool(* dict_nextn_func)(void *itor, size_t count)
bool(* dict_valid_func)(const void *itor)
size_t(* dict_count_func)(const void *obj)
bool(* dict_first_func)(void *itor)
int dict_str_cmp(const void *k1, const void *k2)
bool(* dict_next_func)(void *itor)
void *(* dict_key_func)(void *itor)
unsigned(* dict_hash_func)(const void *)
A pointer to a function that returns the hash value of a key.
size_t(* dict_dfree_func)(void *obj, dict_delete_func delete_func)
void **(* dict_datum_func)(void *itor)
bool(* dict_prevn_func)(void *itor, size_t count)
void **(* dict_search_func)(void *obj, const void *key)
bool(* dict_isearch_func)(void *itor, const void *key)
unsigned(* dict_prio_func)(const void *)
A pointer to a function that returns the priority of a key, used by tr_tree (a treap).
bool(* dict_iremove_func)(void *itor)
bool(* dict_prev_func)(void *itor)
void dict_itor_free(dict_itor *itor)
dict_itor *(* dict_inew_func)(void *obj)
bool(* dict_last_func)(void *itor)
int dict_long_cmp(const void *k1, const void *k2)
bool(* dict_verify_func)(const void *obj)
bool(* dict_visit_func)(const void *, void *, void *)
A pointer to a function used for iterating over dictionary contents.
const char *const kDictVersionString
size_t(* dict_clear_func)(void *obj, dict_delete_func delete_func)
void(* dict_ifree_func)(void *itor)
void(* dict_free_func)(void *)
A pointer to a function that libdict will use to deallocate memory.
int dict_int_cmp(const void *k1, const void *k2)
Comparison functions for common key types, for use as dict_compare_func.
Hash table with open addressing and linear probing.
Hash table with separate chaining; each chain is kept sorted by hash value.
Height-balanced (AVL) tree.
Path-reduction tree [Gonnet 1983].
const itor_vtable * _vtable
The operations of one container type.
dict_search_func search_le
dict_traverse_func traverse
dict_search_func search_gt
dict_search_func search_lt
dict_search_func search_ge
const dict_vtable * _vtable
dict_isearch_func search_lt
dict_isearch_func search_ge
dict_icompare_func compare
dict_isearch_func search_le
dict_isearch_func search_gt
dict_invalidate_func invalid
Treap: a binary search tree on the keys that is at the same time a max-heap on per-node priorities.
Weight-balanced tree, BB[alpha] with alpha = 1 - sqrt(2)/2.