|
Aleph-w 7.10.0
A C++ Library for Data Structures and Algorithms
|
Extended Treap with rank support for O(log n) indexed access. More...
#include <tpl_treapRk.H>
Classes | |
| class | Iterator |
| Iterator on nodes of the tree. More... | |
Public Types | |
| using | Node = NodeType< Key > |
Public Member Functions | |
| void | set_seed (const unsigned long seed) |
Seeds the Mersenne Twister of the treap, as gsl_rng_set() did: the priorities are from then on those of GSL for the seed. | |
| Random_Source & | random_source () noexcept |
| The source of random numbers, which gives the priorities. | |
| 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 treap, which a treap that was given no seed makes here, and draws from it from then on. | |
| Compare & | key_comp () noexcept |
| return the comparison criteria | |
| Compare & | get_compare () noexcept |
See key_comp(). | |
| Gen_Treap_Rk (const unsigned long seed, Compare __cmp=Compare()) | |
Builds an empty treap whose priorities are those of GSL for seed: it draws them from a Mersenne Twister, in dynamic memory. | |
| Gen_Treap_Rk () noexcept(std::is_nothrow_default_constructible_v< Node > and std::is_nothrow_default_constructible_v< Compare > and std::is_nothrow_constructible_v< Compare, Compare & >) | |
| Builds an empty treap with a comparison criteria built by default, which draws its priorities from a SplitMix64 with a seed of its own. | |
| Gen_Treap_Rk (Compare __cmp) noexcept(std::is_nothrow_default_constructible_v< Node > and std::is_nothrow_constructible_v< Compare, Compare & >) | |
Builds an empty treap with the comparison criteria __cmp, which draws its priorities from a SplitMix64 with a seed of its own. | |
| Gen_Treap_Rk (Gen_Treap_Rk &&tree) noexcept(bin_node_detail::nothrow_header_from_v< Node > and bin_node_detail::nothrow_compare_taken_v< Compare >) | |
Takes the nodes, the comparison criteria and the generator of tree, which keeps no nodes, and draws from then on from a SplitMix64 with a seed of its own: it can take nodes again. | |
| void | swap (Gen_Treap_Rk &tree) noexcept(std::is_nothrow_swappable_v< Compare >) |
Swaps in constant time the nodes and the comparison criteria of this and tree. | |
| Node *& | getRoot () noexcept |
| Return the tree's root. | |
| Node * | getRoot () const noexcept |
| Node * | search (const Key &key) const noexcept(nothrow_compare_v< Compare, Key >) |
| Search a key in a treap. | |
| Node * | insert (Node *p) noexcept(nothrow_compare_v< Compare, Key >) |
| Insert a node in a treap. | |
| Node * | insert_dup (Node *p) noexcept(nothrow_compare_v< Compare, Key >) |
| Insert a node in the tree. | |
| Node * | search_or_insert (Node *p) noexcept(nothrow_compare_v< Compare, Key >) |
| Search or insert a key. | |
| bool | verify () const |
Return true if the treap is consistent. | |
| Node * | remove (const Key &key) noexcept(nothrow_compare_v< Compare, Key >) |
| Remove a key from the tree. | |
| Node * | remove (const size_t beg, const size_t end) |
Remove from the treap all the keys between inorder position beg and end. | |
| Node * | remove_pos (const size_t pos) |
| Remove the node at the inorder position pos. | |
| Node * | select (const size_t i) const |
| Return the i-th node in order sense. | |
| size_t | size () const noexcept |
| Return the number of nodes contained in the tree. | |
| bool | is_empty () const noexcept |
Return true if tree is empty. | |
| std::pair< int, Node * > | position (const Key &key) const noexcept(nothrow_compare_copy_v< Compare, Key >) |
| Compute the inorder position of a key. | |
| std::pair< int, Node * > | find_position (const Key &key) const noexcept(nothrow_compare_copy_v< Compare, Key >) |
| Find the inorder position of a key in the tree. | |
| bool | split_key (const Key &key, Gen_Treap_Rk &t1, Gen_Treap_Rk &t2) noexcept(nothrow_compare_v< Compare, Key >) |
| Split the tree according to a key. | |
| void | split_key_dup (const Key &key, Gen_Treap_Rk &t1, Gen_Treap_Rk &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_Treap_Rk &t1, Gen_Treap_Rk &t2) |
| Split the tree at the inorder position pos. | |
| void | join (Gen_Treap_Rk &t, Gen_Treap_Rk &dup) noexcept |
Join this with t filtering the duplicated keys. | |
| void | join_dup (Gen_Treap_Rk &t) noexcept |
Join this with t independently of the presence of duplicated keys. | |
| void | join_exclusive (Gen_Treap_Rk &t) noexcept |
Join exclusive of this with t | |
Private Member Functions | |
| bool | insert (Node *&root, Node *p) noexcept(nothrow_compare_v< Compare, Key >) |
| Node * | search_or_insert (Node *&root, Node *p) noexcept(nothrow_compare_v< Compare, Key >) |
| Node * | insert_dup (Node *&root, Node *p) noexcept(nothrow_compare_v< Compare, Key >) |
| Node * | remove (Node *&root, const Key &key) noexcept(nothrow_compare_v< Compare, Key >) |
| void | join_dup (Node *&t1, Node *t2) noexcept |
| void | join (Node *&t1, Node *t2, Node *&dup) noexcept |
Static Private Member Functions | |
| static unsigned long | generator_seed (const unsigned long seed) noexcept |
| static Node * | join_exclusive (Node *t1, Node *t2) noexcept |
| static Node * | remove_pos (Node *&root, const size_t pos) noexcept |
Private Attributes | |
| Node | head |
| The type of node. | |
| Node * | head_ptr |
| Node *& | tree_root |
| Random_Source | r |
| Compare | cmp |
Extended Treap with rank support for O(log n) indexed access.
TreapRk is a Treap (tree + heap) that extends the basic treap with subtree size counters (COUNT), enabling O(log n) access by rank (inorder position). This allows treating the tree like a sorted dynamic array with efficient indexed operations.
| NodeType | Node template (typically Treap_Rk_Node). |
| Key | The type of keys stored in the tree. |
| Compare | Comparison functor for ordering keys. |
Definition at line 189 of file tpl_treapRk.H.
| using Aleph::Gen_Treap_Rk< NodeType, Key, Compare >::Node = NodeType<Key> |
Definition at line 193 of file tpl_treapRk.H.
|
inline |
Builds an empty treap whose priorities are those of GSL for seed: it draws them from a Mersenne Twister, in dynamic memory.
| [in] | seed | The seed, taken through an unsigned int, modulo 2^32 - 1, as it was for GSL. |
| [in] | __cmp | The comparison criteria, which the treap copies. |
| std::bad_alloc | If there is not enough memory for the Mersenne Twister, or what the default construction of the key of the header node or the copy of __cmp throws. |
Definition at line 263 of file tpl_treapRk.H.
References Aleph::Gen_Treap_Rk< NodeType, Key, Compare >::head_ptr, Aleph::Min_Priority, and Aleph::PRIO().
|
inlinenoexcept |
Builds an empty treap with a comparison criteria built by default, which draws its priorities 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 treap that inherits these, and what the construction of the comparison threw would end the program there.
| what | the default construction of the key of the header node or of the comparison, or the copy of the comparison, throws; nothing when they are noexcept. |
Definition at line 284 of file tpl_treapRk.H.
|
inlinenoexcept |
Builds an empty treap with the comparison criteria __cmp, which draws its priorities from a SplitMix64 with a seed of its own.
It does not allocate.
| [in] | __cmp | The comparison criteria, which the treap copies. |
| what | the default construction of the key of the header node or the copy of __cmp throws; nothing when both are noexcept. The copy is from a Compare that is not const, which a comparison may have apart from the one from a const one. |
Definition at line 304 of file tpl_treapRk.H.
References Aleph::Gen_Treap_Rk< NodeType, Key, Compare >::head_ptr, Aleph::Min_Priority, and Aleph::PRIO().
|
inlinenoexcept |
Takes the nodes, the comparison criteria and the generator of tree, which keeps no nodes, and draws from then on from a SplitMix64 with a seed of its own: it can take nodes again.
It does not allocate.
It builds no key, if it can: the key of the header node is built by default when that cannot throw; else it is that of the header node of tree, moved, when the move of a key cannot throw (see bin_node_detail::header_from()).
| [in,out] | tree | The treap to move. 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 tree 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 the header node throws, with a key whose move may throw too. Then tree keeps its nodes, but not its generator: it draws from a SplitMix64 with a seed of its own. Nothing when they are noexcept. |
Definition at line 334 of file tpl_treapRk.H.
References Aleph::Gen_Treap_Rk< NodeType, Key, Compare >::head_ptr, Aleph::Min_Priority, Aleph::PRIO(), and Aleph::Gen_Treap_Rk< NodeType, Key, Compare >::tree_root.
|
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 the tuple returns the position that would have key if this was in the tree and the parent node that the key would had. 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 inmediataly 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 777 of file tpl_treapRk.H.
References Aleph::Gen_Treap_Rk< NodeType, Key, Compare >::cmp, Aleph::Gen_Treap_Rk< NodeType, Key, Compare >::find_position(), Aleph::Gen_Treap_Rk< NodeType, Key, Compare >::r, and Aleph::Gen_Treap_Rk< NodeType, Key, Compare >::tree_root.
Referenced by Aleph::Gen_Treap_Rk< NodeType, Key, Compare >::find_position(), and Aleph::Gen_Treap_Rk< NodeType, Key, Compare >::Iterator::reset_to_key().
|
inlinestaticprivatenoexcept |
Definition at line 205 of file tpl_treapRk.H.
References Aleph::Gsl_Compatible_Rng::max(), and seed.
|
inlinenoexcept |
See key_comp().
Definition at line 251 of file tpl_treapRk.H.
References Aleph::Gen_Treap_Rk< NodeType, Key, Compare >::key_comp().
|
inlinenoexcept |
Definition at line 365 of file tpl_treapRk.H.
References Aleph::Gen_Treap_Rk< NodeType, Key, Compare >::tree_root.
|
inlinenoexcept |
Return the tree's root.
Definition at line 363 of file tpl_treapRk.H.
References Aleph::Gen_Treap_Rk< NodeType, Key, Compare >::tree_root.
Referenced by Aleph::Gen_Treap_Rk< NodeType, Key, Compare >::Iterator::get_current_position(), Aleph::Gen_Treap_Rk< NodeType, Key, Compare >::Iterator::has_curr(), Aleph::Gen_Treap_Rk< NodeType, Key, Compare >::Iterator::is_container_empty(), main(), Aleph::Gen_Treap_Rk< NodeType, Key, Compare >::Iterator::reset_last(), Aleph::Gen_Treap_Rk< NodeType, Key, Compare >::split_pos(), TEST(), TEST(), Aleph::Gen_Treap_Rk< NodeType, Key, Compare >::Iterator::update_curr(), Aleph::Gen_Treap_Rk< NodeType, Key, Compare >::Iterator::update_pos(), Aleph::Gen_Treap_Rk< NodeType, Key, Compare >::Iterator::verify(), and Aleph::Gen_Treap_Rk< NodeType, Key, Compare >::Iterator::verify().
|
inlineprivatenoexcept |
Definition at line 388 of file tpl_treapRk.H.
References Aleph::Gen_Treap_Rk< NodeType, Key, Compare >::cmp, Aleph::COUNT(), Aleph::Gen_Treap_Rk< NodeType, Key, Compare >::insert(), KEY, LLINK, Aleph::PRIO(), RLINK, root(), Aleph::rotate_to_left_xt(), and Aleph::rotate_to_right_xt().
Referenced by Aleph::Gen_Treap_Rk< NodeType, Key, Compare >::insert(), Aleph::Gen_Treap_Rk< NodeType, Key, Compare >::insert(), Aleph::Gen_Treap_Rk< NodeType, Key, Compare >::join(), main(), and TEST().
|
inlinenoexcept |
Insert a node in a treap.
insert(p) inserts the node p in this treap.
| [in] | p | pointer to the node to be inserted |
p->get_key() is not in the tree, then p is inserted and this node pointer is returned. Otherwise, it is returned nullptr. | anything | that the comparison 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: the priority of p was drawn before the first comparison. |
noexcept only if the comparison cannot throw, so that what it throws reaches the caller. Definition at line 513 of file tpl_treapRk.H.
References Aleph::Random_Source::get(), Aleph::Gen_Treap_Rk< NodeType, Key, Compare >::insert(), Aleph::PRIO(), Aleph::Gen_Treap_Rk< NodeType, Key, Compare >::r, and Aleph::Gen_Treap_Rk< NodeType, Key, Compare >::tree_root.
|
inlineprivatenoexcept |
Definition at line 471 of file tpl_treapRk.H.
References Aleph::Gen_Treap_Rk< NodeType, Key, Compare >::cmp, Aleph::COUNT(), Aleph::Gen_Treap_Rk< NodeType, Key, Compare >::insert_dup(), KEY, LLINK, Aleph::PRIO(), RLINK, root(), Aleph::rotate_to_left_xt(), and Aleph::rotate_to_right_xt().
Referenced by Aleph::Gen_Treap_Rk< NodeType, Key, Compare >::insert_dup(), Aleph::Gen_Treap_Rk< NodeType, Key, Compare >::insert_dup(), Aleph::Gen_Treap_Rk< NodeType, Key, Compare >::join(), and Aleph::Gen_Treap_Rk< NodeType, Key, Compare >::join_dup().
|
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 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: the priority of p was drawn before the first comparison. |
noexcept only if the comparison cannot throw, so that what it throws reaches the caller. Definition at line 535 of file tpl_treapRk.H.
References Aleph::Random_Source::get(), Aleph::Gen_Treap_Rk< NodeType, Key, Compare >::insert_dup(), Aleph::PRIO(), Aleph::Gen_Treap_Rk< NodeType, Key, Compare >::r, and Aleph::Gen_Treap_Rk< NodeType, Key, Compare >::tree_root.
|
inlinenoexcept |
Return true if tree is empty.
Definition at line 722 of file tpl_treapRk.H.
References Aleph::Gen_Treap_Rk< NodeType, Key, Compare >::tree_root.
|
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 | ramdomized tree to join with this |
| [out] | dup | ramdomized 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 898 of file tpl_treapRk.H.
References Aleph::Gen_Treap_Rk< NodeType, Key, Compare >::join(), and Aleph::Gen_Treap_Rk< NodeType, Key, Compare >::tree_root.
|
inlineprivatenoexcept |
Definition at line 859 of file tpl_treapRk.H.
References Aleph::Gen_Treap_Rk< NodeType, Key, Compare >::insert(), Aleph::Gen_Treap_Rk< NodeType, Key, Compare >::insert_dup(), Aleph::Gen_Treap_Rk< NodeType, Key, Compare >::join(), KEY, l, LLINK, Aleph::Gen_Treap_Rk< NodeType, Key, Compare >::r, Aleph::Gen_Treap_Rk< NodeType, Key, Compare >::remove(), and RLINK.
Referenced by Aleph::Gen_Treap_Rk< NodeType, Key, Compare >::join(), and Aleph::Gen_Treap_Rk< NodeType, Key, Compare >::join().
|
inlinenoexcept |
Join this with t independently of the presence of duplicated keys.
join(t) produces a treap result of join of this and t. The resulting tree is stored in this.
| [in] | t | ramdomized 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 918 of file tpl_treapRk.H.
References Aleph::Gen_Treap_Rk< NodeType, Key, Compare >::join_dup(), and Aleph::Gen_Treap_Rk< NodeType, Key, Compare >::tree_root.
|
inlineprivatenoexcept |
Definition at line 847 of file tpl_treapRk.H.
References Aleph::Gen_Treap_Rk< NodeType, Key, Compare >::insert_dup(), Aleph::Gen_Treap_Rk< NodeType, Key, Compare >::join_dup(), l, LLINK, Aleph::Gen_Treap_Rk< NodeType, Key, Compare >::r, and RLINK.
Referenced by Aleph::Gen_Treap_Rk< NodeType, Key, Compare >::join_dup(), and Aleph::Gen_Treap_Rk< NodeType, Key, Compare >::join_dup().
|
inlinenoexcept |
Join exclusive of this with t
Exclusive means that all the keys of this are lesser than all the keys of t. This knowlege allows a more effcient 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 | ramdomized tree to exclusively join with this keys are inserted |
Definition at line 935 of file tpl_treapRk.H.
References Aleph::Gen_Treap_Rk< NodeType, Key, Compare >::join_exclusive(), and Aleph::Gen_Treap_Rk< NodeType, Key, Compare >::tree_root.
|
inlinestaticprivatenoexcept |
Definition at line 580 of file tpl_treapRk.H.
References Aleph::COUNT(), Aleph::Gen_Treap_Rk< NodeType, Key, Compare >::join_exclusive(), LLINK, Aleph::PRIO(), and RLINK.
Referenced by Aleph::Gen_Treap_Rk< NodeType, Key, Compare >::join_exclusive(), Aleph::Gen_Treap_Rk< NodeType, Key, Compare >::join_exclusive(), Aleph::Gen_Treap_Rk< NodeType, Key, Compare >::remove(), Aleph::Gen_Treap_Rk< NodeType, Key, Compare >::remove(), and Aleph::Gen_Treap_Rk< NodeType, Key, Compare >::remove_pos().
|
inlinenoexcept |
return the comparison criteria
Definition at line 248 of file tpl_treapRk.H.
References Aleph::Gen_Treap_Rk< NodeType, Key, Compare >::cmp.
Referenced by Aleph::Gen_Treap_Rk< NodeType, Key, Compare >::get_compare().
|
inlinenoexcept |
The source of random numbers, to look at it: its engine, or whether it is equal to another one.
Definition at line 232 of file tpl_treapRk.H.
References Aleph::Gen_Treap_Rk< NodeType, Key, Compare >::r.
|
inlinenoexcept |
The source of random numbers, which gives the priorities.
Definition at line 228 of file tpl_treapRk.H.
References Aleph::Gen_Treap_Rk< NodeType, Key, Compare >::r.
|
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 638 of file tpl_treapRk.H.
References Aleph::Gen_Treap_Rk< NodeType, Key, Compare >::remove(), and Aleph::Gen_Treap_Rk< NodeType, Key, Compare >::tree_root.
|
inline |
Remove from the treap all the keys between inorder position beg and end.
| [in] | beg | beggining inorder position |
| [in] | end | ending inorder position |
| range_error | if the range is invalid |
Definition at line 657 of file tpl_treapRk.H.
References ah_range_error_if, Aleph::COUNT(), Aleph::Gen_Treap_Rk< NodeType, Key, Compare >::join_exclusive(), Aleph::split_pos_rec(), and Aleph::Gen_Treap_Rk< NodeType, Key, Compare >::tree_root.
|
inlineprivatenoexcept |
Definition at line 599 of file tpl_treapRk.H.
References Aleph::Gen_Treap_Rk< NodeType, Key, Compare >::cmp, Aleph::COUNT(), Aleph::Gen_Treap_Rk< NodeType, Key, Compare >::join_exclusive(), KEY, LLINK, Aleph::Gen_Treap_Rk< NodeType, Key, Compare >::remove(), RLINK, and root().
Referenced by Aleph::Gen_Treap_Rk< NodeType, Key, Compare >::Iterator::del(), Aleph::Gen_Treap_Rk< NodeType, Key, Compare >::join(), main(), Aleph::Gen_Treap_Rk< NodeType, Key, Compare >::remove(), and Aleph::Gen_Treap_Rk< NodeType, Key, Compare >::remove().
|
inline |
Remove the node at the inorder position pos.
| [in] | pos | inorder position of node to be removed |
| out_of_range | if pos is greater or equal than the number of nodes of tree |
Definition at line 699 of file tpl_treapRk.H.
References ah_out_of_range_error_if, Aleph::COUNT(), Aleph::Gen_Treap_Rk< NodeType, Key, Compare >::remove_pos(), and Aleph::Gen_Treap_Rk< NodeType, Key, Compare >::tree_root.
|
inlinestaticprivatenoexcept |
Definition at line 675 of file tpl_treapRk.H.
References Aleph::COUNT(), Aleph::Gen_Treap_Rk< NodeType, Key, Compare >::join_exclusive(), LLINK, Aleph::Gen_Treap_Rk< NodeType, Key, Compare >::remove_pos(), RLINK, and root().
Referenced by Aleph::Gen_Treap_Rk< NodeType, Key, Compare >::remove_pos(), and Aleph::Gen_Treap_Rk< NodeType, Key, Compare >::remove_pos().
|
inline |
The Mersenne Twister of the treap, which a treap that was given no seed makes here, and draws from it from then on.
| std::bad_alloc | If the treap has no Mersenne Twister and there is not enough memory for it. |
Definition at line 245 of file tpl_treapRk.H.
References Aleph::Random_Source::mersenne_twister(), and Aleph::Gen_Treap_Rk< NodeType, Key, Compare >::r.
|
inlinenoexcept |
Search a key in a treap.
| [in] | key | to be searched |
key if this is found; otherwise, nullptr is returned | 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 377 of file tpl_treapRk.H.
References Aleph::Gen_Treap_Rk< NodeType, Key, Compare >::cmp, Aleph::searchInBinTree(), and Aleph::Gen_Treap_Rk< NodeType, Key, Compare >::tree_root.
Referenced by main().
|
inlineprivatenoexcept |
Definition at line 426 of file tpl_treapRk.H.
References Aleph::and, Aleph::Gen_Treap_Rk< NodeType, Key, Compare >::cmp, Aleph::COUNT(), KEY, LLINK, Aleph::PRIO(), RLINK, root(), Aleph::rotate_to_left_xt(), Aleph::rotate_to_right_xt(), and Aleph::Gen_Treap_Rk< NodeType, Key, Compare >::search_or_insert().
Referenced by Aleph::Gen_Treap_Rk< NodeType, Key, Compare >::search_or_insert(), and Aleph::Gen_Treap_Rk< NodeType, Key, Compare >::search_or_insert().
|
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 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: the priority of p was drawn before the first comparison. |
noexcept only if the comparison cannot throw, so that what it throws reaches the caller. Definition at line 562 of file tpl_treapRk.H.
References Aleph::Random_Source::get(), Aleph::PRIO(), Aleph::Gen_Treap_Rk< NodeType, Key, Compare >::r, Aleph::Gen_Treap_Rk< NodeType, Key, Compare >::search_or_insert(), and Aleph::Gen_Treap_Rk< NodeType, Key, Compare >::tree_root.
|
inline |
Return the i-th node in order sense.
| [in] | i | inorder position of node to be selected |
| out_of_range | if pos is greater or equal than the number of nodes of tree |
Definition at line 713 of file tpl_treapRk.H.
References Aleph::select(), and Aleph::Gen_Treap_Rk< NodeType, Key, Compare >::tree_root.
Referenced by main().
|
inline |
Seeds the Mersenne Twister of the treap, as gsl_rng_set() did: the priorities are from then on those of GSL for the seed.
A treap that was given no seed makes its Mersenne Twister here.
| [in] | seed | The seed. |
| std::bad_alloc | If the treap has no Mersenne Twister and there is not enough memory for it; then it is unchanged. |
Definition at line 222 of file tpl_treapRk.H.
References Aleph::Random_Source::Mersenne_Twister, Aleph::Gen_Treap_Rk< NodeType, Key, Compare >::r, Aleph::Random_Source::seed(), and seed.
Referenced by TEST().
|
inlinenoexcept |
Return the number of nodes contained in the tree.
Definition at line 719 of file tpl_treapRk.H.
References Aleph::COUNT(), and Aleph::Gen_Treap_Rk< NodeType, Key, Compare >::tree_root.
Referenced by main().
|
inlinenoexcept |
Split the tree according to a key.
It splits with the comparison criteria of the tree, which links the nodes of t1 and t2 in its order: their criteria must order as it does, or their searches may not find the keys that they hold.
| [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 804 of file tpl_treapRk.H.
References Aleph::Gen_Treap_Rk< NodeType, Key, Compare >::cmp, Aleph::split_key_rec_xt(), and Aleph::Gen_Treap_Rk< 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, which links the nodes of t1 and t2 in its order: their criteria must order as it does, or their searches may not find the keys that they hold.
| [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 828 of file tpl_treapRk.H.
References Aleph::Gen_Treap_Rk< NodeType, Key, Compare >::cmp, Aleph::split_key_dup_rec_xt(), and Aleph::Gen_Treap_Rk< NodeType, Key, Compare >::tree_root.
|
inline |
Split the tree at the inorder position pos.
| [in] | pos | inorder position where to split |
| [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 |
Definition at line 840 of file tpl_treapRk.H.
References Aleph::Gen_Treap_Rk< NodeType, Key, Compare >::getRoot(), Aleph::split_pos_rec(), and Aleph::Gen_Treap_Rk< NodeType, Key, Compare >::tree_root.
|
inlinenoexcept |
Swaps in constant time the nodes and the comparison criteria of this and tree.
| [in,out] | tree | 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 353 of file tpl_treapRk.H.
References Aleph::Gen_Treap_Rk< NodeType, Key, Compare >::cmp, Aleph::Gen_Treap_Rk< NodeType, Key, Compare >::r, Aleph::Random_Source::swap(), and Aleph::Gen_Treap_Rk< NodeType, Key, Compare >::tree_root.
|
inline |
Return true if the treap is consistent.
Definition at line 572 of file tpl_treapRk.H.
References Aleph::and, Aleph::check_bst(), Aleph::check_rank_tree(), Aleph::Gen_Treap_Rk< NodeType, Key, Compare >::cmp, Aleph::is_treap(), and Aleph::Gen_Treap_Rk< NodeType, Key, Compare >::tree_root.
Referenced by TEST().
|
private |
Definition at line 201 of file tpl_treapRk.H.
Referenced by Aleph::Gen_Treap_Rk< NodeType, Key, Compare >::find_position(), Aleph::Gen_Treap_Rk< NodeType, Key, Compare >::insert(), Aleph::Gen_Treap_Rk< NodeType, Key, Compare >::insert_dup(), Aleph::Gen_Treap_Rk< NodeType, Key, Compare >::key_comp(), Aleph::Gen_Treap_Rk< NodeType, Key, Compare >::position(), Aleph::Gen_Treap_Rk< NodeType, Key, Compare >::remove(), Aleph::Gen_Treap_Rk< NodeType, Key, Compare >::search(), Aleph::Gen_Treap_Rk< NodeType, Key, Compare >::search_or_insert(), Aleph::Gen_Treap_Rk< NodeType, Key, Compare >::split_key(), Aleph::Gen_Treap_Rk< NodeType, Key, Compare >::split_key_dup(), Aleph::Gen_Treap_Rk< NodeType, Key, Compare >::swap(), Aleph::Gen_Treap_Rk< NodeType, Key, Compare >::Iterator::update_pos(), and Aleph::Gen_Treap_Rk< NodeType, Key, Compare >::verify().
|
private |
The type of node.
Definition at line 197 of file tpl_treapRk.H.
|
private |
Definition at line 198 of file tpl_treapRk.H.
Referenced by Aleph::Gen_Treap_Rk< NodeType, Key, Compare >::Gen_Treap_Rk(), Aleph::Gen_Treap_Rk< NodeType, Key, Compare >::Gen_Treap_Rk(), and Aleph::Gen_Treap_Rk< NodeType, Key, Compare >::Gen_Treap_Rk().
|
private |
Definition at line 200 of file tpl_treapRk.H.
Referenced by Aleph::Gen_Treap_Rk< NodeType, Key, Compare >::find_position(), Aleph::Gen_Treap_Rk< NodeType, Key, Compare >::insert(), Aleph::Gen_Treap_Rk< NodeType, Key, Compare >::insert_dup(), Aleph::Gen_Treap_Rk< NodeType, Key, Compare >::join(), Aleph::Gen_Treap_Rk< NodeType, Key, Compare >::join_dup(), Aleph::Gen_Treap_Rk< NodeType, Key, Compare >::random_source(), Aleph::Gen_Treap_Rk< NodeType, Key, Compare >::random_source(), Aleph::Gen_Treap_Rk< NodeType, Key, Compare >::rng(), Aleph::Gen_Treap_Rk< NodeType, Key, Compare >::search_or_insert(), Aleph::Gen_Treap_Rk< NodeType, Key, Compare >::set_seed(), Aleph::Gen_Treap_Rk< NodeType, Key, Compare >::swap(), and Aleph::Gen_Treap_Rk< NodeType, Key, Compare >::Iterator::verify().
|
private |
Definition at line 199 of file tpl_treapRk.H.
Referenced by Aleph::Gen_Treap_Rk< NodeType, Key, Compare >::Gen_Treap_Rk(), Aleph::Gen_Treap_Rk< NodeType, Key, Compare >::find_position(), Aleph::Gen_Treap_Rk< NodeType, Key, Compare >::getRoot(), Aleph::Gen_Treap_Rk< NodeType, Key, Compare >::getRoot(), Aleph::Gen_Treap_Rk< NodeType, Key, Compare >::insert(), Aleph::Gen_Treap_Rk< NodeType, Key, Compare >::insert_dup(), Aleph::Gen_Treap_Rk< NodeType, Key, Compare >::is_empty(), Aleph::Gen_Treap_Rk< NodeType, Key, Compare >::join(), Aleph::Gen_Treap_Rk< NodeType, Key, Compare >::join_dup(), Aleph::Gen_Treap_Rk< NodeType, Key, Compare >::join_exclusive(), Aleph::Gen_Treap_Rk< NodeType, Key, Compare >::position(), Aleph::Gen_Treap_Rk< NodeType, Key, Compare >::remove(), Aleph::Gen_Treap_Rk< NodeType, Key, Compare >::remove(), Aleph::Gen_Treap_Rk< NodeType, Key, Compare >::remove_pos(), Aleph::Gen_Treap_Rk< NodeType, Key, Compare >::search(), Aleph::Gen_Treap_Rk< NodeType, Key, Compare >::search_or_insert(), Aleph::Gen_Treap_Rk< NodeType, Key, Compare >::select(), Aleph::Gen_Treap_Rk< NodeType, Key, Compare >::size(), Aleph::Gen_Treap_Rk< NodeType, Key, Compare >::split_key(), Aleph::Gen_Treap_Rk< NodeType, Key, Compare >::split_key_dup(), Aleph::Gen_Treap_Rk< NodeType, Key, Compare >::split_pos(), Aleph::Gen_Treap_Rk< NodeType, Key, Compare >::swap(), and Aleph::Gen_Treap_Rk< NodeType, Key, Compare >::verify().