I accidentally had empty string in my test data and was not able to figure out why tests hang. Maybe consider ingoring such keys when inserting?
func TestAhoCorasick(t *testing.T) {
matcher := ahocorasick.NewMatcher()
matcher.Insert([]byte("adidas"), true)
matcher.Insert([]byte(""), true)
matcher.Compile()
fmt.Println("compiled matcher")
seq := []byte("adidas sneakers")
resp := matcher.Match(seq)
for resp.HasNext() {
items := resp.NextMatchItem(seq)
for _, itr := range items {
fmt.Println("Matched", string(matcher.Key(seq, itr)))
}
}
resp.Release()
}