Commit 5939d29c authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent 6fbd5ad7
...@@ -598,8 +598,8 @@ func TestDelete0(t *testing.T) { ...@@ -598,8 +598,8 @@ func TestDelete0(t *testing.T) {
} }
func TestDelete1(t *testing.T) { func TestDelete1(t *testing.T) {
//const N = 130000 const N = 130000
const N = 40 //const N = 40
for _, x := range []int{0, -1, 0x555555, 0xaaaaaa, 0x333333, 0xcccccc, 0x314159} { for _, x := range []int{0, -1, 0x555555, 0xaaaaaa, 0x333333, 0xcccccc, 0x314159} {
r := TreeNew(cmp) r := TreeNew(cmp)
set := r.Set set := r.Set
...@@ -608,7 +608,8 @@ func TestDelete1(t *testing.T) { ...@@ -608,7 +608,8 @@ func TestDelete1(t *testing.T) {
a[i] = (i ^ x) << 1 a[i] = (i ^ x) << 1
} }
for _, k := range a { for _, k := range a {
set(k, k) set(k, 0)
//set(k, k)
} }
for i, k := range a { for i, k := range a {
......
...@@ -11,10 +11,10 @@ import ( ...@@ -11,10 +11,10 @@ import (
) )
const ( const (
//kx = 32 //TODO benchmark tune this number if using custom key/value type(s). kx = 32 //TODO benchmark tune this number if using custom key/value type(s).
//kd = 32 //TODO benchmark tune this number if using custom key/value type(s). kd = 32 //TODO benchmark tune this number if using custom key/value type(s).
kx = 2 //TODO benchmark tune this number if using custom key/value type(s). //kx = 2 //TODO benchmark tune this number if using custom key/value type(s).
kd = 2 //TODO benchmark tune this number if using custom key/value type(s). //kd = 2 //TODO benchmark tune this number if using custom key/value type(s).
) )
func init() { func init() {
...@@ -620,66 +620,54 @@ func (t *Tree) Set(k interface{} /*K*/, v interface{} /*V*/) { ...@@ -620,66 +620,54 @@ func (t *Tree) Set(k interface{} /*K*/, v interface{} /*V*/) {
pi := -1 pi := -1
var p *x var p *x
var dd *d // XXX naming var dd *d // XXX naming
q := t.r
if q == nil {
z := t.insert(btDPool.Get().(*d), 0, k, v) // XXX update hit
t.r, t.first, t.last = z, z, z
return
}
// check if we can do the update nearby previous change // check if we can do the update nearby previous change
i, ok := t.hitFind(k) i, ok := t.hitFind(k)
if i >= 0 { if i >= 0 {
println("NEVER")
println("NEVER")
println("NEVER")
dd, p, pi = t.hit, t.hitP, t.hitPi dd, p, pi = t.hit, t.hitP, t.hitPi
}
for {
// data page found
if dd != nil {
if ok {
dd.d[i].v = v
} else {
switch {
case dd.c < 2*kd:
t.insert(dd, i, k, v)
default:
t.overflow(p, dd, pi, i, k, v)
}
}
// data page not found yet - search and descent
} else {
q := t.r
if q == nil {
z := t.insert(btDPool.Get().(*d), 0, k, v) // XXX update hit
t.r, t.first, t.last = z, z, z
return return
} }
// data page not found yet - sarch and descent loop:
i, ok = t.find(q, k) for {
if ok { i, ok = t.find(q, k)
switch x := q.(type) { switch x := q.(type) {
case *x: case *x:
if x.c > 2*kx { if x.c > 2*kx {
x, i = t.splitX(p, x, pi, i) x, i = t.splitX(p, x, pi, i)
} }
pi = i + 1
p = x p = x
q = x.x[i+1].ch if ok {
pi = i + 1
q = x.x[i+1].ch
} else {
pi = i
q = x.x[i].ch
}
case *d: case *d:
dd = x dd = x
break loop
} }
continue
} }
}
switch x := q.(type) { // data page found - perform the update
case *x: if ok {
if x.c > 2*kx { dd.d[i].v = v
x, i = t.splitX(p, x, pi, i) } else {
} switch {
pi = i case dd.c < 2*kd:
p = x t.insert(dd, i, k, v)
q = x.x[i].ch default:
case *d: t.overflow(p, dd, pi, i, k, v)
dd = x
} }
} }
} }
......
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