Created
July 3, 2019 14:07
-
-
Save cocomoff/0170bf4b1c6a711b80d2d671fd3058e9 to your computer and use it in GitHub Desktop.
wavelet tree of integer values
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <bits/stdc++.h> | |
#include <sdsl/wavelet_trees.hpp> | |
using namespace std; | |
using namespace sdsl; | |
int main() { | |
wt_int<rrr_vector<63>> wt; | |
// auto iv = int_vector<>({0, 7, 2, 1, 4, 3, 6, 7, 2, 5, 0, 4, 7, 2, 6, 3}); | |
auto iv = int_vector<>({0, 2, 1, 3, 2, 0, 2, 3}); | |
construct_im(wt, iv); | |
cout << "wt.sigma : " << wt.sigma << endl; | |
cout << wt << endl; | |
// get occurrence | |
// size_t idx = 2; | |
// size_t idx = 15; | |
// auto r_c = wt.inverse_select(idx); | |
// cout << get<0>(r_c) + 1 << " occurrence(s) of " | |
// << get<1>(r_c) << " in [0.." << idx << "]" << endl; | |
// Standard for each traversal | |
for (auto v : wt) { cout << v << " "; } cout << endl; | |
// iterator traversal | |
for (auto it = wt.begin(); it != wt.end(); it++) { cout << (*it) << " "; } cout << endl; | |
// get left/right child in wavelet tree | |
auto rn = wt.root(); | |
auto pair = wt.expand(rn); | |
cout << "size=" << pair.size() << endl; | |
auto ln = pair[0], rgn = pair[1]; | |
// print info | |
printf("O-S-L-sym %zu %zu %zu %zu\n", rn.offset, rn.size, rn.level, rn.sym); | |
printf("O-S-L-sym %zu %zu %zu %zu\n", ln.offset, ln.size, ln.level, ln.sym); | |
printf("O-S-L-sym %zu %zu %zu %zu\n", rgn.offset, rgn.size, rgn.level, rgn.sym); | |
// path to the leaf | |
for (auto c = 0; c <= 4; c++) { | |
auto path = wt.path(c); | |
cout << path.first << " " << path.second << endl; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment