Skip to content

Commit 23dc3a1

Browse files
committed
Fixes an issue with ParAnd producing bitmaps with empty containers
This commit fixes an issue with `ParAnd` producing bitmaps that contain empty containers, which AFAIK are invalid.
1 parent 9fee29c commit 23dc3a1

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

parallel.go

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,9 @@ func appenderRoutine(bitmapChan chan<- *Bitmap, resultChan <-chan keyedContainer
170170
},
171171
}
172172
for i := range keys {
173-
answer.highlowcontainer.appendContainer(keys[i], containers[i], false)
173+
if containers[i] != nil { // in case a resulting container was empty, see ParAnd function
174+
answer.highlowcontainer.appendContainer(keys[i], containers[i], false)
175+
}
174176
}
175177

176178
bitmapChan <- answer
@@ -274,8 +276,17 @@ func ParAnd(parallelism int, bitmaps ...*Bitmap) *Bitmap {
274276
for input := range inputChan {
275277
c := input.containers[0].and(input.containers[1])
276278
for _, next := range input.containers[2:] {
279+
if c.getCardinality() == 0 {
280+
break
281+
}
277282
c = c.iand(next)
278283
}
284+
285+
// Send a nil explicitly if the result of the intersection is an empty container
286+
if c.getCardinality() == 0 {
287+
c = nil
288+
}
289+
279290
kx := keyedContainer{
280291
input.key,
281292
c,

parallel_test.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,15 @@ func TestParAggregationsOneEmpty(t *testing.T) {
4646
})
4747
}
4848

49+
func TestParAggregationsDisjointSetIntersection(t *testing.T) {
50+
Convey("Par", t, func() {
51+
rb1 := BitmapOf(1)
52+
rb2 := BitmapOf(2)
53+
54+
So(ParAnd(0, rb1, rb2).Stats().Containers, ShouldEqual, 0)
55+
})
56+
}
57+
4958
func TestParAggregationsReversed3COW(t *testing.T) {
5059
Convey("Par", t, func() {
5160
rb1 := NewBitmap()

0 commit comments

Comments
 (0)