Commit 318c5837 authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent ea98b4ed
......@@ -140,28 +140,14 @@ func (t *Tree) dump() string {
return s
}
// rescan t from root and check that hit D, P, Kmin/Kmax and rest all match what they should
func (t *Tree) checkHit(k interface{} /*K*/) {
badHappenned := false
wrong := false
bad := func(s string, va ...interface{}) {
dbg(s, va...)
badHappenned = true
wrong = true
}
//println()
if t.hitDi >= 0 {
if t.hitD.d[t.hitDi].k != k {
bad("hitD invalid: %v @%v", t.hitD, t.hitDi)
}
}
if t.hitPi >= 0 {
if t.hitP.x[t.hitPi].ch != t.hitD {
bad("hitP invalid: %v @%v", t.hitP, t.hitPi)
}
}
// rescan from root and check Kmin/Kmax and rest
q := t.r
var p *x
pi := -1
......@@ -172,23 +158,21 @@ func (t *Tree) checkHit(k interface{} /*K*/) {
var hitKmin, hitKmax xkey
var hitPKmax xkey
//dbg("k: %v", k)
loop:
loop:
// here he tree is immutable while we are rescanning it, which means
// the logic to get hitKmin/hitKmax & friends is simpler compared to
// that in Set when splitX may occurr.
for {
//dbg("p: %p: @%d %v", p, pi, p)
//dbg("q: %p: %v", q, q)
i, ok = t.find(q, k)
//dbg("\t-> %v, %v", i, ok)
switch x := q.(type) {
case *x:
hitPKmax = hitKmax // XXX recheck
hitPKmax = hitKmax
p = x
pi = i
if ok {
pi++
}
//dbg("\tpi -> %v", pi)
q = p.x[pi].ch
if pi > 0 {
......@@ -200,9 +184,8 @@ func (t *Tree) checkHit(k interface{} /*K*/) {
}
}
if pi < p.c {
//dbg("", p.x, pi)
hitKmax.set(p.x[pi].k) // XXX not sure or x[pi+1] ?
if pi < p.c { // pi = p.c means k = ∞
hitKmax.set(p.x[pi].k)
if hitPKmax.kset && t.cmp(hitKmax.k, hitPKmax.k) >= 0 {
bad("hitKmax not ↓: %v -> %v", hitPKmax.k, hitKmax.k)
......@@ -220,12 +203,8 @@ func (t *Tree) checkHit(k interface{} /*K*/) {
}
}
if hitKmin != t.hitKmin {
bad("hitKmin mismatch: %v ; want %v", t.hitKmin, hitKmin)
}
if hitKmax != t.hitKmax {
bad("hitKmax mismatch: %v ; want %v", t.hitKmax, hitKmax)
if !(hitKmin == t.hitKmin && hitKmax == t.hitKmax) {
bad("hitK mismatch: [%v, %v) ; want [%v, %v)", t.hitKmin, t.hitKmax, hitKmin, hitKmax)
}
if hitPKmax != t.hitPKmax {
......@@ -240,12 +219,7 @@ func (t *Tree) checkHit(k interface{} /*K*/) {
bad("hitP mismatch: %v @%d ; want %v @%d", t.hitP, t.hitPi, p, pi)
}
//v2, ok := t.Get(k)
//if !ok || v2 != v {
// bad("get(%v) -> %v, %v; want %v, %v", k, v2, ok, v, true)
//}
if badHappenned {
if wrong {
panic(0)
}
}
......
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