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

Treap - A randomized binary search tree using heap-ordered priorities. More...

#include <tpl_treap.H>

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

Classes

struct  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.
 
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.
 

Private Member Functions

Node * 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
 

Private Attributes

Node head
 The type of node.
 
Node * head_ptr
 
Node *& tree_root
 
Random_Source r
 
Compare cmp
 

Detailed Description

template<template< typename > class NodeType, typename Key, class Compare>
requires StrictWeakOrder<Compare, Key>
class Aleph::Gen_Treap< NodeType, Key, Compare >

Treap - A randomized binary search tree using heap-ordered priorities.

A Treap (tree + heap) is a randomized binary search tree that combines BST properties on keys with heap properties on randomly assigned priorities. Each node has a key (BST-ordered) and a random priority (heap-ordered).

Key Properties:
  • Keys follow BST ordering: left < parent < right
  • Priorities follow max-heap ordering: parent priority > child priorities
  • Priorities are randomly assigned at insertion time
  • Expected O(log n) height due to randomization

The dual ordering (BST for keys, heap for priorities) creates a unique tree structure for any set of keys with given priorities, ensuring good balance with high probability.

Comparison with Other Randomized Trees:
  • Treap vs Rand_Tree: Treap is typically faster by a constant factor because priorities are chosen once at insertion (bottom-up balancing), while Rand_Tree makes random decisions at each level (top-down).
  • Treap vs AVL/RB: Treap has simpler code, uses randomization instead of deterministic balancing, but has expected (not worst-case) guarantees.
Template Parameters
NodeTypeNode template (TreapNode or TreapNodeVtl).
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
  • Split: O(log n) expected
  • Join: O(log n) expected
  • Space: O(n) + O(1) per node for priority
Random Number Generator:
The priorities come from a Random_Source. A treap that is given no seed draws them from a SplitMix64 inside it, with a seed of its own: it is built and moved without allocating. With a seed, that of a constructor or of set_seed(), it draws them from a Gsl_Compatible_Rng, the Mersenne Twister (mt19937) with the numbers of the one of GSL, which it used before: for a seed, the priorities, and so the trees, are the same. random_source() gives the source, which can be asked for a SplitMix64 with a seed.
Example:
// Set seed for reproducibility (optional)
tree.set_seed(12345);
// Insert nodes
tree.insert(new Treap<int>::Node(42));
tree.insert(new Treap<int>::Node(17));
tree.insert(new Treap<int>::Node(99));
// Search
auto node = tree.search(42);
if (node != nullptr)
std::cout << "Found: " << node->get_key()
<< " (priority: " << PRIO(node) << ")" << '\n';
// Split tree at key 50
Treap<int> left, right;
tree.split_key(50, left, right);
// Join trees
tree.join(left, right);
// Remove
auto removed = tree.remove(42);
delete removed;
NodeType< Key > Node
Definition tpl_treap.H:159
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 ...
Definition tpl_treap.H:186
Node * search(const Key &key) const noexcept(nothrow_compare_v< Compare, Key >)
Search a key in a treap.
Definition tpl_treap.H:350
void join(Node *&t1, Node *t2, Node *&dup) noexcept
Definition tpl_treap.H:632
Node * insert(Node *root, Node *p) noexcept(nothrow_compare_v< Compare, Key >)
Definition tpl_treap.H:360
Node * remove(const Key &key) noexcept(nothrow_compare_v< Compare, Key >)
Remove a key from the tree.
Definition tpl_treap.H:539
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.
Definition tpl_treap.H:727
unsigned long & PRIO(Node *p) noexcept
Access the priority of a treap node.
Definition treapNode.H:120
Treap (a special type of randomized binary search tree) using nodes without virtual destructor.
Definition tpl_treap.H:797
Note
This is a low-level implementation managing raw nodes. For automatic memory management, use DynSetTreap.
Priorities are assigned automatically and transparently.
For ranked operations (indexed access), use TreapRk instead.
See also
Treap Convenient typedef for Treap<Key, Compare>.
TreapRk Treap variant with rank support for O(log n) indexed access.
Rand_Tree Alternative randomized tree with top-down balancing.
DynSetTreap High-level wrapper with automatic memory management.

Definition at line 156 of file tpl_treap.H.

Member Typedef Documentation

◆ Node

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

Definition at line 159 of file tpl_treap.H.

Constructor & Destructor Documentation

◆ Gen_Treap() [1/4]

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

Builds an empty treap whose priorities are those of GSL for seed: it draws them from a Mersenne Twister, in dynamic memory.

Parameters
[in]seedThe seed, taken through an unsigned int, modulo 2^32 - 1, as it was for GSL.
[in]__cmpThe comparison criteria, which the treap copies.
Exceptions
std::bad_allocIf 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 223 of file tpl_treap.H.

