|
ADS
Algorithms and Data Structures
|
The Patricia trie with the blind search of Ferragina and Grossi, beyond the book: the compacted trie of a sorted dictionary of \( n \) strings [see RadixTree in Trie.h, whose edges keep their whole labels] stripped of the labels, each edge keeping only its first character (the branching one) and each node the length of the prefix it stands for, so that it takes \( O( n ) \) space whatever the length of the strings, which are stored apart (e.g., on disk). More...
#include "ADS/Contract.h"#include "ADS/string/PrefixSearch.h"#include <algorithm>#include <cstddef>#include <functional>#include <string>#include <string_view>#include <utility>#include <vector>#include "ADS/dictionary/impl/PatriciaTrie.tpp"Go to the source code of this file.
Classes | |
| class | ADS::PatriciaTrie |
| a sorted dictionary of strings on a Patricia trie, with the blind search More... | |
Namespaces | |
| namespace | ADS |
The Patricia trie with the blind search of Ferragina and Grossi, beyond the book: the compacted trie of a sorted dictionary of \( n \) strings [see RadixTree in Trie.h, whose edges keep their whole labels] stripped of the labels, each edge keeping only its first character (the branching one) and each node the length of the prefix it stands for, so that it takes \( O( n ) \) space whatever the length of the strings, which are stored apart (e.g., on disk).
The blind search of a pattern \( P \) of \( p \) characters finds its lexicographic position (the number of strings smaller than \( P \)) reading a single string, in three stages:
The two traversals take \( O( p \log \sigma ) \) time with the edges of a node in a sorted array (\( O( p ) \) with a perfect hash at each node [see PerfectHashing.h]) and touch no string, and the comparison reads one string, i.e., \( O( p / B ) \) transfers of blocks against the \( O( p ) \) of the compacted trie, which reads a label per edge, and the \( O( ( p / B ) \log n ) \) of the binary search [see PrefixSearch.h]. The positions of \( P \) and of \( P\# \) give the range of the strings prefixed by \( P \) (chapter 9 of Ferragina). A string that is a prefix of another ends with a character smaller than all the others, the leaf of a string \( s \) having length \( | s | + 1 \). The trie is built from the sorted strings and the longest common prefixes of adjacent ones in \( O( N ) \) time with a stack, \( N \) being the characters of the strings.
The contracts [see Contract.h]: the strings sorted and distinct (an audit); each position \( r \) is such that the strings before \( r \) are smaller than the pattern (or than \( P\# \)) and those from \( r \) on are not, a postcondition; the invariant is that every node but the root has at least two children and that the children of a node have increasing characters and consecutive strings. The functions are defined in PatriciaTrie.tpp.