-
Notifications
You must be signed in to change notification settings - Fork 0
/
bp_test.cpp
50 lines (45 loc) · 1.11 KB
/
bp_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
#include <strie/bp.hpp>
#include <iostream>
#include <vector>
#include <sdsl/bit_vectors.hpp>
int main() {
std::string bv = "11110110001001110000";
std::stack<int> os;
int n = bv.size();
std::vector<int> p(n);
for (int i = 0; i < n; i++) {
if (bv[i] == '1') {
os.push(i);
} else {
p[os.top()] = i;
p[i] = os.top();
os.pop();
}
}
sdsl::bit_vector v(n);
for (int i = 0; i < n; i++) v[i] = bv[i] == '1';
sdsl::rank_support_v<> rank(&v);
strie::BpSupport<> bp(&v, &rank);
// bp.print_for_debug();
std::vector<int> fc(n);
for (int i = 0; i < n; i++) {
fc[i] = bv[i] == '1' ? bp.findclose(i) : p[i];
}
// std::cout << bv << std::endl;
// for (int i = 0; i < n; i++) {
// std::cout << p[i] << ' ';
// }
// std::cout << std::endl;
// for (int i = 0; i < n; i++) {
// std::cout << fc[i] << ' ';
// }
// std::cout << std::endl;
for (int i = 0; i < n; i++) {
if (bv[i] == '1' and fc[i] != p[i]) {
std::cout << i << ' ' << fc[i] << " != " << p[i] << std::endl;
exit(EXIT_FAILURE);
assert(false);
}
}
std::cout << "OK" << std::endl;
}