clash/component/trie/node.go

32 lines
536 B
Go
Raw Normal View History

2019-07-14 11:29:58 +00:00
package trie
// Node is the trie's node
2022-04-05 20:25:53 +00:00
type Node[T comparable] struct {
children map[string]*Node[T]
Data T
2019-07-14 11:29:58 +00:00
}
2022-04-05 20:25:53 +00:00
func (n *Node[T]) getChild(s string) *Node[T] {
2019-07-14 11:29:58 +00:00
return n.children[s]
}
2022-04-05 20:25:53 +00:00
func (n *Node[T]) hasChild(s string) bool {
2019-07-14 11:29:58 +00:00
return n.getChild(s) != nil
}
2022-04-05 20:25:53 +00:00
func (n *Node[T]) addChild(s string, child *Node[T]) {
2019-07-14 11:29:58 +00:00
n.children[s] = child
}
2022-04-05 20:25:53 +00:00
func newNode[T comparable](data T) *Node[T] {
return &Node[T]{
2019-07-14 11:29:58 +00:00
Data: data,
2022-04-05 20:25:53 +00:00
children: map[string]*Node[T]{},
2019-07-14 11:29:58 +00:00
}
}
2022-04-05 20:25:53 +00:00
func getZero[T comparable]() T {
var result T
return result
}