RTEMS 6.1-rc5
Loading...
Searching...
No Matches
Files | Data Structures | Macros | Typedefs | Functions
Red-Black Tree Handler

This group contains the Red-Black Tree Handler implementation. More...

Files

file  bsd-tree.h
 This header file provides a red-black tree implementation.
 
file  rbtree.h
 This header file provides interfaces of the Red-Black Tree Handler which are used by the implementation, the Application Configuration, and the API.
 
file  rbtreeimpl.h
 This header file provides interfaces of the Red-Black Tree Handler which are only used by the implementation.
 
file  rbtreeappend.c
 This source file contains the implementation of _RBTree_Append().
 
file  rbtreeextract.c
 This source file contains the implementation of _RBTree_Extract().
 
file  rbtreeinsert.c
 This source file contains the implementation of _RBTree_Insert_color().
 
file  rbtreeiterate.c
 This source file contains the implementation of _RBTree_Iterate().
 
file  rbtreemax.c
 This source file contains the implementation of _RBTree_Maximum().
 
file  rbtreemin.c
 This source file contains the implementation of _RBTree_Minimum().
 
file  rbtreenext.c
 This source file contains the implementation of _RBTree_Minimum(), _RBTree_Maximum(), _RBTree_Successor(), and _RBTree_Predecessor().
 
file  rbtreepostorder.c
 This source file contains the implementation of _RBTree_Postorder_next() and _RBTree_Postorder_first().
 
file  rbtreeprepend.c
 This source file contains the implementation of _RBTree_Prepend().
 
file  rbtreeprev.c
 This source file contains the implementation of _RBTree_Predecessor().
 
file  rbtreereplace.c
 This source file contains the implementation of _RBTree_Replace_node().
 

Data Structures

struct  RBTree_Node
 Red-black tree node. More...
 

Macros

#define RBTREE_INITIALIZER_EMPTY(name)    RTEMS_RB_INITIALIZER( name )
 Initializer for an empty red-black tree with designator name.
 
#define RBTREE_DEFINE_EMPTY(name)    RBTree_Control name = RBTREE_INITIALIZER_EMPTY( name )
 Definition for an empty red-black tree with designator name.
 

Typedefs

typedef struct RBTree_Node RBTree_Node
 Red-black tree node.
 
typedef bool(* RBTree_Visitor) (const RBTree_Node *node, void *visitor_arg)
 Red-black tree visitor.
 

Functions

typedef RTEMS_RB_HEAD (RBTree_Control, RBTree_Node) RBTree_Control
 Red-black tree control.
 
void _RBTree_Insert_color (RBTree_Control *the_rbtree, RBTree_Node *the_node)
 Rebalances the red-black tree after insertion of the node.
 
void _RBTree_Extract (RBTree_Control *the_rbtree, RBTree_Node *the_node)
 Extracts (removes) the node from the red-black tree.
 
RBTree_Node_RBTree_Minimum (const RBTree_Control *the_rbtree)
 Returns the minimum node of the red-black tree.
 
RBTree_Node_RBTree_Maximum (const RBTree_Control *the_rbtree)
 Returns the maximum node of the red-black tree.
 
RBTree_Node_RBTree_Predecessor (const RBTree_Node *node)
 Returns the predecessor of a node.
 
RBTree_Node_RBTree_Successor (const RBTree_Node *node)
 Returns the successor of a 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.
 
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.
 
void * _RBTree_Postorder_next (const RBTree_Node *the_node, size_t offset)
 Returns the container of the next node in postorder.
 
void _RBTree_Append (RBTree_Control *the_rbtree, RBTree_Node *the_node)
 Appends the node to the red-black tree.
 
void _RBTree_Prepend (RBTree_Control *the_rbtree, RBTree_Node *the_node)
 Prepends the node to the red-black tree.
 
void _RBTree_Iterate (const RBTree_Control *rbtree, RBTree_Visitor visitor, void *visitor_arg)
 Red-black tree iteration.
 

Detailed Description

This group contains the Red-Black Tree Handler implementation.

The Red-Black Tree Handler is used to manage sets of entities. This handler provides two data structures. The rbtree Node data structure is included as the first part of every data structure that will be placed on a RBTree. The second data structure is rbtree Control which is used to manage a set of rbtree Nodes.

Typedef Documentation

◆ RBTree_Node

typedef struct RBTree_Node RBTree_Node

Red-black tree node.

This is used to manage each node (element) which is placed on a red-black tree.

◆ RBTree_Visitor

typedef bool(* RBTree_Visitor) (const RBTree_Node *node, void *visitor_arg)

Red-black tree visitor.

Parameters
[in]nodeThe node.
[in]visitor_argThe visitor argument.
Return values
trueStop the iteration.
falseContinue the iteration.
See also
_RBTree_Iterate().

Function Documentation

◆ _RBTree_Append()

void _RBTree_Append ( RBTree_Control *  the_rbtree,
RBTree_Node the_node 
)

