RTEMS  5.0.0
Files | Macros | Typedefs | Functions
Red-Black Trees

A Red-Black Tree container. More...

Files

file  rbtree.c
 Initialize a Red-Black Tree.
 

Macros

#define RTEMS_RBTREE_INITIALIZER_EMPTY(name)   RBTREE_INITIALIZER_EMPTY(name)
 RBTree initializer for an empty rbtree with designator name.
 
#define RTEMS_RBTREE_DEFINE_EMPTY(name)   RBTREE_DEFINE_EMPTY(name)
 RBTree definition for an empty rbtree with designator name.
 

Typedefs

typedef RBTree_Node rtems_rbtree_node
 
typedef RBTree_Control rtems_rbtree_control
 
typedef long rtems_rbtree_compare_result
 Integer type for compare results. More...
 
typedef rtems_rbtree_compare_result(* rtems_rbtree_compare) (const RBTree_Node *first, const RBTree_Node *second)
 Compares two red-black tree nodes. More...
 

Functions

void rtems_rbtree_initialize (rtems_rbtree_control *the_rbtree, rtems_rbtree_compare compare, void *starting_address, size_t number_nodes, size_t node_size, bool is_unique)
 Initialize a RBTree header. More...
 
RTEMS_INLINE_ROUTINE void rtems_rbtree_initialize_empty (rtems_rbtree_control *the_rbtree)
 Initialize this RBTree as Empty. More...
 
RTEMS_INLINE_ROUTINE void rtems_rbtree_set_off_tree (rtems_rbtree_node *node)
 Set off RBtree. More...
 
RTEMS_INLINE_ROUTINE bool rtems_rbtree_is_node_off_tree (const rtems_rbtree_node *node)
 Is the Node off RBTree. More...
 
RTEMS_INLINE_ROUTINE rtems_rbtree_nodertems_rbtree_root (const rtems_rbtree_control *the_rbtree)
 Return pointer to RBTree root. More...
 
RTEMS_INLINE_ROUTINE rtems_rbtree_nodertems_rbtree_min (const rtems_rbtree_control *the_rbtree)
 Returns the minimum node of the red-black tree. More...
 
RTEMS_INLINE_ROUTINE rtems_rbtree_nodertems_rbtree_max (const rtems_rbtree_control *the_rbtree)
 Returns the maximum node of the red-black tree. More...
 
RTEMS_INLINE_ROUTINE rtems_rbtree_nodertems_rbtree_left (const rtems_rbtree_node *the_node)
 Return pointer to the left child node from this node. More...
 
RTEMS_INLINE_ROUTINE rtems_rbtree_nodertems_rbtree_right (const rtems_rbtree_node *the_node)
 Return pointer to the right child node from this node. More...
 
RTEMS_INLINE_ROUTINE rtems_rbtree_nodertems_rbtree_parent (const rtems_rbtree_node *the_node)
 Returns a pointer to the parent of this node. More...
 
RTEMS_INLINE_ROUTINE bool rtems_rbtree_is_empty (const rtems_rbtree_control *the_rbtree)
 Is the RBTree empty. More...
 
RTEMS_INLINE_ROUTINE bool rtems_rbtree_is_min (const rtems_rbtree_control *the_rbtree, const rtems_rbtree_node *the_node)
 Is this the minimum node on the RBTree. More...
 
RTEMS_INLINE_ROUTINE bool rtems_rbtree_is_max (const rtems_rbtree_control *the_rbtree, const rtems_rbtree_node *the_node)
 Is this the maximum node on the RBTree. More...
 
RTEMS_INLINE_ROUTINE bool rtems_rbtree_is_root (const rtems_rbtree_node *the_node)
 Returns true if this node is the root node of a red-black tree, and false otherwise. More...
 
RTEMS_INLINE_ROUTINE bool rtems_rbtree_is_equal (rtems_rbtree_compare_result compare_result)
 
RTEMS_INLINE_ROUTINE bool rtems_rbtree_is_greater (rtems_rbtree_compare_result compare_result)
 
