20 #ifndef _RTEMS_SCORE_RBTREE_H 21 #define _RTEMS_SCORE_RBTREE_H 47 struct RBTree_Control;
70 #define RBTREE_INITIALIZER_EMPTY( name ) \ 71 RB_INITIALIZER( name ) 76 #define RBTREE_DEFINE_EMPTY( name ) \ 77 RBTree_Control name = RBTREE_INITIALIZER_EMPTY( name ) 90 RB_COLOR( the_node, Node ) = -1;
107 return RB_COLOR( the_node, Node ) == -1;
117 RBTree_Control *the_rbtree,
131 #if defined(RTEMS_DEBUG) 152 RB_SET( child, parent, Node );
207 RBTree_Control *the_rbtree,
230 RBTree_Control *the_rbtree,
247 const RBTree_Control *the_rbtree
250 return RB_ROOT( the_rbtree );
262 RBTree_Control *the_rbtree
265 return &RB_ROOT( the_rbtree );
277 const RBTree_Control *the_rbtree
280 return &RB_ROOT( the_rbtree );
299 return RB_PARENT( the_node, Node );
315 return RB_LEFT( the_node, Node );
330 return &RB_LEFT( the_node, Node );
346 return RB_RIGHT( the_node, Node );
361 return &RB_RIGHT( the_node, Node );
376 const RBTree_Control *the_rbtree
379 return RB_EMPTY( the_rbtree );
411 RBTree_Control *the_rbtree
414 RB_INIT( the_rbtree );
425 RBTree_Control *the_rbtree,
430 RB_ROOT( the_rbtree ) = the_node;
431 RB_PARENT( the_node, Node ) = NULL;
432 RB_LEFT( the_node, Node ) = NULL;
433 RB_RIGHT( the_node, Node ) = NULL;
434 RB_COLOR( the_node, Node ) = RB_BLACK;
485 RBTree_Control *the_rbtree,
509 RBTree_Control *the_rbtree,
512 bool ( *less )(
const void *,
const RBTree_Node * )
521 is_new_minimum =
true;
523 while ( *link != NULL ) {
526 if ( ( *less )( key, parent ) ) {
530 is_new_minimum =
false;
536 return is_new_minimum;
558 const RBTree_Control *the_rbtree,
560 bool ( *equal )(
const void *,
const RBTree_Node * ),
561 bool ( *less )(
const void *,
const RBTree_Node * ),
571 while ( *link != NULL ) {
574 if ( ( *equal )( key, parent ) ) {
575 return ( *map )( parent );
576 }
else if ( ( *less )( key, parent ) ) {
632 const RBTree_Control *the_rbtree,
static __inline__ void * _RBTree_Find_inline(const RBTree_Control *the_rbtree, const void *key, bool(*equal)(const void *, const RBTree_Node *), bool(*less)(const void *, const RBTree_Node *), void *(*map)(RBTree_Node *))
Finds an object in the red-black tree with the specified key.
static __inline__ void _RBTree_Set_off_tree(RBTree_Node *the_node)
Sets a red-black tree node as off-tree.
static __inline__ bool _RBTree_Insert_inline(RBTree_Control *the_rbtree, RBTree_Node *the_node, const void *key, bool(*less)(const void *, const RBTree_Node *))
Inserts the node into the red-black tree.
static __inline__ RBTree_Node * _RBTree_Right(const RBTree_Node *the_node)
Returns pointer to the right of this node.
static __inline__ RBTree_Node ** _RBTree_Root_reference(RBTree_Control *the_rbtree)
Returns a reference to the root pointer of the red-black tree.
RBTree_Node * _RBTree_Predecessor(const RBTree_Node *node)
Returns the predecessor of a node.
static __inline__ void _RBTree_Initialize_empty(RBTree_Control *the_rbtree)
Initializes this RBTree as empty.
RBTree_Node * _RBTree_Minimum(const RBTree_Control *the_rbtree)
Returns the minimum node of the red-black tree.
static __inline__ RBTree_Node *const * _RBTree_Root_const_reference(const RBTree_Control *the_rbtree)
Returns a constant reference to the root pointer of the red-black tree.
static __inline__ void _RBTree_Insert_with_parent(RBTree_Control *the_rbtree, RBTree_Node *the_node, RBTree_Node *parent, RBTree_Node **link)
Inserts the node into the red-black tree using the specified parent node and link.
Information for the Assert Handler.
static __inline__ bool _RBTree_Is_root(const RBTree_Node *the_node)
Checks if this node is the root node of a red-black tree.
static __inline__ void _RBTree_Add_child(RBTree_Node *child, RBTree_Node *parent, RBTree_Node **link)
Adds a child node to a parent node.
void * _RBTree_Postorder_first(const RBTree_Control *the_rbtree, size_t offset)
Returns the container of the first node of the specified red-black tree in postorder.
static __inline__ bool _RBTree_Is_empty(const RBTree_Control *the_rbtree)
Checks if the RBTree is empty.
void _RBTree_Insert_color(RBTree_Control *the_rbtree, RBTree_Node *the_node)
Rebalances the red-black tree after insertion of the node.
static __inline__ RBTree_Node * _RBTree_Root(const RBTree_Control *the_rbtree)
Returns a pointer to root node of the red-black tree.
struct RBTree_Node RBTree_Node
Red-black tree node.
void _RBTree_Replace_node(RBTree_Control *the_rbtree, RBTree_Node *victim, RBTree_Node *replacement)
Replaces a node in the red-black tree without a rebalance.
RBTree_Node * _RBTree_Successor(const RBTree_Node *node)
Returns the successor of a node.
static __inline__ bool _RBTree_Is_node_off_tree(const RBTree_Node *the_node)
Checks if this red-black tree node is off-tree.
static __inline__ RBTree_Node * _RBTree_Parent(const RBTree_Node *the_node)
Returns a pointer to the parent of this node.
typedef RB_HEAD(RBTree_Control, RBTree_Node) RBTree_Control
Red-black tree control.
static __inline__ void _RBTree_Initialize_one(RBTree_Control *the_rbtree, RBTree_Node *the_node)
Initializes this red-black tree to contain exactly the specified node.
static __inline__ RBTree_Node * _RBTree_Left(const RBTree_Node *the_node)
Returns pointer to the left of this node.
static __inline__ RBTree_Node ** _RBTree_Left_reference(RBTree_Node *the_node)
Returns a reference to the left child pointer of the red-black tree node.
static __inline__ void _RBTree_Initialize_node(RBTree_Node *the_node)
Initializes a red-black tree node.
This header file provides basic definitions used by the API and the implementation.
void _RBTree_Extract(RBTree_Control *the_rbtree, RBTree_Node *the_node)
Extracts (removes) the node from the red-black tree.
#define RTEMS_INLINE_ROUTINE
Gives a hint to the compiler in a function declaration to inline this function.
static __inline__ RBTree_Node ** _RBTree_Right_reference(RBTree_Node *the_node)
Returns a reference to the right child pointer of the red-black tree node.
RBTree_Node * _RBTree_Maximum(const RBTree_Control *the_rbtree)
Returns the maximum node of the red-black tree.
#define _Assert(_e)
Assertion similar to assert() controlled via RTEMS_DEBUG instead of NDEBUG.
void * _RBTree_Postorder_next(const RBTree_Node *the_node, size_t offset)
Returns the container of the next node in postorder.