18 : pos(fpos), src(fsrc), len(flen) {
25 std::vector<Factor> m_factors;
28 len_t m_shortest_factor;
29 len_t m_longest_factor;
42 m_sorted = m_sorted && (m_factors.empty() || fpos >= m_factors.back().pos);
43 m_factors.emplace_back(fpos, fsrc, flen);
45 m_shortest_factor = std::min(m_shortest_factor, flen);
46 m_longest_factor = std::max(m_longest_factor, flen);
50 return m_factors.cbegin();
54 return m_factors.cend();
58 return m_factors.empty();
61 inline size_t size()
const {
62 return m_factors.size();
71 std::sort(m_factors.begin(), m_factors.end(),
72 [](
const Factor& a,
const Factor& b) ->
bool {
return a.
pos < b.pos; });
80 if(m_factors.empty())
return;
83 <<
"factors need to be sorted before they can be flattened";
86 auto& last = m_factors.back();
92 for(
size_t i = 0; i < m_factors.size(); i++) {
93 auto& f = m_factors[i];
94 for(
size_t j = 0; j < f.len; j++) {
95 fmap[f.pos + j] = i + 1;
100 size_t num_flattened = 0;
101 size_t max_depth = 0;
102 for(
auto& f : m_factors) {
106 while(src < fmap.
size() && fmap[
src]) {
107 auto& s = m_factors[fmap[
src] - 1];
109 size_t d = src - s.pos;
110 if((s.src + d + f.len) <= (s.src + s.len)) {
126 max_depth = std::max(max_depth, depth);
135 return m_shortest_factor;
139 return m_longest_factor;
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.
A vector over arbitrary unsigned integer types.
Factor(len_t fpos, len_t fsrc, len_t flen)
class tdc::lzss::FactorBuffer __attribute__
size_t shortest_factor() const
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.
size_t longest_factor() const
void emplace_back(len_t fpos, len_t fsrc, len_t flen)
const_iterator end() const
static void log(const char *key, const T &value)
Logs a user statistic for the current phase.
constexpr size_t INDEX_MAX
The maximum value of len_compact_t.
std::vector< Factor >::const_iterator const_iterator
const_iterator begin() const