ADS
Algorithms and Data Structures
Loading...
Searching...
No Matches
ADS::PartialRebuildingTree< K, V, P > Class Template Reference

a DICTIONARY on a binary search tree balanced by partial rebuilding by the rule P More...

#include <ADS/tree/PartialRebuildingTree.h>

Classes

struct  Shape
 the shape of the tree, for PathIterator More...

Public types

using Key = K
 the type of the keys
using Value = V
 the type of the values
using value_type = std::pair< K , V >
 the pairs ( key , value ) by value, which own their copies
using key_type = K
 the type of the keys
using mapped_type = V
 the type of the values
using size_type = std::size_t
 the type of the sizes
using difference_type = std::ptrdiff_t
 the type of the distances
using reference = PairRef< const K & , const V & >
 references, by value
using const_reference = reference
 the same
using const_iterator = PathIterator< PartialRebuildingTree , Shape >
 the constant iterator by increasing key, along the path from the root
using iterator = const_iterator
 the constant iterator

Public member functions

 PartialRebuildingTree (std::uint64_t seed=1)
 the empty tree, its random choices (if any) drawn from the seed
 PartialRebuildingTree (const PartialRebuildingTree &)=delete
 no copy, since the nodes are linked by pointers
PartialRebuildingTree & operator= (const PartialRebuildingTree &)=delete
 no copy, since the nodes are linked by pointers
 PartialRebuildingTree (PartialRebuildingTree &&other) noexcept
 the nodes of other, which is left empty
 ~PartialRebuildingTree ()
 frees the nodes
std::optional< V > lookup (const K &k) const
 the value of \( k \), or nothing, in \( O( h ) \) time
void insert (const K &k, const V &v)
 associates \( v \) to \( k \), in \( O( \log n ) \) amortized time (for DynamiteTree, expected after insertions only, and \( O( h ) \) expected, \( h \) the height, after removals)
void remove (const K &k)
 removes \( k \), if it is there, in \( O( \log n ) \) amortized time (for DynamiteTree, \( O( h ) \) expected, \( h \) the height), by the removal of a binary search tree and the rule of insert() on its path
bool contains (const K &k) const
 true if \( k \) is there
std::size_t size (void) const
 the number \( n \) of keys
long height (void) const
 the height, \( -1 \) if empty, in \( O( n ) \)
std::optional< std::pair< K, V > > lowerBound (const K &k) const
 the smallest key not smaller than \( k \) and its value, or nothing (the find(x) of an SSet of Morin)
const K * findKey (const K &k) const
 the address of the key \( k \), nil if absent, in \( O( \log n ) \) time: the find( x ) of a USet of Morin [see DictionarySet]; valid until the key is removed
const K * lowerBoundKey (const K &k) const
 the address of the smallest key not smaller than \( k \), nil if none, in \( O( \log n ) \) time: the find( x ) of an SSet of Morin [see DictionarySet]; valid until the key is removed
template<class F>
void forEach (F &&f) const
 f( k , v ) on the pairs by increasing keys
std::size_t rebuilds (void) const
 the number of rebuilds so far
std::size_t rebuiltNodes (void) const
 the nodes of all the rebuilds so far, the work they took
const_iterator begin (void) const
 the iterator on the smallest key
const_iterator end (void) const
 the iterator past the largest key
const_iterator cbegin (void) const
 as begin()
const_iterator cend (void) const
 as end()

Detailed description

template<std::totally_ordered K, class V, RebuildPolicy P>
class ADS::PartialRebuildingTree< K, V, P >

a DICTIONARY on a binary search tree balanced by partial rebuilding by the rule P

Member typedef documentation

◆ const_iterator

template<std::totally_ordered K, class V, RebuildPolicy P>
using ADS::PartialRebuildingTree< K, V, P >::const_iterator = PathIterator< PartialRebuildingTree , Shape >

the constant iterator by increasing key, along the path from the root

◆ const_reference

template<std::totally_ordered K, class V, RebuildPolicy P>
using ADS::PartialRebuildingTree< K, V, P >::const_reference = reference

the same

◆ difference_type

template<std::totally_ordered K, class V, RebuildPolicy P>
using ADS::PartialRebuildingTree< K, V, P >::difference_type = std::ptrdiff_t

