|
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 [see LempelZiv.h], which searches the window for each phrase, in \( O( n w ) \) time. More...
#include "ADS/Contract.h"#include "ADS/compression/LempelZiv.h"#include "ADS/string/SuffixArray.h"#include <algorithm>#include <cstddef>#include <cstdint>#include <optional>#include <string_view>#include <vector>#include "ADS/compression/impl/LZ77Linear.tpp"Go to the source code of this file.
Namespaces | |
| namespace | ADS |
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 [see LempelZiv.h], which searches the window for each phrase, in \( O( n w ) \) time.
The phrases are those of lz77Parse() with an unbounded window: at the place \( i \) the longest prefix of \( s[ i , n ) \) that starts at an earlier place (and may overlap \( s[ i , n ) \)), its length \( \ell \), the distance back to one such start, and the symbol after it; the parse moves \( \ell + 1 \) places.
Among the suffixes that start before \( i \), the one that shares the longest prefix with the suffix \( i \) is next to it in the order of the suffixes: it is either the previous smaller value or the next smaller value of \( i \),
\[ \mathit{PSV}( i ) = \mathit{SA}[ \max \{ j < r : \mathit{SA}[ j ] < i \} ] , \qquad \mathit{NSV}( i ) = \mathit{SA}[ \min \{ j > r : \mathit{SA}[ j ] < i \} ] , \]
with \( r \) the rank of \( i \) in the suffix array \( \mathit{SA} \) [see SuffixArray.h], since the longest common prefix of two suffixes is the least over the suffixes between them; hence \( \ell = \max( \mathrm{lcp}( i , \mathit{PSV}( i ) ) , \mathrm{lcp}( i , \mathit{NSV}( i ) ) ) \). Both are computed for all \( i \) in one scan of \( \mathit{SA} \) with a stack, each place pushed and popped once, and the two prefixes of a phrase are compared symbol by symbol, at most \( \ell + 1 \) comparisons each, which sum to \( O( n ) \) over the phrases. Hence \( O( n ) \) time with the suffix array of SA-IS, and two arrays of \( n \) integers of 32 bits besides the text and the suffix array, which is freed before the parse; the source found is the previous or the next smaller value, not the closest one of the same chapter, with the same lengths.
The contracts [see Contract.h]: \( n < 2^{32} - 1 \), since \( 2^{32} - 1 \) marks a missing value; the audit is that the phrases decode to the text [see LempelZiv.h]. The function is defined in LZ77Linear.tpp.