24 RCSIDH(fr_rb_h,
"$Id: 0fe56ccec7ab455556b89432090c9e3b46a55766 $")
30 #include <freeradius-devel/util/misc.h>
117 #define fr_rb_talloc_init(_tree, _node_ctx, _type, _data_cmp, _data_free) \
118 _fr_rb_init(_tree, _node_ctx, -1, #_type, _data_cmp, _data_free)
136 #define fr_rb_init(_tree, _node_ctx, _data_cmp, _data_free) \
137 _fr_rb_init(_tree, _node_ctx, -1, NULL, _data_cmp, _data_free)
157 #define fr_rb_inline_talloc_init(_tree, _type, _field, _data_cmp, _data_free) \
158 _Generic((((_type *)0)->_field), \
159 fr_rb_node_t: _fr_rb_init(_tree, NULL, offsetof(_type, _field), #_type, _data_cmp, _data_free) \
180 #define fr_rb_inline_init(_tree, _type, _field, _data_cmp, _data_free) \
181 _Generic((((_type *)0)->_field), \
182 fr_rb_node_t: _fr_rb_init(_tree, NULL, offsetof(_type, _field), NULL, _data_cmp, _data_free) \
205 #define fr_rb_talloc_alloc(_ctx, _type, _data_cmp, _data_free) \
206 _fr_rb_alloc(_ctx, -1, #_type, _data_cmp, _data_free)
223 #define fr_rb_alloc(_ctx, _data_cmp, _data_free) \
224 _fr_rb_alloc(_ctx, -1, NULL, _data_cmp, _data_free)
246 #define fr_rb_inline_talloc_alloc(_ctx, _type, _field, _data_cmp, _data_free) \
247 _Generic((((_type *)0)->_field), \
248 fr_rb_node_t: _fr_rb_alloc(_ctx, offsetof(_type, _field), #_type, _data_cmp, _data_free) \
271 #define fr_rb_inline_alloc(_ctx, _type, _field, _data_cmp, _data_free) \
272 _Generic((((_type *)0)->_field), \
273 fr_rb_node_t: _fr_rb_alloc(_ctx, offsetof(_type, _field), NULL, _data_cmp, _data_free) \
333 #define fr_rb_inorder_foreach(_tree, _type, _iter) \
335 fr_rb_iter_inorder_t _state; \
336 for (_type *_iter = fr_rb_iter_init_inorder(&_state, _tree); _iter; _iter = fr_rb_iter_next_inorder(&_state))
349 #define fr_rb_preorder_foreach(_tree, _type, _iter) \
351 fr_rb_iter_preorder_t _state; \
352 for (_type *_iter = fr_rb_iter_init_preorder(&_state, _tree); _iter; _iter = fr_rb_iter_next_preorder(&_state))
365 #define fr_rb_postorder_foreach(_tree, _type, _iter) \
367 fr_rb_iter_postorder_t _state; \
368 for (_type *_iter = fr_rb_iter_init_postorder(&_state, _tree); _iter; _iter = fr_rb_iter_next_postorder(&_state))
int8_t(* fr_cmp_t)(void const *a, void const *b)
void(* fr_free_t)(void *)
fr_rb_tree_t * tree
Tree being iterated over.
fr_rb_node_t * node
current node
void * fr_rb_iter_init_preorder(fr_rb_iter_preorder_t *iter, fr_rb_tree_t *tree)
Initialise a pre-order iterator.
uint32_t fr_rb_num_elements(fr_rb_tree_t *tree)
void * fr_rb_first(fr_rb_tree_t *tree)
fr_rb_node_t * parent
Parent.
fr_rb_node_t * left
Left child.
void * fr_rb_iter_init_postorder(fr_rb_iter_postorder_t *iter, fr_rb_tree_t *tree)
Initialise a post-order iterator.
bool being_freed
Disable frees if we're currently calling a free function.
int fr_rb_find_or_insert(void **found, fr_rb_tree_t *tree, void const *data))
Attempt to find current data in the tree, if it does not exist insert it.
fr_rb_node_t * next
if non-NULL, next node cached by fr_rb_iter_delete()
fr_rb_node_t * node
current node
void fr_rb_iter_delete_inorder(fr_rb_iter_inorder_t *iter)
Remove the current node from the tree.
fr_cmp_t data_cmp
Callback to compare node data.
TALLOC_CTX * node_ctx
Talloc ctx to allocate nodes in.
fr_rb_node_t * right
Right child.
char const * type
Talloc type to check elements against.
fr_rb_node_t *(* rb_node_alloc_t)(fr_rb_tree_t const *tree, void *data)
Callback used to alloc rbnodes.
static bool fr_rb_node_inline_in_tree(fr_rb_node_t const *node)
Check to see if an item is in a tree by examining its inline fr_rb_node_t.
void * fr_rb_iter_next_inorder(fr_rb_iter_inorder_t *iter)
Return the next node.
void * data
data stored in node
void(* rb_node_free_t)(fr_rb_tree_t const *tree, fr_rb_node_t *node, bool free_data)
Callback used to free rbnodes.
uint32_t num_elements
How many elements are inside the tree.
void * fr_rb_iter_next_preorder(fr_rb_iter_preorder_t *iter)
Return the next node.
fr_free_t data_free
Callback to free node data.
void * fr_rb_remove(fr_rb_tree_t *tree, void const *data)
int fr_rb_flatten_preorder(TALLOC_CTX *ctx, void **out[], fr_rb_tree_t *tree)
fr_rb_tree_t * tree
Tree being iterated over.
uint16_t offset
Where's the fr_rb_node_t is located in the structure being inserted.
bool fr_rb_delete_by_inline_node(fr_rb_tree_t *tree, fr_rb_node_t *node)
Remove node and free data (if a free function was specified)
int fr_rb_replace(void **old, fr_rb_tree_t *tree, void const *data))
int fr_rb_flatten_postorder(TALLOC_CTX *ctx, void **out[], fr_rb_tree_t *tree)
int _fr_rb_init(fr_rb_tree_t *tree, TALLOC_CTX *node_ctx, ssize_t offset, char const *type, fr_cmp_t data_cmp, fr_free_t data_free)
Initialise a new RED-BLACK tree.
int fr_rb_flatten_inorder(TALLOC_CTX *ctx, void **out[], fr_rb_tree_t *tree)
fr_rb_tree_t * _fr_rb_alloc(TALLOC_CTX *ctx, ssize_t offset, char const *type, fr_cmp_t data_cmp, fr_free_t data_free)
Alloc a new RED-BLACK tree.
void * fr_rb_remove_by_inline_node(fr_rb_tree_t *tree, fr_rb_node_t *node)
Remove an entry from the tree, using the node structure, without freeing the data.
rb_node_free_t node_free
Callback to free a node.
bool fr_rb_insert(fr_rb_tree_t *tree, void const *data)
bool being_freed
Prevent double frees in talloc_destructor.
void * fr_rb_iter_next_postorder(fr_rb_iter_postorder_t *iter)
Return the next node.
fr_rb_tree_t * tree
Tree being iterated over.
void * fr_rb_last(fr_rb_tree_t *tree)
fr_rb_node_t * node
current nodeāset to NULL (not NIL) by fr_rb_iter_delete()
bool fr_rb_delete(fr_rb_tree_t *tree, void const *data)
fr_rb_colour_t colour
Node colour (BLACK, RED)
rb_node_alloc_t node_alloc
Callback to allocate a new node.
void * fr_rb_iter_init_inorder(fr_rb_iter_inorder_t *iter, fr_rb_tree_t *tree)
Initialise an in-order iterator.
void * fr_rb_find(fr_rb_tree_t const *tree, void const *data)
fr_rb_node_t * root
Root of the rbtree.
Iterator structure for in-order traversal of an rbtree.
Iterator structure for post-order traversal of an rbtree.
Iterator structure for pre-order traversal of an rbtree.
The main red black tree structure.
static int8_t data_cmp(const void *one, const void *two)
fr_aka_sim_id_type_t type
static size_t char ** out