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
09021d5c
Commit
09021d5c
authored
Apr 13, 2017
by
Kirill Smelkov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
.
parent
a3ada377
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
41 additions
and
20 deletions
+41
-20
all_test.go
all_test.go
+6
-6
btree.go
btree.go
+35
-14
No files found.
all_test.go
View file @
09021d5c
...
...
@@ -161,7 +161,7 @@ func (t *Tree) checkHit(k interface{} /*K*/, op treeOp) {
var
ok
bool
var
hitKmin
,
hitKmax
xkey
var
hitPKmax
xkey
var
hitPKm
in
,
hitPKm
ax
xkey
loop
:
// here he tree is immutable while we are rescanning it, which means
...
...
@@ -176,6 +176,7 @@ loop:
i
,
ok
=
t
.
find
(
q
,
k
)
switch
x
:=
q
.
(
type
)
{
case
*
x
:
hitPKmin
=
hitKmin
hitPKmax
=
hitKmax
p
=
x
...
...
@@ -186,11 +187,10 @@ loop:
q
=
p
.
x
[
pi
]
.
ch
if
pi
>
0
{
hitKminPrev
:=
hitKmin
hitKmin
.
set
(
p
.
x
[
pi
-
1
]
.
k
)
if
hit
KminPrev
.
kset
&&
t
.
cmp
(
hitKmin
.
k
,
hitKminPrev
.
k
)
<=
0
{
bad
(
"hitKmin not ↑: %v -> %v"
,
hit
KminPrev
.
k
,
hitKmin
.
k
)
if
hit
PKmin
.
kset
&&
t
.
cmp
(
hitKmin
.
k
,
hitPKmin
.
k
)
<=
0
{
bad
(
"hitKmin not ↑: %v -> %v"
,
hit
PKmin
.
k
,
hitKmin
.
k
)
}
}
...
...
@@ -230,8 +230,8 @@ loop:
bad
(
"hitK mismatch: [%v, %v) ; want [%v, %v)"
,
t
.
hitKmin
,
t
.
hitKmax
,
hitKmin
,
hitKmax
)
}
if
hitPKmax
!=
t
.
hitPKmax
{
bad
(
"hitPK
max mismatch: %v ; want %v"
,
t
.
hitPKmax
,
hitPKmax
)
if
!
(
hitPKmin
==
t
.
hitPKmin
&&
hitPKmax
==
t
.
hitPKmax
)
{
bad
(
"hitPK
mismatch: [%v, %v) ; want [%v, %v)"
,
t
.
hitPKmin
,
t
.
hitPKmax
,
hitPKmin
,
hitPKmax
)
}
if
dd
!=
t
.
hitD
||
i
!=
t
.
hitDi
{
...
...
btree.go
View file @
09021d5c
...
...
@@ -105,9 +105,10 @@ type (
hitDi
int
hitP
*
x
// parent & pos for data page (= -1 if no parent)
hitPi
int
hitKmin
xkey
//
data page
allowed key range is [hitKmin, hitKmax)
hitKmin
xkey
//
hitD
allowed key range is [hitKmin, hitKmax)
hitKmax
xkey
hitPKmax
xkey
// allowed Kmax for whole hitP
hitPKmin
xkey
// ----//--- for hitP
hitPKmax
xkey
}
xe
struct
{
// x element
...
...
@@ -378,9 +379,9 @@ func (t *Tree) Delete(k interface{} /*K*/) (ok bool) {
//var hitPKmax xkey // Kmax for whole hitP
t
.
hitKmin
=
xkey
{}
// initially [-∞, +∞)
t
.
hitKmax
=
xkey
{}
t
.
hitPKmin
=
xkey
{}
t
.
hitPKmax
=
xkey
{}
for
{
i
,
ok
:=
t
.
find
(
q
,
k
)
switch
x
:=
q
.
(
type
)
{
...
...
@@ -394,6 +395,7 @@ func (t *Tree) Delete(k interface{} /*K*/) (ok bool) {
x
,
i
=
t
.
underflowX
(
p
,
x
,
pi
,
i
)
}
t
.
hitPKmin
=
t
.
hitKmin
t
.
hitPKmax
=
t
.
hitKmax
p
=
x
...
...
@@ -771,6 +773,7 @@ func (t *Tree) Set(k interface{} /*K*/, v interface{} /*V*/) {
//var hitPKmax xkey // Kmax for whole hitP
t
.
hitKmin
=
xkey
{}
// initially [-∞, +∞)
t
.
hitKmax
=
xkey
{}
t
.
hitPKmin
=
xkey
{}
t
.
hitPKmax
=
xkey
{}
for
{
...
...
@@ -787,6 +790,7 @@ func (t *Tree) Set(k interface{} /*K*/, v interface{} /*V*/) {
}
//hitPKmax = hitKmax
t
.
hitPKmin
=
t
.
hitKmin
t
.
hitPKmax
=
t
.
hitKmax
p
=
x
...
...
@@ -1029,9 +1033,20 @@ func (t *Tree) underflow(p *x, q *d, pi int) {
dbg
(
"
\t
underflow -> cat l <- q"
)
t
.
hitD
=
l
t
.
hitDi
+=
l
.
c
t
.
cat
(
p
,
l
,
q
,
pi
-
1
)
t
.
hitKmin
.
set
(
p
.
x
[
pi
-
1
]
.
k
)
t
.
hitPi
=
pi
-
1
pi
--
t
.
cat
(
p
,
l
,
q
,
pi
)
//t.hitKmin.set(p.x[pi-1].k)
t
.
hitKmin
=
t
.
hitPKmin
if
t
.
r
==
l
{
// cat removed p
t
.
hitP
=
nil
t
.
hitPi
=
-
1
}
else
{
if
pi
>
0
{
t
.
hitKmin
.
set
(
p
.
x
[
pi
-
1
]
.
k
)
}
t
.
hitPi
=
pi
}
return
}
...
...
@@ -1039,15 +1054,15 @@ func (t *Tree) underflow(p *x, q *d, pi int) {
t
.
cat
(
p
,
q
,
r
,
pi
)
// hitD/hitDi stays unchanged
t
.
hitKmax
=
t
.
hitPKmax
if
t
.
r
!=
q
{
if
t
.
r
==
q
{
// cat removed p
t
.
hitP
=
nil
t
.
hitPi
=
-
1
}
else
{
if
pi
<
p
.
c
{
// means < ∞
t
.
hitKmax
.
set
(
p
.
x
[
pi
]
.
k
)
}
t
.
hitPi
=
pi
// XXX? (+ already pre-set this way ?)
}
else
{
// cat removed p
t
.
hitP
=
nil
t
.
hitPi
=
-
1
}
}
...
...
@@ -1094,16 +1109,22 @@ func (t *Tree) underflowX(p *x, q *x, pi int, i int) (*x, int) {
if
l
!=
nil
{
i
+=
l
.
c
+
1
t
.
catX
(
p
,
l
,
q
,
pi
-
1
)
t
.
hitKmin
.
set
(
p
.
x
[
pi
-
1
]
.
k
)
pi
--
//t.catX(p, l, q, pi-1)
t
.
catX
(
p
,
l
,
q
,
pi
)
q
=
l
t
.
hitKmin
=
t
.
hitPKmin
if
t
.
r
!=
q
&&
pi
>
0
{
t
.
hitKmin
.
set
(
p
.
x
[
pi
-
1
]
.
k
)
}
//t.hitKmin.set(p.x[pi-1].k) // XXX wrong -> see cat handling in underflow
return
q
,
i
}
t
.
catX
(
p
,
q
,
r
,
pi
)
t
.
hitKmax
=
t
.
hitPKmax
if
t
.
r
!=
q
&&
pi
<
p
.
c
{
// means < ∞
t
.
hitKmax
.
set
(
p
.
x
[
pi
]
.
k
)
t
.
hitKmax
.
set
(
p
.
x
[
pi
]
.
k
)
// XXX ok (was XXX wrong -> see cat handling in underflow)
}
return
q
,
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