-
Notifications
You must be signed in to change notification settings - Fork 3
/
vlg_matching.cpp
62 lines (54 loc) · 1.87 KB
/
vlg_matching.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
#include <sdsl/vlg_index.hpp>
using namespace sdsl;
using namespace std;
template<typename index>
void dump_query_results(index idx, string qry)
{
cout << endl;
cout << "count(" << qry << ")=" << count(idx, qry) << endl;
cout << "locate(" << qry << ")=" << endl;
auto res = locate(idx, qry);
size_t occ = 1;
for (auto it = res.begin(); it != res.end(); ++it, ++occ) {
auto pos = *it;
cout << " " << occ << ". occ starting at position " << pos << endl;
cout << " Subpattern positions:";
for (size_t i=0; i<it.size(); ++i) {
cout << " " << it[i];
}
cout << endl;
}
}
int main(int argc, char* argv[])
{
// index with byte alphabet (default)
{
vlg_index<> idx;
if (argc <= 1) {
construct_im(idx, "abracadabrasimsalabim", 1);
} else {
string filename(argv[1]);
construct(idx, filename, 1);
ofstream out(filename + ".info.html");
write_structure<HTML_FORMAT>(idx, out);
}
dump_query_results(idx, "ac.{2,5}?a.{4,8}?b");
dump_query_results(idx, "a.{0,10}?a.{0,10}?a");
dump_query_results(idx, "foo.{0,10}?bar");
}
// index with int alphabet
{
vlg_index<int_alphabet_tag> idx;
if (argc <= 1) {
construct_im(idx, int_vector<>({97, 98, 114, 97, 99, 97, 100, 97, 98, 114, 97, 115, 105, 109, 115, 97, 108, 97, 98, 105, 109}));
} else {
string filename(argv[1]);
construct(idx, filename, 0);
ofstream out(filename + ".info.html");
write_structure<HTML_FORMAT>(idx, out);
}
dump_query_results(idx, "97 99 .{2,5}? 97 .{4,8}? 98");
dump_query_results(idx, "97 .{0,10}? 97 .{0,10}? 97");
dump_query_results(idx, "1337 .{0,10}? 42");
}
}