Skip to content

Commit a098cfd

Browse files
committed
fixing various and and or issues
1 parent 0533b39 commit a098cfd

File tree

3 files changed

+44
-9
lines changed

3 files changed

+44
-9
lines changed

arraycontainer.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -417,8 +417,10 @@ func (ac *arrayContainer) iorArray(value2 *arrayContainer) container {
417417
func (ac *arrayContainer) iorBitmap(bc2 *bitmapContainer) container {
418418
bc1 := ac.toBitmapContainer()
419419
bc1.iorBitmap(bc2)
420-
*ac = *newArrayContainerFromBitmap(bc1)
421-
return ac
420+
// DO NOT DO THIS:
421+
// *ac = *newArrayContainerFromBitmap(bc1)
422+
// This will create gigantic array containers in the case of repeated calls to iorBitmap.
423+
return bc1
422424
}
423425

424426
func (ac *arrayContainer) iorRun16(rc *runContainer16) container {

roaring_test.go

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import (
55
"fmt"
66
"math"
77
"math/rand"
8+
randv2 "math/rand/v2"
9+
810
"strconv"
911
"testing"
1012

@@ -13,6 +15,39 @@ import (
1315
"github.com/stretchr/testify/require"
1416
)
1517

18+
func TestSplitter_BrokeBm(t *testing.T) {
19+
bm1 := NewBitmap()
20+
bm2 := NewBitmap()
21+
bm3 := NewBitmap()
22+
23+
for i := 0; i < 2000; i++ {
24+
bm1.Add(uint32(i))
25+
bm2.Add(uint32(i + 2000))
26+
bm3.Add(uint32(i * 4000))
27+
}
28+
res := FastOr(bm1, bm2, bm3)
29+
30+
require.NoError(t, res.Validate())
31+
32+
return
33+
}
34+
35+
func TestRoaring_AndMask(t *testing.T) {
36+
r := randv2.New(randv2.NewPCG(13, 22)) // reproducible random
37+
38+
rb := NewBitmap()
39+
for j := 0; j < 1_000_000; j++ {
40+
rb.Add(r.Uint32N(10_000_000) + 5_000_000)
41+
}
42+
43+
mask := New()
44+
mask.AddRange(1, 10_000_001)
45+
mask.And(rb)
46+
47+
err := mask.Validate()
48+
require.NoError(t, err) // this fails
49+
}
50+
1651
func TestIssue440(t *testing.T) {
1752
a := NewBitmap()
1853
a.AddMany([]uint32{1, 2, 3})

runcontainer.go

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1887,9 +1887,13 @@ func (rc *runContainer16) iand(a container) container {
18871887
case *runContainer16:
18881888
return rc.inplaceIntersect(c)
18891889
case *arrayContainer:
1890+
// inplace intersection with array is not supported
1891+
// It is likely not very useful either.
18901892
return rc.andArray(c)
18911893
case *bitmapContainer:
1892-
return rc.iandBitmapContainer(c)
1894+
// inplace intersection with bitmap is not supported
1895+
// It is very difficult to do this inplace and likely not useful.
1896+
return rc.andBitmapContainer(c)
18931897
}
18941898
panic("unsupported container type")
18951899
}
@@ -1900,12 +1904,6 @@ func (rc *runContainer16) inplaceIntersect(rc2 *runContainer16) container {
19001904
return rc
19011905
}
19021906

1903-
func (rc *runContainer16) iandBitmapContainer(bc *bitmapContainer) container {
1904-
isect := rc.andBitmapContainer(bc)
1905-
*rc = *newRunContainer16FromContainer(isect)
1906-
return rc
1907-
}
1908-
19091907
func (rc *runContainer16) andArray(ac *arrayContainer) container {
19101908
if len(rc.iv) == 0 {
19111909
return newArrayContainer()

0 commit comments

Comments
 (0)