14 template<
typename coder_t>
22 Meta m(
"compressor",
"lzss",
"Lempel-Ziv-Storer-Szymanski (Sliding Window)");
42 typename coder_t::Encoder coder(
env().env_for_option(
"coder"), output,
NoLiterals());
44 std::vector<uint8_t> buf;
53 while(buf.size() < 2 * m_window && ins.get(c)) {
54 buf.push_back(uint8_t(c));
59 phase.
log_stat(
"threshold", threshold);
63 while(ahead < buf.size()) {
64 size_t fpos = 0, fsrc = 0, fnum = 0;
67 for(
size_t k = (ahead > m_window ? ahead - m_window : 0); k < ahead; k++) {
70 while(ahead + j < buf.size() && buf[k + j] == buf[ahead + j]) {
75 if(j >= threshold && j > fnum) {
76 fpos = buf_off + ahead;
87 coder.encode(
true,
bit_r);
88 coder.encode(fpos - fsrc,
Range(fpos));
89 coder.encode(fnum,
Range(m_window));
94 coder.encode(
false,
bit_r);
103 if(ahead < m_window) {
106 }
else if(!eof && ins.get(c)) {
108 buf.erase(buf.begin());
109 buf.push_back(uint8_t(c));
121 typename coder_t::Decoder decoder(
env().env_for_option(
"coder"), input);
123 std::vector<uliteral_t> text;
124 while(!decoder.eof()) {
125 bool is_factor = decoder.template decode<bool>(
bit_r);
127 size_t fsrc = text.size() - decoder.template decode<size_t>(
Range(text.size()));
130 size_t fnum = decoder.template decode<size_t>(
Range(m_window));
132 for(
size_t i = 0; i < fnum; i++) {
133 text.push_back(text[fsrc+i]);
136 auto c = decoder.template decode<uliteral_t>(
literal_r);
142 for(uint8_t c : text) outs << c;
Represents a generic range of positive integers.
Contains the text compression and encoding framework.
constexpr auto bit_r
Global predefined range for bits (0 or 1).
uint8_t uliteral_t
Type to represent signed single literals.
const OptionValue & option(const std::string &option) const
Get an option of this algorithm.
Base for data compressors.
LZSSSlidingWindowCompressor()=delete
Default constructor (not supported).
Provides access to runtime and memory measurement in statistics phases.
uint64_t as_integer() const
virtual void decompress(Input &input, Output &output) override
Decompress the given input to the given output.
Env & env()
Provides access to the environment that the algorithm works in.
OutputStream as_stream() const
Creates a stream that allows for character-wise output.
An empty literal iterator that yields no literals whatsoever.
constexpr auto literal_r
Global predefined reange for literals.
An abstraction layer for algorithm output.
fast_t< len_compact_t > len_t
Type to represent an length value.
void log_stat(const char *key, const T &value)
Logs a user statistic for this phase.
LZSSSlidingWindowCompressor(Env &&e)
Construct the class with an environment.
virtual void compress(Input &input, Output &output) override
Compress the given input to the given output.
Local environment for a compression/encoding/decompression call.
Computes the LZ77 factorization of the input by moving a sliding window over it in which redundant ph...