tudocomp
– The TU Dortmund Compression Framework
PhiFromSA.hpp
Go to the documentation of this file.
1 #pragma once
2 
6 
8 
9 namespace tdc {
10 
12 class PhiFromSA: public Algorithm, public ArrayDS {
13 public:
14  inline static Meta meta() {
15  Meta m("phi", "from_sa");
16  return m;
17  }
18 
20  return ds::InputRestrictions {};
21  }
22 
23  template<typename textds_t>
24  inline PhiFromSA(Env&& env, textds_t& t, CompressMode cm)
25  : Algorithm(std::move(env)) {
26 
27  // Construct Suffix Array
28  auto& sa = t.require_sa(cm);
29 
30  const size_t n = t.size();
31  const size_t w = bits_for(n);
32 
33  StatPhase::wrap("Construct Phi Array", [&]{
34  // Construct Phi Array
36 
37  for(len_t i = 1, prev = sa[0]; i < n; i++) {
38  (*this)[sa[i]] = prev;
39  prev = sa[i];
40  }
41  (*this)[sa[0]] = sa[n-1];
42 
43  StatPhase::log("bit_width", size_t(width()));
44  StatPhase::log("size", bit_size() / 8);
45  });
46 
47  if(cm == CompressMode::delayed) compress();
48  }
49 
50  void compress() {
51  debug_check_array_is_initialized();
52 
53  StatPhase::wrap("Compress Phi Array", [this]{
54  width(bits_for(size()));
55  shrink_to_fit();
56 
57  StatPhase::log("bit_width", size_t(width()));
58  StatPhase::log("size", bit_size() / 8);
59  });
60  }
61 };
62 
63 } //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
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).
static ds::InputRestrictions restrictions()
Definition: PhiFromSA.hpp:19
Describes a set of restrictions placed on input data.
void compress()
Definition: PhiFromSA.hpp:50
PhiFromSA(Env &&env, textds_t &t, CompressMode cm)
Definition: PhiFromSA.hpp:24
Base for data structures that use an integer array as a storage.
Definition: ArrayDS.hpp:9
static Meta meta()
Definition: PhiFromSA.hpp:14
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
Constructs the Phi array using the suffix array.
Definition: PhiFromSA.hpp:12
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
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.
size_type size() const
Definition: IntVector.hpp:284
Interface for algorithms.
Definition: Algorithm.hpp:15