8 template<
typename string_coder_t>
14 Meta m(
"lz78u_strategy",
"buffering");
19 template<
typename ref_coder_t>
22 std::shared_ptr<BitOStream> m_out;
25 std::vector<Range> m_ref_ranges;
27 std::vector<size_t> m_refs;
29 std::vector<bool> m_seps;
30 std::vector<uliteral_t> m_chars;
35 std::vector<uint8_t> m_stream;
40 std::shared_ptr<BitOStream> out):
42 m_ref_env(
std::move(ref_env)),
46 m_refs.push_back(ref);
47 m_ref_ranges.push_back(ref_range);
48 m_stream.push_back(0);
52 m_seps.push_back(val);
53 m_stream.push_back(1);
58 m_stream.push_back(2);
69 typename ref_coder_t::Encoder ref_coder {
74 typename string_coder_t::Encoder string_coder {
75 std::move(this->
env().env_for_option(
"string_coder")),
80 auto refs_i = m_refs.begin();
81 auto ref_ranges_i = m_ref_ranges.begin();
82 auto seps_i = m_seps.begin();
83 auto chars_i = m_chars.begin();
85 for (
auto kind : m_stream) {
88 auto ref = *(refs_i++);
89 auto ref_range = *(ref_ranges_i++);
90 ref_coder.encode(ref, ref_range);
95 auto sep = *(seps_i++);
96 m_out->write_bit(sep);
101 auto chr = *(chars_i++);
109 DCHECK(refs_i == m_refs.end());
110 DCHECK(ref_ranges_i == m_ref_ranges.end());
111 DCHECK(seps_i == m_seps.end());
112 DCHECK(chars_i == m_chars.end());
116 template<
typename ref_coder_t>
118 typename ref_coder_t::Decoder m_ref_coder;
119 typename string_coder_t::Decoder m_string_coder;
121 std::vector<uliteral_t> m_buf;
122 std::shared_ptr<BitIStream> m_in;
126 std::shared_ptr<BitIStream> in):
128 m_ref_coder(
std::move(ref_env), in),
129 m_string_coder(
std::move(this->
env().env_for_option(
"string_coder")), in),
133 return m_ref_coder.template decode<size_t>(ref_range);
137 return m_string_coder.template decode<uliteral_t>(
literal_r);
143 auto c = decode_char();
153 return m_in->read_bit();
157 return m_ref_coder.eof();
Represents a generic range of positive integers.
Contains the text compression and encoding framework.
void encode_ref(size_t ref, Range ref_range)
A const view into a slice of memory.
uint8_t uliteral_t
Type to represent signed single literals.
A literal iterator that yields every character from a View.
Algorithm(Algorithm const &)=default
size_t decode_ref(Range ref_range)
Env & env()
Provides access to the environment that the algorithm works in.
void encode_sep(bool val)
An empty literal iterator that yields no literals whatsoever.
constexpr auto literal_r
Global predefined reange for literals.
void encode_char(uliteral_t c)
Decompression(Env &&env, Env &&ref_env, std::shared_ptr< BitIStream > in)
void clear()
Sets the size to 0.
Compression(Env &&env, Env &&ref_env, std::shared_ptr< BitOStream > out)
void encode_str(View str)
Local environment for a compression/encoding/decompression call.
Interface for algorithms.