Commit 09021d5c authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent a3ada377
...@@ -161,7 +161,7 @@ func (t *Tree) checkHit(k interface{} /*K*/, op treeOp) { ...@@ -161,7 +161,7 @@ func (t *Tree) checkHit(k interface{} /*K*/, op treeOp) {
var ok bool var ok bool
var hitKmin, hitKmax xkey var hitKmin, hitKmax xkey
var hitPKmax xkey var hitPKmin, hitPKmax xkey
loop: loop:
// here he tree is immutable while we are rescanning it, which means // here he tree is immutable while we are rescanning it, which means
...@@ -176,6 +176,7 @@ loop: ...@@ -176,6 +176,7 @@ loop:
i, ok = t.find(q, k) i, ok = t.find(q, k)
switch x := q.(type) { switch x := q.(type) {
case *x: case *x:
hitPKmin = hitKmin
hitPKmax = hitKmax hitPKmax = hitKmax
p = x p = x
...@@ -186,11 +187,10 @@ loop: ...@@ -186,11 +187,10 @@ loop:
q = p.x[pi].ch q = p.x[pi].ch
if pi > 0 { if pi > 0 {
hitKminPrev := hitKmin
hitKmin.set(p.x[pi-1].k) hitKmin.set(p.x[pi-1].k)
if hitKminPrev.kset && t.cmp(hitKmin.k, hitKminPrev.k) <= 0 { if hitPKmin.kset && t.cmp(hitKmin.k, hitPKmin.k) <= 0 {
bad("hitKmin not ↑: %v -> %v", hitKminPrev.k, hitKmin.k) bad("hitKmin not ↑: %v -> %v", hitPKmin.k, hitKmin.k)
} }
} }
...@@ -230,8 +230,8 @@ loop: ...@@ -230,8 +230,8 @@ loop:
bad("hitK mismatch: [%v, %v) ; want [%v, %v)", t.hitKmin, t.hitKmax, hitKmin, hitKmax) bad("hitK mismatch: [%v, %v) ; want [%v, %v)", t.hitKmin, t.hitKmax, hitKmin, hitKmax)
} }
if hitPKmax != t.hitPKmax { if !(hitPKmin == t.hitPKmin && hitPKmax == t.hitPKmax) {
bad("hitPKmax mismatch: %v ; want %v", t.hitPKmax, hitPKmax) bad("hitPK mismatch: [%v, %v) ; want [%v, %v)", t.hitPKmin, t.hitPKmax, hitPKmin, hitPKmax)
} }
if dd != t.hitD || i != t.hitDi { if dd != t.hitD || i != t.hitDi {
......
...@@ -105,9 +105,10 @@ type ( ...@@ -105,9 +105,10 @@ type (
hitDi int hitDi int
hitP *x // parent & pos for data page (= -1 if no parent) hitP *x // parent & pos for data page (= -1 if no parent)
hitPi int hitPi int
hitKmin xkey // data page allowed key range is [hitKmin, hitKmax) hitKmin xkey // hitD allowed key range is [hitKmin, hitKmax)
hitKmax xkey hitKmax xkey
hitPKmax xkey // allowed Kmax for whole hitP hitPKmin xkey // ----//--- for hitP
hitPKmax xkey
} }
xe struct { // x element xe struct { // x element
...@@ -378,9 +379,9 @@ func (t *Tree) Delete(k interface{} /*K*/) (ok bool) { ...@@ -378,9 +379,9 @@ func (t *Tree) Delete(k interface{} /*K*/) (ok bool) {
//var hitPKmax xkey // Kmax for whole hitP //var hitPKmax xkey // Kmax for whole hitP
t.hitKmin = xkey{} // initially [-∞, +∞) t.hitKmin = xkey{} // initially [-∞, +∞)
t.hitKmax = xkey{} t.hitKmax = xkey{}
t.hitPKmin = xkey{}
t.hitPKmax = xkey{} t.hitPKmax = xkey{}
for { for {
i, ok := t.find(q, k) i, ok := t.find(q, k)
switch x := q.(type) { switch x := q.(type) {
...@@ -394,6 +395,7 @@ func (t *Tree) Delete(k interface{} /*K*/) (ok bool) { ...@@ -394,6 +395,7 @@ func (t *Tree) Delete(k interface{} /*K*/) (ok bool) {
x, i = t.underflowX(p, x, pi, i) x, i = t.underflowX(p, x, pi, i)
} }
t.hitPKmin = t.hitKmin
t.hitPKmax = t.hitKmax t.hitPKmax = t.hitKmax
p = x p = x
...@@ -771,6 +773,7 @@ func (t *Tree) Set(k interface{} /*K*/, v interface{} /*V*/) { ...@@ -771,6 +773,7 @@ func (t *Tree) Set(k interface{} /*K*/, v interface{} /*V*/) {
//var hitPKmax xkey // Kmax for whole hitP //var hitPKmax xkey // Kmax for whole hitP
t.hitKmin = xkey{} // initially [-∞, +∞) t.hitKmin = xkey{} // initially [-∞, +∞)
t.hitKmax = xkey{} t.hitKmax = xkey{}
t.hitPKmin = xkey{}
t.hitPKmax = xkey{} t.hitPKmax = xkey{}
for { for {
...@@ -787,6 +790,7 @@ func (t *Tree) Set(k interface{} /*K*/, v interface{} /*V*/) { ...@@ -787,6 +790,7 @@ func (t *Tree) Set(k interface{} /*K*/, v interface{} /*V*/) {
} }
//hitPKmax = hitKmax //hitPKmax = hitKmax
t.hitPKmin = t.hitKmin
t.hitPKmax = t.hitKmax t.hitPKmax = t.hitKmax
p = x p = x
...@@ -1029,9 +1033,20 @@ func (t *Tree) underflow(p *x, q *d, pi int) { ...@@ -1029,9 +1033,20 @@ func (t *Tree) underflow(p *x, q *d, pi int) {
dbg("\tunderflow -> cat l <- q") dbg("\tunderflow -> cat l <- q")
t.hitD = l t.hitD = l
t.hitDi += l.c t.hitDi += l.c
t.cat(p, l, q, pi-1) pi--
t.hitKmin.set(p.x[pi-1].k) t.cat(p, l, q, pi)
t.hitPi = pi - 1 //t.hitKmin.set(p.x[pi-1].k)
t.hitKmin = t.hitPKmin
if t.r == l {
// cat removed p
t.hitP = nil
t.hitPi = -1
} else {
if pi > 0 {
t.hitKmin.set(p.x[pi-1].k)
}
t.hitPi = pi
}
return return
} }
...@@ -1039,15 +1054,15 @@ func (t *Tree) underflow(p *x, q *d, pi int) { ...@@ -1039,15 +1054,15 @@ func (t *Tree) underflow(p *x, q *d, pi int) {
t.cat(p, q, r, pi) t.cat(p, q, r, pi)
// hitD/hitDi stays unchanged // hitD/hitDi stays unchanged
t.hitKmax = t.hitPKmax t.hitKmax = t.hitPKmax
if t.r != q { if t.r == q {
// cat removed p
t.hitP = nil
t.hitPi = -1
} else {
if pi < p.c { // means < ∞ if pi < p.c { // means < ∞
t.hitKmax.set(p.x[pi].k) t.hitKmax.set(p.x[pi].k)
} }
t.hitPi = pi // XXX? (+ already pre-set this way ?) t.hitPi = pi // XXX? (+ already pre-set this way ?)
} else {
// cat removed p
t.hitP = nil
t.hitPi = -1
} }
} }
...@@ -1094,16 +1109,22 @@ func (t *Tree) underflowX(p *x, q *x, pi int, i int) (*x, int) { ...@@ -1094,16 +1109,22 @@ func (t *Tree) underflowX(p *x, q *x, pi int, i int) (*x, int) {
if l != nil { if l != nil {
i += l.c + 1 i += l.c + 1
t.catX(p, l, q, pi-1) pi--
t.hitKmin.set(p.x[pi-1].k) //t.catX(p, l, q, pi-1)
t.catX(p, l, q, pi)
q = l q = l
t.hitKmin = t.hitPKmin
if t.r != q && pi > 0 {
t.hitKmin.set(p.x[pi-1].k)
}
//t.hitKmin.set(p.x[pi-1].k) // XXX wrong -> see cat handling in underflow
return q, i return q, i
} }
t.catX(p, q, r, pi) t.catX(p, q, r, pi)
t.hitKmax = t.hitPKmax t.hitKmax = t.hitPKmax
if t.r != q && pi < p.c { // means < ∞ if t.r != q && pi < p.c { // means < ∞
t.hitKmax.set(p.x[pi].k) t.hitKmax.set(p.x[pi].k) // XXX ok (was XXX wrong -> see cat handling in underflow)
} }
return q, i return q, i
} }
......
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