Пример #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)
	}
}
Пример #2
0
func fillFailure(curr, root, parent *trie.TernaryNode) {
	data := getNodeData(curr)
	if data == nil {
		data = &nodeData{}
		curr.SetValue(data)
	}
	if parent == root {
		data.failure = root
		return
	}
	// Determine failure node.
	fnode := getNextNode(getNodeFailure(parent, root), root, curr.Label())
	data.failure = fnode
}
Пример #3
0
func getNodeData(node *trie.TernaryNode) *nodeData {
	d, _ := node.Value().(*nodeData)
	return d
}