Zephyr API Documentation
2.7.0-rc2
A Scalable Open Source RTOS
|
Data Structures | |
struct | rbtree |
Macros | |
#define | RB_FOR_EACH(tree, node) |
Walk a tree in-order without recursing. More... | |
#define | RB_FOR_EACH_CONTAINER(tree, node, field) |
Loop over rbtree with implicit container field logic. More... | |
Typedefs | |
typedef bool(* | rb_lessthan_t) (struct rbnode *a, struct rbnode *b) |
Red/black tree comparison predicate. More... | |
typedef void(* | rb_visit_t) (struct rbnode *node, void *cookie) |
Functions | |
void | rb_insert (struct rbtree *tree, struct rbnode *node) |
Insert node into tree. More... | |
void | rb_remove (struct rbtree *tree, struct rbnode *node) |
Remove node from tree. More... | |
static struct rbnode * | rb_get_min (struct rbtree *tree) |
Returns the lowest-sorted member of the tree. More... | |
static struct rbnode * | rb_get_max (struct rbtree *tree) |
Returns the highest-sorted member of the tree. More... | |
bool | rb_contains (struct rbtree *tree, struct rbnode *node) |
Returns true if the given node is part of the tree. More... | |
static void | rb_walk (struct rbtree *tree, rb_visit_t visit_fn, void *cookie) |
Walk/enumerate a rbtree. More... | |
#define RB_FOR_EACH | ( | tree, | |
node | |||
) |
#include <include/sys/rb.h>
Walk a tree in-order without recursing.
While rb_walk() is very simple, recursing on the C stack can be clumsy for some purposes and on some architectures wastes significant memory in stack frames. This macro implements a non-recursive "foreach" loop that can iterate directly on the tree, at a moderate cost in code size.
Note that the resulting loop is not safe against modifications to the tree. Changes to the tree structure during the loop will produce incorrect results, as nodes may be skipped or duplicated. Unlike linked lists, no _SAFE variant exists.
Note also that the macro expands its arguments multiple times, so they should not be expressions with side effects.
tree | A pointer to a struct rbtree to walk |
node | The symbol name of a local struct rbnode* variable to use as the iterator |
#define RB_FOR_EACH_CONTAINER | ( | tree, | |
node, | |||
field | |||
) |
#include <include/sys/rb.h>
Loop over rbtree with implicit container field logic.
As for RB_FOR_EACH(), but "node" can have an arbitrary type containing a struct rbnode.
tree | A pointer to a struct rbtree to walk |
node | The symbol name of a local iterator |
field | The field name of a struct rbnode inside node |
rb_lessthan_t |
#include <include/sys/rb.h>
Red/black tree comparison predicate.
Compares the two nodes and returns true if node A is strictly less than B according to the tree's sorting criteria, false otherwise.
Note that during insert, the new node being inserted will always be "A", where "B" is the existing node within the tree against which it is being compared. This trait can be used (with care!) to implement "most/least recently added" semantics between nodes which would otherwise compare as equal.
#include <include/sys/rb.h>
#include <include/sys/rb.h>
Returns true if the given node is part of the tree.
Note that this does not internally dereference the node pointer (though the tree's lessthan callback might!), it just tests it for equality with items in the tree. So it's feasible to use this to implement a "set" construct by simply testing the pointer value itself.
#include <include/sys/rb.h>
Returns the highest-sorted member of the tree.
#include <include/sys/rb.h>
Returns the lowest-sorted member of the tree.
#include <include/sys/rb.h>
Insert node into tree.
#include <include/sys/rb.h>
Remove node from tree.
|
inlinestatic |
#include <include/sys/rb.h>
Walk/enumerate a rbtree.
Very simple recursive enumeration. Low code size, but requiring a separate function can be clumsy for the user and there is no way to break out of the loop early. See RB_FOR_EACH for an iterative implementation.