|
Aleph-w 7.10.0
A C++ Library for Data Structures and Algorithms
|
Top-down red-black tree with rank support (select/position). More...
#include <tpl_tdRbTreeRk.H>
Classes | |
| struct | Iterator |
| Iterator. More... | |
Public Types | |
| using | Node = NodeType< Key > |
| using | key_type = Key |
| using | compare_type = Compare |
Public Member Functions | |
| GenTdRbTreeRk () noexcept(std::is_nothrow_default_constructible_v< Node > and std::is_nothrow_default_constructible_v< Compare >) | |
| Builds an empty tree with a comparison criteria built by default. | |
| GenTdRbTreeRk (const Compare &__cmp) noexcept(std::is_nothrow_default_constructible_v< Node > and std::is_nothrow_copy_constructible_v< Compare >) | |
Builds an empty tree with the comparison criteria __cmp. | |
| GenTdRbTreeRk (GenTdRbTreeRk &&other) noexcept(bin_node_detail::nothrow_header_from_v< Node > and bin_node_detail::nothrow_compare_taken_v< Compare >) | |
Takes the nodes and the comparison criteria of other, which is left empty and can take nodes again. | |
| GenTdRbTreeRk & | operator= (GenTdRbTreeRk &&other) noexcept(std::is_nothrow_move_assignable_v< Compare >) |
Takes the nodes and the comparison criteria of other, which is left empty. | |
| GenTdRbTreeRk (const GenTdRbTreeRk &)=delete | |
| GenTdRbTreeRk & | operator= (const GenTdRbTreeRk &)=delete |
| void | reset () noexcept |
| Reset tree (does not free nodes) | |
| void | swap (GenTdRbTreeRk &other) noexcept(std::is_nothrow_swappable_v< Compare >) |
Swaps in constant time the nodes and the comparison criteria of this and other. | |
| virtual | ~GenTdRbTreeRk ()=default |
| size_t | size () const noexcept |
| Get number of nodes O(1) | |
| bool | is_empty () const noexcept |
| Check if empty. | |
| Compare & | get_compare () noexcept |
| Get comparator. | |
| const Compare & | get_compare () const noexcept |
| Node * | insert (Node *p) noexcept(nothrow_compare_v< Compare, Key >) |
| Insert a node. | |
| Node * | insert_dup (Node *p) noexcept(nothrow_compare_v< Compare, Key >) |
| Insert a node allowing duplicates. | |
| Node * | search_or_insert (Node *p) noexcept(nothrow_compare_v< Compare, Key >) |
| Search or insert. | |
| Node * | search (const Key &key) const noexcept(nothrow_compare_v< Compare, Key >) |
| Search for a key. | |
| Node * | remove (const Key &key) noexcept(nothrow_compare_v< Compare, Key >) |
| Remove node with given key. | |
| Node *& | getRoot () noexcept |
| Get root pointer. | |
| Node * | getRoot () const noexcept |
| Node * | select (size_t i) const |
| Select i-th node in order. | |
| std::pair< long, Node * > | position (const Key &key) const noexcept(nothrow_compare_copy_v< Compare, Key >) |
| Find position of a key. | |
| std::pair< long, Node * > | find_position (const Key &key) const noexcept(nothrow_compare_copy_v< Compare, Key >) |
| Find position of a key (even if not in tree). | |
| Node * | remove_pos (size_t i) |
| Remove node at position i. | |
| void | split_pos (size_t pos, GenTdRbTreeRk &t1, GenTdRbTreeRk &t2) noexcept |
| Split tree by position. | |
| bool | verify () const |
| Verify tree properties. It throws what the comparator throws. | |
Static Public Attributes | |
| static constexpr size_t | PATH_STACK_CAPACITY = 128 |
Private Member Functions | |
| bool | less (const Key &a, const Key &b) const noexcept(nothrow_compare_v< Compare, Key >) |
| Returns true if a < b according to comparator; it throws what the comparator throws. | |
| bool | equals (const Key &a, const Key &b) const noexcept(nothrow_compare_v< Compare, Key >) |
| Returns true if a == b (neither a < b nor b < a); it throws what the comparator throws. | |
| void | restoreRedCondition (Node *p, Node *&fp, Node *ffp, Node *fffp) noexcept |
| Restore red-black property after color flip. | |
| Node * | searchFlipColorsAndInsert (Node *q) noexcept(nothrow_compare_v< Compare, Key >) |
| Search for insertion point, flipping colors proactively. | |
| Node * | searchFlipColorsAndInsertDup (Node *q) noexcept(nothrow_compare_v< Compare, Key >) |
| Search for insertion point allowing duplicates. | |
| void | colorRootAsRed () noexcept |
| Color root red if safe. | |
| Node * | searchAndColorRed (const Key &key, Node *&fp, Node **stack, size_t &stack_len) noexcept(nothrow_compare_v< Compare, Key >) |
| Search for key while coloring nodes red for deletion. | |
| void | init () noexcept |
| Initialize header nodes. | |
| void | split_pos_inorder (Node *p, size_t pos, GenTdRbTreeRk &t1, GenTdRbTreeRk &t2, size_t &count) noexcept |
Static Private Member Functions | |
| static Node * | rotate_to_right_rk (Node *p, Node *pp) noexcept |
| Rotate to right with counter update. | |
| static Node * | rotate_to_left_rk (Node *p, Node *pp) noexcept |
| Rotate to left with counter update. | |
| static void | flipColors (Node *p) noexcept |
| Flip colors with counter preservation. | |
| static size_t | updateCountRec (Node *p) noexcept |
| Recursively update counts in subtree - O(n) | |
| static void | updateCountsFromStack (Node **stack, size_t len) noexcept |
| Update counts for nodes in stack (bottom-up) - O(log n) After rotations, nodes may have moved but their counts can be recalculated from their current children. | |
| static Node * | gotoLeftAndColorRed (Node *fp, Node *&ffp) noexcept |
| Descend to left child for deletion, ensuring red. | |
| static Node * | gotoRightAndColorRed (Node *fp, Node *&ffp) noexcept |
| Descend to right child for deletion, ensuring red. | |
| static void | findSuccAndSwap (Node *p, Node *&fp) noexcept |
| Find successor and swap for deletion. | |
| static void | findPredAndSwap (Node *p, Node *&fp) noexcept |
| Find predecessor and swap for deletion. | |
| static void | removeAndRendLeafRed (Node *p, Node *fp) noexcept |
| Remove node, making it a red leaf. | |
Private Attributes | |
| Node | headNode |
| Sentinel header node (parent of root) | |
| Node | headParent |
| Sentinel grandparent node. | |
| Node * | head |
| Pointer to header. | |
| Node * | fHead |
| Pointer to header's parent. | |
| Node *& | root |
| Reference to root (right child of head) | |
| Compare | cmp |
| Comparison functor. | |
Top-down red-black tree with rank support (select/position).
This class extends the top-down red-black tree algorithm with subtree counters in each node, enabling O(log n) operations for:
For O(log n) remove with rank, use Rb_Tree_Rk (bottom-up) which tracks the full path during descent.
| NodeType | Node template (typically RbNodeRk or RbNodeRkVtl). |
| Key | The type of keys stored in the tree. |
| Compare | Comparison functor for ordering keys. |
Definition at line 99 of file tpl_tdRbTreeRk.H.
| using Aleph::GenTdRbTreeRk< NodeType, Key, Compare >::compare_type = Compare |
Definition at line 104 of file tpl_tdRbTreeRk.H.
| using Aleph::GenTdRbTreeRk< NodeType, Key, Compare >::key_type = Key |
Definition at line 103 of file tpl_tdRbTreeRk.H.
| using Aleph::GenTdRbTreeRk< NodeType, Key, Compare >::Node = NodeType<Key> |
Definition at line 102 of file tpl_tdRbTreeRk.H.
|
inlinenoexcept |
Builds an empty tree with a comparison criteria built by default.
| what | the default construction of the key of a header node or of the comparison criteria throws; nothing when both are noexcept. |
Definition at line 714 of file tpl_tdRbTreeRk.H.
References Aleph::GenTdRbTreeRk< NodeType, Key, Compare >::init().
|
inlineexplicitnoexcept |
Builds an empty tree with the comparison criteria __cmp.
| [in] | __cmp | the comparison criteria, which the tree copies. |
| what | the default construction of the key of a header node or the copy of __cmp throws; nothing when both are noexcept. |
Definition at line 728 of file tpl_tdRbTreeRk.H.
References Aleph::GenTdRbTreeRk< NodeType, Key, Compare >::init().
|
inlinenoexcept |
Takes the nodes and the comparison criteria of other, which is left empty and can take nodes again.
It builds no key, if it can: the key of each of the two header nodes is built by default when that cannot throw; else it is that of the same header node of other, moved, when the move of a key cannot throw (see bin_node_detail::header_from()).
| [in,out] | other | the tree to move from. It keeps its comparison criteria, which are copied: from a const one, or from one that is not const, if they have only that copy. Criteria that cannot be copied are moved, and other keeps criteria that were moved from. |
| what | the copy of the comparison criteria throws, or their move if they cannot be copied; and what the default construction of the key of a header node throws, with a key whose move may throw too. Then other keeps its nodes. Nothing when they are noexcept. |
Definition at line 753 of file tpl_tdRbTreeRk.H.
References Aleph::GenTdRbTreeRk< NodeType, Key, Compare >::init(), and Aleph::GenTdRbTreeRk< NodeType, Key, Compare >::root.
|
delete |
|
virtualdefault |
|
inlineprivatenoexcept |
Color root red if safe.
Definition at line 626 of file tpl_tdRbTreeRk.H.
References Aleph::and, BLACK, COLOR, LLINK, RED, RLINK, and Aleph::GenTdRbTreeRk< NodeType, Key, Compare >::root.
Referenced by Aleph::GenTdRbTreeRk< NodeType, Key, Compare >::searchAndColorRed().
|
inlineprivatenoexcept |
Returns true if a == b (neither a < b nor b < a); it throws what the comparator throws.
Definition at line 127 of file tpl_tdRbTreeRk.H.
References Aleph::and, and Aleph::GenTdRbTreeRk< NodeType, Key, Compare >::cmp.
Referenced by Aleph::GenTdRbTreeRk< NodeType, Key, Compare >::remove(), Aleph::GenTdRbTreeRk< NodeType, Key, Compare >::search(), Aleph::GenTdRbTreeRk< NodeType, Key, Compare >::searchAndColorRed(), and Aleph::GenTdRbTreeRk< NodeType, Key, Compare >::searchFlipColorsAndInsert().
|
inlinenoexcept |
Find position of a key (even if not in tree).
| key | Key to search for. |
| anything | that the comparison or its copy throws; the search does not modify the tree, so it is left as it was. |
noexcept only if the comparison and its copy cannot throw, so that what it throws reaches the caller. Definition at line 998 of file tpl_tdRbTreeRk.H.
References Aleph::GenTdRbTreeRk< NodeType, Key, Compare >::cmp, Aleph::GenTdRbTreeRk< NodeType, Key, Compare >::find_position(), r, and Aleph::GenTdRbTreeRk< NodeType, Key, Compare >::root.
Referenced by Aleph::GenTdRbTreeRk< NodeType, Key, Compare >::find_position().
|
inlinestaticprivatenoexcept |
Find predecessor and swap for deletion.
Definition at line 573 of file tpl_tdRbTreeRk.H.
References COLOR, Aleph::COUNT(), Aleph::GenTdRbTreeRk< NodeType, Key, Compare >::gotoLeftAndColorRed(), Aleph::GenTdRbTreeRk< NodeType, Key, Compare >::gotoRightAndColorRed(), LLINK, pred, and RLINK.
Referenced by Aleph::GenTdRbTreeRk< NodeType, Key, Compare >::removeAndRendLeafRed().
|
inlinestaticprivatenoexcept |
Find successor and swap for deletion.
Definition at line 519 of file tpl_tdRbTreeRk.H.
References COLOR, Aleph::COUNT(), Aleph::GenTdRbTreeRk< NodeType, Key, Compare >::gotoLeftAndColorRed(), Aleph::GenTdRbTreeRk< NodeType, Key, Compare >::gotoRightAndColorRed(), LLINK, and RLINK.
Referenced by Aleph::GenTdRbTreeRk< NodeType, Key, Compare >::removeAndRendLeafRed().
|
inlinestaticprivatenoexcept |
Flip colors with counter preservation.
Definition at line 224 of file tpl_tdRbTreeRk.H.
References Aleph::and, BLACK, COLOR, LLINK, RED, and RLINK.
Referenced by Aleph::GenTdRbTreeRk< NodeType, Key, Compare >::searchFlipColorsAndInsert(), and Aleph::GenTdRbTreeRk< NodeType, Key, Compare >::searchFlipColorsAndInsertDup().
|
inlinenoexcept |
Definition at line 820 of file tpl_tdRbTreeRk.H.
References Aleph::GenTdRbTreeRk< NodeType, Key, Compare >::cmp.
|
inlinenoexcept |
Get comparator.
Definition at line 819 of file tpl_tdRbTreeRk.H.
References Aleph::GenTdRbTreeRk< NodeType, Key, Compare >::cmp.
|
inlinenoexcept |
Definition at line 959 of file tpl_tdRbTreeRk.H.
References Aleph::GenTdRbTreeRk< NodeType, Key, Compare >::root.
|
inlinenoexcept |
Get root pointer.
Definition at line 958 of file tpl_tdRbTreeRk.H.
References Aleph::GenTdRbTreeRk< NodeType, Key, Compare >::root.
|
inlinestaticprivatenoexcept |
Descend to left child for deletion, ensuring red.
Definition at line 407 of file tpl_tdRbTreeRk.H.
References Aleph::and, BLACK, COLOR, LLINK, RED, RLINK, Aleph::GenTdRbTreeRk< NodeType, Key, Compare >::rotate_to_left_rk(), and Aleph::GenTdRbTreeRk< NodeType, Key, Compare >::rotate_to_right_rk().
Referenced by Aleph::GenTdRbTreeRk< NodeType, Key, Compare >::findPredAndSwap(), Aleph::GenTdRbTreeRk< NodeType, Key, Compare >::findSuccAndSwap(), and Aleph::GenTdRbTreeRk< NodeType, Key, Compare >::searchAndColorRed().
|
inlinestaticprivatenoexcept |
Descend to right child for deletion, ensuring red.
Definition at line 463 of file tpl_tdRbTreeRk.H.
References Aleph::and, BLACK, COLOR, LLINK, RED, RLINK, Aleph::GenTdRbTreeRk< NodeType, Key, Compare >::rotate_to_left_rk(), and Aleph::GenTdRbTreeRk< NodeType, Key, Compare >::rotate_to_right_rk().
Referenced by Aleph::GenTdRbTreeRk< NodeType, Key, Compare >::findPredAndSwap(), Aleph::GenTdRbTreeRk< NodeType, Key, Compare >::findSuccAndSwap(), and Aleph::GenTdRbTreeRk< NodeType, Key, Compare >::searchAndColorRed().
|
inlineprivatenoexcept |
Initialize header nodes.
Definition at line 698 of file tpl_tdRbTreeRk.H.
References BLACK, COLOR, Aleph::COUNT(), Aleph::GenTdRbTreeRk< NodeType, Key, Compare >::fHead, Aleph::GenTdRbTreeRk< NodeType, Key, Compare >::head, and RLINK.
Referenced by Aleph::GenTdRbTreeRk< NodeType, Key, Compare >::GenTdRbTreeRk(), Aleph::GenTdRbTreeRk< NodeType, Key, Compare >::GenTdRbTreeRk(), and Aleph::GenTdRbTreeRk< NodeType, Key, Compare >::GenTdRbTreeRk().
|
inlinenoexcept |
Insert a node.
| p | Node to insert (must be red with null children). |
| anything | that the comparison throws; the color flips and rotations done on the way down leave a valid red-black tree with right counters, and p is linked after the last comparison, so the tree keeps its keys, without p. |
noexcept only if the comparison cannot throw, so that what it throws reaches the caller. Definition at line 832 of file tpl_tdRbTreeRk.H.
References COLOR, Aleph::COUNT(), RED, Aleph::GenTdRbTreeRk< NodeType, Key, Compare >::root, and Aleph::GenTdRbTreeRk< NodeType, Key, Compare >::searchFlipColorsAndInsert().
|
inlinenoexcept |
Insert a node allowing duplicates.
| p | Node to insert (must be red with null children). |
| anything | that the comparison throws; then the tree is valid with its keys, without p, as in insert(). |
noexcept only if the comparison cannot throw, so that what it throws reaches the caller. Definition at line 855 of file tpl_tdRbTreeRk.H.
References COLOR, Aleph::COUNT(), RED, Aleph::GenTdRbTreeRk< NodeType, Key, Compare >::root, and Aleph::GenTdRbTreeRk< NodeType, Key, Compare >::searchFlipColorsAndInsertDup().
|
inlinenoexcept |
Check if empty.
Definition at line 816 of file tpl_tdRbTreeRk.H.
References Aleph::GenTdRbTreeRk< NodeType, Key, Compare >::root.
|
inlineprivatenoexcept |
Returns true if a < b according to comparator; it throws what the comparator throws.
Definition at line 119 of file tpl_tdRbTreeRk.H.
References Aleph::GenTdRbTreeRk< NodeType, Key, Compare >::cmp.
|
delete |
|
inlinenoexcept |
Takes the nodes and the comparison criteria of other, which is left empty.
| [in,out] | other | the tree to move from. |
*this. | what | the move assignment of the comparison criteria throws, which goes first: then the nodes stay where they were. |
Definition at line 773 of file tpl_tdRbTreeRk.H.
References Aleph::GenTdRbTreeRk< NodeType, Key, Compare >::cmp, and Aleph::GenTdRbTreeRk< NodeType, Key, Compare >::root.
|
inlinenoexcept |
Find position of a key.
| key | Key to search for. |
| anything | that the comparison or its copy throws; the search does not modify the tree, so it is left as it was. |
noexcept only if the comparison and its copy cannot throw, so that what it throws reaches the caller. Definition at line 981 of file tpl_tdRbTreeRk.H.
References Aleph::GenTdRbTreeRk< NodeType, Key, Compare >::cmp, Aleph::inorder_position(), and Aleph::GenTdRbTreeRk< NodeType, Key, Compare >::root.
|
inlinenoexcept |
Remove node with given key.
| key | Key to remove. |
| anything | that the comparison throws; the recolorings and rotations done on the way down leave a valid red-black tree with right counters, and the node is unlinked after the last comparison, so the tree keeps its keys. |
noexcept only if the comparison cannot throw, so that what it throws reaches the caller. Definition at line 929 of file tpl_tdRbTreeRk.H.
References Aleph::GenTdRbTreeRk< NodeType, Key, Compare >::equals(), KEY, Aleph::GenTdRbTreeRk< NodeType, Key, Compare >::PATH_STACK_CAPACITY, Aleph::GenTdRbTreeRk< NodeType, Key, Compare >::removeAndRendLeafRed(), Aleph::GenTdRbTreeRk< NodeType, Key, Compare >::root, Aleph::GenTdRbTreeRk< NodeType, Key, Compare >::searchAndColorRed(), and Aleph::GenTdRbTreeRk< NodeType, Key, Compare >::updateCountRec().
Referenced by Aleph::GenTdRbTreeRk< NodeType, Key, Compare >::remove_pos(), and TEST().
|
inline |
Remove node at position i.
| i | Zero-based position. |
Definition at line 1011 of file tpl_tdRbTreeRk.H.
References KEY, Aleph::GenTdRbTreeRk< NodeType, Key, Compare >::remove(), and Aleph::GenTdRbTreeRk< NodeType, Key, Compare >::select().
|
inlinestaticprivatenoexcept |
Remove node, making it a red leaf.
Definition at line 678 of file tpl_tdRbTreeRk.H.
References Aleph::GenTdRbTreeRk< NodeType, Key, Compare >::findPredAndSwap(), Aleph::GenTdRbTreeRk< NodeType, Key, Compare >::findSuccAndSwap(), LLINK, and RLINK.
Referenced by Aleph::GenTdRbTreeRk< NodeType, Key, Compare >::remove().
|
inlinenoexcept |
Reset tree (does not free nodes)
Definition at line 790 of file tpl_tdRbTreeRk.H.
References Aleph::GenTdRbTreeRk< NodeType, Key, Compare >::root.
|
inlineprivatenoexcept |
Restore red-black property after color flip.
Definition at line 178 of file tpl_tdRbTreeRk.H.
References Aleph::and, BLACK, COLOR, LLINK, RED, RLINK, Aleph::GenTdRbTreeRk< NodeType, Key, Compare >::root, Aleph::GenTdRbTreeRk< NodeType, Key, Compare >::rotate_to_left_rk(), and Aleph::GenTdRbTreeRk< NodeType, Key, Compare >::rotate_to_right_rk().
Referenced by Aleph::GenTdRbTreeRk< NodeType, Key, Compare >::searchFlipColorsAndInsert(), and Aleph::GenTdRbTreeRk< NodeType, Key, Compare >::searchFlipColorsAndInsertDup().
|
inlinestaticprivatenoexcept |
Rotate to left with counter update.
Definition at line 156 of file tpl_tdRbTreeRk.H.
References Aleph::COUNT(), LLINK, and RLINK.
Referenced by Aleph::GenTdRbTreeRk< NodeType, Key, Compare >::gotoLeftAndColorRed(), Aleph::GenTdRbTreeRk< NodeType, Key, Compare >::gotoRightAndColorRed(), and Aleph::GenTdRbTreeRk< NodeType, Key, Compare >::restoreRedCondition().
|
inlinestaticprivatenoexcept |
Rotate to right with counter update.
Definition at line 134 of file tpl_tdRbTreeRk.H.
References Aleph::COUNT(), LLINK, and RLINK.
Referenced by Aleph::GenTdRbTreeRk< NodeType, Key, Compare >::gotoLeftAndColorRed(), Aleph::GenTdRbTreeRk< NodeType, Key, Compare >::gotoRightAndColorRed(), and Aleph::GenTdRbTreeRk< NodeType, Key, Compare >::restoreRedCondition().
|
inlinenoexcept |
Search for a key.
| key | Key to search for. |
| anything | that the comparison throws; the search does not modify the tree, so it is left as it was. |
noexcept only if the comparison cannot throw, so that what it throws reaches the caller. Definition at line 905 of file tpl_tdRbTreeRk.H.
References Aleph::GenTdRbTreeRk< NodeType, Key, Compare >::equals(), KEY, LLINK, RLINK, and Aleph::GenTdRbTreeRk< NodeType, Key, Compare >::root.
Referenced by Aleph::GenTdRbTreeRk< NodeType, Key, Compare >::search_or_insert(), TEST(), and TEST_F().
|
inlinenoexcept |
Search or insert.
| p | Node to search or insert (must be red with null children). |
| anything | that the comparison throws; then the tree is valid with its keys, without p, as in insert(). |
noexcept only if the comparison cannot throw, so that what it throws reaches the caller. Definition at line 878 of file tpl_tdRbTreeRk.H.
References COLOR, Aleph::COUNT(), KEY, RED, Aleph::GenTdRbTreeRk< NodeType, Key, Compare >::root, Aleph::GenTdRbTreeRk< NodeType, Key, Compare >::search(), and Aleph::GenTdRbTreeRk< NodeType, Key, Compare >::searchFlipColorsAndInsert().
|
inlineprivatenoexcept |
Search for key while coloring nodes red for deletion.
Also collects visited nodes in stack for count updates. Each step leaves a valid red-black tree with right counters, so a comparison that throws leaves a valid tree with all its keys.
Definition at line 639 of file tpl_tdRbTreeRk.H.
References Aleph::GenTdRbTreeRk< NodeType, Key, Compare >::colorRootAsRed(), Aleph::GenTdRbTreeRk< NodeType, Key, Compare >::equals(), Aleph::GenTdRbTreeRk< NodeType, Key, Compare >::fHead, Aleph::GenTdRbTreeRk< NodeType, Key, Compare >::gotoLeftAndColorRed(), Aleph::GenTdRbTreeRk< NodeType, Key, Compare >::gotoRightAndColorRed(), Aleph::GenTdRbTreeRk< NodeType, Key, Compare >::head, KEY, LLINK, RLINK, and Aleph::GenTdRbTreeRk< NodeType, Key, Compare >::root.
Referenced by Aleph::GenTdRbTreeRk< NodeType, Key, Compare >::remove().
|
inlineprivatenoexcept |
Search for insertion point, flipping colors proactively.
Uses stack to track path for O(log n) count updates. Each color flip and rotation leaves a valid red-black tree with right counters, and q is linked after the last comparison, so a comparison that throws leaves a valid tree without q.
Definition at line 240 of file tpl_tdRbTreeRk.H.
References Aleph::and, BLACK, COLOR, Aleph::GenTdRbTreeRk< NodeType, Key, Compare >::equals(), Aleph::GenTdRbTreeRk< NodeType, Key, Compare >::fHead, Aleph::GenTdRbTreeRk< NodeType, Key, Compare >::flipColors(), Aleph::GenTdRbTreeRk< NodeType, Key, Compare >::head, KEY, LLINK, Aleph::GenTdRbTreeRk< NodeType, Key, Compare >::PATH_STACK_CAPACITY, RED, Aleph::GenTdRbTreeRk< NodeType, Key, Compare >::restoreRedCondition(), RLINK, Aleph::GenTdRbTreeRk< NodeType, Key, Compare >::root, and Aleph::GenTdRbTreeRk< NodeType, Key, Compare >::updateCountsFromStack().
Referenced by Aleph::GenTdRbTreeRk< NodeType, Key, Compare >::insert(), and Aleph::GenTdRbTreeRk< NodeType, Key, Compare >::search_or_insert().
|
inlineprivatenoexcept |
Search for insertion point allowing duplicates.
Uses stack for O(log n) count updates. As searchFlipColorsAndInsert(), a comparison that throws leaves a valid tree without q.
Definition at line 315 of file tpl_tdRbTreeRk.H.
References Aleph::and, BLACK, COLOR, Aleph::GenTdRbTreeRk< NodeType, Key, Compare >::fHead, Aleph::GenTdRbTreeRk< NodeType, Key, Compare >::flipColors(), Aleph::GenTdRbTreeRk< NodeType, Key, Compare >::head, KEY, LLINK, Aleph::GenTdRbTreeRk< NodeType, Key, Compare >::PATH_STACK_CAPACITY, RED, Aleph::GenTdRbTreeRk< NodeType, Key, Compare >::restoreRedCondition(), RLINK, Aleph::GenTdRbTreeRk< NodeType, Key, Compare >::root, and Aleph::GenTdRbTreeRk< NodeType, Key, Compare >::updateCountsFromStack().
Referenced by Aleph::GenTdRbTreeRk< NodeType, Key, Compare >::insert_dup().
|
inline |
Select i-th node in order.
| i | Zero-based position. |
| out_of_range | if i >= size(). |
Definition at line 968 of file tpl_tdRbTreeRk.H.
References Aleph::GenTdRbTreeRk< NodeType, Key, Compare >::root, and Aleph::select().
Referenced by Aleph::GenTdRbTreeRk< NodeType, Key, Compare >::remove_pos(), TEST(), and TEST().
|
inlinenoexcept |
Get number of nodes O(1)
Definition at line 813 of file tpl_tdRbTreeRk.H.
References Aleph::COUNT(), and Aleph::GenTdRbTreeRk< NodeType, Key, Compare >::root.
Referenced by Aleph::GenTdRbTreeRk< NodeType, Key, Compare >::split_pos(), TEST(), TEST(), TEST(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), and TEST_F().
|
inlinenoexcept |
Split tree by position.
| pos | Split position. |
| t1 | Receives nodes [0, pos). |
| t2 | Receives nodes [pos, size). |
std::terminate()). noexcept because it inserts the nodes one by one in t1 and t2, which compares: a comparison that threw in the middle would leave nodes out of every tree. Definition at line 1029 of file tpl_tdRbTreeRk.H.
References Aleph::count(), Aleph::GenTdRbTreeRk< NodeType, Key, Compare >::root, Aleph::GenTdRbTreeRk< NodeType, Key, Compare >::size(), and Aleph::GenTdRbTreeRk< NodeType, Key, Compare >::split_pos_inorder().
|
inlineprivatenoexcept |
Definition at line 1055 of file tpl_tdRbTreeRk.H.
References Aleph::count(), LLINK, RLINK, and Aleph::GenTdRbTreeRk< NodeType, Key, Compare >::split_pos_inorder().
Referenced by Aleph::GenTdRbTreeRk< NodeType, Key, Compare >::split_pos(), and Aleph::GenTdRbTreeRk< NodeType, Key, Compare >::split_pos_inorder().
|
inlinenoexcept |
Swaps in constant time the nodes and the comparison criteria of this and other.
| [in,out] | other | the tree to swap with. |
| what | the swap of the comparison criteria throws, which goes first: then the nodes stay where they were. |
Definition at line 802 of file tpl_tdRbTreeRk.H.
References Aleph::GenTdRbTreeRk< NodeType, Key, Compare >::cmp, and Aleph::GenTdRbTreeRk< NodeType, Key, Compare >::root.
|
inlinestaticprivatenoexcept |
Recursively update counts in subtree - O(n)
Definition at line 381 of file tpl_tdRbTreeRk.H.
References Aleph::COUNT(), LLINK, RLINK, and Aleph::GenTdRbTreeRk< NodeType, Key, Compare >::updateCountRec().
Referenced by Aleph::GenTdRbTreeRk< NodeType, Key, Compare >::remove(), and Aleph::GenTdRbTreeRk< NodeType, Key, Compare >::updateCountRec().
|
inlinestaticprivatenoexcept |
Update counts for nodes in stack (bottom-up) - O(log n) After rotations, nodes may have moved but their counts can be recalculated from their current children.
Definition at line 395 of file tpl_tdRbTreeRk.H.
References Aleph::COUNT(), LLINK, and RLINK.
Referenced by Aleph::GenTdRbTreeRk< NodeType, Key, Compare >::searchFlipColorsAndInsert(), and Aleph::GenTdRbTreeRk< NodeType, Key, Compare >::searchFlipColorsAndInsertDup().
|
inline |
Verify tree properties. It throws what the comparator throws.
Definition at line 1079 of file tpl_tdRbTreeRk.H.
References Aleph::and, Aleph::check_rank_tree(), Aleph::GenTdRbTreeRk< NodeType, Key, Compare >::cmp, Aleph::is_red_black_bst_rk(), and Aleph::GenTdRbTreeRk< NodeType, Key, Compare >::root.
Referenced by TEST(), TEST(), TEST(), TEST_F(), TEST_F(), and TEST_F().
|
private |
Comparison functor.
Definition at line 115 of file tpl_tdRbTreeRk.H.
Referenced by Aleph::GenTdRbTreeRk< NodeType, Key, Compare >::equals(), Aleph::GenTdRbTreeRk< NodeType, Key, Compare >::find_position(), Aleph::GenTdRbTreeRk< NodeType, Key, Compare >::get_compare(), Aleph::GenTdRbTreeRk< NodeType, Key, Compare >::get_compare(), Aleph::GenTdRbTreeRk< NodeType, Key, Compare >::less(), Aleph::GenTdRbTreeRk< NodeType, Key, Compare >::operator=(), Aleph::GenTdRbTreeRk< NodeType, Key, Compare >::position(), Aleph::GenTdRbTreeRk< NodeType, Key, Compare >::swap(), and Aleph::GenTdRbTreeRk< NodeType, Key, Compare >::verify().
|
private |
Pointer to header's parent.
Definition at line 113 of file tpl_tdRbTreeRk.H.
Referenced by Aleph::GenTdRbTreeRk< NodeType, Key, Compare >::init(), Aleph::GenTdRbTreeRk< NodeType, Key, Compare >::searchAndColorRed(), Aleph::GenTdRbTreeRk< NodeType, Key, Compare >::searchFlipColorsAndInsert(), and Aleph::GenTdRbTreeRk< NodeType, Key, Compare >::searchFlipColorsAndInsertDup().
|
private |
Pointer to header.
Definition at line 112 of file tpl_tdRbTreeRk.H.
Referenced by Aleph::GenTdRbTreeRk< NodeType, Key, Compare >::init(), Aleph::GenTdRbTreeRk< NodeType, Key, Compare >::searchAndColorRed(), Aleph::GenTdRbTreeRk< NodeType, Key, Compare >::searchFlipColorsAndInsert(), and Aleph::GenTdRbTreeRk< NodeType, Key, Compare >::searchFlipColorsAndInsertDup().
|
private |
Sentinel header node (parent of root)
Definition at line 110 of file tpl_tdRbTreeRk.H.
|
private |
Sentinel grandparent node.
Definition at line 111 of file tpl_tdRbTreeRk.H.
|
staticconstexpr |
|
private |
Reference to root (right child of head)
Definition at line 114 of file tpl_tdRbTreeRk.H.
Referenced by Aleph::GenTdRbTreeRk< NodeType, Key, Compare >::GenTdRbTreeRk(), Aleph::GenTdRbTreeRk< NodeType, Key, Compare >::colorRootAsRed(), Aleph::GenTdRbTreeRk< NodeType, Key, Compare >::find_position(), Aleph::GenTdRbTreeRk< NodeType, Key, Compare >::getRoot(), Aleph::GenTdRbTreeRk< NodeType, Key, Compare >::getRoot(), Aleph::GenTdRbTreeRk< NodeType, Key, Compare >::insert(), Aleph::GenTdRbTreeRk< NodeType, Key, Compare >::insert_dup(), Aleph::GenTdRbTreeRk< NodeType, Key, Compare >::is_empty(), Aleph::GenTdRbTreeRk< NodeType, Key, Compare >::operator=(), Aleph::GenTdRbTreeRk< NodeType, Key, Compare >::position(), Aleph::GenTdRbTreeRk< NodeType, Key, Compare >::remove(), Aleph::GenTdRbTreeRk< NodeType, Key, Compare >::reset(), Aleph::GenTdRbTreeRk< NodeType, Key, Compare >::restoreRedCondition(), Aleph::GenTdRbTreeRk< NodeType, Key, Compare >::search(), Aleph::GenTdRbTreeRk< NodeType, Key, Compare >::search_or_insert(), Aleph::GenTdRbTreeRk< NodeType, Key, Compare >::searchAndColorRed(), Aleph::GenTdRbTreeRk< NodeType, Key, Compare >::searchFlipColorsAndInsert(), Aleph::GenTdRbTreeRk< NodeType, Key, Compare >::searchFlipColorsAndInsertDup(), Aleph::GenTdRbTreeRk< NodeType, Key, Compare >::select(), Aleph::GenTdRbTreeRk< NodeType, Key, Compare >::size(), Aleph::GenTdRbTreeRk< NodeType, Key, Compare >::split_pos(), Aleph::GenTdRbTreeRk< NodeType, Key, Compare >::swap(), and Aleph::GenTdRbTreeRk< NodeType, Key, Compare >::verify().