|
ADS
Algorithms and Data Structures
|
the compacted trie of a sorted dictionary of strings in DFUDS, the strings numbered by their lexicographic rank More...
#include <ADS/dictionary/SuccinctPatriciaTrie.h>
Public member functions | |
| SuccinctPatriciaTrie (void) | |
| the empty dictionary | |
| SuccinctPatriciaTrie (const std::vector< std::string > &D) | |
| the trie of the strings of \( D \) | |
| std::size_t | size (void) const |
| the number \( n \) of strings | |
| bool | empty (void) const |
| whether there is no string | |
| std::size_t | nodes (void) const |
| the nodes of the compacted trie, \( N \) | |
| std::size_t | lookup (std::string_view Q) const |
| the rank of \( Q \) in the dictionary, size() if it is not there | |
| bool | contains (std::string_view Q) const |
| whether \( Q \) is a string of the dictionary, by lookup() | |
| std::string | access (std::size_t i) const |
| the string of rank \( i \) | |
| std::size_t | lexicographicPosition (std::string_view Q) const |
| the number of strings smaller than \( Q \), by the walk of lookup() up to the first mismatch and the end of a subtree there | |
| std::pair< std::size_t, std::size_t > | prefixRange (std::string_view P) const |
| the range \( [ l , r ) \) of the ranks of the strings prefixed by \( P \), empty at lexicographicPosition( P ) if there is none | |
| std::size_t | bytes (void) const |
| the bytes of the structure: the parentheses with their directory and tree, the first characters, the marks and the rests of the labels | |
the compacted trie of a sorted dictionary of strings in DFUDS, the strings numbered by their lexicographic rank
| ADS::SuccinctPatriciaTrie::SuccinctPatriciaTrie | ( | void | ) |
the empty dictionary
|
explicit |
the trie of the strings of \( D \)
In pseudocode (Benoit et al., beyond the book), a node as the range \( [ l , r ) \) of the strings below it and the depth \( h \) of its end:
\[\class{pseudocode}{\begin{array}{r@{\quad}l} 1 & \textbf{procedure}\ \mathrm{build}( D ) \cr 2 & \quad \mathrm{append}( \mathit{BP} , \text{(} );\ S \gets \text{a stack with the root } ( 0 , n , 0 ) \cr 3 & \quad \textbf{while}\ S \ne \emptyset\ \textbf{do} \cr 4 & \qquad ( l , r , h ) \gets \mathrm{pop}( S );\ \mathrm{append}( T , | s_l | = h );\ \textbf{if}\ | s_l | = h\ \textbf{then}\ l \gets l + 1 \cr 5 & \qquad \text{split } [ l , r ) \text{ into the runs } [ a_k , b_k ) \text{ of the same character } s_{a_k}[ h ] \cr 6 & \qquad \textbf{foreach}\ k\ \textbf{do}\ \mathrm{append}( \mathit{BP} , \text{(} );\ \mathrm{append}( \Lambda , s_{a_k}[ h ] ) \cr 7 & \qquad \mathrm{append}( \mathit{BP} , \text{)} ) \cr 8 & \qquad \textbf{foreach}\ k \text{ from the last}\ \textbf{do} \cr 9 & \qquad\quad h' \gets | s_{a_k} | \text{ if } b_k = a_k + 1 \text{, else } \mathrm{commonPrefixLength}( s_{a_k} , s_{b_k - 1} ) \cr 10 & \qquad\quad \text{the rest of its label is } s_{a_k}[ h + 1 .. h' - 1 ];\ \mathrm{push}( S , ( a_k , b_k , h' ) ) \end{array}} \]
where the rest is written when the node is popped, so that the rests are in the order of the visit too.
|
nodiscard |
the string of rank \( i \)
In pseudocode (Benoit et al., beyond the book):
\[\class{pseudocode}{\begin{array}{r@{\quad}l} 1 & \textbf{function}\ \mathrm{access}( i ) \cr 2 & \quad v \gets \mathrm{select}_1( T , i + 1 );\ s \gets \text{the } \text{empty string} \cr 3 & \quad \textbf{while}\ v \text{ is not the root}\ \textbf{do} \cr 4 & \qquad q \gets \mathrm{findOpen}( p_v - 1 );\ u \gets \text{the } \text{node of } q \cr 5 & \qquad s \gets \Lambda[ \text{the child } p_u + d_u - 1 - q \text{ of } u ] \cdot \lambda( v ) \cdot s;\ v \gets u \cr 6 & \quad \textbf{return}\ s \end{array}} \]
|
nodiscard |
the bytes of the structure: the parentheses with their directory and tree, the first characters, the marks and the rests of the labels
|
nodiscard |
whether \( Q \) is a string of the dictionary, by lookup()
|
nodiscard |
whether there is no string
|
nodiscard |
the number of strings smaller than \( Q \), by the walk of lookup() up to the first mismatch and the end of a subtree there
|
nodiscard |
the rank of \( Q \) in the dictionary, size() if it is not there
In pseudocode (Benoit et al., beyond the book), \( \lambda( v ) \) the rest of the label of the node \( v \) and \( T \) the marks of the nodes where a string ends:
\[\class{pseudocode}{\begin{array}{r@{\quad}l} 1 & \textbf{function}\ \mathrm{lookup}( Q ) \cr 2 & \quad v \gets \text{the root};\ j \gets 0 \cr 3 & \quad \textbf{loop} \cr 4 & \qquad \textbf{if}\ \lambda( v ) \text{ is not } Q[ j .. j + | \lambda( v ) | - 1 ]\ \textbf{then return}\ n \cr 5 & \qquad j \gets j + | \lambda( v ) | \cr 6 & \qquad \textbf{if}\ j = | Q |\ \textbf{then return} \ \mathrm{rank}_1( T , v ) \text{ if } T[ v ] = 1 \text{, else } n \cr 7 & \qquad i \gets \text{the child of } v \text{ whose first character } \text{is } Q[ j ] \text{, by a binary search};\ \textbf{if} \ \text{none}\ \textbf{then return}\ n \cr 8 & \qquad v \gets \mathrm{findClose}( p_v + d_v - 1 - i ) + 1;\ j \gets j + 1 \end{array}} \]
|
nodiscard |
the nodes of the compacted trie, \( N \)
|
nodiscard |
the range \( [ l , r ) \) of the ranks of the strings prefixed by \( P \), empty at lexicographicPosition( P ) if there is none
In pseudocode (Benoit et al., beyond the book):
\[\class{pseudocode}{\begin{array}{r@{\quad}l} 1 & \textbf{function}\ \mathrm{prefixRange}( P ) \cr 2 & \quad v \gets \text{the highest node whose path from the root has } P \text{ as a prefix, by the walk of } \mathrm{lookup}() \cr 3 & \quad \textbf{if}\ \text{none}\ \textbf{then return}\ [ x , x ) \text{ for } x = \mathrm{lexicographicPosition}( P ) \cr 4 & \quad e \gets \mathrm{forwardSearch}( p_v - 1 , -1 ) + 1\quad \triangleright\ \text{the end of the subtree of } v \cr 5 & \quad \textbf{return}\ [ \mathrm{rank}_1( T , v ) , \mathrm{rank}_1( T , \mathrm{rank}_0( \mathit{BP} , e ) ) ) \end{array}} \]
|
nodiscard |
the number \( n \) of strings