Commit a452276d authored by Kirill Smelkov's avatar Kirill Smelkov

X storage/fs1/fsb: regenerate @x/refill

parent fe0f712e
// DO NOT EDIT - AUTOGENERATED (by gen-fsbtree from github.com/cznic/b 4efd872)
// DO NOT EDIT - AUTOGENERATED (by gen-fsbtree from github.com/cznic/b 93348d0)
// KEY=zodb.Oid VALUE=int64
// ---- 8< ----
......@@ -370,6 +370,12 @@ func (t *Tree) Delete(k zodb.Oid) (ok bool) {
}
}
// don't leave previously active data page with < 50% load
if t.hitD != nil && t.hitD.c < kd && t.hitP != nil {
//println("refill")
t.refill(t.hitP, t.hitD, t.hitPi)
}
// data page not quickly found - search and descent from root
pi := -1
var p *x
......@@ -748,6 +754,12 @@ func (t *Tree) Set(k zodb.Oid, v int64) {
}
}
// don't leave previously active data page with < 50% load
if t.hitD != nil && t.hitD.c < kd && t.hitP != nil {
//println("refill")
t.refill(t.hitP, t.hitD, t.hitPi)
}
// data page not quickly found - search and descent from root
pi := -1
var p *x
......@@ -899,6 +911,12 @@ func (t *Tree) Put(k zodb.Oid, upd func(oldV int64, exists bool) (newV int64, wr
}
}
// don't leave previously active data page with < 50% load
if t.hitD != nil && t.hitD.c < kd && t.hitP != nil {
//println("refill")
t.refill(t.hitP, t.hitD, t.hitPi)
}
// data page not quickly found - search and descent from root
t.hitKminSet, t.hitKmaxSet = false, false // initially [-∞, +∞)
t.hitPKminSet, t.hitPKmaxSet = false, false
......@@ -988,13 +1006,19 @@ func (t *Tree) split(p *x, q *d, pi, i int, k zodb.Oid, v int64) {
q.n = r
r.p = q
// don't copy on sequential bulk-set pattern
if i == 2*kd {
t.insert(r, 0, k, v)
} else {
copy(r.d[:], q.d[kd:2*kd])
for i := range q.d[kd:] {
q.d[kd+i] = zde
}
q.c = kd
r.c = kd
}
// XXX vs ^^^ (not adding elements)
if pi >= 0 {
p.insert(pi, r.d[0].k, r)
} else {
......@@ -1006,7 +1030,10 @@ func (t *Tree) split(p *x, q *d, pi, i int, k zodb.Oid, v int64) {
}
if i > kd {
// XXX vvv try to merge with ^^^ t.insert(r, 0, k, v)
if i < 2*kd {
t.insert(r, i-kd, k, v)
}
t.setHitKmin(p.x[pi].k)
if pi+1 < p.c { // k=+∞ @p.c
t.setHitKmax(p.x[pi+1].k)
......@@ -1061,6 +1088,8 @@ func (t *Tree) underflow(p *x, q *d, pi int) {
t.ver++
l, r := p.siblings(pi)
// TODO don't move 1 elements for bulk-delete patterb (see split for bulk-set case)
if l != nil && l.c+q.c >= 2*kd {
l.mvR(q, 1)
p.x[pi-1].k = q.d[0].k
......@@ -1181,6 +1210,47 @@ func (t *Tree) underflowX(p *x, q *x, pi int, i int) (*x, int) {
return q, i
}
// refill refills data page to have >= 50% load taking data entries from siblings
// if siblings have not enough entries for such refill, the data page in question is concatenated into one of them.
// XXX naming -> fillup ?
func (t *Tree) refill(p *x, q *d, pi int) {
t.ver++
l, r := p.siblings(pi)
δl := 0
δr := 0
if l != nil {
δl = l.c - kd
}
if r != nil {
δr = r.c - kd
}
if q.c + δl + δr < kd {
// cannot refill - concatenate into l or r
if l != nil {
t.cat(p, l, q, pi-1)
} else {
t.cat(p, q, r, pi)
}
return
}
// refill from siblings
δ := kd - q.c
δl = δ * δl / (δl + δr)
δr = δ - δl
if δl != 0 {
l.mvR(q, δl)
p.x[pi-1].k = q.d[0].k
}
if δr != 0 {
q.mvL(r, δr)
p.x[pi].k = r.d[0].k
}
}
// ----------------------------------------------------------------- Enumerator
// Close recycles e to a pool for possible later reuse. No references to e
......
// DO NOT EDIT - AUTOGENERATED (by gen-fsbtree from github.com/cznic/b 4efd872)
// DO NOT EDIT - AUTOGENERATED (by gen-fsbtree from github.com/cznic/b 93348d0)
// ---- 8< ----
package fsb
import (
......
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