-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnode.go
64 lines (47 loc) · 1.05 KB
/
node.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
package tickers
import "fmt"
type node struct {
children map[rune]*node
tickers []*Ticker
}
func newNode() *node {
return &node{
children: map[rune]*node{},
tickers: []*Ticker{},
}
}
func (n *node) createChild(key rune) error {
if _, exists := n.children[key]; exists {
return fmt.Errorf("Node error: child %c exists", key)
}
n.children[key] = newNode()
return nil
}
func (n *node) getChild(key rune) (*node, error) {
child, exists := n.children[key]
if !exists {
return nil, fmt.Errorf("Node error: child doesn't %c exists", key)
}
return child, nil
}
func (n *node) hasChild(key rune) bool {
_, exists := n.children[key]
return exists
}
func (n *node) addTicker(ticker *Ticker) {
n.tickers = append(n.tickers, ticker)
}
func (n *node) getTickers() []Ticker {
tickers := []Ticker{}
for _, ticker := range n.tickers {
tickers = append(tickers, *ticker)
}
return tickers
}
func (n *node) getChildren() []*node {
children := []*node{}
for _, value := range n.children {
children = append(children, value)
}
return children
}