package trie
import "github.com/cheekybits/genny/generic"
type ValueType generic.Type
//Node represents a node in the trie
type Node struct {
branches [256]*Node
val generic.Type
terminal bool
}
// Walk returns the node reached along edge c, if one exists. If node doesn't
// exist we return nil
func (n *Node) Walk(c byte) *Node {
return n.branches[c]
}
// Terminal indicates whether n is terminal in the trie (that is, whether the path from the root to n
// represents an element in the set). For instance, if the root node is terminal, then []byte{} is in the
// trie.
func (n *Node) Terminal() bool { return n.terminal }
// Val gives the value associated with this node. It panics if n is not terminal.
func (n *Node) Val() generic.Type {
if !n.terminal {
panic("Val called on non-terminal node")
}
return n.val
}
Generation command
genny -in node.go gen "ValueType=int"
Error
Failed to goimports the generated code: node.go:28:2: expected declaration, found 'if'
Input
Generation command
Error