Commit 232e9671 authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent a8edaa30
...@@ -415,12 +415,11 @@ func (t *Tree) find2(d *d, k interface{} /*K*/, l, h int) (i int, ok bool) { ...@@ -415,12 +415,11 @@ func (t *Tree) find2(d *d, k interface{} /*K*/, l, h int) (i int, ok bool) {
return l, false return l, false
} }
// hitTest 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.hit with min(k' : k' >= k)
// - ok: whether k' == k // - ok: whether k' == k
// XXX -> hitFind
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.hit
if hit == nil { if hit == nil {
...@@ -502,7 +501,6 @@ func (t *Tree) Get(k interface{} /*K*/) (v interface{} /*V*/, ok bool) { ...@@ -502,7 +501,6 @@ func (t *Tree) Get(k interface{} /*K*/) (v interface{} /*V*/, ok bool) {
} }
func (t *Tree) insert(q *d, i int, k interface{} /*K*/, v interface{} /*V*/) *d { func (t *Tree) insert(q *d, i int, k interface{} /*K*/, v interface{} /*V*/) *d {
// TODO update hit
t.ver++ t.ver++
c := q.c c := q.c
if i < c { if i < c {
...@@ -512,6 +510,8 @@ func (t *Tree) insert(q *d, i int, k interface{} /*K*/, v interface{} /*V*/) *d ...@@ -512,6 +510,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 = d
t.hitIdx = i
return q return q
} }
...@@ -532,12 +532,14 @@ func (t *Tree) Len() int { ...@@ -532,12 +532,14 @@ func (t *Tree) Len() int {
func (t *Tree) overflow(p *x, q *d, pi, i int, k interface{} /*K*/, v interface{} /*V*/) { func (t *Tree) overflow(p *x, q *d, pi, i int, k interface{} /*K*/, v interface{} /*V*/) {
t.ver++ t.ver++
t.hitP = p
l, r := p.siblings(pi) l, r := p.siblings(pi)
if l != nil && l.c < 2*kd && i != 0 { if l != nil && l.c < 2*kd && i != 0 {
l.mvL(q, 1) l.mvL(q, 1)
t.insert(q, i-1, k, v) t.insert(q, i-1, k, v)
p.x[pi-1].k = q.d[0].k p.x[pi-1].k = q.d[0].k
t.hitPi = pi
return return
} }
...@@ -546,11 +548,13 @@ func (t *Tree) overflow(p *x, q *d, pi, i int, k interface{} /*K*/, v interface{ ...@@ -546,11 +548,13 @@ func (t *Tree) overflow(p *x, q *d, pi, i int, k interface{} /*K*/, v interface{
q.mvR(r, 1) q.mvR(r, 1)
t.insert(q, i, k, v) t.insert(q, i, k, v)
p.x[pi].k = r.d[0].k p.x[pi].k = r.d[0].k
t.hitPi = pi
return return
} }
t.insert(r, 0, k, v) t.insert(r, 0, k, v)
p.x[pi].k = k p.x[pi].k = k
t.hitPi = pi + 1
return return
} }
...@@ -660,16 +664,19 @@ func (t *Tree) Set(k interface{} /*K*/, v interface{} /*V*/) { ...@@ -660,16 +664,19 @@ func (t *Tree) Set(k interface{} /*K*/, v interface{} /*V*/) {
} }
// data page found - perform the update // data page found - perform the update
if ok {
dd.d[i].v = v
} else {
switch { switch {
case ok:
dd.d[i].v = v
t.hit, t.hitIdx = dd, i
t.hitP, t.hitPi = p, pi
case dd.c < 2*kd: case dd.c < 2*kd:
t.insert(dd, i, k, v) t.insert(dd, i, k, v)
t.hitP, t.hitPi = p, pi
default: default:
t.overflow(p, dd, pi, i, k, v) t.overflow(p, dd, pi, i, k, v)
} }
}
} }
// 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
...@@ -778,6 +785,7 @@ func (t *Tree) split(p *x, q *d, pi, i int, k interface{} /*K*/, v interface{} / ...@@ -778,6 +785,7 @@ func (t *Tree) split(p *x, q *d, pi, i int, k interface{} /*K*/, v interface{} /
if i > kd { if i > kd {
done = true done = true
t.insert(r, i-kd, k, v) t.insert(r, i-kd, k, v)
t.hitPi = pi + 1
} }
if pi >= 0 { if pi >= 0 {
p.insert(pi, r.d[0].k, r) p.insert(pi, r.d[0].k, r)
...@@ -789,6 +797,7 @@ func (t *Tree) split(p *x, q *d, pi, i int, k interface{} /*K*/, v interface{} / ...@@ -789,6 +797,7 @@ func (t *Tree) split(p *x, q *d, pi, i int, k interface{} /*K*/, v interface{} /
} }
t.insert(q, i, k, v) t.insert(q, i, k, v)
t.hitPi = pi
} }
func (t *Tree) splitX(p *x, q *x, pi int, i int) (*x, int) { func (t *Tree) splitX(p *x, q *x, pi int, i int) (*x, 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