Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
N
neo
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Labels
Merge Requests
2
Merge Requests
2
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Jobs
Commits
Open sidebar
Kirill Smelkov
neo
Commits
1b838adf
Commit
1b838adf
authored
Apr 02, 2019
by
Kirill Smelkov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
.
parent
830a64cb
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
53 additions
and
24 deletions
+53
-24
go/zodb/btree/btree.go
go/zodb/btree/btree.go
+1
-0
go/zodb/btree/btree.go.in
go/zodb/btree/btree.go.in
+17
-8
go/zodb/btree/gen-btree
go/zodb/btree/gen-btree
+1
-0
go/zodb/btree/ziobtree.go
go/zodb/btree/ziobtree.go
+17
-8
go/zodb/btree/zlobtree.go
go/zodb/btree/zlobtree.go
+17
-8
No files found.
go/zodb/btree/btree.go
View file @
1b838adf
...
...
@@ -18,6 +18,7 @@
// kind: they are either all leafs or all intermediate nodes(+).
//
// BTree and Bucket represent an intermediate and a leaf tree node correspondingly.
// Node represents any of them.
//
// node.Get(key) performs point-query.
//
...
...
go/zodb/btree/btree.go.in
View file @
1b838adf
...
...
@@ -29,6 +29,15 @@ import (
"lab.nexedi.com/kirr/neo/go/zodb/internal/pickletools"
)
//
Node
represents
a
tree
node
-
either
BTree
or
Bucket
.
type
Node
interface
{
zodb
.
IPersistent
node
()
}
func
(
t
*
BTree
)
node
()
{}
func
(
b
*
Bucket
)
node
()
{}
//
BTree
is
a
non
-
leaf
node
of
a
B
⁺
tree
.
//
//
It
contains
[]
Entry
in
↑
key
order
.
...
...
@@ -61,7 +70,7 @@ type BTree struct {
//
Key
limits
child
's keys - see BTree.Entryv for details.
type Entry struct {
key KEY
child
zodb.IPersistent
// BTree or Bucket
child
Node
// BTree or Bucket
}
// Bucket is a leaf node of a B⁺ tree.
...
...
@@ -99,7 +108,7 @@ type BucketEntry struct {
func (e *Entry) Key() KEY { return e.key }
// Child returns BTree entry child.
func (e *Entry) Child()
zodb.IPersistent
{ return e.child }
func (e *Entry) Child()
Node
{ return e.child }
// Entryv returns entries of a BTree node.
//
...
...
@@ -159,7 +168,7 @@ func (t *BTree) Get(ctx context.Context, key KEY) (_ interface{}, _ bool, err er
// VGet is like Get but also calls visit while traversing the tree.
//
// Visit is called with node being activated.
func (t *BTree) VGet(ctx context.Context, key KEY, visit func(node
zodb.IPersistent
)) (_ interface{}, _ bool, err error) {
func (t *BTree) VGet(ctx context.Context, key KEY, visit func(node
Node
)) (_ interface{}, _ bool, err error) {
defer xerr.Contextf(&err, "btree(%s): get %v", t.POid(), key)
err = t.PActivate(ctx)
if err != nil {
...
...
@@ -237,7 +246,7 @@ func (t *BTree) MinKey(ctx context.Context) (_ KEY, ok bool, err error) {
// VMinKey is like MinKey but also calls visit while traversing the tree.
//
// Visit is called with node being activated.
func (t *BTree) VMinKey(ctx context.Context, visit func(node
zodb.IPersistent
)) (_ KEY, ok bool, err error) {
func (t *BTree) VMinKey(ctx context.Context, visit func(node
Node
)) (_ KEY, ok bool, err error) {
defer xerr.Contextf(&err, "btree(%s): minkey", t.POid())
err = t.PActivate(ctx)
if err != nil {
...
...
@@ -256,7 +265,7 @@ func (t *BTree) VMinKey(ctx context.Context, visit func(node zodb.IPersistent))
// NOTE -> can also use t.firstbucket
for {
child := t.data[0].child
.(zodb.IPersistent)
child := t.data[0].child
t.PDeactivate()
err = child.PActivate(ctx)
if err != nil {
...
...
@@ -290,7 +299,7 @@ func (t *BTree) MaxKey(ctx context.Context) (_ KEY, _ bool, err error) {
// VMaxKey is like MaxKey but also calls visit while traversing the tree.
//
// Visit is called with node being activated.
func (t *BTree) VMaxKey(ctx context.Context, visit func(node
zodb.IPersistent
)) (_ KEY, _ bool, err error) {
func (t *BTree) VMaxKey(ctx context.Context, visit func(node
Node
)) (_ KEY, _ bool, err error) {
defer xerr.Contextf(&err, "btree(%s): maxkey", t.POid())
err = t.PActivate(ctx)
if err != nil {
...
...
@@ -309,7 +318,7 @@ func (t *BTree) VMaxKey(ctx context.Context, visit func(node zodb.IPersistent))
}
for {
child := t.data[l-1].child
.(zodb.IPersistent)
child := t.data[l-1].child
t.PDeactivate()
err = child.PActivate(ctx)
if err != nil {
...
...
@@ -615,7 +624,7 @@ func (bt *btreeState) PySetState(pystate interface{}) (err error) {
fmt.Errorf("data: [%d]: children must be of the same type", i)
}
bt.data = append(bt.data, Entry{key: kkey, child: child.(
zodb.IPersistent
)})
bt.data = append(bt.data, Entry{key: kkey, child: child.(
Node
)})
}
return nil
...
...
go/zodb/btree/gen-btree
View file @
1b838adf
...
...
@@ -38,6 +38,7 @@ sed \
-e
"s/<KIND>/
$KIND
/g"
\
-e
"s/KEY/
$KEY
/g"
\
-e
"s/<Key>/
$Key
/g"
\
-e
"s/
\b
Node
\b
/
${
KIND
}
Node/g"
\
-e
"s/
\b
BTree
\b
/
${
KIND
}
BTree/g"
\
-e
"s/
\b
Entry
\b
/
${
KIND
}
Entry/g"
\
-e
"s/
\b
Bucket
\b
/
${
KIND
}
Bucket/g"
\
...
...
go/zodb/btree/ziobtree.go
View file @
1b838adf
...
...
@@ -31,6 +31,15 @@ import (
"lab.nexedi.com/kirr/neo/go/zodb/internal/pickletools"
)
// IONode represents a tree node - either IOBTree or IOBucket.
type
IONode
interface
{
zodb
.
IPersistent
node
()
}
func
(
t
*
IOBTree
)
node
()
{}
func
(
b
*
IOBucket
)
node
()
{}
// IOBTree is a non-leaf node of a B⁺ tree.
//
// It contains []IOEntry in ↑ key order.
...
...
@@ -63,7 +72,7 @@ type IOBTree struct {
// Key limits child's keys - see IOBTree.Entryv for details.
type
IOEntry
struct
{
key
int32
child
zodb
.
IPersistent
// IOBTree or IOBucket
child
IONode
// IOBTree or IOBucket
}
// IOBucket is a leaf node of a B⁺ tree.
...
...
@@ -101,7 +110,7 @@ type IOBucketEntry struct {
func
(
e
*
IOEntry
)
Key
()
int32
{
return
e
.
key
}
// Child returns IOBTree entry child.
func
(
e
*
IOEntry
)
Child
()
zodb
.
IPersistent
{
return
e
.
child
}
func
(
e
*
IOEntry
)
Child
()
IONode
{
return
e
.
child
}
// Entryv returns entries of a IOBTree node.
//
...
...
@@ -161,7 +170,7 @@ func (t *IOBTree) Get(ctx context.Context, key int32) (_ interface{}, _ bool, er
// VGet is like Get but also calls visit while traversing the tree.
//
// Visit is called with node being activated.
func
(
t
*
IOBTree
)
VGet
(
ctx
context
.
Context
,
key
int32
,
visit
func
(
node
zodb
.
IPersistent
))
(
_
interface
{},
_
bool
,
err
error
)
{
func
(
t
*
IOBTree
)
VGet
(
ctx
context
.
Context
,
key
int32
,
visit
func
(
node
IONode
))
(
_
interface
{},
_
bool
,
err
error
)
{
defer
xerr
.
Contextf
(
&
err
,
"btree(%s): get %v"
,
t
.
POid
(),
key
)
err
=
t
.
PActivate
(
ctx
)
if
err
!=
nil
{
...
...
@@ -239,7 +248,7 @@ func (t *IOBTree) MinKey(ctx context.Context) (_ int32, ok bool, err error) {
// VMinKey is like MinKey but also calls visit while traversing the tree.
//
// Visit is called with node being activated.
func
(
t
*
IOBTree
)
VMinKey
(
ctx
context
.
Context
,
visit
func
(
node
zodb
.
IPersistent
))
(
_
int32
,
ok
bool
,
err
error
)
{
func
(
t
*
IOBTree
)
VMinKey
(
ctx
context
.
Context
,
visit
func
(
node
IONode
))
(
_
int32
,
ok
bool
,
err
error
)
{
defer
xerr
.
Contextf
(
&
err
,
"btree(%s): minkey"
,
t
.
POid
())
err
=
t
.
PActivate
(
ctx
)
if
err
!=
nil
{
...
...
@@ -258,7 +267,7 @@ func (t *IOBTree) VMinKey(ctx context.Context, visit func(node zodb.IPersistent)
// NOTE -> can also use t.firstbucket
for
{
child
:=
t
.
data
[
0
]
.
child
.
(
zodb
.
IPersistent
)
child
:=
t
.
data
[
0
]
.
child
t
.
PDeactivate
()
err
=
child
.
PActivate
(
ctx
)
if
err
!=
nil
{
...
...
@@ -292,7 +301,7 @@ func (t *IOBTree) MaxKey(ctx context.Context) (_ int32, _ bool, err error) {
// VMaxKey is like MaxKey but also calls visit while traversing the tree.
//
// Visit is called with node being activated.
func
(
t
*
IOBTree
)
VMaxKey
(
ctx
context
.
Context
,
visit
func
(
node
zodb
.
IPersistent
))
(
_
int32
,
_
bool
,
err
error
)
{
func
(
t
*
IOBTree
)
VMaxKey
(
ctx
context
.
Context
,
visit
func
(
node
IONode
))
(
_
int32
,
_
bool
,
err
error
)
{
defer
xerr
.
Contextf
(
&
err
,
"btree(%s): maxkey"
,
t
.
POid
())
err
=
t
.
PActivate
(
ctx
)
if
err
!=
nil
{
...
...
@@ -311,7 +320,7 @@ func (t *IOBTree) VMaxKey(ctx context.Context, visit func(node zodb.IPersistent)
}
for
{
child
:=
t
.
data
[
l
-
1
]
.
child
.
(
zodb
.
IPersistent
)
child
:=
t
.
data
[
l
-
1
]
.
child
t
.
PDeactivate
()
err
=
child
.
PActivate
(
ctx
)
if
err
!=
nil
{
...
...
@@ -617,7 +626,7 @@ func (bt *iobtreeState) PySetState(pystate interface{}) (err error) {
fmt
.
Errorf
(
"data: [%d]: children must be of the same type"
,
i
)
}
bt
.
data
=
append
(
bt
.
data
,
IOEntry
{
key
:
kkey
,
child
:
child
.
(
zodb
.
IPersistent
)})
bt
.
data
=
append
(
bt
.
data
,
IOEntry
{
key
:
kkey
,
child
:
child
.
(
IONode
)})
}
return
nil
...
...
go/zodb/btree/zlobtree.go
View file @
1b838adf
...
...
@@ -31,6 +31,15 @@ import (
"lab.nexedi.com/kirr/neo/go/zodb/internal/pickletools"
)
// LONode represents a tree node - either LOBTree or LOBucket.
type
LONode
interface
{
zodb
.
IPersistent
node
()
}
func
(
t
*
LOBTree
)
node
()
{}
func
(
b
*
LOBucket
)
node
()
{}
// LOBTree is a non-leaf node of a B⁺ tree.
//
// It contains []LOEntry in ↑ key order.
...
...
@@ -63,7 +72,7 @@ type LOBTree struct {
// Key limits child's keys - see LOBTree.Entryv for details.
type
LOEntry
struct
{
key
int64
child
zodb
.
IPersistent
// LOBTree or LOBucket
child
LONode
// LOBTree or LOBucket
}
// LOBucket is a leaf node of a B⁺ tree.
...
...
@@ -101,7 +110,7 @@ type LOBucketEntry struct {
func
(
e
*
LOEntry
)
Key
()
int64
{
return
e
.
key
}
// Child returns LOBTree entry child.
func
(
e
*
LOEntry
)
Child
()
zodb
.
IPersistent
{
return
e
.
child
}
func
(
e
*
LOEntry
)
Child
()
LONode
{
return
e
.
child
}
// Entryv returns entries of a LOBTree node.
//
...
...
@@ -161,7 +170,7 @@ func (t *LOBTree) Get(ctx context.Context, key int64) (_ interface{}, _ bool, er
// VGet is like Get but also calls visit while traversing the tree.
//
// Visit is called with node being activated.
func
(
t
*
LOBTree
)
VGet
(
ctx
context
.
Context
,
key
int64
,
visit
func
(
node
zodb
.
IPersistent
))
(
_
interface
{},
_
bool
,
err
error
)
{
func
(
t
*
LOBTree
)
VGet
(
ctx
context
.
Context
,
key
int64
,
visit
func
(
node
LONode
))
(
_
interface
{},
_
bool
,
err
error
)
{
defer
xerr
.
Contextf
(
&
err
,
"btree(%s): get %v"
,
t
.
POid
(),
key
)
err
=
t
.
PActivate
(
ctx
)
if
err
!=
nil
{
...
...
@@ -239,7 +248,7 @@ func (t *LOBTree) MinKey(ctx context.Context) (_ int64, ok bool, err error) {
// VMinKey is like MinKey but also calls visit while traversing the tree.
//
// Visit is called with node being activated.
func
(
t
*
LOBTree
)
VMinKey
(
ctx
context
.
Context
,
visit
func
(
node
zodb
.
IPersistent
))
(
_
int64
,
ok
bool
,
err
error
)
{
func
(
t
*
LOBTree
)
VMinKey
(
ctx
context
.
Context
,
visit
func
(
node
LONode
))
(
_
int64
,
ok
bool
,
err
error
)
{
defer
xerr
.
Contextf
(
&
err
,
"btree(%s): minkey"
,
t
.
POid
())
err
=
t
.
PActivate
(
ctx
)
if
err
!=
nil
{
...
...
@@ -258,7 +267,7 @@ func (t *LOBTree) VMinKey(ctx context.Context, visit func(node zodb.IPersistent)
// NOTE -> can also use t.firstbucket
for
{
child
:=
t
.
data
[
0
]
.
child
.
(
zodb
.
IPersistent
)
child
:=
t
.
data
[
0
]
.
child
t
.
PDeactivate
()
err
=
child
.
PActivate
(
ctx
)
if
err
!=
nil
{
...
...
@@ -292,7 +301,7 @@ func (t *LOBTree) MaxKey(ctx context.Context) (_ int64, _ bool, err error) {
// VMaxKey is like MaxKey but also calls visit while traversing the tree.
//
// Visit is called with node being activated.
func
(
t
*
LOBTree
)
VMaxKey
(
ctx
context
.
Context
,
visit
func
(
node
zodb
.
IPersistent
))
(
_
int64
,
_
bool
,
err
error
)
{
func
(
t
*
LOBTree
)
VMaxKey
(
ctx
context
.
Context
,
visit
func
(
node
LONode
))
(
_
int64
,
_
bool
,
err
error
)
{
defer
xerr
.
Contextf
(
&
err
,
"btree(%s): maxkey"
,
t
.
POid
())
err
=
t
.
PActivate
(
ctx
)
if
err
!=
nil
{
...
...
@@ -311,7 +320,7 @@ func (t *LOBTree) VMaxKey(ctx context.Context, visit func(node zodb.IPersistent)
}
for
{
child
:=
t
.
data
[
l
-
1
]
.
child
.
(
zodb
.
IPersistent
)
child
:=
t
.
data
[
l
-
1
]
.
child
t
.
PDeactivate
()
err
=
child
.
PActivate
(
ctx
)
if
err
!=
nil
{
...
...
@@ -617,7 +626,7 @@ func (bt *lobtreeState) PySetState(pystate interface{}) (err error) {
fmt
.
Errorf
(
"data: [%d]: children must be of the same type"
,
i
)
}
bt
.
data
=
append
(
bt
.
data
,
LOEntry
{
key
:
kkey
,
child
:
child
.
(
zodb
.
IPersistent
)})
bt
.
data
=
append
(
bt
.
data
,
LOEntry
{
key
:
kkey
,
child
:
child
.
(
LONode
)})
}
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