Commit dc9c0aac authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent 920dac9a
...@@ -715,9 +715,10 @@ func TestDelete0(t *testing.T) { ...@@ -715,9 +715,10 @@ func TestDelete0(t *testing.T) {
} }
func TestDelete1(t *testing.T) { func TestDelete1(t *testing.T) {
const N = 130000 //const N = 130000
//const N = 40 const N = 40
for _, x := range []int{0, -1, 0x555555, 0xaaaaaa, 0x333333, 0xcccccc, 0x314159} { //for _, x := range []int{0, -1, 0x555555, 0xaaaaaa, 0x333333, 0xcccccc, 0x314159} {
for _, x := range []int{0} {
r := TreeNew(cmp) r := TreeNew(cmp)
set := r.Set set := r.Set
a := make([]int, N) a := make([]int, N)
......
...@@ -245,7 +245,7 @@ func (t *Tree) Close() { ...@@ -245,7 +245,7 @@ func (t *Tree) Close() {
} }
func (t *Tree) cat(p *x, q, r *d, pi int) { func (t *Tree) cat(p *x, q, r *d, pi int) {
// FIXME update hit (called from Delete -> underflow ) // XXX update hit (called from Delete -> underflow ) ?
t.ver++ t.ver++
q.mvL(r, r.c) q.mvL(r, r.c)
if r.n != nil { if r.n != nil {
...@@ -376,9 +376,21 @@ func (t *Tree) Delete(k interface{} /*K*/) (ok bool) { ...@@ -376,9 +376,21 @@ func (t *Tree) Delete(k interface{} /*K*/) (ok bool) {
hitPKmax = hitKmax hitPKmax = hitKmax
if x.c < kx && q != t.r { if x.c < kx && q != t.r {
x, i = t.underflowX(p, x, pi, i) x, i, pi = t.underflowX(p, x, pi, i)
// TODO Kmin/Kmax/PKmax correct after underflowX // NOTE underflowX changes p which means hit
// Kmin/Kmax/PKmax have to be recomputed
if pi >= 0 && pi < p.c {
hitPKmax.set(p.x[pi].k)
dbg("hitPKmax X: %v", hitPKmax)
hitKmax = hitPKmax
dbg("hitKmax X: %v", hitKmax)
}
if pi > 0 {
hitKmin.set(p.x[pi-1].k)
dbg("hitKmin X: %v", hitKmin)
}
} }
p = x p = x
...@@ -390,12 +402,12 @@ func (t *Tree) Delete(k interface{} /*K*/) (ok bool) { ...@@ -390,12 +402,12 @@ 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)
//dbg("hitKmin: %v", hitKmin) dbg("hitKmin: %v", 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)
//dbg("hitKmax: %v", hitKmax) dbg("hitKmax: %v", hitKmax)
} }
case *d: case *d:
...@@ -407,11 +419,13 @@ func (t *Tree) Delete(k interface{} /*K*/) (ok bool) { ...@@ -407,11 +419,13 @@ func (t *Tree) Delete(k interface{} /*K*/) (ok bool) {
t.hitPKmax = hitPKmax t.hitPKmax = hitPKmax
if !ok { if !ok {
dbg("!ok")
t.hitD = x t.hitD = x
t.hitDi = i // XXX vs > h ? t.hitDi = i // XXX vs > h ?
return false return false
} }
dbg("extract")
t.extract(x, i) t.extract(x, i)
if x.c >= kd { if x.c >= kd {
return true return true
...@@ -419,8 +433,10 @@ func (t *Tree) Delete(k interface{} /*K*/) (ok bool) { ...@@ -419,8 +433,10 @@ func (t *Tree) Delete(k interface{} /*K*/) (ok bool) {
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")
t.underflow(p, x, pi) t.underflow(p, x, pi)
} else if t.c == 0 { } else if t.c == 0 {
dbg("clear")
t.Clear() t.Clear()
} }
return true return true
...@@ -1037,7 +1053,7 @@ func (t *Tree) underflow(p *x, q *d, pi int) { ...@@ -1037,7 +1053,7 @@ func (t *Tree) underflow(p *x, q *d, pi int) {
t.hitPi = pi t.hitPi = pi
} }
func (t *Tree) underflowX(p *x, q *x, pi int, i int) (*x, int) { func (t *Tree) underflowX(p *x, q *x, pi int, i int) (*x, int, int) {
t.ver++ t.ver++
var l, r *x var l, r *x
...@@ -1059,7 +1075,7 @@ func (t *Tree) underflowX(p *x, q *x, pi int, i int) (*x, int) { ...@@ -1059,7 +1075,7 @@ func (t *Tree) underflowX(p *x, q *x, pi int, i int) (*x, int) {
i++ i++
l.c-- l.c--
p.x[pi-1].k = l.x[l.c].k p.x[pi-1].k = l.x[l.c].k
return q, i return q, i, pi
} }
if r != nil && r.c > kx { if r != nil && r.c > kx {
...@@ -1073,18 +1089,18 @@ func (t *Tree) underflowX(p *x, q *x, pi int, i int) (*x, int) { ...@@ -1073,18 +1089,18 @@ func (t *Tree) underflowX(p *x, q *x, pi int, i int) (*x, int) {
r.x[rc].ch = r.x[rc+1].ch r.x[rc].ch = r.x[rc+1].ch
r.x[rc].k = zk r.x[rc].k = zk
r.x[rc+1].ch = nil r.x[rc+1].ch = nil
return q, i return q, i, pi
} }
if l != nil { if l != nil {
i += l.c + 1 i += l.c + 1
t.catX(p, l, q, pi-1) t.catX(p, l, q, pi-1)
q = l q = l
return q, i return q, i, pi - 1
} }
t.catX(p, q, r, pi) t.catX(p, q, r, pi)
return q, i return q, i, pi
} }
// ----------------------------------------------------------------- Enumerator // ----------------------------------------------------------------- Enumerator
......
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