|
Aleph-w 7.10.0
A C++ Library for Data Structures and Algorithms
|
Treap (a special type of randomized binary search tree) using nodes without virtual destructor. More...
#include <tpl_treap.H>
Public Types | |
| using | Base = Gen_Treap< TreapNode, Key, Compare > |
Public Types inherited from Aleph::Gen_Treap< NodeType, Key, Compare > | |
| using | Node = NodeType< Key > |
Additional Inherited Members | |
Public Member Functions inherited from Aleph::Gen_Treap< NodeType, Key, Compare > | |
| 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. | |
| void | swap (Gen_Treap &tree) noexcept(std::is_nothrow_swappable_v< Compare >) |
Swaps in constant time the nodes and the comparison criteria of this and tree. | |
| Compare & | key_comp () noexcept |
| return the comparison criteria | |
| Compare & | get_compare () noexcept |
See key_comp(). | |
| Gen_Treap (const unsigned long seed, const 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 () noexcept(std::is_nothrow_default_constructible_v< Node > and std::is_nothrow_default_constructible_v< Compare > and std::is_nothrow_copy_constructible_v< 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 (const Compare &cmp) noexcept(std::is_nothrow_default_constructible_v< Node > and std::is_nothrow_copy_constructible_v< 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 (Gen_Treap &&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. | |
| 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. | |
| Node *& | getRoot () noexcept |
| Return the tree's root. | |
| 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 * | search_or_insert (Node *p) noexcept(nothrow_compare_v< Compare, Key >) |
| Search or insert a key. | |
| Node * | insert_dup (Node *p) noexcept(nothrow_compare_v< Compare, Key >) |
| Insert a node in the tree. | |
| bool | verify () const |
Return true if this is a consistent treap. | |
| Node * | remove (const Key &key) noexcept(nothrow_compare_v< Compare, Key >) |
| Remove a key from the tree. | |
| void | join (Gen_Treap &t, Gen_Treap &dup) noexcept |
Join this with t filtering the duplicated keys. | |
| void | join_dup (Gen_Treap &t) noexcept |
Join this with t independently of the presence of duplicated keys. | |
| void | join_exclusive (Gen_Treap &t) noexcept |
Join exclusive of this with t | |
| bool | split_key (const Key &key, Gen_Treap &t1, Gen_Treap &t2) noexcept(nothrow_compare_v< Compare, Key >) |
| Split the tree according to a key. | |
| void | split_key_dup (const Key &key, Gen_Treap &t1, Gen_Treap &t2) noexcept(nothrow_compare_v< Compare, Key >) |
| Split the tree according to a key that could be in the tree. | |
Treap (a special type of randomized binary search tree) using nodes without virtual destructor.
The treap is a binary search tree whose very high performance is achieved by randomization. The basic idea is to store a priority value in each node which is randomly chosen. By the side of keys, the tree a binary search, but by the side of priorities, the tree is a heap. It is shown that this class of tree has an expected perfomance of \(O(\lg n)\) for the majority of its operations.
The treap is faster than the randomized tree by a constant time (both approaches are logarithmic). However, since the priority is chosen just one time and the adjustements are done in a botton-top way (by contrast with the randomized which is top-bottom), the treap takes less time.
The priorities come from a Random_Source: by default, from a SplitMix64 inside the treap, with a seed of its own; with a seed, from a Gsl_Compatible_Rng, the Mersenne twister with the numbers of the one of GSL - GNU Scientific Library, which it used before.
Definition at line 796 of file tpl_treap.H.
| using Aleph::Treap< Key, Compare >::Base = Gen_Treap<TreapNode, Key, Compare> |
Definition at line 798 of file tpl_treap.H.