|
Aleph-w 7.10.0
A C++ Library for Data Structures and Algorithms
|
Red-Black tree node definition and validation utilities. More...
#include <tpl_binNode.H>Go to the source code of this file.
Classes | |
| class | RbNode_Data |
| Data portion of a Red-Black tree node. More... | |
| class | RbNode< Key > |
| Declare RbNode type with 128-byte pool allocation. More... | |
| class | RbNodeVtl< Key > |
Macros | |
| #define | COLOR(p) ((p)->getColor()) |
| Access the color of node p. | |
| #define | RED (0) |
| Red color constant (newly inserted nodes are red) | |
| #define | BLACK (1) |
| Black color constant. | |
Typedefs | |
| typedef unsigned char | Color |
| Color type for RB nodes. | |
Functions | |
| template<class Node > | |
| bool | test_black_condition (Node *p, int &max, int bh=0) |
| Test the black-height property of an RB tree. | |
| template<class Node > | |
| int | red_black_height (Node *p) noexcept |
| Black height of a red-black subtree, checking all its nodes. | |
| template<class Node > | |
| bool | is_red_black (Node *node) |
| Test all Red-Black tree properties for a node. | |
| template<class Node > | |
| bool | is_red_black_tree (Node *node) |
| Test RB properties for entire subtree. | |
| template<class Node , class Compare > | |
| bool | is_red_black_bst (Node *node, Compare &cmp) |
| Verify that tree is both a valid RB tree and valid BST. | |
Red-Black tree node definition and validation utilities.
This file defines the RbNode structure for Red-Black trees, including the color attribute (RED or BLACK) and functions to validate RB tree properties.
The usual definition adds that the root is black. The red-black trees of the library do not force it: the root can be red, as the only node of a tree is. A red root has black children, so the height is still at most 2 log2(n + 1), and the validation functions accept it.
is_red_black(): Tests all RB propertiestest_black_condition(): Verifies black-height propertyis_red_black_bst(): Verifies RB + BST orderingDefinition in file rbNode.H.
| #define COLOR | ( | p | ) | ((p)->getColor()) |
| #define RED (0) |
Test all Red-Black tree properties for a node.
Validates that:
| Node | RB node type |
| node | Node to test |
Definition at line 203 of file rbNode.H.
References BLACK, COLOR, LLINK, max(), RED, RLINK, and test_black_condition().
Referenced by main().
Verify that tree is both a valid RB tree and valid BST.
Combines RB property validation with BST ordering validation.
| Node | RB node type |
| Compare | Comparison functor for keys |
| node | Root of tree to validate |
| cmp | Comparison function object |
Definition at line 251 of file rbNode.H.
References cmp(), and is_red_black_tree().
Referenced by Aleph::HtdRbTree< Key, Compare >::verify(), and Aleph::Gen_Rb_Tree< NodeType, Key, Compare >::verify().
Test RB properties for entire subtree.
Validates the RB properties of node and of all its descendants: valid colors, no red node with a red child, and the same number of black nodes on every path down to Node::NullPtr. node itself can be red or black.
| Node | RB node type |
| node | Root of subtree to test |
Definition at line 234 of file rbNode.H.
References red_black_height().
Referenced by is_red_black_bst(), Aleph::HtdRbTree< Key, Compare >::verifyRedBlack(), and Aleph::GenTdRbTree< NodeType, Key, Compare >::verifyRedBlack().
Black height of a red-black subtree, checking all its nodes.
In one traversal, checks every node of the subtree rooted at p: its color is RED or BLACK, a red node has no red child, and every path from p down to Node::NullPtr crosses the same number of black nodes.
| Node | RB node type |
| p | Root of subtree to test |
Definition at line 164 of file rbNode.H.
References BLACK, COLOR, LLINK, RED, red_black_height(), and RLINK.
Referenced by is_red_black_tree(), and red_black_height().
Test the black-height property of an RB tree.
Verifies that all paths from node p down to Node::NullPtr have the same number of black nodes (black-height).
| Node | RB node type |
| p | Root of subtree to test |
| max | Reference to store/compare black heights (-1 initially) |
| bh | Current black height along this path (default 0) |
Definition at line 131 of file rbNode.H.
References BLACK, COLOR, LLINK, max(), RLINK, and test_black_condition().
Referenced by is_red_black(), and test_black_condition().