-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathedges48.go
63 lines (48 loc) · 874 Bytes
/
edges48.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
package art
type edges48 struct {
edges [48]*node
keys [256]byte
children uint8
}
func newEdges48() *edges48 {
return &edges48{}
}
func (e *edges48) ntype() uint8 {
return Node48
}
func (e *edges48) next(b byte) *node {
i := uint8(e.keys[b])
if i == 0 {
return nil
}
return e.edges[i-1]
}
func (e *edges48) setNext(b byte, next *node) {
if e.keys[b] != 0 {
e.edges[e.keys[b]-1] = next
return
}
e.keys[b] = e.children + 1
e.edges[e.children] = next
e.children++
}
func (e *edges48) copy() edges {
ne := &edges48{
children: e.children,
}
ne.keys = e.keys
ne.edges = e.edges
return ne
}
func (e *edges48) upgrade() edges {
newEdges := newEdges256()
for i := 0; i < 256; i++ {
if e.keys[i] > 0 {
newEdges.edges[i] = e.edges[e.keys[i]-1]
}
}
return newEdges
}
func (e *edges48) full() bool {
return e.children == 48
}