Intrusive Binary Tree, Node.
- Template Parameters
-
R | The class that will be the owner of the List. Must derive from TreeInRoot<R, N, K, n> |
N | The class that will be the nodes of the List. Must derive from TreeInNode<R, N, K, n> |
K | The class defining the Key used to lookup Nodes in the tree. |
s | The ContainerThreadSafety value to define the thread safety model of the Container |
n | A numerical parameter to allow a give List/Node combination to have multiple list-node relationships. Defaults to 0 if not provided. |
- Invariant
New:
- if m_right == nullptr:
- level == 1
- m_left == nullptr
- if m_left != nullptr:
- m_left->m_level + 1 == level
- m_right != nullptr = if m_right != nullptr:
- m_right->m_level == m_level || m_right->m_level + 1 == m_level
- if m_right->m_right != nullptr:
- m_right->m_right->m_level < m_level // only 1 stay at level in a row in a row)
- if level > 1:
- m_left != nullptr
- m_right != nullptr
Simplified if null items have level == 0
- m_level == m_left->m_level + 1
- m_level == m_right->m_level + 1 || m_right->m_right->m_level + 1
From TreeInNode:
- if m_root == NULL: // Free Node
- m_parent == NULL
- m_left == NULL
- m_right == NULL
- if m_root != NULL and m_parent == NULL // Base Node
- if m_parent != nullptr: // Child Node
- Either m_parent->m_left or parent->m_right == this
- if m_left != nullptr
- m_left->m_parent = this
- m_left->m_root == m_root
- m_root->compare(*this, *m_left) <= 0
- m_root->compare(*m_left, *this) >= 0
- if m_right != nullptr:
- m_right->m_parent = this
- m_right->m_root == m_root
- m_root->compare(*this, *m_right) >= 0
- m_root->compare(*m_right, *this) <= 0
- See also
- AATreeInRoot
|
inlineprotectedvirtualinherited |
Remove node from whatever tree it is on, if it is on a tree.
Delete Node N
Simple Cases, Not both childern (x is empty link)
P P P P P P
| => x | => | | => |
N N L N R
x x / x \
L R
Rebalance at P
More Complicated, as we have both childern
More Complicated Special Case
P P P P
| => | | => |
N D N L
/ \ / \ / \ / \
L R L R L R A R
\ \ / x
A A A
\ \
B B
\ \
D C
/ x
C
Rebalance at B. D might be L if it had no right child in which case rebalance at L
L < A < B < C < D < N < R
Link to P either a left or right, or Root if P is NULL.
x indicates NULL links
Set our Container.
Used to allow to Node to record what Container it is in. Used only if safety method need resources from the Container, like a Mutex
If an operation changes the root of a node, then it needs to save the original root to exit the critical section on that container that it entered before the operation.
Referenced by ContainerNode< s >::ContainerNode(), DListInNode< R, N, s, n >::setRoot(), ListInNode< R, N, s, n >::setRoot(), and TreeInNode< R, N, K, s, n >::setRoot().