-
Notifications
You must be signed in to change notification settings - Fork 8
/
indexnode.go
75 lines (57 loc) · 1.31 KB
/
indexnode.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
package bptree
import (
"fmt"
"unsafe"
)
type indexNode struct {
children Elems
prev *indexNode
next *indexNode
isInternal bool
depthToLeaf int
_tmpKey Key // for temporary empty node (to be deleted soon)
}
// return smallest key in sub-tree
func (node *indexNode) Key() Key {
if len(node.children) < 1 {
return node._tmpKey
}
var n *indexNode = node
for n.isInternal {
n = n.children[0].(*indexNode)
}
return n.children[0].Key()
}
func (node *indexNode) String() string {
var pKey, nKey string
if node.prev != nil {
pKey = fmt.Sprintf("%v", node.prev.Key())
} else {
pKey = "nil"
}
if node.next != nil {
nKey = fmt.Sprintf("%v", node.next.Key())
} else {
nKey = "nil"
}
return fmt.Sprintf("%p{c:%v, p:%v, n:%v, i:%v, d:%d}", unsafe.Pointer(node), node.children, pKey, nKey, node.isInternal, node.depthToLeaf)
}
func (node *indexNode) insertElem(elem Elem, maxDegree int, allowOverlap bool) error {
newChildren, err := node.children.insert(elem, maxDegree, allowOverlap)
if err != nil {
return err
}
node.children = newChildren
return nil
}
func (node *indexNode) deleteElem(key Key, maxDegree int) bool {
newChildren, ok := node.children.delete(key, maxDegree)
if !ok {
return false
}
if len(newChildren) < 1 {
node._tmpKey = key
}
node.children = newChildren
return true
}