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
b2362a56
Commit
b2362a56
authored
Apr 26, 2015
by
Jan Mercl
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Small updates. Regenerate example/int.go.
parent
c4adf3a5
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
81 additions
and
72 deletions
+81
-72
btree.go
btree.go
+0
-52
doc.go
doc.go
+53
-0
example/int.go
example/int.go
+28
-20
No files found.
btree.go
View file @
b2362a56
...
...
@@ -2,58 +2,6 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// Package b implements a B+tree.
//
// Changelog
//
// 2014-06-26: Lower GC presure by recycling things.
//
// 2014-04-18: Added new method Put.
//
// Generic types
//
// Keys and their associated values are interface{} typed, similar to all of
// the containers in the standard library.
//
// Semiautomatic production of a type specific variant of this package is
// supported via
//
// $ make generic
//
// This command will write to stdout a version of the btree.go file where
// every key type occurrence is replaced by the word 'key' (written in all
// CAPS) and every value type occurrence is replaced by the word 'value'
// (written in all CAPS). Then you have to replace these tokens with your
// desired type(s), using any technique you're comfortable with.
//
// This is how, for example, 'example/int.go' was created:
//
// $ mkdir example
// $
// $ # Note: the command below must be actually written using the words
// $ # 'key' and 'value' in all CAPS. The proper form is avoided in this
// $ # documentation to not confuse any text replacement mechanism.
// $
// $ make generic | sed -e 's/key/int/g' -e 's/value/int/g' > example/int.go
//
// No other changes to int.go are necessary, it compiles just fine.
//
// Running the benchmarks for 1000 keys on a machine with Intel i5-4670 CPU @
// 3.4GHz, Go release 1.3.
//
// $ go test -bench 1e3 example/all_test.go example/int.go
// PASS
// BenchmarkSetSeq1e3 10000 146740 ns/op
// BenchmarkGetSeq1e3 10000 108261 ns/op
// BenchmarkSetRnd1e3 10000 254359 ns/op
// BenchmarkGetRnd1e3 10000 134621 ns/op
// BenchmarkDelRnd1e3 10000 211864 ns/op
// BenchmarkSeekSeq1e3 10000 148628 ns/op
// BenchmarkSeekRnd1e3 10000 215166 ns/op
// BenchmarkNext1e3 200000 9211 ns/op
// BenchmarkPrev1e3 200000 8843 ns/op
// ok command-line-arguments 25.071s
// $
package
b
import
(
...
...
doc.go
0 → 100644
View file @
b2362a56
// Copyright 2014 The b Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// Package b implements a B+tree.
//
// Changelog
//
// 2014-06-26: Lower GC presure by recycling things.
//
// 2014-04-18: Added new method Put.
//
// Generic types
//
// Keys and their associated values are interface{} typed, similar to all of
// the containers in the standard library.
//
// Semiautomatic production of a type specific variant of this package is
// supported via
//
// $ make generic
//
// This command will write to stdout a version of the btree.go file where every
// key type occurrence is replaced by the word 'KEY' and every value type
// occurrence is replaced by the word 'VALUE'. Then you have to replace these
// tokens with your desired type(s), using any technique you're comfortable
// with.
//
// This is how, for example, 'example/int.go' was created:
//
// $ mkdir example
// $ make generic | sed -e 's/KEY/int/g' -e 's/VALUE/int/g' > example/int.go
//
// No other changes to int.go are necessary, it compiles just fine.
//
// Running the benchmarks for 1000 keys on a machine with Intel i5-4670 CPU @
// 3.4GHz, Go release 1.4.2.
//
// $ go test -bench 1e3 example/all_test.go example/int.go
// PASS
// BenchmarkSetSeq1e3 10000 151620 ns/op
// BenchmarkGetSeq1e3 10000 115354 ns/op
// BenchmarkSetRnd1e3 5000 255865 ns/op
// BenchmarkGetRnd1e3 10000 140466 ns/op
// BenchmarkDelSeq1e3 10000 143860 ns/op
// BenchmarkDelRnd1e3 10000 188228 ns/op
// BenchmarkSeekSeq1e3 10000 156448 ns/op
// BenchmarkSeekRnd1e3 10000 190587 ns/op
// BenchmarkNext1e3 200000 9407 ns/op
// BenchmarkPrev1e3 200000 9306 ns/op
// ok command-line-arguments 26.369s
// $
package
b
example/int.go
View file @
b2362a56
...
...
@@ -2,7 +2,6 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// Package b implements a int->int B+tree.
package
b
import
(
...
...
@@ -234,17 +233,18 @@ func (t *Tree) cat(p *x, q, r *d, pi int) {
if
p
.
c
>
1
{
p
.
extract
(
pi
)
p
.
x
[
pi
]
.
ch
=
q
}
else
{
switch
x
:=
t
.
r
.
(
type
)
{
case
*
x
:
*
x
=
zx
btXPool
.
Put
(
x
)
case
*
d
:
*
x
=
zd
btDPool
.
Put
(
x
)
}
t
.
r
=
q
return
}
switch
x
:=
t
.
r
.
(
type
)
{
case
*
x
:
*
x
=
zx
btXPool
.
Put
(
x
)
case
*
d
:
*
x
=
zd
btDPool
.
Put
(
x
)
}
t
.
r
=
q
}
func
(
t
*
Tree
)
catX
(
p
,
q
,
r
*
x
,
pi
int
)
{
...
...
@@ -462,10 +462,11 @@ func (t *Tree) overflow(p *x, q *d, pi, i int, k int, v int) {
q
.
mvR
(
r
,
1
)
t
.
insert
(
q
,
i
,
k
,
v
)
p
.
x
[
pi
]
.
k
=
r
.
d
[
0
]
.
k
}
else
{
t
.
insert
(
r
,
0
,
k
,
v
)
p
.
x
[
pi
]
.
k
=
k
return
}
t
.
insert
(
r
,
0
,
k
,
v
)
p
.
x
[
pi
]
.
k
=
k
return
}
...
...
@@ -586,9 +587,9 @@ func (t *Tree) Set(k int, v int) {
// (whatever, false) if it decides not to create or not to update the value of
// the KV pair.
//
// tree.Set(k, v) c
onceptually equals
// tree.Set(k, v) c
all conceptually equals calling
//
// tree.Put(k, func(
k, v []byte){ return v, true }([]byte, bool)
)
// tree.Put(k, func(
int, bool){ return v, true }
)
//
// modulo the differing return values.
func
(
t
*
Tree
)
Put
(
k
int
,
upd
func
(
oldV
int
,
exists
bool
)
(
newV
int
,
write
bool
))
(
oldV
int
,
written
bool
)
{
...
...
@@ -739,15 +740,22 @@ func (t *Tree) underflow(p *x, q *d, pi int) {
if
l
!=
nil
&&
l
.
c
+
q
.
c
>=
2
*
kd
{
l
.
mvR
(
q
,
1
)
p
.
x
[
pi
-
1
]
.
k
=
q
.
d
[
0
]
.
k
}
else
if
r
!=
nil
&&
q
.
c
+
r
.
c
>=
2
*
kd
{
return
}
if
r
!=
nil
&&
q
.
c
+
r
.
c
>=
2
*
kd
{
q
.
mvL
(
r
,
1
)
p
.
x
[
pi
]
.
k
=
r
.
d
[
0
]
.
k
r
.
d
[
r
.
c
]
=
zde
// GC
}
else
if
l
!=
nil
{
return
}
if
l
!=
nil
{
t
.
cat
(
p
,
l
,
q
,
pi
-
1
)
}
else
{
t
.
cat
(
p
,
q
,
r
,
pi
)
return
}
t
.
cat
(
p
,
q
,
r
,
pi
)
}
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