References Aleph::Gen_Treap< NodeType, Key, Compare >::head_ptr, Aleph::Min_Priority, and Aleph::PRIO().

◆ Gen_Treap() [2/4]

template<template< typename > class NodeType, typename Key , class Compare >
Aleph::Gen_Treap< NodeType, Key, Compare >::Gen_Treap ( )
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.

Exceptions
whatthe 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 244 of file tpl_treap.H.

◆ Gen_Treap() [3/4]

template<template< typename > class NodeType, typename Key , class Compare >
Aleph::Gen_Treap< NodeType, Key, Compare >::Gen_Treap ( const Compare &  cmp)
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.

Parameters
[in]cmpThe comparison criteria, which the treap copies.
Exceptions
whatthe default construction of the key of the header node or the copy of cmp throws; nothing when both are noexcept.

Definition at line 262 of file tpl_treap.H.

References Aleph::Gen_Treap< NodeType, Key, Compare >::head_ptr, Aleph::Min_Priority, and Aleph::PRIO().

◆ Gen_Treap() [4/4]

template<template< typename > class NodeType, typename Key , class Compare >
Aleph::Gen_Treap< NodeType, Key, Compare >::Gen_Treap ( Gen_Treap< NodeType, Key, Compare > &&  tree)
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()).

Parameters
[in,out]treeThe 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.
Exceptions
whatthe 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 292 of file tpl_treap.H.

References Aleph::Gen_Treap< NodeType, Key, Compare >::head_ptr, Aleph::Min_Priority, Aleph::PRIO(), and Aleph::Gen_Treap< NodeType, Key, Compare >::tree_root.

Member Function Documentation

◆ generator_seed()

template<template< typename > class NodeType, typename Key , class Compare >
static unsigned long Aleph::Gen_Treap< NodeType, Key, Compare >::generator_seed ( const unsigned long  seed)
inlinestaticprivatenoexcept

Definition at line 170 of file tpl_treap.H.

References Aleph::Gsl_Compatible_Rng::max(), and seed.

◆ get_compare()

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

◆ getRoot()

template<template< typename > class NodeType, typename Key , class Compare >
Node *& Aleph::Gen_Treap< NodeType, Key, Compare >::getRoot ( )
inlinenoexcept

Return the tree's root.

Definition at line 338 of file tpl_treap.H.

References Aleph::Gen_Treap< NodeType, Key, Compare >::tree_root.

Referenced by main(), TEST(), TEST(), TreapTest::tree_empty(), TreapTest::tree_size(), and write_treap().

◆ insert() [1/2]

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

Insert a node in a treap.

insert(p) inserts the node p in this treap.

Parameters
[in]ppointer to the node to be inserted
Returns
if p->get_key() is not in the tree, then p is inserted and this node pointer is returned. Otherwise, it is returned nullptr.
Exceptions
anythingthat 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.
Note
It is noexcept only if the comparison cannot throw, so that what it throws reaches the caller.

Definition at line 458 of file tpl_treap.H.

References Aleph::Random_Source::get(), Aleph::Gen_Treap< NodeType, Key, Compare >::insert(), Aleph::PRIO(), Aleph::Gen_Treap< NodeType, Key, Compare >::r, and Aleph::Gen_Treap< NodeType, Key, Compare >::tree_root.

◆ insert() [2/2]

◆ insert_dup() [1/2]

template<template< typename > class NodeType, typename Key , class Compare >
Node * Aleph::Gen_Treap< 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
Exceptions
anythingthat 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.
Note
It is noexcept only if the comparison cannot throw, so that what it throws reaches the caller.

Definition at line 512 of file tpl_treap.H.

References Aleph::Random_Source::get(), Aleph::Gen_Treap< NodeType, Key, Compare >::insert_dup(), Aleph::PRIO(), Aleph::Gen_Treap< NodeType, Key, Compare >::r, and Aleph::Gen_Treap< NodeType, Key, Compare >::tree_root.

◆ insert_dup() [2/2]

◆ join() [1/2]

template<template< typename > class NodeType, typename Key , class Compare >
void Aleph::Gen_Treap< NodeType, Key, Compare >::join ( Gen_Treap< NodeType, Key, Compare > &  t,
Gen_Treap< NodeType, Key, Compare > &  dup 
)
inlinenoexcept

Join this with t filtering the duplicated keys.

join(t, dup) produces a treap 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]tramdomized tree to join with this
[out]dupramdomized tree where nodes containing duplicated keys are inserted
Precondition
The comparison does not throw; if it does, the program ends (std::terminate()).
Note
It stays 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 670 of file tpl_treap.H.

