mirror of
https://github.com/featurebasedb/featurebase.git
synced 2026-09-10 23:11:01 +00:00
add btree tests
The upstream btree code has a test file, this is an import of that test file, adjusted/adapted to make it work with our de-genericized uint64/*Container implementation, so we have some tests and benchmarks available for the btree implementation itself.
This commit is contained in:
parent
aab42e97a4
commit
8fb8bb3609
4 changed files with 1550 additions and 0 deletions
|
|
@ -76,6 +76,7 @@ type (
|
|||
Cmp func(a, b uint64) int64
|
||||
|
||||
d struct { // data page
|
||||
dTree //lint:ignore U1000 this is conditional on a build flag
|
||||
c int
|
||||
d [2*kd + 1]de
|
||||
n *d
|
||||
|
|
@ -107,6 +108,7 @@ type (
|
|||
|
||||
// tree is a B+tree.
|
||||
tree struct {
|
||||
treeInst //lint:ignore U1000 this is conditional on a build flag
|
||||
c int
|
||||
cmp Cmp
|
||||
first *d
|
||||
|
|
@ -197,6 +199,7 @@ func (q *x) siblings(i int) (l, r *d) {
|
|||
// -------------------------------------------------------------------------- d
|
||||
|
||||
func (l *d) mvL(r *d, c int) {
|
||||
r.didCopy(r.c)
|
||||
copy(l.d[l.c:], r.d[:c])
|
||||
copy(r.d[:], r.d[c:r.c])
|
||||
// Zero out the de's here to prevent reading bad data
|
||||
|
|
@ -209,6 +212,7 @@ func (l *d) mvL(r *d, c int) {
|
|||
}
|
||||
|
||||
func (l *d) mvR(r *d, c int) {
|
||||
l.didCopy(r.c + c)
|
||||
copy(r.d[c:], r.d[:r.c])
|
||||
copy(r.d[:c], l.d[l.c-c:])
|
||||
// Zero out the de's here to prevent reading bad data
|
||||
|
|
@ -364,6 +368,7 @@ func (t *tree) extract(q *d, i int) { // (r *container) {
|
|||
//r = q.d[i].v // prepared for Extract
|
||||
q.c--
|
||||
if i < q.c {
|
||||
t.didCopy(q.c - i)
|
||||
copy(q.d[i:], q.d[i+1:q.c+1])
|
||||
}
|
||||
q.d[q.c] = zde // GC
|
||||
|
|
@ -446,8 +451,10 @@ func (t *tree) Get(k uint64) (v *Container, ok bool) {
|
|||
|
||||
func (t *tree) insert(q *d, i int, k uint64, v *Container) *d {
|
||||
t.ver++
|
||||
q.setTree(t)
|
||||
c := q.c
|
||||
if i < c {
|
||||
t.didCopy(c - i)
|
||||
copy(q.d[i+1:], q.d[i:c])
|
||||
}
|
||||
c++
|
||||
|
|
@ -704,6 +711,7 @@ func (t *tree) Put(k uint64, upd func(oldV *Container, exists bool) (newV *Conta
|
|||
func (t *tree) split(p *x, q *d, pi, i int, k uint64, v *Container) {
|
||||
t.ver++
|
||||
r := btDPool.Get().(*d)
|
||||
r.setTree(t)
|
||||
if q.n != nil {
|
||||
r.n = q.n
|
||||
r.n.p = r
|
||||
|
|
@ -713,6 +721,7 @@ func (t *tree) split(p *x, q *d, pi, i int, k uint64, v *Container) {
|
|||
q.n = r
|
||||
r.p = q
|
||||
|
||||
t.didCopy(kd)
|
||||
copy(r.d[:], q.d[kd:2*kd])
|
||||
for i := range q.d[kd:] {
|
||||
q.d[kd+i] = zde
|
||||
|
|
|
|||
1490
roaring/btree_test.go
Normal file
1490
roaring/btree_test.go
Normal file
File diff suppressed because it is too large
Load diff
27
roaring/inst.go
Normal file
27
roaring/inst.go
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
// +build btreeInstrumentation
|
||||
|
||||
package roaring
|
||||
|
||||
type dTree struct {
|
||||
t *tree
|
||||
}
|
||||
|
||||
type treeInst struct {
|
||||
deCopied int64
|
||||
}
|
||||
|
||||
func (t *tree) didCopy(n int) {
|
||||
t.deCopied += int64(n)
|
||||
}
|
||||
|
||||
func (d *d) didCopy(n int) {
|
||||
d.t.deCopied += int64(n)
|
||||
}
|
||||
|
||||
func (t *tree) countCopies() int64 {
|
||||
return t.deCopied
|
||||
}
|
||||
|
||||
func (d *d) setTree(t *tree) {
|
||||
d.t = t
|
||||
}
|
||||
24
roaring/nop_inst.go
Normal file
24
roaring/nop_inst.go
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
// +build !btreeInstrumentation
|
||||
|
||||
package roaring
|
||||
|
||||
//lint:ignore U1000 this is conditional on a build flag
|
||||
type dTree struct {
|
||||
}
|
||||
|
||||
//lint:ignore U1000 this is conditional on a build flag
|
||||
type treeInst struct {
|
||||
}
|
||||
|
||||
func (t *tree) didCopy(n int) {
|
||||
}
|
||||
|
||||
func (d *d) didCopy(n int) {
|
||||
}
|
||||
|
||||
func (t *tree) countCopies() int64 {
|
||||
return 0
|
||||
}
|
||||
|
||||
func (d *d) setTree(t *tree) {
|
||||
}
|
||||
Loading…
Add table
Reference in a new issue