the x-fast trie of a doubly linked list and \( w + 1 \) hash tables (exercise 13.2 of Morin's book)
More...
|
| | 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
|
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)
template<std::unsigned_integral U, class V = std::monostate, int W = std::numeric_limits< U >::digits>
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 \)
template<std::unsigned_integral U, class V = std::monostate, int W = std::numeric_limits< U >::digits>
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
template<std::unsigned_integral U, class V = std::monostate, int W = std::numeric_limits< U >::digits>
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 \)
template<std::unsigned_integral U, class V = std::monostate, int W = std::numeric_limits< U >::digits>
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