References Aleph::Gen_Treap< NodeType, Key, Compare >::join(), and Aleph::Gen_Treap< NodeType, Key, Compare >::tree_root.

◆ join() [2/2]

◆ join_dup() [1/2]

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

Parameters
[in]tramdomized tree to join with this keys are inserted
Precondition
The comparison does not throw; if it does, the program ends (std::terminate()).
Note
It stays 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 690 of file tpl_treap.H.

References Aleph::Gen_Treap< NodeType, Key, Compare >::join_dup(), and Aleph::Gen_Treap< NodeType, Key, Compare >::tree_root.

◆ join_dup() [2/2]

template<template< typename > class NodeType, typename Key , class Compare >
void Aleph::Gen_Treap< NodeType, Key, Compare >::join_dup ( Node *&  t1,
Node *  t2 
)
inlineprivatenoexcept

◆ join_exclusive() [1/2]

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

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

Definition at line 707 of file tpl_treap.H.

References Aleph::Gen_Treap< NodeType, Key, Compare >::join_exclusive(), and Aleph::Gen_Treap< NodeType, Key, Compare >::tree_root.

◆ join_exclusive() [2/2]

template<template< typename > class NodeType, typename Key , class Compare >
static Node * Aleph::Gen_Treap< NodeType, Key, Compare >::join_exclusive ( Node *  t1,
Node *  t2 
)
inlinestaticprivatenoexcept

◆ key_comp()

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

return the comparison criteria

Definition at line 208 of file tpl_treap.H.

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

Referenced by Aleph::Gen_Treap< NodeType, Key, Compare >::get_compare().

◆ random_source() [1/2]

template<template< typename > class NodeType, typename Key , class Compare >
const Random_Source & Aleph::Gen_Treap< NodeType, Key, Compare >::random_source ( ) const
inlinenoexcept

The source of random numbers, to look at it: its engine, or whether it is equal to another one.

Definition at line 309 of file tpl_treap.H.

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

◆ random_source() [2/2]

template<template< typename > class NodeType, typename Key , class Compare >
Random_Source & Aleph::Gen_Treap< NodeType, Key, Compare >::random_source ( )
inlinenoexcept

The source of random numbers, which gives the priorities.

Definition at line 305 of file tpl_treap.H.

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

Referenced by TEST(), and TEST().

◆ remove() [1/2]

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

Remove a key from the tree.

Parameters
[in]keyto remove
Returns
a valid pointer to the removed node if key was found in the tree, nullptr otherwise
Exceptions
anythingthat the comparison throws; the tree changes only after the last comparison, so it is left as it was.
Note
It is noexcept only if the comparison cannot throw, so that what it throws reaches the caller.

Definition at line 539 of file tpl_treap.H.

References Aleph::and, Aleph::Gen_Treap< NodeType, Key, Compare >::cmp, Aleph::Gen_Treap< NodeType, Key, Compare >::head_ptr, KEY, LLINK, Aleph::PRIO(), RLINK, Aleph::rotate_to_left(), Aleph::rotate_to_right(), and Aleph::Gen_Treap< NodeType, Key, Compare >::tree_root.

Referenced by Aleph::Gen_Treap< NodeType, Key, Compare >::join(), main(), and Aleph::Gen_Treap< NodeType, Key, Compare >::remove().

◆ remove() [2/2]

template<template< typename > class NodeType, typename Key , class Compare >
Node * Aleph::Gen_Treap< NodeType, Key, Compare >::remove ( Node *&  root,
const Key &  key 
)
inlineprivatenoexcept

◆ rng()

template<template< typename > class NodeType, typename Key , class Compare >
Gsl_Compatible_Rng & Aleph::Gen_Treap< NodeType, Key, Compare >::rng ( )
inline

The Mersenne Twister of the treap, which a treap that was given no seed makes here, and draws from it from then on.

Deprecated:
It makes a generator of some 2500 bytes in a treap that has none; use random_source(). It goes in 8.0.0.
Returns
The Mersenne Twister: Random_Source::mersenne_twister().
Exceptions
std::bad_allocIf the treap has no Mersenne Twister and there is not enough memory for it.

Definition at line 322 of file tpl_treap.H.

References Aleph::Random_Source::mersenne_twister(), and Aleph::Gen_Treap< NodeType, Key, Compare >::r.

Referenced by TEST().

◆ search()

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

Search a key in a treap.

Parameters
[in]keyto be searched
Returns
a pointer to the node containing key if this is found; otherwise, nullptr is returned
Exceptions
anythingthat the comparison throws; the search does not modify the tree, so it is left as it was.
Note
It is noexcept only if the comparison cannot throw, so that what it throws reaches the caller.

Definition at line 350 of file tpl_treap.H.

