tudocomp
– The TU Dortmund Compression Framework
PLCPFromPhi.hpp
Go to the documentation of this file.
1 #pragma once
2 
6 
8 
9 namespace tdc {
10 
12 class PLCPFromPhi: public Algorithm, public ArrayDS {
13 private:
14  len_t m_max;
15 
16 public:
17  inline static Meta meta() {
18  Meta m("plcp", "from_phi");
19  return m;
20  }
21 
23  return ds::InputRestrictions {};
24  }
25 
26  template<typename textds_t>
27  inline PLCPFromPhi(Env&& env, textds_t& t, CompressMode cm)
28  : Algorithm(std::move(env)) {
29 
30  const size_t n = t.size();
31 
32  // Construct Phi and attempt to work in-place
33  set_array(t.inplace_phi(cm));
34 
35  StatPhase::wrap("Construct PLCP Array", [&]{
36  // Use Phi algorithm to compute PLCP array
37  m_max = 0;
38  for(len_t i = 0, l = 0; i < n - 1; ++i) {
39  const len_t phii = (*this)[i];
40  while(t[i+l] == t[phii+l]) ++l;
41  m_max = std::max(m_max, l);
42  (*this)[i] = l;
43  if(l) --l;
44  }
45 
46  StatPhase::log("bit_width", size_t(width()));
47  StatPhase::log("size", bit_size() / 8);
48  });
49 
51  compress();
52  }
53  }
54 
55  inline len_t max_lcp() const {
56  return m_max;
57  }
58 
59  void compress() {
60  debug_check_array_is_initialized();
61 
62  StatPhase::wrap("Compress PLCP Array", [this]{
63  width(bits_for(m_max));
64  shrink_to_fit();
65 
66  StatPhase::log("bit_width", size_t(width()));
67  StatPhase::log("size", bit_size() / 8);
68  });
69  }
70 };
71 
72 } //ns
Contains the text compression and encoding framework.
Definition: namespaces.hpp:11
constexpr uint_fast8_t bits_for(size_t n)
Computes the number of bits required to store the given integer value.
Provides meta information about an Algorithm.
Definition: Meta.hpp:34
Data structures are constructed directly in bit-compressed space (slower construction, but smaller memory usage).
len_t max_lcp() const
Definition: PLCPFromPhi.hpp:55
PLCPFromPhi(Env &&env, textds_t &t, CompressMode cm)
Definition: PLCPFromPhi.hpp:27
Describes a set of restrictions placed on input data.
Constructs the PLCP array using the phi array.
Definition: PLCPFromPhi.hpp:12
static Meta meta()
Definition: PLCPFromPhi.hpp:17
Base for data structures that use an integer array as a storage.
Definition: ArrayDS.hpp:9
CompressMode
Defines when data structures are bit-compressed.
Definition: CompressMode.hpp:6
Env & env()
Provides access to the environment that the algorithm works in.
Definition: Algorithm.hpp:51
fast_t< len_compact_t > len_t
Type to represent an length value.
Definition: def.hpp:114
void set_array(iv_t &&iv)
Definition: ArrayDS.hpp:26
static void log(const char *key, const T &value)
Logs a user statistic for the current phase.
Definition: StatPhase.hpp:218
static ds::InputRestrictions restrictions()
Definition: PLCPFromPhi.hpp:22
uint64_t bit_size() const
Definition: IntVector.hpp:288
static auto wrap(const char *title, F func) -> typename std::result_of< F(StatPhase &)>::type
Executes a lambda as a single statistics phase.
Definition: StatPhase.hpp:143
Data structures are bit-compressed after they have been constructed (fast construction, but possibly high memory peak).
Local environment for a compression/encoding/decompression call.
Interface for algorithms.
Definition: Algorithm.hpp:15