Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
W
wendelin.core
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Labels
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
Kirill Smelkov
wendelin.core
Commits
db65b87d
Commit
db65b87d
authored
Jul 19, 2018
by
Kirill Smelkov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
.
parent
6c37f3b3
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
25 additions
and
10 deletions
+25
-10
wcfs/btree.go
wcfs/btree.go
+25
-10
No files found.
wcfs/btree.go
View file @
db65b87d
...
@@ -18,6 +18,7 @@ import (
...
@@ -18,6 +18,7 @@ import (
"context"
"context"
"sort"
"sort"
"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"
pickle
"github.com/kisielk/og-rek"
)
)
...
@@ -73,9 +74,12 @@ type ZBTree struct {
...
@@ -73,9 +74,12 @@ type ZBTree struct {
// Get searches BTree by key.
// Get searches BTree by key.
//
//
// It loads intermediate BTree nodes from database on demand as needed.
// It loads intermediate BTree nodes from database on demand as needed.
// XXX ok -> ErrKeyNotFound?
func
(
t
*
ZBTree
)
Get
(
ctx
context
.
Context
,
key
KEY
)
(
_
interface
{},
_
bool
,
err
error
)
{
func
(
t
*
ZBTree
)
Get
(
ctx
context
.
Context
,
key
KEY
)
(
interface
{},
bool
,
error
)
{
defer
xerr
.
Contextf
(
&
err
,
"btree(%s): get %s"
)
// XXX + url?
t
.
PActivate
(
ctx
)
// XXX err
err
=
t
.
PActivate
(
ctx
)
if
err
!=
nil
{
return
nil
,
false
,
err
}
if
len
(
t
.
data
)
==
0
{
if
len
(
t
.
data
)
==
0
{
// empty btree
// empty btree
...
@@ -97,24 +101,35 @@ func (t *ZBTree) Get(ctx context.Context, key KEY) (interface{}, bool, error) {
...
@@ -97,24 +101,35 @@ func (t *ZBTree) Get(ctx context.Context, key KEY) (interface{}, bool, error) {
case
*
ZBTree
:
case
*
ZBTree
:
t
.
PDeactivate
()
t
.
PDeactivate
()
t
=
child
t
=
child
t
.
PActivate
(
ctx
)
// XXX err
err
=
t
.
PActivate
(
ctx
)
if
err
!=
nil
{
return
nil
,
false
,
err
}
case
*
ZBucket
:
case
*
ZBucket
:
t
.
PDeactivate
()
t
.
PDeactivate
()
child
.
PActivate
(
ctx
)
// XXX err
return
child
.
Get
(
ctx
,
key
)
v
,
ok
:=
child
.
get
(
key
)
child
.
PDeactivate
()
return
v
,
ok
,
nil
}
}
}
}
}
}
// Get searches Bucket by key.
func
(
b
*
ZBucket
)
Get
(
ctx
context
.
Context
,
key
KEY
)
(
_
interface
{},
_
bool
,
err
error
)
{
defer
xerr
.
Contextf
(
&
err
,
"bucket(%s): get %s"
)
// XXX + url?
err
=
b
.
PActivate
(
ctx
)
if
err
!=
nil
{
return
nil
,
false
,
err
}
v
,
ok
:=
b
.
get
(
key
)
b
.
PDeactivate
()
return
v
,
ok
,
nil
}
// get searches Bucket by key.
// get searches Bucket by key.
//
//
// no loading from database is done. The bucket must be already activated.
// no loading from database is done. The bucket must be already activated.
func
(
b
*
ZBucket
)
get
(
key
KEY
)
(
interface
{},
bool
)
{
func
(
b
*
ZBucket
)
get
(
key
KEY
)
(
interface
{},
bool
)
{
// XXX b.PActivate ? XXX better caller? (or inside if get -> Get)
// search i: K(i-1) < k ≤ K(i) ; K(-1) = -∞, K(len) = +∞
// search i: K(i-1) < k ≤ K(i) ; K(-1) = -∞, K(len) = +∞
i
:=
sort
.
Search
(
len
(
b
.
keys
),
func
(
i
int
)
bool
{
i
:=
sort
.
Search
(
len
(
b
.
keys
),
func
(
i
int
)
bool
{
return
key
<=
b
.
keys
[
i
]
return
key
<=
b
.
keys
[
i
]
...
...
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