8 #include <boost/heap/pairing_heap.hpp> 27 Meta m(
"lcpcomp_comp",
"bheap",
"boost heaps");
37 template<
typename text_t>
45 auto& sa = text.require_sa();
46 auto& isa = text.require_isa();
49 auto lcp = text.release_lcp();
52 using lcp_t = decltype(lcp);
53 using sa_t = decltype(sa);
56 LCPCompare(lcp_t& lcp_, sa_t& sa_) : m_lcp(lcp_), m_sa(sa_) {}
58 bool operator()(
const len_t i,
const len_t j)
const {
59 if(m_lcp[i] == m_lcp[j])
return m_sa[i] > m_sa[j];
60 return m_lcp[i] < m_lcp[j];
65 LCPCompare comp(lcp,sa);
69 boost::heap::pairing_heap<len_compact_t,boost::heap::compare<LCPCompare>> heap(comp);
70 std::vector<typename decltype(heap)::handle_type> handles(lcp.size());
72 handles[0].node_ =
nullptr;
73 for(
size_t i = 1; i < lcp.size(); ++i) {
74 if(lcp[i] >= threshold) handles[i] = heap.emplace(i);
75 else handles[i].node_ =
nullptr;
79 phase.
split(
"Process MaxLCPHeap");
81 while(heap.size() > 0) {
86 const len_t fpos = sa[m];
87 const len_t fsrc = sa[m-1];
88 const len_t flen = lcp[m];
93 for(
size_t k = 0; k < flen; k++) {
95 if(handles[pos].node_ ==
nullptr)
continue;
96 heap.erase(handles[pos]);
97 handles[
pos].node_ =
nullptr;
101 for(
size_t k = 0; k < flen && fpos > k; k++) {
102 size_t s = fpos - k - 1;
104 if(handles[i].node_ !=
nullptr) {
105 if(s + lcp[i] > fpos) {
109 heap.decrease(handles[i]);
111 heap.erase(handles[i]);
112 handles[i].node_ =
nullptr;
Contains the text compression and encoding framework.
Implements the original "Max LCP" selection strategy for LCPComp.
void factorize(text_t &text, const size_t threshold, lzss::FactorBuffer &factors)
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.
Algorithm(Algorithm const &)=default
static ds::dsflags_t textds_flags()
uint32_t len_compact_t
Type to represent an bit-compact length value.
fast_t< len_compact_t > len_t
Type to represent an length value.
void emplace_back(len_t fpos, len_t fsrc, len_t flen)
static auto wrap(const char *title, F func) -> typename std::result_of< F(StatPhase &)>::type
Executes a lambda as a single statistics phase.
Interface for algorithms.