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

a DICTIONARY on a treap with the parents, the sizes and the extremes of the subtrees, searched from a finger More...

#include <ADS/tree/FingerTreap.h>

Classes

class  Finger
 a node of the treap, from which a search may start; valid until the node is removed More...
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< FingerTreap , Shape >
 the constant iterator by increasing key, along the path from the root
using iterator = const_iterator
 the constant iterator

Public member functions

 FingerTreap (std::uint64_t seed=1)
 the empty treap, its priorities drawn from the seed
 FingerTreap (const FingerTreap &)=delete
 no copy, since the nodes are linked by pointers
FingerTreap & operator= (const FingerTreap &)=delete
 no copy, since the nodes are linked by pointers
 FingerTreap (FingerTreap &&other) noexcept
 the nodes of other, which is left empty
 ~FingerTreap ()
 frees the nodes
std::optional< V > lookup (const K &k) const
 the value of \( k \), or nothing, from the root, in \( O( \log n ) \) expected time
std::optional< V > fingerLookup (const K &k)
 the value of \( k \), or nothing, by a search from the node of the last fingerLookup(), which becomes the node where this one ends, in \( O( 1 + \log r ) \) expected time (exercise 7.9 of Morin)
std::optional< V > lookupFrom (const K &k, Finger f) const
 the value of \( k \), or nothing, by a search from \( f \), in \( O( 1 + \log r ) \) expected time, \( r \) the keys between \( k \) and that of \( f \) (the fingerFind(x,u) of exercise 7.9 of Morin)
Finger finger (const K &k) const
 the node of \( k \), or the last node of its search from the root, as a finger
void insert (const K &k, const V &v)
 associates \( v \) to \( k \), in \( O( \log n ) \) expected time: a leaf rotated up while its priority beats its parent's, then the sizes and the extremes corrected up to the root
void remove (const K &k)
 removes \( k \), if it is there, in \( O( \log n ) \) expected time: the node rotated down to a leaf, the child of larger priority going up, and spliced, then the sizes and the extremes corrected up to the root
bool contains (const K &k) const
 true if \( k \) is there
std::size_t size (void) const
 the number \( n \) of keys
int 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 ) \) expected 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 ) \) expected time: the find( x ) of an SSet of Morin [see DictionarySet]; valid until the key is removed
std::pair< K, V > select (std::size_t i) const
 the pair of rank \( i \), by the sizes, as Treap::select()
std::size_t rank (const K &k) const
 the number of keys smaller than \( k \), by the sizes
template<class F>
void forEach (F &&f) const
 f( k , v ) on the pairs by increasing keys
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>
class ADS::FingerTreap< K, V >

a DICTIONARY on a treap with the parents, the sizes and the extremes of the subtrees, searched from a finger

Member typedef documentation

◆ const_iterator

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

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

◆ const_reference

template<std::totally_ordered K, class V>
using ADS::FingerTreap< K, V >::const_reference = reference

the same

◆ difference_type

template<std::totally_ordered K, class V>
using ADS::FingerTreap< K, V >::difference_type = std::ptrdiff_t

the type of the distances

◆ iterator

template<std::totally_ordered K, class V>
using ADS::FingerTreap< K, V >::iterator = const_iterator

the constant iterator

◆ Key

template<std::totally_ordered K, class V>
using ADS::FingerTreap< K, V >::Key = K

the type of the keys

◆ key_type

template<std::totally_ordered K, class V>
using ADS::FingerTreap< K, V >::key_type = K

the type of the keys

◆ mapped_type

template<std::totally_ordered K, class V>
using ADS::FingerTreap< K, V >::mapped_type = V

the type of the values

◆ reference

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

references, by value

◆ size_type

template<std::totally_ordered K, class V>
using ADS::FingerTreap< K, V >::size_type = std::size_t

the type of the sizes

◆ Value

template<std::totally_ordered K, class V>
using ADS::FingerTreap< K, V >::Value = V

the type of the values

◆ value_type

template<std::totally_ordered K, class V>
using ADS::FingerTreap< K, V >::value_type = std::pair< K , V >

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

Constructor and destructor documentation

◆ FingerTreap() [1/3]

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

the empty treap, its priorities drawn from the seed

◆ FingerTreap() [2/3]

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

no copy, since the nodes are linked by pointers

◆ FingerTreap() [3/3]

