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() {
}
func
(
t
*
Tree
)
cat
(
p
*
x
,
q
,
r
*
d
,
pi
int
)
{
// XXX update hit (called from Delete -> underflow ) ?
t
.
ver
++
q
.
mvL
(
r
,
r
.
c
)
if
r
.
n
!=
nil
{
...
...
@@ -365,19 +364,28 @@ func (t *Tree) Delete(k interface{} /*K*/) (ok bool) {
return
false
}
var
hitKmin
,
hitKmax
xkey
// initially [-∞, +∞)
var
hitPKmax
xkey
// Kmax for whole hitP
// XXX recheck what is better - directly update t.hitK* or copy
// 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
{
i
,
ok
:=
t
.
find
(
q
,
k
)
switch
x
:=
q
.
(
type
)
{
case
*
x
:
hitPKmax
=
hitKmax
if
ok
{
i
++
}
if
x
.
c
<
kx
&&
q
!=
t
.
r
{
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)
// NOTE underflowX changes p which means hit
...
...
@@ -393,32 +401,34 @@ func (t *Tree) Delete(k interface{} /*K*/) (ok bool) {
hitKmin.set(p.x[pi-1].k)
dbg("hitKmin X: %v", hitKmin)
}
*/
}
t
.
hitPKmax
=
t
.
hitKmax
p
=
x
pi
=
i
if
ok
{
pi
++
}
q
=
x
.
x
[
pi
]
.
ch
if
pi
>
0
{
hitKmin
.
set
(
p
.
x
[
pi
-
1
]
.
k
)
dbg
(
"hitKmin: %v"
,
hitKmin
)
//hitKmin.set(p.x[pi-1].k)
t
.
hitKmin
.
set
(
p
.
x
[
pi
-
1
]
.
k
)
dbg
(
"hitKmin: %v"
,
t
.
hitKmin
)
}
if
pi
<
p
.
c
{
// == p.c means ∞
hitKmax
.
set
(
p
.
x
[
pi
]
.
k
)
dbg
(
"hitKmax: %v"
,
hitKmax
)
//hitKmax.set(p.x[pi].k)
t
.
hitKmax
.
set
(
p
.
x
[
pi
]
.
k
)
dbg
(
"hitKmax: %v"
,
t
.
hitKmax
)
}
case
*
d
:
// data page found - perform the delete
t
.
hitP
=
p
t
.
hitPi
=
pi
t
.
hitKmin
=
hitKmin
t
.
hitKmax
=
hitKmax
t
.
hitPKmax
=
hitPKmax
//
t.hitKmin = hitKmin
//
t.hitKmax = hitKmax
//
t.hitPKmax = hitPKmax
if
!
ok
{
dbg
(
"!ok"
)
...
...
@@ -1031,15 +1041,15 @@ func (t *Tree) underflow(p *x, q *d, pi int) {
t
.
cat
(
p
,
q
,
r
,
pi
)
// hitD/hitDi stays unchanged
kmax
:
=
t
.
hitPKmax
if
pi
<
p
.
c
{
// means < ∞
k
max
.
set
(
p
.
x
[
pi
]
.
k
)
t
.
hitKmax
=
t
.
hitPKmax
if
t
.
r
!=
q
&&
pi
<
p
.
c
{
// means < ∞
t
.
hitK
max
.
set
(
p
.
x
[
pi
]
.
k
)
}
t
.
hitKmax
=
kmax
t
.
hitPi
=
pi
// XXX vvv correct vs t.r != q ?
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
++
var
l
,
r
*
x
...
...
@@ -1061,7 +1071,8 @@ func (t *Tree) underflowX(p *x, q *x, pi int, i int) (*x, int, int) {
i
++
l
.
c
--
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
{
...
...
@@ -1069,24 +1080,30 @@ func (t *Tree) underflowX(p *x, q *x, pi int, i int) (*x, int, int) {
q
.
c
++
q
.
x
[
q
.
c
]
.
ch
=
r
.
x
[
0
]
.
ch
p
.
x
[
pi
]
.
k
=
r
.
x
[
0
]
.
k
t
.
hitKmax
.
set
(
r
.
x
[
0
]
.
k
)
copy
(
r
.
x
[
:
],
r
.
x
[
1
:
r
.
c
])
r
.
c
--
rc
:=
r
.
c
r
.
x
[
rc
]
.
ch
=
r
.
x
[
rc
+
1
]
.
ch
r
.
x
[
rc
]
.
k
=
zk
r
.
x
[
rc
+
1
]
.
ch
=
nil
return
q
,
i
,
pi
return
q
,
i
}
if
l
!=
nil
{
i
+=
l
.
c
+
1
t
.
catX
(
p
,
l
,
q
,
pi
-
1
)
t
.
hitKmin
.
set
(
p
.
x
[
pi
-
1
]
.
k
)
q
=
l
return
q
,
i
,
pi
-
1
return
q
,
i
}
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
...
...
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