Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
N
neoppod
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Levin Zimmermann
neoppod
Commits
cc519ed7
Commit
cc519ed7
authored
Sep 04, 2018
by
Kirill Smelkov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
.
parent
1ebc3574
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
127 additions
and
38 deletions
+127
-38
go/zodb/btree/btree.go.in
go/zodb/btree/btree.go.in
+42
-13
go/zodb/btree/gen-btree
go/zodb/btree/gen-btree
+2
-0
go/zodb/btree/ziobtree.go
go/zodb/btree/ziobtree.go
+42
-13
go/zodb/btree/zlobtree.go
go/zodb/btree/zlobtree.go
+41
-12
No files found.
go/zodb/btree/btree.go.in
View file @
cc519ed7
...
@@ -32,7 +32,7 @@ import (
...
@@ -32,7 +32,7 @@ import (
//
//
//
It
contains
[]
Entry
in
↑
key
order
.
//
It
contains
[]
Entry
in
↑
key
order
.
//
//
//
It
mimics
?
OBTree
from
btree
/
py
,
with
?
being
any
integer
.
//
It
mimics
BTree
from
btree
/
py
.
type
BTree
struct
{
type
BTree
struct
{
zodb
.
Persistent
zodb
.
Persistent
...
@@ -67,7 +67,7 @@ type Entry struct {
...
@@ -67,7 +67,7 @@ type Entry struct {
//
//
// It contains []BucketEntry in ↑ key order.
// It contains []BucketEntry in ↑ key order.
//
//
// It mimics
?OBucket from btree/py, with ? being any integer
.
// It mimics
Bucket from btree/py
.
type Bucket struct {
type Bucket struct {
zodb.Persistent
zodb.Persistent
...
@@ -123,8 +123,6 @@ func (e *BucketEntry) Key() KEY { return e.key }
...
@@ -123,8 +123,6 @@ func (e *BucketEntry) Key() KEY { return e.key }
func (e *BucketEntry) Value() interface{} { return e.value }
func (e *BucketEntry) Value() interface{} { return e.value }
// Entryv returns entries of a Bucket node.
// Entryv returns entries of a Bucket node.
//
// XXX
func (b *Bucket) Entryv() []BucketEntry {
func (b *Bucket) Entryv() []BucketEntry {
ev := make([]BucketEntry, len(b.keys))
ev := make([]BucketEntry, len(b.keys))
for i, k := range b.keys {
for i, k := range b.keys {
...
@@ -270,17 +268,27 @@ func (b *bucketState) PySetState(pystate interface{}) (err error) {
...
@@ -270,17 +268,27 @@ func (b *bucketState) PySetState(pystate interface{}) (err error) {
b.keys = make([]KEY, 0, n)
b.keys = make([]KEY, 0, n)
b.values = make([]interface{}, 0, n)
b.values = make([]interface{}, 0, n)
var kprev int64
for i := 0; i < n; i++ {
for i := 0; i < n; i++ {
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 -> 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
kk := KEY(k)
b.keys = append(b.keys, KEY(k)) // XXX cast
if int64(kk) != k {
return fmt.Errorf("data: [%d]: key overflows %T", i, kk)
}
if i > 0 && !(k > kprev) {
return fmt.Errorf("data: [%d]: key not ↑", i)
}
kprev = k
b.keys = append(b.keys, kk)
b.values = append(b.values, v)
b.values = append(b.values, v)
}
}
...
@@ -375,8 +383,10 @@ func (bt *btreeState) PySetState(pystate interface{}) (err error) {
...
@@ -375,8 +383,10 @@ func (bt *btreeState) PySetState(pystate interface{}) (err error) {
n := (len(t) + 1) / 2
n := (len(t) + 1) / 2
bt.data = make([]Entry, 0, n)
bt.data = make([]Entry, 0, n)
var kprev int64
var childrenKind int // 1 - BTree, 2 - Bucket
for i, idx := 0, 0; i < n; i++ {
for i, idx := 0, 0; i < n; i++ {
key := int64(math.Min
Int64) // int64
(-∞) (qualifies for ≤)
key := int64(math.Min
<Key>) // KEY
(-∞) (qualifies for ≤)
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
...
@@ -388,17 +398,36 @@ func (bt *btreeState) PySetState(pystate interface{}) (err error) {
...
@@ -388,17 +398,36 @@ func (bt *btreeState) PySetState(pystate interface{}) (err error) {
child := t[idx]
child := t[idx]
idx++
idx++
kkey := KEY(key)
if int64(kkey) != key {
return fmt.Errorf("data: [%d]: key overflows %T", i, kkey)
}
if i > 1 && !(key > kprev) {
fmt.Errorf("data: [%d]: key not ↑", i)
}
kprev = key
// check all children are of the same type
var kind int // see childrenKind ^^^
switch child.(type) {
switch child.(type) {
default:
default:
return fmt.Errorf("data: [%d]: child must be BTree|Bucket; got %T", i, child)
return fmt.Errorf("data: [%d]: child must be BTree|Bucket; got %T", i, child)
// XXX check all children are of the same type
case *BTree:
case *BTree: // ok
kind = 1
case *Bucket: // ok
case *Bucket:
kind = 2
}
if i == 0 {
childrenKind = kind
}
if kind != childrenKind {
fmt.Errorf("data: [%d]: children must be of the same type", i)
}
}
// XXX check key ↑
bt.data = append(bt.data, Entry{key: kkey, child: child})
bt.data = append(bt.data, Entry{key: KEY(key), child: child})
}
}
return nil
return nil
...
...
go/zodb/btree/gen-btree
View file @
cc519ed7
...
@@ -26,6 +26,7 @@ KEY=$2
...
@@ -26,6 +26,7 @@ KEY=$2
out
=
$3
out
=
$3
kind
=
${
KIND
,,
}
# IO -> io
kind
=
${
KIND
,,
}
# IO -> io
Key
=
${
KEY
^
}
input
=
$(
dirname
$0
)
/btree.go.in
input
=
$(
dirname
$0
)
/btree.go.in
...
@@ -36,6 +37,7 @@ sed \
...
@@ -36,6 +37,7 @@ sed \
-e
"s/<kind>/
$kind
/g"
\
-e
"s/<kind>/
$kind
/g"
\
-e
"s/<KIND>/
$KIND
/g"
\
-e
"s/<KIND>/
$KIND
/g"
\
-e
"s/KEY/
$KEY
/g"
\
-e
"s/KEY/
$KEY
/g"
\
-e
"s/<Key>/
$Key
/g"
\
-e
"s/
\b
BTree
\b
/
${
KIND
}
BTree/g"
\
-e
"s/
\b
BTree
\b
/
${
KIND
}
BTree/g"
\
-e
"s/
\b
Entry
\b
/
${
KIND
}
Entry/g"
\
-e
"s/
\b
Entry
\b
/
${
KIND
}
Entry/g"
\
-e
"s/
\b
Bucket
\b
/
${
KIND
}
Bucket/g"
\
-e
"s/
\b
Bucket
\b
/
${
KIND
}
Bucket/g"
\
...
...
go/zodb/btree/ziobtree.go
View file @
cc519ed7
...
@@ -34,7 +34,7 @@ import (
...
@@ -34,7 +34,7 @@ import (
//
//
// It contains []IOEntry in ↑ key order.
// It contains []IOEntry in ↑ key order.
//
//
// It mimics
?OBTree from btree/py, with ? being any integer
.
// It mimics
IOBTree from btree/py
.
type
IOBTree
struct
{
type
IOBTree
struct
{
zodb
.
Persistent
zodb
.
Persistent
...
@@ -69,7 +69,7 @@ type IOEntry struct {
...
@@ -69,7 +69,7 @@ type IOEntry struct {
//
//
// It contains []IOBucketEntry in ↑ key order.
// It contains []IOBucketEntry in ↑ key order.
//
//
// It mimics
?OBucket from btree/py, with ? being any integer
.
// It mimics
IOBucket from btree/py
.
type
IOBucket
struct
{
type
IOBucket
struct
{
zodb
.
Persistent
zodb
.
Persistent
...
@@ -125,8 +125,6 @@ func (e *IOBucketEntry) Key() int32 { return e.key }
...
@@ -125,8 +125,6 @@ func (e *IOBucketEntry) Key() int32 { return e.key }
func
(
e
*
IOBucketEntry
)
Value
()
interface
{}
{
return
e
.
value
}
func
(
e
*
IOBucketEntry
)
Value
()
interface
{}
{
return
e
.
value
}
// Entryv returns entries of a IOBucket node.
// Entryv returns entries of a IOBucket node.
//
// XXX
func
(
b
*
IOBucket
)
Entryv
()
[]
IOBucketEntry
{
func
(
b
*
IOBucket
)
Entryv
()
[]
IOBucketEntry
{
ev
:=
make
([]
IOBucketEntry
,
len
(
b
.
keys
))
ev
:=
make
([]
IOBucketEntry
,
len
(
b
.
keys
))
for
i
,
k
:=
range
b
.
keys
{
for
i
,
k
:=
range
b
.
keys
{
...
@@ -272,17 +270,27 @@ func (b *iobucketState) PySetState(pystate interface{}) (err error) {
...
@@ -272,17 +270,27 @@ func (b *iobucketState) PySetState(pystate interface{}) (err error) {
b
.
keys
=
make
([]
int32
,
0
,
n
)
b
.
keys
=
make
([]
int32
,
0
,
n
)
b
.
values
=
make
([]
interface
{},
0
,
n
)
b
.
values
=
make
([]
interface
{},
0
,
n
)
var
kprev
int64
for
i
:=
0
;
i
<
n
;
i
++
{
for
i
:=
0
;
i
<
n
;
i
++
{
xk
:=
t
[
2
*
i
]
xk
:=
t
[
2
*
i
]
v
:=
t
[
2
*
i
+
1
]
v
:=
t
[
2
*
i
+
1
]
k
,
ok
:=
xk
.
(
int64
)
// XXX
use int32 XXX
-> Xint64
k
,
ok
:=
xk
.
(
int64
)
// 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
kk
:=
int32
(
k
)
b
.
keys
=
append
(
b
.
keys
,
int32
(
k
))
// XXX cast
if
int64
(
kk
)
!=
k
{
return
fmt
.
Errorf
(
"data: [%d]: key overflows %T"
,
i
,
kk
)
}
if
i
>
0
&&
!
(
k
>
kprev
)
{
return
fmt
.
Errorf
(
"data: [%d]: key not ↑"
,
i
)
}
kprev
=
k
b
.
keys
=
append
(
b
.
keys
,
kk
)
b
.
values
=
append
(
b
.
values
,
v
)
b
.
values
=
append
(
b
.
values
,
v
)
}
}
...
@@ -377,8 +385,10 @@ func (bt *iobtreeState) PySetState(pystate interface{}) (err error) {
...
@@ -377,8 +385,10 @@ func (bt *iobtreeState) PySetState(pystate interface{}) (err error) {
n
:=
(
len
(
t
)
+
1
)
/
2
n
:=
(
len
(
t
)
+
1
)
/
2
bt
.
data
=
make
([]
IOEntry
,
0
,
n
)
bt
.
data
=
make
([]
IOEntry
,
0
,
n
)
var
kprev
int64
var
childrenKind
int
// 1 - IOBTree, 2 - IOBucket
for
i
,
idx
:=
0
,
0
;
i
<
n
;
i
++
{
for
i
,
idx
:=
0
,
0
;
i
<
n
;
i
++
{
key
:=
int64
(
math
.
MinInt
64
)
// int64
(-∞) (qualifies for ≤)
key
:=
int64
(
math
.
MinInt
32
)
// int32
(-∞) (qualifies for ≤)
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
...
@@ -390,17 +400,36 @@ func (bt *iobtreeState) PySetState(pystate interface{}) (err error) {
...
@@ -390,17 +400,36 @@ func (bt *iobtreeState) PySetState(pystate interface{}) (err error) {
child
:=
t
[
idx
]
child
:=
t
[
idx
]
idx
++
idx
++
kkey
:=
int32
(
key
)
if
int64
(
kkey
)
!=
key
{
return
fmt
.
Errorf
(
"data: [%d]: key overflows %T"
,
i
,
kkey
)
}
if
i
>
1
&&
!
(
key
>
kprev
)
{
fmt
.
Errorf
(
"data: [%d]: key not ↑"
,
i
)
}
kprev
=
key
// check all children are of the same type
var
kind
int
// see childrenKind ^^^
switch
child
.
(
type
)
{
switch
child
.
(
type
)
{
default
:
default
:
return
fmt
.
Errorf
(
"data: [%d]: child must be IOBTree|IOBucket; got %T"
,
i
,
child
)
return
fmt
.
Errorf
(
"data: [%d]: child must be IOBTree|IOBucket; got %T"
,
i
,
child
)
// XXX check all children are of the same type
case
*
IOBTree
:
case
*
IOBTree
:
// ok
kind
=
1
case
*
IOBucket
:
// ok
case
*
IOBucket
:
kind
=
2
}
if
i
==
0
{
childrenKind
=
kind
}
if
kind
!=
childrenKind
{
fmt
.
Errorf
(
"data: [%d]: children must be of the same type"
,
i
)
}
}
// XXX check key ↑
bt
.
data
=
append
(
bt
.
data
,
IOEntry
{
key
:
kkey
,
child
:
child
})
bt
.
data
=
append
(
bt
.
data
,
IOEntry
{
key
:
int32
(
key
),
child
:
child
})
}
}
return
nil
return
nil
...
...
go/zodb/btree/zlobtree.go
View file @
cc519ed7
...
@@ -34,7 +34,7 @@ import (
...
@@ -34,7 +34,7 @@ import (
//
//
// It contains []LOEntry in ↑ key order.
// It contains []LOEntry in ↑ key order.
//
//
// It mimics
?OBTree from btree/py, with ? being any integer
.
// It mimics
LOBTree from btree/py
.
type
LOBTree
struct
{
type
LOBTree
struct
{
zodb
.
Persistent
zodb
.
Persistent
...
@@ -69,7 +69,7 @@ type LOEntry struct {
...
@@ -69,7 +69,7 @@ type LOEntry struct {
//
//
// It contains []LOBucketEntry in ↑ key order.
// It contains []LOBucketEntry in ↑ key order.
//
//
// It mimics
?OBucket from btree/py, with ? being any integer
.
// It mimics
LOBucket from btree/py
.
type
LOBucket
struct
{
type
LOBucket
struct
{
zodb
.
Persistent
zodb
.
Persistent
...
@@ -125,8 +125,6 @@ func (e *LOBucketEntry) Key() int64 { return e.key }
...
@@ -125,8 +125,6 @@ func (e *LOBucketEntry) Key() int64 { return e.key }
func
(
e
*
LOBucketEntry
)
Value
()
interface
{}
{
return
e
.
value
}
func
(
e
*
LOBucketEntry
)
Value
()
interface
{}
{
return
e
.
value
}
// Entryv returns entries of a LOBucket node.
// Entryv returns entries of a LOBucket node.
//
// XXX
func
(
b
*
LOBucket
)
Entryv
()
[]
LOBucketEntry
{
func
(
b
*
LOBucket
)
Entryv
()
[]
LOBucketEntry
{
ev
:=
make
([]
LOBucketEntry
,
len
(
b
.
keys
))
ev
:=
make
([]
LOBucketEntry
,
len
(
b
.
keys
))
for
i
,
k
:=
range
b
.
keys
{
for
i
,
k
:=
range
b
.
keys
{
...
@@ -272,17 +270,27 @@ func (b *lobucketState) PySetState(pystate interface{}) (err error) {
...
@@ -272,17 +270,27 @@ func (b *lobucketState) PySetState(pystate interface{}) (err error) {
b
.
keys
=
make
([]
int64
,
0
,
n
)
b
.
keys
=
make
([]
int64
,
0
,
n
)
b
.
values
=
make
([]
interface
{},
0
,
n
)
b
.
values
=
make
([]
interface
{},
0
,
n
)
var
kprev
int64
for
i
:=
0
;
i
<
n
;
i
++
{
for
i
:=
0
;
i
<
n
;
i
++
{
xk
:=
t
[
2
*
i
]
xk
:=
t
[
2
*
i
]
v
:=
t
[
2
*
i
+
1
]
v
:=
t
[
2
*
i
+
1
]
k
,
ok
:=
xk
.
(
int64
)
// XXX
use int64 XXX
-> Xint64
k
,
ok
:=
xk
.
(
int64
)
// 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
kk
:=
int64
(
k
)
b
.
keys
=
append
(
b
.
keys
,
int64
(
k
))
// XXX cast
if
int64
(
kk
)
!=
k
{
return
fmt
.
Errorf
(
"data: [%d]: key overflows %T"
,
i
,
kk
)
}
if
i
>
0
&&
!
(
k
>
kprev
)
{
return
fmt
.
Errorf
(
"data: [%d]: key not ↑"
,
i
)
}
kprev
=
k
b
.
keys
=
append
(
b
.
keys
,
kk
)
b
.
values
=
append
(
b
.
values
,
v
)
b
.
values
=
append
(
b
.
values
,
v
)
}
}
...
@@ -377,6 +385,8 @@ func (bt *lobtreeState) PySetState(pystate interface{}) (err error) {
...
@@ -377,6 +385,8 @@ func (bt *lobtreeState) PySetState(pystate interface{}) (err error) {
n
:=
(
len
(
t
)
+
1
)
/
2
n
:=
(
len
(
t
)
+
1
)
/
2
bt
.
data
=
make
([]
LOEntry
,
0
,
n
)
bt
.
data
=
make
([]
LOEntry
,
0
,
n
)
var
kprev
int64
var
childrenKind
int
// 1 - LOBTree, 2 - LOBucket
for
i
,
idx
:=
0
,
0
;
i
<
n
;
i
++
{
for
i
,
idx
:=
0
,
0
;
i
<
n
;
i
++
{
key
:=
int64
(
math
.
MinInt64
)
// int64(-∞) (qualifies for ≤)
key
:=
int64
(
math
.
MinInt64
)
// int64(-∞) (qualifies for ≤)
if
i
>
0
{
if
i
>
0
{
...
@@ -390,17 +400,36 @@ func (bt *lobtreeState) PySetState(pystate interface{}) (err error) {
...
@@ -390,17 +400,36 @@ func (bt *lobtreeState) PySetState(pystate interface{}) (err error) {
child
:=
t
[
idx
]
child
:=
t
[
idx
]
idx
++
idx
++
kkey
:=
int64
(
key
)
if
int64
(
kkey
)
!=
key
{
return
fmt
.
Errorf
(
"data: [%d]: key overflows %T"
,
i
,
kkey
)
}
if
i
>
1
&&
!
(
key
>
kprev
)
{
fmt
.
Errorf
(
"data: [%d]: key not ↑"
,
i
)
}
kprev
=
key
// check all children are of the same type
var
kind
int
// see childrenKind ^^^
switch
child
.
(
type
)
{
switch
child
.
(
type
)
{
default
:
default
:
return
fmt
.
Errorf
(
"data: [%d]: child must be LOBTree|LOBucket; got %T"
,
i
,
child
)
return
fmt
.
Errorf
(
"data: [%d]: child must be LOBTree|LOBucket; got %T"
,
i
,
child
)
// XXX check all children are of the same type
case
*
LOBTree
:
case
*
LOBTree
:
// ok
kind
=
1
case
*
LOBucket
:
// ok
case
*
LOBucket
:
kind
=
2
}
if
i
==
0
{
childrenKind
=
kind
}
if
kind
!=
childrenKind
{
fmt
.
Errorf
(
"data: [%d]: children must be of the same type"
,
i
)
}
}
// XXX check key ↑
bt
.
data
=
append
(
bt
.
data
,
LOEntry
{
key
:
kkey
,
child
:
child
})
bt
.
data
=
append
(
bt
.
data
,
LOEntry
{
key
:
int64
(
key
),
child
:
child
})
}
}
return
nil
return
nil
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment