113 if (grandparent ==
NULL)
127 parent = grandparent->
children[fromParent];
162 while (current !=
NULL)
165 if (tree->
compare(node, current) < 0)
232 b->
color = tempColor;
272 if (otherChild !=
NULL)
508 distantNephew = sibling;
509 sibling = closeNephew;
543 return tree->
size == 0;
#define assert(expression)
void(* rbnode_update_t)(rbnode_t *node)
Update function for Red-Black Tree nodes.
rbnode_t * rbtree_next(const rbnode_t *node)
Get the next node in the tree, in predecessor order.
#define RBNODE_OPPOSITE(direction)
Get the opposite direction (left <-> right).
int64_t(* rbnode_compare_t)(const rbnode_t *a, const rbnode_t *b)
Comparison function for Red-Black Tree nodes.
void rbtree_swap(rbtree_t *tree, rbnode_t *a, rbnode_t *b)
Swap two nodes in the Red-Black Tree.
rbnode_t * rbtree_find_min(rbnode_t *node)
Find the minimum node in a subtree.
rbnode_color_t
Red-Black Tree Node Colors.
rbnode_direction_t
Red-Black Tree Node Directions.
rbnode_t * rbtree_rotate(rbtree_t *tree, rbnode_t *node, rbnode_direction_t direction)
Rotate a node in the Red-Black Tree.
void rbtree_init(rbtree_t *tree, rbnode_compare_t compare, rbnode_update_t update)
Initialize a Red-Black Tree.
rbnode_t * rbtree_prev(const rbnode_t *node)
Get the previous node in the tree, in predecessor order.
void rbtree_remove(rbtree_t *tree, rbnode_t *node)
Remove a node from the Red-Black Tree.
void rbtree_insert(rbtree_t *tree, rbnode_t *node)
Insert a node into the Red-Black Tree.
rbnode_t * rbtree_find_max(rbnode_t *node)
Find the maximum node in a subtree.
void rbtree_fix(rbtree_t *tree, rbnode_t *node)
Move the node to its correct position in the Red-Black Tree.
#define RBNODE_FROM_PARENT(node)
Get the direction of a node from its parent.
bool rbtree_is_empty(const rbtree_t *tree)
Check if the Red-Black Tree is empty.
#define NULL
Pointer error value.
static void rbtree_remove_sanitize(rbtree_t *tree, rbnode_t *node)
static void rbtree_update(rbtree_t *tree, rbnode_t *node)
static void rbtree_update_to_root(rbtree_t *tree, rbnode_t *node)
static void rbtree_insert_at(rbtree_t *tree, rbnode_t *parent, rbnode_t *node, rbnode_direction_t direction)
rbnode_t * children[RBNODE_AMOUNT]