Aleph-w 7.10.0
A C++ Library for Data Structures and Algorithms
Loading...
Searching...
No Matches
Aleph::Rand_Tree_Vtl< Key, Compare > Struct Template Reference

Randomized binary search tree. More...

#include <tpl_rand_tree.H>

Inheritance diagram for Aleph::Rand_Tree_Vtl< Key, Compare >:
[legend]
Collaboration diagram for Aleph::Rand_Tree_Vtl< Key, Compare >:
[legend]

Public Types

using Base = Gen_Rand_Tree< RandNodeVtl, Key, Compare >
 
- Public Types inherited from Aleph::Gen_Rand_Tree< NodeType, Key, Compare >
using Node = NodeType< Key >
 

Additional Inherited Members

- Public Member Functions inherited from Aleph::Gen_Rand_Tree< NodeType, Key, Compare >
 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
 

Detailed Description

template<typename Key, class Compare = Aleph::less<Key>>
requires StrictWeakOrder<Compare, Key>
struct Aleph::Rand_Tree_Vtl< Key, Compare >

Randomized binary search tree.

This class implements a randomized binary search tree. It is shown that this type of tree always is equivalent to a classic binary search tree built from a random insertion sequence. Consequently, all the operations of this tree are \(O(\lg n)\) expected case, independently of insertion order and of removals are interleaved with insertions.

In addition, these trees support select() and position() operations. That is, their keys can be accessed according to their inorder position and logarithmic time. This allows to treat the tree as if it was an array.

This tree type is unbeatable when there are splits and especially joins operations on very large data sets. Other tree types perform the join of independent data sets in \(O(n \lg m)\), where \(n\) and \(m\) are the size of two data sets, while the randomized approach takes \(O(\max(\lg n, \lg m))\).

The positions come from a Random_Source: by default, from a SplitMix64 inside the tree, 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.

See also
Treap Treap_Vtl Treap_Rk

Definition at line 1053 of file tpl_rand_tree.H.

Member Typedef Documentation

◆ Base

template<typename Key , class Compare = Aleph::less<Key>>
using Aleph::Rand_Tree_Vtl< Key, Compare >::Base = Gen_Rand_Tree<RandNodeVtl, Key, Compare>

Definition at line 1055 of file tpl_rand_tree.H.


The documentation for this struct was generated from the following file: