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
1f651171
Commit
1f651171
authored
Aug 08, 2018
by
Kirill Smelkov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
.
parent
72a0bb1e
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
14 additions
and
15 deletions
+14
-15
go/zodb/btree/btree.go
go/zodb/btree/btree.go
+14
-15
No files found.
go/zodb/btree/btree.go
View file @
1f651171
...
...
@@ -28,9 +28,9 @@ import (
"reflect"
"sort"
pickle
"github.com/kisielk/og-rek"
"lab.nexedi.com/kirr/go123/xerr"
"lab.nexedi.com/kirr/neo/go/zodb"
pickle
"github.com/kisielk/og-rek"
)
// KEY is the type for BTree keys.
...
...
@@ -38,7 +38,6 @@ import (
// XXX -> template?
type
KEY
int64
// Bucket is a leaf node of a B⁺ tree.
//
// It mimics ?OBucket from btree/py, with ? being any integer.
...
...
@@ -53,17 +52,17 @@ type Bucket struct {
// are chained together via 'next', so that the entire BTree contents
// can be traversed in sorted order quickly and easily.
next
*
Bucket
// the bucket with the next-larger keys
keys
[]
KEY
// 'len' keys, in increasing order
values
[]
interface
{}
// 'len' corresponding values
next
*
Bucket
// the bucket with the next-larger keys
keys
[]
KEY
// 'len' keys, in increasing order
values
[]
interface
{}
// 'len' corresponding values
}
// _BTreeItem mimics BTreeItem from btree/py.
//
// XXX export for BTree.Children?
type
_BTreeItem
struct
{
key
KEY
child
interface
{}
// BTree or Bucket
key
KEY
child
interface
{}
// BTree or Bucket
}
// BTree is a non-leaf node of a B⁺ tree.
...
...
@@ -86,7 +85,7 @@ type BTree struct {
// 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
// endpoints pretending that data[0].key is -∞ and data[len].key is +∞.
data
[]
_BTreeItem
data
[]
_BTreeItem
}
// Get searches BTree by key.
...
...
@@ -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
{
j
:=
i
+
1
if
j
==
len
(
t
.
data
)
{
return
true
// [len].key = +∞
return
true
// [len].key = +∞
}
return
key
<
t
.
data
[
j
]
.
key
})
...
...
@@ -216,7 +215,7 @@ func (b *bucketState) PySetState(pystate interface{}) (err error) {
if
!
ok
{
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
))
}
...
...
@@ -229,13 +228,13 @@ func (b *bucketState) PySetState(pystate interface{}) (err error) {
xk
:=
t
[
2
*
i
]
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
{
return
fmt
.
Errorf
(
"data: [%d]: key must be integer; got %T"
,
i
,
xk
)
}
// 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
)
}
...
...
@@ -324,7 +323,7 @@ func (bt *btreeState) PySetState(pystate interface{}) (err error) {
if
!
ok
{
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
))
}
...
...
@@ -334,8 +333,8 @@ func (bt *btreeState) PySetState(pystate interface{}) (err error) {
key
:=
int64
(
0
)
if
i
>
0
{
// key[0] is unused and not saved
key
,
ok
=
t
[
idx
]
.
(
int64
)
// XXX Xint
if
!
ok
{
key
,
ok
=
t
[
idx
]
.
(
int64
)
// XXX Xint
if
!
ok
{
return
fmt
.
Errorf
(
"data: [%d]: key must be integer; got %T"
,
i
,
t
[
idx
])
}
idx
++
...
...
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