Пример #1
0
void test_cst_dfs_iterator_and_depth(Cst& cst, typename Cst::size_type times=1000000, bool output=false)
{
    if (times > 2*cst.nodes()-cst.size())
        times = 2*cst.nodes()-cst.size();
    typedef typename Cst::size_type size_type;
    size_type cnt=0;
    write_R_output("cst","dfs and depth","begin",times,cnt);
    typename Cst::const_iterator it = cst.begin();
    if (!output) {
        for (size_type i=0; i<times; ++i, ++it) {
            if (!cst.is_leaf(*it))
                cnt += cst.depth(*it);
        }
    } else {
        for (size_type i=0; i<times; ++i, ++it) {
            if (!cst.is_leaf(*it)) {
                size_type d = cst.depth(*it);
                std::cerr << d << "-[" << cst.lb(*it) << "," << cst.rb(*it) << "] ";
                if (d < 60) {
                    for (int i=1; i<=d; ++i)
                        std::cerr<< cst.edge(*it, i);
                }
                std::cerr << std::endl;
                cnt += d;
            }
        }
    }
    write_R_output("cst","dfs and depth","end",times,cnt);
}
Пример #2
0
	//! Prefix increment of the iterator.
	iterator& operator++()
	{
		if (!m_valid) return *this;
		if (m_v == m_cst->root() and m_visited) {
			m_valid = false;
			return *this;
		}
		value_type w;
		if (!m_visited) { // go down, if possible
			if (m_cst->is_leaf(m_v)) {
				w = m_cst->sibling(m_v);  // determine sibling of leaf v
				if (w == m_cst->root()) { // if there exists no right sibling of the leaf v
										  //					w = m_cst->parent(m_v);
					w		  = parent();
					m_visited = true; // go up
				}
			} else { // v is not a leaf => go down the tree
				w = first_child();
			}
		} else { //
			w = m_cst->sibling(m_v);
			if (w == m_cst->root()) { // if there exists no right sibling
				w = parent();
			} else {
				m_visited = false;
			}
		}
		m_v = w;
		return *this;
	}
Пример #3
0
void test_cst_depth_operation_for_inner_nodes(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;
    std::vector<node_type> nodes;
    {
        std::vector<node_type> nodes2;
        generate_nodes_from_random_leaves(cst, times, nodes2, x);
        for (size_type i=0; i<nodes2.size(); ++i)
            if (!cst.is_leaf(nodes2[i])) {
                nodes.push_back(nodes2[i]);
            }
    }
    size_type cnt = 0;
    write_R_output("cst","depth of inner nodes","begin",nodes.size(),cnt);
    for (size_type i=0; i < nodes.size(); ++i) {
        cnt += cst.depth(nodes[i]);
    }
    write_R_output("cst","depth of inner nodes","end",nodes.size(),cnt);
}