RTEMS_INLINE_ROUTINE bool rtems_rbtree_is_lesser (rtems_rbtree_compare_result compare_result)
 
rtems_rbtree_nodertems_rbtree_find (const rtems_rbtree_control *the_rbtree, const rtems_rbtree_node *the_node, rtems_rbtree_compare compare, bool is_unique)
 Tries to find a node for the specified key in the tree. More...
 
RTEMS_INLINE_ROUTINE rtems_rbtree_nodertems_rbtree_predecessor (const rtems_rbtree_node *node)
 Returns the predecessor of a node. More...
 
RTEMS_INLINE_ROUTINE rtems_rbtree_nodertems_rbtree_successor (const rtems_rbtree_node *node)
 Returns the successor of a node. More...
 
RTEMS_INLINE_ROUTINE void rtems_rbtree_extract (rtems_rbtree_control *the_rbtree, rtems_rbtree_node *the_node)
 Extracts (removes) the node from the red-black tree. More...
 
RTEMS_INLINE_ROUTINE rtems_rbtree_nodertems_rbtree_get_min (rtems_rbtree_control *the_rbtree)
 Gets a node with the minimum key value from the red-black tree. More...
 
RTEMS_INLINE_ROUTINE rtems_rbtree_nodertems_rbtree_get_max (rtems_rbtree_control *the_rbtree)
 Gets a node with the maximal key value from the red-black tree. More...
 
RTEMS_INLINE_ROUTINE rtems_rbtree_nodertems_rbtree_peek_min (const rtems_rbtree_control *the_rbtree)
 Peek at the min node on a rbtree. More...
 
RTEMS_INLINE_ROUTINE rtems_rbtree_nodertems_rbtree_peek_max (const rtems_rbtree_control *the_rbtree)
 Peek at the max node on a rbtree. More...
 
rtems_rbtree_nodertems_rbtree_insert (RBTree_Control *the_rbtree, RBTree_Node *the_node, rtems_rbtree_compare compare, bool is_unique)
 Inserts the node into the red-black tree. More...
 

Detailed Description

A Red-Black Tree container.

The red-black tree container offers no internal protection against concurrent access. The user must ensure that at most one thread at once can access a red-black tree instance.

Typedef Documentation

◆ rtems_rbtree_compare

typedef rtems_rbtree_compare_result( * rtems_rbtree_compare) (const RBTree_Node *first, const RBTree_Node *second)

Compares two red-black tree nodes.

Parameters
[in]firstThe first node.
[in]secondThe second node.
Return values
positiveThe key value of the first node is greater than the one of the second node.
0The key value of the first node is equal to the one of the second node.
negativeThe key value of the first node is less than the one of the second node.

◆ rtems_rbtree_compare_result

Integer type for compare results.

The type is large enough to represent pointers and 32-bit signed integers.

See also
rtems_rbtree_compare.

◆ rtems_rbtree_control

The rbtree's control anchors the rbtree.

◆ rtems_rbtree_node

A node that can be manipulated in the rbtree.

Function Documentation

◆ rtems_rbtree_extract()

RTEMS_INLINE_ROUTINE void rtems_rbtree_extract ( rtems_rbtree_control the_rbtree,
rtems_rbtree_node the_node 
)

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

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

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

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

◆ rtems_rbtree_find()

rtems_rbtree_node* rtems_rbtree_find ( const rtems_rbtree_control the_rbtree,
const rtems_rbtree_node the_node,
rtems_rbtree_compare  compare,
bool  is_unique 
)

Tries to find a node for the specified key in the tree.

Parameters
[in]the_rbtreeThe red-black tree control.
[in]the_nodeA node specifying the key.
[in]compareThe node compare function.
[in]is_uniqueIf true, then return the first node with a key equal to the one of the node specified if it exits, else return the last node if it exists.
Return values
nodeA node corresponding to the key. If the tree is not unique and contains duplicate keys, the set of duplicate keys acts as FIFO.
NULLNo node exists in the tree for the key.

