7 namespace tdc {
namespace esp {
12 bool print_early =
true;
13 std::vector<std::function<void(std::ostream&)>> m_print_instructions;
16 std::shared_ptr<Data>
m_data;
24 f(m_data->m_child_data);
29 static std::vector<size_t>
cast_vec(
const U& v) {
30 std::vector<size_t> r;
41 m_data->m_print_instructions.push_back(f);
42 if (m_data->print_early) {
43 m_data->m_print_instructions.back()(*(m_data->m_out));
49 m_data = std::make_shared<Data>(Data { &o, p_ea });
55 m_data = std::make_shared<Data>(Data {
57 parent.m_data->print_early
63 m_data(other.m_data) {}
67 if (!m_data->print_early) {
68 for (
auto& f : m_data->m_print_instructions) {
98 m_data.alphabet_size = alphabet_size;
106 m_data.alphabet_size = alphabet_size;
111 void init(
size_t type,
const T&
string,
size_t offset) {
118 o <<
" type: " <<
m_data->type
119 <<
", offset: " <<
m_data->offset
126 void block(
size_t width,
size_t type) {
128 auto b =
TypedBlock { uint8_t(width), uint8_t(type) };
129 m_data.unadjusted_blocks.push_back(b);
132 o <<
" block: " << b <<
"\n";
143 o <<
" Alphabet reduction initial:\n" 152 o <<
" Reduce to 6:\n";
160 auto p = std::make_shared<std::vector<size_t>>(
cast_vec(buf));
161 m_data.mb2_reduce_to_6_steps.push_back(p);
172 o <<
" Reduce to 3:\n";
180 auto p = std::make_shared<std::vector<size_t>>(
cast_vec(buf));
181 m_data.mb2_reduce_to_3_steps.push_back(p);
195 o <<
" High landmarks:\n" 207 o <<
" High and low landmarks:\n" 217 size_t root_node = 0;
243 size_t alphabet_size) {
247 m_data.alphabet_size = alphabet_size;
250 o <<
"\n[Round #" <<
m_data->number <<
"]:\n" 252 o <<
" Alphabet size: " <<
m_data->alphabet_size <<
"\n";
263 o <<
" DONE, empty input\n";
265 o <<
" DONE, root node: " << m_data->root_node <<
"\n";
274 as =
m_data.alphabet_size;
278 m_data.metablocks.push_back(m_data_child);
280 this->
print([m_data_child](std::ostream& o) {
281 m_data_child.print_all();
290 m_data.adjusted_blocks = buf;
293 o <<
" Adjusted blocks:\n";
294 for (
auto b :
m_data->adjusted_blocks) {
295 o <<
" block: " << b <<
"\n";
304 o <<
" Slice-Symbol map:\n";
312 auto p = std::make_shared<std::pair<std::vector<size_t>,
size_t>>(
313 std::pair<std::vector<size_t>,
size_t> {
318 m_data.slice_symbol_map.push_back(p);
323 << p->second <<
"\n";
337 std::vector<std::shared_ptr<std::vector<size_t>>>
encode_slp;
353 o <<
"\n[Input]:\n\"" <<
m_data->input <<
"\"\n";
361 m_data.root_node = root_node;
364 o <<
"\n[Grammar]:\n" 365 <<
" Is empty: " << (
m_data->empty?
"yes" :
"no") <<
"\n" 366 <<
" Root node: " <<
m_data->root_node <<
"\n";
374 o <<
"\n[Encode]:\n";
381 m_data.encode_max_value = value;
382 m_data.encode_max_value_bits = bits;
385 o <<
" Max value: " <<
m_data->encode_max_value <<
"\n";
386 o <<
" Bits: " <<
m_data->encode_max_value_bits <<
"\n";
393 m_data.encode_root_node = node;
396 o <<
" Root node: " <<
m_data->encode_root_node <<
"\n";
412 auto p = std::make_shared<std::vector<size_t>>(
cast_vec(rule));
413 m_data.encode_slp.push_back(p);
424 m_data.rounds.push_back(m_data_child);
426 this->
print([m_data_child](std::ostream& o) {
Contains the text compression and encoding framework.
std::vector< size_t > mb2_high_and_low_landmarks
void slice_symbol_map(const T &slice, size_t symbol)
void mb2_reduce_to_3_step(const T &buf)
DebugRoundContext(std::ostream &o, bool p_en, bool p_ea)
void mb2_reduce_to_3_start()
size_t encode_max_value_bits
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 ])...
DebugContextBase(std::ostream &o, bool p_en, bool p_ea)
A const view into a slice of memory.
DebugMetablockContext(DebugContextBase< U > &parent, size_t alphabet_size)
void adjusted_blocks(const ConstGenericView< TypedBlock > &buf)
std::vector< std::shared_ptr< std::pair< std::vector< size_t >, size_t > > > slice_symbol_map
void encode_root_node(size_t node)
std::vector< std::shared_ptr< std::vector< size_t > > > mb2_reduce_to_6_steps
DebugContext(std::ostream &o, bool p_en, bool p_ea)
std::vector< std::shared_ptr< std::vector< size_t > > > mb2_reduce_to_3_steps
void mb2_high_and_low_landmarks(const T &buf)
void input_string(string_ref s)
void block(size_t width, size_t type)
void init(size_t number, const X &string, size_t alphabet_size)
void mb2_high_landmarks(const T &buf)
void last_round(size_t rn, bool empty)
std::vector< DebugRoundContext > rounds
std::vector< std::shared_ptr< std::vector< size_t > > > encode_slp
void encode_max_value(size_t value, size_t bits)
static std::vector< size_t > cast_vec(const U &v)
DebugMetablockContext metablock()
std::vector< size_t > string
void mb2_reduce_to_6_start()
DebugMetablockContext(std::ostream &o, bool p_en, bool p_ea, size_t alphabet_size)
DebugRoundContext round()
void mb2_reduce_to_6_step(const T &buf)
DebugContextBase(const DebugContextBase &other)
void generate_grammar(bool empty, size_t root_node)
std::vector< size_t > mb2_high_landmarks
DebugContextBase(DebugContextBase< U > &parent)
std::vector< size_t > metablock
void init(size_t type, const T &string, size_t offset)
std::vector< size_t > mb2_initial
std::vector< DebugMetablockContext > metablocks
DebugRoundContext(DebugContextBase< U > &parent)
std::vector< TypedBlock > adjusted_blocks
void mb2_initial(const T &buf)
std::vector< TypedBlock > unadjusted_blocks
void slice_symbol_map_start()
void encode_rule(const T &rule)