Commit 1f651171 authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent 72a0bb1e
...@@ -28,9 +28,9 @@ import ( ...@@ -28,9 +28,9 @@ import (
"reflect" "reflect"
"sort" "sort"
pickle "github.com/kisielk/og-rek"
"lab.nexedi.com/kirr/go123/xerr" "lab.nexedi.com/kirr/go123/xerr"
"lab.nexedi.com/kirr/neo/go/zodb" "lab.nexedi.com/kirr/neo/go/zodb"
pickle "github.com/kisielk/og-rek"
) )
// KEY is the type for BTree keys. // KEY is the type for BTree keys.
...@@ -38,7 +38,6 @@ import ( ...@@ -38,7 +38,6 @@ import (
// XXX -> template? // XXX -> template?
type KEY int64 type KEY int64
// Bucket is a leaf node of a B⁺ tree. // Bucket is a leaf node of a B⁺ tree.
// //
// It mimics ?OBucket from btree/py, with ? being any integer. // It mimics ?OBucket from btree/py, with ? being any integer.
...@@ -53,17 +52,17 @@ type Bucket struct { ...@@ -53,17 +52,17 @@ type Bucket struct {
// are chained together via 'next', so that the entire BTree contents // are chained together via 'next', so that the entire BTree contents
// can be traversed in sorted order quickly and easily. // can be traversed in sorted order quickly and easily.
next *Bucket // the bucket with the next-larger keys next *Bucket // the bucket with the next-larger keys
keys []KEY // 'len' keys, in increasing order keys []KEY // 'len' keys, in increasing order
values []interface{} // 'len' corresponding values values []interface{} // 'len' corresponding values
} }
// _BTreeItem mimics BTreeItem from btree/py. // _BTreeItem mimics BTreeItem from btree/py.
// //
// XXX export for BTree.Children? // XXX export for BTree.Children?
type _BTreeItem struct { type _BTreeItem struct {
key KEY key KEY
child interface{} // BTree or Bucket child interface{} // BTree or Bucket
} }
// BTree is a non-leaf node of a B⁺ tree. // BTree is a non-leaf node of a B⁺ tree.
...@@ -86,7 +85,7 @@ type BTree struct { ...@@ -86,7 +85,7 @@ type BTree struct {
// order. data[0].key is unused. For i in 0 .. len-1, all keys reachable // order. data[0].key is unused. For i in 0 .. len-1, all keys reachable
// from data[i].child are >= data[i].key and < data[i+1].key, at the // from data[i].child are >= data[i].key and < data[i+1].key, at the
// endpoints pretending that data[0].key is -∞ and data[len].key is +∞. // endpoints pretending that data[0].key is -∞ and data[len].key is +∞.
data []_BTreeItem data []_BTreeItem
} }
// Get searches BTree by key. // Get searches BTree by key.
...@@ -112,7 +111,7 @@ func (t *BTree) Get(ctx context.Context, key KEY) (_ interface{}, _ bool, err er ...@@ -112,7 +111,7 @@ func (t *BTree) Get(ctx context.Context, key KEY) (_ interface{}, _ bool, err er
i := sort.Search(len(t.data), func(i int) bool { i := sort.Search(len(t.data), func(i int) bool {
j := i + 1 j := i + 1
if j == len(t.data) { if j == len(t.data) {
return true // [len].key = +∞ return true // [len].key = +∞
} }
return key < t.data[j].key return key < t.data[j].key
}) })
...@@ -216,7 +215,7 @@ func (b *bucketState) PySetState(pystate interface{}) (err error) { ...@@ -216,7 +215,7 @@ func (b *bucketState) PySetState(pystate interface{}) (err error) {
if !ok { if !ok {
return fmt.Errorf("data: expect (...); got %T", t[0]) return fmt.Errorf("data: expect (...); got %T", t[0])
} }
if len(t) % 2 != 0 { if len(t)%2 != 0 {
return fmt.Errorf("data: expect [%%2](); got [%d]()", len(t)) return fmt.Errorf("data: expect [%%2](); got [%d]()", len(t))
} }
...@@ -229,13 +228,13 @@ func (b *bucketState) PySetState(pystate interface{}) (err error) { ...@@ -229,13 +228,13 @@ func (b *bucketState) PySetState(pystate interface{}) (err error) {
xk := t[2*i] xk := t[2*i]
v := t[2*i+1] v := t[2*i+1]
k, ok := xk.(int64) // XXX use KEY XXX -> Xint64 k, ok := xk.(int64) // XXX use KEY XXX -> Xint64
if !ok { if !ok {
return fmt.Errorf("data: [%d]: key must be integer; got %T", i, xk) return fmt.Errorf("data: [%d]: key must be integer; got %T", i, xk)
} }
// XXX check keys are sorted? // XXX check keys are sorted?
b.keys = append(b.keys, KEY(k)) // XXX cast b.keys = append(b.keys, KEY(k)) // XXX cast
b.values = append(b.values, v) b.values = append(b.values, v)
} }
...@@ -324,7 +323,7 @@ func (bt *btreeState) PySetState(pystate interface{}) (err error) { ...@@ -324,7 +323,7 @@ func (bt *btreeState) PySetState(pystate interface{}) (err error) {
if !ok { if !ok {
return fmt.Errorf("data: expect (...); got %T", t[0]) return fmt.Errorf("data: expect (...); got %T", t[0])
} }
if len(t) % 2 == 0 { if len(t)%2 == 0 {
return fmt.Errorf("data: expect [!%%2](); got [%d]()", len(t)) return fmt.Errorf("data: expect [!%%2](); got [%d]()", len(t))
} }
...@@ -334,8 +333,8 @@ func (bt *btreeState) PySetState(pystate interface{}) (err error) { ...@@ -334,8 +333,8 @@ func (bt *btreeState) PySetState(pystate interface{}) (err error) {
key := int64(0) key := int64(0)
if i > 0 { if i > 0 {
// key[0] is unused and not saved // key[0] is unused and not saved
key, ok = t[idx].(int64) // XXX Xint key, ok = t[idx].(int64) // XXX Xint
if ! ok { if !ok {
return fmt.Errorf("data: [%d]: key must be integer; got %T", i, t[idx]) return fmt.Errorf("data: [%d]: key must be integer; got %T", i, t[idx])
} }
idx++ idx++
......
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