◆ rtems_rbtree_get_max()

RTEMS_INLINE_ROUTINE rtems_rbtree_node* rtems_rbtree_get_max ( rtems_rbtree_control the_rbtree)

Gets a node with the maximal key value from the red-black tree.

This function extracts a node with the maximum key value from tree and returns a pointer to that node if it exists. In case multiple nodes with a maximum key value exist, then they are extracted in LIFO order.

Parameters
[in]the_rbtreeThe red-black tree control.
Return values
NULLThe tree is empty.
nodeA node with the maximal key value on the tree.

◆ rtems_rbtree_get_min()

RTEMS_INLINE_ROUTINE rtems_rbtree_node* rtems_rbtree_get_min ( rtems_rbtree_control the_rbtree)

Gets a node with the minimum key value from the red-black tree.

This function extracts a node with the minimum key value from tree and returns a pointer to that node if it exists. In case multiple nodes with a minimum key value exist, then they are extracted in FIFO order.

Parameters
[in]the_rbtreeThe red-black tree control.
Return values
NULLThe tree is empty.
nodeA node with the minimal key value on the tree.

◆ rtems_rbtree_initialize()

void rtems_rbtree_initialize ( rtems_rbtree_control the_rbtree,
rtems_rbtree_compare  compare,
void *  starting_address,
size_t  number_nodes,
size_t  node_size,
bool  is_unique 
)

Initialize a RBTree header.

This routine initializes the_rbtree structure to manage the contiguous array of number_nodes nodes which starts at starting_address. Each node is of node_size bytes.

Parameters
[in]the_rbtreeis the pointer to rbtree header
[in]compareThe node compare function.
[in]starting_addressis the starting address of first node
[in]number_nodesis the number of nodes in rbtree
[in]node_sizeis the size of node in bytes
[in]is_uniqueIf true, then reject nodes with a duplicate key, else otherwise.

◆ rtems_rbtree_initialize_empty()

RTEMS_INLINE_ROUTINE void rtems_rbtree_initialize_empty ( rtems_rbtree_control the_rbtree)

Initialize this RBTree as Empty.

This routine initializes the_rbtree to contain zero nodes.

◆ rtems_rbtree_insert()

rtems_rbtree_node* rtems_rbtree_insert ( RBTree_Control *  the_rbtree,
RBTree_Node the_node,
rtems_rbtree_compare  compare,
bool  is_unique 
)

Inserts the node into the red-black tree.

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

Parameters
[in]the_rbtreeThe red-black tree control.
[in]the_nodeThe node to insert.
[in]compareThe node compare function.
[in]is_uniqueIf true, then reject nodes with a duplicate key, else insert nodes in FIFO order in case the key value is equal to existing nodes.
Return values
NULLSuccessfully inserted.
existing_nodeThis is a unique insert and there exists a node with an equal key in the tree already.

◆ rtems_rbtree_is_empty()

RTEMS_INLINE_ROUTINE bool rtems_rbtree_is_empty ( const rtems_rbtree_control the_rbtree)

Is the RBTree empty.

This function returns true if there a no nodes on the_rbtree and false otherwise.

◆ rtems_rbtree_is_max()

RTEMS_INLINE_ROUTINE bool rtems_rbtree_is_max ( const rtems_rbtree_control the_rbtree,
const rtems_rbtree_node the_node 
)

Is this the maximum node on the RBTree.

This function returns true if the_node is the max node on the_rbtree and false otherwise.

◆ rtems_rbtree_is_min()

RTEMS_INLINE_ROUTINE bool rtems_rbtree_is_min ( const rtems_rbtree_control the_rbtree,
const rtems_rbtree_node the_node 
)

Is this the minimum node on the RBTree.

This function returns true if the_node is the min node on the_rbtree and false otherwise.

◆ rtems_rbtree_is_node_off_tree()

RTEMS_INLINE_ROUTINE bool rtems_rbtree_is_node_off_tree ( const rtems_rbtree_node node)

Is the Node off RBTree.

