-
Notifications
You must be signed in to change notification settings - Fork 1
/
trie.go
45 lines (42 loc) · 793 Bytes
/
trie.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
package trie
import (
"bytes"
"reflect"
)
func Equal(a, b *Node) bool {
if a == b {
return true
}
if !bytes.Equal(a.key, b.key) {
debugf("Equal: different key: %q != %q", a.key, b.key)
return false
}
if !reflect.DeepEqual(a.value, b.value) {
debugf("Equal: different values for %q: %#v != %#v", a.key, a.value, b.value)
return false
}
return edgesEqual(a.edges, b.edges)
}
func edgesEqual(a, b edges) bool {
if len(a) != len(b) {
debugf("edgesEqual: different lengths; %d != %d", len(a), len(b))
return false
}
switch {
case a == nil:
if b == nil {
return true
}
debugf("edgesEqual: nil A")
return false
case b == nil:
debugf("edgesEqual: nil B")
return false
}
for i, e := range a {
if !Equal(e, b[i]) {
return false
}
}
return true
}