-
Notifications
You must be signed in to change notification settings - Fork 8
/
util.go
57 lines (42 loc) · 759 Bytes
/
util.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
package bptree
import (
"bytes"
"fmt"
"io"
"os"
)
func PrintTreeToWriter(tree *Bptree, w io.Writer) error {
node := tree.root
for node != nil {
if !node.isInternal {
break
}
node = node.children[0].(*indexNode)
}
if node == nil {
return fmt.Errorf("tree is nil")
}
i := 0
for node != nil {
fmt.Fprintln(w, "leaf ---", i)
for _, child := range node.children {
fmt.Fprintf(w, "\t%v\n", child)
}
node = node.next
i += 1
}
return nil
}
// for debug
func PrintTree(tree *Bptree) error {
return PrintTreeToWriter(tree, os.Stdout)
}
func printTreeToString(tree *Bptree) (s string, err error) {
buf := new(bytes.Buffer)
err = PrintTreeToWriter(tree, buf)
if err != nil {
return
}
s = buf.String()
return
}