Commit 8cde7ef9 authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent 55f5a80c
// DO NOT EDIT - AUTOGENERATED (by gen-fsbtree from github.com/cznic/b bcff30a)
// ---- 8< ----
package fsb
import (
"bytes"
"github.com/cznic/strutil" // XXX better to not depend on it
)
func isNil(p interface{}) bool {
switch x := p.(type) {
case *x:
if x == nil {
return true
}
case *d:
if x == nil {
return true
}
}
return false
}
func (t *Tree) dump() string {
var buf bytes.Buffer
f := strutil.IndentFormatter(&buf, "\t")
num := map[interface{}]int{}
visited := map[interface{}]bool{}
handle := func(p interface{}) int {
if isNil(p) {
return 0
}
if n, ok := num[p]; ok {
return n
}
n := len(num) + 1
num[p] = n
return n
}
var pagedump func(interface{}, string)
pagedump = func(p interface{}, pref string) {
if isNil(p) || visited[p] {
return
}
visited[p] = true
switch x := p.(type) {
case *x:
h := handle(p)
n := 0
for i, v := range x.x {
if v.ch != nil || true {
n = i + 1
}
}
f.Format("%sX#%d(%p) n %d:%d {", pref, h, x, x.c, n)
a := []interface{}{}
for i, v := range x.x[:n] {
a = append(a, v.ch)
if i != 0 {
f.Format(" ")
}
f.Format("(C#%d K %v)", handle(v.ch), v.k)
}
f.Format("}\n")
for _, p := range a {
pagedump(p, pref+". ")
}
case *d:
h := handle(p)
n := 0
for i, v := range x.d {
if true || (true || &v != nil) {
n = i + 1
}
}
f.Format("%sD#%d(%p) P#%d N#%d n %d:%d {", pref, h, x, handle(x.p), handle(x.n), x.c, n)
for i, v := range x.d[:n] {
if i != 0 {
f.Format(" ")
}
f.Format("%v:%v", v.k, v.v)
}
f.Format("}\n")
}
}
pagedump(t.r, "")
s := buf.String()
if s != "" {
s = s[:len(s)-1]
}
return s
}
......@@ -26,3 +26,26 @@ make -s -C $Bdir generic |sed \
-e 's/func (p \*btTpool) get(cmp Cmp)/func (p *btTpool) get()/g' \
-e '/x\.cmp = cmp$/d' \
>>$out
# also extract dump() routine
out=fsbtree_util.go
echo "// DO NOT EDIT - AUTOGENERATED (by gen-fsbtree from $b $Brev)" >$out
echo "// ---- 8< ----" >>$out
cat >>$out <<EOF
package fsb
import (
"bytes"
"github.com/cznic/strutil" // XXX better to not depend on it
)
EOF
echo >>$out
sed -n \
-e '/^func isNil(/,/^}/p' \
-e '/^func.* dump()/,/^}/ {
s/v\.k != nil/true/g
s/v\.v != nil/(true || \&v != nil)/g
p
}' \
\
$Bdir/all_test.go \
>>$out
......@@ -161,7 +161,7 @@ func TestIndexSaveLoad(t *testing.T) {
// XXX is it ok to compare trees via reflect.DeepEqual ?
if !treeEqual(fsi2.Tree, fsi.Tree) {
t.Errorf("index load: trees mismatch: %v ; want %v", fsi2.Tree, fsi.Tree)
t.Errorf("index load: trees mismatch: %v ; want %v", fsi2.Tree.dump(), fsi.Tree.dump())
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment