Skip to content

Commit

Permalink
chore: add printHamt() for debugging
Browse files Browse the repository at this point in the history
  • Loading branch information
rvagg committed Aug 6, 2020
1 parent 21886a1 commit 9ba88a6
Showing 1 changed file with 36 additions and 3 deletions.
39 changes: 36 additions & 3 deletions hamt_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,12 +129,12 @@ func addAndRemoveKeys(t *testing.T, keys []string, extraKeys []string, options .
}
}

fmt.Println("start flush")
bef := time.Now()
// fmt.Println("start flush")
// bef := time.Now()
if err := begn.Flush(ctx); err != nil {
t.Fatal(err)
}
fmt.Println("flush took: ", time.Since(bef))
// fmt.Println("flush took: ", time.Since(bef))
c, err := cs.Put(ctx, begn)
if err != nil {
t.Fatal(err)
Expand All @@ -158,6 +158,8 @@ func addAndRemoveKeys(t *testing.T, keys []string, extraKeys []string, options .
}
}

printHamt(begn)

// create second hamt by adding and deleting the extra keys
for i := 0; i < len(extraKeys); i++ {
begn.Set(ctx, extraKeys[i], randValue())
Expand Down Expand Up @@ -188,6 +190,37 @@ func addAndRemoveKeys(t *testing.T, keys []string, extraKeys []string, options .
}
}

func printHamt(hamt *Node) {
ctx := context.Background()

var printNode func(n *Node, depth int)

printNode = func(n *Node, depth int) {
c, err := n.store.Put(ctx, n)
if err != nil {
panic(err)
}
fmt.Printf("%s‣ %v:\n", strings.Repeat(" ", depth), c)
for _, p := range n.Pointers {
if p.isShard() {
child, err := p.loadChild(ctx, n.store, n.bitWidth, n.hash)
if err != nil {
panic(err)
}
printNode(child, depth+1)
} else {
var keys []string
for _, pt := range p.KVs {
keys = append(keys, string(pt.Key))
}
fmt.Printf("%s⇶ [ %s ]\n", strings.Repeat(" ", depth+1), strings.Join(keys, ", "))
}
}
}

printNode(hamt, 0)
}

func dotGraphRec(n *Node, name *int) {
cur := *name
for _, p := range n.Pointers {
Expand Down

0 comments on commit 9ba88a6

Please sign in to comment.