4 #include <sdsl/int_vector.hpp> 5 #include <sdsl/rank_support.hpp> 28 const sdsl::bit_vector m_bv;
29 const sdsl::bit_vector::rank_1_type m_rank;
30 const len_t m_empty_entries;
33 IF_STATS(
len_t m_longest_chain = 0);
34 IF_STATS(
len_t m_current_chain = 0);
40 , m_bv ( [&buffer] () -> sdsl::bit_vector {
41 sdsl::bit_vector bv { buffer.size(),0 };
42 for(
len_t i = 0; i < buffer.size(); ++i) {
43 if(buffer[i])
continue;
50 , m_empty_entries {
static_cast<len_t>(std::count_if(buffer.cbegin(), buffer.cend(), [] (
const uliteral_t& i) {
return i == 0; })) }
53 std::fill(m_fwd,m_fwd+m_empty_entries,
nullptr);
58 return m_rank.rank(i+1);
61 void decode(
const std::vector<len_compact_t>& m_target_pos,
const std::vector<len_compact_t>& m_source_pos,
const std::vector<len_compact_t>& m_length) {
63 const len_t factors = m_source_pos.size();
66 for(
len_t j = 0; j < factors; ++j) {
70 for(
len_t i = 0; i < factor_length; ++i) {
71 if(m_buffer[source_position+i]) {
74 DCHECK_EQ(m_bv[source_position+i],1);
76 if(bucket ==
nullptr) {
79 bucket[1] = target_position+i;
85 bucket[bucket[0]-1] = target_position+i;
92 if((j+1) % ((factors+5)/5) == 0 ) {
94 std::string(
"Decoding Factors at position ")
101 IF_STATS(++m_current_chain);
102 IF_STATS(m_longest_chain = std::max(m_longest_chain, m_current_chain));
104 DCHECK(m_buffer[pos] == 0 || m_buffer[pos] == c) <<
"would write " << c <<
" to mbuffer[" << pos <<
"] = " << m_buffer[
pos];
106 DCHECK(c != 0 || pos == m_buffer.size()-1);
110 DCHECK_LE(rankpos, m_empty_entries);
111 if(m_fwd[rankpos] !=
nullptr) {
113 for(
size_t i = 1; i < bucket[0]; ++i) {
116 delete [] m_fwd[rankpos];
117 m_fwd[rankpos] =
nullptr;
121 IF_STATS(--m_current_chain);
125 inline len_t longest_chain()
const {
126 return m_longest_chain;
130 DCHECK(m_fwd !=
nullptr);
131 for(
size_t i = 0; i < m_empty_entries; ++i) {
132 if(m_fwd[i] ==
nullptr)
continue;
149 Meta m(
"lcpcomp_dec",
"scan");
157 size_t lazy = m_scans;
168 decoder->
decode(m_target_pos, m_source_pos, m_length);
169 IF_STATS(m_longest_chain = decoder->longest_chain());
177 inline void decode_lazy_() {
178 const len_t factors = m_source_pos.size();
179 for(
len_t j = 0; j < factors; ++j) {
183 for(
len_t i = 0; i < factor_length; ++i) {
185 m_buffer[target_position+i] = m_buffer[source_position+i];
189 const size_t m_scans;
196 std::vector<len_compact_t> m_target_pos;
197 std::vector<len_compact_t> m_source_pos;
198 std::vector<len_compact_t> m_length;
205 , m_scans(
std::move(other.m_scans))
206 , m_cursor(
std::move(other.m_cursor))
207 , m_buffer(
std::move(other.m_buffer))
212 , m_scans(this->env().option(
"scans").as_integer())
218 m_buffer[m_cursor++] = c;
219 DCHECK(c != 0 || m_cursor == m_buffer.
size());
223 bool factor_stored =
false;
224 for(
len_t i = 0; i < factor_length; ++i) {
225 const len_t src_pos = source_position+i;
226 if(m_buffer[src_pos]) {
227 m_buffer[m_cursor] = m_buffer[src_pos];
229 else if(factor_stored ==
false) {
230 factor_stored =
true;
232 m_source_pos.push_back(src_pos);
233 m_length.push_back(factor_length-i);
240 inline len_t longest_chain()
const {
241 return m_longest_chain;
244 inline void write_to(std::ostream& out)
const {
245 for(
auto c : m_buffer) out << c;
Contains the text compression and encoding framework.
A vector over arbitrary unsigned integer types.
uint8_t uliteral_t
Type to represent signed single literals.
void push_back(const value_type &val)
std::string to_string(tdc::uint_impl_t< N > value)
void decode_factor(const len_t source_position, const len_t factor_length)
Provides access to runtime and memory measurement in statistics phases.
void split(const char *new_title)
Starts a new phase as a sibling, reusing the same object.
EagerScanDec(Env &env, IntVector< uliteral_t > &buffer)
Runs a number of scans of the factors.
void decode_literal(uliteral_t c)
IF_STATS(inline len_t longest_chain() const { return m_longest_chain;}) ~EagerScanDec()
uint32_t len_compact_t
Type to represent an bit-compact length value.
len_t rank(len_t i) const
fast_t< len_compact_t > len_t
Type to represent an length value.
#define IF_STATS(x)
x is compiled only when the STATS_DISABLED macro is undefined.
void decode(const std::vector< len_compact_t > &m_target_pos, const std::vector< len_compact_t > &m_source_pos, const std::vector< len_compact_t > &m_length)
void log_stat(const char *key, const T &value)
Logs a user statistic for this phase.
static void log(const char *key, const T &value)
Logs a user statistic for the current phase.
static auto wrap(const char *title, F func) -> typename std::result_of< F(StatPhase &)>::type
Executes a lambda as a single statistics phase.
void decode_literal_at(len_t pos, uliteral_t c)
Local environment for a compression/encoding/decompression call.
Interface for algorithms.
ScanDec(Env &&env, len_t size)