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

the x-fast trie: a binary trie with a hash table of the prefixes per depth More...

#include <ADS/dictionary/XFastTrie.h>

Inheritance diagram for ADS::XFastTrie< U, V, W >:

Public member functions

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

Detailed description

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

the x-fast trie: a binary trie with a hash table of the prefixes per depth

Member function documentation

◆ findNear()

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

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

In pseudocode (exercise 13.4 of Morin's book), \( t[ i ]( p ) \) the node of the prefix \( p \) of depth \( i \), or nil:

\[\class{pseudocode}{\begin{array}{r@{\quad}l} 1 & \textbf{function}\ \mathrm{findNear}( x ) \cr 2 & \quad \textbf{if}\ x \text{ is there}\ \textbf{then return}\ x \cr 3 & \quad h \gets w;\ K \gets 1 \cr 4 & \quad \textbf{loop} \cr 5 & \qquad d \gets w - K;\ p \gets \lfloor x / 2^K \rfloor \cr 6 & \qquad \textbf{if}\ t[ d ]( p ) \ne \textbf{nil}\ \textbf{then} \cr 7 & \qquad\quad u \gets \text{the deepest node of the path of } x \text{, by a binary search between } d \text{ and } h \cr 8 & \qquad\quad \textbf{return}\ \text{the successor of } x \text{ from } u \text{, as in } \mathrm{lowerBound} \cr 9 & \qquad \textbf{if}\ t[ d ]( p + 1 ) \ne \textbf{nil}\ \textbf{then} \ \textbf{return}\ \text{its smallest leaf} \cr 10 & \qquad h \gets d;\ K \gets \min\{ 2 K , w \} \end{array}} \]

Precondition
\( x < 2^w \)

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