iohub / ahocorasick

A fast and memory efficient implementation of aho-corasick algorithm based on double-array trie (cedar), supports visualizing structure via graphviz.
GNU General Public License v2.0
115 stars 20 forks source link

Failed with test from cloudflare/ahocorasick #1

Closed wolfmetr closed 6 years ago

wolfmetr commented 6 years ago
func TestInterior(t *testing.T) {
    m := NewMatcher()
    for i, v := range []string{"Steel", "tee", "e"} {
        m.Insert([]byte(v), i)
    }
    m.Compile()

    seq := []byte("The Man Of Steel: Superman")
    mp := m.Match(seq)

    for _, item := range mp {
        fmt.Printf("item.Pos: %d item.OutID: %d\n", item.Pos, item.OutID)
    }
    req := m.ExportMItem(seq, mp)
    assert(t, len(req) == 3)

    for _, item := range req {
        fmt.Printf("key:%s value:%d\n", item.Key, item.Value.(int))
    }

    assert(t, req[0].Value.(int) == 2)
    assert(t, req[1].Value.(int) == 1)
    assert(t, req[2].Value.(int) == 0)
}

Output:

item.Pos: 2 item.OutID: 100
item.Pos: 15 item.OutID: 259
item.Pos: 21 item.OutID: 100
key:e value:2
key:Steel value:0
key:e value:2
iohub commented 6 years ago

Thanks for your feedback, that's a bug inner output function. I already fixed it. I was so busy about my work that replying you until today. and the fixed output:

item.Pos: 2 item.OutID: 100
item.Pos: 14 item.OutID: 258
item.Pos: 15 item.OutID: 259
item.Pos: 21 item.OutID: 100
key:e value:2
key:tee value:1
key:e value:2
key:Steel value:0
key:e value:2