|
LibSWOC++ 1.5.14
Solid Wall of C++
|
#include <RBTree.h>


Classes | |
| struct | Linkage |
Support for IntrusiveDList. More... | |
Public Types | |
| enum class | Color { RED , BLACK } |
| Node colors. More... | |
| enum class | Direction { NONE , LEFT , RIGHT } |
| Directional constants. More... | |
| using | self_type = RBNode |
| self reference type | |
Public Member Functions | |
| RBNode ()=default | |
| Default constructor. | |
| virtual | ~RBNode () |
| Force virtual destructor. | |
| self_type * | child_at (Direction d) const |
| Direction | direction_of (self_type *const &n) const |
| Color | color () const |
| self_type * | left_most_descendant () const |
| Direction | flip (Direction d) |
| int | validate () |
| self_type * | rotate (Direction dir) |
| self_type * | set_child (self_type *child, Direction dir) |
| self_type * | remove () |
| void | clear_child (Direction dir) |
Subclass hook methods | |
| Color | _color {Color::RED} |
| node color | |
| self_type * | _parent {nullptr} |
| parent node (needed for rotations) | |
| self_type * | _left {nullptr} |
| left child | |
| self_type * | _right {nullptr} |
| right child | |
| self_type * | _next {nullptr} |
| Next node. | |
| self_type * | _prev {nullptr} |
| Previous node. | |
| virtual void | structure_fixup () |
| virtual bool | structure_validate () |
| void | replace_with (self_type *n) |
| self_type * | rebalance_after_insert () |
| Rebalance the tree starting at this node. | |
| self_type * | rebalance_after_remove (Color c, Direction dir) |
| self_type * | ripple_structure_fixup () |
| static self_type * | buildTree (self_type *&head, int n) |
| Recursively build a balanced RB tree from a sorted linked list. | |
| static self_type * | buildTree (self_type *&head, int n, bool isBlack) |
| Called by buildTree above. | |
| static void | printTree (self_type *root, std::string indent="", bool last=true) |
| Recursively print the tree in a human-readable format. | |
A node in a red/black tree.
This class provides only the basic tree operations. The container must provide the search and decision logic. This enables this class to be a base class for templated nodes with much less code duplication.
|
strong |
|
strong |
|
inlinevirtual |
Recursively build a balanced RB tree from a sorted linked list.
Constraints:
| head | Copy of the head pointer of the list. |
| n | Number of nodes being processed at the current level. |
|
inline |
|
inline |
|
inline |
|
inline |
| auto swoc::detail::RBNode::left_most_descendant | ( | ) | const |
|
static |
| RBNode * swoc::detail::RBNode::rebalance_after_insert | ( | ) |
Rebalance the tree after a deletion. Called on the lowest modified node.
| c | The color of the removed node. |
| d | The direction of the removed node from this. |
Invariant: this is the parent of the removed node.
Rebalance tree after a deletion Called on the spliced in node or its parent, whichever is not NIL. This modifies the tree structure only if c is BLACK.
| c | The color of the removed node |
| d | Direction of removed node from its parent |
| RBNode * swoc::detail::RBNode::remove | ( | ) |
| void swoc::detail::RBNode::replace_with | ( | self_type * | n | ) |
| RBNode * swoc::detail::RBNode::ripple_structure_fixup | ( | ) |
Rotate the subtree rooted at this node in the direction dir.
| dir | Direction of rotatoin. |
this node is rotated in to the position of its dir child and the child in the other direction becomes the new root node for the subtree. This operation is a no-op if there is no other child.
If this node has a parent then that parent's child pointer is updated as needed.
Set the dir child of this node to child.
| child | Node to set as the child. |
| dir | Direction of the child location. |
The internal pointers in both this and child are updated as needed. It is an error to call this if the specified child is already set.
|
inlinevirtual |
Structural change notification.
This method is called if the structure of the subtree rooted at this node was changed. This makes it possible to keep subtree information nodes synchronized with the state of the tree efficiently.
This is intended a hook. The base method is empty so that subclasses are not required to override.
Reimplemented in swoc::DiscreteSpace< METRIC, PAYLOAD >::Node.
|
inlinevirtual |
| int swoc::detail::RBNode::validate | ( | ) |
Perform internal validation checks.
Ensure that the local information associated with each node is correct globally This should only be called on debug builds as it breaks any efficiencies we have gained from our tree structure.
| self_type* swoc::detail::RBNode::_left {nullptr} |
| self_type* swoc::detail::RBNode::_next {nullptr} |
| self_type* swoc::detail::RBNode::_parent {nullptr} |
| self_type* swoc::detail::RBNode::_prev {nullptr} |
| self_type* swoc::detail::RBNode::_right {nullptr} |