Aleph-w 3.0
A C++ Library for Data Structures and Algorithms
Loading...
Searching...
No Matches
Aleph::Gen_Rand_Tree< NodeType, Key, Compare > Class Template Reference

Randomized binary search tree with rank support. More...

#include <tpl_rand_tree.H>

Inheritance diagram for Aleph::Gen_Rand_Tree< NodeType, Key, Compare >:
[legend]

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_Treeoperator= (const Gen_Rand_Tree &)=delete
 
Compare & key_comp () noexcept
 return the comparison criteria
 
const Compare & key_comp () const noexcept
 
Compare & get_compare () noexcept
 
const Compare & get_compare () const noexcept
 
gsl_rnggsl_rng_object () noexcept
 Get a pointer to gsl random number generator.
 
void set_seed (const unsigned long seed) noexcept
 Set the random number generator seed.
 
 Gen_Rand_Tree (const unsigned int seed, const Compare &__cmp=Compare())
 Initialize a random tree with random seed and comparison criteria __cmp
 
 Gen_Rand_Tree (const Compare &cmp=Compare()) noexcept
 Initialize a random tree with random seed from system time and comparison criteria cmp
 
void swap (Gen_Rand_Tree &tree) noexcept
 Swap in constant time all the nodes of this with tree
 
 Gen_Rand_Tree (Gen_Rand_Tree &&other) noexcept
 Move constructor - transfers ownership of tree and RNG.
 
Gen_Rand_Treeoperator= (Gen_Rand_Tree &&other) noexcept
 Move assignment - transfers ownership of tree and RNG.
 
virtual ~Gen_Rand_Tree () noexcept
 
Nodeinsert (Node *p) noexcept
 Insert a node in the tree.
 
Nodeinsert_dup (Node *p) noexcept
 Insert a node in the tree.
 
Noderemove (const Key &key) noexcept
 Remove a key from the tree.
 
Nodesearch (const Key &key) const noexcept
 Search a key.
 
Nodesearch_or_insert (Node *p) noexcept
 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.
 
Nodeselect (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
 Compute the inorder position of a key.
 
std::pair< long, Node * > find_position (const Key &key) const noexcept
 Find the inorder position of a key in the tree.
 
Noderemove_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
 Split the tree according to a key.
 
void split_key_dup (const Key &key, Gen_Rand_Tree &t1, Gen_Rand_Tree &t2) noexcept
 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) noexcept
 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

Noderandom_insert (Node *root, Node *p) noexcept
 
Noderandom_insert_dup (Node *root, Node *p) noexcept
 
Noderandom_search_or_insert (Node *&root, Node *p) noexcept
 
void init (const unsigned long seed)
 
Noderandom_join_exclusive (Node *tl, Node *tr) noexcept
 
Noderandom_remove (Node *&root, const Key &key) noexcept
 
Noderemove_pos (Node *&root, const size_t pos) noexcept
 
Noderandom_join (Node *t1, Node *t2, Node *&dup)
 
Noderandom_join (Node *t1, Node *t2)
 

Private Attributes

Nodetree_root
 The type of node.
 
gsl_rngr
 
Compare cmp
 

Detailed Description

template<template< typename > class NodeType, typename Key, class Compare>
class Aleph::Gen_Rand_Tree< NodeType, Key, Compare >

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.

Key Insight:
At each insertion, a random "raffle" determines whether the new node becomes the root (and existing nodes are split around it) or is inserted recursively into a subtree. This ensures that every node has an equal probability of being at any position, producing expected O(log n) height.
Ranked Operations:
Unlike basic BSTs, randomized trees maintain subtree sizes (COUNT), enabling O(log n) access by rank (inorder position):
  • select(i): Get the i-th smallest element
  • position(key): Get the rank of a key
  • remove_pos(i): Remove the i-th element

This allows treating the tree like a sorted dynamic array with O(log n) indexed access, insertion, and deletion.

Split and Join:
Randomized trees excel at split/join operations, which take O(log(max(n,m))) time. This is dramatically better than other balanced trees that require O(n log m) for joining two trees of sizes n and m.
Template Parameters
NodeTypeNode template (RandNode or RandNodeVtl).
KeyThe type of keys stored in the tree.
CompareComparison functor for ordering keys.
Complexity:
  • Search: O(log n) expected
  • Insert: O(log n) expected
  • Delete: O(log n) expected
  • Select (by rank): O(log n) expected
  • Position (get rank): O(log n) expected
  • Split: O(log n) expected
  • Join: O(log(max(n,m))) expected - much better than other trees
  • Space: O(n) + O(1) per node for COUNT
