Beispiel #1
0
func getNextNode(node, root *trie.TernaryNode, r rune) *trie.TernaryNode {
	for {
		next, _ := node.Get(r).(*trie.TernaryNode)
		if next != nil {
			return next
		} else if node == root {
			return root
		}
		node = getNodeFailure(node, root)
	}
}
Beispiel #2
0
func fillFailure(curr, root, parent *trie.TernaryNode) {
	data := getNodeData(curr)
	if data == nil {
		data = &Data{}
		curr.SetValue(data)
	}
	if parent == root {
		data.failure = root
		return
	}
	// Determine failure node.
	fnode := getNextNode(getNodeFailure(parent, root), root, curr.Label())
	data.failure = fnode
}
Beispiel #3
0
func getNodeData(node *trie.TernaryNode) *Data {
	d, _ := node.Value().(*Data)
	return d
}