tudocomp
– The TU Dortmund Compression Framework
LCPFromPLCP.hpp
Go to the documentation of this file.
1 #pragma once
2 
6 
8 
9 namespace tdc {
10 
12 class LCPFromPLCP: public Algorithm, public ArrayDS {
13 private:
14  len_t m_max;
15 
16 public:
17  inline static Meta meta() {
18  Meta m("lcp", "from_phi");
19  return m;
20  }
21 
23  return ds::InputRestrictions {};
24  }
25 
26  template<typename textds_t>
27  inline LCPFromPLCP(Env&& env, textds_t& t, CompressMode cm)
28  : Algorithm(std::move(env)) {
29 
30  // Construct Suffix Array and PLCP Array
31  auto& sa = t.require_sa(cm);
32  auto& plcp = t.require_plcp(cm);
33 
34  const size_t n = t.size();
35 
36  StatPhase::wrap("Construct LCP Array", [&]{
37  // Compute LCP array
38  m_max = plcp.max_lcp();
39  const size_t w = bits_for(m_max);
40 
42 
43  (*this)[0] = 0;
44  for(len_t i = 1; i < n; i++) {
45  const len_t x = plcp[sa[i]];
46  (*this)[i] = x;
47  }
48 
49  StatPhase::log("bit_width", size_t(width()));
50  StatPhase::log("size", bit_size() / 8);
51  });
52 
53  if(cm == CompressMode::delayed) compress();
54  }
55 
56  inline len_t max_lcp() const {
57  return m_max;
58  }
59 
60  void compress() {
61  debug_check_array_is_initialized();
62 
63  StatPhase::wrap("Compress LCP Array", [this]{
64  width(bits_for(m_max));
65  shrink_to_fit();
66 
67  StatPhase::log("bit_width", size_t(width()));
68  StatPhase::log("size", bit_size() / 8);
69  });
70  }
71 };
72 
73 } //ns
static ds::InputRestrictions restrictions()
Definition: LCPFromPLCP.hpp:22
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
DynamicIntVector iv_t
The type of integer array to use as storage.
Definition: ArrayDS.hpp:12
Data structures are constructed directly in bit-compressed space (slower construction, but smaller memory usage).
Describes a set of restrictions placed on input data.
LCPFromPLCP(Env &&env, textds_t &t, CompressMode cm)
Definition: LCPFromPLCP.hpp:27
Base for data structures that use an integer array as a storage.
Definition: ArrayDS.hpp:9
Constructs the LCP array using the Phi algorithm.
Definition: LCPFromPLCP.hpp:12
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 Meta meta()
Definition: LCPFromPLCP.hpp:17
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
constexpr size_t INDEX_FAST_BITS
The amount of bits required to store the binary representation of a value of type len_t...
Definition: def.hpp:128
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
len_t max_lcp() const
Definition: LCPFromPLCP.hpp:56