-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathk2bp_compr.cpp
62 lines (44 loc) · 1.47 KB
/
k2bp_compr.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
// std includes
#include <iostream>
// local includes
#include "k2tree_bp_sdsl.hpp"
#include "k2tree_bp_sdsl_idems.hpp"
int main(int argc, char** argv) {
if(argc <= 1) {
std::cerr << "At least one arguments:" << endl;
std::cerr << " ./k2bp_build.x <path file matrix>" << endl;
exit(1);
}
for(uint64_t i = 1; i < argc; i+=1) {
cerr << "Getting parameters..." << endl;
std::string k2_path = argv[i];
ifstream k2_file;
k2_file.open(k2_path);
if(!k2_file.is_open()) {
cerr << "Error opening file. Check if the file exists or the path is writed correctly" << endl;
exit(1);
}
cerr << "Reading k2tree..." << endl;
k2tree_bp_sdsl<2, rrr_vector<127>> k2tree;
k2tree.load(k2_file);
k2_file.close();
cerr << "Getting ones k2tree..." << endl;
auto ones = k2tree.get_pos_ones();
cerr << "Compressing k2tree..." << endl;
k2tree_bp_sdsl_idems<2, rrr_vector<127>,
sd_vector<>, rank_support_sd<1>,
sd_vector<>, rank_support_sd<1>, rank_support_sd<0>,
select_support_sd<1>, select_support_sd<0>> k2tree_idem(k2tree);
cerr << "Checking if it is correct..." << endl;
auto check = k2tree_idem.get_pos_ones();
sort(check.begin(), check.end());
sort(ones.begin(), ones.end());
assert(check == ones);
cerr << "Writing file..." << endl;
ofstream k2_file_idem;
k2_file_idem.open(k2_path + "i");
k2tree_idem.write(k2_file_idem);
k2_file_idem.close();
}
return 0;
}