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,16 +463,12 @@ func (t *Tree) extract(q *d, i int) { // (r interface{} /*V*/) { ...@@ -461,16 +463,12 @@ 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) {
case *x:
h := x.c - 1 h := x.c - 1
for l <= h { for l <= h {
m := (l + h) >> 1 m := (l + h) >> 1
mk = x.x[m].k switch cmp := t.cmp(k, x.x[m].k); {
switch cmp := t.cmp(k, mk); {
case cmp > 0: case cmp > 0:
l = m + 1 l = m + 1
case cmp == 0: case cmp == 0:
...@@ -479,12 +477,15 @@ func (t *Tree) find(q interface{}, k interface{} /*K*/) (i int, ok bool) { ...@@ -479,12 +477,15 @@ func (t *Tree) find(q interface{}, k interface{} /*K*/) (i int, ok bool) {
h = m - 1 h = m - 1
} }
} }
case *d: return l, false
}
func (t *Tree) find(x *d, k interface{} /*K*/) (i int, ok bool) {
l := 0
h := x.c - 1 h := x.c - 1
for l <= h { for l <= h {
m := (l + h) >> 1 m := (l + h) >> 1
mk = x.d[m].k switch cmp := t.cmp(k, x.d[m].k); {
switch cmp := t.cmp(k, mk); {
case cmp > 0: case cmp > 0:
l = m + 1 l = m + 1
case cmp == 0: case cmp == 0:
...@@ -493,7 +494,6 @@ func (t *Tree) find(q interface{}, k interface{} /*K*/) (i int, ok bool) { ...@@ -493,7 +494,6 @@ func (t *Tree) find(q interface{}, k interface{} /*K*/) (i int, ok bool) {
h = m - 1 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) { switch x := q.(type) {
case *x: case *x:
q = x.x[i+1].ch i, ok := t.findX(x, k)
continue if ok {
i++
}
q = x.x[i].ch
case *d: case *d:
i, ok := t.find(x, k)
if ok {
return x.d[i].v, true return x.d[i].v, true
} }
} return v, ok
switch x := q.(type) {
case *x:
q = x.x[i].ch
default:
return
} }
} }
} }
...@@ -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) { switch x := q.(type) {
case *x: case *x:
q = x.x[i+1].ch i, ok := t.findX(x, k)
continue if ok {
case *d: i++
return btEPool.get(nil, ok, i, k, x, t, t.ver), true
}
} }
switch x := q.(type) {
case *x:
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,16 +463,12 @@ func (t *Tree) extract(q *d, i int) { // (r int) { ...@@ -461,16 +463,12 @@ 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) {
case *x:
h := x.c - 1 h := x.c - 1
for l <= h { for l <= h {
m := (l + h) >> 1 m := (l + h) >> 1
mk = x.x[m].k switch cmp := t.cmp(k, x.x[m].k); {
switch cmp := t.cmp(k, mk); {
case cmp > 0: case cmp > 0:
l = m + 1 l = m + 1
case cmp == 0: case cmp == 0:
...@@ -479,12 +477,15 @@ func (t *Tree) find(q interface{}, k int) (i int, ok bool) { ...@@ -479,12 +477,15 @@ func (t *Tree) find(q interface{}, k int) (i int, ok bool) {
h = m - 1 h = m - 1
} }
} }
case *d: return l, false
}
func (t *Tree) find(x *d, k int) (i int, ok bool) {
l := 0
h := x.c - 1 h := x.c - 1
for l <= h { for l <= h {
m := (l + h) >> 1 m := (l + h) >> 1
mk = x.d[m].k switch cmp := t.cmp(k, x.d[m].k); {
switch cmp := t.cmp(k, mk); {
case cmp > 0: case cmp > 0:
l = m + 1 l = m + 1
case cmp == 0: case cmp == 0:
...@@ -493,7 +494,6 @@ func (t *Tree) find(q interface{}, k int) (i int, ok bool) { ...@@ -493,7 +494,6 @@ func (t *Tree) find(q interface{}, k int) (i int, ok bool) {
h = m - 1 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) { switch x := q.(type) {
case *x: case *x:
q = x.x[i+1].ch i, ok := t.findX(x, k)
continue if ok {
i++
}
q = x.x[i].ch
case *d: case *d:
i, ok := t.find(x, k)
if ok {
return x.d[i].v, true return x.d[i].v, true
} }
} return v, ok
switch x := q.(type) {
case *x:
q = x.x[i].ch
default:
return
} }
} }
} }
...@@ -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) { switch x := q.(type) {
case *x: case *x:
q = x.x[i+1].ch i, ok := t.findX(x, k)
continue if ok {
case *d: i++
return btEPool.get(nil, ok, i, k, x, t, t.ver), true
}
} }
switch x := q.(type) {
case *x:
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