Commit db65b87d authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent 6c37f3b3
......@@ -18,6 +18,7 @@ import (
"context"
"sort"
"lab.nexedi.com/kirr/go123/xerr"
//"lab.nexedi.com/kirr/neo/go/zodb"
pickle "github.com/kisielk/og-rek"
)
......@@ -73,9 +74,12 @@ type ZBTree struct {
// Get searches BTree by key.
//
// It loads intermediate BTree nodes from database on demand as needed.
// XXX ok -> ErrKeyNotFound?
func (t *ZBTree) Get(ctx context.Context, key KEY) (interface{}, bool, error) {
t.PActivate(ctx) // XXX err
func (t *ZBTree) Get(ctx context.Context, key KEY) (_ interface{}, _ bool, err error) {
defer xerr.Contextf(&err, "btree(%s): get %s") // XXX + url?
err = t.PActivate(ctx)
if err != nil {
return nil, false, err
}
if len(t.data) == 0 {
// empty btree
......@@ -97,24 +101,35 @@ func (t *ZBTree) Get(ctx context.Context, key KEY) (interface{}, bool, error) {
case *ZBTree:
t.PDeactivate()
t = child
t.PActivate(ctx) // XXX err
err = t.PActivate(ctx)
if err != nil {
return nil, false, err
}
case *ZBucket:
t.PDeactivate()
child.PActivate(ctx) // XXX err
v, ok := child.get(key)
child.PDeactivate()
return v, ok, nil
return child.Get(ctx, key)
}
}
}
// Get searches Bucket by key.
func (b *ZBucket) Get(ctx context.Context, key KEY) (_ interface{}, _ bool, err error) {
defer xerr.Contextf(&err, "bucket(%s): get %s") // XXX + url?
err = b.PActivate(ctx)
if err != nil {
return nil, false, err
}
v, ok := b.get(key)
b.PDeactivate()
return v, ok, nil
}
// get searches Bucket by key.
//
// no loading from database is done. The bucket must be already activated.
func (b *ZBucket) get(key KEY) (interface{}, bool) {
// XXX b.PActivate ? XXX better caller? (or inside if get -> Get)
// search i: K(i-1) < k ≤ K(i) ; K(-1) = -∞, K(len) = +∞
i := sort.Search(len(b.keys), func(i int) bool {
return key <= b.keys[i]
......
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