-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathedges16.go
79 lines (61 loc) · 1.1 KB
/
edges16.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
package art
import (
"bytes"
)
type edges16 struct {
edges [16]*node
keys [16]byte
children uint8
}
func newEdges16() *edges16 {
return &edges16{}
}
func (e *edges16) ntype() uint8 {
return Node16
}
func (e *edges16) next(b byte) *node {
i := bytes.IndexByte(e.keys[:], b)
if i < 0 {
return nil
}
return e.edges[i]
}
func (e *edges16) setNext(b byte, next *node) {
p := e.search(b)
if e.keys[p] == b {
e.edges[p] = next
return
}
copy(e.keys[p+1:], e.keys[p:])
copy(e.edges[p+1:], e.edges[p:])
e.keys[p] = b
e.edges[p] = next
e.children++
}
func (e *edges16) search(b byte) uint8 {
for i := uint8(0); i < uint8(len(e.keys)); i++ {
if e.keys[i] >= b {
return i
}
}
return e.children
}
func (e *edges16) copy() edges {
ne := &edges16{
children: e.children,
}
ne.keys = e.keys
ne.edges = e.edges
return ne
}
func (e *edges16) upgrade() edges {
newEdges := newEdges48()
for i := uint8(0); i < e.children; i++ {
newEdges.keys[e.keys[i]] = i + 1
newEdges.edges[i] = e.edges[i]
}
return newEdges
}
func (e *edges16) full() bool {
return e.children == 16
}