tudocomp
– The TU Dortmund Compression Framework
DecodeQueueListBuffer.hpp
Go to the documentation of this file.
1 #pragma once
2 
3 #include <vector>
4 #include <tudocomp/def.hpp>
5 #include <tudocomp/Algorithm.hpp>
7 
8 namespace tdc {
9 namespace lcpcomp {
10 
11 constexpr len_t undef_len = std::numeric_limits<len_compact_t>::max();
13  public:
14  inline static Meta meta() {
15  Meta m("lcpcomp_dec", "QueueListBuffer");
16  return m;
17  }
18  inline void decode_lazy() const {
19  }
20  inline void decode_eagerly() const {
21  }
22 
23 private:
24  std::vector<uliteral_t> m_buffer;
25  std::vector<std::vector<len_compact_t>> m_fwd;
26  BitVector m_decoded;
27 
28  len_t m_cursor;
29 
30  //stats:
31  len_t m_longest_chain;
32  len_t m_current_chain;
33  len_t m_max_depth;
34 
35  inline void decode_literal_at(len_t pos, uliteral_t c) {
36  ++m_current_chain;
37  m_longest_chain = std::max(m_longest_chain, m_current_chain);
38  m_max_depth = std::max<len_t>(m_max_depth, m_fwd[pos].size());
39 
40  m_buffer[pos] = c;
41  m_decoded[pos] = 1;
42 
43  for(auto fwd : m_fwd[pos]) {
44  decode_literal_at(fwd, c); // recursion
45  }
46  std::vector<len_compact_t>().swap(m_fwd[pos]); // forces vector to drop to capacity 0
47 // m_fwd[pos].clear();
48 
49  --m_current_chain;
50  }
51 
52 public:
54  : Algorithm(std::move(env)), m_cursor(0), m_longest_chain(0), m_current_chain(0), m_max_depth(0) {
55 
56  m_buffer.resize(size, 0);
57  m_fwd.resize(size, std::vector<len_compact_t>());
58  m_decoded = BitVector(size, 0);
59  }
60 
61  inline void decode_literal(uliteral_t c) {
62  decode_literal_at(m_cursor++, c);
63  }
64 
65  inline void decode_factor(len_t pos, len_t num) {
66  for(len_t i = 0; i < num; i++) {
67  len_t src = pos+i;
68  if(m_decoded[src]) {
69  decode_literal_at(m_cursor, m_buffer[src]);
70  } else {
71  m_fwd[src].push_back(m_cursor);
72  }
73 
74  ++m_cursor;
75  }
76  }
77 
78  inline len_t longest_chain() const {
79  return m_longest_chain;
80  }
81 
82  inline void write_to(std::ostream& out) {
83  for(auto c : m_buffer) out << c;
84  }
85 };
86 
87 }} //ns
88 
Contains the text compression and encoding framework.
Definition: namespaces.hpp:11
Provides meta information about an Algorithm.
Definition: Meta.hpp:34
A vector over arbitrary unsigned integer types.
Definition: IntVector.hpp:175
uint8_t uliteral_t
Type to represent signed single literals.
Definition: def.hpp:131
IntVector< uint_t< 1 > > BitVector
Represents a bit vector, alias for IntVector with a fixed bit width of 1.
Definition: IntVector.hpp:545
Env & env()
Provides access to the environment that the algorithm works in.
Definition: Algorithm.hpp:51
len_compact_t src
Definition: LZSSFactors.hpp:38
fast_t< len_compact_t > len_t
Type to represent an length value.
Definition: def.hpp:114
void swap(GenericViewBase< T, Q > &lhs, GenericViewBase< T, Q > &rhs)
len_compact_t pos
Definition: LZSSFactors.hpp:38
constexpr len_t undef_len
Local environment for a compression/encoding/decompression call.
Interface for algorithms.
Definition: Algorithm.hpp:15