Commit fecb9373 authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent 09021d5c
...@@ -317,12 +317,12 @@ func (t *Tree) Delete(k interface{} /*K*/) (ok bool) { ...@@ -317,12 +317,12 @@ func (t *Tree) Delete(k interface{} /*K*/) (ok bool) {
// 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)
if i >= 0 { if i >= 0 {
dbg("hit found\t-> %d, %v", i, ok) //dbg("hit found\t-> %d, %v", i, ok)
dd := t.hitD dd := t.hitD
switch { switch {
case !ok: case !ok:
dbg("ok'") //dbg("ok'")
if i >= dd.c { if i >= dd.c {
// tried to delete element past max k in hitD // tried to delete element past max k in hitD
i = dd.c - 1 i = dd.c - 1
...@@ -331,7 +331,7 @@ func (t *Tree) Delete(k interface{} /*K*/) (ok bool) { ...@@ -331,7 +331,7 @@ func (t *Tree) Delete(k interface{} /*K*/) (ok bool) {
return false return false
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 { if t.hitDi >= dd.c {
t.hitDi-- t.hitDi--
...@@ -346,7 +346,7 @@ func (t *Tree) Delete(k interface{} /*K*/) (ok bool) { ...@@ -346,7 +346,7 @@ func (t *Tree) Delete(k interface{} /*K*/) (ok bool) {
break break
} }
dbg("underflow'") //dbg("underflow'")
t.extract(dd, i) t.extract(dd, i)
// XXX recheck // XXX recheck
...@@ -391,7 +391,7 @@ func (t *Tree) Delete(k interface{} /*K*/) (ok bool) { ...@@ -391,7 +391,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") //dbg("underflowX")
x, i = t.underflowX(p, x, pi, i) x, i = t.underflowX(p, x, pi, i)
} }
...@@ -405,13 +405,13 @@ func (t *Tree) Delete(k interface{} /*K*/) (ok bool) { ...@@ -405,13 +405,13 @@ func (t *Tree) Delete(k interface{} /*K*/) (ok bool) {
if pi > 0 { if pi > 0 {
//hitKmin.set(p.x[pi-1].k) //hitKmin.set(p.x[pi-1].k)
t.hitKmin.set(p.x[pi-1].k) t.hitKmin.set(p.x[pi-1].k)
dbg("hitKmin: %v", t.hitKmin) //dbg("hitKmin: %v", t.hitKmin)
} }
if pi < p.c { // == p.c means ∞ if pi < p.c { // == p.c means ∞
//hitKmax.set(p.x[pi].k) //hitKmax.set(p.x[pi].k)
t.hitKmax.set(p.x[pi].k) t.hitKmax.set(p.x[pi].k)
dbg("hitKmax: %v", t.hitKmax) //dbg("hitKmax: %v", t.hitKmax)
} }
case *d: case *d:
...@@ -429,13 +429,13 @@ func (t *Tree) Delete(k interface{} /*K*/) (ok bool) { ...@@ -429,13 +429,13 @@ func (t *Tree) Delete(k interface{} /*K*/) (ok bool) {
return false return false
} }
dbg("extract %v @%d", x, i) //dbg("extract")
t.extract(x, i) t.extract(x, i)
if x.c < kd { if x.c < kd {
if q != t.r { if q != t.r {
// NOTE overflow will correct hit Kmin, Kmax, P and Pi as needed // NOTE overflow will correct hit Kmin, Kmax, P and Pi as needed
dbg("underflow") //dbg("underflow")
t.underflow(p, x, pi) t.underflow(p, x, pi)
} else if t.c == 0 { } else if t.c == 0 {
dbg("clear") dbg("clear")
...@@ -1009,7 +1009,7 @@ func (t *Tree) underflow(p *x, q *d, pi int) { ...@@ -1009,7 +1009,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") //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)
...@@ -1019,7 +1019,7 @@ func (t *Tree) underflow(p *x, q *d, pi int) { ...@@ -1019,7 +1019,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") //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)
...@@ -1030,12 +1030,11 @@ func (t *Tree) underflow(p *x, q *d, pi int) { ...@@ -1030,12 +1030,11 @@ func (t *Tree) underflow(p *x, q *d, pi int) {
} }
if l != nil { if l != nil {
dbg("\tunderflow -> cat l <- q") //dbg("\tunderflow -> cat l <- q")
t.hitD = l t.hitD = l
t.hitDi += l.c t.hitDi += l.c
pi-- pi--
t.cat(p, l, q, pi) t.cat(p, l, q, pi)
//t.hitKmin.set(p.x[pi-1].k)
t.hitKmin = t.hitPKmin t.hitKmin = t.hitPKmin
if t.r == l { if t.r == l {
// cat removed p // cat removed p
...@@ -1050,7 +1049,7 @@ func (t *Tree) underflow(p *x, q *d, pi int) { ...@@ -1050,7 +1049,7 @@ func (t *Tree) underflow(p *x, q *d, pi int) {
return return
} }
dbg("\tunderflow -> cat q <- r") //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