-
Notifications
You must be signed in to change notification settings - Fork 1
/
Debug.go
69 lines (60 loc) · 1.37 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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
package main
import (
"fmt"
)
func (s HamtRoot) debugPrint() {
if s.root != nil {
debugPrint(s.root)
} else {
fmt.Print("()")
}
}
func debugPrint(n HamtNode) {
fmt.Print("(")
for i := 0; i < valuesPerLevel; i++ {
switch c := n.childAtIndex(i).(type) {
case HamtNode:
debugPrint(c)
case HamtKey:
fmt.Print(c, ", ")
case []HamtKey:
fmt.Print("{")
for _, v := range c {
fmt.Print(v, ", ")
}
fmt.Print("}")
}
}
fmt.Print(")")
}
type HamtStats struct {
nodes uint64
nodesByWidth [valuesPerLevel + 1]uint64
nodesByDepth [maxDepth + 1]uint64
leavesByDepth [maxDepth + 1]uint64
collidingLeaves uint64
}
func (s HamtRoot) dumpStats() {
stats := HamtStats{}
internalDumpStats(s.root, &stats, 0)
fmt.Println("Width: ", stats.nodesByWidth)
fmt.Println("Depth: ", stats.nodesByDepth)
fmt.Println("Leaves: ", stats.leavesByDepth)
fmt.Println("Nodes: ", stats.nodes, " Collisions: ", stats.collidingLeaves)
}
func internalDumpStats(n HamtNode, stats *HamtStats, d int) {
stats.nodes++
stats.nodesByDepth[d]++
stats.nodesByWidth[n.width()]++
for i := 0; i < valuesPerLevel; i++ {
switch c := n.childAtIndex(i).(type) {
case HamtNode:
internalDumpStats(c, stats, d+1)
case HamtKey:
stats.leavesByDepth[d]++
case []HamtKey:
stats.leavesByDepth[d] += uint64(len(c))
stats.collidingLeaves += uint64(len(c))
}
}
}