Commit 050650f2 authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent 7ce1eb75
...@@ -39,7 +39,7 @@ type btTpool struct{ sync.Pool } ...@@ -39,7 +39,7 @@ type btTpool struct{ sync.Pool }
func (p *btTpool) get(cmp Cmp) *Tree { func (p *btTpool) get(cmp Cmp) *Tree {
x := p.Get().(*Tree) x := p.Get().(*Tree)
x.cmp = cmp x.cmp = cmp
//x.hitIdx = -1 //x.hitDi = -1
//x.hitPi = -1 //x.hitPi = -1
//x.hitMinKMInf = true //x.hitMinKMInf = true
//x.hitMaxKInf = true //x.hitMaxKInf = true
...@@ -104,8 +104,8 @@ type ( ...@@ -104,8 +104,8 @@ type (
// last data page which Set/Put/Delete/XXX recheck modified // last data page which Set/Put/Delete/XXX recheck modified
// XXX naming // XXX naming
hit *d hitD *d
hitIdx int hitDi int
hitKmin xkey hitKmin xkey
hitKmax xkey hitKmax xkey
...@@ -128,15 +128,15 @@ type ( ...@@ -128,15 +128,15 @@ type (
x [2*kx + 2]xe x [2*kx + 2]xe
} }
xkey struct { // key + whether value is present xkey struct { // key + whether value is present at all
k interface {} /*K*/ k interface {} /*K*/
kset bool // if not set - k not present kset bool // if not set - k not present
} }
keyrange struct { // key range [kmin, kmax) //keyrange struct { // key range [kmin, kmax)
kmin xkey // if not set = -∞ // kmin xkey // if not set = -∞
kmax xkey // if not set = +∞ // kmax xkey // if not set = +∞
} //}
) )
var ( // R/O zero values var ( // R/O zero values
...@@ -245,7 +245,7 @@ func (t *Tree) Clear() { ...@@ -245,7 +245,7 @@ func (t *Tree) Clear() {
clr(t.r) clr(t.r)
t.c, t.first, t.last, t.r = 0, nil, nil, nil t.c, t.first, t.last, t.r = 0, nil, nil, nil
// TODO reset .hit // TODO reset .hitD
t.ver++ t.ver++
} }
...@@ -446,15 +446,15 @@ func (t *Tree) find2(d *d, k interface{} /*K*/, l, h int) (i int, ok bool) { ...@@ -446,15 +446,15 @@ func (t *Tree) find2(d *d, k interface{} /*K*/, l, h int) (i int, ok bool) {
// hitFind returns whether k belongs to previosly hit data page XXX text // hitFind returns whether k belongs to previosly hit data page XXX text
// if no -1, false is returned // if no -1, false is returned
// if yes returned are: // if yes returned are:
// - i: index corresponding to data entry in t.hit with min(k' : k' >= k) // - i: index corresponding to data entry in t.hitD with min(k' : k' >= k)
// - ok: whether k' == k // - ok: whether k' == k
func (t *Tree) hitFind(k interface{} /*K*/) (i int, ok bool) { func (t *Tree) hitFind(k interface{} /*K*/) (i int, ok bool) {
hit := t.hit hit := t.hitD
if hit == nil { if hit == nil {
return -1, false return -1, false
} }
i = t.hitIdx i = t.hitDi
//p := t.hitP //p := t.hitP
//pi := t.hitPi //pi := t.hitPi
...@@ -546,8 +546,8 @@ func (t *Tree) insert(q *d, i int, k interface{} /*K*/, v interface{} /*V*/) *d ...@@ -546,8 +546,8 @@ func (t *Tree) insert(q *d, i int, k interface{} /*K*/, v interface{} /*V*/) *d
q.c = c q.c = c
q.d[i].k, q.d[i].v = k, v q.d[i].k, q.d[i].v = k, v
t.c++ t.c++
t.hit = q t.hitD = q
t.hitIdx = i t.hitDi = i
return q return q
} }
...@@ -670,7 +670,7 @@ func (t *Tree) SeekLast() (e *Enumerator, err error) { ...@@ -670,7 +670,7 @@ 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))\n%s", k, v, t.hit, t.hitIdx, t.hitKmin, t.hitKmax, t.dump()) //dbg("--- PRE Set(%v, %v)\t(%v @%d, [%v, %v))\n%s", k, v, t.hitD, t.hitDi, t.hitKmin, t.hitKmax, t.dump())
//defer func() { //defer func() {
// //if r := recover(); r != nil { // //if r := recover(); r != nil {
// // panic(r) // // panic(r)
...@@ -682,14 +682,14 @@ func (t *Tree) Set(k interface{} /*K*/, v interface{} /*V*/) { ...@@ -682,14 +682,14 @@ func (t *Tree) Set(k interface{} /*K*/, v interface{} /*V*/) {
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, p, pi := t.hit, t.hitP, t.hitPi //dd, p, pi := t.hitD, t.hitP, t.hitPi
dd := t.hit dd := t.hitD
switch { switch {
case ok: case ok:
//dbg("ok'") //dbg("ok'")
dd.d[i].v = v dd.d[i].v = v
t.hitIdx = i t.hitDi = i
return return
case dd.c < 2*kd: case dd.c < 2*kd:
...@@ -697,6 +697,7 @@ func (t *Tree) Set(k interface{} /*K*/, v interface{} /*V*/) { ...@@ -697,6 +697,7 @@ func (t *Tree) Set(k interface{} /*K*/, v interface{} /*V*/) {
t.insert(dd, i, k, v) t.insert(dd, i, k, v)
return return
// XXX reenable overflow here
//case p == nil || p.c <= 2*kx: //case p == nil || p.c <= 2*kx:
// dbg("overflow'") // dbg("overflow'")
// t.overflow(p, dd, pi, i, k, v) // t.overflow(p, dd, pi, i, k, v)
...@@ -712,7 +713,6 @@ func (t *Tree) Set(k interface{} /*K*/, v interface{} /*V*/) { ...@@ -712,7 +713,6 @@ func (t *Tree) Set(k interface{} /*K*/, v interface{} /*V*/) {
pi := -1 pi := -1
var p *x var p *x
q := t.r q := t.r
if q == nil { if q == nil {
//dbg("empty") //dbg("empty")
z := t.insert(btDPool.Get().(*d), 0, k, v) // XXX update hit z := t.insert(btDPool.Get().(*d), 0, k, v) // XXX update hit
...@@ -767,7 +767,7 @@ func (t *Tree) Set(k interface{} /*K*/, v interface{} /*V*/) { ...@@ -767,7 +767,7 @@ func (t *Tree) Set(k interface{} /*K*/, v interface{} /*V*/) {
case ok: case ok:
//dbg("ok") //dbg("ok")
x.d[i].v = v x.d[i].v = v
t.hit, t.hitIdx = x, i t.hitD, t.hitDi = x, i
case x.c < 2*kd: case x.c < 2*kd:
//dbg("insert") //dbg("insert")
...@@ -782,7 +782,6 @@ func (t *Tree) Set(k interface{} /*K*/, v interface{} /*V*/) { ...@@ -782,7 +782,6 @@ func (t *Tree) Set(k interface{} /*K*/, v interface{} /*V*/) {
return return
} }
} }
} }
// Put combines Get and Set in a more efficient way where the tree is walked // Put combines Get and Set in a more efficient way where the tree is walked
...@@ -814,7 +813,7 @@ func (t *Tree) Put(k interface{} /*K*/, upd func(oldV interface{} /*V*/, exists ...@@ -814,7 +813,7 @@ func (t *Tree) Put(k interface{} /*K*/, upd func(oldV interface{} /*V*/, exists
return return
} }
// TODO handle t.hit // TODO handle t.hitD
for { for {
i, ok := t.find(q, k) i, ok := t.find(q, k)
...@@ -978,14 +977,14 @@ func (t *Tree) underflow(p *x, q *d, pi int) { ...@@ -978,14 +977,14 @@ func (t *Tree) underflow(p *x, q *d, pi int) {
if l != nil && l.c+q.c >= 2*kd { if l != nil && l.c+q.c >= 2*kd {
l.mvR(q, 1) l.mvR(q, 1)
// TODO update t.hit = q @ i // TODO update t.hitD = q @ i
p.x[pi-1].k = q.d[0].k p.x[pi-1].k = q.d[0].k
return return
} }
if r != nil && q.c+r.c >= 2*kd { if r != nil && q.c+r.c >= 2*kd {
q.mvL(r, 1) q.mvL(r, 1)
// TODO update t.hit = q @ i // TODO update t.hitD = q @ i
p.x[pi].k = r.d[0].k p.x[pi].k = r.d[0].k
r.d[r.c] = zde // GC r.d[r.c] = zde // GC
return return
......
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