From 187a17aab854d060138316715fa243c4fbe38bcf Mon Sep 17 00:00:00 2001 From: bstrausser Date: Mon, 17 Jun 2024 14:32:44 -0400 Subject: [PATCH 01/15] BitmapContainer: orArrayCardinality test --- bitmapcontainer_test.go | 47 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/bitmapcontainer_test.go b/bitmapcontainer_test.go index d1feb0fc..fe94049a 100644 --- a/bitmapcontainer_test.go +++ b/bitmapcontainer_test.go @@ -485,3 +485,50 @@ func TestBitmapcontainerNextHasMany(t *testing.T) { assert.Equal(t, 256, result) }) } + +func TestBitmapcontainerOrArrayCardinality(t *testing.T) { + t.Run("Empty Bitmap and Empty Array", func(t *testing.T) { + array := newArrayContainer() + bc := newBitmapContainer() + result := bc.orArrayCardinality(array) + + assert.Equal(t, 0, result) + }) + + t.Run("Populated Bitmap with Empty Array", func(t *testing.T) { + bc := newBitmapContainer() + bc.iaddRange(0, 1024) + array := newArrayContainer() + + result := bc.orArrayCardinality(array) + + assert.Equal(t, 1024, result) + }) + + t.Run("Populated Bitmap with Empty Run Container", func(t *testing.T) { + bc := newBitmapContainer() + bc.iaddRange(0, 1024) + + runC := newRunContainer16() + + result := runC.orBitmapContainerCardinality(bc) + + assert.Equal(t, 1024, result) + + other := newBitmapContainerFromRun(runC) + result = bc.orBitmapCardinality(other) + + assert.Equal(t, 1024, result) + }) + + t.Run("Populated Bitmap with Empty Bitmap", func(t *testing.T) { + bc := newBitmapContainer() + bc.iaddRange(0, 1024) + + other := newBitmapContainer() + + result := bc.orBitmapCardinality(other) + + assert.Equal(t, 1024, result) + }) +} From 1ee17be9506da934f5f5ac99166eccd59e9f13be Mon Sep 17 00:00:00 2001 From: bstrausser Date: Mon, 17 Jun 2024 15:16:02 -0400 Subject: [PATCH 02/15] Runcontainer: Union Cardinality --- runcontainer_test.go | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/runcontainer_test.go b/runcontainer_test.go index 296c3d6c..9fe761cf 100644 --- a/runcontainer_test.go +++ b/runcontainer_test.go @@ -2628,6 +2628,49 @@ func TestIntervalValidationsPassing(t *testing.T) { assert.NoError(t, rc.validate()) } +func TestRunContainerUnionCardinality(t *testing.T) { + t.Run("Two Empty Runs", func(t *testing.T) { + first := runContainer16{} + second := runContainer16{} + result := first.unionCardinality(&second) + assert.Equal(t, uint(0), result) + }) + + t.Run("First Run Empty", func(t *testing.T) { + first := runContainer16{} + second := runContainer16{} + second.iaddRange(0, 1024) + result := first.unionCardinality(&second) + assert.Equal(t, uint(1024), result) + }) + + t.Run("Second Run Empty", func(t *testing.T) { + first := runContainer16{} + second := runContainer16{} + first.iaddRange(0, 1024) + result := first.unionCardinality(&second) + assert.Equal(t, uint(1024), result) + }) + + t.Run("Disjoint Ranges", func(t *testing.T) { + first := runContainer16{} + first.iaddRange(512, 1024) + second := runContainer16{} + second.iaddRange(0, 256) + result := first.unionCardinality(&second) + assert.Equal(t, uint(256+512), result) + }) + + t.Run("Complete Overlap", func(t *testing.T) { + first := runContainer16{} + first.iaddRange(0, 256) + second := runContainer16{} + second.iaddRange(0, 256) + result := first.unionCardinality(&second) + assert.Equal(t, uint(256), result) + }) +} + // go test -bench BenchmarkShortIteratorAdvance -run - func BenchmarkShortIteratorAdvanceRuntime(b *testing.B) { benchmarkContainerIteratorAdvance(b, newRunContainer16()) From d1ef9403e390d4744eb3125756c4ab727555f8e9 Mon Sep 17 00:00:00 2001 From: bstrausser Date: Mon, 17 Jun 2024 15:40:19 -0400 Subject: [PATCH 03/15] Runcontainer: Intersect Cardinality --- runcontainer_test.go | 52 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/runcontainer_test.go b/runcontainer_test.go index 9fe761cf..d3a2e60c 100644 --- a/runcontainer_test.go +++ b/runcontainer_test.go @@ -2671,6 +2671,58 @@ func TestRunContainerUnionCardinality(t *testing.T) { }) } +func TestRunContainerIntersectCardinality(t *testing.T) { + t.Run("Two Empty Runs", func(t *testing.T) { + first := runContainer16{} + second := runContainer16{} + result := first.intersectCardinality(&second) + assert.Equal(t, 0, result) + }) + + t.Run("First Run Empty", func(t *testing.T) { + first := runContainer16{} + second := runContainer16{} + second.iaddRange(0, 1024) + result := first.intersectCardinality(&second) + assert.Equal(t, 0, result) + }) + + t.Run("Second Run Empty", func(t *testing.T) { + first := runContainer16{} + second := runContainer16{} + first.iaddRange(0, 1024) + result := first.intersectCardinality(&second) + assert.Equal(t, 0, result) + }) + + t.Run("Disjoint Ranges", func(t *testing.T) { + first := runContainer16{} + first.iaddRange(512, 1024) + second := runContainer16{} + second.iaddRange(0, 256) + result := first.intersectCardinality(&second) + assert.Equal(t, 0, result) + }) + + t.Run("Complete Overlap", func(t *testing.T) { + first := runContainer16{} + first.iaddRange(0, 256) + second := runContainer16{} + second.iaddRange(0, 256) + result := first.intersectCardinality(&second) + assert.Equal(t, 256, result) + }) + + t.Run("Single Element Intersection", func(t *testing.T) { + first := runContainer16{} + first.iaddRange(0, 257) + second := runContainer16{} + second.iaddRange(256, 512) + result := first.intersectCardinality(&second) + assert.Equal(t, 1, result) + }) +} + // go test -bench BenchmarkShortIteratorAdvance -run - func BenchmarkShortIteratorAdvanceRuntime(b *testing.B) { benchmarkContainerIteratorAdvance(b, newRunContainer16()) From ecb965a0fc8d71ead73ec5d22602c9d593cf75fc Mon Sep 17 00:00:00 2001 From: bstrausser Date: Mon, 17 Jun 2024 19:16:49 -0400 Subject: [PATCH 04/15] RoaringArray(64): AdvanceUntil --- roaring64/roaringarray64.go | 10 +++++++++- roaring64/roaringarray64_test.go | 23 +++++++++++++++++++++++ roaringarray_test.go | 23 +++++++++++++++++++++++ 3 files changed, 55 insertions(+), 1 deletion(-) create mode 100644 roaring64/roaringarray64_test.go create mode 100644 roaringarray_test.go diff --git a/roaring64/roaringarray64.go b/roaring64/roaringarray64.go index 5bd885df..2f5020f1 100644 --- a/roaring64/roaringarray64.go +++ b/roaring64/roaringarray64.go @@ -140,7 +140,6 @@ func (ra *roaringArray64) clear() { } func (ra *roaringArray64) clone() *roaringArray64 { - sa := roaringArray64{} sa.copyOnWrite = ra.copyOnWrite @@ -328,6 +327,15 @@ func (ra *roaringArray64) hasRunCompression() bool { return false } +/** + * Find the smallest integer index strictly larger than pos such that array[index].key>=min. If none can + * be found, return size. Based on code by O. Kaser. + * + * @param min minimal value + * @param pos index to exceed + * @return the smallest index greater than pos such that array[index].key is at least as large as + * min, or size if it is not possible. + */ func (ra *roaringArray64) advanceUntil(min uint32, pos int) int { lower := pos + 1 diff --git a/roaring64/roaringarray64_test.go b/roaring64/roaringarray64_test.go new file mode 100644 index 00000000..525e97ec --- /dev/null +++ b/roaring64/roaringarray64_test.go @@ -0,0 +1,23 @@ +package roaring64 + +import ( + "testing" + + "github.com/stretchr/testify/assert" +) + +func TestRoaringArray64AdvanceUntil(t *testing.T) { + bitmap := New() + bitmap.AddRange(0, 128) + assert.Equal(t, 0, bitmap.highlowcontainer.advanceUntil(0, -1)) + assert.Equal(t, 1, bitmap.highlowcontainer.advanceUntil(0, 0)) + assert.Equal(t, 65, bitmap.highlowcontainer.advanceUntil(64, 0)) +} + +func TestRoaringArray64AdvanceUntilJavaRegression(t *testing.T) { + bitmap := New() + bitmap.AddMany([]uint64{0, 3, 16, 18, 21, 29, 30}) + assert.Equal(t, 1, bitmap.highlowcontainer.advanceUntil(3, -1)) + assert.Equal(t, 5, bitmap.highlowcontainer.advanceUntil(28, -1)) + assert.Equal(t, 5, bitmap.highlowcontainer.advanceUntil(29, -1)) +} diff --git a/roaringarray_test.go b/roaringarray_test.go new file mode 100644 index 00000000..1b91bad0 --- /dev/null +++ b/roaringarray_test.go @@ -0,0 +1,23 @@ +package roaring + +import ( + "testing" + + "github.com/stretchr/testify/assert" +) + +func TestRoaringArrayAdvanceUntil(t *testing.T) { + bitmap := New() + bitmap.AddRange(0, 128) + assert.Equal(t, 0, bitmap.highlowcontainer.advanceUntil(0, -1)) + assert.Equal(t, 1, bitmap.highlowcontainer.advanceUntil(0, 0)) + assert.Equal(t, 65, bitmap.highlowcontainer.advanceUntil(64, 0)) +} + +func TestRoaringArrayAdvanceUntilJavaRegression(t *testing.T) { + bitmap := New() + bitmap.AddMany([]uint32{0, 3, 16, 18, 21, 29, 30}) + assert.Equal(t, 1, bitmap.highlowcontainer.advanceUntil(3, -1)) + assert.Equal(t, 5, bitmap.highlowcontainer.advanceUntil(28, -1)) + assert.Equal(t, 5, bitmap.highlowcontainer.advanceUntil(29, -1)) +} From 7efe682054ce02fccd6f34472e58d572949bc1f0 Mon Sep 17 00:00:00 2001 From: bstrausser Date: Tue, 18 Jun 2024 00:42:52 -0400 Subject: [PATCH 05/15] RoaringArray(65): advanceUntil tests --- roaring64/roaringarray64_test.go | 26 ++++++++++++++++---------- roaringarray_test.go | 26 ++++++++++++++++---------- 2 files changed, 32 insertions(+), 20 deletions(-) diff --git a/roaring64/roaringarray64_test.go b/roaring64/roaringarray64_test.go index 525e97ec..9de9e562 100644 --- a/roaring64/roaringarray64_test.go +++ b/roaring64/roaringarray64_test.go @@ -8,16 +8,22 @@ import ( func TestRoaringArray64AdvanceUntil(t *testing.T) { bitmap := New() - bitmap.AddRange(0, 128) + low := 1 << 32 + mid := 2 << 32 + high := 3 << 32 + bitmap.AddRange(uint64(low)-1, uint64(low)+2) + bitmap.AddRange(uint64(mid)-1, uint64(mid)+2) + bitmap.AddRange(uint64(high)-1, uint64(high)+2) + assert.Equal(t, 0, bitmap.highlowcontainer.advanceUntil(0, -1)) - assert.Equal(t, 1, bitmap.highlowcontainer.advanceUntil(0, 0)) - assert.Equal(t, 65, bitmap.highlowcontainer.advanceUntil(64, 0)) -} + assert.Equal(t, 1, bitmap.highlowcontainer.advanceUntil(1, -1)) + assert.Equal(t, 2, bitmap.highlowcontainer.advanceUntil(2, -1)) + assert.Equal(t, 3, bitmap.highlowcontainer.advanceUntil(3, -1)) + assert.Equal(t, 4, bitmap.highlowcontainer.advanceUntil(4, -1)) -func TestRoaringArray64AdvanceUntilJavaRegression(t *testing.T) { - bitmap := New() - bitmap.AddMany([]uint64{0, 3, 16, 18, 21, 29, 30}) - assert.Equal(t, 1, bitmap.highlowcontainer.advanceUntil(3, -1)) - assert.Equal(t, 5, bitmap.highlowcontainer.advanceUntil(28, -1)) - assert.Equal(t, 5, bitmap.highlowcontainer.advanceUntil(29, -1)) + assert.Equal(t, 1, bitmap.highlowcontainer.advanceUntil(0, 0)) + assert.Equal(t, 2, bitmap.highlowcontainer.advanceUntil(1, 1)) + assert.Equal(t, 3, bitmap.highlowcontainer.advanceUntil(2, 2)) + assert.Equal(t, 4, bitmap.highlowcontainer.advanceUntil(3, 3)) + assert.Equal(t, 5, bitmap.highlowcontainer.advanceUntil(4, 4)) } diff --git a/roaringarray_test.go b/roaringarray_test.go index 1b91bad0..bf45b1e0 100644 --- a/roaringarray_test.go +++ b/roaringarray_test.go @@ -8,16 +8,22 @@ import ( func TestRoaringArrayAdvanceUntil(t *testing.T) { bitmap := New() - bitmap.AddRange(0, 128) + low := 1 << 16 + mid := 2 << 16 + high := 3 << 16 + bitmap.AddRange(uint64(low)-1, uint64(low)+2) + bitmap.AddRange(uint64(mid)-1, uint64(mid)+2) + bitmap.AddRange(uint64(high)-1, uint64(high)+2) + assert.Equal(t, 0, bitmap.highlowcontainer.advanceUntil(0, -1)) - assert.Equal(t, 1, bitmap.highlowcontainer.advanceUntil(0, 0)) - assert.Equal(t, 65, bitmap.highlowcontainer.advanceUntil(64, 0)) -} + assert.Equal(t, 1, bitmap.highlowcontainer.advanceUntil(1, -1)) + assert.Equal(t, 2, bitmap.highlowcontainer.advanceUntil(2, -1)) + assert.Equal(t, 3, bitmap.highlowcontainer.advanceUntil(3, -1)) + assert.Equal(t, 4, bitmap.highlowcontainer.advanceUntil(4, -1)) -func TestRoaringArrayAdvanceUntilJavaRegression(t *testing.T) { - bitmap := New() - bitmap.AddMany([]uint32{0, 3, 16, 18, 21, 29, 30}) - assert.Equal(t, 1, bitmap.highlowcontainer.advanceUntil(3, -1)) - assert.Equal(t, 5, bitmap.highlowcontainer.advanceUntil(28, -1)) - assert.Equal(t, 5, bitmap.highlowcontainer.advanceUntil(29, -1)) + assert.Equal(t, 1, bitmap.highlowcontainer.advanceUntil(0, 0)) + assert.Equal(t, 2, bitmap.highlowcontainer.advanceUntil(1, 1)) + assert.Equal(t, 3, bitmap.highlowcontainer.advanceUntil(2, 2)) + assert.Equal(t, 4, bitmap.highlowcontainer.advanceUntil(3, 3)) + assert.Equal(t, 5, bitmap.highlowcontainer.advanceUntil(4, 4)) } From 44c256c836083fa78212a4fe9cd117f26e54ede6 Mon Sep 17 00:00:00 2001 From: bstrausser Date: Sun, 23 Jun 2024 01:09:09 -0400 Subject: [PATCH 06/15] Roaring64: Copy and Parrallel test coverage --- roaring64/parallel64.go | 7 ++- roaring64/roaring64_test.go | 33 ++++++++-- roaring64/roaringarray64_test.go | 102 +++++++++++++++++++++++++++++++ 3 files changed, 134 insertions(+), 8 deletions(-) diff --git a/roaring64/parallel64.go b/roaring64/parallel64.go index d6548bba..5dadc8de 100644 --- a/roaring64/parallel64.go +++ b/roaring64/parallel64.go @@ -144,6 +144,8 @@ func (c parChunk) size() int { return c.ra.size() } +// parNaiveStartAt returns the index of the first key that is inclusive between start and last +// Returns the size if there is no such key func parNaiveStartAt(ra *roaringArray64, start uint32, last uint32) int { for idx, key := range ra.keys { if key >= start && key <= last { @@ -170,7 +172,6 @@ func orOnRange(ra1, ra2 *roaringArray64, start, last uint32) *roaringArray64 { key2 = ra2.getKeyAtIndex(idx2) for key1 <= last && key2 <= last { - if key1 < key2 { answer.appendCopy(*ra1, idx1) idx1++ @@ -188,7 +189,7 @@ func orOnRange(ra1, ra2 *roaringArray64, start, last uint32) *roaringArray64 { } else { c1 := ra1.getContainerAtIndex(idx1) - //answer.appendContainer(key1, c1.lazyOR(ra2.getContainerAtIndex(idx2)), false) + // answer.appendContainer(key1, c1.lazyOR(ra2.getContainerAtIndex(idx2)), false) answer.appendContainer(key1, roaring.Or(c1, ra2.getContainerAtIndex(idx2)), false) idx1++ idx2++ @@ -261,7 +262,7 @@ func iorOnRange(ra1, ra2 *roaringArray64, start, last uint32) *roaringArray64 { } else { c1 := ra1.getWritableContainerAtIndex(idx1) - //ra1.containers[idx1] = c1.lazyIOR(ra2.getContainerAtIndex(idx2)) + // ra1.containers[idx1] = c1.lazyIOR(ra2.getContainerAtIndex(idx2)) c1.Or(ra2.getContainerAtIndex(idx2)) ra1.setContainerAtIndex(idx1, c1) diff --git a/roaring64/roaring64_test.go b/roaring64/roaring64_test.go index 98a80ec1..7efb8eed 100644 --- a/roaring64/roaring64_test.go +++ b/roaring64/roaring64_test.go @@ -52,6 +52,29 @@ func TestIssue266(t *testing.T) { } } +func TestParOr64(t *testing.T) { + t.Run("Test 1", func(t *testing.T) { + a := BitmapOf(0, 1, 2, 3, 4) + b := BitmapOf(5, 6, 7, 8, 9, 10) + c := BitmapOf(11, 12, 13, 14, 15) + d := ParOr(0, a, b, c) + expected := BitmapOf(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15) + assert.True(t, d.Equals(expected)) + }) + + t.Run("Test 2", func(t *testing.T) { + a := BitmapOf(0, 1, 2, 3, 4) + + offset1 := uint64(2 << 16) + b := BitmapOf(offset1, offset1+1, offset1+2, offset1+3, offset1+5) + offset2 := uint64(4 << 16) + c := BitmapOf(offset2, offset2+1, offset2+2, offset2+3, offset2+5) + d := ParOr(0, a, b, c) + expected := BitmapOf(0, 1, 2, 3, 4, offset1, offset1+1, offset1+2, offset1+3, offset1+5, offset2, offset2+1, offset2+2, offset2+3, offset2+5) + assert.True(t, d.Equals(expected)) + }) +} + func TestRoaringRangeEnd(t *testing.T) { r := New() r.Add(roaring.MaxUint32) @@ -245,7 +268,7 @@ func TestRangeRemovalFromContent(t *testing.T) { bm.RemoveRange(0, 30000) c := bm.GetCardinality() - assert.EqualValues(t, 00, c) + assert.EqualValues(t, 0o0, c) } func TestFlipOnEmpty(t *testing.T) { @@ -624,7 +647,6 @@ func TestBitmap(t *testing.T) { assert.Equal(t, len(arrayres), len(arrayand)) assert.True(t, ok) - }) t.Run("Test AND 4", func(t *testing.T) { @@ -1401,6 +1423,7 @@ func TestBitmap(t *testing.T) { assert.True(t, valide) }) } + func TestXORtest4(t *testing.T) { t.Run("XORtest 4", func(t *testing.T) { rb := NewBitmap() @@ -1895,9 +1918,9 @@ func TestSerialization(t *testing.T) { //assert.Nil(t, err) //assert.True(t, bufBmp.Equals(bmp)) - //var base64 string - //base64, err = bufBmp.ToBase64() - //assert.Nil(t, err) + // var base64 string + // base64, err = bufBmp.ToBase64() + // assert.Nil(t, err) //base64Bmp := New() //_, err = base64Bmp.FromBase64(base64) diff --git a/roaring64/roaringarray64_test.go b/roaring64/roaringarray64_test.go index 9de9e562..24a4be72 100644 --- a/roaring64/roaringarray64_test.go +++ b/roaring64/roaringarray64_test.go @@ -27,3 +27,105 @@ func TestRoaringArray64AdvanceUntil(t *testing.T) { assert.Equal(t, 4, bitmap.highlowcontainer.advanceUntil(3, 3)) assert.Equal(t, 5, bitmap.highlowcontainer.advanceUntil(4, 4)) } + +func TestCopies(t *testing.T) { + tests := []struct { + name string + cow1 bool + cow2 bool + }{ + {"AppendCopiesAfterCoW", true, true}, + } + + for _, test := range tests { + t.Run(test.name, func(t *testing.T) { + r1 := 1 << 32 + r2 := 2 << 32 + r3 := 3 << 32 + r4 := 4 << 32 + // key := highbits(uint64(r4)) + + bitmap1 := New() + bitmap2 := New() + bitmap1.SetCopyOnWrite(test.cow1) + bitmap2.SetCopyOnWrite(test.cow2) + + bitmap2.AddRange(uint64(r1)-1, uint64(r1)+2) + bitmap2.AddRange(uint64(r2)-1, uint64(r2)+2) + bitmap2.AddRange(uint64(r3)-1, uint64(r3)+2) + bitmap2.AddRange(uint64(r4)-1, uint64(r4)+2) + + assert.False(t, bitmap1.Contains(uint64(r2))) + assert.False(t, bitmap1.Contains(uint64(r3))) + assert.Equal(t, 0, len(bitmap1.highlowcontainer.keys)) + bitmap1.highlowcontainer.appendCopiesAfter(bitmap2.highlowcontainer, 0) + assert.Equal(t, 4, len(bitmap1.highlowcontainer.keys)) + assert.True(t, bitmap1.Contains(uint64(r2))) + assert.True(t, bitmap1.Contains(uint64(r3))) + + for idx1, c1 := range bitmap1.highlowcontainer.containers { + for idx2, c2 := range bitmap2.highlowcontainer.containers { + // idx+1 is required because appendCopiesAfter starts at key 1 + if idx1+1 == idx2 { + if test.cow1 && test.cow2 { + assert.True(t, c1 == c2) + } else { + assert.False(t, c1 == c2) + } + } + } + } + }) + } + + tests = []struct { + name string + cow1 bool + cow2 bool + }{ + {"AppendCopiesUntilCoW", true, true}, + {"AppendCopiesUntilCoW", false, false}, + {"AppendCopiesUntilMixedCoW", true, false}, + {"AppendCopiesUntilMixedCoW", false, true}, + } + + for _, test := range tests { + t.Run(test.name, func(t *testing.T) { + r1 := 1 << 32 + r2 := 2 << 32 + r3 := 3 << 32 + r4 := 4 << 32 + key := highbits(uint64(r4)) + + bitmap1 := New() + bitmap2 := New() + bitmap1.SetCopyOnWrite(test.cow1) + bitmap2.SetCopyOnWrite(test.cow2) + + bitmap2.AddRange(uint64(r1)-1, uint64(r1)+2) + bitmap2.AddRange(uint64(r2)-1, uint64(r2)+2) + bitmap2.AddRange(uint64(r3)-1, uint64(r3)+2) + bitmap2.AddRange(uint64(r4)-1, uint64(r4)+2) + + assert.False(t, bitmap1.Contains(uint64(r2))) + assert.False(t, bitmap1.Contains(uint64(r3))) + assert.Equal(t, 0, len(bitmap1.highlowcontainer.keys)) + bitmap1.highlowcontainer.appendCopiesUntil(bitmap2.highlowcontainer, key) + assert.Equal(t, 4, len(bitmap1.highlowcontainer.keys)) + assert.True(t, bitmap1.Contains(uint64(r2))) + assert.True(t, bitmap1.Contains(uint64(r3))) + + for idx1, c1 := range bitmap1.highlowcontainer.containers { + for idx2, c2 := range bitmap2.highlowcontainer.containers { + if idx1 == idx2 { + if test.cow1 && test.cow2 { + assert.True(t, c1 == c2) + } else { + assert.False(t, c1 == c2) + } + } + } + } + }) + } +} From c744587beec6f23e074110f70e9514c6ccf79802 Mon Sep 17 00:00:00 2001 From: bstrausser Date: Sun, 23 Jun 2024 13:10:53 -0400 Subject: [PATCH 07/15] Roaring: Code coverage on OrCardinality --- roaring_test.go | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/roaring_test.go b/roaring_test.go index e5a7d032..44d1da6d 100644 --- a/roaring_test.go +++ b/roaring_test.go @@ -406,6 +406,42 @@ func TestFastCard(t *testing.T) { assert.Equal(t, bm.GetCardinality(), bm2.OrCardinality(bm)) } +func TestFastCardUnequalKeys(t *testing.T) { + // These tests will excercise the interior code branches of OrCardinality + + t.Run("Merge small into large", func(t *testing.T) { + bm := NewBitmap() + bm.AddRange(0, 1024) + bm2 := NewBitmap() + start := uint64(2 << 16) + bm2.AddRange(start, start+3) + + assert.Equal(t, uint64(1027), bm2.OrCardinality(bm)) + }) + t.Run("Merge large into small", func(t *testing.T) { + bm := NewBitmap() + bm.AddRange(0, 1024) + bm2 := NewBitmap() + start := uint64(2 << 16) + bm2.AddRange(start, start+3) + + assert.Equal(t, uint64(1027), bm.OrCardinality(bm2)) + }) + + t.Run("Merge large into small same keyrange start", func(t *testing.T) { + bm := NewBitmap() + start := uint64(2 << 16) + bm.AddRange(0, 1024) + bm.AddRange(start, start+3) + + bm2 := NewBitmap() + bm2.AddRange(0, 512) + bm2.AddRange(start, start+3) + + assert.Equal(t, uint64(1027), bm.OrCardinality(bm2)) + }) +} + func TestIntersects1(t *testing.T) { bm := NewBitmap() bm.Add(1) From 23ba605bc2848860ff807a0bf07fcf3243b055cb Mon Sep 17 00:00:00 2001 From: bstrausser Date: Mon, 24 Jun 2024 00:38:59 -0400 Subject: [PATCH 08/15] BitmapContainer: Fix orArrayCardinality --- bitmapcontainer.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bitmapcontainer.go b/bitmapcontainer.go index 1b705501..3eaad2ba 100644 --- a/bitmapcontainer.go +++ b/bitmapcontainer.go @@ -542,7 +542,7 @@ func (bc *bitmapContainer) orArray(value2 *arrayContainer) container { } func (bc *bitmapContainer) orArrayCardinality(value2 *arrayContainer) int { - answer := 0 + answer := bc.getCardinality() c := value2.getCardinality() for k := 0; k < c; k++ { // branchless: From a2e7f221ed8b6aef4d670eef8b6e4a33f5d1fba2 Mon Sep 17 00:00:00 2001 From: Barrett Strausser Date: Tue, 25 Jun 2024 00:16:47 -0400 Subject: [PATCH 09/15] Update roaring64/roaringarray64_test.go Co-authored-by: Daniel Lemire --- roaring64/roaringarray64_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/roaring64/roaringarray64_test.go b/roaring64/roaringarray64_test.go index 24a4be72..8b7255bc 100644 --- a/roaring64/roaringarray64_test.go +++ b/roaring64/roaringarray64_test.go @@ -9,7 +9,7 @@ import ( func TestRoaringArray64AdvanceUntil(t *testing.T) { bitmap := New() low := 1 << 32 - mid := 2 << 32 + mid := uint64(2) << 32 high := 3 << 32 bitmap.AddRange(uint64(low)-1, uint64(low)+2) bitmap.AddRange(uint64(mid)-1, uint64(mid)+2) From 8021f38f003f694424790022deb763e5b1974ee0 Mon Sep 17 00:00:00 2001 From: Barrett Strausser Date: Tue, 25 Jun 2024 00:17:03 -0400 Subject: [PATCH 10/15] Update roaring64/roaringarray64_test.go Co-authored-by: Daniel Lemire --- roaring64/roaringarray64_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/roaring64/roaringarray64_test.go b/roaring64/roaringarray64_test.go index 8b7255bc..281322dc 100644 --- a/roaring64/roaringarray64_test.go +++ b/roaring64/roaringarray64_test.go @@ -8,7 +8,7 @@ import ( func TestRoaringArray64AdvanceUntil(t *testing.T) { bitmap := New() - low := 1 << 32 + low := uint64(1) << 32 mid := uint64(2) << 32 high := 3 << 32 bitmap.AddRange(uint64(low)-1, uint64(low)+2) From 1cbac0823a0bd943ea053a0a54e9fcd6ea977fa0 Mon Sep 17 00:00:00 2001 From: Barrett Strausser Date: Tue, 25 Jun 2024 00:17:10 -0400 Subject: [PATCH 11/15] Update roaring64/roaringarray64_test.go Co-authored-by: Daniel Lemire --- roaring64/roaringarray64_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/roaring64/roaringarray64_test.go b/roaring64/roaringarray64_test.go index 281322dc..0a7d0cc3 100644 --- a/roaring64/roaringarray64_test.go +++ b/roaring64/roaringarray64_test.go @@ -10,7 +10,7 @@ func TestRoaringArray64AdvanceUntil(t *testing.T) { bitmap := New() low := uint64(1) << 32 mid := uint64(2) << 32 - high := 3 << 32 + high := uint64(3) << 32 bitmap.AddRange(uint64(low)-1, uint64(low)+2) bitmap.AddRange(uint64(mid)-1, uint64(mid)+2) bitmap.AddRange(uint64(high)-1, uint64(high)+2) From 0e396c278b97682ef5de226e8cb251f99d448bbf Mon Sep 17 00:00:00 2001 From: Barrett Strausser Date: Tue, 25 Jun 2024 00:17:16 -0400 Subject: [PATCH 12/15] Update roaring64/roaringarray64_test.go Co-authored-by: Daniel Lemire --- roaring64/roaringarray64_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/roaring64/roaringarray64_test.go b/roaring64/roaringarray64_test.go index 0a7d0cc3..965ccba7 100644 --- a/roaring64/roaringarray64_test.go +++ b/roaring64/roaringarray64_test.go @@ -40,7 +40,7 @@ func TestCopies(t *testing.T) { for _, test := range tests { t.Run(test.name, func(t *testing.T) { r1 := 1 << 32 - r2 := 2 << 32 + r2 := uint64(2) << 32 r3 := 3 << 32 r4 := 4 << 32 // key := highbits(uint64(r4)) From a4270d5bcdd2fff14a8e6a20edb554bb20a0e303 Mon Sep 17 00:00:00 2001 From: Barrett Strausser Date: Tue, 25 Jun 2024 00:17:22 -0400 Subject: [PATCH 13/15] Update roaring64/roaringarray64_test.go Co-authored-by: Daniel Lemire --- roaring64/roaringarray64_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/roaring64/roaringarray64_test.go b/roaring64/roaringarray64_test.go index 965ccba7..55077b1b 100644 --- a/roaring64/roaringarray64_test.go +++ b/roaring64/roaringarray64_test.go @@ -41,7 +41,7 @@ func TestCopies(t *testing.T) { t.Run(test.name, func(t *testing.T) { r1 := 1 << 32 r2 := uint64(2) << 32 - r3 := 3 << 32 + r3 := uint64(3) << 32 r4 := 4 << 32 // key := highbits(uint64(r4)) From 930a4609652a92ca37096fed15ebdef02445d7cc Mon Sep 17 00:00:00 2001 From: Barrett Strausser Date: Tue, 25 Jun 2024 00:17:28 -0400 Subject: [PATCH 14/15] Update roaring64/roaringarray64_test.go Co-authored-by: Daniel Lemire --- roaring64/roaringarray64_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/roaring64/roaringarray64_test.go b/roaring64/roaringarray64_test.go index 55077b1b..233b0e9a 100644 --- a/roaring64/roaringarray64_test.go +++ b/roaring64/roaringarray64_test.go @@ -42,7 +42,7 @@ func TestCopies(t *testing.T) { r1 := 1 << 32 r2 := uint64(2) << 32 r3 := uint64(3) << 32 - r4 := 4 << 32 + r4 := uint64(4) << 32 // key := highbits(uint64(r4)) bitmap1 := New() From 3625fd1bb6f5c597f68ddb69f5bad2268fe890f1 Mon Sep 17 00:00:00 2001 From: bstrausser Date: Tue, 25 Jun 2024 00:28:14 -0400 Subject: [PATCH 15/15] RoaringArray64: fix architecture for input values --- roaring64/roaringarray64_test.go | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/roaring64/roaringarray64_test.go b/roaring64/roaringarray64_test.go index 233b0e9a..8b3a696a 100644 --- a/roaring64/roaringarray64_test.go +++ b/roaring64/roaringarray64_test.go @@ -39,11 +39,10 @@ func TestCopies(t *testing.T) { for _, test := range tests { t.Run(test.name, func(t *testing.T) { - r1 := 1 << 32 + r1 := uint64(1) << 32 r2 := uint64(2) << 32 r3 := uint64(3) << 32 r4 := uint64(4) << 32 - // key := highbits(uint64(r4)) bitmap1 := New() bitmap2 := New() @@ -91,10 +90,10 @@ func TestCopies(t *testing.T) { for _, test := range tests { t.Run(test.name, func(t *testing.T) { - r1 := 1 << 32 - r2 := 2 << 32 - r3 := 3 << 32 - r4 := 4 << 32 + r1 := uint64(1) << 32 + r2 := uint64(2) << 32 + r3 := uint64(3) << 32 + r4 := uint64(4) << 32 key := highbits(uint64(r4)) bitmap1 := New()