ADS
Algorithms and Data Structures
Loading...
Searching...
No Matches
ADS::YFastTrie< U, V, W > Class Template Reference

the y-fast trie: an x-fast trie of representatives over treaps of \( O( w ) \) keys More...

#include <ADS/dictionary/YFastTrie.h>

Public types

using Key = U
 the type of the keys
using Item = U
 the items of the SSet, the keys
using Value = V
 the type of the values

Public member functions

 YFastTrie (std::uint64_t seed=1)
 the empty trie, its coins drawn from the seed
 YFastTrie (YFastTrie &&o)
 the trie of o, which is left empty
YFastTrie & operator= (YFastTrie &&o) noexcept
 the trie of o, which gets the keys of this one
 YFastTrie (const YFastTrie &)=delete
YFastTrie & operator= (const YFastTrie &)=delete
 ~YFastTrie ()
 frees the groups
const U * lowerBound (U x) const
 the smallest key \( \ge x \), nil if none (the find( x ) of the SSet of Morin's book), in \( O( \log w ) \) expected time
const U * find (U x) const
 the key \( x \), nil if it is not there, in \( O( \log w ) \) expected time
std::optional< V > lookup (U x) const
 the value of \( x \), or nothing
bool contains (U x) const
 true if \( x \) is there
bool insert (U x, const V &v=V())
 associates \( v \) to \( x \); true if \( x \) was not there, in \( O( \log w ) \) expected amortized time
bool remove (U x)
 removes \( x \); true if it was there, in \( O( \log w ) \) expected amortized time
std::size_t size (void) const
 the number \( n \) of keys
bool empty (void) const
 true if there are no keys
std::size_t groups (void) const
 the number of groups, the last one included
template<class F>
void forEach (F &&f) const
 f( x , v ) on the pairs by increasing keys

Detailed description

template<std::unsigned_integral U, class V = std::monostate, int W = std::numeric_limits< U >::digits>
requires TrieWidth< U , W >
class ADS::YFastTrie< U, V, W >

the y-fast trie: an x-fast trie of representatives over treaps of \( O( w ) \) keys

Member typedef documentation

◆ Item

template<std::unsigned_integral U, class V = std::monostate, int W = std::numeric_limits< U >::digits>
using ADS::YFastTrie< U, V, W >::Item = U

the items of the SSet, the keys

◆ Key

template<std::unsigned_integral U, class V = std::monostate, int W = std::numeric_limits< U >::digits>
using ADS::YFastTrie< U, V, W >::Key = U

the type of the keys

◆ Value

template<std::unsigned_integral U, class V = std::monostate, int W = std::numeric_limits< U >::digits>
using ADS::YFastTrie< U, V, W >::Value = V

the type of the values

Constructor and destructor documentation

◆ YFastTrie() [1/3]

template<std::unsigned_integral U, class V = std::monostate, int W = std::numeric_limits< U >::digits>
ADS::YFastTrie< U, V, W >::YFastTrie ( std::uint64_t seed = 1)
explicit

the empty trie, its coins drawn from the seed

◆ YFastTrie() [2/3]

template<std::unsigned_integral U, class V = std::monostate, int W = std::numeric_limits< U >::digits>
ADS::YFastTrie< U, V, W >::YFastTrie ( YFastTrie< U, V, W > && o)

the trie of o, which is left empty

◆ YFastTrie() [3/3]

template<std::unsigned_integral U, class V = std::monostate, int W = std::numeric_limits< U >::digits>
ADS::YFastTrie< U, V, W >::YFastTrie ( const YFastTrie< U, V, W > & )
delete

◆ ~YFastTrie()

template<std::unsigned_integral U, class V = std::monostate, int W = std::numeric_limits< U >::digits>
ADS::YFastTrie< U, V, W >::~YFastTrie ( )

frees the groups

Member function documentation

◆ contains()

template<std::unsigned_integral U, class V = std::monostate, int W = std::numeric_limits< U >::digits>
bool ADS::YFastTrie< U, V, W >::contains ( U x) const
nodiscard

true if \( x \) is there

Precondition
\( x < 2^w \)

◆ empty()

template<std::unsigned_integral U, class V = std::monostate, int W = std::numeric_limits< U >::digits>
bool ADS::YFastTrie< U, V, W >::empty ( void ) const
inlinenodiscard

true if there are no keys

◆ find()

template<std::unsigned_integral U, class V = std::monostate, int W = std::numeric_limits< U >::digits>
const U * ADS::YFastTrie< U, V, W >::find ( U x) const
nodiscard

the key \( x \), nil if it is not there, in \( O( \log w ) \) expected time

Precondition
\( x < 2^w \)

◆ forEach()

template<std::unsigned_integral U, class V = std::monostate, int W = std::numeric_limits< U >::digits>
template<class F>
void ADS::YFastTrie< U, V, W >::forEach ( F && f) const

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

◆ groups()

template<std::unsigned_integral U, class V = std::monostate, int W = std::numeric_limits< U >::digits>
std::size_t ADS::YFastTrie< U, V, W >::groups ( void ) const
inlinenodiscard

the number of groups, the last one included

◆ insert()

template<std::unsigned_integral U, class V = std::monostate, int W = std::numeric_limits< U >::digits>
bool ADS::YFastTrie< U, V, W >::insert ( U x,
const V & v = V() )

associates \( v \) to \( x \); true if \( x \) was not there, in \( O( \log w ) \) expected amortized time

In pseudocode (section 13.3 of Morin's book):

\[\class{pseudocode}{\begin{array}{r@{\quad}l} 1 & \textbf{function}\ \mathrm{insert}( x , v ) \cr 2 & \quad ( r , T ) \gets \text{the pair of } X.\mathrm{lowerBound}( x ) \cr 3 & \quad \textbf{if}\ x \in T\ \textbf{then}\ \text{give it the value } v;\ \textbf{return false} \cr 4 & \quad T.\mathrm{insert}( x , v ) \cr 5 & \quad \textbf{if}\ x \ne r \text{ and a coin of bias } 1 / w \text{ comes up}\ \textbf{then} \cr 6 & \qquad ( T' , T ) \gets \text{the keys of } T \text{ up to } x \text{ and the others, by a split} \cr 7 & \qquad X.\mathrm{insert}( x , T' ) \cr 8 & \quad \textbf{return true} \end{array}} \]

Precondition
\( x < 2^w \)
Postcondition
\( x \) is there

◆ lookup()

template<std::unsigned_integral U, class V = std::monostate, int W = std::numeric_limits< U >::digits>
std::optional< V > ADS::YFastTrie< U, V, W >::lookup ( U x) const
nodiscard

the value of \( x \), or nothing

Precondition
\( x < 2^w \)

◆ lowerBound()

template<std::unsigned_integral U, class V = std::monostate, int W = std::numeric_limits< U >::digits>
const U * ADS::YFastTrie< U, V, W >::lowerBound ( U x) const
nodiscard

the smallest key \( \ge x \), nil if none (the find( x ) of the SSet of Morin's book), in \( O( \log w ) \) expected time

In pseudocode (section 13.3 of Morin's book), \( X \) the x-fast trie of the representatives:

\[\class{pseudocode}{\begin{array}{r@{\quad}l} 1 & \textbf{function}\ \mathrm{lowerBound}( x ) \cr 2 & \quad ( r , T ) \gets \text{the pair of } X.\mathrm{lowerBound}( x ) \cr 3 & \quad \textbf{return}\ \text{the smallest key} \ge x \text{ of } T \text{, or } \textbf{nil} \end{array}} \]

Precondition
\( x < 2^w \)

◆ operator=() [1/2]

template<std::unsigned_integral U, class V = std::monostate, int W = std::numeric_limits< U >::digits>
YFastTrie & ADS::YFastTrie< U, V, W >::operator= ( const YFastTrie< U, V, W > & )
delete

◆ operator=() [2/2]

template<std::unsigned_integral U, class V = std::monostate, int W = std::numeric_limits< U >::digits>
YFastTrie & ADS::YFastTrie< U, V, W >::operator= ( YFastTrie< U, V, W > && o)
noexcept

the trie of o, which gets the keys of this one

◆ remove()

template<std::unsigned_integral U, class V = std::monostate, int W = std::numeric_limits< U >::digits>
bool ADS::YFastTrie< U, V, W >::remove ( U x)

removes \( x \); true if it was there, in \( O( \log w ) \) expected amortized time

In pseudocode (section 13.3 of Morin's book):

\[\class{pseudocode}{\begin{array}{r@{\quad}l} 1 & \textbf{function}\ \mathrm{remove}( x ) \cr 2 & \quad ( r , T ) \gets \text{the pair of } X.\mathrm{lowerBound}( x ) \cr 3 & \quad \textbf{if}\ x \notin T\ \textbf{then return false} \cr 4 & \quad T.\mathrm{remove}( x ) \cr 5 & \quad \textbf{if}\ x = r \ne 2^w - 1\ \textbf{then} \cr 6 & \qquad ( r' , T' ) \gets \text{the pair after } ( r , T ) \text{ in } X \cr 7 & \qquad T' \gets \mathrm{join}( T , T' );\ X.\mathrm{remove}( x ) \cr 8 & \quad \textbf{return true} \end{array}} \]

Precondition
\( x < 2^w \)
Postcondition
\( x \) is not there

◆ size()

template<std::unsigned_integral U, class V = std::monostate, int W = std::numeric_limits< U >::digits>
std::size_t ADS::YFastTrie< U, V, W >::size ( void ) const
inlinenodiscard

the number \( n \) of keys


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