mirror of
https://github.com/featurebasedb/featurebase.git
synced 2026-09-07 09:05:55 +00:00
Add and use bitmap-to-slice-or-set comparison functions
The generation of slices from things, and use of reflect.DeepEqual to compare the slices, is a lot more expensive than it needs to be. Omitting it removes most of the runtime of the marshal tests.
This commit is contained in:
parent
1952a43ed4
commit
1484674a1c
2 changed files with 35 additions and 7 deletions
|
|
@ -5756,7 +5756,37 @@ func xorBitmapRun(a, b *Container) *Container {
|
|||
return output
|
||||
}
|
||||
|
||||
// CompareEquality is used mostly in test cases to confirm that two bitmaps came
|
||||
// CompareBitmapSlice checks whether a bitmap has the same values in it
|
||||
// that a provided slice does.
|
||||
func CompareBitmapSlice(b *Bitmap, vals []uint64) (bool, error) {
|
||||
count := b.Count()
|
||||
if count != uint64(len(vals)) {
|
||||
return false, fmt.Errorf("length mismatch: bitmap has %d bits, slice has %d", count, len(vals))
|
||||
}
|
||||
for _, v := range vals {
|
||||
if !b.Contains(v) {
|
||||
return false, fmt.Errorf("bitmap lacks expected value %d", v)
|
||||
}
|
||||
}
|
||||
return true, nil
|
||||
}
|
||||
|
||||
// CompareBitmapMap checks whether a bitmap has the same values in it
|
||||
// that a provided map[uint64]struct{} has as keys.
|
||||
func CompareBitmapMap(b *Bitmap, vals map[uint64]struct{}) (bool, error) {
|
||||
count := b.Count()
|
||||
if count != uint64(len(vals)) {
|
||||
return false, fmt.Errorf("length mismatch: bitmap has %d bits, map has %d", count, len(vals))
|
||||
}
|
||||
for v := range vals {
|
||||
if !b.Contains(v) {
|
||||
return false, fmt.Errorf("bitmap lacks expected value %d", v)
|
||||
}
|
||||
}
|
||||
return true, nil
|
||||
}
|
||||
|
||||
// BitwiseEqual is used mostly in test cases to confirm that two bitmaps came
|
||||
// out the same. It does not expect corresponding opN, or OpWriter, but expects
|
||||
// identical bit contents. It does not expect identical representations; a bitmap
|
||||
// container can be identical to an array container. It returns a boolean value,
|
||||
|
|
|
|||
|
|
@ -1570,14 +1570,12 @@ func testBitmapMarshalQuick(t *testing.T, n int, min, max uint64, sorted bool) {
|
|||
t.Fatal(err)
|
||||
}
|
||||
|
||||
// Verify the original bitmap has the correct set of values.
|
||||
if exp, got := generator.Uint64SetSlice(set), bm.Slice(); !reflect.DeepEqual(exp, got) {
|
||||
t.Fatalf("mismatch: %s\n\nexp=%+v\n\ngot=%+v\n\n", diff(exp, got), exp, got)
|
||||
if _, err := roaring.CompareBitmapMap(bm, set); err != nil {
|
||||
t.Fatalf("source mismatch: %v", err)
|
||||
}
|
||||
|
||||
// Verify the bitmap loaded with the ops log has the correct set of values.
|
||||
if exp, got := generator.Uint64SetSlice(set), bm2.Slice(); !reflect.DeepEqual(exp, got) {
|
||||
t.Fatalf("mismatch: %s\n\nexp=%+v\n\ngot=%+v\n\n", diff(exp, got), exp, got)
|
||||
if _, err := roaring.CompareBitmapMap(bm2, set); err != nil {
|
||||
t.Fatalf("unmarshalled mismatch: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue