Commit 1eca15f8 authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent 6977a8c2
...@@ -223,13 +223,13 @@ func TestSetGet0(t *testing.T) { ...@@ -223,13 +223,13 @@ func TestSetGet0(t *testing.T) {
} }
func TestSetGet1(t *testing.T) { func TestSetGet1(t *testing.T) {
//const N = 40000 const N = 40000
//const N = 21 //const N = 21
//const N = 41 //const N = 41
//const N = 320 //const N = 320
const N = 730 //const N = 730
//for _, x := range []int{0, -1, 0x555555, 0xaaaaaa, 0x333333, 0xcccccc, 0x314159} { for _, x := range []int{0, -1, 0x555555, 0xaaaaaa, 0x333333, 0xcccccc, 0x314159} {
for _, x := range []int{0x333333} { //for _, x := range []int{0x333333} {
//for _, x := range []int{0x314159} { //for _, x := range []int{0x314159} {
//for _, x := range []int{0} { //for _, x := range []int{0} {
r := TreeNew(cmp) r := TreeNew(cmp)
......
...@@ -655,7 +655,7 @@ func (t *Tree) SeekLast() (e *Enumerator, err error) { ...@@ -655,7 +655,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) 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 func() { defer func() {
badHappenned := false badHappenned := false
bad := func(s string, va ...interface{}) { bad := func(s string, va ...interface{}) {
...@@ -663,7 +663,7 @@ func (t *Tree) Set(k interface{} /*K*/, v interface{} /*V*/) { ...@@ -663,7 +663,7 @@ func (t *Tree) Set(k interface{} /*K*/, v interface{} /*V*/) {
badHappenned = true badHappenned = true
} }
println() //println()
if t.hitDi >= 0 { if t.hitDi >= 0 {
if t.hitD.d[t.hitDi].k != k { if t.hitD.d[t.hitDi].k != k {
...@@ -767,9 +767,9 @@ func (t *Tree) Set(k interface{} /*K*/, v interface{} /*V*/) { ...@@ -767,9 +767,9 @@ func (t *Tree) Set(k interface{} /*K*/, v interface{} /*V*/) {
} }
}() }()
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
...@@ -780,13 +780,13 @@ func (t *Tree) Set(k interface{} /*K*/, v interface{} /*V*/) { ...@@ -780,13 +780,13 @@ func (t *Tree) Set(k interface{} /*K*/, v interface{} /*V*/) {
switch { switch {
case ok: case ok:
dbg("ok'") //dbg("ok'")
dd.d[i].v = v dd.d[i].v = v
t.hitDi = i t.hitDi = i
return return
case dd.c < 2*kd: case dd.c < 2*kd:
dbg("insert'") //dbg("insert'")
t.insert(dd, i, k, v) t.insert(dd, i, k, v)
return return
...@@ -797,7 +797,7 @@ func (t *Tree) Set(k interface{} /*K*/, v interface{} /*V*/) { ...@@ -797,7 +797,7 @@ func (t *Tree) Set(k interface{} /*K*/, v interface{} /*V*/) {
//break //break
p, pi := t.hitP, t.hitPi p, pi := t.hitP, t.hitPi
if p == nil || p.c <= 2*kx { // XXX < vs <= if p == nil || p.c <= 2*kx { // XXX < vs <=
dbg("overflow'") //dbg("overflow'")
t.overflow(p, dd, pi, i, k, v) t.overflow(p, dd, pi, i, k, v)
return return
} }
...@@ -809,7 +809,7 @@ func (t *Tree) Set(k interface{} /*K*/, v interface{} /*V*/) { ...@@ -809,7 +809,7 @@ func (t *Tree) Set(k interface{} /*K*/, v interface{} /*V*/) {
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
t.r, t.first, t.last = z, z, z t.r, t.first, t.last = z, z, z
return return
...@@ -826,18 +826,18 @@ func (t *Tree) Set(k interface{} /*K*/, v interface{} /*V*/) { ...@@ -826,18 +826,18 @@ func (t *Tree) Set(k interface{} /*K*/, v interface{} /*V*/) {
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)
dbg("splitX") //dbg("splitX")
x, i, p, pi = t.splitX(p, x, pi, i) x, i, p, pi = t.splitX(p, x, pi, i)
// NOTE splitX changes p // NOTE splitX changes p
if pi >= 0 && pi < p.c { if pi >= 0 && pi < p.c {
hitPKmax.set(p.x[pi].k) hitPKmax.set(p.x[pi].k)
dbg("hitPKmax X: %v", hitPKmax) //dbg("hitPKmax X: %v", hitPKmax)
} }
if pi > 0 { if pi > 0 {
hitKmin.set(p.x[pi-1].k) hitKmin.set(p.x[pi-1].k)
dbg("hitKmin X: %v", hitKmin) //dbg("hitKmin X: %v", hitKmin)
} }
} else { } else {
// p unchanged // p unchanged
...@@ -854,12 +854,12 @@ func (t *Tree) Set(k interface{} /*K*/, v interface{} /*V*/) { ...@@ -854,12 +854,12 @@ func (t *Tree) Set(k interface{} /*K*/, v interface{} /*V*/) {
if pi > 0 { // XXX also check < p.c ? if pi > 0 { // XXX also check < p.c ?
hitKmin.set(p.x[pi-1].k) hitKmin.set(p.x[pi-1].k)
dbg("hitKmin: %v", hitKmin) //dbg("hitKmin: %v", hitKmin)
} }
if pi < p.c { if pi < p.c {
hitKmax.set(p.x[pi].k) hitKmax.set(p.x[pi].k)
dbg("hitKmax: %v", hitKmax) //dbg("hitKmax: %v", hitKmax)
} }
...@@ -873,16 +873,16 @@ func (t *Tree) Set(k interface{} /*K*/, v interface{} /*V*/) { ...@@ -873,16 +873,16 @@ func (t *Tree) Set(k interface{} /*K*/, v interface{} /*V*/) {
switch { switch {
case ok: case ok:
dbg("ok") //dbg("ok")
x.d[i].v = v x.d[i].v = v
t.hitD, t.hitDi = x, i t.hitD, t.hitDi = x, i
case x.c < 2*kd: case x.c < 2*kd:
dbg("insert") //dbg("insert")
t.insert(x, i, k, v) t.insert(x, i, k, v)
default: default:
dbg("overflow") //dbg("overflow")
// NOTE overflow will correct hit Kmin, Kmax, P and Pi as needed // NOTE overflow will correct hit Kmin, Kmax, P and Pi as needed
t.overflow(p, x, pi, i, k, v) t.overflow(p, x, pi, i, k, v)
} }
......
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