libyasm
Macros | Typedefs | Functions
hamt.h File Reference

Hash Array Mapped Trie (HAMT) functions. More...

Go to the source code of this file.

Typedefs

typedef struct HAMT HAMT
 Hash array mapped trie data structure (opaque type). More...
 
typedef struct HAMTEntry HAMTEntry
 Hash array mapped trie entry (opaque type). More...
 

Functions

YASM_LIB_DECL HAMTHAMT_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 HAMTEntryHAMT_first (const HAMT *hamt)
 Get the first entry in a HAMT. More...
 
YASM_LIB_DECL const HAMTEntryHAMT_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...
 

Detailed Description

Hash Array Mapped Trie (HAMT) functions.

Definition in file hamt.h.

Typedef Documentation

typedef struct HAMT HAMT

Hash array mapped trie data structure (opaque type).

Definition at line 38 of file hamt.h.

typedef struct HAMTEntry HAMTEntry

Hash array mapped trie entry (opaque type).

Definition at line 40 of file hamt.h.

Function Documentation

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
nocasenonzero if HAMT should be case-insensitive
error_funcfunction 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
hamtHash array mapped trie
deletefuncData deletion function
YASM_LIB_DECL const HAMTEntry* HAMT_first ( const HAMT hamt)

Get the first entry in a HAMT.

Parameters
hamtHash 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
hamtHash array mapped trie
strKey
dataData to associate with key
replaceSee above description
deletefuncData deletion function if data is replaced
Returns
Data now associated with key.
YASM_LIB_DECL const HAMTEntry* HAMT_next ( const HAMTEntry prev)

Get the next entry in a HAMT.

Parameters
prevPrevious 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
hamtHash array mapped trie
strKey
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
hamtHash array mapped trie
dData to pass to each call to func.
funcFunction 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
entryHAMT entry (as returned by HAMT_first() and HAMT_next())
Returns
Corresponding data item.