Commit 4efd872d authored by Kirill Smelkov's avatar Kirill Smelkov

X find -> find + findX

parent eca71390
...@@ -211,9 +211,10 @@ loop: ...@@ -211,9 +211,10 @@ loop:
break break
} }
i, ok = t.find(q, k)
switch x := q.(type) { switch x := q.(type) {
case *x: case *x:
i, ok = t.findX(x, k)
hitPKmin = hitKmin hitPKmin = hitKmin
hitPKmax = hitKmax hitPKmax = hitKmax
hitPKminSet = hitKminSet hitPKminSet = hitKminSet
...@@ -246,6 +247,8 @@ loop: ...@@ -246,6 +247,8 @@ loop:
} }
case *d: case *d:
i, ok = t.find(x, k)
switch op { switch op {
case opGet: case opGet:
// tried to search for key > max k in x // tried to search for key > max k in x
......
...@@ -378,9 +378,9 @@ func (t *Tree) Delete(k interface{} /*K*/) (ok bool) { ...@@ -378,9 +378,9 @@ func (t *Tree) Delete(k interface{} /*K*/) (ok bool) {
t.hitPKminSet, t.hitPKmaxSet = false, false t.hitPKminSet, t.hitPKmaxSet = false, false
for { for {
i, ok := t.find(q, k)
switch x := q.(type) { switch x := q.(type) {
case *x: case *x:
i, ok := t.findX(x, k)
if ok { if ok {
i++ i++
} }
...@@ -408,6 +408,8 @@ func (t *Tree) Delete(k interface{} /*K*/) (ok bool) { ...@@ -408,6 +408,8 @@ func (t *Tree) Delete(k interface{} /*K*/) (ok bool) {
} }
case *d: case *d:
i, ok := t.find(x, k)
// data page found - perform the delete // data page found - perform the delete
t.hitP = p t.hitP = p
t.hitPi = pi t.hitPi = pi
...@@ -461,37 +463,35 @@ func (t *Tree) extract(q *d, i int) { // (r interface{} /*V*/) { ...@@ -461,37 +463,35 @@ func (t *Tree) extract(q *d, i int) { // (r interface{} /*V*/) {
return return
} }
func (t *Tree) find(q interface{}, k interface{} /*K*/) (i int, ok bool) { func (t *Tree) findX(x *x, k interface{} /*K*/) (i int, ok bool) {
var mk interface{} /*K*/
l := 0 l := 0
switch x := q.(type) { h := x.c - 1
case *x: for l <= h {
h := x.c - 1 m := (l + h) >> 1
for l <= h { switch cmp := t.cmp(k, x.x[m].k); {
m := (l + h) >> 1 case cmp > 0:
mk = x.x[m].k l = m + 1
switch cmp := t.cmp(k, mk); { case cmp == 0:
case cmp > 0: return m, true
l = m + 1 default:
case cmp == 0: h = m - 1
return m, true
default:
h = m - 1
}
} }
case *d: }
h := x.c - 1 return l, false
for l <= h { }
m := (l + h) >> 1
mk = x.d[m].k func (t *Tree) find(x *d, k interface{} /*K*/) (i int, ok bool) {
switch cmp := t.cmp(k, mk); { l := 0
case cmp > 0: h := x.c - 1
l = m + 1 for l <= h {
case cmp == 0: m := (l + h) >> 1
return m, true switch cmp := t.cmp(k, x.d[m].k); {
default: case cmp > 0:
h = m - 1 l = m + 1
} case cmp == 0:
return m, true
default:
h = m - 1
} }
} }
return l, false return l, false
...@@ -570,21 +570,20 @@ func (t *Tree) Get(k interface{} /*K*/) (v interface{} /*V*/, ok bool) { ...@@ -570,21 +570,20 @@ func (t *Tree) Get(k interface{} /*K*/) (v interface{} /*V*/, ok bool) {
} }
for { for {
var i int
if i, ok = t.find(q, k); ok {
switch x := q.(type) {
case *x:
q = x.x[i+1].ch
continue
case *d:
return x.d[i].v, true
}
}
switch x := q.(type) { switch x := q.(type) {
case *x: case *x:
i, ok := t.findX(x, k)
if ok {
i++
}
q = x.x[i].ch q = x.x[i].ch
default:
return case *d:
i, ok := t.find(x, k)
if ok {
return x.d[i].v, true
}
return v, ok
} }
} }
} }
...@@ -670,22 +669,17 @@ func (t *Tree) Seek(k interface{} /*K*/) (e *Enumerator, ok bool) { ...@@ -670,22 +669,17 @@ func (t *Tree) Seek(k interface{} /*K*/) (e *Enumerator, ok bool) {
} }
for { for {
var i int
if i, ok = t.find(q, k); ok {
switch x := q.(type) {
case *x:
q = x.x[i+1].ch
continue
case *d:
return btEPool.get(nil, ok, i, k, x, t, t.ver), true
}
}
switch x := q.(type) { switch x := q.(type) {
case *x: case *x:
i, ok := t.findX(x, k)
if ok {
i++
}
q = x.x[i].ch q = x.x[i].ch
case *d: case *d:
return btEPool.get(nil, ok, i, k, x, t, t.ver), false i, ok := t.find(x, k)
return btEPool.get(nil, ok, i, k, x, t, t.ver), ok
} }
} }
} }
...@@ -764,9 +758,9 @@ func (t *Tree) Set(k interface{} /*K*/, v interface{} /*V*/) { ...@@ -764,9 +758,9 @@ func (t *Tree) Set(k interface{} /*K*/, v interface{} /*V*/) {
t.hitPKminSet, t.hitPKmaxSet = false, false t.hitPKminSet, t.hitPKmaxSet = false, false
for { for {
i, ok := t.find(q, k)
switch x := q.(type) { switch x := q.(type) {
case *x: case *x:
i, ok := t.findX(x, k)
if ok { if ok {
i++ i++
} }
...@@ -794,6 +788,8 @@ func (t *Tree) Set(k interface{} /*K*/, v interface{} /*V*/) { ...@@ -794,6 +788,8 @@ func (t *Tree) Set(k interface{} /*K*/, v interface{} /*V*/) {
} }
case *d: case *d:
i, ok := t.find(x, k)
// data page found - perform the update // data page found - perform the update
t.hitP = p t.hitP = p
t.hitPi = pi t.hitPi = pi
...@@ -904,9 +900,9 @@ func (t *Tree) Put(k interface{} /*K*/, upd func(oldV interface{} /*V*/, exists ...@@ -904,9 +900,9 @@ func (t *Tree) Put(k interface{} /*K*/, upd func(oldV interface{} /*V*/, exists
t.hitPKminSet, t.hitPKmaxSet = false, false t.hitPKminSet, t.hitPKmaxSet = false, false
for { for {
i, ok := t.find(q, k)
switch x := q.(type) { switch x := q.(type) {
case *x: case *x:
i, ok := t.findX(x, k)
if ok { if ok {
i++ i++
} }
...@@ -934,6 +930,8 @@ func (t *Tree) Put(k interface{} /*K*/, upd func(oldV interface{} /*V*/, exists ...@@ -934,6 +930,8 @@ func (t *Tree) Put(k interface{} /*K*/, upd func(oldV interface{} /*V*/, exists
} }
case *d: case *d:
i, ok := t.find(x, k)
// data page found - perform the update // data page found - perform the update
t.hitP = p t.hitP = p
t.hitPi = pi t.hitPi = pi
......
...@@ -378,9 +378,9 @@ func (t *Tree) Delete(k int) (ok bool) { ...@@ -378,9 +378,9 @@ func (t *Tree) Delete(k int) (ok bool) {
t.hitPKminSet, t.hitPKmaxSet = false, false t.hitPKminSet, t.hitPKmaxSet = false, false
for { for {
i, ok := t.find(q, k)
switch x := q.(type) { switch x := q.(type) {
case *x: case *x:
i, ok := t.findX(x, k)
if ok { if ok {
i++ i++
} }
...@@ -408,6 +408,8 @@ func (t *Tree) Delete(k int) (ok bool) { ...@@ -408,6 +408,8 @@ func (t *Tree) Delete(k int) (ok bool) {
} }
case *d: case *d:
i, ok := t.find(x, k)
// data page found - perform the delete // data page found - perform the delete
t.hitP = p t.hitP = p
t.hitPi = pi t.hitPi = pi
...@@ -461,37 +463,35 @@ func (t *Tree) extract(q *d, i int) { // (r int) { ...@@ -461,37 +463,35 @@ func (t *Tree) extract(q *d, i int) { // (r int) {
return return
} }
func (t *Tree) find(q interface{}, k int) (i int, ok bool) { func (t *Tree) findX(x *x, k int) (i int, ok bool) {
var mk int
l := 0 l := 0
switch x := q.(type) { h := x.c - 1
case *x: for l <= h {
h := x.c - 1 m := (l + h) >> 1
for l <= h { switch cmp := t.cmp(k, x.x[m].k); {
m := (l + h) >> 1 case cmp > 0:
mk = x.x[m].k l = m + 1
switch cmp := t.cmp(k, mk); { case cmp == 0:
case cmp > 0: return m, true
l = m + 1 default:
case cmp == 0: h = m - 1
return m, true
default:
h = m - 1
}
} }
case *d: }
h := x.c - 1 return l, false
for l <= h { }
m := (l + h) >> 1
mk = x.d[m].k func (t *Tree) find(x *d, k int) (i int, ok bool) {
switch cmp := t.cmp(k, mk); { l := 0
case cmp > 0: h := x.c - 1
l = m + 1 for l <= h {
case cmp == 0: m := (l + h) >> 1
return m, true switch cmp := t.cmp(k, x.d[m].k); {
default: case cmp > 0:
h = m - 1 l = m + 1
} case cmp == 0:
return m, true
default:
h = m - 1
} }
} }
return l, false return l, false
...@@ -570,21 +570,20 @@ func (t *Tree) Get(k int) (v int, ok bool) { ...@@ -570,21 +570,20 @@ func (t *Tree) Get(k int) (v int, ok bool) {
} }
for { for {
var i int
if i, ok = t.find(q, k); ok {
switch x := q.(type) {
case *x:
q = x.x[i+1].ch
continue
case *d:
return x.d[i].v, true
}
}
switch x := q.(type) { switch x := q.(type) {
case *x: case *x:
i, ok := t.findX(x, k)
if ok {
i++
}
q = x.x[i].ch q = x.x[i].ch
default:
return case *d:
i, ok := t.find(x, k)
if ok {
return x.d[i].v, true
}
return v, ok
} }
} }
} }
...@@ -670,22 +669,17 @@ func (t *Tree) Seek(k int) (e *Enumerator, ok bool) { ...@@ -670,22 +669,17 @@ func (t *Tree) Seek(k int) (e *Enumerator, ok bool) {
} }
for { for {
var i int
if i, ok = t.find(q, k); ok {
switch x := q.(type) {
case *x:
q = x.x[i+1].ch
continue
case *d:
return btEPool.get(nil, ok, i, k, x, t, t.ver), true
}
}
switch x := q.(type) { switch x := q.(type) {
case *x: case *x:
i, ok := t.findX(x, k)
if ok {
i++
}
q = x.x[i].ch q = x.x[i].ch
case *d: case *d:
return btEPool.get(nil, ok, i, k, x, t, t.ver), false i, ok := t.find(x, k)
return btEPool.get(nil, ok, i, k, x, t, t.ver), ok
} }
} }
} }
...@@ -764,9 +758,9 @@ func (t *Tree) Set(k int, v int) { ...@@ -764,9 +758,9 @@ func (t *Tree) Set(k int, v int) {
t.hitPKminSet, t.hitPKmaxSet = false, false t.hitPKminSet, t.hitPKmaxSet = false, false
for { for {
i, ok := t.find(q, k)
switch x := q.(type) { switch x := q.(type) {
case *x: case *x:
i, ok := t.findX(x, k)
if ok { if ok {
i++ i++
} }
...@@ -794,6 +788,8 @@ func (t *Tree) Set(k int, v int) { ...@@ -794,6 +788,8 @@ func (t *Tree) Set(k int, v int) {
} }
case *d: case *d:
i, ok := t.find(x, k)
// data page found - perform the update // data page found - perform the update
t.hitP = p t.hitP = p
t.hitPi = pi t.hitPi = pi
...@@ -904,9 +900,9 @@ func (t *Tree) Put(k int, upd func(oldV int, exists bool) (newV int, write bool) ...@@ -904,9 +900,9 @@ func (t *Tree) Put(k int, upd func(oldV int, exists bool) (newV int, write bool)
t.hitPKminSet, t.hitPKmaxSet = false, false t.hitPKminSet, t.hitPKmaxSet = false, false
for { for {
i, ok := t.find(q, k)
switch x := q.(type) { switch x := q.(type) {
case *x: case *x:
i, ok := t.findX(x, k)
if ok { if ok {
i++ i++
} }
...@@ -934,6 +930,8 @@ func (t *Tree) Put(k int, upd func(oldV int, exists bool) (newV int, write bool) ...@@ -934,6 +930,8 @@ func (t *Tree) Put(k int, upd func(oldV int, exists bool) (newV int, write bool)
} }
case *d: case *d:
i, ok := t.find(x, k)
// data page found - perform the update // data page found - perform the update
t.hitP = p t.hitP = p
t.hitPi = pi t.hitPi = pi
......
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