Random Number Generator:
Uses GSL (GNU Scientific Library) Mersenne Twister (mt19937) by default. Seed can be set via set_seed() for reproducible behavior.
Example:
// Insert nodes
// Ranked access (treat as sorted array)
auto smallest = tree.select(0); // Get 0th element (8)
auto median = tree.select(tree.size() / 2); // Get median
// Find position/rank of a key
size_t pos = tree.position(42); // Returns 2 (0-indexed)
// Remove by position
auto removed = tree.remove_pos(1); // Remove 2nd smallest
delete removed;
// Efficient split at key
Rand_Tree<int> left, right;
tree.split_key(50, left, right); // All <= 50 go to left, > 50 to right
// Efficient join (O(log(max(n,m))))
tree.join(left, right);
NodeType< Key > Node
bool split_key(const Key &key, Gen_Rand_Tree &t1, Gen_Rand_Tree &t2) noexcept
Split the tree according to a key.
Node * insert(Node *p) noexcept
Insert a node in the tree.
size_t size() const noexcept
Return the number of nodes that have the tree.
Node * select(const size_t i) const
Return the i-th node in inorder sense.
void join(Gen_Rand_Tree &t, Gen_Rand_Tree &dup) noexcept
Join this with t filtering the duplicated keys.
Node * remove_pos(Node *&root, const size_t pos) noexcept
std::pair< long, Node * > position(const Key &key) const noexcept
Compute the inorder position of a key.
const T * median(const T &a, const T &b, const T &c, const Compare &cmp=Compare())
Return a pointer to the median value among three elements.
Definition ahUtils.H:84
DynList< T > maps(const C &c, Op op)
Classic map operation.
Randomized binary search tree.
Note
This is a low-level implementation managing raw nodes. For automatic memory management, use DynSetRandTree.
All operations maintain COUNT values for ranked operations.
Best choice when frequent split/join operations are needed.
See also
Rand_Tree Convenient typedef for Rand_Tree<Key, Compare>.
Treap Alternative randomized tree (often faster by constant factor).
TreapRk Treap with rank support.
DynSetRandTree High-level wrapper with automatic memory management.

Definition at line 151 of file tpl_rand_tree.H.

Member Typedef Documentation

◆ Node

template<template< typename > class NodeType, typename Key , class Compare >
using Aleph::Gen_Rand_Tree< NodeType, Key, Compare >::Node = NodeType<Key>

Definition at line 154 of file tpl_rand_tree.H.

Constructor & Destructor Documentation

◆ Gen_Rand_Tree() [1/4]

template<template< typename > class NodeType, typename Key , class Compare >
Aleph::Gen_Rand_Tree< NodeType, Key, Compare >::Gen_Rand_Tree ( const Gen_Rand_Tree< NodeType, Key, Compare > &  )
delete

◆ Gen_Rand_Tree() [2/4]

template<template< typename > class NodeType, typename Key , class Compare >
Aleph::Gen_Rand_Tree< NodeType, Key, Compare >::Gen_Rand_Tree ( const unsigned int  seed,
const Compare &  __cmp = Compare() 
)
inline

Initialize a random tree with random seed and comparison criteria __cmp

Definition at line 307 of file tpl_rand_tree.H.

References Aleph::init.

◆ Gen_Rand_Tree() [3/4]

template<template< typename > class NodeType, typename Key , class Compare >
Aleph::Gen_Rand_Tree< NodeType, Key, Compare >::Gen_Rand_Tree ( const Compare &  cmp = Compare())
inlinenoexcept

Initialize a random tree with random seed from system time and comparison criteria cmp

Definition at line 315 of file tpl_rand_tree.H.

◆ Gen_Rand_Tree() [4/4]

template<template< typename > class NodeType, typename Key , class Compare >
Aleph::Gen_Rand_Tree< NodeType, Key, Compare >::Gen_Rand_Tree ( Gen_Rand_Tree< NodeType, Key, Compare > &&  other)
inlinenoexcept

Move constructor - transfers ownership of tree and RNG.

Definition at line 329 of file tpl_rand_tree.H.

References Aleph::maps().

◆ ~Gen_Rand_Tree()

template<template< typename > class NodeType, typename Key , class Compare >
virtual Aleph::Gen_Rand_Tree< NodeType, Key, Compare >::~Gen_Rand_Tree ( )
inlinevirtualnoexcept

