23 template<
typename coder_t,
typename text_t = TextDS<>>
27 Meta m(
"compressor",
"lzss_lcp",
"LZSS Factorization using LCP");
44 DCHECK(view.ends_with(uint8_t(0)));
48 return text_t(
env().env_for_option(
"textds"), view,
52 auto& sa = text.require_sa();
53 auto& isa = text.require_isa();
54 auto& lcp = text.require_lcp();
57 const len_t text_length = text.size();
63 for(
len_t i = 0; i+1 < text_length;) {
65 const size_t& cur_pos = isa[i];
71 size_t psv_lcp = lcp[cur_pos];
72 ssize_t psv_pos = cur_pos - 1;
74 while (psv_pos >= 0 && sa[psv_pos] > sa[cur_pos]) {
75 psv_lcp = std::min<size_t>(psv_lcp, lcp[psv_pos--]);
83 size_t nsv_pos = cur_pos + 1;
84 if (nsv_pos < text_length) {
87 nsv_lcp = std::min<size_t>(nsv_lcp, lcp[nsv_pos]);
88 if (sa[nsv_pos] < sa[cur_pos]) {
91 }
while (++nsv_pos < text_length);
93 if (nsv_pos >= text_length) {
99 const size_t& max_lcp = std::max(psv_lcp, nsv_lcp);
100 if(max_lcp >= threshold) {
101 const ssize_t& max_pos = max_lcp == psv_lcp ? psv_pos : nsv_pos;
102 DCHECK_LT(max_pos, text_length);
103 DCHECK_GE(max_pos, 0);
119 typename coder_t::Encoder coder(
env().env_for_option(
"coder"),
127 typename coder_t::Decoder decoder(
env().env_for_option(
"coder"), input);
130 lzss::decode_text<typename coder_t::Decoder, lzss::DecodeBackBuffer>(decoder, outs);
Contains the text compression and encoding framework.
virtual void decompress(Input &input, Output &output) override
Decompress the given input to the given output.
const OptionValue & option(const std::string &option) const
Get an option of this algorithm.
Computes the LZ77 factorization of the input using its suffix array and LCP table.
Base for data compressors.
void encode_text(coder_t &coder, const text_t &text, const factor_t &factors)
uint64_t as_integer() const
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.
virtual void compress(Input &input, Output &output) override
Compress the given input to the given output.
LZSSLCPCompressor()=delete
Default constructor (not supported).
An abstraction layer for algorithm output.
fast_t< len_compact_t > len_t
Type to represent an length value.
LZSSLCPCompressor(Env &&env)
Construct the class with an environment.
void emplace_back(len_t fpos, len_t fsrc, len_t flen)
static void log(const char *key, const T &value)
Logs a user statistic for the current phase.
static auto wrap(const char *title, F func) -> typename std::result_of< F(StatPhase &)>::type
Executes a lambda as a single statistics phase.
Local environment for a compression/encoding/decompression call.
Manages text related data structures.