-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathdebug.go
46 lines (40 loc) · 993 Bytes
/
debug.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
package btree
import (
"fmt"
)
//debug func
func (n *TreeNode) printNode() {
if n.GetNodeType() == isLeaf {
fmt.Println("---LeafID---", n.GetId())
fmt.Println("Key", toArray(n.GetKeys()))
fmt.Println("values", toArray(n.GetValues()))
} else {
fmt.Println("---NodeID---", n.GetId())
fmt.Println("Key", toArray(n.GetKeys()))
fmt.Println("Childrens", n.GetChildrens())
}
}
func toArray(data [][]byte) []string {
var rst []string
for _, v := range data {
rst = append(rst, string(v))
}
return rst
}
// PrintInfo print some basic btree info
func (t *Btree) PrintInfo() {
fmt.Println("Root", t.GetRoot())
fmt.Println("IndexCursor", t.GetIndexCursor())
}
// PrintTree print all btree's leafs/nodes
func (t *Btree) PrintTree() {
fmt.Println("-----------Tree-------------")
for i := 0; i < int(t.GetIndexCursor()); i++ {
if node, err := t.getTreeNode(int64(i)); err == nil {
if node.GetIsDirt() == 0 {
node.printNode()
fmt.Println("--------")
}
}
}
}