Member Function Documentation

◆ find_position()

template<template< typename > class NodeType, typename Key , class Compare >
std::pair< long, Node * > Aleph::Gen_Rand_Tree< NodeType, Key, Compare >::find_position ( const Key &  key) const
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:

  1. if key is lesser than the minimum key of tree, then first is -1 and the node is one with the smallest key.
  2. If 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.
  3. For any other case, first is the inorder position that would have key if this was in the tree and second is the node whose key is immediately greater than key.
Parameters
[in]keyto be searched
Returns
a pair with the inorder position and related node

Definition at line 572 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::maps(), 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(), TEST(), TEST(), TEST(), and TEST().

◆ get_compare() [1/2]

template<template< typename > class NodeType, typename Key , class Compare >
Aleph::Gen_Rand_Tree< NodeType, Key, Compare >::get_compare ( ) const
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 294 of file tpl_rand_tree.H.

References Aleph::Gen_Rand_Tree< NodeType, Key, Compare >::cmp.

◆ get_compare() [2/2]

template<template< typename > class NodeType, typename Key , class Compare >
Compare & Aleph::Gen_Rand_Tree< NodeType, Key, Compare >::get_compare ( )
inlinenoexcept

Definition at line 291 of file tpl_rand_tree.H.

References Aleph::Gen_Rand_Tree< NodeType, Key, Compare >::key_comp().

Referenced by TEST().

◆ getRoot()

◆ gsl_rng_object()

template<template< typename > class NodeType, typename Key , class Compare >
gsl_rng * Aleph::Gen_Rand_Tree< NodeType, Key, Compare >::gsl_rng_object ( )
inlinenoexcept

Get a pointer to gsl random number generator.

Definition at line 297 of file tpl_rand_tree.H.

References Aleph::Gen_Rand_Tree< NodeType, Key, Compare >::r.

Referenced by TEST().

◆ init()

template<template< typename > class NodeType, typename Key , class Compare >
void Aleph::Gen_Rand_Tree< NodeType, Key, Compare >::init ( const unsigned long  seed)
inlineprivate

◆ insert()

template<template< typename > class NodeType, typename Key , class Compare >
Node * Aleph::Gen_Rand_Tree< NodeType, Key, Compare >::insert ( Node p)
inlinenoexcept

Insert a node in the tree.

Parameters
[in]ppointer to the node to insert
Returns
if p->get_key() is not in the tree, then the pointer p is returned (it was inserted); otherwise, nullptr is returned

Definition at line 372 of file tpl_rand_tree.H.

References Aleph::COUNT(), Aleph::LLINK(), Aleph::maps(), Aleph::Gen_Rand_Tree< NodeType, Key, Compare >::random_insert(), Aleph::RLINK(), and Aleph::Gen_Rand_Tree< NodeType, Key, Compare >::tree_root.

Referenced by RankTreeTest< Tree >::insert_all(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), test(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), and write_rand().

◆ insert_dup()

template<template< typename > class NodeType, typename Key , class Compare >
Node * Aleph::Gen_Rand_Tree< NodeType, Key, Compare >::insert_dup ( Node p)
inlinenoexcept

Insert a node in the tree.

This method does not fail. It always inserts.

Parameters
[in]ppointer to the node to insert
Returns
the p pointer

Definition at line 392 of file tpl_rand_tree.H.

References Aleph::COUNT(), Aleph::LLINK(), Aleph::maps(), Aleph::Gen_Rand_Tree< NodeType, Key, Compare >::random_insert_dup(), Aleph::RLINK(), and Aleph::Gen_Rand_Tree< NodeType, Key, Compare >::tree_root.

Referenced by TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), and TEST().

◆ is_empty()

template<template< typename > class NodeType, typename Key , class Compare >
bool Aleph::Gen_Rand_Tree< NodeType, Key, Compare >::is_empty ( ) const
inlinenoexcept

◆ join()

template<template< typename > class NodeType, typename Key , class Compare >
void Aleph::Gen_Rand_Tree< NodeType, Key, Compare >::join ( Gen_Rand_Tree< NodeType, Key, Compare > &  t,
Gen_Rand_Tree< NodeType, Key, Compare > &  dup 
)
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

Parameters
[in]trandomized tree to join with this
[out]duprandomized tree where nodes containing duplicated keys are inserted

Definition at line 758 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.

◆ join_dup()

