8 namespace tdc {
namespace esp {
9 template<
typename d_coding_t = DMonotonSubseq<>>
14 Meta m(
"slp_coder",
"sorted");
38 if (
env().option(
"dump_json").as_bool()) {
39 phase.split(
"Dump JSON");
40 std::ofstream ostream(
env().option(
"dump_json_file").as_string() +
".json");
42 std::vector<size_t> dl;
43 std::vector<size_t> dr;
44 for (
auto& e : slp.rules) {
58 phase.split(
"Encode headers");
63 auto bouts = std::make_shared<BitOStream>(output.
as_stream());
66 DCHECK_GE(bit_width, 1);
67 DCHECK_LE(bit_width, 63);
72 DCHECK(slp.rules.empty());
73 DCHECK_EQ(slp.root_rule, 0);
77 bout.write_int(bit_width, 6);
80 bout.write_int(max_val, bit_width);
83 bout.write_int(slp.root_rule, bit_width);
85 if (slp.empty || slp.root_rule < 256) {
106 phase.split(
"Encode SLP LHS");
111 for (
auto& e : slp.rules) {
112 DCHECK_LE(last, e[0]);
113 size_t diff = e[0] - last;
114 bout.write_unary(diff);
119 phase.split(
"Encode SLP RHS");
123 d_coding.encode(rhs, bouts, bit_width, max_val);
127 auto bins = std::make_shared<BitIStream>(input.
as_stream());
131 auto bit_width = bin.read_int<
size_t>(6);
132 bool empty = (bit_width == 0);
135 auto max_val = bin.read_int<
size_t>(bit_width);
138 auto root_rule = bin.read_int<
size_t>(bit_width);
148 slp.root_rule = root_rule;
150 if (empty || slp.root_rule < 256) {
154 size_t slp_size = (max_val + 1) - 256;
155 slp.rules.reserve(slp_size);
156 slp.rules.resize(slp_size);
161 for(
size_t i = 0; i < slp_size && !bin.eof(); i++) {
163 auto diff = bin.read_unary<
size_t>();
165 slp.rules[i][0] = last;
171 d_coding.decode(D, bins, bit_width, max_val);
void encode(DebugContext &debug, SLP &&slp, Output &output) const
Contains the text compression and encoding framework.
constexpr uint_fast8_t bits_for(size_t n)
Computes the number of bits required to store the given integer value.
size_t GRAMMAR_PD_ELLIDED_PREFIX
std::string vec_to_debug_string(const T &s, size_t indent=0)
Builds the string representation of a vector of byte values, sorrounded by square brackets ([ and ])...
Env env_for_option(const std::string &option) const
Create the environment for a sub algorithm option.
Provides access to runtime and memory measurement in statistics phases.
void slp_dep_sort(SLP &slp)
Algorithm(Algorithm const &)=default
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 abstraction layer for algorithm output.
SLP decode(Input &input) const
Interface for algorithms.