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
e4802b23
Commit
e4802b23
authored
Oct 20, 2013
by
Jan Mercl
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Make tree version numbers more robust
parent
5f12ed84
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
34 additions
and
15 deletions
+34
-15
Makefile
Makefile
+11
-7
btree.go
btree.go
+9
-2
example/int.go
example/int.go
+14
-6
No files found.
Makefile
View file @
e4802b23
all
:
go
fmt
go
test
-i
go
test
.PHONY
:
all todo clean cover generic
all
:
editor
go build
go vet
go
install
make todo
editor
:
go
fmt
go
test
-i
go
test
todo
:
@
grep
-n
^[[:space:]]
*
_[[:space:]]
*
=[[
:space:]][[:alpha:]][[:alnum:]]
*
*
.go
||
true
@
grep
-n
TODO
*
.go
||
true
...
...
@@ -15,10 +19,10 @@ todo:
clean
:
@
go clean
rm
-f
*
~
cov cov.html
rm
-f
*
~
gocov
:
gocov
test
$(COV)
| gocov-html
>
cov.html
cover
:
t
=
$(
shell
tempfile
)
;
go
test
-coverprofile
$$
t
&&
go tool cover
-html
$$
t
&&
unlink
$$
t
generic
:
@
# writes to stdout a version where the type of key is KEY and the type
...
...
btree.go
View file @
e4802b23
...
...
@@ -230,6 +230,7 @@ func (t *Tree) Clear() {
}
func
(
t
*
Tree
)
cat
(
p
*
x
,
q
,
r
*
d
,
pi
int
)
{
t
.
ver
++
q
.
mvL
(
r
,
r
.
c
)
if
r
.
n
!=
nil
{
r
.
n
.
p
=
q
...
...
@@ -246,6 +247,7 @@ func (t *Tree) cat(p *x, q, r *d, pi int) {
}
func
(
t
*
Tree
)
catX
(
p
,
q
,
r
*
x
,
pi
int
)
{
t
.
ver
++
q
.
x
[
q
.
c
]
.
sep
=
p
.
x
[
pi
]
.
sep
copy
(
q
.
x
[
q
.
c
+
1
:
],
r
.
x
[
:
r
.
c
])
q
.
c
+=
r
.
c
+
1
...
...
@@ -298,7 +300,6 @@ func (t *Tree) Delete(k interface{} /*K*/) (ok bool) {
}
case
*
d
:
t
.
extract
(
x
,
i
)
t
.
ver
++
if
x
.
c
>=
kd
{
return
}
...
...
@@ -327,6 +328,7 @@ func (t *Tree) Delete(k interface{} /*K*/) (ok bool) {
}
func
(
t
*
Tree
)
extract
(
q
*
d
,
i
int
)
{
// (r interface{} /*V*/) {
t
.
ver
++
//r = q.d[i].v // prepared for Extract
q
.
c
--
if
i
<
q
.
c
{
...
...
@@ -411,6 +413,7 @@ func (t *Tree) Get(k interface{} /*K*/) (v interface{} /*V*/, ok bool) {
}
func
(
t
*
Tree
)
insert
(
q
*
d
,
i
int
,
k
interface
{}
/*K*/
,
v
interface
{}
/*V*/
)
*
d
{
t
.
ver
++
c
:=
q
.
c
if
i
<
c
{
copy
(
q
.
d
[
i
+
1
:
],
q
.
d
[
i
:
c
])
...
...
@@ -438,6 +441,7 @@ func (t *Tree) Len() int {
}
func
(
t
*
Tree
)
overflow
(
p
*
x
,
q
*
d
,
pi
,
i
int
,
k
interface
{}
/*K*/
,
v
interface
{}
/*V*/
)
{
t
.
ver
++
l
,
r
:=
p
.
siblings
(
pi
)
if
l
!=
nil
&&
l
.
c
<
2
*
kd
{
...
...
@@ -546,7 +550,6 @@ func (t *Tree) Set(k interface{} /*K*/, v interface{} /*V*/) {
default
:
t
.
overflow
(
p
,
x
,
pi
,
i
,
k
,
v
)
}
t
.
ver
++
return
}
}
...
...
@@ -558,6 +561,7 @@ func (t *Tree) Set(k interface{} /*K*/, v interface{} /*V*/) {
}
func
(
t
*
Tree
)
split
(
p
*
x
,
q
*
d
,
pi
,
i
int
,
k
interface
{}
/*K*/
,
v
interface
{}
/*V*/
)
{
t
.
ver
++
r
:=
&
d
{}
if
q
.
n
!=
nil
{
r
.
n
=
q
.
n
...
...
@@ -588,6 +592,7 @@ func (t *Tree) split(p *x, q *d, pi, i int, k interface{} /*K*/, v interface{} /
}
func
(
t
*
Tree
)
splitX
(
p
*
x
,
pp
**
x
,
pi
int
,
i
*
int
)
{
t
.
ver
++
q
:=
*
pp
r
:=
&
x
{}
copy
(
r
.
x
[
:
],
q
.
x
[
kx
+
1
:
])
...
...
@@ -609,6 +614,7 @@ func (t *Tree) splitX(p *x, pp **x, pi int, i *int) {
}
func
(
t
*
Tree
)
underflow
(
p
*
x
,
q
*
d
,
pi
int
)
{
t
.
ver
++
l
,
r
:=
p
.
siblings
(
pi
)
if
l
!=
nil
&&
l
.
c
+
q
.
c
>=
2
*
kd
{
...
...
@@ -624,6 +630,7 @@ func (t *Tree) underflow(p *x, q *d, pi int) {
}
func
(
t
*
Tree
)
underflowX
(
p
*
x
,
pp
**
x
,
pi
int
,
i
*
int
)
{
t
.
ver
++
var
l
,
r
*
x
q
:=
*
pp
...
...
example/int.go
View file @
e4802b23
...
...
@@ -21,7 +21,7 @@
// This is how, for example, 'example/int.go' was created:
//
// $ mkdir example
// $ make generic | sed -e 's/
int/int/g' -e 's/int
/int/g' > example/int.go
// $ make generic | sed -e 's/
key/int/g' -e 's/value
/int/g' > example/int.go
//
package
b
...
...
@@ -39,9 +39,10 @@ const (
type
(
// Cmp compares a and b. Return value is:
//
// -1 if a < b
// 0 if a == b
// +1 if a > b
// < 0 if a < b
// 0 if a == b
// > 0 if a > b
//
Cmp
func
(
a
,
b
int
)
int
d
struct
{
// data page
...
...
@@ -194,6 +195,7 @@ func (t *Tree) Clear() {
}
func
(
t
*
Tree
)
cat
(
p
*
x
,
q
,
r
*
d
,
pi
int
)
{
t
.
ver
++
q
.
mvL
(
r
,
r
.
c
)
if
r
.
n
!=
nil
{
r
.
n
.
p
=
q
...
...
@@ -210,6 +212,7 @@ func (t *Tree) cat(p *x, q, r *d, pi int) {
}
func
(
t
*
Tree
)
catX
(
p
,
q
,
r
*
x
,
pi
int
)
{
t
.
ver
++
q
.
x
[
q
.
c
]
.
sep
=
p
.
x
[
pi
]
.
sep
copy
(
q
.
x
[
q
.
c
+
1
:
],
r
.
x
[
:
r
.
c
])
q
.
c
+=
r
.
c
+
1
...
...
@@ -262,7 +265,6 @@ func (t *Tree) Delete(k int) (ok bool) {
}
case
*
d
:
t
.
extract
(
x
,
i
)
t
.
ver
++
if
x
.
c
>=
kd
{
return
}
...
...
@@ -291,6 +293,7 @@ func (t *Tree) Delete(k int) (ok bool) {
}
func
(
t
*
Tree
)
extract
(
q
*
d
,
i
int
)
{
// (r int) {
t
.
ver
++
//r = q.d[i].v // prepared for Extract
q
.
c
--
if
i
<
q
.
c
{
...
...
@@ -375,6 +378,7 @@ func (t *Tree) Get(k int) (v int, ok bool) {
}
func
(
t
*
Tree
)
insert
(
q
*
d
,
i
int
,
k
int
,
v
int
)
*
d
{
t
.
ver
++
c
:=
q
.
c
if
i
<
c
{
copy
(
q
.
d
[
i
+
1
:
],
q
.
d
[
i
:
c
])
...
...
@@ -402,6 +406,7 @@ func (t *Tree) Len() int {
}
func
(
t
*
Tree
)
overflow
(
p
*
x
,
q
*
d
,
pi
,
i
int
,
k
int
,
v
int
)
{
t
.
ver
++
l
,
r
:=
p
.
siblings
(
pi
)
if
l
!=
nil
&&
l
.
c
<
2
*
kd
{
...
...
@@ -510,7 +515,6 @@ func (t *Tree) Set(k int, v int) {
default
:
t
.
overflow
(
p
,
x
,
pi
,
i
,
k
,
v
)
}
t
.
ver
++
return
}
}
...
...
@@ -522,6 +526,7 @@ func (t *Tree) Set(k int, v int) {
}
func
(
t
*
Tree
)
split
(
p
*
x
,
q
*
d
,
pi
,
i
int
,
k
int
,
v
int
)
{
t
.
ver
++
r
:=
&
d
{}
if
q
.
n
!=
nil
{
r
.
n
=
q
.
n
...
...
@@ -552,6 +557,7 @@ func (t *Tree) split(p *x, q *d, pi, i int, k int, v int) {
}
func
(
t
*
Tree
)
splitX
(
p
*
x
,
pp
**
x
,
pi
int
,
i
*
int
)
{
t
.
ver
++
q
:=
*
pp
r
:=
&
x
{}
copy
(
r
.
x
[
:
],
q
.
x
[
kx
+
1
:
])
...
...
@@ -573,6 +579,7 @@ func (t *Tree) splitX(p *x, pp **x, pi int, i *int) {
}
func
(
t
*
Tree
)
underflow
(
p
*
x
,
q
*
d
,
pi
int
)
{
t
.
ver
++
l
,
r
:=
p
.
siblings
(
pi
)
if
l
!=
nil
&&
l
.
c
+
q
.
c
>=
2
*
kd
{
...
...
@@ -588,6 +595,7 @@ func (t *Tree) underflow(p *x, q *d, pi int) {
}
func
(
t
*
Tree
)
underflowX
(
p
*
x
,
pp
**
x
,
pi
int
,
i
*
int
)
{
t
.
ver
++
var
l
,
r
*
x
q
:=
*
pp
...
...
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