62 cstl_rbtree_color_t c;
95#define CSTL_RBTREE_INITIALIZER(TYPE, MEMB, CMP, PRIV) \
97 .t = CSTL_BINTREE_INITIALIZER(TYPE, MEMB.n, CMP, PRIV), \
98 .off = offsetof(TYPE, MEMB), \
114#define DECLARE_CSTL_RBTREE(NAME, TYPE, MEMB, CMP, PRIV) \
115 struct cstl_rbtree NAME = \
116 CSTL_RBTREE_INITIALIZER(TYPE, MEMB, CMP, PRIV)
188 const struct cstl_rbtree *
const t,
const void *
const e,
189 const void **
const p)
254 cstl_swap(&a->off, &b->off, &t,
sizeof(t));
292 size_t *
const min,
size_t *
const max)
static void cstl_swap(void *const x, void *const y, void *const t, const size_t sz)
Swap values at two memory locations via use of a third.
void cstl_xtor_func_t(void *obj, void *priv)
Type for functions called to construct, clear, or destroy an object.
int cstl_compare_func_t(const void *obj1, const void *obj2, void *priv)
Function type for comparing (in)equality of two objects.
static size_t cstl_bintree_size(const struct cstl_bintree *const bt)
Get the number of objects in the tree.
static void cstl_bintree_init(struct cstl_bintree *const bt, cstl_compare_func_t *const cmp, void *const priv, const size_t off)
Initialize a binary tree object.
cstl_bintree_foreach_dir_t
Enumeration indicating the order in which elements in a tree are visited during cstl_bintree_foreach(...
int cstl_bintree_const_visit_func_t(const void *e, cstl_bintree_visit_order_t ord, void *p)
The type of visit function associated with cstl_bintree_foreach()
void cstl_bintree_height(const struct cstl_bintree *bt, size_t *min, size_t *max)
Determine the maximum and minimum heights of a tree.
int cstl_bintree_foreach(const struct cstl_bintree *bt, cstl_bintree_const_visit_func_t *visit, void *priv, cstl_bintree_foreach_dir_t dir)
Visit each element in a tree, calling a user-defined function for each visit.
const void * cstl_bintree_find(const struct cstl_bintree *bt, const void *e, const void **p)
Find an element within a tree.
void cstl_bintree_swap(struct cstl_bintree *a, struct cstl_bintree *b)
Swap the tree objects at the two given locations.
void cstl_bintree_clear(struct cstl_bintree *bt, cstl_xtor_func_t *clr, void *priv)
Remove all elements from the tree.
static void cstl_rbtree_init(struct cstl_rbtree *const t, cstl_compare_func_t *const cmp, void *const priv, const size_t off)
Initialize a red-black tree object.
static int cstl_rbtree_foreach(const struct cstl_rbtree *const t, cstl_bintree_const_visit_func_t *const visit, void *const priv, const cstl_bintree_foreach_dir_t dir)
Visit each element in a tree, calling a user-defined function for each visit.
void cstl_rbtree_insert(struct cstl_rbtree *t, void *e, void *p)
Insert a new object into the tree.
static const void * cstl_rbtree_find(const struct cstl_rbtree *const t, const void *const e, const void **const p)
Find an element within a tree.
static void cstl_rbtree_swap(struct cstl_rbtree *const a, struct cstl_rbtree *const b)
Swap the tree objects at the two given locations.
static void cstl_rbtree_height(const struct cstl_rbtree *const t, size_t *const min, size_t *const max)
Determine the maximum and minimum heights of a tree.
static void cstl_rbtree_clear(struct cstl_rbtree *const t, cstl_xtor_func_t *const clr, void *const priv)
Remove all elements from the tree.
static size_t cstl_rbtree_size(const struct cstl_rbtree *const t)
Get the number of objects in the tree.
void * cstl_rbtree_erase(struct cstl_rbtree *t, const void *e)
Remove an element from the tree.
Node to anchor an element within a binary tree.
Node to anchor an element within a red-black tree.