the type of the distances

◆ iterator

template<std::totally_ordered K, class V, RebuildPolicy P>
using ADS::PartialRebuildingTree< K, V, P >::iterator = const_iterator

the constant iterator

◆ Key

template<std::totally_ordered K, class V, RebuildPolicy P>
using ADS::PartialRebuildingTree< K, V, P >::Key = K

the type of the keys

◆ key_type

template<std::totally_ordered K, class V, RebuildPolicy P>
using ADS::PartialRebuildingTree< K, V, P >::key_type = K

the type of the keys

◆ mapped_type

template<std::totally_ordered K, class V, RebuildPolicy P>
using ADS::PartialRebuildingTree< K, V, P >::mapped_type = V

the type of the values

◆ reference

template<std::totally_ordered K, class V, RebuildPolicy P>
using ADS::PartialRebuildingTree< K, V, P >::reference = PairRef< const K & , const V & >

references, by value

◆ size_type

template<std::totally_ordered K, class V, RebuildPolicy P>
using ADS::PartialRebuildingTree< K, V, P >::size_type = std::size_t

the type of the sizes

◆ Value

template<std::totally_ordered K, class V, RebuildPolicy P>
using ADS::PartialRebuildingTree< K, V, P >::Value = V

the type of the values

◆ value_type

template<std::totally_ordered K, class V, RebuildPolicy P>
using ADS::PartialRebuildingTree< K, V, P >::value_type = std::pair< K , V >

the pairs ( key , value ) by value, which own their copies

Constructor and destructor documentation

◆ PartialRebuildingTree() [1/3]

template<std::totally_ordered K, class V, RebuildPolicy P>
ADS::PartialRebuildingTree< K, V, P >::PartialRebuildingTree ( std::uint64_t seed = 1)
inlineexplicit

the empty tree, its random choices (if any) drawn from the seed

◆ PartialRebuildingTree() [2/3]

template<std::totally_ordered K, class V, RebuildPolicy P>
ADS::PartialRebuildingTree< K, V, P >::PartialRebuildingTree ( const PartialRebuildingTree< K, V, P > & )
delete

no copy, since the nodes are linked by pointers

◆ PartialRebuildingTree() [3/3]

template<std::totally_ordered K, class V, RebuildPolicy P>
ADS::PartialRebuildingTree< K, V, P >::PartialRebuildingTree ( PartialRebuildingTree< K, V, P > && other)
noexcept

the nodes of other, which is left empty

◆ ~PartialRebuildingTree()

template<std::totally_ordered K, class V, RebuildPolicy P>
ADS::PartialRebuildingTree< K, V, P >::~PartialRebuildingTree ( )

frees the nodes

Member function documentation

◆ begin()

template<std::totally_ordered K, class V, RebuildPolicy P>
const_iterator ADS::PartialRebuildingTree< K, V, P >::begin ( void ) const
inlinenodiscard

the iterator on the smallest key

◆ cbegin()

template<std::totally_ordered K, class V, RebuildPolicy P>
const_iterator ADS::PartialRebuildingTree< K, V, P >::cbegin ( void ) const
inlinenodiscard

as begin()

◆ cend()

template<std::totally_ordered K, class V, RebuildPolicy P>
const_iterator ADS::PartialRebuildingTree< K, V, P >::cend ( void ) const
inlinenodiscard

as end()

◆ contains()

template<std::totally_ordered K, class V, RebuildPolicy P>
bool ADS::PartialRebuildingTree< K, V, P >::contains ( const K & k) const
nodiscard

true if \( k \) is there

◆ end()

template<std::totally_ordered K, class V, RebuildPolicy P>
const_iterator ADS::PartialRebuildingTree< K, V, P >::end ( void ) const
inlinenodiscard

the iterator past the largest key

◆ findKey()

template<std::totally_ordered K, class V, RebuildPolicy P>
const K * ADS::PartialRebuildingTree< K, V, P >::findKey ( const K & k) const
nodiscard

the address of the key \( k \), nil if absent, in \( O( \log n ) \) time: the find( x ) of a USet of Morin [see DictionarySet]; valid until the key is removed

◆ forEach()

