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
817e27db
Commit
817e27db
authored
Apr 13, 2017
by
Kirill Smelkov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
.
parent
a77b5775
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
42 additions
and
25 deletions
+42
-25
btree.go
btree.go
+42
-25
No files found.
btree.go
View file @
817e27db
...
@@ -245,7 +245,6 @@ func (t *Tree) Close() {
...
@@ -245,7 +245,6 @@ func (t *Tree) Close() {
}
}
func
(
t
*
Tree
)
cat
(
p
*
x
,
q
,
r
*
d
,
pi
int
)
{
func
(
t
*
Tree
)
cat
(
p
*
x
,
q
,
r
*
d
,
pi
int
)
{
// XXX update hit (called from Delete -> underflow ) ?
t
.
ver
++
t
.
ver
++
q
.
mvL
(
r
,
r
.
c
)
q
.
mvL
(
r
,
r
.
c
)
if
r
.
n
!=
nil
{
if
r
.
n
!=
nil
{
...
@@ -365,19 +364,28 @@ func (t *Tree) Delete(k interface{} /*K*/) (ok bool) {
...
@@ -365,19 +364,28 @@ func (t *Tree) Delete(k interface{} /*K*/) (ok bool) {
return
false
return
false
}
}
var
hitKmin
,
hitKmax
xkey
// initially [-∞, +∞)
// XXX recheck what is better - directly update t.hitK* or copy
var
hitPKmax
xkey
// Kmax for whole hitP
// NOTE having t.hitK* up to data is handy for underflowX
//var hitKmin, hitKmax xkey // initially [-∞, +∞)
//var hitPKmax xkey // Kmax for whole hitP
t
.
hitKmin
=
xkey
{}
// initially [-∞, +∞)
t
.
hitKmax
=
xkey
{}
t
.
hitPKmax
=
xkey
{}
for
{
for
{
i
,
ok
:=
t
.
find
(
q
,
k
)
i
,
ok
:=
t
.
find
(
q
,
k
)
switch
x
:=
q
.
(
type
)
{
switch
x
:=
q
.
(
type
)
{
case
*
x
:
case
*
x
:
hitPKmax
=
hitKmax
if
ok
{
i
++
}
if
x
.
c
<
kx
&&
q
!=
t
.
r
{
if
x
.
c
<
kx
&&
q
!=
t
.
r
{
dbg
(
"UNDERFLOWX
\n\t
p: %v @%d
\n\t
x: %v @%d"
,
p
,
pi
,
x
,
i
)
dbg
(
"UNDERFLOWX
\n\t
p: %v @%d
\n\t
x: %v @%d"
,
p
,
pi
,
x
,
i
)
x
,
i
,
pi
=
t
.
underflowX
(
p
,
x
,
pi
,
i
)
x
,
i
=
t
.
underflowX
(
p
,
x
,
pi
,
i
)
/*
dbg("\n\t-> p: %v @%d\n\tx: %v @%d", p, pi, x, i)
dbg("\n\t-> p: %v @%d\n\tx: %v @%d", p, pi, x, i)
// NOTE underflowX changes p which means hit
// NOTE underflowX changes p which means hit
...
@@ -393,32 +401,34 @@ func (t *Tree) Delete(k interface{} /*K*/) (ok bool) {
...
@@ -393,32 +401,34 @@ func (t *Tree) Delete(k interface{} /*K*/) (ok bool) {
hitKmin.set(p.x[pi-1].k)
hitKmin.set(p.x[pi-1].k)
dbg("hitKmin X: %v", hitKmin)
dbg("hitKmin X: %v", hitKmin)
}
}
*/
}
}
t
.
hitPKmax
=
t
.
hitKmax
p
=
x
p
=
x
pi
=
i
pi
=
i
if
ok
{
pi
++
}
q
=
x
.
x
[
pi
]
.
ch
q
=
x
.
x
[
pi
]
.
ch
if
pi
>
0
{
if
pi
>
0
{
hitKmin
.
set
(
p
.
x
[
pi
-
1
]
.
k
)
//hitKmin.set(p.x[pi-1].k)
dbg
(
"hitKmin: %v"
,
hitKmin
)
t
.
hitKmin
.
set
(
p
.
x
[
pi
-
1
]
.
k
)
dbg
(
"hitKmin: %v"
,
t
.
hitKmin
)
}
}
if
pi
<
p
.
c
{
// == p.c means ∞
if
pi
<
p
.
c
{
// == p.c means ∞
hitKmax
.
set
(
p
.
x
[
pi
]
.
k
)
//hitKmax.set(p.x[pi].k)
dbg
(
"hitKmax: %v"
,
hitKmax
)
t
.
hitKmax
.
set
(
p
.
x
[
pi
]
.
k
)
dbg
(
"hitKmax: %v"
,
t
.
hitKmax
)
}
}
case
*
d
:
case
*
d
:
// data page found - perform the delete
// data page found - perform the delete
t
.
hitP
=
p
t
.
hitP
=
p
t
.
hitPi
=
pi
t
.
hitPi
=
pi
t
.
hitKmin
=
hitKmin
//
t.hitKmin = hitKmin
t
.
hitKmax
=
hitKmax
//
t.hitKmax = hitKmax
t
.
hitPKmax
=
hitPKmax
//
t.hitPKmax = hitPKmax
if
!
ok
{
if
!
ok
{
dbg
(
"!ok"
)
dbg
(
"!ok"
)
...
@@ -1031,15 +1041,15 @@ func (t *Tree) underflow(p *x, q *d, pi int) {
...
@@ -1031,15 +1041,15 @@ func (t *Tree) underflow(p *x, q *d, pi int) {
t
.
cat
(
p
,
q
,
r
,
pi
)
t
.
cat
(
p
,
q
,
r
,
pi
)
// hitD/hitDi stays unchanged
// hitD/hitDi stays unchanged
kmax
:
=
t
.
hitPKmax
t
.
hitKmax
=
t
.
hitPKmax
if
pi
<
p
.
c
{
// means < ∞
if
t
.
r
!=
q
&&
pi
<
p
.
c
{
// means < ∞
k
max
.
set
(
p
.
x
[
pi
]
.
k
)
t
.
hitK
max
.
set
(
p
.
x
[
pi
]
.
k
)
}
}
t
.
hitKmax
=
kmax
// XXX vvv correct vs t.r != q ?
t
.
hitPi
=
pi
t
.
hitPi
=
pi
// XXX? (+ already pre-set this way ?)
}
}
func
(
t
*
Tree
)
underflowX
(
p
*
x
,
q
*
x
,
pi
int
,
i
int
)
(
*
x
,
int
,
int
)
{
func
(
t
*
Tree
)
underflowX
(
p
*
x
,
q
*
x
,
pi
int
,
i
int
)
(
*
x
,
int
)
{
t
.
ver
++
t
.
ver
++
var
l
,
r
*
x
var
l
,
r
*
x
...
@@ -1061,7 +1071,8 @@ func (t *Tree) underflowX(p *x, q *x, pi int, i int) (*x, int, int) {
...
@@ -1061,7 +1071,8 @@ func (t *Tree) underflowX(p *x, q *x, pi int, i int) (*x, int, int) {
i
++
i
++
l
.
c
--
l
.
c
--
p
.
x
[
pi
-
1
]
.
k
=
l
.
x
[
l
.
c
]
.
k
p
.
x
[
pi
-
1
]
.
k
=
l
.
x
[
l
.
c
]
.
k
return
q
,
i
,
pi
t
.
hitKmin
.
set
(
l
.
x
[
l
.
c
]
.
k
)
return
q
,
i
}
}
if
r
!=
nil
&&
r
.
c
>
kx
{
if
r
!=
nil
&&
r
.
c
>
kx
{
...
@@ -1069,24 +1080,30 @@ func (t *Tree) underflowX(p *x, q *x, pi int, i int) (*x, int, int) {
...
@@ -1069,24 +1080,30 @@ func (t *Tree) underflowX(p *x, q *x, pi int, i int) (*x, int, int) {
q
.
c
++
q
.
c
++
q
.
x
[
q
.
c
]
.
ch
=
r
.
x
[
0
]
.
ch
q
.
x
[
q
.
c
]
.
ch
=
r
.
x
[
0
]
.
ch
p
.
x
[
pi
]
.
k
=
r
.
x
[
0
]
.
k
p
.
x
[
pi
]
.
k
=
r
.
x
[
0
]
.
k
t
.
hitKmax
.
set
(
r
.
x
[
0
]
.
k
)
copy
(
r
.
x
[
:
],
r
.
x
[
1
:
r
.
c
])
copy
(
r
.
x
[
:
],
r
.
x
[
1
:
r
.
c
])
r
.
c
--
r
.
c
--
rc
:=
r
.
c
rc
:=
r
.
c
r
.
x
[
rc
]
.
ch
=
r
.
x
[
rc
+
1
]
.
ch
r
.
x
[
rc
]
.
ch
=
r
.
x
[
rc
+
1
]
.
ch
r
.
x
[
rc
]
.
k
=
zk
r
.
x
[
rc
]
.
k
=
zk
r
.
x
[
rc
+
1
]
.
ch
=
nil
r
.
x
[
rc
+
1
]
.
ch
=
nil
return
q
,
i
,
pi
return
q
,
i
}
}
if
l
!=
nil
{
if
l
!=
nil
{
i
+=
l
.
c
+
1
i
+=
l
.
c
+
1
t
.
catX
(
p
,
l
,
q
,
pi
-
1
)
t
.
catX
(
p
,
l
,
q
,
pi
-
1
)
t
.
hitKmin
.
set
(
p
.
x
[
pi
-
1
]
.
k
)
q
=
l
q
=
l
return
q
,
i
,
pi
-
1
return
q
,
i
}
}
t
.
catX
(
p
,
q
,
r
,
pi
)
t
.
catX
(
p
,
q
,
r
,
pi
)
return
q
,
i
,
pi
t
.
hitKmax
=
t
.
hitPKmax
if
t
.
r
!=
q
&&
pi
<
p
.
c
{
// means < ∞
t
.
hitKmax
.
set
(
p
.
x
[
pi
]
.
k
)
}
return
q
,
i
}
}
// ----------------------------------------------------------------- Enumerator
// ----------------------------------------------------------------- Enumerator
...
...
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