|
ADS
Algorithms and Data Structures
|
The compressors of Lempel and Ziv (chapter 13, Dictionary-Based Compressors, of Ferragina's book, beyond the book of Montresor), whose dictionary is the text itself: they replace a string seen before with a reference to it, and need no model of the source. More...
#include "ADS/Contract.h"#include <algorithm>#include <cstddef>#include <cstdint>#include <limits>#include <map>#include <optional>#include <string>#include <string_view>#include <unordered_map>#include <utility>#include <vector>#include "ADS/compression/impl/LempelZiv.tpp"Go to the source code of this file.
Classes | |
| struct | ADS::LZ77Phrase |
| a phrase of LZ77: copy length symbols from distance back, then next (none at the end of the text); distance is 0 when length is 0 More... | |
| struct | ADS::LZSSPhrase |
| a phrase of LZSS: a copy of length symbols from distance back, or the literal when distance is 0 More... | |
| struct | ADS::LZ78Phrase |
| a phrase of LZ78: the phrase id followed by next More... | |
Namespaces | |
| namespace | ADS |
Functions | |
| std::vector< LZ77Phrase > | ADS::lz77Parse (std::string_view s, std::size_t w=std::numeric_limits< std::size_t >::max()) |
| the parse of LZ77 of \( s \) with a window of \( w \) symbols, the closest among the longest copies | |
| std::string | ADS::lz77Decode (const std::vector< LZ77Phrase > &P) |
| the text of the phrases \( P \) of LZ77 | |
| std::vector< LZSSPhrase > | ADS::lzssParse (std::string_view s, std::size_t w=std::numeric_limits< std::size_t >::max(), std::size_t minLength=1) |
| the parse of LZSS of \( s \) with a window of \( w \) symbols, a copy for the closest among the longest prefixes of length at least minLength, a literal otherwise, by searching the whole window | |
| std::vector< LZSSPhrase > | ADS::lzssParseHashed (std::string_view s, std::size_t w, std::size_t minLength=3, std::size_t maxChain=std::numeric_limits< std::size_t >::max()) |
| the parse of LZSS of \( s \) by the chains of the hashes of 3 symbols, as in gzip, following at most maxChain candidates | |
| std::string | ADS::lzssDecode (const std::vector< LZSSPhrase > &P) |
| the text of the phrases \( P \) of LZSS | |
| std::vector< LZ78Phrase > | ADS::lz78Parse (std::string_view s, std::size_t maxPhrases=std::numeric_limits< std::size_t >::max()) |
| the parse of LZ78 of \( s \), the dictionary restarting when it has maxPhrases phrases besides the empty one | |
| std::string | ADS::lz78Decode (const std::vector< LZ78Phrase > &P, std::size_t maxPhrases=std::numeric_limits< std::size_t >::max()) |
| the text of the phrases \( P \) of LZ78 | |
| std::vector< std::uint32_t > | ADS::lzwEncode (std::string_view s) |
| the identifiers of the code of LZW of \( s \) | |
| std::string | ADS::lzwDecode (const std::vector< std::uint32_t > &I) |
| the text of the code \( I \) of LZW | |
The compressors of Lempel and Ziv (chapter 13, Dictionary-Based Compressors, of Ferragina's book, beyond the book of Montresor), whose dictionary is the text itself: they replace a string seen before with a reference to it, and need no model of the source.
All of them are universal: on the text of an ergodic source their bits per symbol tend to its entropy (Ziv and Lempel), and the number of phrases bounds the entropy of order \( k \) of every text (Kosaraju and Manzini), but with a term that vanishes slowly. The practice uses LZ77 with long windows and fast searches: the suffix trees or arrays of an unbounded window, and the parse that minimizes the bits rather than the phrases (Ferragina, Nitto and Venturini); LZMA, Zstandard and Brotli add context models and codes of the arithmetic family to the fields of the phrases.
The contracts [see Contract.h]: the window and the number of phrases are positive, the minimum length of lzssParseHashed() is at least 3, the phrases decoded refer to symbols already decoded; the decoding of each parse gives back its text, an audit. The functions are defined in LempelZiv.tpp.