Commit af686f0f authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent 3c1df9e8
......@@ -180,8 +180,62 @@ func (t *ZBTree) DropState() {
}
// PySetState implements PyStateful to set btree data from pystate.
func (t *ZBTree) PySetState(pystate interface{}) error {
panic("TODO")
func (bt *ZBTree) PySetState(pystate interface{}) error {
// empty btree
if _, ok := pystate.(pickle.None); ok {
bt.firstbucket = nil
bt.data = nil
return nil
}
t, ok := pystate.(pickle.Tuple)
if !ok || !(1 <= len(t) && len(t) <= 2) {
// XXX
}
// btree with 1 child bucket without oid
if len(t) == 1 {
// TODO
}
// regular btree
t, ok = t[0].(pickle.Tuple)
if !(ok && len(t) % 2 == 0) {
// XXX
}
bt.firstbucket, ok = t[1].(*ZBucket)
if !ok {
// XXX
}
n := len(t) / 2
bt.data = make([]zBTreeItem, 0, n)
for i, idx := 0, 0; i < n; i++ {
key := int64(0)
if i > 0 {
// key[0] is unused and not saved
key, ok = t[idx].(int64) // XXX Xint
if ! ok {
// XXX
}
idx++
}
child := t[idx]
idx++
switch child.(type) {
default:
// XXX
case *ZBTree: // ok
case *ZBucket: // ok
}
bt.data = append(bt.data, zBTreeItem{key: KEY(key), child: child})
}
return nil
}
......@@ -234,11 +288,12 @@ func (b *ZBucket) PySetState(pystate interface{}) error {
xk := t[2*i]
v := t[2*i+1]
k, ok := xk.(int64) // XXX use KEY
k, ok := xk.(int64) // XXX use KEY XXX -> Xint64
if !ok {
// XXX
}
// XXX check keys are sorted?
b.keys = append(b.keys, KEY(k)) // XXX cast
b.values = append(b.values, v)
}
......@@ -249,8 +304,8 @@ func (b *ZBucket) PySetState(pystate interface{}) error {
// ---- register classes to ZODB ----
func bucketNew(pyobj *PyPersistent) IPyPersistent { return &ZBucket{PyPersistent: pyobj} }
func btreeNew(pyobj *PyPersistent) IPyPersistent { return &ZBTree{PyPersistent: pyobj} }
func bucketNew(base *PyPersistent) IPyPersistent { return &ZBucket{PyPersistent: base} }
func btreeNew(base *PyPersistent) IPyPersistent { return &ZBTree{PyPersistent: base} }
func init() {
registerPyClass("zodb.BTree.LOBucket", bucketNew)
......
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