38 #ifndef ETCPAL_RBTREE_H_
39 #define ETCPAL_RBTREE_H_
42 #include "etcpal/error.h"
126 #ifndef ETCPAL_RB_ITER_MAX_HEIGHT
127 #define ETCPAL_RB_ITER_MAX_HEIGHT 64
etcpal_error_t
A set of error codes that can be returned by library functions.
Definition: error.h:49
etcpal_error_t etcpal_rbtree_insert_node(EtcPalRbTree *self, EtcPalRbNode *node)
Insert a node containing a new value into a red-black tree.
Definition: rbtree.c:294
int(* EtcPalRbTreeNodeCmpFunc)(const EtcPalRbTree *self, const void *value_a, const void *value_b)
A function type that compares two value instances contained in a tree.
Definition: rbtree.h:153
etcpal_error_t etcpal_rbtree_clear(EtcPalRbTree *self)
Clear all values from a red-black tree.
Definition: rbtree.c:529
void * etcpal_rbiter_first(EtcPalRbIter *self, EtcPalRbTree *tree)
Point a red-black tree iterator at the first value in the tree.
Definition: rbtree.c:750
void etcpal_rbtree_node_dealloc_cb(const EtcPalRbTree *self, EtcPalRbNode *node)
The default node deallocation callback.
Definition: rbtree.c:139
void * etcpal_rbiter_upper_bound(EtcPalRbIter *self, EtcPalRbTree *tree, const void *value)
Point a red-black tree iterator to the upper-bound of a value.
Definition: rbtree.c:857
etcpal_error_t etcpal_rbtree_clear_with_cb(EtcPalRbTree *self, EtcPalRbTreeNodeFunc node_cb)
Clear all values from a red-black tree, calling back into the application for each node and value bei...
Definition: rbtree.c:552
#define ETCPAL_RB_ITER_MAX_HEIGHT
The tallest allowable tree that can be iterated over.
Definition: rbtree.h:127
int etcpal_rbtree_test(EtcPalRbTree *self, EtcPalRbNode *root)
Test the validity of a red-black tree.
Definition: rbtree.c:612
void * etcpal_rbiter_lower_bound(EtcPalRbIter *self, EtcPalRbTree *tree, const void *value)
Point a red-black tree iterator to the lower-bound of a value.
Definition: rbtree.c:820
etcpal_error_t etcpal_rbtree_remove(EtcPalRbTree *self, const void *value)
Remove a value from a red-black tree.
Definition: rbtree.c:392
void * etcpal_rbtree_find(EtcPalRbTree *self, const void *value)
Find a value in a red-black tree.
Definition: rbtree.c:214
void(* EtcPalRbTreeNodeFunc)(const EtcPalRbTree *self, EtcPalRbNode *node)
A function type to be called for each node in a tree.
Definition: rbtree.h:166
void * etcpal_rbiter_last(EtcPalRbIter *self, EtcPalRbTree *tree)
Point a red-black tree iterator at the last value in the tree.
Definition: rbtree.c:768
EtcPalRbNode *(* EtcPalRbNodeAllocFunc)(void)
A function type to allocate a new node.
Definition: rbtree.h:177
struct EtcPalRbIter EtcPalRbIter
A red-black tree iterator.
void * etcpal_rbiter_next(EtcPalRbIter *self)
Advance a red-black tree iterator.
Definition: rbtree.c:785
void(* EtcPalRbNodeDeallocFunc)(EtcPalRbNode *node)
A function type to deallocate a node.
Definition: rbtree.h:188
EtcPalRbTree * etcpal_rbtree_init(EtcPalRbTree *self, EtcPalRbTreeNodeCmpFunc node_cmp_cb, EtcPalRbNodeAllocFunc alloc_f, EtcPalRbNodeDeallocFunc dealloc_f)
Initialize a red-black tree node.
Definition: rbtree.c:158
int etcpal_rbtree_node_cmp_ptr_cb(const EtcPalRbTree *self, const void *a, const void *b)
The default node comparison callback.
Definition: rbtree.c:127
void * etcpal_rbiter_prev(EtcPalRbIter *self)
Reverse-advance a red-black tree iterator.
Definition: rbtree.c:802
size_t etcpal_rbtree_size(EtcPalRbTree *self)
Get the current number of values in a red-black tree.
Definition: rbtree.c:591
EtcPalRbIter * etcpal_rbiter_init(EtcPalRbIter *self)
Initialize a red-black tree iterator.
Definition: rbtree.c:665
etcpal_error_t etcpal_rbtree_insert(EtcPalRbTree *self, void *value)
Insert a new value into a red-black tree.
Definition: rbtree.c:255
etcpal_error_t etcpal_rbtree_remove_with_cb(EtcPalRbTree *self, const void *value, EtcPalRbTreeNodeFunc node_cb)
Remove a value from a red-black tree, calling back into the application with the node and value being...
Definition: rbtree.c:418
EtcPalRbNode * etcpal_rbnode_init(EtcPalRbNode *self, void *value)
Initialize a red-black tree node.
Definition: rbtree.c:64
A red-black tree iterator.
Definition: rbtree.h:223
EtcPalRbTree * tree
The tree being iterated over.
Definition: rbtree.h:224
EtcPalRbNode * node
The current node.
Definition: rbtree.h:225
EtcPalRbNode * path[ETCPAL_RB_ITER_MAX_HEIGHT]
The traversal path to the current node.
Definition: rbtree.h:226
size_t top
Top of the traversal stack.
Definition: rbtree.h:227
void * info
User provided, not used by etcpal_rbiter.
Definition: rbtree.h:228
A red-black tree node.
Definition: rbtree.h:196
void * value
The value object represented by this node.
Definition: rbtree.h:199
EtcPalRbNode * link[2]
Child node links: left [0], right [1].
Definition: rbtree.h:198
int red
The node color: red (1), black (0)
Definition: rbtree.h:197
A red-black tree.
Definition: rbtree.h:208
EtcPalRbNodeAllocFunc alloc_f
A function to use for allocating a new node.
Definition: rbtree.h:212
EtcPalRbNodeDeallocFunc dealloc_f
A function to use for deallocating a node.
Definition: rbtree.h:213
EtcPalRbTreeNodeCmpFunc cmp
A function to use for comparing two nodes.
Definition: rbtree.h:210
size_t size
The current count of nodes in the tree.
Definition: rbtree.h:211
void * info
User provided, not used by etcpal_rbtree.
Definition: rbtree.h:214
EtcPalRbNode * root
The root node of the tree.
Definition: rbtree.h:209