the y-fast trie: an x-fast trie of representatives over treaps of \( O( w ) \) keys
More...
|
| | YFastTrie (std::uint64_t seed=1) |
| | the empty trie, its coins drawn from the seed
|
| | YFastTrie (YFastTrie &&o) |
| | the trie of o, which is left empty
|
| YFastTrie & | operator= (YFastTrie &&o) noexcept |
| | the trie of o, which gets the keys of this one
|
| | YFastTrie (const YFastTrie &)=delete |
| YFastTrie & | operator= (const YFastTrie &)=delete |
| | ~YFastTrie () |
| | frees the groups
|
| 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( \log w ) \) expected 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, in \( O( \log w ) \) expected amortized time
|
| bool | remove (U x) |
| | removes \( x \); true if it was there, in \( O( \log w ) \) expected amortized 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 | groups (void) const |
| | the number of groups, the last one 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::YFastTrie< U, V, W >
the y-fast trie: an x-fast trie of representatives over treaps of \( O( w ) \) keys
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( \log w ) \) expected amortized time
In pseudocode (section 13.3 of Morin's book):
\[\class{pseudocode}{\begin{array}{r@{\quad}l}
1 & \textbf{function}\ \mathrm{insert}( x , v ) \cr
2 & \quad ( r , T ) \gets \text{the pair of }
X.\mathrm{lowerBound}( x ) \cr
3 & \quad \textbf{if}\ x \in T\ \textbf{then}\ \text{give it the value }
v;\ \textbf{return false} \cr
4 & \quad T.\mathrm{insert}( x , v ) \cr
5 & \quad \textbf{if}\ x \ne r \text{ and a coin of bias } 1 / w
\text{ comes up}\ \textbf{then} \cr
6 & \qquad ( T' , T ) \gets \text{the keys of } T \text{ up to } x
\text{ and the others, by a split} \cr
7 & \qquad X.\mathrm{insert}( x , T' ) \cr
8 & \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 (section 13.3 of Morin's book), \( X \) the x-fast trie of the representatives:
\[\class{pseudocode}{\begin{array}{r@{\quad}l}
1 & \textbf{function}\ \mathrm{lowerBound}( x ) \cr
2 & \quad ( r , T ) \gets \text{the pair of } X.\mathrm{lowerBound}( x )
\cr
3 & \quad \textbf{return}\ \text{the smallest key} \ge x \text{ of }
T \text{, or } \textbf{nil}
\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( \log w ) \) expected amortized time
In pseudocode (section 13.3 of Morin's book):
\[\class{pseudocode}{\begin{array}{r@{\quad}l}
1 & \textbf{function}\ \mathrm{remove}( x ) \cr
2 & \quad ( r , T ) \gets \text{the pair of }
X.\mathrm{lowerBound}( x ) \cr
3 & \quad \textbf{if}\ x \notin T\ \textbf{then return false} \cr
4 & \quad T.\mathrm{remove}( x ) \cr
5 & \quad \textbf{if}\ x = r \ne 2^w - 1\ \textbf{then} \cr
6 & \qquad ( r' , T' ) \gets \text{the pair after } ( r , T ) \text{ in }
X \cr
7 & \qquad T' \gets \mathrm{join}( T , T' );\ X.\mathrm{remove}( x ) \cr
8 & \quad \textbf{return true}
\end{array}}
\]
- Precondition
- \( x < 2^w \)
- Postcondition
- \( x \) is not there