|
ADS
Algorithms and Data Structures
|
The binary tries of the integers of \( w \) bits, beyond the book: a SORTED SET of keys \( x \in \{ 0 , \ldots , 2^w - 1 \} \), each with a value, in which lowerBound( x ) gives the smallest key \( \ge x \) (the successor, the find( x ) of the SSet of Morin's book), in time that depends on \( w \) and not on the number \( n \) of keys. More...
#include "ADS/Contract.h"#include "ADS/Iterators.h"#include "ADS/Portable.h"#include "ADS/dictionary/FlatHashTable.h"#include "ADS/memory/ObjectPool.h"#include <array>#include <concepts>#include <cstddef>#include <iterator>#include <limits>#include <optional>#include <type_traits>#include <utility>#include <variant>#include "ADS/dictionary/impl/BinaryTrie.tpp"Go to the source code of this file.
Classes | |
| class | ADS::BinaryTrie< U, V, W > |
| a binary trie of the integers of \( w \) bits with the list of the leaves and the jump pointers, a SORTED SET with a value per key More... | |
| 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) More... | |
Namespaces | |
| namespace | ADS |
Concepts | |
| concept | ADS::TrieWidth |
| the number of bits of the keys of a trie on U: \( w \), if it is between 1 and the bits of U | |
The binary tries of the integers of \( w \) bits, beyond the book: a SORTED SET of keys \( x \in \{ 0 , \ldots , 2^w - 1 \} \), each with a value, in which lowerBound( x ) gives the smallest key \( \ge x \) (the successor, the find( x ) of the SSet of Morin's book), in time that depends on \( w \) and not on the number \( n \) of keys.
Against the code of Morin's book: the nodes of BinaryTrie come from a pool instead of one call to the allocator each, and those made one after another lie next to each other, so that the \( w \) nodes of a new path seldom cost an allocation and the walk from the root misses the cache less (where it is meant to be faster); the keys have any width up to 64 bits, where the book fixes \( w = 32 \); and remove() reads the links of the leaf before it frees it, while the code of the book reads them from the freed leaf. SimpleBinaryTrie, with two pointers per internal node instead of five, takes less memory, at the price of the walk down to the leftmost leaf.
The x-fast trie of section 13.2 shares the code of BinaryTrie [see XFastTrie.h]. 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 depth of the leaves, the order of the list, the jump pointers and, for the x-fast trie, the tables of the prefixes) is checked in \( O( n w ) \) time at the level 3 while \( n \le 256 \), and at the leaf of the operation beyond. The operations are defined in BinaryTrie.tpp.