a binary trie of the integers of \( w \) bits with no list and no jump pointers (exercise 13.1 of Morin's book)
More...
|
| | SimpleBinaryTrie (void)=default |
| | the empty trie
|
| | SimpleBinaryTrie (SimpleBinaryTrie &&o) noexcept |
| | the trie of o, which is left empty
|
| SimpleBinaryTrie & | operator= (SimpleBinaryTrie &&o) noexcept |
| | the trie of o, which is left empty; the nodes of this one are freed
|
| | SimpleBinaryTrie (const SimpleBinaryTrie &)=delete |
| SimpleBinaryTrie & | operator= (const SimpleBinaryTrie &)=delete |
| | ~SimpleBinaryTrie () |
| | frees the nodes
|
| 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( w ) \) time
|
| const U * | find (U x) const |
| | the key \( x \), nil if it is not there, in \( O( w ) \) 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, by adding the missing nodes of its path, \( O( w ) \) time
|
| bool | remove (U x) |
| | removes \( x \); true if it was there, by removing the nodes of its path left with no child, \( O( w ) \) 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 | nodes (void) const |
| | the number of nodes, the root and the leaves included
|
| template<class F> |
| void | forEach (F &&f) const |
| | f( x , v ) on the pairs by increasing keys
|
template<std::unsigned_integral U, class V = std::monostate, int W = std::numeric_limits< U >::digits>
requires TrieWidth< U , W >
class ADS::SimpleBinaryTrie< U, V, W >
a binary trie of the integers of \( w \) bits with no list and no jump pointers (exercise 13.1 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 (the find( x ) of the SSet of Morin's book), in \( O( w ) \) time
In pseudocode (exercise 13.1 of Morin's book), \( a \) the child 1 of the deepest node of the path of \( x \) where the path goes to the child 0 and the child 1 is there, i.e., the root of the larger keys nearest to \( x \):
\[\class{pseudocode}{\begin{array}{r@{\quad}l}
1 & \textbf{function}\ \mathrm{lowerBound}( x ) \cr
2 & \quad u \gets \mathit{root};\ a \gets \textbf{nil} \cr
3 & \quad \textbf{for}\ i \gets 0\ \textbf{to}\ w - 1\ \textbf{do} \cr
4 & \qquad c \gets \text{the bit } i \text{ of } x \cr
5 & \qquad \textbf{if}\ c = 0\ \textbf{and}\ u.\mathit{child}[ 1 ] \ne
\textbf{nil}\ \textbf{then}\ a \gets u.\mathit{child}[ 1 ] \cr
6 & \qquad \textbf{if}\ u.\mathit{child}[ c ] = \textbf{nil}
\ \textbf{then break} \cr
7 & \qquad u \gets u.\mathit{child}[ c ] \cr
8 & \quad \textbf{if}\ i = w\ \textbf{then return}\ x \cr
9 & \quad \textbf{if}\ a = \textbf{nil}\ \textbf{then return nil} \cr
10 & \quad \textbf{return}\ \text{the leftmost leaf below } a
\end{array}}
\]
- Precondition
- \( x < 2^w \)