|
Aleph-w 7.10.0
A C++ Library for Data Structures and Algorithms
|
AVL tree node with balance factor. More...
#include <tpl_binNodeUtils.H>Go to the source code of this file.
Classes | |
| class | AvlNode_Data |
| Data portion of an AVL tree node. More... | |
| class | AvlNode< Key > |
| Declare AvlNode type with 40-byte pool allocation. More... | |
| class | AvlNodeVtl< Key > |
Macros | |
| #define | DIFF(p) ((p)->getDiff()) |
| Access the balance factor of node p. | |
Functions | |
| template<class Node > | |
| int | checked_avl_height (Node *p) noexcept |
| Height of an AVL subtree, checking all its nodes. | |
| template<class Node > | |
| bool | is_avl (Node *p) |
| Validate that a tree satisfies AVL properties. | |
AVL tree node with balance factor.
This file defines the AvlNode structure for AVL trees, including the balance factor (height difference) attribute and validation functions.
An AVL tree maintains the invariant that for every node: |height(left) - height(right)| ≤ 1
The balance factor (diff) stores: height(right) - height(left) Valid values are -1, 0, or +1.
| diff | Meaning |
|---|---|
| -1 | Left subtree is 1 taller |
| 0 | Both subtrees have equal height |
| +1 | Right subtree is 1 taller |
Definition in file avlNode.H.
| #define DIFF | ( | p | ) | ((p)->getDiff()) |
Height of an AVL subtree, checking all its nodes.
In one traversal, checks at every node of the subtree rooted at p that the heights of its two subtrees differ by at most one and that its stored balance factor is that difference.
| Node | AVL node type |
| p | Root of subtree to validate |
Definition at line 114 of file avlNode.H.
References checked_avl_height(), Aleph::diff(), DIFF, LLINK, and RLINK.
Referenced by checked_avl_height(), and is_avl().
Validate that a tree satisfies AVL properties.
Checks that:
It does not look at the keys; Gen_Avl_Tree::verify() also checks their order.
| Node | AVL node type |
| p | Root of subtree to validate |
Definition at line 160 of file avlNode.H.
References checked_avl_height().
Referenced by main(), TEST(), TEST(), and Aleph::Gen_Avl_Tree< NodeType, Key, Compare >::verify().