-
Notifications
You must be signed in to change notification settings - Fork 0
/
debug.go
54 lines (44 loc) · 1.03 KB
/
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
47
48
49
50
51
52
53
54
package radixdb
import (
"fmt"
)
// DebugPrint prints the RadixDB structure in a directory tree format.
// This function is only for development and debugging purposes.
func (rdb *RadixDB) DebugPrint() {
rdb.mu.RLock()
defer rdb.mu.RUnlock()
printTree(rdb.root, "", true, true, rdb.Len())
}
func printTree(node *node, prefix string, isLast bool, isRoot bool, treeSize uint64) {
if node == nil {
return
}
var val string
if node.data != nil {
val = string(node.data)
} else {
val = "<nil>"
}
if isRoot && treeSize == 1 {
fmt.Printf("%s (%q)\n", string(node.key), val)
return
}
if isRoot {
if node.key != nil {
fmt.Printf("%s (%q)\n", string(node.key), val)
} else {
fmt.Println(".")
}
} else {
if isLast {
fmt.Printf("%s└─ %s (%q)\n", prefix, string(node.key), val)
prefix += " "
} else {
fmt.Printf("%s├─ %s (%q)\n", prefix, string(node.key), val)
prefix += "│ "
}
}
for i, child := range node.children {
printTree(child, prefix, i == len(node.children)-1, false, treeSize)
}
}