forked from simongog/sdsl-lite
-
Notifications
You must be signed in to change notification settings - Fork 1
/
cst-traversal.cpp
30 lines (27 loc) · 957 Bytes
/
cst-traversal.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
#include <sdsl/suffix_trees.hpp>
#include <iostream>
#include <string>
using namespace sdsl;
using namespace std;
int main(int argc, char* argv[])
{
if (argc < 3) {
cout << "Usage: " << argv[0] << " file " << "int [max_depth]" << endl;
return 1;
}
cst_sct3<> cst;
construct(cst, argv[1], 1);
uint64_t max_depth = stoull(argv[2]);
// use the DFS iterator to traverse `cst`
for (auto it=cst.begin(); it!=cst.end(); ++it) {
if (it.visit() == 1) { // node visited the first time
auto v = *it; // get the node by dereferencing the iterator
if (cst.depth(v) <= max_depth) { // if depth node is <= max_depth
// process node, e.g. output it in format d-[lb, rb]
cout<<cst.depth(v)<<"-["<<cst.lb(v)<< ","<<cst.rb(v)<<"]"<<endl;
} else { // skip the subtree otherwise
it.skip_subtree();
}
}
}
}