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
10480280
Commit
10480280
authored
Jul 31, 2018
by
Kirill Smelkov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
.
parent
66d65cc9
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
70 additions
and
70 deletions
+70
-70
go/zodb/btree/btree.go
go/zodb/btree/btree.go
+67
-67
go/zodb/btree/btree_test.go
go/zodb/btree/btree_test.go
+1
-1
go/zodb/btree/py/gen-testdata
go/zodb/btree/py/gen-testdata
+1
-1
go/zodb/btree/ztestdata_expect_test.go
go/zodb/btree/ztestdata_expect_test.go
+1
-1
No files found.
go/zodb/btree/btree.go
View file @
10480280
...
...
@@ -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
()
{
...
...
go/zodb/btree/btree_test.go
View file @
10480280
...
...
@@ -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
)
...
...
go/zodb/btree/py/gen-testdata
View file @
10480280
...
...
@@ -49,7 +49,7 @@ def main():
emit
(
"package btree
\
n
"
)
#emit("import \"lab.nexedi.com/kirr/neo/go/zodb\"\n")
emit
(
"
\
n
var _
1fs_testEntry
= [...]testEntry{"
)
emit
(
"
\
n
var _
bucketTestv
= [...]testEntry{"
)
for
b
in
(
b0
,
b1
,
b2
):
s
=
"testEntry{oid: %s, itemv: []kv{"
%
u64
(
b
.
_p_oid
)
for
k
,
v
in
b
.
items
():
...
...
go/zodb/btree/ztestdata_expect_test.go
View file @
10480280
...
...
@@ -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"
},
}},
...
...
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