Red-black tree.
More...
#include "st/logger/except.h"
#include "vx/graph.h"
#include <stdint.h>
Go to the source code of this file.
◆ StBstChild
Indices for children in a binary search tree.
Enumerator |
---|
ST_BST_LEFT | left child.
|
ST_BST_RIGHT | right child.
|
ST_BST_N_CHILDREN | number of children.
|
◆ StBstOrder
Nodes order for a binary search tree.
Enumerator |
---|
ST_BST_INORDER | in-order.
|
ST_BST_PREORDER | pre-order.
|
ST_BST_POSTORDER | post-order.
|
◆ st_rb_first()
Get the first node of the red-black tree for the given BST order.
- Parameters
-
[in] | node | Any node from the red-black tree. |
[in] | order | The order: BST_INORDER, BST_PREORDER or BST_POSTORDER. |
- Returns
- The first node.
◆ st_rb_insrebal()
Insert a node in a red-black tree and rebalance the tree.
- Parameters
-
[in,out] | root | The root of the red-black tree. |
[in,out] | node | The inserted node. |
- Returns
- The new root.
- Note
- Prepare node with st_rb_link() before insertion.
- See also
- st_rb_link().
◆ st_rb_left()
Get the left child of the given node.
- Parameters
-
- Returns
- The left child.
◆ st_rb_link()
Prepare a node for insertion in a red-black tree.
- Parameters
-
[in,out] | node | The node prepared for insertion. |
[in] | parent | The parent node. |
This will paint node red and set its parent pointer to parent. This will also ensure that the left and right pointers of node are NULL. After preparing the node for insertion, insert it with st_rb_insrebal().
- See also
- st_rb_insrebal().
- Returns
- The prepared node.
◆ st_rb_next()
Get the next node for the current red-black tree node and the BST order.
- Parameters
-
[in] | node | The current red-black tree node. |
[in] | order | The order: BST_INORDER, BST_PREORDER or BST_POSTORDER. |
- Returns
- The next node.
◆ st_rb_parent()
Get the parent of the red-black tree node.
- Parameters
-
[in] | node | The red-black tree node. |
- Returns
- The parent.
◆ st_rb_right()
Get the right child of the given node.
- Parameters
-
- Returns
- The right child.