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

the x-fast trie of a doubly linked list and \( w + 1 \) hash tables (exercise 13.2 of Morin's book) More...

#include <ADS/dictionary/XFastTrie.h>

Classes

class  const_iterator
 the bidirectional iterator along the list More...

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
using value_type = typename const_iterator::value_type
 the type of the items, for the standard library
using size_type = std::size_t
 the type of the sizes
using difference_type = std::ptrdiff_t
 the type of the distances between two iterators
using reference = typename const_iterator::reference
 a pair of references, by value
using const_reference = reference
 a pair of references, by value
using iterator = const_iterator
 the iterator on the items

Public member functions

 ListXFastTrie (void)
 the empty trie
 ListXFastTrie (ListXFastTrie &&o)
 the trie of o, which is left empty
ListXFastTrie & operator= (ListXFastTrie &&o) noexcept
 the trie of o, which is left empty; the keys of this one are freed
 ListXFastTrie (const ListXFastTrie &)=delete
ListXFastTrie & operator= (const ListXFastTrie &)=delete
 ~ListXFastTrie ()
 frees the keys
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( 1 ) \) expected time
const U * findNear (U x) const
 the smallest key \( \ge x \), nil if none, in \( O( 1 + \log \log d( x ) ) \) expected time
std::optional< V > lookup (U x) const
 the value of \( x \), or nothing, in \( O( 1 ) \) expected time
bool contains (U x) const
 true if \( x \) is there, in \( O( 1 ) \) expected time
bool insert (U x, const V &v=V())
 associates \( v \) to \( x \); true if \( x \) was not there, in \( O( w ) \) expected time
bool remove (U x)
 removes \( x \); true if it was there, in \( O( w ) \) expected 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 entries (void) const
 the number of entries of the tables
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()
const_iterator seek (U x) const
 the iterator on the smallest key \( \ge x \), end() if none

Detailed description

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

