Commit 10480280 authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent 66d65cc9
......@@ -146,12 +146,77 @@ func (b *Bucket) get(key KEY) (interface{}, bool) {
return b.values[i], true
}
// XXX Bucket.MinKey ?
// XXX Bucket.MaxKey ?
// TODO Bucket.MinKey
// TODO Bucket.MaxKey
// ---- serialization ----
// from https://github.com/zopefoundation/BTrees/blob/4.5.0-1-gc8bf24e/BTrees/BucketTemplate.c#L1195:
//
// For a mapping bucket (self->values is not NULL), a one-tuple or two-tuple.
// The first element is a tuple interleaving keys and values, of length
// 2 * self->len. The second element is the next bucket, present iff next is
// non-NULL:
//
// (
// (keys[0], values[0], keys[1], values[1], ...,
// keys[len-1], values[len-1]),
// <self->next iff non-NULL>
// )
type bucketState Bucket // hide state methods from public API
// DropState implements Stateful to discard bucket state.
func (b *bucketState) DropState() {
b.next = nil
b.keys = nil
b.values = nil
}
// PySetState implements PyStateful to set bucket data from pystate.
func (b *bucketState) PySetState(pystate interface{}) error {
t, ok := pystate.(pickle.Tuple)
if !ok || !(1 <= len(t) && len(t) <= 2) {
// XXX complain
}
// .next present
if len(t) == 2 {
next, ok := t[1].(*Bucket)
if !ok {
// XXX
}
b.next = next
}
// main part
t, ok = t[0].(pickle.Tuple)
// XXX if !ok || (len(t) % 2 != 0)
// reset arrays just in case
n := len(t) / 2
b.keys = make([]KEY, 0, n)
b.values = make([]interface{}, 0, n)
for i := 0; i < n; i++ {
xk := t[2*i]
v := t[2*i+1]
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)
}
return nil
}
// from https://github.com/zopefoundation/BTrees/blob/4.5.0-1-gc8bf24e/BTrees/BTreeTemplate.c#L1087:
//
// For an empty BTree (self->len == 0), None.
......@@ -254,71 +319,6 @@ func (bt *btreeState) PySetState(pystate interface{}) error {
}
// from https://github.com/zopefoundation/BTrees/blob/4.5.0-1-gc8bf24e/BTrees/BucketTemplate.c#L1195:
//
// For a mapping bucket (self->values is not NULL), a one-tuple or two-tuple.
// The first element is a tuple interleaving keys and values, of length
// 2 * self->len. The second element is the next bucket, present iff next is
// non-NULL:
//
// (
// (keys[0], values[0], keys[1], values[1], ...,
// keys[len-1], values[len-1]),
// <self->next iff non-NULL>
// )
type bucketState Bucket // hide state methods from public API
// DropState implements Stateful to discard bucket state.
func (b *bucketState) DropState() {
b.next = nil
b.keys = nil
b.values = nil
}
// PySetState implements PyStateful to set bucket data from pystate.
func (b *bucketState) PySetState(pystate interface{}) error {
t, ok := pystate.(pickle.Tuple)
if !ok || !(1 <= len(t) && len(t) <= 2) {
// XXX complain
}
// .next present
if len(t) == 2 {
next, ok := t[1].(*Bucket)
if !ok {
// XXX
}
b.next = next
}
// main part
t, ok = t[0].(pickle.Tuple)
// XXX if !ok || (len(t) % 2 != 0)
// reset arrays just in case
n := len(t) / 2
b.keys = make([]KEY, 0, n)
b.values = make([]interface{}, 0, n)
for i := 0; i < n; i++ {
xk := t[2*i]
v := t[2*i+1]
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)
}
return nil
}
// ---- register classes to ZODB ----
func init() {
......
......@@ -58,7 +58,7 @@ func TestBucket(t *testing.T) {
t.Fatal(err)
}
for _, tt := range _1fs_testEntry {
for _, tt := range _bucketTestv {
xobj, err := conn.Get(ctx, tt.oid)
if err != nil {
t.Fatal(err)
......
......@@ -49,7 +49,7 @@ def main():
emit("package btree\n")
#emit("import \"lab.nexedi.com/kirr/neo/go/zodb\"\n")
emit("\nvar _1fs_testEntry = [...]testEntry{")
emit("\nvar _bucketTestv = [...]testEntry{")
for b in (b0, b1, b2):
s = "testEntry{oid: %s, itemv: []kv{" % u64(b._p_oid)
for k, v in b.items():
......
......@@ -2,7 +2,7 @@
package btree
var _1fs_testEntry = [...]testEntry{
var _bucketTestv = [...]testEntry{
testEntry{oid: 1, itemv: []kv{}},
testEntry{oid: 2, itemv: []kv{{10, int64(17)}, }},
testEntry{oid: 3, itemv: []kv{{15, int64(1)}, {23, "hello"}, }},
......
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