Hash Array Mapped Trie (HAMT) functions.
More...
Go to the source code of this file.
|
YASM_LIB_DECL HAMT * | HAMT_create (int nocase, void(*error_func)(const char *file, unsigned int line, const char *message)) |
| Create new, empty, HAMT. More...
|
|
YASM_LIB_DECL void | HAMT_destroy (HAMT *hamt, void(*deletefunc)(void *data)) |
| Delete HAMT and all data associated with it. More...
|
|
YASM_LIB_DECL void * | HAMT_insert (HAMT *hamt, const char *str, void *data, int *replace, void(*deletefunc)(void *data)) |
| Insert key into HAMT, associating it with data. More...
|
|
YASM_LIB_DECL void * | HAMT_search (HAMT *hamt, const char *str) |
| Search for the data associated with a key in the HAMT. More...
|
|
YASM_LIB_DECL int | HAMT_traverse (HAMT *hamt, void *d, int(*func)(void *node, void *d)) |
| Traverse over all keys in HAMT, calling function on each data item. More...
|
|
YASM_LIB_DECL const HAMTEntry * | HAMT_first (const HAMT *hamt) |
| Get the first entry in a HAMT. More...
|
|
YASM_LIB_DECL const HAMTEntry * | HAMT_next (const HAMTEntry *prev) |
| Get the next entry in a HAMT. More...
|
|
YASM_LIB_DECL void * | HAMTEntry_get_data (const HAMTEntry *entry) |
| Get the corresponding data for a HAMT entry. More...
|
|
Hash Array Mapped Trie (HAMT) functions.
Definition in file hamt.h.
Hash array mapped trie data structure (opaque type).
Definition at line 38 of file hamt.h.
Hash array mapped trie entry (opaque type).
Definition at line 40 of file hamt.h.
YASM_LIB_DECL HAMT* HAMT_create |
( |
int |
nocase, |
|
|
void(*)(const char *file, unsigned int line, const char *message) |
error_func |
|
) |
| |
Create new, empty, HAMT.
error_func() is called when an internal error is encountered–it should NOT return to the calling function.
- Parameters
-
nocase | nonzero if HAMT should be case-insensitive |
error_func | function called on internal error |
- Returns
- New, empty, hash array mapped trie.
YASM_LIB_DECL void HAMT_destroy |
( |
HAMT * |
hamt, |
|
|
void(*)(void *data) |
deletefunc |
|
) |
| |
Delete HAMT and all data associated with it.
Uses deletefunc() to delete each data item.
- Parameters
-
hamt | Hash array mapped trie |
deletefunc | Data deletion function |
Get the first entry in a HAMT.
- Parameters
-
hamt | Hash array mapped trie |
- Returns
- First entry in HAMT, or NULL if HAMT is empty.
YASM_LIB_DECL void* HAMT_insert |
( |
HAMT * |
hamt, |
|
|
const char * |
str, |
|
|
void * |
data, |
|
|
int * |
replace, |
|
|
void(*)(void *data) |
deletefunc |
|
) |
| |
Insert key into HAMT, associating it with data.
If the key is not present in the HAMT, inserts it, sets *replace to 1, and returns the data passed in. If the key is already present and *replace is 0, deletes the data passed in using deletefunc() and returns the data currently associated with the key. If the key is already present and *replace is 1, deletes the data currently associated with the key using deletefunc() and replaces it with the data passed in.
- Parameters
-
hamt | Hash array mapped trie |
str | Key |
data | Data to associate with key |
replace | See above description |
deletefunc | Data deletion function if data is replaced |
- Returns
- Data now associated with key.
Get the next entry in a HAMT.
- Parameters
-
prev | Previous entry in HAMT |
- Returns
- Next entry in HAMT, or NULL if no more entries.
YASM_LIB_DECL void* HAMT_search |
( |
HAMT * |
hamt, |
|
|
const char * |
str |
|
) |
| |
Search for the data associated with a key in the HAMT.
- Parameters
-
hamt | Hash array mapped trie |
str | Key |
- Returns
- NULL if key/data not present in HAMT, otherwise associated data.
YASM_LIB_DECL int HAMT_traverse |
( |
HAMT * |
hamt, |
|
|
void * |
d, |
|
|
int(*)(void *node, void *d) |
func |
|
) |
| |
Traverse over all keys in HAMT, calling function on each data item.
- Parameters
-
hamt | Hash array mapped trie |
d | Data to pass to each call to func. |
func | Function to call |
- Returns
- Stops early (and returns func's return value) if func returns a nonzero value; otherwise 0.
YASM_LIB_DECL void* HAMTEntry_get_data |
( |
const HAMTEntry * |
entry | ) |
|
Get the corresponding data for a HAMT entry.
- Parameters
-
- Returns
- Corresponding data item.