本文整理汇总了C++中Cst::parent方法的典型用法代码示例。如果您正苦于以下问题:C++ Cst::parent方法的具体用法?C++ Cst::parent怎么用?C++ Cst::parent使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Cst
的用法示例。
在下文中一共展示了Cst::parent方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: test_cst_parent_operation
void test_cst_parent_operation(const Cst& cst, typename Cst::size_type times=100000, uint64_t x=17)
{
typedef typename Cst::size_type size_type;
typedef typename Cst::node_type node_type;
srand(x);
size_type n = cst.csa.size();
// take \f$ time \f$ random leaves
std::vector<node_type> rand_leaf(times);
for (size_type i=0; i<rand_leaf.size(); ++i) {
rand_leaf[i] = cst.select_leaf(1+ (rand() % n));
}
node_type p;
size_type cnt=0;
write_R_output("cst","parent","begin",times,cnt);
for (size_type i=0; i<times; ++i, ++cnt) {
p = cst.parent(rand_leaf[i]);
while (p != cst.root()) {
p = cst.parent(p);
++cnt;
}
}
write_R_output("cst","parent","end",times,cnt);
}
示例2: parent
inline node_type parent() {
--m_stack_size; // decrease stack size
if (m_stack_cache != nullptr and m_stack_size < cache_size) {
return m_stack_cache[m_stack_size];
} else
return m_cst->parent(m_v);
}
示例3: test_cst_matching_statistics
void test_cst_matching_statistics(const Cst& cst, unsigned char* S2, typename Cst::size_type n2)
{
typedef typename Cst::size_type size_type;
typedef typename Cst::node_type node_type;
size_type cnt = 0;
write_R_output("cst","mstats","begin",n2,cnt);
size_type q = 0; // current match length
size_type p2 = n2-1; // position in S2
size_type i = 0, j = cst.csa.size()-1; // \f$ \epsilon \f$ matches all suffixes of S1
while (p2+1 > 0) {
size_type lb, rb;
// perform backward search on interval \f$ [i,j] \f$
size_type size = algorithm::backward_search(cst.csa, i, j, S2[p2], lb, rb);
if (size > 0) {
q = q + 1;
i = lb; j = rb;
p2 = p2 - 1;
} else if (i==0 and j == cst.csa.size()) {
p2 = p2 -1;
} else {
// map interval to a node of the cst and calculate parent
node_type p = cst.parent(cst.node(i, j));
q = cst.depth(p); // update match length
i = cst.lb(p); // update left bound
j = cst.rb(p); // update right bound
}
cnt += q;
}
write_R_output("cst","mstats","end",n2,cnt);
}
示例4:
//! Prefix increment of the iterator.
iterator& operator++()
{
if (!m_valid) return *this;
if (m_v == m_cst->root()) {
m_valid = false;
return *this;
}
value_type w = m_cst->sibling(m_v);
if (w == m_cst->root()) { // if no next right sibling exist
m_v = m_cst->parent(m_v); // go to parent
} else { // if next right sibling exist
m_v = m_cst->leftmost_leaf(w); // go to leaftmost leaf in the subtree of w
}
return *this;
}
示例5: generate_nodes_from_random_leaves
void generate_nodes_from_random_leaves(const Cst& cst, typename Cst::size_type times, std::vector<typename Cst::node_type>& nodes, uint64_t x=17)
{
typedef typename Cst::size_type size_type;
typedef typename Cst::node_type node_type;
srand(x);
size_type n = cst.csa.size();
// generate nodes
for (size_type i=0; i<times; ++i) {
node_type p = cst.select_leaf(1+ (rand() % n));
nodes.push_back(p);
while (p != cst.root()) {
p = cst.parent(p);
nodes.push_back(p);
}
}
}
示例6: test_cst_sl_operation
void test_cst_sl_operation(const Cst& cst, typename Cst::size_type times=500, uint64_t x=17)
{
typedef typename Cst::size_type size_type;
typedef typename Cst::node_type node_type;
size_type n = cst.csa.size();
if (times > n)
times = n;
std::vector<node_type> nodes(times);
srand(x);
// take \f$ times \f$ random leaves and calculate each parent
for (size_type i=0; i<times; ++i) {
nodes[i] = cst.parent(cst.select_leaf(rand()%n + 1));
}
size_type cnt=0;
times = 0;
write_R_output("cst","sl","begin",0,cnt);
for (size_type i=0; i<nodes.size(); ++i) {
node_type v = nodes[i];
// std::cout<<"v="<<cst.lb(v)<<" "<<cst.rb(v)<<std::endl;
// size_type d = cst.depth(v);
while (v != cst.root()) { // while v is not the root
++cnt;
v = cst.sl(v); // follow suffix link
// if( cnt < 30 ){
// std::cout<< cnt << " " << cst.lb(v) << " " << cst.rb(v) << " " << cst.depth(v) << std::endl;
// }
// size_type d2 = cst.depth(v);
// if( d != d2+1 ){
// std::cout<<"error at cnt "<<cnt<<" d="<<d<<" d2="<<d2<<std::endl;
// }
// d = d2;
}
}
write_R_output("cst","sl","end",cnt,cnt);
}