|
ADS
Algorithms and Data Structures
|
The parse of LZ77 with no window in \( O( n ) \) time, the algorithm of Kärkkäinen, Kempa and Puglisi (beyond the book), against the parse of chapter 13, Dictionary-Based Compressors, of Ferragina's book, which searches the window for each phrase, in \( O( n w ) \) time. More...
Files | |
| file | ADS/compression/LZ77Linear.h |
| The parse of LZ77 with no window in \( O( n ) \) time, the algorithm of Kärkkäinen, Kempa and Puglisi (beyond the book), against the parse of chapter 13, Dictionary-Based Compressors, of Ferragina's book [see LempelZiv.h], which searches the window for each phrase, in \( O( n w ) \) time. | |
Functions | |
| std::vector< LZ77Phrase > | ADS::lz77ParseLinear (std::string_view s) |
| the phrases of LZ77 of \( s \) with no window, in \( O( |s| ) \) time | |
The parse of LZ77 with no window in \( O( n ) \) time, the algorithm of Kärkkäinen, Kempa and Puglisi (beyond the book), against the parse of chapter 13, Dictionary-Based Compressors, of Ferragina's book, which searches the window for each phrase, in \( O( n w ) \) time.
The definitions, the invariants and the costs of the area are in Theory of compression.
|
inlinenodiscard |
the phrases of LZ77 of \( s \) with no window, in \( O( |s| ) \) time
In pseudocode (the algorithm of Kärkkäinen, Kempa and Puglisi, beyond the book), the previous and the next smaller values found by one scan of the suffix array with a stack \( S \) of places, increasing from the bottom:
\[\class{pseudocode}{\begin{array}{r@{\quad}l} 1 & \textbf{function}\ \mathrm{lz77ParseLinear}( s ) \cr 2 & \quad \mathit{SA} \gets \text{the suffix array of } s;\ S \gets \text{an empty stack} \cr 3 & \quad \textbf{foreach}\ x \in \mathit{SA} \text{, in order} \ \textbf{do} \cr 4 & \qquad \textbf{while}\ S \ne \emptyset\ \textbf{and} \ \mathrm{top}( S ) > x\ \textbf{do}\ \mathit{NSV}[ \mathrm{pop}( S ) ] \gets x \cr 5 & \qquad \textbf{if}\ S \ne \emptyset\ \textbf{then}\ \mathit{PSV}[ x ] \gets \mathrm{top}( S ) \cr 6 & \qquad \mathrm{push}( S , x ) \cr 7 & \quad i \gets 0;\ P \gets \text{an empty list} \cr 8 & \quad \textbf{while}\ i < n\ \textbf{do} \cr 9 & \qquad a \gets \mathrm{lcp}( i , \mathit{PSV}[ i ] );\ b \gets \mathrm{lcp}( i , \mathit{NSV}[ i ] )\quad \triangleright\ 0 \text{ } \text{if missing} \cr 10 & \qquad \ell \gets \max( a , b ) \cr 11 & \qquad d \gets 0 \text{ if } \ell = 0 \text{, else } i - ( \mathit{PSV}[ i ] \text{ if } a \ge b \text{, else } \mathit{NSV}[ i ] ) \cr 12 & \qquad c \gets s[ i + \ell ] \text{ if } i + \ell < n \text{, none } \text{otherwise} \cr 13 & \qquad \text{append } \langle d , \ell , c \rangle \text{ to } P;\ i \gets i + \ell + 1 \cr 14 & \quad \textbf{return}\ P \end{array}} \]