References Aleph::Gen_Treap< NodeType, Key, Compare >::cmp, Aleph::searchInBinTree(), and Aleph::Gen_Treap< NodeType, Key, Compare >::tree_root.

Referenced by main(), and write_treap().

◆ search_or_insert() [1/2]

template<template< typename > class NodeType, typename Key , class Compare >
Node * Aleph::Gen_Treap< NodeType, Key, Compare >::search_or_insert ( Node *&  root,
Node *  p 
)
inlineprivatenoexcept

◆ search_or_insert() [2/2]

template<template< typename > class NodeType, typename Key , class Compare >
Node * Aleph::Gen_Treap< 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
Exceptions
anythingthat 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.
Note
It is noexcept only if the comparison cannot throw, so that what it throws reaches the caller.

Definition at line 490 of file tpl_treap.H.

References Aleph::Random_Source::get(), Aleph::PRIO(), Aleph::Gen_Treap< NodeType, Key, Compare >::r, Aleph::Gen_Treap< NodeType, Key, Compare >::search_or_insert(), and Aleph::Gen_Treap< NodeType, Key, Compare >::tree_root.

◆ set_seed()

template<template< typename > class NodeType, typename Key , class Compare >
void Aleph::Gen_Treap< NodeType, Key, Compare >::set_seed ( const unsigned long  seed)
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.

Parameters
[in]seedThe seed.
Exceptions
std::bad_allocIf the treap has no Mersenne Twister and there is not enough memory for it; then it is unchanged.

Definition at line 186 of file tpl_treap.H.

References Aleph::Random_Source::Mersenne_Twister, Aleph::Gen_Treap< NodeType, Key, Compare >::r, Aleph::Random_Source::seed(), and seed.

Referenced by main(), TreapTest::SetUp(), TEST(), and TEST().

◆ split_key()

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

Split the tree according to a key.

It splits with the comparison criteria of the tree.

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
Exceptions
anythingthat the comparison throws; every comparison comes before the first change, so the three trees are left as they were.
Note
It is noexcept only if the comparison cannot throw, so that what it throws reaches the caller.

Definition at line 727 of file tpl_treap.H.

References Aleph::Gen_Treap< NodeType, Key, Compare >::cmp, Aleph::split_key_rec(), and Aleph::Gen_Treap< NodeType, Key, Compare >::tree_root.

◆ split_key_dup()

template<template< typename > class NodeType, typename Key , class Compare >
void Aleph::Gen_Treap< NodeType, Key, Compare >::split_key_dup ( const Key &  key,
Gen_Treap< NodeType, Key, Compare > &  t1,
Gen_Treap< 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. It splits with the comparison criteria of the tree.

Parameters
[in]keyfor splitting
[out]t1resulting tree with the keys lesser than key
[out]t2resulting tree with the keys greater or equal than key
Exceptions
anythingthat the comparison throws; every comparison comes before the first change, so the three trees are left as they were.
Note
It is noexcept only if the comparison cannot throw, so that what it throws reaches the caller.

Definition at line 748 of file tpl_treap.H.

References Aleph::Gen_Treap< NodeType, Key, Compare >::cmp, Aleph::split_key_dup_rec(), and Aleph::Gen_Treap< NodeType, Key, Compare >::tree_root.

◆ swap()

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

Swaps in constant time the nodes and the comparison criteria of this and tree.

Parameters
[in,out]treethe tree to swap with.
Exceptions
whatthe swap of the comparison criteria throws, which goes first: then the nodes stay where they were.

Definition at line 198 of file tpl_treap.H.

References Aleph::Gen_Treap< NodeType, Key, Compare >::cmp, Aleph::Gen_Treap< NodeType, Key, Compare >::r, Aleph::Random_Source::swap(), and Aleph::Gen_Treap< NodeType, Key, Compare >::tree_root.

◆ verify()

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

Return true if this is a consistent treap.

It throws what the comparator throws.

Definition at line 524 of file tpl_treap.H.

References Aleph::and, Aleph::check_bst(), Aleph::Gen_Treap< NodeType, Key, Compare >::cmp, Aleph::is_treap(), and Aleph::Gen_Treap< NodeType, Key, Compare >::tree_root.

Referenced by TEST().

Member Data Documentation

◆ cmp

◆ head

template<template< typename > class NodeType, typename Key , class Compare >
Node Aleph::Gen_Treap< NodeType, Key, Compare >::head
private

The type of node.

Definition at line 162 of file tpl_treap.H.

◆ head_ptr

template<template< typename > class NodeType, typename Key , class Compare >
Node* Aleph::Gen_Treap< NodeType, Key, Compare >::head_ptr
private

◆ r

◆ tree_root


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