6 #include <sdsl/select_support_mcl.hpp> 18 template<
class phi_t,
class sa_t>
20 const len_t n = sa.size();
24 for(
size_t i = 1, prev = sa[0]; i < n; i++) {
39 template<
typename phi_t,
typename text_t>
41 const size_t n = phi.size();
42 DCHECK_EQ(text[n-1],0);
43 for(
len_t i = 0, l = 0; i < n - 1; ++i) {
44 const len_t phii = phi[i];
48 while(text[i+l] == text[phii+l]) {
65 typename select_t = sdsl::select_support_mcl<1,1>>
68 const sdsl::bit_vector m_bv;
69 const select_t m_select;
71 LCPSada(
const sa_t& sa,
const sdsl::bit_vector&& bv)
78 if(
size() == 1)
return 0;
79 const len_t idx = m_sa[i];
80 return m_select.select(idx+1) - 2*idx;
83 if(
size() == 1)
return 0;
84 return m_select.select(idx+1) - 2*idx;
116 sdsl::bit_vector m_bv;
120 len_t m_blockrank = 0;
128 DCHECK_GE(m_bv.size(), 1);
130 DCHECK_LT(m_idx+1, m_bv.size());
131 const len_t chunk_size = 1 + ((m_bv.size()-1)/64);
132 const uint64_t*
const data = m_bv.data();
133 while(m_block < chunk_size) {
134 const uint_fast8_t ones = sdsl::bits::cnt(data[m_block]);
135 if(m_blockrank+ones >= m_idx+1)
break;
139 if(m_block == chunk_size)
return m_bv.size();
140 return 64*m_block + sdsl::bits::sel(data[m_block], m_idx+1-m_blockrank);
144 const len_t ret = next_select() - 2*m_idx;
152 template<
class plcp_t>
153 inline static sdsl::bit_vector construct_plcp_bitvector(
const plcp_t&
plcp) {
154 const len_t n = plcp.size();
156 for(
len_t i = 0; i+1 < n; i++) {
157 DCHECK_GE(plcp[i+1]+1, plcp[i]);
158 len += plcp[i+1]-plcp[i]+1;
160 sdsl::bit_vector bv(len+n,0);
163 for(
len_t i = 0; i+1 < n; i++) {
164 len += plcp[i+1]-plcp[i]+2;
165 DCHECK_LT(len, bv.size());
168 DCHECK_EQ(len, bv.size()-1);
169 DCHECK_EQ(plcp.size(), std::accumulate(bv.begin(), bv.end(), 0));
173 template<
class sa_t,
class text_t,
class select_t = sdsl::select_support_mcl<1,1>>
174 sdsl::bit_vector construct_plcp_bitvector(
Env&,
const sa_t& sa,
const text_t& text) {
178 return construct_phi_array<phi_t,sa_t>(sa);
186 auto ret = construct_plcp_bitvector(phi);
192 template<
class sa_t,
class text_t,
class select_t = sdsl::select_support_mcl<1,1>>
195 sdsl::bit_vector bv = construct_plcp_bitvector(env, sa, text);
Contains the text compression and encoding framework.
constexpr uint_fast8_t bits_for(size_t n)
Computes the number of bits required to store the given integer value.
phi_t construct_phi_array(const sa_t &sa)
Constructs the phi array with phi[sa[i]] = sa[i-1].
LCPSada< sa_t, select_t > construct_lcp_sada(Env &env, const sa_t &sa, const text_t &text)
A vector over arbitrary unsigned integer types.
void phi_algorithm(phi_t &phi, const text_t &text)
Constructs the PLCP array.
len_t operator[](len_t i) const
len_t plcp(len_t idx) const
fast_t< len_compact_t > len_t
Type to represent an length value.
static void log(const char *key, const T &value)
Logs a user statistic for the current phase.
LCPSada(const sa_t &sa, const sdsl::bit_vector &&bv)
static auto wrap(const char *title, F func) -> typename std::result_of< F(StatPhase &)>::type
Executes a lambda as a single statistics phase.
Local environment for a compression/encoding/decompression call.
LCPForwardIterator(sdsl::bit_vector &&bv)