template<template< typename > class NodeType, typename Key , class Compare >
void Aleph::Gen_Rand_Tree< NodeType, Key, Compare >::join_dup ( Gen_Rand_Tree< NodeType, Key, Compare > &  t)
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.

Parameters
[in]trandomized tree to join with this keys are inserted

Definition at line 772 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.

◆ join_exclusive()

template<template< typename > class NodeType, typename Key , class Compare >
void Aleph::Gen_Rand_Tree< NodeType, Key, Compare >::join_exclusive ( Gen_Rand_Tree< NodeType, Key, Compare > &  t)
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.

Parameters
[in]trandomized tree to exclusively join with this keys are inserted

Definition at line 789 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.

◆ key_comp() [1/2]

template<template< typename > class NodeType, typename Key , class Compare >
Aleph::Gen_Rand_Tree< NodeType, Key, Compare >::key_comp ( ) const
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 288 of file tpl_rand_tree.H.

References Aleph::Gen_Rand_Tree< NodeType, Key, Compare >::cmp.

◆ key_comp() [2/2]

template<template< typename > class NodeType, typename Key , class Compare >
Aleph::Gen_Rand_Tree< NodeType, Key, Compare >::key_comp ( )
inlinenoexcept

return the comparison criteria

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 285 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(), TEST(), and TEST().

◆ operator=() [1/2]

template<template< typename > class NodeType, typename Key , class Compare >
Gen_Rand_Tree & Aleph::Gen_Rand_Tree< NodeType, Key, Compare >::operator= ( const Gen_Rand_Tree< NodeType, Key, Compare > &  )
delete

◆ operator=() [2/2]

template<template< typename > class NodeType, typename Key , class Compare >
Gen_Rand_Tree & Aleph::Gen_Rand_Tree< NodeType, Key, Compare >::operator= ( Gen_Rand_Tree< NodeType, Key, Compare > &&  other)
inlinenoexcept

◆ random_insert()

◆ random_insert_dup()

◆ random_join() [1/2]

◆ random_join() [2/2]

◆ random_join_exclusive()

◆ random_remove()

◆ random_search_or_insert()

◆ remove()

template<template< typename > class NodeType, typename Key , class Compare >
Node * Aleph::Gen_Rand_Tree< NodeType, Key, Compare >::remove ( const Key &  key)
inlinenoexcept

◆ remove_pos() [1/2]

template<template< typename > class NodeType, typename Key , class Compare >
Node * Aleph::Gen_Rand_Tree< NodeType, Key, Compare >::remove_pos ( const size_t  i)
inline

Remove the key at inorder position i

Parameters
[in]iinorder position to be removed
Returns
a valid pointer to the removed node
Exceptions
out_of_rangeif i is greater or equal than the number of nodes of tree

Definition at line 607 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.

◆ remove_pos() [2/2]

◆ search()

template<template< typename > class NodeType, typename Key , class Compare >
Node * Aleph::Gen_Rand_Tree< NodeType, Key, Compare >::search ( const Key &  key) const
inlinenoexcept

Search a key.

Parameters
[in]keyto be searched
Returns
a pointer to the containing key if this was found; otherwise nullptr

Definition at line 475 of file tpl_rand_tree.H.

References Aleph::Gen_Rand_Tree< NodeType, Key, Compare >::cmp, Aleph::maps(), and Aleph::Gen_Rand_Tree< NodeType, Key, Compare >::tree_root.

Referenced by TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), test(), TEST_F(), TEST_F(), TEST_F(), and write_rand().

◆ search_or_insert()

template<template< typename > class NodeType, typename Key , class Compare >
Node * Aleph::Gen_Rand_Tree< NodeType, Key, Compare >::search_or_insert ( Node p)
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.

Parameters
[in]pnode containing a key to be searched and eventually inserted
Returns
if the key contained in p is found, then a pointer to the containing key in the tree is returned. Otherwise, p is inserted and returned

Definition at line 493 of file tpl_rand_tree.H.

References Aleph::COUNT(), Aleph::maps(), Aleph::Gen_Rand_Tree< NodeType, Key, Compare >::random_search_or_insert(), and Aleph::Gen_Rand_Tree< NodeType, Key, Compare >::tree_root.

Referenced by TEST(), TEST(), TEST(), TEST(), and TEST().

◆ select()

template<template< typename > class NodeType, typename Key , class Compare >
Node * Aleph::Gen_Rand_Tree< NodeType, Key, Compare >::select ( const size_t  i) const
inline

Return the i-th node in inorder sense.

