Пример #1
0
def test_trie_trie():
    t1 = make_t1()
    t2 = make_t2()
    t1.insert(t2)
    if in_ipynb(): html(graph_to_html(t1))
    assert num_vertices(t1) == 26
    assert num_vertices(t2) == 12
Пример #2
0
def test_max_suffix_tree_g():
    t = make_suffix_trie("ananas")
    if in_ipynb(): html(graph_to_html(t))
    assert num_vertices(t) == 16
    for q in vertices(t):
        assert is_final(q, t)
    assert not is_final(BOTTOM, t)
Пример #3
0
def make_suffix_trie(w :str = "", max_len :int = None, g :Trie = None) -> Trie:
    if g is None:
        g = Trie()
    if num_vertices(g) == 0:
        add_vertex(g)
    g.m_pmap_final = make_func_property_map(lambda q: q != BOTTOM)

    # Naive implementation (slow)
    # g.insert("")
    # for factor in factors(w, max_len):
    #     g.insert(factor)

    # Optimized version, designed by Elie.
    n = len(w)
    for i in range(n):
        q = initial(g)
        for j in range(i, min(n, i + max_len) if max_len else n):
            a = w[j]
            r = delta(q, a, g)
            if r is BOTTOM:
                r = add_vertex(g)
                add_edge(q, r, a, g)
            q = r
    return g
Пример #4
0
def test_trie_digital_sequence():
    t2 = make_t2()
    if in_ipynb(): html(graph_to_html(t2))
    assert num_vertices(t2) == 12
Пример #5
0
def test_trie_string():
    t1 = make_t1()
    if in_ipynb(): html(graph_to_html(t1))
    assert num_vertices(t1) == 17