Commit a77b5775 authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent 84c589d6
...@@ -647,11 +647,10 @@ func (t *Tree) overflow(p *x, q *d, pi, i int, k interface{} /*K*/, v interface{ ...@@ -647,11 +647,10 @@ func (t *Tree) overflow(p *x, q *d, pi, i int, k interface{} /*K*/, v interface{
p.x[pi].k = k p.x[pi].k = k
t.hitKmin.set(k) t.hitKmin.set(k)
kmax := t.hitPKmax t.hitKmax = t.hitPKmax
if pi + 1 < p.c { // means < ∞ if pi + 1 < p.c { // means < ∞
kmax.set(p.x[pi+1].k) t.hitKmax.set(p.x[pi+1].k)
} }
t.hitKmax = kmax
t.hitPi = pi + 1 t.hitPi = pi + 1
return return
} }
...@@ -714,11 +713,11 @@ func (t *Tree) SeekLast() (e *Enumerator, err error) { ...@@ -714,11 +713,11 @@ func (t *Tree) SeekLast() (e *Enumerator, err error) {
// Set sets the value associated with k. // Set sets the value associated with k.
func (t *Tree) Set(k interface{} /*K*/, v interface{} /*V*/) { func (t *Tree) Set(k interface{} /*K*/, v interface{} /*V*/) {
dbg("--- PRE Set(%v, %v)\t; %v @%d, [%v, %v) PKmax: %v\n%s", k, v, t.hitD, t.hitDi, t.hitKmin, t.hitKmax, t.hitPKmax, t.dump()) //dbg("--- PRE Set(%v, %v)\t; %v @%d, [%v, %v) PKmax: %v\n%s", k, v, t.hitD, t.hitDi, t.hitKmin, t.hitKmax, t.hitPKmax, t.dump())
defer t.checkHit(k, opSet) defer t.checkHit(k, opSet)
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 update nearby previous change // check if we can do the update nearby previous change
...@@ -763,56 +762,43 @@ func (t *Tree) Set(k interface{} /*K*/, v interface{} /*V*/) { ...@@ -763,56 +762,43 @@ func (t *Tree) Set(k interface{} /*K*/, v interface{} /*V*/) {
return return
} }
var hitKmin, hitKmax xkey // initially [-∞, +∞) // XXX recheck what is better - to update hits in t. directly or here and copy at last
var hitPKmax xkey // Kmax for whole hitP // (performance) NOTE for splitX it is handy to have them in t.
//var hitKmin, hitKmax xkey // initially [-∞, +∞)
//var hitPKmax xkey // Kmax for whole hitP
t.hitKmin = xkey{} // initially [-∞, +∞)
t.hitKmax = 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) {
case *x: case *x:
//hitPKmax = hitKmax
if ok { if ok {
i++ i++
} }
if x.c > 2*kx { if x.c > 2*kx {
//dbg("splitX") //dbg("splitX")
x, i, p, pi = t.splitX(p, x, pi, i) x, i = t.splitX(p, x, pi, i)
// FIXME move logic inside splitX
// NOTE splitX 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)
}
} else {
// p unchanged
// FIXME move to above without else
hitPKmax = hitKmax
} }
//hitPKmax = hitKmax
t.hitPKmax = t.hitKmax
p = x p = x
pi = i pi = i
//if ok {
// pi++
//}
q = p.x[pi].ch q = p.x[pi].ch
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)
//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)
t.hitKmax.set(p.x[pi].k)
//dbg("hitKmax: %v", hitKmax) //dbg("hitKmax: %v", hitKmax)
} }
...@@ -821,9 +807,9 @@ func (t *Tree) Set(k interface{} /*K*/, v interface{} /*V*/) { ...@@ -821,9 +807,9 @@ 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.hitKmin = hitKmin
t.hitKmax = hitKmax //t.hitKmax = hitKmax
t.hitPKmax = hitPKmax //t.hitPKmax = hitPKmax
switch { switch {
case ok: case ok:
...@@ -885,7 +871,7 @@ func (t *Tree) Put(k interface{} /*K*/, upd func(oldV interface{} /*V*/, exists ...@@ -885,7 +871,7 @@ func (t *Tree) Put(k interface{} /*K*/, upd func(oldV interface{} /*V*/, exists
i++ i++
if x.c > 2*kx { if x.c > 2*kx {
panic("TODO") panic("TODO")
x, i, _, _ = t.splitX(p, x, pi, i) x, i = t.splitX(p, x, pi, i)
} }
pi = i pi = i
p = x p = x
...@@ -978,7 +964,7 @@ func (t *Tree) split(p *x, q *d, pi, i int, k interface{} /*K*/, v interface{} / ...@@ -978,7 +964,7 @@ func (t *Tree) split(p *x, q *d, pi, i int, k interface{} /*K*/, v interface{} /
} }
} }
func (t *Tree) splitX(p *x, q *x, pi int, i int) (*x, int, *x, int) { func (t *Tree) splitX(p *x, q *x, pi int, i int) (*x, int) {
t.ver++ t.ver++
r := btXPool.Get().(*x) r := btXPool.Get().(*x)
copy(r.x[:], q.x[kx+1:]) copy(r.x[:], q.x[kx+1:])
...@@ -999,10 +985,16 @@ func (t *Tree) splitX(p *x, q *x, pi int, i int) (*x, int, *x, int) { ...@@ -999,10 +985,16 @@ func (t *Tree) splitX(p *x, q *x, pi int, i int) (*x, int, *x, int) {
if i > kx { if i > kx {
q = r q = r
i -= kx + 1 i -= kx + 1
pi++ t.hitKmin.set(p.x[pi].k)
t.hitKmax = t.hitPKmax
if pi + 1 < p.c { // means < ∞
t.hitKmax.set(p.x[pi+1].k)
}
} else {
t.hitKmax.set(p.x[pi].k)
} }
return q, i, p, pi return q, i
} }
func (t *Tree) underflow(p *x, q *d, pi int) { func (t *Tree) underflow(p *x, q *d, pi int) {
......
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