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
76522214
Commit
76522214
authored
Apr 11, 2017
by
Kirill Smelkov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
.
parent
811610f0
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
23 additions
and
52 deletions
+23
-52
btree.go
btree.go
+23
-52
No files found.
btree.go
View file @
76522214
...
@@ -231,7 +231,8 @@ func (t *Tree) Clear() {
...
@@ -231,7 +231,8 @@ 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 .hitD
t
.
hitD
,
t
.
hitDi
,
t
.
hitP
,
t
.
hitPi
=
nil
,
-
1
,
nil
,
-
1
t
.
hitKmin
,
t
.
hitKmax
,
t
.
hitPKmax
=
xkey
{},
xkey
{},
xkey
{}
t
.
ver
++
t
.
ver
++
}
}
...
@@ -314,7 +315,6 @@ func (t *Tree) Delete(k interface{} /*K*/) (ok bool) {
...
@@ -314,7 +315,6 @@ func (t *Tree) Delete(k interface{} /*K*/) (ok bool) {
//}()
//}()
// check if we can do the delete nearby previous change
// check if we can do the delete nearby previous change
/*
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)
...
@@ -326,11 +326,11 @@ func (t *Tree) Delete(k interface{} /*K*/) (ok bool) {
...
@@ -326,11 +326,11 @@ func (t *Tree) Delete(k interface{} /*K*/) (ok bool) {
return
false
return
false
// here: need to extract / underflow but check to not underflow too much XXX
// here: need to extract / underflow but check to not underflow too much XXX
// (no underflowX must be called ?)
default
:
default
:
// TODO
// TODO
}
}
}
}
*/
// data page not quickly found - search and descent from root
// data page not quickly found - search and descent from root
pi
:=
-
1
pi
:=
-
1
...
@@ -373,58 +373,14 @@ func (t *Tree) Delete(k interface{} /*K*/) (ok bool) {
...
@@ -373,58 +373,14 @@ func (t *Tree) Delete(k interface{} /*K*/) (ok bool) {
if
q
!=
t
.
r
{
if
q
!=
t
.
r
{
t
.
underflow
(
p
,
x
,
pi
)
// hit
t
.
underflow
(
p
,
x
,
pi
)
// hit
}
else
if
t
.
c
==
0
{
}
else
if
t
.
c
==
0
{
t
.
Clear
()
// hit
t
.
Clear
()
}
}
return
true
return
true
}
}
}
}
/*
if ok {
switch x := q.(type) {
case *x:
if x.c < kx && q != t.r {
x, i = t.underflowX(p, x, pi, i)
}
pi = i + 1
p = x
q = x.x[pi].ch
ok = false
continue
case *d:
t.extract(x, i)
if x.c >= kd {
return true
}
if q != t.r {
t.underflow(p, x, pi) // hit
} else if t.c == 0 {
t.Clear() // hit
}
return true
}
}
switch x := q.(type) {
case *x:
if x.c < kx && q != t.r {
x, i = t.underflowX(p, x, pi, i)
}
pi = i
p = x
q = x.x[i].ch
case *d:
return false
}
}
*/
}
}
func
(
t
*
Tree
)
extract
(
q
*
d
,
i
int
)
{
// (r interface{} /*V*/) {
func
(
t
*
Tree
)
extract
(
q
*
d
,
i
int
)
{
// (r interface{} /*V*/) {
// XXX update hit
t
.
ver
++
t
.
ver
++
//r = q.d[i].v // prepared for Extract
//r = q.d[i].v // prepared for Extract
q
.
c
--
q
.
c
--
...
@@ -433,6 +389,8 @@ func (t *Tree) extract(q *d, i int) { // (r interface{} /*V*/) {
...
@@ -433,6 +389,8 @@ func (t *Tree) extract(q *d, i int) { // (r interface{} /*V*/) {
}
}
q
.
d
[
q
.
c
]
=
zde
// GC
q
.
d
[
q
.
c
]
=
zde
// GC
t
.
c
--
t
.
c
--
t
.
hitD
=
q
t
.
hitDi
=
i
// XXX ok (pointing post data ?)
return
return
}
}
...
@@ -695,7 +653,6 @@ func (t *Tree) Set(k interface{} /*K*/, v interface{} /*V*/) {
...
@@ -695,7 +653,6 @@ func (t *Tree) Set(k interface{} /*K*/, v interface{} /*V*/) {
// check if we can do the update nearby previous change
// check if we can do the update nearby previous change
/*
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)
...
@@ -725,7 +682,6 @@ func (t *Tree) Set(k interface{} /*K*/, v interface{} /*V*/) {
...
@@ -725,7 +682,6 @@ func (t *Tree) Set(k interface{} /*K*/, v interface{} /*V*/) {
}
}
}
}
}
}
*/
// data page not quickly found - search and descent from root
// data page not quickly found - search and descent from root
pi
:=
-
1
pi
:=
-
1
...
@@ -994,25 +950,40 @@ func (t *Tree) underflow(p *x, q *d, pi int) {
...
@@ -994,25 +950,40 @@ 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.hitD = q @ i
p
.
x
[
pi
-
1
]
.
k
=
q
.
d
[
0
]
.
k
p
.
x
[
pi
-
1
]
.
k
=
q
.
d
[
0
]
.
k
t
.
hitKmin
.
set
(
q
.
d
[
0
]
.
k
)
t
.
hitPi
=
pi
// XXX? (+ already pre-set this way ?)
t
.
hitDi
+=
1
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.hitD = q @ i
p
.
x
[
pi
]
.
k
=
r
.
d
[
0
]
.
k
p
.
x
[
pi
]
.
k
=
r
.
d
[
0
]
.
k
t
.
hitKmax
.
set
(
r
.
d
[
0
]
.
k
)
t
.
hitPi
=
pi
// XXX? (+ already pre-set this way ?)
// hitDi stays the same
r
.
d
[
r
.
c
]
=
zde
// GC
r
.
d
[
r
.
c
]
=
zde
// GC
return
return
}
}
if
l
!=
nil
{
if
l
!=
nil
{
t
.
hitD
=
l
t
.
hitDi
+=
l
.
c
t
.
cat
(
p
,
l
,
q
,
pi
-
1
)
t
.
cat
(
p
,
l
,
q
,
pi
-
1
)
t
.
hitKmin
.
set
(
p
.
x
[
pi
-
1
]
.
k
)
t
.
hitPi
=
pi
-
1
return
return
}
}
t
.
cat
(
p
,
q
,
r
,
pi
)
t
.
cat
(
p
,
q
,
r
,
pi
)
// hitD/hitDi stays unchanged
kmax
:=
t
.
hitPKmax
if
pi
<
p
.
c
{
// means < ∞
kmax
.
set
(
p
.
x
[
pi
]
.
k
}
t
.
hitKmax
=
kmax
t
.
hitPi
=
pi
}
}
func
(
t
*
Tree
)
underflowX
(
p
*
x
,
q
*
x
,
pi
int
,
i
int
)
(
*
x
,
int
)
{
func
(
t
*
Tree
)
underflowX
(
p
*
x
,
q
*
x
,
pi
int
,
i
int
)
(
*
x
,
int
)
{
...
...
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