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) } }
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 }
func getNodeData(node *trie.TernaryNode) *nodeData { d, _ := node.Value().(*nodeData) return d }