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 }
func
(
p
*
btTpool
)
get
(
cmp
Cmp
)
*
Tree
{
x
:=
p
.
Get
()
.
(
*
Tree
)
x
.
cmp
=
cmp
//x.hit
Idx
= -1
//x.hit
Di
= -1
//x.hitPi = -1
//x.hitMinKMInf = true
//x.hitMaxKInf = true
...
...
@@ -104,8 +104,8 @@ type (
// last data page which Set/Put/Delete/XXX recheck modified
// XXX naming
hit
*
d
hit
Idx
int
hit
D
*
d
hit
Di
int
hitKmin
xkey
hitKmax
xkey
...
...
@@ -128,15 +128,15 @@ type (
x
[
2
*
kx
+
2
]
xe
}
xkey
struct
{
// key + whether value is present
xkey
struct
{
// key + whether value is present
at all
k
interface
{}
/*K*/
kset
bool
// if not set - k not present
}
keyrange
struct
{
// key range [kmin, kmax)
kmin
xkey
// if not set = -∞
kmax
xkey
// if not set = +∞
}
//
keyrange struct { // key range [kmin, kmax)
//
kmin xkey // if not set = -∞
//
kmax xkey // if not set = +∞
//
}
)
var
(
// R/O zero values
...
...
@@ -245,7 +245,7 @@ func (t *Tree) Clear() {
clr
(
t
.
r
)
t
.
c
,
t
.
first
,
t
.
last
,
t
.
r
=
0
,
nil
,
nil
,
nil
// TODO reset .hit
// TODO reset .hit
D
t
.
ver
++
}
...
...
@@ -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
// if no -1, false is returned
// 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
func
(
t
*
Tree
)
hitFind
(
k
interface
{}
/*K*/
)
(
i
int
,
ok
bool
)
{
hit
:=
t
.
hit
hit
:=
t
.
hit
D
if
hit
==
nil
{
return
-
1
,
false
}
i
=
t
.
hit
Idx
i
=
t
.
hit
Di
//p := t.hitP
//pi := t.hitPi
...
...
@@ -546,8 +546,8 @@ func (t *Tree) insert(q *d, i int, k interface{} /*K*/, v interface{} /*V*/) *d
q
.
c
=
c
q
.
d
[
i
]
.
k
,
q
.
d
[
i
]
.
v
=
k
,
v
t
.
c
++
t
.
hit
=
q
t
.
hit
Idx
=
i
t
.
hit
D
=
q
t
.
hit
Di
=
i
return
q
}
...
...
@@ -670,7 +670,7 @@ func (t *Tree) SeekLast() (e *Enumerator, err error) {
// Set sets the value associated with k.
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() {
// //if r := recover(); r != nil {
// // panic(r)
...
...
@@ -682,14 +682,14 @@ func (t *Tree) Set(k interface{} /*K*/, v interface{} /*V*/) {
i
,
ok
:=
t
.
hitFind
(
k
)
if
i
>=
0
{
//dbg("hit found\t-> %d, %v", i, ok)
//dd, p, pi := t.hit, t.hitP, t.hitPi
dd
:=
t
.
hit
//dd, p, pi := t.hit
D
, t.hitP, t.hitPi
dd
:=
t
.
hit
D
switch
{
case
ok
:
//dbg("ok'")
dd
.
d
[
i
]
.
v
=
v
t
.
hit
Idx
=
i
t
.
hit
Di
=
i
return
case
dd
.
c
<
2
*
kd
:
...
...
@@ -697,6 +697,7 @@ func (t *Tree) Set(k interface{} /*K*/, v interface{} /*V*/) {
t
.
insert
(
dd
,
i
,
k
,
v
)
return
// XXX reenable overflow here
//case p == nil || p.c <= 2*kx:
// dbg("overflow'")
// t.overflow(p, dd, pi, i, k, v)
...
...
@@ -712,7 +713,6 @@ func (t *Tree) Set(k interface{} /*K*/, v interface{} /*V*/) {
pi
:=
-
1
var
p
*
x
q
:=
t
.
r
if
q
==
nil
{
//dbg("empty")
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*/) {
case
ok
:
//dbg("ok")
x
.
d
[
i
]
.
v
=
v
t
.
hit
,
t
.
hitIdx
=
x
,
i
t
.
hit
D
,
t
.
hitDi
=
x
,
i
case
x
.
c
<
2
*
kd
:
//dbg("insert")
...
...
@@ -782,7 +782,6 @@ func (t *Tree) Set(k interface{} /*K*/, v interface{} /*V*/) {
return
}
}
}
// 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
return
}
// TODO handle t.hit
// TODO handle t.hit
D
for
{
i
,
ok
:=
t
.
find
(
q
,
k
)
...
...
@@ -978,14 +977,14 @@ func (t *Tree) underflow(p *x, q *d, pi int) {
if
l
!=
nil
&&
l
.
c
+
q
.
c
>=
2
*
kd
{
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
return
}
if
r
!=
nil
&&
q
.
c
+
r
.
c
>=
2
*
kd
{
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
r
.
d
[
r
.
c
]
=
zde
// GC
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