Esempio n. 1
0
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);
}
Esempio n. 2
0
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);
        }
    }
}
Esempio n. 3
0
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);
}
Esempio n. 4
0
void test_cst_lca_operation(const Cst& cst, typename Cst::size_type times=1000000, uint64_t x=17)
{
    typedef typename Cst::size_type size_type;
    typedef typename Cst::node_type node_type;
    // 	generate \f$2^{19}\f$ random pairs of leafs
    size_type n = cst.csa.size();
    uint64_t mask = (1<<20)-1;
    std::vector<node_type> nodes(1<<20);
    srand(x);
    for (size_type i=0; i < nodes.size(); ++i) {
        nodes[i] = cst.select_leaf(rand()%n + 1);
    }

    size_type cnt=0;
    write_R_output("cst","lca","begin",times,cnt);
    for (size_type i=0; i<times; ++i) {
        node_type v = cst.lca(nodes[(2*i) & mask], nodes[(2*i+1) & mask]);
        if (v == cst.root())
            cnt++;
//		if(i<30)
//			std::cout<<"lca("<<cst.lb(nodes[(2*i)&mask])<<","<<cst.lb(nodes[(2*i+1)&mask])<<")=("<<cst.lb(v)<<","<<cst.rb(v)<<")"<<std::endl;
    }
    write_R_output("cst","lca","end",times,cnt);
}