Parameters
[in]iinorder position to be located
Returns
a valid pointer to the i-th node inorder sense
Exceptions
out_of_rangeif i is greater or equal that the number of nodes

Definition at line 517 of file tpl_rand_tree.H.

References Aleph::select(), and Aleph::Gen_Rand_Tree< NodeType, Key, Compare >::tree_root.

Referenced by TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), and TEST().

◆ set_seed()

template<template< typename > class NodeType, typename Key , class Compare >
void Aleph::Gen_Rand_Tree< NodeType, Key, Compare >::set_seed ( const unsigned long  seed)
inlinenoexcept

Set the random number generator seed.

Definition at line 300 of file tpl_rand_tree.H.

References Aleph::maps(), and Aleph::Gen_Rand_Tree< NodeType, Key, Compare >::r.

◆ size()

◆ split_key()

template<template< typename > class NodeType, typename Key , class Compare >
bool Aleph::Gen_Rand_Tree< NodeType, Key, Compare >::split_key ( const Key &  key,
Gen_Rand_Tree< NodeType, Key, Compare > &  t1,
Gen_Rand_Tree< NodeType, Key, Compare > &  t2 
)
inlinenoexcept

Split the tree according to a key.

Parameters
[in]keyfor splitting
[out]t1tree with keys lesser than key
[out]t2tree with keys greater than key
Returns
true if tree was split; that is if key is not in the tree. Otherwise, if key is in the tree, false is returned

Definition at line 622 of file tpl_rand_tree.H.

References Aleph::maps(), Aleph::split_key_rec_xt(), and Aleph::Gen_Rand_Tree< NodeType, Key, Compare >::tree_root.

Referenced by TEST(), and TEST().

◆ split_key_dup()

template<template< typename > class NodeType, typename Key , class Compare >
void Aleph::Gen_Rand_Tree< NodeType, Key, Compare >::split_key_dup ( const Key &  key,
Gen_Rand_Tree< NodeType, Key, Compare > &  t1,
Gen_Rand_Tree< NodeType, Key, Compare > &  t2 
)
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.

Parameters
[in]keyfor splitting
[out]t1resulting tree with the keys lesser than key
[out]t2resulting tree with the keys greater or equal than key

Definition at line 638 of file tpl_rand_tree.H.

References Aleph::maps(), Aleph::split_key_dup_rec_xt(), and Aleph::Gen_Rand_Tree< NodeType, Key, Compare >::tree_root.

Referenced by TEST().

◆ split_pos()

template<template< typename > class NodeType, typename Key , class Compare >
void Aleph::Gen_Rand_Tree< NodeType, Key, Compare >::split_pos ( size_t  pos,
Gen_Rand_Tree< NodeType, Key, Compare > &  t1,
Gen_Rand_Tree< NodeType, Key, Compare > &  t2 
)
inlinenoexcept

Split a extended binary tree according to a position.

split_pos(pos, ts, tg) splits the tree two trees t1 and t2 according to a position pos. t1 contains the keys from 0 to pos - 1 inorder sense and tg the keys from pos to n -

  1. After completion this becames empty.
Parameters
[in]posposition for splitting
[out]t1tree where the rank of keys \([0, i)\) will be put
[out]t2tree where the rank of keys \([i, n]\) will be put

Definition at line 655 of file tpl_rand_tree.H.

References Aleph::maps(), Aleph::split_pos_rec(), and Aleph::Gen_Rand_Tree< NodeType, Key, Compare >::tree_root.

Referenced by TEST().

◆ swap()

template<template< typename > class NodeType, typename Key , class Compare >
void Aleph::Gen_Rand_Tree< NodeType, Key, Compare >::swap ( Gen_Rand_Tree< NodeType, Key, Compare > &  tree)
inlinenoexcept

◆ verify()

template<template< typename > class NodeType, typename Key , class Compare >
bool Aleph::Gen_Rand_Tree< NodeType, Key, Compare >::verify ( ) const
inline

Return true if this is a consistent randomized tree.

Definition at line 502 of file tpl_rand_tree.H.

References Aleph::check_rank_tree(), and Aleph::Gen_Rand_Tree< NodeType, Key, Compare >::tree_root.

Referenced by TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), TEST(), and TEST().

Member Data Documentation

◆ cmp

◆ r

◆ tree_root

template<template< typename > class NodeType, typename Key , class Compare >
Node* Aleph::Gen_Rand_Tree< NodeType, Key, Compare >::tree_root
private

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