|
Aleph-w 7.10.0
A C++ Library for Data Structures and Algorithms
|
Functor encompassing basic operation for binary search trees. More...
#include <tpl_binTreeOps.H>
Public Types | |
| using | Key = typename Node::key_type |
| using | key_type = typename Node::key_type |
| The type of key. | |
Public Member Functions | |
| Cmp & | key_comp () noexcept |
| Return the comparison criteria. | |
| Cmp & | get_compare () noexcept |
See key_comp(). | |
| BinTree_Operation (Cmp cmp_=Cmp()) noexcept(std::is_nothrow_constructible_v< Cmp, Cmp & >) | |
| The type of key. | |
| Node * | search (Node *root, const Key &key) noexcept(nothrow_compare_v< Cmp, Key >) |
| Search a node with a specific key. | |
| Node * | search_parent (Node *root, const Key &key, Node *&parent) noexcept(nothrow_compare_v< Cmp, Key >) |
| Search a key and find its node and parent. | |
| Node * | search_rank_parent (Node *root, const Key &key) noexcept(nothrow_compare_v< Cmp, Key >) |
| Rank search of a key in a binary search tree. | |
| Node * | insert (Node *&root, Node *p) noexcept(nothrow_compare_v< Cmp, Key >) |
Insert a node p in a binary search tree. | |
| Node * | insert_dup (Node *&root, Node *p) noexcept(nothrow_compare_v< Cmp, Key >) |
Insert a node p in a binary search tree. | |
| Node * | search_or_insert (Node *&r, Node *p) noexcept(nothrow_compare_v< Cmp, Key >) |
| Search or insert a node in a binary search tree. | |
| bool | split_key_rec (Node *&root, const Key &key, Node *&ts, Node *&tg) noexcept(nothrow_compare_v< Cmp, Key >) |
| Split recursively according to a key. | |
| void | split_key_dup_rec (Node *&root, const typename Node::key_type &key, Node *&ts, Node *&tg) noexcept(nothrow_compare_v< Cmp, Key >) |
| Split a tree according to a key value. | |
| Node * | remove (Node *&root, const Key &key) noexcept(nothrow_compare_v< Cmp, Key >) |
| Remove a key from a binary search tree. | |
| Node * | insert_root (Node *&root, Node *p) noexcept(nothrow_compare_v< Cmp, Key >) |
Insert the node p as the root of a binary search tree. | |
| Node * | insert_dup_root (Node *&root, Node *p) noexcept(nothrow_compare_v< Cmp, Key >) |
Insert node p as root of a binary search tree. | |
| Node * | join_preorder (Node *t1, Node *t2, Node *&dup) noexcept |
| Union of two binary search trees. | |
| Node * | join (Node *t1, Node *t2, Node *&dup) noexcept |
| Fast union of two binary search trees. | |
| void | split_key (Node *root, const Key &key, Node *&l, Node *&r) noexcept |
| Split a binary search tree according to a key. | |
| Node * | insert_root_rec (Node *root, Node *p) noexcept(nothrow_compare_v< Cmp, Key >) |
| Insert a node as root in a binary search tree. | |
| Node * | search_or_insert_root_rec (Node *root, Node *p) noexcept(nothrow_compare_v< Cmp, Key >) |
Search and eventually insert p as root in a binary search tree. | |
Protected Attributes | |
| Cmp | cmp |
Private Member Functions | |
| bool | split_key_rec_helper (Node *root, const Key &key, Node *&ts, Node *&tg) noexcept(nothrow_compare_v< Cmp, Key >) |
| void | split_key_dup_rec_helper (Node *root, const typename Node::key_type &key, Node *&ts, Node *&tg) noexcept(nothrow_compare_v< Cmp, Key >) |
Functor encompassing basic operation for binary search trees.
The operations that compare keys are noexcept only if the comparison cannot throw (nothrow_compare_v). Those that compare before they change the tree let what the comparison throws reach the caller, with the tree as it was; join_preorder(), join() and split_key() change the tree between comparisons, and stay noexcept: their comparison must not throw.
Definition at line 65 of file tpl_binTreeOps.H.
| using Aleph::BinTree_Operation< Node, Cmp >::Key = typename Node::key_type |
Definition at line 77 of file tpl_binTreeOps.H.
| using Aleph::BinTree_Operation< Node, Cmp >::key_type = typename Node::key_type |
The type of key.
Definition at line 79 of file tpl_binTreeOps.H.
|
inlinenoexcept |
The type of key.
Initialize the functor with comparison criteria cmp_.
| [in] | cmp_ | the comparison criteria, which the functor copies. |
| anything | that the copy of Cmp throws; it is noexcept only if that copy cannot throw, so that what it throws reaches the caller. |
Definition at line 88 of file tpl_binTreeOps.H.
|
inlinenoexcept |
See key_comp().
Definition at line 75 of file tpl_binTreeOps.H.
References Aleph::BinTree_Operation< Node, Cmp >::cmp.
Insert a node p in a binary search tree.
insert(root, p) inserts the node p in the binary search tree with root
| [in,out] | root | of tree |
| [in] | p | pointer to the node to be inserted |
p if this was inserted; that is if p->get_key() is not in the tree; otherwise, Node::NullPtr is returned | anything | that the comparison throws; p is linked only after the last comparison, so the tree is left as it was. |
noexcept only if the comparison cannot throw, so that what it throws reaches the caller. Definition at line 170 of file tpl_binTreeOps.H.
References Aleph::BinTree_Operation< Node, Cmp >::cmp, Aleph::BinTree_Operation< Node, Cmp >::insert(), KEY, LLINK, RLINK, and root().
Referenced by Aleph::BinTree_Operation< Node, Cmp >::insert(), Aleph::GenBinTree< NodeType, Key, Compare >::insert(), Aleph::BinTree_Operation< Node, Cmp >::join(), and Aleph::BinTree_Operation< Node, Cmp >::join_preorder().
Insert a node p in a binary search tree.
insert_dup(root, p) inserts the node p in the binary search tree with root. The key contained in p can be already present in the tree.
| [in,out] | root | of tree |
| [in] | p | pointer to the node to be inserted |
p | anything | that the comparison throws; p is linked only after the last comparison, so the tree is left as it was. |
noexcept only if the comparison cannot throw, so that what it throws reaches the caller. Definition at line 206 of file tpl_binTreeOps.H.
References Aleph::BinTree_Operation< Node, Cmp >::cmp, Aleph::BinTree_Operation< Node, Cmp >::insert_dup(), KEY, LLINK, RLINK, and root().
Referenced by Aleph::BinTree_Operation< Node, Cmp >::insert_dup(), and Aleph::GenBinTree< NodeType, Key, Compare >::insert_dup().
|
inlinenoexcept |
Insert node p as root of a binary search tree.
The key of p can be duplicated.
| [in,out] | root | of tree |
| [in] | p | node to insert as root |
p which has became the root of tree | anything | that the comparison throws; the split compares before it changes the tree, so the tree is left as it was. |
noexcept only if the comparison cannot throw, so that what it throws reaches the caller. Definition at line 446 of file tpl_binTreeOps.H.
References KEY, LLINK, RLINK, root(), and Aleph::BinTree_Operation< Node, Cmp >::split_key_dup_rec().
Insert the node p as the root of a binary search tree.
insert_root(root, p) inserts in the tree root the node p. After insertion, p becomes the new root of tree.
| [in,out] | root | of binary search tree |
| [in] | p | pointer to node to insert |
p if this was inserted; that is, if p->get_key() was not present in the tree. Otherwise, no insertion is done and Node::NullPtr is returned | anything | that the comparison throws; the split compares before it changes the tree, so the tree is left as it was. |
noexcept only if the comparison cannot throw, so that what it throws reaches the caller. Definition at line 420 of file tpl_binTreeOps.H.
References KEY, l, LLINK, r, RLINK, root(), and Aleph::BinTree_Operation< Node, Cmp >::split_key_rec().
Referenced by Aleph::BinTree_Operation< Node, Cmp >::join().
|
inlinenoexcept |
Insert a node as root in a binary search tree.
This version first inserts p as a leaf of a tree. Then p is rotated until the root.
| [in] | root | of tree |
| [in] | p | pointer to the node to insert |
p if p->get_key() is not in the tree. Otherwise the function returns Node::NullPtr | anything | that the comparison throws; it compares on the way down and rotates on the way back, so the tree is left as it was. |
noexcept only if the comparison cannot throw, so that what it throws reaches the caller. Definition at line 616 of file tpl_binTreeOps.H.
References Aleph::BinTree_Operation< Node, Cmp >::cmp, Aleph::BinTree_Operation< Node, Cmp >::insert_root_rec(), KEY, LLINK, RLINK, root(), Aleph::rotate_to_left(), and Aleph::rotate_to_right().
Referenced by Aleph::BinTree_Operation< Node, Cmp >::insert_root_rec().
|
inlinenoexcept |
Fast union of two binary search trees.
join(t1, t2, dup) joins the nodes of t1 with the nodes of t2. The duplicated keys of t2 are copied in the binary search tree dup.
| [in] | t1 | root of first tree |
| [in] | t2 | root of second tree |
| [out] | dup | tree where the duplicated keys of t2 are put |
std::terminate()). noexcept because it moves the nodes one by one: a comparison that threw in the middle would leave nodes out of every tree. Definition at line 502 of file tpl_binTreeOps.H.
References Aleph::BinTree_Operation< Node, Cmp >::insert(), Aleph::BinTree_Operation< Node, Cmp >::insert_root(), Aleph::BinTree_Operation< Node, Cmp >::join(), KEY, l, LLINK, r, Aleph::BinTree_Operation< Node, Cmp >::remove(), and RLINK.
Referenced by Aleph::BinTree_Operation< Node, Cmp >::join().
|
inlinenoexcept |
Union of two binary search trees.
t1 and t2respectively. Use join() which is much more faster| [in] | t1 | root of first tree |
| [in] | t2 | root of second tree |
| [out] | dup | root of tree where the duplicated keys will be put |
std::terminate()). noexcept because it moves the nodes one by one: a comparison that threw in the middle would leave nodes out of every tree. Definition at line 469 of file tpl_binTreeOps.H.
References Aleph::BinTree_Operation< Node, Cmp >::insert(), Aleph::BinTree_Operation< Node, Cmp >::join_preorder(), l, LLINK, r, and RLINK.
Referenced by Aleph::BinTree_Operation< Node, Cmp >::join_preorder().
|
inlinenoexcept |
Return the comparison criteria.
Definition at line 72 of file tpl_binTreeOps.H.
References Aleph::BinTree_Operation< Node, Cmp >::cmp.
|
inlinenoexcept |
Remove a key from a binary search tree.
| [in,out] | root | of tree |
| [in] | key | to remove |
key was found in the tree, Node::NullPtr otherwise | anything | that the comparison throws; the node is unlinked only after the last comparison, so the tree is left as it was. |
noexcept only if the comparison cannot throw, so that what it throws reaches the caller. Definition at line 386 of file tpl_binTreeOps.H.
References Aleph::BinTree_Operation< Node, Cmp >::cmp, Aleph::join_exclusive(), KEY, LLINK, Aleph::BinTree_Operation< Node, Cmp >::remove(), RLINK, and root().
Referenced by Aleph::BinTree_Operation< Node, Cmp >::join(), Aleph::GenBinTree< NodeType, Key, Compare >::remove(), and Aleph::BinTree_Operation< Node, Cmp >::remove().
|
inlinenoexcept |
Search a node with a specific key.
| [in] | root | of the tree |
| [in] | key | to be searched |
Node::NullPtr otherwise | 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 104 of file tpl_binTreeOps.H.
References Aleph::BinTree_Operation< Node, Cmp >::cmp, root(), and Aleph::searchInBinTree().
Referenced by Aleph::GenBinTree< NodeType, Key, Compare >::search().
|
inlinenoexcept |
Search or insert a node in a binary search tree.
search_or_insert(root, p) searches in root a node containing p->get_key(). If found, then this node is returned. Otherwise, p is inserted and returned.
| [in,out] | r | root of tree |
| [in] | p | node to search or insert |
p if its key was not in the tree; otherwise, a pointer containing the tree is returned. | anything | that the comparison throws; p is linked only after the last comparison, so the tree is left as it was. |
noexcept only if the comparison cannot throw, so that what it throws reaches the caller. Definition at line 239 of file tpl_binTreeOps.H.
References Aleph::BinTree_Operation< Node, Cmp >::cmp, KEY, LLINK, r, RLINK, and Aleph::BinTree_Operation< Node, Cmp >::search_or_insert().
Referenced by Aleph::BinTree_Operation< Node, Cmp >::search_or_insert(), and Aleph::GenBinTree< NodeType, Key, Compare >::search_or_insert().
|
inlinenoexcept |
Search and eventually insert p as root in a binary search tree.
| [in] | root | of tree |
| [in] | p | pointer to the node to eventually insert |
p is inserted, then it returns p; otherwise, it returns a pointer to the tree node containing to p->get_key() | anything | that the comparison throws; it compares on the way down and rotates on the way back, so the tree is left as it was. |
noexcept only if the comparison cannot throw, so that what it throws reaches the caller. Definition at line 658 of file tpl_binTreeOps.H.
References Aleph::BinTree_Operation< Node, Cmp >::cmp, KEY, LLINK, RLINK, root(), Aleph::rotate_to_left(), Aleph::rotate_to_right(), and Aleph::BinTree_Operation< Node, Cmp >::search_or_insert_root_rec().
Referenced by Aleph::BinTree_Operation< Node, Cmp >::search_or_insert_root_rec().
|
inlinenoexcept |
Search a key and find its node and parent.
| [in] | root | of tree |
| [in] | key | to search |
| [out] | parent | pointer to parent node if key was found. Otherwise, value is undetermined |
key if this is found; otherwise, it returns a pointer to the last visited node | 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 123 of file tpl_binTreeOps.H.
References Aleph::BinTree_Operation< Node, Cmp >::cmp, and root().
|
inlinenoexcept |
Split a binary search tree according to a key.
split_key(root, key, l, r) splits the tree root according to key. At the end, l contains all the keys lesser than key and r all the keys greater or equal than key.
| [in,out] | root | of tree to split |
| [in] | key | for splitting |
| [out] | l | tree with keys lesser than key |
| [out] | r | tree with keys greater or equal than key |
std::terminate()). noexcept because it relinks the nodes as it compares: a comparison that threw in the middle would leave the tree broken. Definition at line 546 of file tpl_binTreeOps.H.
References Aleph::BinTree_Operation< Node, Cmp >::cmp, KEY, l, LLINK, r, RLINK, and root().
|
inlinenoexcept |
Split a tree according to a key value.
split_key_dup_rec(root, key, ts, tg) splits according to key the tree withrootand build two trees.t1contains the keys lesser thankeyandt2the keys greater or equal thankey`.
| [in,out] | root | of tre to be split |
| [in] | key | for splitting |
| [out] | ts | tree with the keys lesser than key |
| [out] | tg | tree with the keys greater or equal than key |
| anything | that the comparison throws; every comparison comes before the first change, so root, ts and tg are left as they were. |
noexcept only if the comparison cannot throw, so that what it throws reaches the caller. Definition at line 367 of file tpl_binTreeOps.H.
References root(), and Aleph::BinTree_Operation< Node, Cmp >::split_key_dup_rec_helper().
Referenced by Aleph::BinTree_Operation< Node, Cmp >::insert_dup_root().
|
inlineprivatenoexcept |
Definition at line 326 of file tpl_binTreeOps.H.
References Aleph::BinTree_Operation< Node, Cmp >::cmp, KEY, LLINK, RLINK, root(), and Aleph::BinTree_Operation< Node, Cmp >::split_key_dup_rec_helper().
Referenced by Aleph::BinTree_Operation< Node, Cmp >::split_key_dup_rec(), and Aleph::BinTree_Operation< Node, Cmp >::split_key_dup_rec_helper().
|
inlinenoexcept |
Split recursively according to a key.
split_key_rec(root, key, ts, tg) splits the tree with root in two trees t1 which contain the keys lesser than key and t2 which contains the keys greater than key.
The split only is performed if key is not in the tree.
| [in,out] | root | of tree |
| [in] | key | for slitting |
| [out] | ts | tree with keys lesser than key |
| [out] | tg | tree with keys greater than key |
true if the tree was split; that is if key was not in the tree. Otherwise, the split is not performed and it return false | anything | that the comparison throws; every comparison comes before the first change, so root, ts and tg are left as they were. |
noexcept only if the comparison cannot throw, so that what it throws reaches the caller. Definition at line 314 of file tpl_binTreeOps.H.
References root(), and Aleph::BinTree_Operation< Node, Cmp >::split_key_rec_helper().
Referenced by Aleph::BinTree_Operation< Node, Cmp >::insert_root().
|
inlineprivatenoexcept |
Definition at line 264 of file tpl_binTreeOps.H.
References Aleph::BinTree_Operation< Node, Cmp >::cmp, KEY, LLINK, RLINK, root(), and Aleph::BinTree_Operation< Node, Cmp >::split_key_rec_helper().
Referenced by Aleph::BinTree_Operation< Node, Cmp >::split_key_rec(), and Aleph::BinTree_Operation< Node, Cmp >::split_key_rec_helper().
|
protected |
Definition at line 68 of file tpl_binTreeOps.H.
Referenced by Aleph::BinTreeXt_Operation< Node, Cmp >::find_position(), Aleph::BinTree_Operation< Node, Cmp >::get_compare(), Aleph::BinTreeXt_Operation< Node, Cmp >::inorder_position(), Aleph::BinTree_Operation< Node, Cmp >::insert(), Aleph::BinTree_Operation< Node, Cmp >::insert_dup(), Aleph::BinTree_Operation< Node, Cmp >::insert_root_rec(), Aleph::BinTree_Operation< Node, Cmp >::key_comp(), Aleph::BinTree_Operation< Node, Cmp >::remove(), Aleph::BinTree_Operation< Node, Cmp >::search(), Aleph::BinTree_Operation< Node, Cmp >::search_or_insert(), Aleph::BinTree_Operation< Node, Cmp >::search_or_insert_root_rec(), Aleph::BinTree_Operation< Node, Cmp >::search_parent(), Aleph::BinTree_Operation< Node, Cmp >::search_rank_parent(), Aleph::BinTree_Operation< Node, Cmp >::split_key(), Aleph::BinTreeXt_Operation< Node, Cmp >::split_key_dup_rec(), Aleph::BinTree_Operation< Node, Cmp >::split_key_dup_rec_helper(), Aleph::BinTreeXt_Operation< Node, Cmp >::split_key_rec(), and Aleph::BinTree_Operation< Node, Cmp >::split_key_rec_helper().