Commit a3ada377 authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent 9e241343
...@@ -307,11 +307,11 @@ func (t *Tree) catX(p, q, r *x, pi int) { ...@@ -307,11 +307,11 @@ func (t *Tree) catX(p, q, r *x, pi int) {
// Delete removes the k's KV pair, if it exists, in which case Delete returns // Delete removes the k's KV pair, if it exists, in which case Delete returns
// true. // true.
func (t *Tree) Delete(k interface{} /*K*/) (ok bool) { func (t *Tree) Delete(k interface{} /*K*/) (ok bool) {
dbg("--- PRE Delete(%v)\t; %v @%d, [%v, %v) PKmax: %v\n%s", k, t.hitD, t.hitDi, t.hitKmin, t.hitKmax, t.hitPKmax, t.dump()) //dbg("--- PRE Delete(%v)\t; %v @%d, [%v, %v) PKmax: %v\n%s", k, t.hitD, t.hitDi, t.hitKmin, t.hitKmax, t.hitPKmax, t.dump())
defer t.checkHit(k, opDel) defer t.checkHit(k, opDel)
defer func() { //defer func() {
dbg("--- POST\n%s\n====\n", t.dump()) // dbg("--- POST\n%s\n====\n", t.dump())
}() //}()
// check if we can do the delete nearby previous change // check if we can do the delete nearby previous change
i, ok := t.hitFind(k) i, ok := t.hitFind(k)
...@@ -332,6 +332,9 @@ func (t *Tree) Delete(k interface{} /*K*/) (ok bool) { ...@@ -332,6 +332,9 @@ func (t *Tree) Delete(k interface{} /*K*/) (ok bool) {
case dd.c > kd: case dd.c > kd:
dbg("extract'") dbg("extract'")
t.extract(dd, i) t.extract(dd, i)
if t.hitDi >= dd.c {
t.hitDi--
}
return true return true
// here: need to extract / underflow but check to not underflow too much XXX // here: need to extract / underflow but check to not underflow too much XXX
...@@ -351,6 +354,11 @@ func (t *Tree) Delete(k interface{} /*K*/) (ok bool) { ...@@ -351,6 +354,11 @@ func (t *Tree) Delete(k interface{} /*K*/) (ok bool) {
} else if t.c == 0 { } else if t.c == 0 {
t.Clear() t.Clear()
} }
if t.hitD != nil && t.hitDi >= t.hitD.c {
t.hitDi--
}
return true return true
} }
} }
...@@ -382,7 +390,7 @@ func (t *Tree) Delete(k interface{} /*K*/) (ok bool) { ...@@ -382,7 +390,7 @@ func (t *Tree) Delete(k interface{} /*K*/) (ok bool) {
} }
if x.c < kx && q != t.r { if x.c < kx && q != t.r {
dbg("UNDERFLOWX\n\tp: %v @%d\n\tx: %v @%d", p, pi, x, i) dbg("underflowX")
x, i = t.underflowX(p, x, pi, i) x, i = t.underflowX(p, x, pi, i)
} }
...@@ -419,19 +427,22 @@ func (t *Tree) Delete(k interface{} /*K*/) (ok bool) { ...@@ -419,19 +427,22 @@ func (t *Tree) Delete(k interface{} /*K*/) (ok bool) {
return false return false
} }
dbg("extract") dbg("extract %v @%d", x, i)
t.extract(x, i) t.extract(x, i)
if x.c >= kd {
return true if x.c < kd {
if q != t.r {
// NOTE overflow will correct hit Kmin, Kmax, P and Pi as needed
dbg("underflow")
t.underflow(p, x, pi)
} else if t.c == 0 {
dbg("clear")
t.Clear()
}
} }
if q != t.r { if t.hitD != nil && t.hitDi >= t.hitD.c {
// NOTE overflow will correct hit Kmin, Kmax, P and Pi as needed t.hitDi--
dbg("underflow")
t.underflow(p, x, pi)
} else if t.c == 0 {
dbg("clear")
t.Clear()
} }
return true return true
} }
...@@ -448,9 +459,9 @@ func (t *Tree) extract(q *d, i int) { // (r interface{} /*V*/) { ...@@ -448,9 +459,9 @@ func (t *Tree) extract(q *d, i int) { // (r interface{} /*V*/) {
q.d[q.c] = zde // GC q.d[q.c] = zde // GC
t.c-- t.c--
t.hitD = q t.hitD = q
if i >= q.c { //if i >= q.c {
i-- // i--
} //}
t.hitDi = i t.hitDi = i
return return
} }
...@@ -994,6 +1005,7 @@ func (t *Tree) underflow(p *x, q *d, pi int) { ...@@ -994,6 +1005,7 @@ func (t *Tree) underflow(p *x, q *d, pi int) {
l, r := p.siblings(pi) l, r := p.siblings(pi)
if l != nil && l.c+q.c >= 2*kd { if l != nil && l.c+q.c >= 2*kd {
dbg("\tunderflow -> mv-from-l")
l.mvR(q, 1) l.mvR(q, 1)
p.x[pi-1].k = q.d[0].k p.x[pi-1].k = q.d[0].k
t.hitKmin.set(q.d[0].k) t.hitKmin.set(q.d[0].k)
...@@ -1003,6 +1015,7 @@ func (t *Tree) underflow(p *x, q *d, pi int) { ...@@ -1003,6 +1015,7 @@ func (t *Tree) underflow(p *x, q *d, pi int) {
} }
if r != nil && q.c+r.c >= 2*kd { if r != nil && q.c+r.c >= 2*kd {
dbg("\tunderflow -> mv-from-r")
q.mvL(r, 1) q.mvL(r, 1)
p.x[pi].k = r.d[0].k p.x[pi].k = r.d[0].k
t.hitKmax.set(r.d[0].k) t.hitKmax.set(r.d[0].k)
...@@ -1013,6 +1026,7 @@ func (t *Tree) underflow(p *x, q *d, pi int) { ...@@ -1013,6 +1026,7 @@ func (t *Tree) underflow(p *x, q *d, pi int) {
} }
if l != nil { if l != nil {
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) t.cat(p, l, q, pi-1)
...@@ -1021,6 +1035,7 @@ func (t *Tree) underflow(p *x, q *d, pi int) { ...@@ -1021,6 +1035,7 @@ func (t *Tree) underflow(p *x, q *d, pi int) {
return return
} }
dbg("\tunderflow -> cat q <- r")
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
......
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