-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathb-tree.go
More file actions
40 lines (35 loc) · 870 Bytes
/
Copy pathb-tree.go
File metadata and controls
40 lines (35 loc) · 870 Bytes
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
package main
import (
"./logger"
"./nodes"
)
type BTree struct {
root nodes.Node
left nodes.Node
prop *nodes.NodeP
}
func (this *BTree) SetProp(prop *nodes.NodeP) {
this.prop = prop
}
func (this *BTree) Insert(t *nodes.Tuple) {
if this.root == nil {
this.root = new(nodes.DataNode)
this.root.SetProp(this.prop)
this.left = this.root
}
split := this.root.Insert(t)
logger.Debug().Println("checking split", split)
logger.Debug().Println("checking split 1?", split)
if split != nil {
logger.Debug().Println("checking split 2?", split)
newRoot := new(nodes.IndexNode)
newRoot.SetProp(this.prop)
logger.Debug().Println("checking split 3?", split)
newRoot.Keys = []int64{split.MinKey()}
newRoot.Nodes = []nodes.Node{this.root, split}
this.root = newRoot
}
}
func (this *BTree) Find(key int64) *nodes.Tuple {
return this.root.Find(key)
}