Skip to content

Commit 275f14d

Browse files
author
xieguanfeng
committed
fix map
1 parent 7cc0625 commit 275f14d

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

filter/ahocorasick.go

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ func (m *AcModel) buildFailPointers() {
129129
} else {
130130
p := tmpAcNode.fail
131131
for p != nil {
132-
if next, found := p.children[node.value]; found {
132+
if next, found := p.getChild(node.value); found {
133133
node.fail = next
134134
break
135135
}
@@ -181,23 +181,29 @@ func (m *AcModel) FindAll(text string) []string {
181181

182182
for pos := 0; pos < len(runes); pos++ {
183183
_, found = now.getChild(runes[pos])
184-
if !found && now != m.root {
184+
if !found && now != nil && now != m.root {
185185
now = now.fail
186-
for ; !found && now != m.root; now, found = now.getChild(runes[pos]) {
186+
for ; !found && now != nil && now != m.root; now, found = now.getChild(runes[pos]) {
187187
now = now.fail
188188
}
189189
}
190190

191191
// 若找到匹配成功的字符串结点, 则指向那个结点, 否则指向根结点
192-
if next, ok := now.getChild(runes[pos]); ok {
192+
var next *acNode
193+
var ok bool
194+
195+
if now != nil {
196+
next, ok = now.getChild(runes[pos])
197+
}
198+
if ok {
193199
now = next
194200
} else {
195201
now = m.root
196202
}
197203

198204
temp = now
199205

200-
for temp != m.root {
206+
for temp != nil && temp != m.root {
201207
if temp.word != nil {
202208
matches = append(matches, *temp.word)
203209
}

0 commit comments

Comments
 (0)