-
Notifications
You must be signed in to change notification settings - Fork 0
/
leaf.go
73 lines (56 loc) · 1.44 KB
/
leaf.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
package art
import (
"bytes"
"fmt"
)
type leaf[T any] struct {
key Key
value T
}
func (l leaf[T]) Kind() Kind {
return Leaf
}
func (l *leaf[T]) leftmost() node[T] {
return l
}
func (l *leaf[T]) insert(other *leaf[T], depth int, parent *olock, parentVersion uint64) (value node[T], restart bool, updated bool) {
if other.cmp(l.key) { // replace
return other, false, true
}
longestPrefix := comparePrefix(l.key, other.key, depth)
nn := &inner[T]{
prefixLen: longestPrefix,
node: &node4[T]{},
}
nn.setPrefix(other.key[depth:], longestPrefix)
nn.node.addChild(l.key.At(depth+longestPrefix), l)
nn.node.addChild(other.key.At(depth+longestPrefix), other)
return nn, false, false
}
func (l leaf[T]) del(bytes Key, i int, o *olock, u uint64, f func(node[T])) (bool, bool, node[T]) {
panic("not needed")
}
func (l leaf[T]) get(key Key, i int, o *olock, u uint64) (value T, found bool, restart bool) {
if l.cmp(key) {
return l.value, true, false
}
return value, false, false
}
func (l *leaf[T]) walk(fn walkFn[T], depth int) bool {
panic("implement me")
}
func (n *leaf[T]) addPrefixBefore(node *inner[T], key byte) {
}
//
//func (l *leaf[T]) inherit(prefix [maxPrefixLen]byte, prefixLen int) node[T] {
// return l
//}
func (l leaf[T]) isLeaf() bool {
return true
}
func (l leaf[T]) String() string {
return fmt.Sprintf("leaf[%x]", l.key)
}
func (l *leaf[T]) cmp(other []byte) bool {
return bytes.Compare(l.key, other) == 0
}