template<std::totally_ordered K, class V, RebuildPolicy P>
template<class F>
void ADS::PartialRebuildingTree< K, V, P >::forEach ( F && f) const

f( k , v ) on the pairs by increasing keys

◆ height()

template<std::totally_ordered K, class V, RebuildPolicy P>
long ADS::PartialRebuildingTree< K, V, P >::height ( void ) const
nodiscard

the height, \( -1 \) if empty, in \( O( n ) \)

◆ insert()

template<std::totally_ordered K, class V, RebuildPolicy P>
void ADS::PartialRebuildingTree< K, V, P >::insert ( const K & k,
const V & v )

associates \( v \) to \( k \), in \( O( \log n ) \) amortized time (for DynamiteTree, expected after insertions only, and \( O( h ) \) expected, \( h \) the height, after removals)

In pseudocode (exercises 8.8 to 8.10 of Morin), \( P \) the path from the root to the new leaf:

\[\class{pseudocode}{\begin{array}{r@{\quad}l} 1 & \textbf{procedure}\ \mathrm{insert}( k , v ) \cr 2 & \quad \text{the insertion of a binary search tree, along } P \cr 3 & \quad \textbf{foreach}\ u \in P\ \textbf{do}\ s( u ) \gets s( u ) + 1 \cr 4 & \quad w \gets \text{the first node of } P \text{ selected by the} \text{ rule} \cr 5 & \quad \textbf{if}\ w \ne \textbf{nil}\ \textbf{then} \ \mathrm{rebuild}( w ) \end{array}} \]

where the rule selects \( u \) with a child of size above \( \frac23 s( u ) \) (WEIGHT), \( u \) whose timer, decremented, is 0 (COUNTDOWN), \( u \) with probability \( 1 / s( u ) \) (DYNAMITE)

Postcondition
\( k \) has the value \( v \)

◆ lookup()

template<std::totally_ordered K, class V, RebuildPolicy P>
std::optional< V > ADS::PartialRebuildingTree< K, V, P >::lookup ( const K & k) const
nodiscard

the value of \( k \), or nothing, in \( O( h ) \) time

◆ lowerBound()

template<std::totally_ordered K, class V, RebuildPolicy P>
std::optional< std::pair< K, V > > ADS::PartialRebuildingTree< K, V, P >::lowerBound ( const K & k) const
nodiscard

the smallest key not smaller than \( k \) and its value, or nothing (the find(x) of an SSet of Morin)

◆ lowerBoundKey()

template<std::totally_ordered K, class V, RebuildPolicy P>
const K * ADS::PartialRebuildingTree< K, V, P >::lowerBoundKey ( const K & k) const
nodiscard

the address of the smallest key not smaller than \( k \), nil if none, in \( O( \log n ) \) time: the find( x ) of an SSet of Morin [see DictionarySet]; valid until the key is removed

◆ operator=()

template<std::totally_ordered K, class V, RebuildPolicy P>
PartialRebuildingTree & ADS::PartialRebuildingTree< K, V, P >::operator= ( const PartialRebuildingTree< K, V, P > & )
delete

no copy, since the nodes are linked by pointers

◆ rebuilds()

template<std::totally_ordered K, class V, RebuildPolicy P>
std::size_t ADS::PartialRebuildingTree< K, V, P >::rebuilds ( void ) const
inlinenodiscard

the number of rebuilds so far

◆ rebuiltNodes()

template<std::totally_ordered K, class V, RebuildPolicy P>
std::size_t ADS::PartialRebuildingTree< K, V, P >::rebuiltNodes ( void ) const
inlinenodiscard

the nodes of all the rebuilds so far, the work they took

◆ remove()

template<std::totally_ordered K, class V, RebuildPolicy P>
void ADS::PartialRebuildingTree< K, V, P >::remove ( const K & k)

removes \( k \), if it is there, in \( O( \log n ) \) amortized time (for DynamiteTree, \( O( h ) \) expected, \( h \) the height), by the removal of a binary search tree and the rule of insert() on its path

Postcondition
\( k \) is not there

◆ size()

template<std::totally_ordered K, class V, RebuildPolicy P>
std::size_t ADS::PartialRebuildingTree< K, V, P >::size ( void ) const
inlinenodiscard

the number \( n \) of keys


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