This function returns true if the node is not on a rbtree. A node is off rbtree if the next and previous fields are set to NULL.

◆ rtems_rbtree_is_root()

RTEMS_INLINE_ROUTINE bool rtems_rbtree_is_root ( const rtems_rbtree_node the_node)

Returns true if this node is the root node of a red-black tree, and false otherwise.

The root node may change after insert or extract operations. In case the node is not a node of a tree, then this function yields unpredictable results.

Parameters
[in]the_nodeThe node of interest.
Return values
trueThe node is the root node.
falseOtherwise.
See also
_RBTree_Root().

◆ rtems_rbtree_left()

RTEMS_INLINE_ROUTINE rtems_rbtree_node* rtems_rbtree_left ( const rtems_rbtree_node the_node)

Return pointer to the left child node from this node.

This function returns a pointer to the left child node of the_node.

◆ rtems_rbtree_max()

RTEMS_INLINE_ROUTINE rtems_rbtree_node* rtems_rbtree_max ( const rtems_rbtree_control the_rbtree)

Returns the maximum node of the red-black tree.

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

◆ rtems_rbtree_min()

RTEMS_INLINE_ROUTINE rtems_rbtree_node* rtems_rbtree_min ( const rtems_rbtree_control the_rbtree)

Returns the minimum node of the red-black tree.

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

◆ rtems_rbtree_parent()

RTEMS_INLINE_ROUTINE rtems_rbtree_node* rtems_rbtree_parent ( const rtems_rbtree_node the_node)

Returns a pointer to the parent of this node.

The node must have a parent, thus it is invalid to use this function for the root node or a node that is not part of a tree. To test for the root node compare with _RBTree_Root() or use _RBTree_Is_root().

Parameters
[in]the_nodeThe node of interest.
Return values
parentThe parent of this node.
undefinedThe node is the root node or not part of a tree.

◆ rtems_rbtree_peek_max()

RTEMS_INLINE_ROUTINE rtems_rbtree_node* rtems_rbtree_peek_max ( const rtems_rbtree_control the_rbtree)

Peek at the max node on a rbtree.

This function returns a pointer to the max node from the_rbtree without changing the tree. If the_rbtree is empty, then NULL is returned.

◆ rtems_rbtree_peek_min()

RTEMS_INLINE_ROUTINE rtems_rbtree_node* rtems_rbtree_peek_min ( const rtems_rbtree_control the_rbtree)

Peek at the min node on a rbtree.

This function returns a pointer to the min node from the_rbtree without changing the tree. If the_rbtree is empty, then NULL is returned.

◆ rtems_rbtree_predecessor()

RTEMS_INLINE_ROUTINE rtems_rbtree_node* rtems_rbtree_predecessor ( const rtems_rbtree_node node)

Returns the predecessor of a node.

Parameters
[in]nodeis the node.
Return values
NULLThe predecessor does not exist. Otherwise it returns the predecessor node.

◆ rtems_rbtree_right()

RTEMS_INLINE_ROUTINE rtems_rbtree_node* rtems_rbtree_right ( const rtems_rbtree_node the_node)

Return pointer to the right child node from this node.

This function returns a pointer to the right child node of the_node.

◆ rtems_rbtree_root()

RTEMS_INLINE_ROUTINE rtems_rbtree_node* rtems_rbtree_root ( const rtems_rbtree_control the_rbtree)

Return pointer to RBTree root.

This function returns a pointer to the root node of the_rbtree.

◆ rtems_rbtree_set_off_tree()

RTEMS_INLINE_ROUTINE void rtems_rbtree_set_off_tree ( rtems_rbtree_node node)

Set off RBtree.

This function sets the next and previous fields of the node to NULL indicating the node is not part of any rbtree.

◆ rtems_rbtree_successor()

RTEMS_INLINE_ROUTINE rtems_rbtree_node* rtems_rbtree_successor ( const rtems_rbtree_node node)

Returns the successor of a node.

Parameters
[in]nodeis the node.
Return values
NULLThe successor does not exist. Otherwise the successor node.