Commit d0a62510 authored by Kirill Smelkov's avatar Kirill Smelkov

go/zodb/btree: Switch Entry.child to IPersistent

It is either BTree or Bucket.
parent 14dee52f
......@@ -61,7 +61,7 @@ type BTree struct {
// Key limits child's keys - see BTree.Entryv for details.
type Entry struct {
key KEY
child interface{} // BTree or Bucket
child zodb.IPersistent // BTree or Bucket
}
// Bucket is a leaf node of a B⁺ tree.
......@@ -99,7 +99,7 @@ type BucketEntry struct {
func (e *Entry) Key() KEY { return e.key }
// Child returns BTree entry child.
func (e *Entry) Child() interface{} { return e.child }
func (e *Entry) Child() zodb.IPersistent { return e.child }
// Entryv returns entries of a BTree node.
//
......@@ -175,18 +175,21 @@ func (t *BTree) Get(ctx context.Context, key KEY) (_ interface{}, _ bool, err er
return key < t.data[j].key
})
switch child := t.data[i].child.(type) {
case *BTree:
child := t.data[i].child
t.PDeactivate()
t = child
err = t.PActivate(ctx)
err = child.PActivate(ctx)
if err != nil {
return nil, false, err
}
switch child := child.(type) {
case *BTree:
t = child
case *Bucket:
t.PDeactivate()
return child.Get(ctx, key)
v, ok, err := child.Get(ctx, key)
child.PDeactivate()
return v, ok, err
}
}
}
......@@ -547,7 +550,7 @@ func (bt *btreeState) PySetState(pystate interface{}) (err error) {
fmt.Errorf("data: [%d]: children must be of the same type", i)
}
bt.data = append(bt.data, Entry{key: kkey, child: child})
bt.data = append(bt.data, Entry{key: kkey, child: child.(zodb.IPersistent)})
}
return nil
......
......@@ -63,7 +63,7 @@ type IOBTree struct {
// Key limits child's keys - see IOBTree.Entryv for details.
type IOEntry struct {
key int32
child interface{} // IOBTree or IOBucket
child zodb.IPersistent // IOBTree or IOBucket
}
// IOBucket is a leaf node of a B⁺ tree.
......@@ -101,7 +101,7 @@ type IOBucketEntry struct {
func (e *IOEntry) Key() int32 { return e.key }
// Child returns IOBTree entry child.
func (e *IOEntry) Child() interface{} { return e.child }
func (e *IOEntry) Child() zodb.IPersistent { return e.child }
// Entryv returns entries of a IOBTree node.
//
......@@ -177,18 +177,21 @@ func (t *IOBTree) Get(ctx context.Context, key int32) (_ interface{}, _ bool, er
return key < t.data[j].key
})
switch child := t.data[i].child.(type) {
case *IOBTree:
child := t.data[i].child
t.PDeactivate()
t = child
err = t.PActivate(ctx)
err = child.PActivate(ctx)
if err != nil {
return nil, false, err
}
switch child := child.(type) {
case *IOBTree:
t = child
case *IOBucket:
t.PDeactivate()
return child.Get(ctx, key)
v, ok, err := child.Get(ctx, key)
child.PDeactivate()
return v, ok, err
}
}
}
......@@ -549,7 +552,7 @@ func (bt *iobtreeState) PySetState(pystate interface{}) (err error) {
fmt.Errorf("data: [%d]: children must be of the same type", i)
}
bt.data = append(bt.data, IOEntry{key: kkey, child: child})
bt.data = append(bt.data, IOEntry{key: kkey, child: child.(zodb.IPersistent)})
}
return nil
......
......@@ -63,7 +63,7 @@ type LOBTree struct {
// Key limits child's keys - see LOBTree.Entryv for details.
type LOEntry struct {
key int64
child interface{} // LOBTree or LOBucket
child zodb.IPersistent // LOBTree or LOBucket
}
// LOBucket is a leaf node of a B⁺ tree.
......@@ -101,7 +101,7 @@ type LOBucketEntry struct {
func (e *LOEntry) Key() int64 { return e.key }
// Child returns LOBTree entry child.
func (e *LOEntry) Child() interface{} { return e.child }
func (e *LOEntry) Child() zodb.IPersistent { return e.child }
// Entryv returns entries of a LOBTree node.
//
......@@ -177,18 +177,21 @@ func (t *LOBTree) Get(ctx context.Context, key int64) (_ interface{}, _ bool, er
return key < t.data[j].key
})
switch child := t.data[i].child.(type) {
case *LOBTree:
child := t.data[i].child
t.PDeactivate()
t = child
err = t.PActivate(ctx)
err = child.PActivate(ctx)
if err != nil {
return nil, false, err
}
switch child := child.(type) {
case *LOBTree:
t = child
case *LOBucket:
t.PDeactivate()
return child.Get(ctx, key)
v, ok, err := child.Get(ctx, key)
child.PDeactivate()
return v, ok, err
}
}
}
......@@ -549,7 +552,7 @@ func (bt *lobtreeState) PySetState(pystate interface{}) (err error) {
fmt.Errorf("data: [%d]: children must be of the same type", i)
}
bt.data = append(bt.data, LOEntry{key: kkey, child: child})
bt.data = append(bt.data, LOEntry{key: kkey, child: child.(zodb.IPersistent)})
}
return nil
......
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