the x-fast trie of a doubly linked list and \( w + 1 \) hash tables (exercise 13.2 of Morin's book)

Member typedef documentation

◆ const_reference

template<std::unsigned_integral U, class V = std::monostate, int W = std::numeric_limits< U >::digits>
using ADS::ListXFastTrie< U, V, W >::const_reference = reference

a pair of references, by value

◆ difference_type

template<std::unsigned_integral U, class V = std::monostate, int W = std::numeric_limits< U >::digits>
using ADS::ListXFastTrie< U, V, W >::difference_type = std::ptrdiff_t

the type of the distances between two iterators

◆ Item

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

the items of the SSet, the keys

◆ iterator

template<std::unsigned_integral U, class V = std::monostate, int W = std::numeric_limits< U >::digits>
using ADS::ListXFastTrie< U, V, W >::iterator = const_iterator

the iterator on the items

◆ Key

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

the type of the keys

◆ reference

template<std::unsigned_integral U, class V = std::monostate, int W = std::numeric_limits< U >::digits>
using ADS::ListXFastTrie< U, V, W >::reference = typename const_iterator::reference

a pair of references, by value

◆ size_type

template<std::unsigned_integral U, class V = std::monostate, int W = std::numeric_limits< U >::digits>
using ADS::ListXFastTrie< U, V, W >::size_type = std::size_t

the type of the sizes

◆ Value

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

the type of the values

◆ value_type

template<std::unsigned_integral U, class V = std::monostate, int W = std::numeric_limits< U >::digits>
using ADS::ListXFastTrie< U, V, W >::value_type = typename const_iterator::value_type

the type of the items, for the standard library

Constructor and destructor documentation

◆ ListXFastTrie() [1/3]

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

the empty trie

◆ ListXFastTrie() [2/3]

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

the trie of o, which is left empty

◆ ListXFastTrie() [3/3]

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

◆ ~ListXFastTrie()

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

frees the keys

Member function documentation

◆ begin()

template<std::unsigned_integral U, class V = std::monostate, int W = std::numeric_limits< U >::digits>
const_iterator ADS::ListXFastTrie< U, V, W >::begin ( void ) const
inlinenodiscard

the iterator on the smallest key

◆ cbegin()

template<std::unsigned_integral U, class V = std::monostate, int W = std::numeric_limits< U >::digits>
const_iterator ADS::ListXFastTrie< U, V, W >::cbegin ( void ) const
inlinenodiscard

as begin()

◆ cend()

template<std::unsigned_integral U, class V = std::monostate, int W = std::numeric_limits< U >::digits>
const_iterator ADS::ListXFastTrie< U, V, W >::cend ( void ) const
inlinenodiscard

as end()

◆ contains()

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

true if \( x \) is there, in \( O( 1 ) \) expected time

Precondition
\( x < 2^w \)

◆ empty()

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

true if there are no keys

◆ end()

template<std::unsigned_integral U, class V = std::monostate, int W = std::numeric_limits< U >::digits>
const_iterator ADS::ListXFastTrie< U, V, W >::end ( void ) const
inlinenodiscard

the iterator past the largest key

◆ entries()

template<std::unsigned_integral U, class V = std::monostate, int W = std::numeric_limits< U >::digits>
std::size_t ADS::ListXFastTrie< U, V, W >::entries ( void ) const
nodiscard

the number of entries of the tables

◆ find()

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

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

Precondition
\( x < 2^w \)

◆ findNear()

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

the smallest key \( \ge x \), nil if none, in \( O( 1 + \log \log d( x ) ) \) expected time

It is the pseudocode of XFastTrie::findNear(), the smallest key of the prefix \( p + 1 \) read from its entry (exercise 13.4 of Morin's book).

Precondition
\( x < 2^w \)

◆ insert()

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

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

In pseudocode (exercise 13.2 of Morin's book):

\[\class{pseudocode}{\begin{array}{r@{\quad}l} 1 & \textbf{function}\ \mathrm{insert}( x , v ) \cr 2 & \quad \textbf{if}\ t[ w ]( x ) \ne \textbf{nil}\ \textbf{then} \ \text{give it the value } v;\ \textbf{return false} \cr 3 & \quad \text{link a new key } x \text{ before the one of } \mathrm{lowerBound}( x ) \cr 4 & \quad \textbf{for}\ i \gets 1\ \textbf{to}\ w\ \textbf{do} \cr 5 & \qquad e \gets t[ i ]( \lfloor x / 2^{w-i} \rfloor ) \cr 6 & \qquad \textbf{if}\ e = \textbf{nil}\ \textbf{then}\ e \gets ( x , x ) \ \textbf{else}\ e \gets ( \min\{ e.\mathit{min} , x \} , \max\{ e.\mathit{max} , x \} ) \cr 7 & \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::ListXFastTrie< U, V, W >::lookup ( U x) const
nodiscard

the value of \( x \), or nothing, in \( O( 1 ) \) expected time

Precondition
\( x < 2^w \)

◆ lowerBound()

template<std::unsigned_integral U, class V = std::monostate, int W = std::numeric_limits< U >::digits>
const U * ADS::ListXFastTrie< 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 (exercise 13.2 of Morin's book), \( t[ i ]( p ) \) the entry of the prefix \( p \) of depth \( i \), with the smallest and the largest key that have it:

\[\class{pseudocode}{\begin{array}{r@{\quad}l} 1 & \textbf{function}\ \mathrm{lowerBound}( x ) \cr 2 & \quad l \gets 0;\ h \gets w + 1 \cr 3 & \quad \textbf{while}\ h - l > 1\ \textbf{do} \cr 4 & \qquad i \gets \lfloor ( l + h ) / 2 \rfloor \cr 5 & \qquad \textbf{if}\ t[ i ]( \lfloor x / 2^{w-i} \rfloor ) \ne \textbf{nil}\ \textbf{then}\ l \gets i\ \textbf{else}\ h \gets i \cr 6 & \quad e \gets t[ l ]( \lfloor x / 2^{w-l} \rfloor ) \cr 7 & \quad \textbf{if}\ l = w\ \textbf{then return}\ x \cr 8 & \quad \textbf{if}\ \text{the bit } l \text{ of } x \text{ is } 0 \ \textbf{then return}\ e.\mathit{min} \cr 9 & \quad \textbf{return}\ e.\mathit{max}.\mathit{next} \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>
ListXFastTrie & ADS::ListXFastTrie< U, V, W >::operator= ( const ListXFastTrie< U, V, W > & )
delete

◆ operator=() [2/2]

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

the trie of o, which is left empty; the keys of this one are freed

◆ remove()

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

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

In pseudocode (exercise 13.2 of Morin's book), \( \ell \) the key \( x \) in the list:

\[\class{pseudocode}{\begin{array}{r@{\quad}l} 1 & \textbf{function}\ \mathrm{remove}( x ) \cr 2 & \quad \textbf{if}\ t[ w ]( x ) = \textbf{nil}\ \textbf{then return} \ \textbf{false} \cr 3 & \quad \textbf{for}\ i \gets 1\ \textbf{to}\ w\ \textbf{do} \cr 4 & \qquad e \gets t[ i ]( \lfloor x / 2^{w-i} \rfloor ) \cr 5 & \qquad \textbf{if}\ e = ( \ell , \ell )\ \textbf{then}\ \text{remove } e \cr 6 & \qquad \textbf{else if}\ e.\mathit{min} = \ell\ \textbf{then} \ e.\mathit{min} \gets \ell.\mathit{next} \cr 7 & \qquad \textbf{else if}\ e.\mathit{max} = \ell\ \textbf{then} \ e.\mathit{max} \gets \ell.\mathit{prev} \cr 8 & \quad \text{unlink } \ell;\ \textbf{return true} \end{array}} \]

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

◆ seek()

template<std::unsigned_integral U, class V = std::monostate, int W = std::numeric_limits< U >::digits>
const_iterator ADS::ListXFastTrie< U, V, W >::seek ( U x) const
nodiscard

the iterator on the smallest key \( \ge x \), end() if none

Precondition
\( x < 2^w \)

◆ size()

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

the number \( n \) of keys


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