43 #ifndef LDNS_RBTREE_H_
44 #define LDNS_RBTREE_H_
76 #define LDNS_RBTREE_NULL &ldns_rbtree_null_node
94 int (*
cmp) (
const void *,
const void *);
207 #define LDNS_RBTREE_FOR(node, type, rbtree) \
208 for(node=(type)ldns_rbtree_first(rbtree); \
209 (ldns_rbnode_t*)node != LDNS_RBTREE_NULL; \
210 node = (type)ldns_rbtree_next((ldns_rbnode_t*)node))
ldns_rbtree_t * ldns_rbtree_create(int(*cmpf)(const void *, const void *))
Create new tree (malloced) with given key compare function.
ldns_rbnode_t * ldns_rbtree_next(ldns_rbnode_t *rbtree)
Returns next larger node in the tree.
void ldns_traverse_postorder(ldns_rbtree_t *tree, void(*func)(ldns_rbnode_t *, void *), void *arg)
Call function for all elements in the redblack tree, such that leaf elements are called before parent...
ldns_rbtree_t * ldns_rbtree_split(ldns_rbtree_t *tree, size_t elements)
split off 'elements' number of elements from the start of the name tree and return a new tree contain...
void ldns_rbtree_free(ldns_rbtree_t *rbtree)
Free the complete tree (but not its keys)
ldns_rbnode_t * ldns_rbtree_previous(ldns_rbnode_t *rbtree)
Returns previous smaller node in the tree.
void ldns_rbtree_insert_vref(ldns_rbnode_t *data, void *rbtree)
Insert data into the tree (reversed arguments, for use as callback)
ldns_rbnode_t * ldns_rbtree_first(const ldns_rbtree_t *rbtree)
Returns first (smallest) node in the tree.
ldns_rbnode_t ldns_rbtree_null_node
the global empty node
int ldns_rbtree_find_less_equal(ldns_rbtree_t *rbtree, const void *key, ldns_rbnode_t **result)
Find, but match does not have to be exact.
ldns_rbnode_t * ldns_rbtree_delete(ldns_rbtree_t *rbtree, const void *key)
Delete element from tree.
ldns_rbnode_t * ldns_rbtree_search(ldns_rbtree_t *rbtree, const void *key)
Find key in tree.
void ldns_rbtree_join(ldns_rbtree_t *tree1, ldns_rbtree_t *tree2)
add all node from the second tree to the first (removing them from the second), and fix up nsec(3)s i...
void ldns_rbtree_init(ldns_rbtree_t *rbtree, int(*cmpf)(const void *, const void *))
Init a new tree (malloced by caller) with given key compare function.
ldns_rbnode_t * ldns_rbtree_last(const ldns_rbtree_t *rbtree)
Returns last (largest) node in the tree.
ldns_rbnode_t * ldns_rbtree_insert(ldns_rbtree_t *rbtree, ldns_rbnode_t *data)
Insert data into the tree.
The rbnode_t struct definition.
const void * data
pointer to data
ldns_rbnode_t * right
right node (larger items)
ldns_rbnode_t * parent
parent in rbtree, RBTREE_NULL for root
const void * key
pointer to sorting key
ldns_rbnode_t * left
left node (smaller items)
uint8_t color
colour of this node
definition for tree struct
size_t count
The number of the nodes in the tree.
ldns_rbnode_t * root
The root of the red-black tree.
int(* cmp)(const void *, const void *)
Key compare function.