Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
B
b
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
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
b
Commits
050650f2
Commit
050650f2
authored
Apr 11, 2017
by
Kirill Smelkov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
.
parent
7ce1eb75
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
23 additions
and
24 deletions
+23
-24
btree.go
btree.go
+23
-24
No files found.
btree.go
View file @
050650f2
...
@@ -39,7 +39,7 @@ type btTpool struct{ sync.Pool }
...
@@ -39,7 +39,7 @@ type btTpool struct{ sync.Pool }
func
(
p
*
btTpool
)
get
(
cmp
Cmp
)
*
Tree
{
func
(
p
*
btTpool
)
get
(
cmp
Cmp
)
*
Tree
{
x
:=
p
.
Get
()
.
(
*
Tree
)
x
:=
p
.
Get
()
.
(
*
Tree
)
x
.
cmp
=
cmp
x
.
cmp
=
cmp
//x.hit
Idx
= -1
//x.hit
Di
= -1
//x.hitPi = -1
//x.hitPi = -1
//x.hitMinKMInf = true
//x.hitMinKMInf = true
//x.hitMaxKInf = true
//x.hitMaxKInf = true
...
@@ -104,8 +104,8 @@ type (
...
@@ -104,8 +104,8 @@ type (
// last data page which Set/Put/Delete/XXX recheck modified
// last data page which Set/Put/Delete/XXX recheck modified
// XXX naming
// XXX naming
hit
*
d
hit
D
*
d
hit
Idx
int
hit
Di
int
hitKmin
xkey
hitKmin
xkey
hitKmax
xkey
hitKmax
xkey
...
@@ -128,15 +128,15 @@ type (
...
@@ -128,15 +128,15 @@ type (
x
[
2
*
kx
+
2
]
xe
x
[
2
*
kx
+
2
]
xe
}
}
xkey
struct
{
// key + whether value is present
xkey
struct
{
// key + whether value is present
at all
k
interface
{}
/*K*/
k
interface
{}
/*K*/
kset
bool
// if not set - k not present
kset
bool
// if not set - k not present
}
}
keyrange
struct
{
// key range [kmin, kmax)
//
keyrange struct { // key range [kmin, kmax)
kmin
xkey
// if not set = -∞
//
kmin xkey // if not set = -∞
kmax
xkey
// if not set = +∞
//
kmax xkey // if not set = +∞
}
//
}
)
)
var
(
// R/O zero values
var
(
// R/O zero values
...
@@ -245,7 +245,7 @@ func (t *Tree) Clear() {
...
@@ -245,7 +245,7 @@ func (t *Tree) Clear() {
clr
(
t
.
r
)
clr
(
t
.
r
)
t
.
c
,
t
.
first
,
t
.
last
,
t
.
r
=
0
,
nil
,
nil
,
nil
t
.
c
,
t
.
first
,
t
.
last
,
t
.
r
=
0
,
nil
,
nil
,
nil
// TODO reset .hit
// TODO reset .hit
D
t
.
ver
++
t
.
ver
++
}
}
...
@@ -446,15 +446,15 @@ func (t *Tree) find2(d *d, k interface{} /*K*/, l, h int) (i int, ok bool) {
...
@@ -446,15 +446,15 @@ func (t *Tree) find2(d *d, k interface{} /*K*/, l, h int) (i int, ok bool) {
// hitFind returns whether k belongs to previosly hit data page XXX text
// hitFind returns whether k belongs to previosly hit data page XXX text
// if no -1, false is returned
// if no -1, false is returned
// if yes returned are:
// if yes returned are:
// - i: index corresponding to data entry in t.hit with min(k' : k' >= k)
// - i: index corresponding to data entry in t.hit
D
with min(k' : k' >= k)
// - ok: whether k' == k
// - ok: whether k' == k
func
(
t
*
Tree
)
hitFind
(
k
interface
{}
/*K*/
)
(
i
int
,
ok
bool
)
{
func
(
t
*
Tree
)
hitFind
(
k
interface
{}
/*K*/
)
(
i
int
,
ok
bool
)
{
hit
:=
t
.
hit
hit
:=
t
.
hit
D
if
hit
==
nil
{
if
hit
==
nil
{
return
-
1
,
false
return
-
1
,
false
}
}
i
=
t
.
hit
Idx
i
=
t
.
hit
Di
//p := t.hitP
//p := t.hitP
//pi := t.hitPi
//pi := t.hitPi
...
@@ -546,8 +546,8 @@ func (t *Tree) insert(q *d, i int, k interface{} /*K*/, v interface{} /*V*/) *d
...
@@ -546,8 +546,8 @@ func (t *Tree) insert(q *d, i int, k interface{} /*K*/, v interface{} /*V*/) *d
q
.
c
=
c
q
.
c
=
c
q
.
d
[
i
]
.
k
,
q
.
d
[
i
]
.
v
=
k
,
v
q
.
d
[
i
]
.
k
,
q
.
d
[
i
]
.
v
=
k
,
v
t
.
c
++
t
.
c
++
t
.
hit
=
q
t
.
hit
D
=
q
t
.
hit
Idx
=
i
t
.
hit
Di
=
i
return
q
return
q
}
}
...
@@ -670,7 +670,7 @@ func (t *Tree) SeekLast() (e *Enumerator, err error) {
...
@@ -670,7 +670,7 @@ func (t *Tree) SeekLast() (e *Enumerator, err error) {
// Set sets the value associated with k.
// Set sets the value associated with k.
func
(
t
*
Tree
)
Set
(
k
interface
{}
/*K*/
,
v
interface
{}
/*V*/
)
{
func
(
t
*
Tree
)
Set
(
k
interface
{}
/*K*/
,
v
interface
{}
/*V*/
)
{
//dbg("--- PRE Set(%v, %v)\t(%v @%d, [%v, %v))\n%s", k, v, t.hit
, t.hitIdx
, t.hitKmin, t.hitKmax, t.dump())
//dbg("--- PRE Set(%v, %v)\t(%v @%d, [%v, %v))\n%s", k, v, t.hit
D, t.hitDi
, t.hitKmin, t.hitKmax, t.dump())
//defer func() {
//defer func() {
// //if r := recover(); r != nil {
// //if r := recover(); r != nil {
// // panic(r)
// // panic(r)
...
@@ -682,14 +682,14 @@ func (t *Tree) Set(k interface{} /*K*/, v interface{} /*V*/) {
...
@@ -682,14 +682,14 @@ func (t *Tree) Set(k interface{} /*K*/, v interface{} /*V*/) {
i
,
ok
:=
t
.
hitFind
(
k
)
i
,
ok
:=
t
.
hitFind
(
k
)
if
i
>=
0
{
if
i
>=
0
{
//dbg("hit found\t-> %d, %v", i, ok)
//dbg("hit found\t-> %d, %v", i, ok)
//dd, p, pi := t.hit, t.hitP, t.hitPi
//dd, p, pi := t.hit
D
, t.hitP, t.hitPi
dd
:=
t
.
hit
dd
:=
t
.
hit
D
switch
{
switch
{
case
ok
:
case
ok
:
//dbg("ok'")
//dbg("ok'")
dd
.
d
[
i
]
.
v
=
v
dd
.
d
[
i
]
.
v
=
v
t
.
hit
Idx
=
i
t
.
hit
Di
=
i
return
return
case
dd
.
c
<
2
*
kd
:
case
dd
.
c
<
2
*
kd
:
...
@@ -697,6 +697,7 @@ func (t *Tree) Set(k interface{} /*K*/, v interface{} /*V*/) {
...
@@ -697,6 +697,7 @@ func (t *Tree) Set(k interface{} /*K*/, v interface{} /*V*/) {
t
.
insert
(
dd
,
i
,
k
,
v
)
t
.
insert
(
dd
,
i
,
k
,
v
)
return
return
// XXX reenable overflow here
//case p == nil || p.c <= 2*kx:
//case p == nil || p.c <= 2*kx:
// dbg("overflow'")
// dbg("overflow'")
// t.overflow(p, dd, pi, i, k, v)
// t.overflow(p, dd, pi, i, k, v)
...
@@ -712,7 +713,6 @@ func (t *Tree) Set(k interface{} /*K*/, v interface{} /*V*/) {
...
@@ -712,7 +713,6 @@ func (t *Tree) Set(k interface{} /*K*/, v interface{} /*V*/) {
pi
:=
-
1
pi
:=
-
1
var
p
*
x
var
p
*
x
q
:=
t
.
r
q
:=
t
.
r
if
q
==
nil
{
if
q
==
nil
{
//dbg("empty")
//dbg("empty")
z
:=
t
.
insert
(
btDPool
.
Get
()
.
(
*
d
),
0
,
k
,
v
)
// XXX update hit
z
:=
t
.
insert
(
btDPool
.
Get
()
.
(
*
d
),
0
,
k
,
v
)
// XXX update hit
...
@@ -767,7 +767,7 @@ func (t *Tree) Set(k interface{} /*K*/, v interface{} /*V*/) {
...
@@ -767,7 +767,7 @@ func (t *Tree) Set(k interface{} /*K*/, v interface{} /*V*/) {
case
ok
:
case
ok
:
//dbg("ok")
//dbg("ok")
x
.
d
[
i
]
.
v
=
v
x
.
d
[
i
]
.
v
=
v
t
.
hit
,
t
.
hitIdx
=
x
,
i
t
.
hit
D
,
t
.
hitDi
=
x
,
i
case
x
.
c
<
2
*
kd
:
case
x
.
c
<
2
*
kd
:
//dbg("insert")
//dbg("insert")
...
@@ -782,7 +782,6 @@ func (t *Tree) Set(k interface{} /*K*/, v interface{} /*V*/) {
...
@@ -782,7 +782,6 @@ func (t *Tree) Set(k interface{} /*K*/, v interface{} /*V*/) {
return
return
}
}
}
}
}
}
// Put combines Get and Set in a more efficient way where the tree is walked
// Put combines Get and Set in a more efficient way where the tree is walked
...
@@ -814,7 +813,7 @@ func (t *Tree) Put(k interface{} /*K*/, upd func(oldV interface{} /*V*/, exists
...
@@ -814,7 +813,7 @@ func (t *Tree) Put(k interface{} /*K*/, upd func(oldV interface{} /*V*/, exists
return
return
}
}
// TODO handle t.hit
// TODO handle t.hit
D
for
{
for
{
i
,
ok
:=
t
.
find
(
q
,
k
)
i
,
ok
:=
t
.
find
(
q
,
k
)
...
@@ -978,14 +977,14 @@ func (t *Tree) underflow(p *x, q *d, pi int) {
...
@@ -978,14 +977,14 @@ func (t *Tree) underflow(p *x, q *d, pi int) {
if
l
!=
nil
&&
l
.
c
+
q
.
c
>=
2
*
kd
{
if
l
!=
nil
&&
l
.
c
+
q
.
c
>=
2
*
kd
{
l
.
mvR
(
q
,
1
)
l
.
mvR
(
q
,
1
)
// TODO update t.hit = q @ i
// TODO update t.hit
D
= q @ i
p
.
x
[
pi
-
1
]
.
k
=
q
.
d
[
0
]
.
k
p
.
x
[
pi
-
1
]
.
k
=
q
.
d
[
0
]
.
k
return
return
}
}
if
r
!=
nil
&&
q
.
c
+
r
.
c
>=
2
*
kd
{
if
r
!=
nil
&&
q
.
c
+
r
.
c
>=
2
*
kd
{
q
.
mvL
(
r
,
1
)
q
.
mvL
(
r
,
1
)
// TODO update t.hit = q @ i
// TODO update t.hit
D
= q @ i
p
.
x
[
pi
]
.
k
=
r
.
d
[
0
]
.
k
p
.
x
[
pi
]
.
k
=
r
.
d
[
0
]
.
k
r
.
d
[
r
.
c
]
=
zde
// GC
r
.
d
[
r
.
c
]
=
zde
// GC
return
return
...
...
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