libusual  0.1
Typedefs | Functions
usual/cbtree.h File Reference

Crit-bit tree / binary radix tree. More...

Typedefs

typedef size_t(* cbtree_getkey_func )(void *ctx, void *obj, const void **dst_p)
 returns length of the key
typedef bool(* cbtree_walker_func )(void *ctx, void *obj)
 walk over tree

Functions

struct CBTree * cbtree_create (cbtree_getkey_func obj_key_cb, cbtree_walker_func obj_free_cb, void *cb_ctx, CxMem *cx)
 Create new tree.
void cbtree_destroy (struct CBTree *tree)
 frees all resources allocated.
bool cbtree_insert (struct CBTree *tree, void *obj) _MUSTCHECK
 Inserts new node to tree.
bool cbtree_delete (struct CBTree *tree, const void *key, size_t klen)
 Removed node from tree.
void * cbtree_lookup (struct CBTree *tree, const void *key, size_t klen)
 Lookup a key.
bool cbtree_walk (struct CBTree *tree, cbtree_walker_func cb_func, void *cb_arg)
 Walk over tree.

Detailed Description

Crit-bit tree / binary radix tree.


Typedef Documentation

typedef size_t(* cbtree_getkey_func)(void *ctx, void *obj, const void **dst_p)

returns length of the key

typedef bool(* cbtree_walker_func)(void *ctx, void *obj)

walk over tree


Function Documentation

struct CBTree* cbtree_create ( cbtree_getkey_func  obj_key_cb,
cbtree_walker_func  obj_free_cb,
void *  cb_ctx,
CxMem cx 
) [read]

Create new tree.

Parameters:
obj_key_cbcallback to get the key for a object
obj_free_cbcallback to free the object when tree node is freed (optional)
cb_ctxextra pointer passed to callbacks
cxmemory context where from allocate
void cbtree_destroy ( struct CBTree *  tree)

frees all resources allocated.

If obj_free_cb is non-NULL, it will be called per each object.

bool cbtree_insert ( struct CBTree *  tree,
void *  obj 
)

Inserts new node to tree.

bool cbtree_delete ( struct CBTree *  tree,
const void *  key,
size_t  klen 
)

Removed node from tree.

If obj_free_cb is non-NULL, it will be called for the object.

Returns:
true if key was found, false otherwise.
void* cbtree_lookup ( struct CBTree *  tree,
const void *  key,
size_t  klen 
)

Lookup a key.

Returns:
object pointer if found, NULL ohterwise
bool cbtree_walk ( struct CBTree *  tree,
cbtree_walker_func  cb_func,
void *  cb_arg 
)

Walk over tree.