3 #include <sdsl/suffix_trees.hpp> 4 #include <glog/logging.h> 23 const cst_t::node_type
root;
31 , internal_nodes(m_bp_rank1.rank(m_bp_rank1.size()) - cst.bp_rank_10.rank(m_bp_rank1.size()))
35 cst_t::node_type
parent(
const cst_t::node_type& node)
const {
36 return cst.parent(node);
43 cst_t::node_type
level_anc(
const cst_t::node_type& node,
size_t depth)
const {
44 VLOG(2) <<
"LevelAnc of node " << node <<
" on depth " << depth <<
" is " << cst.bp_support.level_anc(node, cst.node_depth(node)-depth) << std::endl;
45 return cst.bp_support.level_anc(node, cst.node_depth(node)-depth);
53 cst_t::node_type
select_leaf(
const cst_t::size_type& i)
const {
54 return cst.select_leaf(i+1);
62 return cst.select_leaf(cst.csa.isa[0]+1);
67 cst_t::node_type
next_leaf(
const cst_t::node_type& node)
const {
68 VLOG(2) <<
"Next Leaf " << node <<
"-> " << cst.select_leaf(cst.csa.psi[leafrank(node)]+1) << std::endl;
69 return cst.select_leaf(cst.csa.psi[leafrank(node)]+1);
74 cst_t::node_type
next_mth_leaf(
const cst_t::node_type& node, cst_t::size_type m)
const {
75 cst_t::size_type val = leafrank(node);
77 val = cst.csa.psi[val];
80 VLOG(2) <<
"Next " << m <<
"-th Leaf " << node <<
"-> " << cst.select_leaf(m+1) << std::endl;
81 return cst.select_leaf(val+1);
86 cst_t::size_type
leafrank(
const cst_t::node_type& node)
const{
87 VLOG(2) <<
"Leafrank " << node <<
"-> " << cst.bp_rank_10.rank(node) << std::endl;
88 return cst.bp_rank_10.rank(node);
94 cst_t::size_type
str_depth(
const cst_t::node_type& node)
const{
95 return cst.depth(node);
101 cst_t::size_type
nid(
const cst_t::node_type& node)
const{
102 assert(!cst.is_leaf(node));
103 VLOG(2) <<
"NID of node " << node <<
" is " << m_bp_rank1.rank(node) - cst.bp_rank_10.rank(node) << std::endl;
104 return m_bp_rank1.rank(node)- cst.bp_rank_10.rank(node);
111 return cst.size(node);
117 sdsl::util::set_to_value(bv, 0);
121 typedef sdsl::bp_support_sada<> bp_support;
122 using cst_t = cst_sada<>;
123 const bp_support& m_bp;
125 sdsl::rrr_vector<> m_rc_rrrv;
126 sdsl::rrr_vector<>::rank_1_type m_rc_rank;
127 typedef bp_support::size_type size_type;
130 inline static bool is_root(size_type v)
137 const size_t m_size = bp.size();
138 sdsl::bit_vector root_children(m_size);
141 while(rc < m_size - 1) {
142 root_children[rc] = 1;
143 rc = bp.find_close(rc) + 1;
145 m_rc_rrrv = sdsl::rrr_vector<>(root_children);
146 m_rc_rank = sdsl::rrr_vector<>::rank_1_type(&m_rc_rrrv);
154 size_type
rank(size_type i)
const {
156 DCHECK(is_root(m_bp.level_anc(i, 1)));
166 VLOG(2) <<
"child: " << rank(st.
level_anc(node,1)) << std::endl;
167 VLOG(2) <<
"Edge: " << (int) st.
cst.csa.comp2char[rank(st.
level_anc(node,1))] << std::endl;
170 return st.
cst.csa.comp2char[rank(st.
level_anc(node,1))];
177 if(ST.
cst.is_leaf(node)) {
178 return (ST.
cst.size() <= 1) ? 0 : (ST.
cst.size()-ST.
cst.sn(node));
180 auto la = ST.
cst.leftmost_leaf(ST.
cst.select_child(node, 1));
181 auto lb = ST.
cst.leftmost_leaf(ST.
cst.select_child(node, 2));
183 while(head(ST,la) == head(ST,lb)) {
188 DCHECK_EQ(m, ST.
cst.depth(node));
189 VLOG(2) <<
"Depth of " << node <<
" is " << m << std::endl;
char head(const SuffixTree &st, const cst_t::node_type &node) const
Returns the first character of the string on the path from the root to the node.
cst_t::size_type nid(const cst_t::node_type &node) const
Contains the text compression and encoding framework.
const cst_t::node_type root
sdsl suffix tree
void reset_bitvector(bit_vector &bv)
cst_t::size_type str_depth(const SuffixTree &ST, const cst_t::node_type &node) const
const rank_support_v5< 1 > m_bp_rank1
the root node of the suffix tree
SuffixTree(const cst_t &_cst)
number of internal nodes
cst_t::node_type select_leaf(const cst_t::size_type &i) const
Select the i-th leaf in SA-order 0 <= i < n.
cst_t::size_type leafrank(const cst_t::node_type &node) const
cst_t::node_type level_anc(const cst_t::node_type &node, size_t depth) const
Returns the level ancestor of node.
cst_t::node_type smallest_leaf() const
Return the leaf corresponding to the suffix starting at position 0, i.e., the leaf with the longest s...
cst_t::node_type next_leaf(const cst_t::node_type &node) const
cst_t::size_type str_depth(const cst_t::node_type &node) const
cst_t::node_type node_type
cst_t::node_type next_mth_leaf(const cst_t::node_type &node, cst_t::size_type m) const
const size_t internal_nodes
rank the one bits in the BP
root_childrank_support(const bp_support &bp)
cst_t::size_type number_of_leaves(const cst_t::node_type &node) const
Returns the number of leaves contained in the subtree rooted at 'node'.
This is a wrapper class around the sdsl-lite library to get a easier translation between the pseudoco...
size_type rank(size_type i) const
Returns how many preceding silbings node has.
cst_t::node_type parent(const cst_t::node_type &node) const