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