7 namespace tdc {
namespace esp {
11 Meta m(
"subseq",
"optimal");
17 template<
typename SortedIndices>
25 Meta m(
"subseq",
"greedy");
31 template<
typename SortedIndices>
34 ret.
Dpi.reserve(sis.size());
35 ret.
Dpi.resize(sis.size(), 999);
37 size_t Dpi_counter = 0;
39 DCHECK_GE(sis.size(), 1);
40 std::vector<std::pair<size_t, size_t>> free_list;
41 free_list.reserve(sis.size() + 2);
42 free_list.resize(sis.size() + 2);
43 for (
size_t i = 1; i < (free_list.size() - 3); i++) {
44 free_list[i].first = i - 1;
45 free_list[i].second = i + 1;
47 const size_t start_dummy_link = free_list.size() - 2;
48 const size_t end_dummy_link = free_list.size() - 1;
50 if ((free_list.size() - 2) > 1) {
51 free_list[0].first = start_dummy_link;
52 free_list[0].second = 1;
53 free_list[free_list.size() - 3].first = free_list.size() - 4;
54 free_list[free_list.size() - 3].second = end_dummy_link;
56 free_list[0].first = start_dummy_link;
57 free_list[0].second = end_dummy_link;
60 free_list[start_dummy_link].first = start_dummy_link;
61 free_list[end_dummy_link].second = end_dummy_link;
63 free_list[start_dummy_link].second = 0;
64 free_list[end_dummy_link].first = free_list.size() - 3;
66 std::vector<size_t> increasing;
67 std::vector<size_t> decreasing;
71 auto si_of = [&](
size_t link) {
72 DCHECK(link != start_dummy_link);
73 DCHECK(link != end_dummy_link);
77 auto remove = [&](
size_t link) {
78 DCHECK(link != start_dummy_link);
79 DCHECK(link != end_dummy_link);
80 auto prev = free_list[link].first;
81 auto next = free_list[link].second;
83 free_list[prev].second = next;
84 free_list[next].first = prev;
86 free_list[link].first = link;
87 free_list[link].second = link;
90 auto handle = [&](
const std::vector<size_t>& seq) {
91 for (
auto link : seq) {
92 DCHECK(link != start_dummy_link);
93 DCHECK(link != end_dummy_link);
94 ret.
Dpi[link] = Dpi_counter;
97 for (
auto link : seq) {
104 while (free_list[start_dummy_link].second != end_dummy_link) {
106 size_t cstart = free_list[start_dummy_link].second;
108 increasing.push_back(cstart);
112 if (free_list[cstart].second == end_dummy_link) {
117 cstart = free_list[cstart].second;
121 DCHECK(si_of(cstart) != si_of(increasing.back()));
122 if (si_of(cstart) > si_of(increasing.back())) {
123 increasing.push_back(cstart);
128 size_t cend = free_list[end_dummy_link].first;
130 decreasing.push_back(cend);
133 if (free_list[cend].first == start_dummy_link) {
137 cend = free_list[cend].first;
140 DCHECK(si_of(cend) != si_of(decreasing.back()));
141 if (si_of(cend) > si_of(decreasing.back())) {
142 decreasing.push_back(cend);
146 std::reverse(decreasing.begin(), decreasing.end());
152 if (increasing.size() >= decreasing.size()) {
Contains the text compression and encoding framework.
std::vector< Sindex > sorted_indices(const View &input)
Dpi_and_b create_dpi_and_b_from_sorted_indices(const SortedIndices &sorted_indices) const
void push_back(const value_type &val)
std::vector< size_t > Dpi
Algorithm(Algorithm const &)=default
typename uint_dispatch_t< N >::type uint_t
IntVector< uint_t< 1 > > b
Dpi_and_b create_dpi_and_b_from_sorted_indices(const SortedIndices &sis) const
Interface for algorithms.
Dpi_and_b create_dpi_and_b_from_sorted_indices(const SortedIndices &sorted_indices)