Commit 22a81b26 authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent e13ff140
...@@ -322,6 +322,7 @@ func (t *Tree) Delete(k interface{} /*K*/) (ok bool) { ...@@ -322,6 +322,7 @@ func (t *Tree) Delete(k interface{} /*K*/) (ok bool) {
switch { switch {
case !ok: case !ok:
// tried to delete last or element past max k in hitD // tried to delete last or element past max k in hitD
// see also "extract rule" below
if i >= dd.c { if i >= dd.c {
i-- i--
} }
...@@ -330,6 +331,7 @@ func (t *Tree) Delete(k interface{} /*K*/) (ok bool) { ...@@ -330,6 +331,7 @@ func (t *Tree) Delete(k interface{} /*K*/) (ok bool) {
case dd.c > kd: case dd.c > kd:
t.extract(dd, i) t.extract(dd, i)
// extract rule for t.hitDi
if t.hitDi >= dd.c { if t.hitDi >= dd.c {
t.hitDi-- t.hitDi--
} }
...@@ -346,13 +348,13 @@ func (t *Tree) Delete(k interface{} /*K*/) (ok bool) { ...@@ -346,13 +348,13 @@ func (t *Tree) Delete(k interface{} /*K*/) (ok bool) {
t.extract(dd, i) t.extract(dd, i)
// XXX recheck
if p != nil { if p != nil {
t.underflow(p, dd, pi) t.underflow(p, dd, pi)
} else if t.c == 0 { } else if t.c == 0 {
t.Clear() t.Clear()
} }
// extract rule for t.hitDi
if t.hitD != nil && t.hitDi >= t.hitD.c { if t.hitD != nil && t.hitDi >= t.hitD.c {
t.hitDi-- t.hitDi--
} }
...@@ -381,6 +383,7 @@ func (t *Tree) Delete(k interface{} /*K*/) (ok bool) { ...@@ -381,6 +383,7 @@ func (t *Tree) Delete(k interface{} /*K*/) (ok bool) {
} }
if x.c < kx && q != t.r { if x.c < kx && q != t.r {
// NOTE underflowX will correct ... XXX do we need this comment ?
x, i = t.underflowX(p, x, pi, i) x, i = t.underflowX(p, x, pi, i)
} }
...@@ -391,11 +394,11 @@ func (t *Tree) Delete(k interface{} /*K*/) (ok bool) { ...@@ -391,11 +394,11 @@ func (t *Tree) Delete(k interface{} /*K*/) (ok bool) {
pi = i pi = i
q = x.x[pi].ch q = x.x[pi].ch
if pi > 0 { if pi > 0 { // k=-∞ @ pi=-1
t.hitKmin.set(p.x[pi-1].k) t.hitKmin.set(p.x[pi-1].k)
} }
if pi < p.c { // k=∞ @ pi=p.c if pi < p.c { // k=+∞ @ pi=p.c
t.hitKmax.set(p.x[pi].k) t.hitKmax.set(p.x[pi].k)
} }
...@@ -418,13 +421,14 @@ func (t *Tree) Delete(k interface{} /*K*/) (ok bool) { ...@@ -418,13 +421,14 @@ func (t *Tree) Delete(k interface{} /*K*/) (ok bool) {
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 underflow will correct hit Kmin, Kmax, P and Pi as needed
t.underflow(p, x, pi) t.underflow(p, x, pi)
} else if t.c == 0 { } else if t.c == 0 {
t.Clear() t.Clear()
} }
} }
// extract rule for t.hitDi
if t.hitD != nil && t.hitDi >= t.hitD.c { if t.hitD != nil && t.hitDi >= t.hitD.c {
t.hitDi-- t.hitDi--
} }
...@@ -761,11 +765,10 @@ func (t *Tree) Set(k interface{} /*K*/, v interface{} /*V*/) { ...@@ -761,11 +765,10 @@ func (t *Tree) Set(k interface{} /*K*/, v interface{} /*V*/) {
} }
if x.c > 2*kx { if x.c > 2*kx {
//dbg("splitX") // NOTE splitX will correct ... XXX do we need this comment ?
x, i = t.splitX(p, x, pi, i) x, i = t.splitX(p, x, pi, i)
} }
//hitPKmax = hitKmax
t.hitPKmin = t.hitKmin t.hitPKmin = t.hitKmin
t.hitPKmax = t.hitKmax t.hitPKmax = t.hitKmax
...@@ -773,16 +776,12 @@ func (t *Tree) Set(k interface{} /*K*/, v interface{} /*V*/) { ...@@ -773,16 +776,12 @@ func (t *Tree) Set(k interface{} /*K*/, v interface{} /*V*/) {
pi = i pi = i
q = p.x[pi].ch q = p.x[pi].ch
if pi > 0 { if pi > 0 { // k=-∞ @ pi=-1
//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", hitKmin)
} }
if pi < p.c { // == p.c means ∞ if pi < p.c { // k=+∞ @ pi=p.c
//hitKmax.set(p.x[pi].k)
t.hitKmax.set(p.x[pi].k) t.hitKmax.set(p.x[pi].k)
//dbg("hitKmax: %v", hitKmax)
} }
...@@ -790,22 +789,16 @@ func (t *Tree) Set(k interface{} /*K*/, v interface{} /*V*/) { ...@@ -790,22 +789,16 @@ func (t *Tree) Set(k interface{} /*K*/, v interface{} /*V*/) {
// data page found - perform the update // data page found - perform the update
t.hitP = p t.hitP = p
t.hitPi = pi t.hitPi = pi
//t.hitKmin = hitKmin
//t.hitKmax = hitKmax
//t.hitPKmax = hitPKmax
switch { switch {
case ok: case ok:
//dbg("ok")
x.d[i].v = v x.d[i].v = v
t.hitD, t.hitDi = x, i t.hitD, t.hitDi = x, i
case x.c < 2*kd: case x.c < 2*kd:
//dbg("insert")
t.insert(x, i, k, v) t.insert(x, i, k, v)
default: default:
//dbg("overflow")
// NOTE overflow will correct hit Kmin, Kmax, P and Pi as needed // NOTE overflow will correct hit Kmin, Kmax, P and Pi as needed
t.overflow(p, x, pi, i, k, v) t.overflow(p, x, pi, i, k, v)
} }
......
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