MCPcopy
hub / github.com/RoaringBitmap/roaring / testAddOffset

Function testAddOffset

roaring_test.go:702–740  ·  view source on GitHub ↗
(t *testing.T, arr []uint32, offset int64)

Source from the content-addressed store, hash-verified

700}
701
702func testAddOffset(t *testing.T, arr []uint32, offset int64) {
703 expected := make([]uint32, 0, len(arr))
704 for _, i := range arr {
705 v := int64(i) + offset
706 if v >= 0 && v <= MaxUint32 {
707 expected = append(expected, uint32(v))
708 }
709 }
710
711 bmp := NewBitmap()
712 bmp.AddMany(arr)
713
714 cop := AddOffset64(bmp, offset)
715
716 if !assert.EqualValues(t, len(expected), cop.GetCardinality()) {
717 t.Logf("Applying offset %d", offset)
718 }
719 if !assert.EqualValues(t, expected, cop.ToArray()) {
720 t.Logf("Applying offset %d", offset)
721 }
722
723 // Now check backing off gets us back all non-discarded numbers
724 expected2 := make([]uint32, 0, len(expected))
725 for _, i := range expected {
726 v := int64(i) - offset
727 if v >= 0 && v <= MaxUint32 {
728 expected2 = append(expected2, uint32(v))
729 }
730 }
731
732 cop2 := AddOffset64(cop, -offset)
733
734 if !assert.EqualValues(t, len(expected2), cop2.GetCardinality()) {
735 t.Logf("Restoring from offset %d", offset)
736 }
737 if !assert.EqualValues(t, expected2, cop2.ToArray()) {
738 t.Logf("Restoring from offset %d", offset)
739 }
740}
741
742func TestRoaringBitmapAddOffset(t *testing.T) {
743 type testCase struct {

Callers 1

Calls 5

AddManyMethod · 0.95
AddOffset64Function · 0.85
NewBitmapFunction · 0.70
GetCardinalityMethod · 0.45
ToArrayMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…