|
Aleph-w 7.10.0
A C++ Library for Data Structures and Algorithms
|
Randomized binary search tree with rank support. More...
#include <tpl_rand_tree.H>
Classes | |
| struct | Iterator |
| Iterator on nodes of the tree. More... | |
Public Types | |
| using | Node = NodeType< Key > |
Public Member Functions | |
| Gen_Rand_Tree (const Gen_Rand_Tree &)=delete | |
| Gen_Rand_Tree & | operator= (const Gen_Rand_Tree &)=delete |
| Compare & | key_comp () noexcept |
| return the comparison criteria | |
| const Compare & | key_comp () const noexcept |
| Compare & | get_compare () noexcept |
See key_comp(). | |
| const Compare & | get_compare () const noexcept |
| Random_Source & | random_source () noexcept |
| The source of random numbers, which draws the positions of the nodes. | |
| const Random_Source & | random_source () const noexcept |
| The source of random numbers, to look at it: its engine, or whether it is equal to another one. | |
| Gsl_Compatible_Rng & | rng () |
| The Mersenne Twister of the tree, which a tree that was given no seed makes here, and draws from it from then on. | |
| void | set_seed (const unsigned long seed) |
| Seeds the Mersenne Twister of the tree, modulo 2^32 - 1: the positions are from then on those of GSL for the seed. | |
| Gen_Rand_Tree (const unsigned int seed, const Compare &__cmp=Compare()) | |
Builds an empty random tree whose positions are those of GSL for seed: it draws them from a Mersenne Twister, in dynamic memory. | |
| Gen_Rand_Tree () noexcept(std::is_nothrow_default_constructible_v< Compare > and std::is_nothrow_copy_constructible_v< Compare >) | |
| Builds an empty random tree with a comparison criteria built by default, which draws its positions from a SplitMix64 with a seed of its own. | |
| Gen_Rand_Tree (const Compare &cmp) noexcept(std::is_nothrow_copy_constructible_v< Compare >) | |
Builds an empty random tree with the comparison criteria cmp, which draws its positions from a SplitMix64 with a seed of its own. | |
| void | swap (Gen_Rand_Tree &tree) noexcept(std::is_nothrow_swappable_v< Compare >) |
Swap in constant time all the nodes of this with tree. | |
| Gen_Rand_Tree (Gen_Rand_Tree &&other) noexcept(std::is_nothrow_copy_constructible_v< Compare >) | |
| Take the nodes, the generator and the comparison criterion of another tree, which is left empty, and draws from then on from a SplitMix64 with a seed of its own. | |
| Gen_Rand_Tree & | operator= (Gen_Rand_Tree &&other) noexcept(noexcept(swap(other))) |
| Exchange this tree with another, which is left with the previous nodes, generator and comparison criterion of this one. | |
| virtual | ~Gen_Rand_Tree () noexcept |
| Node * | insert (Node *p) noexcept(nothrow_compare_copy_v< Compare, Key >) |
| Insert a node in the tree. | |
| Node * | insert_dup (Node *p) noexcept(nothrow_compare_copy_v< Compare, Key >) |
| Insert a node in the tree. | |
| Node * | remove (const Key &key) noexcept(nothrow_compare_v< Compare, Key >) |
| Remove a key from the tree. | |
| Node * | search (const Key &key) const noexcept(nothrow_compare_v< Compare, Key >) |
| Search a key. | |
| Node * | search_or_insert (Node *p) noexcept(nothrow_compare_copy_v< Compare, Key >) |
| Search or insert a key. | |
| bool | verify () const |
Return true if this is a consistent randomized tree. | |
| Node *& | getRoot () noexcept |
| Return the tree's root. | |
| Node * | select (const size_t i) const |
| Return the i-th node in inorder sense. | |
| size_t | size () const noexcept |
| Return the number of nodes that have the tree. | |
| bool | is_empty () const noexcept |
| Return true if the tree is empty. | |
| std::pair< long, Node * > | position (const Key &key) const noexcept(nothrow_compare_copy_v< Compare, Key >) |
| Compute the inorder position of a key. | |
| std::pair< long, Node * > | find_position (const Key &key) const noexcept(nothrow_compare_copy_v< Compare, Key >) |
| Find the inorder position of a key in the tree. | |
| Node * | remove_pos (const size_t i) |
Remove the key at inorder position i | |
| bool | split_key (const Key &key, Gen_Rand_Tree &t1, Gen_Rand_Tree &t2) noexcept(nothrow_compare_v< Compare, Key >) |
| Split the tree according to a key. | |
| void | split_key_dup (const Key &key, Gen_Rand_Tree &t1, Gen_Rand_Tree &t2) noexcept(nothrow_compare_v< Compare, Key >) |
| Split the tree according to a key that could be in the tree. | |
| void | split_pos (size_t pos, Gen_Rand_Tree &t1, Gen_Rand_Tree &t2) |
| Split a extended binary tree according to a position. | |
| void | join (Gen_Rand_Tree &t, Gen_Rand_Tree &dup) noexcept |
Join this with t filtering the duplicated keys. | |
| void | join_dup (Gen_Rand_Tree &t) noexcept |
Join this with t independently of the presence of duplicated keys. | |
| void | join_exclusive (Gen_Rand_Tree &t) noexcept |
Join exclusive of this with t | |
Private Member Functions | |
| Node * | random_insert (Node *root, Node *p) noexcept(nothrow_compare_copy_v< Compare, Key >) |
| Node * | random_insert_dup (Node *root, Node *p) noexcept(nothrow_compare_copy_v< Compare, Key >) |
| Node * | random_search_or_insert (Node *&root, Node *p) noexcept(nothrow_compare_copy_v< Compare, Key >) |
| Node * | random_join_exclusive (Node *tl, Node *tr) noexcept |
| Node * | random_remove (Node *&root, const Key &key) noexcept(nothrow_compare_v< Compare, Key >) |
| Node * | remove_pos (Node *&root, const size_t pos) noexcept |
| Node * | random_join (Node *t1, Node *t2, Node *&dup) |
| Node * | random_join (Node *t1, Node *t2) |
Static Private Member Functions | |
| static unsigned long | generator_seed (const unsigned long seed) noexcept |
Private Attributes | |
| Node * | tree_root |
| The type of node. | |
| Random_Source | r |
| Compare | cmp |
Randomized binary search tree with rank support.
This class implements a randomized binary search tree where random decisions during insertion and deletion ensure that the tree has the same expected properties as if it were built from a random permutation of keys, regardless of actual insertion order.
This allows treating the tree like a sorted dynamic array with O(log n) indexed access, insertion, and deletion.
| NodeType | Node template (RandNode or RandNodeVtl). |
| Key | The type of keys stored in the tree. |
| Compare | Comparison functor for ordering keys. |
Definition at line 161 of file tpl_rand_tree.H.
| using Aleph::Gen_Rand_Tree< NodeType, Key, Compare >::Node = NodeType<Key> |
Definition at line 164 of file tpl_rand_tree.H.
|
delete |
|
inline |
Builds an empty random tree whose positions are those of GSL for seed: it draws them from a Mersenne Twister, in dynamic memory.
| [in] | seed | The seed, taken modulo 2^32 - 1, as it was for GSL. |
| [in] | __cmp | The comparison criteria, which the tree copies. |
| std::bad_alloc | If there is not enough memory for the Mersenne Twister, or what the copy of __cmp throws. |
Definition at line 366 of file tpl_rand_tree.H.
|
inlinenoexcept |
Builds an empty random tree with a comparison criteria built by default, which draws its positions from a SplitMix64 with a seed of its own.
It does not allocate.
It is a constructor apart from the one that takes the comparison, and not a default argument of that one: GCC and Clang do not count a default argument in the noexcept of the implicit default constructor of a tree that inherits these, and what the construction of the comparison threw would end the program there.
| what | the default construction or the copy of the comparison throws; nothing when they are noexcept. |
Definition at line 386 of file tpl_rand_tree.H.
|
inlinenoexcept |
Builds an empty random tree with the comparison criteria cmp, which draws its positions from a SplitMix64 with a seed of its own.
It does not allocate.
| [in] | cmp | the comparison criteria, which the tree copies. |
| what | the copy of cmp throws; nothing when it is noexcept. |
Definition at line 402 of file tpl_rand_tree.H.
|
inlinenoexcept |
Take the nodes, the generator and the comparison criterion of another tree, which is left empty, and draws from then on from a SplitMix64 with a seed of its own.
It does not allocate.
| [in,out] | other | the tree to move from. |
| what | the copy of the comparison criterion throws; then other is unchanged. Nothing when that copy is noexcept. |
Definition at line 434 of file tpl_rand_tree.H.
References Aleph::Gen_Rand_Tree< NodeType, Key, Compare >::r, Aleph::Random_Source::swap(), and Aleph::Gen_Rand_Tree< NodeType, Key, Compare >::tree_root.
|
inlinevirtualnoexcept |
Definition at line 462 of file tpl_rand_tree.H.
|
inlinenoexcept |
Find the inorder position of a key in the tree.
find_position(key) determines the inorder position that has or had key in the tree. Themethod return a tuple with a position and a node pointer.
If key is found then its inorder position is returned along with a pointer to the node containing it.
Otherwise, the tuple returns the position that would have key if this was in the tree and the parent node that the key should be. At this regard, there are three cases:
key is lesser than the minimum key of tree, then first is -1 and the node is one with the smallest key.key is greater than the maximum key in the tree, then first is the number of keys and the node is one with the maximum key in the tree.key if this was in the tree and second is the node whose key is immediately greater than key.| [in] | key | to be searched |
| 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 715 of file tpl_rand_tree.H.
References Aleph::Gen_Rand_Tree< NodeType, Key, Compare >::cmp, Aleph::Gen_Rand_Tree< NodeType, Key, Compare >::find_position(), Aleph::Gen_Rand_Tree< NodeType, Key, Compare >::r, and Aleph::Gen_Rand_Tree< NodeType, Key, Compare >::tree_root.
Referenced by Aleph::Gen_Rand_Tree< NodeType, Key, Compare >::find_position().
|
inlinestaticprivatenoexcept |
Definition at line 291 of file tpl_rand_tree.H.
References Aleph::Gsl_Compatible_Rng::max(), and seed.
Referenced by Aleph::Gen_Rand_Tree< NodeType, Key, Compare >::set_seed().
|
inlinenoexcept |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Definition at line 307 of file tpl_rand_tree.H.
References Aleph::Gen_Rand_Tree< NodeType, Key, Compare >::cmp.
|
inlinenoexcept |
See key_comp().
Definition at line 304 of file tpl_rand_tree.H.
References Aleph::Gen_Rand_Tree< NodeType, Key, Compare >::key_comp().
|
inlinenoexcept |
Return the tree's root.
Definition at line 642 of file tpl_rand_tree.H.
References Aleph::Gen_Rand_Tree< NodeType, Key, Compare >::tree_root.
Referenced by main(), Aleph::Gen_Rand_Tree< NodeType, Key, Compare >::split_pos(), TEST(), Moved_From_Case< Rand_Tree< int > >::use(), and write_rand().
|
inlinenoexcept |
Insert a node in the tree.
| [in] | p | pointer to the node to insert |
p->get_key() is not in the tree, then the pointer p is returned (it was inserted); otherwise, nullptr is returned | anything | that the comparison or its copy throws; the tree changes only after the last comparison, so its links and nodes are left as they were, without p; not so the random generator, which the insertion may have used. |
noexcept only if the comparison and its copy cannot throw, so that what it throws reaches the caller. Definition at line 480 of file tpl_rand_tree.H.
References Aleph::and, Aleph::COUNT(), LLINK, Aleph::Gen_Rand_Tree< NodeType, Key, Compare >::random_insert(), RLINK, and Aleph::Gen_Rand_Tree< NodeType, Key, Compare >::tree_root.
Referenced by main(), TEST(), and write_rand().
|
inlinenoexcept |
Insert a node in the tree.
This method does not fail. It always inserts.
| [in] | p | pointer to the node to insert |
p pointer | anything | that the comparison or its copy throws; the tree changes only after the last comparison, so its links and nodes are left as they were, without p; not so the random generator, which the insertion may have used. |
noexcept only if the comparison and its copy cannot throw, so that what it throws reaches the caller. Definition at line 508 of file tpl_rand_tree.H.
References Aleph::and, Aleph::COUNT(), LLINK, Aleph::Gen_Rand_Tree< NodeType, Key, Compare >::random_insert_dup(), RLINK, and Aleph::Gen_Rand_Tree< NodeType, Key, Compare >::tree_root.
|
inlinenoexcept |
Return true if the tree is empty.
Definition at line 660 of file tpl_rand_tree.H.
References Aleph::Gen_Rand_Tree< NodeType, Key, Compare >::tree_root.
Referenced by Moved_From_Case< Rand_Tree< int > >::is_empty(), and Moved_From_Case< Rand_Tree< int > >::use().
|
inlinenoexcept |
Join this with t filtering the duplicated keys.
join(t, dup) produces a random tree result of join of this and t. The resulting tree is stored in this.
Nodes containing duplicated keys are inserted in the randomized tree dup. The nodes could belong to any of two trees
| [in] | t | randomized tree to join with this |
| [out] | dup | randomized tree where nodes containing duplicated keys are inserted |
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 922 of file tpl_rand_tree.H.
References Aleph::Gen_Rand_Tree< NodeType, Key, Compare >::random_join(), and Aleph::Gen_Rand_Tree< NodeType, Key, Compare >::tree_root.
|
inlinenoexcept |
Join this with t independently of the presence of duplicated keys.
join(t) produces a random tree result of join of this and t. The resulting tree is stored in this.
| [in] | t | randomized tree to join with this keys are inserted |
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 942 of file tpl_rand_tree.H.
References Aleph::Gen_Rand_Tree< NodeType, Key, Compare >::random_join(), and Aleph::Gen_Rand_Tree< NodeType, Key, Compare >::tree_root.
|
inlinenoexcept |
Join exclusive of this with t
Exclusive means that all the keys of this are lesser than all the keys of t. This knowledge allows a more efficient way for joining that when the keys ranks are overlapped. However, use very carefully because the algorithm does not perform any check and the result would be incorrect.
| [in] | t | randomized tree to exclusively join with this keys are inserted |
Definition at line 959 of file tpl_rand_tree.H.
References Aleph::Gen_Rand_Tree< NodeType, Key, Compare >::random_join_exclusive(), and Aleph::Gen_Rand_Tree< NodeType, Key, Compare >::tree_root.
|
inlinenoexcept |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Definition at line 301 of file tpl_rand_tree.H.
References Aleph::Gen_Rand_Tree< NodeType, Key, Compare >::cmp.
|
inlinenoexcept |
return the comparison criteria
Definition at line 298 of file tpl_rand_tree.H.
References Aleph::Gen_Rand_Tree< NodeType, Key, Compare >::cmp.
Referenced by Aleph::Gen_Rand_Tree< NodeType, Key, Compare >::get_compare().
|
delete |
|
inlinenoexcept |
Exchange this tree with another, which is left with the previous nodes, generator and comparison criterion of this one.
The previous assignment took the generator of other, which then drew from a null one, and freed the nodes of this tree, which the tree does not own: they go now to other, as in swap().
| [in,out] | other | the tree to move from. |
| what | swapping the comparison criteria throws; then nothing is exchanged. |
Definition at line 456 of file tpl_rand_tree.H.
References Aleph::Gen_Rand_Tree< NodeType, Key, Compare >::swap().
|
inlineprivatenoexcept |
Definition at line 174 of file tpl_rand_tree.H.
References Aleph::Gen_Rand_Tree< NodeType, Key, Compare >::cmp, Aleph::COUNT(), Aleph::BinTreeXt_Operation< Node, Cmp >::insert_root(), KEY, LLINK, Aleph::Gen_Rand_Tree< NodeType, Key, Compare >::r, Aleph::Gen_Rand_Tree< NodeType, Key, Compare >::random_insert(), RLINK, root(), and Aleph::Random_Source::uniform_int_ne().
Referenced by Aleph::Gen_Rand_Tree< NodeType, Key, Compare >::insert(), and Aleph::Gen_Rand_Tree< NodeType, Key, Compare >::random_insert().
|
inlineprivatenoexcept |
Definition at line 215 of file tpl_rand_tree.H.
References Aleph::Gen_Rand_Tree< NodeType, Key, Compare >::cmp, Aleph::COUNT(), Aleph::BinTreeXt_Operation< Node, Cmp >::insert_dup_root(), KEY, LLINK, Aleph::Gen_Rand_Tree< NodeType, Key, Compare >::r, Aleph::Gen_Rand_Tree< NodeType, Key, Compare >::random_insert_dup(), RLINK, root(), and Aleph::Random_Source::uniform_int_ne().
Referenced by Aleph::Gen_Rand_Tree< NodeType, Key, Compare >::insert_dup(), Aleph::Gen_Rand_Tree< NodeType, Key, Compare >::random_insert_dup(), and Aleph::Gen_Rand_Tree< NodeType, Key, Compare >::random_join().
|
inlineprivate |
Definition at line 871 of file tpl_rand_tree.H.
References Aleph::Gen_Rand_Tree< NodeType, Key, Compare >::cmp, Aleph::COUNT(), Aleph::insert_dup_root_xt(), l, LLINK, m, Aleph::Gen_Rand_Tree< NodeType, Key, Compare >::r, Aleph::Gen_Rand_Tree< NodeType, Key, Compare >::random_join(), RLINK, and Aleph::Random_Source::uniform_int_ne().
|
inlineprivate |
Definition at line 820 of file tpl_rand_tree.H.
References Aleph::Gen_Rand_Tree< NodeType, Key, Compare >::cmp, Aleph::COUNT(), Aleph::insert_root_xt(), KEY, l, LLINK, m, Aleph::Gen_Rand_Tree< NodeType, Key, Compare >::r, Aleph::Gen_Rand_Tree< NodeType, Key, Compare >::random_insert_dup(), Aleph::Gen_Rand_Tree< NodeType, Key, Compare >::random_join(), Aleph::Gen_Rand_Tree< NodeType, Key, Compare >::random_remove(), RLINK, and Aleph::Random_Source::uniform_int_ne().
Referenced by Aleph::Gen_Rand_Tree< NodeType, Key, Compare >::join(), Aleph::Gen_Rand_Tree< NodeType, Key, Compare >::join_dup(), Aleph::Gen_Rand_Tree< NodeType, Key, Compare >::random_join(), and Aleph::Gen_Rand_Tree< NodeType, Key, Compare >::random_join().
|
inlineprivatenoexcept |
Definition at line 520 of file tpl_rand_tree.H.
References Aleph::COUNT(), LLINK, m, Aleph::Gen_Rand_Tree< NodeType, Key, Compare >::r, Aleph::Gen_Rand_Tree< NodeType, Key, Compare >::random_join_exclusive(), RLINK, and Aleph::Random_Source::uniform_int_ne().
Referenced by Aleph::Gen_Rand_Tree< NodeType, Key, Compare >::join_exclusive(), Aleph::Gen_Rand_Tree< NodeType, Key, Compare >::random_join_exclusive(), Aleph::Gen_Rand_Tree< NodeType, Key, Compare >::random_remove(), and Aleph::Gen_Rand_Tree< NodeType, Key, Compare >::remove_pos().
|
inlineprivatenoexcept |
Definition at line 541 of file tpl_rand_tree.H.
References Aleph::Gen_Rand_Tree< NodeType, Key, Compare >::cmp, Aleph::COUNT(), KEY, LLINK, Aleph::Gen_Rand_Tree< NodeType, Key, Compare >::random_join_exclusive(), Aleph::Gen_Rand_Tree< NodeType, Key, Compare >::random_remove(), RLINK, and root().
Referenced by Aleph::Gen_Rand_Tree< NodeType, Key, Compare >::random_join(), Aleph::Gen_Rand_Tree< NodeType, Key, Compare >::random_remove(), and Aleph::Gen_Rand_Tree< NodeType, Key, Compare >::remove().
|
inlineprivatenoexcept |
Definition at line 241 of file tpl_rand_tree.H.
References Aleph::Gen_Rand_Tree< NodeType, Key, Compare >::cmp, Aleph::COUNT(), Aleph::BinTreeXt_Operation< Node, Cmp >::insert_root(), KEY, LLINK, Aleph::Gen_Rand_Tree< NodeType, Key, Compare >::r, Aleph::Gen_Rand_Tree< NodeType, Key, Compare >::random_search_or_insert(), RLINK, root(), and Aleph::Random_Source::uniform_int_ne().
Referenced by Aleph::Gen_Rand_Tree< NodeType, Key, Compare >::random_search_or_insert(), and Aleph::Gen_Rand_Tree< NodeType, Key, Compare >::search_or_insert().
|
inlinenoexcept |
The source of random numbers, to look at it: its engine, or whether it is equal to another one.
Definition at line 315 of file tpl_rand_tree.H.
References Aleph::Gen_Rand_Tree< NodeType, Key, Compare >::r.
|
inlinenoexcept |
The source of random numbers, which draws the positions of the nodes.
Definition at line 311 of file tpl_rand_tree.H.
References Aleph::Gen_Rand_Tree< NodeType, Key, Compare >::r.
Referenced by TEST().
|
inlinenoexcept |
Remove a key from the tree.
| [in] | key | to remove |
key was found in the tree, nullptr otherwise | anything | that the comparison throws; the tree changes only after the last comparison, 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 585 of file tpl_rand_tree.H.
References Aleph::Gen_Rand_Tree< NodeType, Key, Compare >::random_remove(), and Aleph::Gen_Rand_Tree< NodeType, Key, Compare >::tree_root.
|
inline |
Remove the key at inorder position i
| [in] | i | inorder position to be removed |
| out_of_range | if i is greater or equal than the number of nodes of tree |
Definition at line 751 of file tpl_rand_tree.H.
References ah_out_of_range_error_if, Aleph::COUNT(), Aleph::Gen_Rand_Tree< NodeType, Key, Compare >::remove_pos(), and Aleph::Gen_Rand_Tree< NodeType, Key, Compare >::tree_root.
|
inlineprivatenoexcept |
Definition at line 727 of file tpl_rand_tree.H.
References Aleph::COUNT(), LLINK, Aleph::Gen_Rand_Tree< NodeType, Key, Compare >::random_join_exclusive(), Aleph::Gen_Rand_Tree< NodeType, Key, Compare >::remove_pos(), RLINK, and root().
Referenced by Aleph::Gen_Rand_Tree< NodeType, Key, Compare >::remove_pos(), and Aleph::Gen_Rand_Tree< NodeType, Key, Compare >::remove_pos().
|
inline |
The Mersenne Twister of the tree, which a tree that was given no seed makes here, and draws from it from then on.
| std::bad_alloc | If the tree has no Mersenne Twister and there is not enough memory for it. |
Definition at line 328 of file tpl_rand_tree.H.
References Aleph::Random_Source::mersenne_twister(), and Aleph::Gen_Rand_Tree< NodeType, Key, Compare >::r.
|
inlinenoexcept |
Search a key.
| [in] | key | to be searched |
nullptr | 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 602 of file tpl_rand_tree.H.
References Aleph::Gen_Rand_Tree< NodeType, Key, Compare >::cmp, and Aleph::Gen_Rand_Tree< NodeType, Key, Compare >::tree_root.
Referenced by main(), and write_rand().
|
inlinenoexcept |
Search or insert a key.
search_or_insert(p) searches in the tree the key KEY(p). If this key is found, then a pointer to the node containing it is returned. Otherwise, p is inserted.
| [in] | p | node containing a key to be searched and eventually inserted |
p is found, then a pointer to the containing key in the tree is returned. Otherwise, p is inserted and returned | anything | that the comparison or its copy throws; the tree changes only after the last comparison, so its links and nodes are left as they were, without p; not so the random generator, which the insertion may have used. |
noexcept only if the comparison and its copy cannot throw, so that what it throws reaches the caller. Definition at line 626 of file tpl_rand_tree.H.
References Aleph::COUNT(), Aleph::Gen_Rand_Tree< NodeType, Key, Compare >::random_search_or_insert(), and Aleph::Gen_Rand_Tree< NodeType, Key, Compare >::tree_root.
|
inline |
Return the i-th node in inorder sense.
| [in] | i | inorder position to be located |
| out_of_range | if i is greater or equal that the number of nodes |
Definition at line 651 of file tpl_rand_tree.H.
References Aleph::select(), and Aleph::Gen_Rand_Tree< NodeType, Key, Compare >::tree_root.
Referenced by Moved_From_Case< Rand_Tree< int > >::use().
|
inline |
Seeds the Mersenne Twister of the tree, modulo 2^32 - 1: the positions are from then on those of GSL for the seed.
A tree that was given no seed makes its Mersenne Twister here.
| [in] | seed | The seed. |
| std::bad_alloc | If the tree has no Mersenne Twister and there is not enough memory for it; then it is unchanged. |
Definition at line 352 of file tpl_rand_tree.H.
References Aleph::Gen_Rand_Tree< NodeType, Key, Compare >::generator_seed(), Aleph::Random_Source::Mersenne_Twister, Aleph::Gen_Rand_Tree< NodeType, Key, Compare >::r, Aleph::Random_Source::seed(), and seed.
|
inlinenoexcept |
Return the number of nodes that have the tree.
Definition at line 657 of file tpl_rand_tree.H.
References Aleph::COUNT(), and Aleph::Gen_Rand_Tree< NodeType, Key, Compare >::tree_root.
Referenced by Moved_From_Case< Rand_Tree< int > >::is_empty(), Moved_From_Case< Rand_Tree< int > >::use(), and write_rand().
|
inlinenoexcept |
Split the tree according to a key.
It splits with the comparison criteria of the tree.
| [in] | key | for splitting |
| [out] | t1 | tree with keys lesser than key |
| [out] | t2 | tree with keys greater than key |
true if tree was split; that is if key is not in the tree. Otherwise, if key is in the tree, false is returned | anything | that the comparison throws; every comparison comes before the first change, so the three trees are left as they were. |
noexcept only if the comparison cannot throw, so that what it throws reaches the caller. Definition at line 772 of file tpl_rand_tree.H.
References Aleph::Gen_Rand_Tree< NodeType, Key, Compare >::cmp, Aleph::split_key_rec_xt(), and Aleph::Gen_Rand_Tree< NodeType, Key, Compare >::tree_root.
|
inlinenoexcept |
Split the tree according to a key that could be in the tree.
split_dup(key, t1, t2) splits the tree according to key in two trees t1 which contains the key lesser than key and t2 which contains the keys greater or equal than key. It splits with the comparison criteria of the tree.
| [in] | key | for splitting |
| [out] | t1 | resulting tree with the keys lesser than key |
| [out] | t2 | resulting tree with the keys greater or equal than key |
| anything | that the comparison throws; every comparison comes before the first change, so the three trees are left as they were. |
noexcept only if the comparison cannot throw, so that what it throws reaches the caller. Definition at line 793 of file tpl_rand_tree.H.
References Aleph::Gen_Rand_Tree< NodeType, Key, Compare >::cmp, Aleph::split_key_dup_rec_xt(), and Aleph::Gen_Rand_Tree< NodeType, Key, Compare >::tree_root.
|
inline |
Split a extended binary tree according to a position.
split_pos(pos, t1, t2) splits the tree in two trees t1 and t2 according to a position pos. t1 contains the keys from 0 to pos - 1 inorder sense and t2 the keys from pos to n -
this becames empty.It is not noexcept: a position past the end throws, and inside noexcept that would end the program.
| [in] | pos | position for splitting, at most size() |
| [out] | t1 | tree where the rank of keys \([0, pos)\) will be put |
| [out] | t2 | tree where the rank of keys \([pos, n)\) will be put |
| std::out_of_range | if pos > size(); then nothing changes |
Definition at line 814 of file tpl_rand_tree.H.
References Aleph::Gen_Rand_Tree< NodeType, Key, Compare >::getRoot(), Aleph::split_pos_rec(), and Aleph::Gen_Rand_Tree< NodeType, Key, Compare >::tree_root.
|
inlinenoexcept |
Swap in constant time all the nodes of this with tree.
| [in,out] | tree | the tree to exchange with. |
| what | swapping the comparison criteria throws. They are exchanged first, so that, if that swap throws, nothing else is exchanged, and both trees are left as they were if it left its arguments as they were. |
Definition at line 416 of file tpl_rand_tree.H.
References Aleph::Gen_Rand_Tree< NodeType, Key, Compare >::cmp, Aleph::Gen_Rand_Tree< NodeType, Key, Compare >::r, Aleph::Gen_Rand_Tree< NodeType, Key, Compare >::swap(), Aleph::Random_Source::swap(), and Aleph::Gen_Rand_Tree< NodeType, Key, Compare >::tree_root.
Referenced by Aleph::Gen_Rand_Tree< NodeType, Key, Compare >::operator=(), and Aleph::Gen_Rand_Tree< NodeType, Key, Compare >::swap().
|
inline |
Return true if this is a consistent randomized tree.
Definition at line 636 of file tpl_rand_tree.H.
References Aleph::and, Aleph::check_bst(), Aleph::check_rank_tree(), Aleph::Gen_Rand_Tree< NodeType, Key, Compare >::cmp, and Aleph::Gen_Rand_Tree< NodeType, Key, Compare >::tree_root.
Referenced by Moved_From_Case< Rand_Tree< int > >::use().
|
private |
Definition at line 169 of file tpl_rand_tree.H.
Referenced by Aleph::Gen_Rand_Tree< NodeType, Key, Compare >::find_position(), Aleph::Gen_Rand_Tree< NodeType, Key, Compare >::get_compare(), Aleph::Gen_Rand_Tree< NodeType, Key, Compare >::key_comp(), Aleph::Gen_Rand_Tree< NodeType, Key, Compare >::key_comp(), Aleph::Gen_Rand_Tree< NodeType, Key, Compare >::position(), Aleph::Gen_Rand_Tree< NodeType, Key, Compare >::random_insert(), Aleph::Gen_Rand_Tree< NodeType, Key, Compare >::random_insert_dup(), Aleph::Gen_Rand_Tree< NodeType, Key, Compare >::random_join(), Aleph::Gen_Rand_Tree< NodeType, Key, Compare >::random_join(), Aleph::Gen_Rand_Tree< NodeType, Key, Compare >::random_remove(), Aleph::Gen_Rand_Tree< NodeType, Key, Compare >::random_search_or_insert(), Aleph::Gen_Rand_Tree< NodeType, Key, Compare >::search(), Aleph::Gen_Rand_Tree< NodeType, Key, Compare >::split_key(), Aleph::Gen_Rand_Tree< NodeType, Key, Compare >::split_key_dup(), Aleph::Gen_Rand_Tree< NodeType, Key, Compare >::swap(), and Aleph::Gen_Rand_Tree< NodeType, Key, Compare >::verify().
|
private |
Definition at line 168 of file tpl_rand_tree.H.
Referenced by Aleph::Gen_Rand_Tree< NodeType, Key, Compare >::Gen_Rand_Tree(), Aleph::Gen_Rand_Tree< NodeType, Key, Compare >::find_position(), Aleph::Gen_Rand_Tree< NodeType, Key, Compare >::random_insert(), Aleph::Gen_Rand_Tree< NodeType, Key, Compare >::random_insert_dup(), Aleph::Gen_Rand_Tree< NodeType, Key, Compare >::random_join(), Aleph::Gen_Rand_Tree< NodeType, Key, Compare >::random_join(), Aleph::Gen_Rand_Tree< NodeType, Key, Compare >::random_join_exclusive(), Aleph::Gen_Rand_Tree< NodeType, Key, Compare >::random_search_or_insert(), Aleph::Gen_Rand_Tree< NodeType, Key, Compare >::random_source(), Aleph::Gen_Rand_Tree< NodeType, Key, Compare >::random_source(), Aleph::Gen_Rand_Tree< NodeType, Key, Compare >::rng(), Aleph::Gen_Rand_Tree< NodeType, Key, Compare >::set_seed(), and Aleph::Gen_Rand_Tree< NodeType, Key, Compare >::swap().
|
private |
The type of node.
Definition at line 167 of file tpl_rand_tree.H.
Referenced by Aleph::Gen_Rand_Tree< NodeType, Key, Compare >::Gen_Rand_Tree(), Aleph::Gen_Rand_Tree< NodeType, Key, Compare >::find_position(), Aleph::Gen_Rand_Tree< NodeType, Key, Compare >::getRoot(), Aleph::Gen_Rand_Tree< NodeType, Key, Compare >::insert(), Aleph::Gen_Rand_Tree< NodeType, Key, Compare >::insert_dup(), Aleph::Gen_Rand_Tree< NodeType, Key, Compare >::is_empty(), Aleph::Gen_Rand_Tree< NodeType, Key, Compare >::join(), Aleph::Gen_Rand_Tree< NodeType, Key, Compare >::join_dup(), Aleph::Gen_Rand_Tree< NodeType, Key, Compare >::join_exclusive(), Aleph::Gen_Rand_Tree< NodeType, Key, Compare >::position(), Aleph::Gen_Rand_Tree< NodeType, Key, Compare >::remove(), Aleph::Gen_Rand_Tree< NodeType, Key, Compare >::remove_pos(), Aleph::Gen_Rand_Tree< NodeType, Key, Compare >::search(), Aleph::Gen_Rand_Tree< NodeType, Key, Compare >::search_or_insert(), Aleph::Gen_Rand_Tree< NodeType, Key, Compare >::select(), Aleph::Gen_Rand_Tree< NodeType, Key, Compare >::size(), Aleph::Gen_Rand_Tree< NodeType, Key, Compare >::split_key(), Aleph::Gen_Rand_Tree< NodeType, Key, Compare >::split_key_dup(), Aleph::Gen_Rand_Tree< NodeType, Key, Compare >::split_pos(), Aleph::Gen_Rand_Tree< NodeType, Key, Compare >::swap(), and Aleph::Gen_Rand_Tree< NodeType, Key, Compare >::verify().