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

.

parent ea98b4ed
...@@ -140,114 +140,88 @@ func (t *Tree) dump() string { ...@@ -140,114 +140,88 @@ func (t *Tree) dump() string {
return s 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*/) { func (t *Tree) checkHit(k interface{} /*K*/) {
badHappenned := false wrong := false
bad := func(s string, va ...interface{}) { bad := func(s string, va ...interface{}) {
dbg(s, va...) dbg(s, va...)
badHappenned = true wrong = true
} }
//println()
if t.hitDi >= 0 { q := t.r
if t.hitD.d[t.hitDi].k != k { var p *x
bad("hitD invalid: %v @%v", t.hitD, t.hitDi) pi := -1
} var dd *d
} var i int
var ok bool
var hitKmin, hitKmax xkey
var hitPKmax xkey
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 {
i, ok = t.find(q, k)
switch x := q.(type) {
case *x:
hitPKmax = hitKmax
if t.hitPi >= 0 { p = x
if t.hitP.x[t.hitPi].ch != t.hitD { pi = i
bad("hitP invalid: %v @%v", t.hitP, t.hitPi) if ok {
pi++
} }
}
// rescan from root and check Kmin/Kmax and rest q = p.x[pi].ch
q := t.r if pi > 0 {
var p *x hitKminPrev := hitKmin
pi := -1 hitKmin.set(p.x[pi-1].k)
var dd *d
var i int
var ok bool
var hitKmin, hitKmax xkey if hitKminPrev.kset && t.cmp(hitKmin.k, hitKminPrev.k) <= 0 {
var hitPKmax xkey bad("hitKmin not ↑: %v -> %v", hitKminPrev.k, hitKmin.k)
//dbg("k: %v", k)
loop:
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
p = x
pi = i
if ok {
pi++
}
//dbg("\tpi -> %v", pi)
q = p.x[pi].ch
if pi > 0 {
hitKminPrev := hitKmin
hitKmin.set(p.x[pi-1].k)
if hitKminPrev.kset && t.cmp(hitKmin.k, hitKminPrev.k) <= 0 {
bad("hitKmin not ↑: %v -> %v", hitKminPrev.k, hitKmin.k)
}
} }
}
if pi < p.c { if pi < p.c { // pi = p.c means k = ∞
//dbg("", p.x, pi) hitKmax.set(p.x[pi].k)
hitKmax.set(p.x[pi].k) // XXX not sure or x[pi+1] ?
if hitPKmax.kset && t.cmp(hitKmax.k, hitPKmax.k) >= 0 { if hitPKmax.kset && t.cmp(hitKmax.k, hitPKmax.k) >= 0 {
bad("hitKmax not ↓: %v -> %v", hitPKmax.k, hitKmax.k) bad("hitKmax not ↓: %v -> %v", hitPKmax.k, hitKmax.k)
}
} }
}
case *d: case *d:
if !ok { if !ok {
bad("key %v not found after set", k) bad("key %v not found after set", k)
}
dd = x
break loop
} }
}
if hitKmin != t.hitKmin { dd = x
bad("hitKmin mismatch: %v ; want %v", t.hitKmin, hitKmin) break loop
}
if hitKmax != t.hitKmax {
bad("hitKmax mismatch: %v ; want %v", t.hitKmax, hitKmax)
} }
}
if hitPKmax != t.hitPKmax { if !(hitKmin == t.hitKmin && hitKmax == t.hitKmax) {
bad("hitPKmax mismatch: %v ; want %v", t.hitPKmax, hitPKmax) bad("hitK mismatch: [%v, %v) ; want [%v, %v)", t.hitKmin, t.hitKmax, hitKmin, hitKmax)
} }
if dd != t.hitD || i != t.hitDi { if hitPKmax != t.hitPKmax {
bad("hitD mismatch: %v @%d ; want %v @%d", t.hitD, t.hitDi, dd, i) bad("hitPKmax mismatch: %v ; want %v", t.hitPKmax, hitPKmax)
} }
if p != t.hitP || pi != t.hitPi { if dd != t.hitD || i != t.hitDi {
bad("hitP mismatch: %v @%d ; want %v @%d", t.hitP, t.hitPi, p, pi) bad("hitD mismatch: %v @%d ; want %v @%d", t.hitD, t.hitDi, dd, i)
} }
//v2, ok := t.Get(k) if p != t.hitP || pi != t.hitPi {
//if !ok || v2 != v { bad("hitP mismatch: %v @%d ; want %v @%d", t.hitP, t.hitPi, p, pi)
// bad("get(%v) -> %v, %v; want %v, %v", k, v2, ok, v, true) }
//}
if badHappenned { if wrong {
panic(0) panic(0)
} }
} }
func rng() *mathutil.FC32 { func rng() *mathutil.FC32 {
......
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