tudocomp
– The TU Dortmund Compression Framework
NaiveStrategy.hpp
Go to the documentation of this file.
1 #pragma once
2 
3 #include <vector>
4 
5 #include <tudocomp/Algorithm.hpp>
7 #include <tudocomp/ds/TextDS.hpp>
8 
10 
11 namespace tdc {
12 namespace lcpcomp {
13 
17 class NaiveStrategy : public Algorithm {
18 public:
20 
21  inline static Meta meta() {
22  Meta m("lcpcomp_comp", "naive");
23  return m;
24  }
25 
26  inline static ds::dsflags_t textds_flags() {
27  return ds::SA | ds::ISA | ds::LCP;
28  }
29 
30  template<typename text_t>
31  inline void factorize(text_t& text,
32  size_t threshold,
33  lzss::FactorBuffer& factors) {
34 
35  // Construct SA, ISA and LCP
36  text.require(text_t::SA | text_t::ISA | text_t::LCP);
37 
38  auto& sa = text.require_sa();
39  auto& isa = text.require_isa();
40  auto& lcp = text.require_lcp();
41 
42  //
43  size_t n = sa.size();
44  size_t i = 0;
45 
46  BitVector marked(n, 0);
47 
48  while(i+1 < n) { // we skip text position T[n] == 0
49  size_t s = isa[i];
50  size_t l = lcp[s];
51  if(l >= threshold) {
52  //check if any position is marked
53  bool available = true;
54  for(size_t k = 0; k < l; k++) {
55  if(marked[i + k]) {
56  available = false;
57  break;
58  }
59  }
60 
61  if(available) {
62  //introduce factor
63  size_t src = sa[s - 1];
64  factors.emplace_back(i, src, l);
65 
66  //mark source positions
67  for(size_t k = 0; k < l; k++) {
68  marked[src + k] = 1;
69  }
70 
71  i += l;
72  continue;
73  }
74  }
75 
76  ++i;
77  }
78  }
79 };
80 
81 }}
82 
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
unsigned int dsflags_t
Definition: TextDSFlags.hpp:8
constexpr dsflags_t ISA
Definition: TextDSFlags.hpp:12
static ds::dsflags_t textds_flags()
Algorithm(Algorithm const &)=default
void factorize(text_t &text, size_t threshold, lzss::FactorBuffer &factors)
A very naive selection strategy for LCPComp.
len_compact_t src
Definition: LZSSFactors.hpp:38
void emplace_back(len_t fpos, len_t fsrc, len_t flen)
Definition: LZSSFactors.hpp:41
constexpr dsflags_t SA
Definition: TextDSFlags.hpp:11
constexpr dsflags_t LCP
Definition: TextDSFlags.hpp:13
Interface for algorithms.
Definition: Algorithm.hpp:15