|
ADS
Algorithms and Data Structures
|
The x-fast tries of Willard, beyond the book: SORTED SETs of the integers of \( w \) bits, each with a value, in which lowerBound( x ) gives the smallest key \( \ge x \) (the find( x ) of the SSet of Morin's book) in \( O( \log w ) \) expected time. More...
#include "ADS/Contract.h"#include "ADS/Iterators.h"#include "ADS/dictionary/BinaryTrie.h"#include "ADS/dictionary/FlatHashTable.h"#include "ADS/memory/ObjectPool.h"#include <array>#include <concepts>#include <cstddef>#include <iterator>#include <limits>#include <optional>#include <utility>#include <variant>#include "ADS/dictionary/impl/XFastTrie.tpp"Go to the source code of this file.
Classes | |
| class | ADS::XFastTrie< U, V, W > |
| the x-fast trie: a binary trie with a hash table of the prefixes per depth More... | |
| 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) More... | |
| class | ADS::ListXFastTrie< U, V, W >::const_iterator |
| the bidirectional iterator along the list More... | |
Namespaces | |
| namespace | ADS |
The x-fast tries of Willard, beyond the book: SORTED SETs of the integers of \( w \) bits, each with a value, in which lowerBound( x ) gives the smallest key \( \ge x \) (the find( x ) of the SSet of Morin's book) in \( O( \log w ) \) expected time.
Both have also findNear( x ), the search of exercise 13.4 of Morin's book, whose time depends on the distance \( d( x ) \) between \( x \) and its successor (\( 2^w \) if there is none): with \( k = \lceil \log_2( d( x ) + 1 ) \rceil \), the successor lies in \( [ x , x + 2^k ) \), which meets at most two blocks of \( 2^k \) keys aligned to \( 2^k \), those of the prefixes \( p \) and \( p + 1 \) of depth \( w - k \), with \( p = \lfloor x / 2^k \rfloor \). The search tries \( K = 1 , 2 , 4 , \ldots \) until one of the two prefixes of depth \( w - K \) is there, \( O( \log k ) \) steps, and then either searches \( \ell \) between \( w - K \) and \( w - K / 2 \), in \( O( \log K ) \) lookups, or takes the smallest key of the prefix \( p + 1 \): in \( O( 1 ) \) in ListXFastTrie, which keeps it, and by a walk of \( O( K ) \) nodes in XFastTrie. The expected time is \( O( 1 + \log \log d( x ) ) \) for ListXFastTrie, the second point of the exercise, and \( O( 1 + \log d( x ) ) \) for XFastTrie, the first one.
Where it is meant to be faster than the code of Morin's book: the tables are FlatHashTables, which compare a fingerprint of the hash with 15 places at once and touch about one line of cache per lookup, where the book uses its LinearHashTable of pairs, whose probes compare whole keys; a binary search makes \( \lceil \log_2( w + 1 ) \rceil \) lookups that depend on each other, so that the latency of each one is what counts. The nodes come from a pool [see BinaryTrie.h].
The tables are FlatHashTables [see FlatHashTable.h], whose expected time per operation is \( O( 1 ) \). 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 (the order of the list and the tables of the prefixes) is checked in \( O( n w ) \) time at the level 3 while \( n \le 256 \), and around the key of the operation beyond. The operations are defined in XFastTrie.tpp.