|
ADS
Algorithms and Data Structures
|
The y-fast trie of Willard, beyond the book, in the form of section 13.3 of Morin's book: a SORTED SET of the integers of \( w \) bits, each with a value, in \( O( n ) \) space, whose lowerBound( x ) (the smallest key \( \ge x \), the find( x ) of the SSet of the book), insert() and remove() take \( O( \log w ) \) expected time, the last two amortized. More...
#include "ADS/Contract.h"#include "ADS/dictionary/RandomHashing.h"#include "ADS/dictionary/XFastTrie.h"#include "ADS/tree/Treap.h"#include <concepts>#include <cstddef>#include <cstdint>#include <limits>#include <optional>#include <variant>#include "ADS/dictionary/impl/YFastTrie.tpp"Go to the source code of this file.
Classes | |
| class | ADS::YFastTrie< U, V, W > |
| the y-fast trie: an x-fast trie of representatives over treaps of \( O( w ) \) keys More... | |
Namespaces | |
| namespace | ADS |
The y-fast trie of Willard, beyond the book, in the form of section 13.3 of Morin's book: a SORTED SET of the integers of \( w \) bits, each with a value, in \( O( n ) \) space, whose lowerBound( x ) (the smallest key \( \ge x \), the find( x ) of the SSet of the book), insert() and remove() take \( O( \log w ) \) expected time, the last two amortized.
The keys are cut into groups of consecutive keys, each kept in a Treap [see Treap.h], and the largest key of each group, its representative, is in an XFastTrie [see XFastTrie.h] with its group as the value; the key \( 2^w - 1 \) is always a representative, of the last group, so that every key has a group, the one of the smallest representative \( \ge \) it. A new key goes into its group and, with probability \( 1 / w \), becomes a representative, the group being split at it; a removed representative merges its group with the next one. The representatives are thus about \( n / w \), and the x-fast trie takes \( O( n ) \) space; a group has \( O( w ) \) keys in expectation (Lemma 13.3 of Morin's book), so that the operations on the treaps take \( O( \log w ) \) expected time, as the search in the x-fast trie does, while its updates, \( O( w ) \), happen once every \( w \) operations on average.
Where it is meant to be faster than the code of Morin's book: the x-fast trie of the representatives is the one of XFastTrie.h, with its faster tables; the search in a group descends its treap with no copy of a key, and the coin of an insertion is one word of SplitMix64 reduced modulo \( w \) instead of a call to rand().
The coins come from SplitMix64 [see RandomHashing.h], seeded, so that a run is reproducible. The contracts [see Contract.h]: the keys are below \( 2^w \), insert() ensures that the key is there and remove() that it is not; the invariant (each group between two consecutive representatives, each representative in its group but the last, and the count of the keys) is checked in \( O( n ) \) time at the level 3 while \( n \le 256 \). The operations are defined in YFastTrie.tpp.