|
ADS
Algorithms and Data Structures
|
the x-fast trie: a binary trie with a hash table of the prefixes per depth More...
#include <ADS/dictionary/XFastTrie.h>
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 | |
the x-fast trie: a binary trie with a hash table of the prefixes per depth
|
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}} \]