mirror of
https://github.com/featurebasedb/featurebase.git
synced 2026-09-06 08:35:55 +00:00
This commit moves the computation of the intersection count to the `roaring` package so that no allocations are required. The implementation operates at the roaring container level and has specialized functions for array-array, array-bitmap, and bitmap-bitmap container pairs.
43 lines
775 B
Go
43 lines
775 B
Go
package roaring
|
|
|
|
import (
|
|
"reflect"
|
|
"testing"
|
|
)
|
|
|
|
// Ensure iterator returns values from a bitmap.
|
|
func TestBitmapIterator(t *testing.T) {
|
|
for i, tt := range []struct {
|
|
bitmap []uint64
|
|
values []uint16
|
|
}{
|
|
// Empty
|
|
{
|
|
bitmap: []uint64{6}, // 0110
|
|
values: []uint16{1, 2},
|
|
},
|
|
|
|
// Single uint64 bitmap
|
|
{
|
|
bitmap: []uint64{6}, // 0110
|
|
values: []uint16{1, 2},
|
|
},
|
|
|
|
// Multi uint64 bitmap
|
|
{
|
|
bitmap: []uint64{1 << 63, 1, 0, 1, 3 << 62},
|
|
values: []uint16{63, 64, 192, 318, 319},
|
|
},
|
|
} {
|
|
itr := newBitmapIterator(tt.bitmap)
|
|
|
|
var a []uint16
|
|
for v, eof := itr.next(); !eof; v, eof = itr.next() {
|
|
a = append(a, v)
|
|
}
|
|
|
|
if !reflect.DeepEqual(a, tt.values) {
|
|
t.Errorf("%d. unexpected values: exp=%+v, got=%+v", i, a, tt.values)
|
|
}
|
|
}
|
|
}
|