template<std::totally_ordered K, class V>
ADS::FingerTreap< K, V >::FingerTreap ( FingerTreap< K, V > && other)
inlinenoexcept

the nodes of other, which is left empty

◆ ~FingerTreap()

template<std::totally_ordered K, class V>
ADS::FingerTreap< K, V >::~FingerTreap ( )

frees the nodes

Member function documentation

◆ begin()

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

the iterator on the smallest key

◆ cbegin()

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

as begin()

◆ cend()

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

as end()

◆ contains()

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

true if \( k \) is there

◆ end()

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

the iterator past the largest key

◆ findKey()

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

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

◆ finger()

template<std::totally_ordered K, class V>
Finger ADS::FingerTreap< K, V >::finger ( const K & k) const
nodiscard

the node of \( k \), or the last node of its search from the root, as a finger

◆ fingerLookup()

template<std::totally_ordered K, class V>
std::optional< V > ADS::FingerTreap< K, V >::fingerLookup ( const K & k)
nodiscard

the value of \( k \), or nothing, by a search from the node of the last fingerLookup(), which becomes the node where this one ends, in \( O( 1 + \log r ) \) expected time (exercise 7.9 of Morin)

◆ forEach()

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

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

◆ height()

template<std::totally_ordered K, class V>
int ADS::FingerTreap< K, V >::height ( void ) const
nodiscard

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

◆ insert()

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

associates \( v \) to \( k \), in \( O( \log n ) \) expected time: a leaf rotated up while its priority beats its parent's, then the sizes and the extremes corrected up to the root

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

◆ lookup()

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

the value of \( k \), or nothing, from the root, in \( O( \log n ) \) expected time

◆ lookupFrom()

template<std::totally_ordered K, class V>
std::optional< V > ADS::FingerTreap< K, V >::lookupFrom ( const K & k,
Finger f ) const
nodiscard

the value of \( k \), or nothing, by a search from \( f \), in \( O( 1 + \log r ) \) expected time, \( r \) the keys between \( k \) and that of \( f \) (the fingerFind(x,u) of exercise 7.9 of Morin)

In pseudocode (exercise 7.9 of Morin, and Seidel and Aragon):

\[\class{pseudocode}{\begin{array}{r@{\quad}l} 1 & \textbf{function}\ \mathrm{fingerFind}( k , u ) \cr 2 & \quad w \gets u \cr 3 & \quad \textbf{while}\ w.\mathit{parent} \ne \textbf{nil} \ \textbf{and}\ ( k < w.\mathit{min}.\mathit{key}\ \textbf{or} \ k > w.\mathit{max}.\mathit{key} )\ \textbf{do}\ w \gets w.\mathit{parent} \cr 4 & \quad \textbf{while}\ w \ne \textbf{nil}\ \textbf{and} \ w.\mathit{key} \ne k\ \textbf{do}\ w \gets w.\mathit{left} \text{ if } k < w.\mathit{key} \text{, else } w.\mathit{right} \cr 5 & \quad \textbf{return}\ w \end{array}} \]

Precondition
\( f \) is a node of this treap, or empty

◆ lowerBound()

template<std::totally_ordered K, class V>
std::optional< std::pair< K, V > > ADS::FingerTreap< K, V >::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>
const K * ADS::FingerTreap< K, V >::lowerBoundKey ( const K & k) const
nodiscard

the address of the smallest key not smaller than \( k \), nil if none, in \( O( \log n ) \) expected 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>
FingerTreap & ADS::FingerTreap< K, V >::operator= ( const FingerTreap< K, V > & )
delete

no copy, since the nodes are linked by pointers

◆ rank()

template<std::totally_ordered K, class V>
std::size_t ADS::FingerTreap< K, V >::rank ( const K & k) const
nodiscard

the number of keys smaller than \( k \), by the sizes

◆ remove()

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

removes \( k \), if it is there, in \( O( \log n ) \) expected time: the node rotated down to a leaf, the child of larger priority going up, and spliced, then the sizes and the extremes corrected up to the root

Postcondition
\( k \) is not there

◆ select()

template<std::totally_ordered K, class V>
std::pair< K, V > ADS::FingerTreap< K, V >::select ( std::size_t i) const
nodiscard

the pair of rank \( i \), by the sizes, as Treap::select()

Precondition
\( i < n \)

◆ size()

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

the number \( n \) of keys


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