File: cst_helper.hpp

package info (click to toggle)
libsdsl 2.1.1%2Bdfsg-6
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 4,020 kB
  • sloc: cpp: 42,286; makefile: 1,171; ansic: 318; sh: 201; python: 27
file content (58 lines) | stat: -rw-r--r-- 1,513 bytes parent folder | download | duplicates (16)
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#ifndef SDSL_TEST_CST_HELPER
#define SDSL_TEST_CST_HELPER

#include <sstream>
#include <iostream>
#include "gtest/gtest.h"
#ifdef WIN32
#include "iso646.h"
#endif

template<class Cst>
std::string format_node(const Cst& cst, const typename Cst::node_type& v)
{
    std::stringstream ss;
    ss << cst.depth(v) << "-["<<cst.lb(v)<<","<<cst.rb(v)<<"]";
    return ss.str();
}

template<class tCst>
void check_node_method(const tCst& cst)
{
    typedef typename tCst::const_iterator const_iterator;
    typedef typename tCst::node_type node_type;
    typedef typename tCst::size_type size_type;
    for (const_iterator it = cst.begin(), end = cst.end(); it != end; ++it) {
        if (it.visit() == 1) {
            node_type v = *it;
            size_type lb = cst.lb(v), rb = cst.rb(v);
            ASSERT_EQ(v, cst.node(lb, rb));
        }
    }
}

template<class Cst>
typename Cst::node_type naive_lca(const Cst& cst, typename Cst::node_type v, typename Cst::node_type w, bool output=false)
{
    typedef typename Cst::size_type size_type;
    size_type steps = 0;
    while (v != w  and steps < cst.csa.size()) {
        if (cst.depth(v) > cst.depth(w)) {
            v = cst.parent(v);
            if (output) {
                std::cout << "v="<<format_node(cst, v) << std::endl;
            }
        } else {
            w = cst.parent(w);
            if (output) {
                std::cout << "w="<<format_node(cst, v) << std::endl;
            }
        }
        steps++;
    }
    return v;
}



#endif