132 rbtree->
root = right;
191 ldns_rbtree_rotate_left(rbtree, node);
216 ldns_rbtree_rotate_right(rbtree, node);
254 if ((r = rbtree->
cmp(data->
key, node->
key)) == 0) {
277 parent->
right = data;
284 ldns_rbtree_insert_fixup(rbtree, data);
306 static void swap_int8(uint8_t* x, uint8_t* y)
308 uint8_t t = *x; *x = *y; *y = t;
322 if(rbtree->
root == old) rbtree->
root =
new;
325 if(parent->
left == old) parent->
left =
new;
350 smright = smright->
left;
357 swap_int8(&to_delete->
color, &smright->
color);
360 change_parent_ptr(rbtree, to_delete->
parent, to_delete, smright);
361 if(to_delete->
right != smright)
362 change_parent_ptr(rbtree, smright->
parent, smright, to_delete);
365 change_child_ptr(smright->
left, smright, to_delete);
366 change_child_ptr(smright->
left, smright, to_delete);
367 change_child_ptr(smright->
right, smright, to_delete);
368 change_child_ptr(smright->
right, smright, to_delete);
369 change_child_ptr(to_delete->
left, to_delete, smright);
370 if(to_delete->
right != smright)
371 change_child_ptr(to_delete->
right, to_delete, smright);
372 if(to_delete->
right == smright)
375 to_delete->
right = to_delete;
376 smright->
parent = smright;
381 swap_np(&to_delete->
left, &smright->
left);
388 else child = to_delete->
right;
391 change_parent_ptr(rbtree, to_delete->
parent, to_delete, child);
392 change_child_ptr(child, to_delete, to_delete->
parent);
403 else ldns_rbtree_delete_fixup(rbtree, child, to_delete->
parent);
419 if(child_parent->
right == child) sibling = child_parent->
left;
420 else sibling = child_parent->
right;
434 if(child_parent->
right == child)
435 ldns_rbtree_rotate_right(rbtree, child_parent);
436 else ldns_rbtree_rotate_left(rbtree, child_parent);
438 if(child_parent->
right == child) sibling = child_parent->
left;
439 else sibling = child_parent->
right;
450 child = child_parent;
451 child_parent = child_parent->
parent;
453 if(child_parent->
right == child) sibling = child_parent->
left;
454 else sibling = child_parent->
right;
473 if(child_parent->
right == child
480 ldns_rbtree_rotate_left(rbtree, sibling);
482 if(child_parent->
right == child) sibling = child_parent->
left;
483 else sibling = child_parent->
right;
485 else if(child_parent->
left == child
492 ldns_rbtree_rotate_right(rbtree, sibling);
494 if(child_parent->
right == child) sibling = child_parent->
left;
495 else sibling = child_parent->
right;
501 if(child_parent->
right == child)
504 ldns_rbtree_rotate_right(rbtree, child_parent);
509 ldns_rbtree_rotate_left(rbtree, child_parent);
526 r = rbtree->
cmp(key, node->
key);
580 for (node = node->
right;
601 for (node = node->
left;
653 traverse_post(
void (*func)(
ldns_rbnode_t*,
void*),
void* arg,
659 traverse_post(func, arg, node->
left);
660 traverse_post(func, arg, node->
right);
669 traverse_post(func, arg, tree->
root);
ldns_rbtree_t * ldns_rbtree_create(int(*cmpf)(const void *, const void *))
Create new tree (malloced) with given key compare function.
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
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 *node)
Returns previous smaller node in the tree.
#define BLACK
Node colour black.
void ldns_rbtree_insert_vref(ldns_rbnode_t *data, void *rbtree)
Insert data into the tree (reversed arguments, for use as callback)
#define RED
Node colour red.
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 NULL node, global alloc
ldns_rbnode_t * ldns_rbtree_next(ldns_rbnode_t *node)
Returns next larger node in the tree.
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.
#define LDNS_RBTREE_NULL
The nullpointer, points to empty node.
The rbnode_t struct definition.
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.
#define LDNS_MALLOC(type)
Memory management macros.