-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathwrapper_test.cpp
151 lines (122 loc) · 4.07 KB
/
wrapper_test.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
#include <iterator>
#include <iostream>
#include <type_traits>
#include <vector>
#include <boost/iterator/iterator_facade.hpp>
#include <alphabet.hpp>
#include <dumper.hpp>
#include <get_matchings.hpp>
#include <api.hpp>
#include <parse_rlzap.hpp>
namespace rlz {
namespace detail {
template <typename T>
using SignedType = typename std::make_signed<typename std::remove_reference<T>::type>::type;
}
template <
typename RandomIt,
typename Value = detail::SignedType<decltype(*RandomIt{})>
>
class differential_iterator : public boost::iterator_facade<
differential_iterator<RandomIt>,
Value const,
boost::forward_traversal_tag,
Value const
>
{
Value previous;
RandomIt it;
friend class boost::iterator_core_access;
public:
differential_iterator(RandomIt it) : previous(Value{}), it(it) { }
void increment()
{
previous = *it;
std::advance(it, 1);
}
bool equal(differential_iterator<RandomIt, Value> const& other) const
{
return this->it == other.it;
}
Value dereference() const
{
return *it - previous;
}
};
class wrapped_index {
private:
public:
wrapped_index() { }
};
template <typename RefIt, typename InputIt>
wrapped_index get_index(RefIt ref_beg, RefIt ref_end, InputIt input_beg, InputIt input_end)
{
// Step 1: parsing + index
using SignedAlphabet = rlz::alphabet::dlcp_32;
using UnsignedAlphabet = rlz::alphabet::lcp_32;
using T = typename SignedAlphabet::Symbol;
using DiffIt = differential_iterator<RefIt, T>;
rlz::utils::iterator_dumper<DiffIt> ref_dumper{DiffIt(ref_beg), DiffIt(ref_end)},
input_dumper{DiffIt(input_beg), DiffIt(input_end)};
auto matches = std::get<0>(
rlz::get_relative_matches<SignedAlphabet>(ref_dumper, input_dumper)
);
std::cout << "Ref: ";
for (auto it = ref_beg; it != ref_end; ++it) {
std::cout << std::setw(3) << *it << " ";
}
std::cout << "\n-----" << std::endl;
std::cout << "Dif: ";
for (auto it = DiffIt(ref_beg); it != DiffIt(ref_end); ++it) {
std::cout << std::setw(3) << *it << " ";
}
std::cout << "\n=====" << std::endl;
std::cout << "Inp: ";
for (auto it = input_beg; it != input_end; ++it) {
std::cout << std::setw(3) << *it << " ";
}
std::cout << "\n-----" << std::endl;
std::cout << "Dif: ";
for (auto it = DiffIt(input_beg); it != DiffIt(input_end); ++it) {
std::cout << std::setw(3) << *it << " ";
}
std::cout << "\n=====" << std::endl;
auto pos = 0UL;
for (const auto &m : matches) {
std::cout << pos++ << " <- " << m.ptr << " @ " << m.len << std::endl;
}
// Get index builder. Prerequisites: source (reference) container.
using SourceContainer = rlz::iterator_container<UnsignedAlphabet, RefIt>;
using Index = rlz::index<UnsignedAlphabet, SourceContainer>;
using IndexBuilder = typename Index::template builder<RefIt>;
using PK = rlz::impl::Bind<rlz::api::ParseKeeper<>, UnsignedAlphabet>;
using LK = rlz::impl::Bind<rlz::api::LiteralKeeper<>, UnsignedAlphabet>;
const size_t delta_pointer_size = 4UL;
const size_t abs_pointer_size = 32UL;
const size_t symbol_length = 32UL;
SourceContainer reference{ref_beg, ref_end};
rlz::parser_rlzap parser{delta_pointer_size, abs_pointer_size, symbol_length};
auto index = rlz::impl::construct<UnsignedAlphabet, PK, LK>(
input_beg,
reference,
parser,
matches.begin(), matches.end()
);
auto index_size = index.size();
std::cout << "Index size: " << index_size << std::endl;
for (auto i = 0U; i < index_size; ++i) {
std::cout << std::setw(3) << index(i) << " ";
}
std::cout << std::endl;
return wrapped_index{};
}
}
int main(int argc, char **argv)
{
std::vector<std::uint32_t> ref_lcps {{ 1, 5, 3, 0, 7, 2 }};
std::vector<std::uint32_t> input_lcps {{ 1, 5, 8, 6, 13, 8 }};
auto W = rlz::get_index(
ref_lcps.begin(), ref_lcps.end(),
input_lcps.begin(), input_lcps.end()
);
}