Appends the node to the red-black tree.

The appended node is the new maximum node of the tree. The caller shall ensure that the appended node is indeed the maximum node with respect to the tree order.

Parameters
[in,out]the_rbtreeis the red-black tree control.
the_node[out]is the node to append.

◆ _RBTree_Extract()

void _RBTree_Extract ( RBTree_Control *  the_rbtree,
RBTree_Node the_node 
)

Extracts (removes) the node from the red-black tree.

This function does not set the node off-tree. In the case this is desired, then call _RBTree_Set_off_tree() after the extraction.

In the case the node to extract is not a node of the tree, then this function yields unpredictable results.

Parameters
[in,out]the_rbtreeThe red-black tree control.
[out]the_nodeThe node to extract.

◆ _RBTree_Insert_color()

void _RBTree_Insert_color ( RBTree_Control *  the_rbtree,
RBTree_Node the_node 
)

Rebalances the red-black tree after insertion of the node.

Parameters
[in,out]the_rbtreeThe red-black tree control.
[in,out]the_nodeThe most recently inserted node.

◆ _RBTree_Iterate()

void _RBTree_Iterate ( const RBTree_Control *  rbtree,
RBTree_Visitor  visitor,
void *  visitor_arg 
)

Red-black tree iteration.

Parameters
rbtreeThe red-black tree.
visitorThe visitor.
visitor_argThe visitor argument.

◆ _RBTree_Maximum()

RBTree_Node * _RBTree_Maximum ( const RBTree_Control *  the_rbtree)

Returns the maximum node of the red-black tree.

Parameters
the_rbtreeThe red-black tree control.
Return values
nodeThe maximum node.
NULLThe red-black tree is empty.

◆ _RBTree_Minimum()

RBTree_Node * _RBTree_Minimum ( const RBTree_Control *  the_rbtree)

Returns the minimum node of the red-black tree.

Parameters
the_rbtreeThe red-black tree control.
Return values
nodeThe minimum node.
NULLThe red-black tree is empty.

◆ _RBTree_Postorder_first()

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.

Postorder traversal may be used to delete all nodes of a red-black tree.

Parameters
the_rbtreeThe red-black tree control.
offsetThe offset to the red-black tree node in the container structure.
Return values
containerThe container of the first node of the specified red-black tree in postorder.
NULLThe red-black tree is empty.
See also
_RBTree_Postorder_next().
typedef struct {
int data;
} Container_Control;
void visit( Container_Control *the_container );
void postorder_traversal( RBTree_Control *the_rbtree )
{
Container_Control *the_container;
the_container = _RBTree_Postorder_first(
the_rbtree,
offsetof( Container_Control, Node )
);
while ( the_container != NULL ) {
visit( the_container );
the_container = _RBTree_Postorder_next(
&the_container->Node,
offsetof( Container_Control, 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.
Definition: rbtreepostorder.c:81
void * _RBTree_Postorder_next(const RBTree_Node *the_node, size_t offset)
Returns the container of the next node in postorder.
Definition: rbtreepostorder.c:59
This header file provides interfaces of the Red-Black Tree Handler which are used by the implementati...
Red-black tree node.
Definition: rbtree.h:73

◆ _RBTree_Postorder_next()

void * _RBTree_Postorder_next ( const RBTree_Node the_node,
size_t  offset 
)

Returns the container of the next node in postorder.

Parameters
the_nodeThe red-black tree node. The node must not be NULL.
offsetThe offset to the red-black tree node in the container structure.
Return values
containerThe container of the next node in postorder.
NULLThe node is NULL or there is no next node in postorder.
See also
_RBTree_Postorder_first().

◆ _RBTree_Predecessor()

RBTree_Node * _RBTree_Predecessor ( const RBTree_Node node)

Returns the predecessor of a node.

Parameters
nodeis the node.
Return values
nodeThe predecessor node.
NULLThe predecessor does not exist.

◆ _RBTree_Prepend()

void _RBTree_Prepend ( RBTree_Control *  the_rbtree,
RBTree_Node the_node 
)

Prepends the node to the red-black tree.

The prepended node is the new minimum node of the tree. The caller shall ensure that the prepended node is indeed the minimum node with respect to the tree order.

Parameters
[in,out]the_rbtreeis the red-black tree control.
the_node[out]is the node to prepend.

◆ _RBTree_Replace_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.

Parameters
[in,out]the_rbtreeThe red-black tree control.
victimThe victim node.
[out]replacementThe replacement node.

◆ _RBTree_Successor()

RBTree_Node * _RBTree_Successor ( const RBTree_Node node)

Returns the successor of a node.

Parameters
nodeis the node.
Return values
nodeThe successor node.
NULLThe successor does not exist.

◆ RTEMS_RB_HEAD()

typedef RTEMS_RB_HEAD ( RBTree_Control  ,
RBTree_Node   
)

Red-black tree control.

This is used to manage a red-black tree. A red-black tree consists of a tree of zero or more nodes.