Skip to content

Commit

Permalink
Merge pull request #111 from maciej/par_and_fix
Browse files Browse the repository at this point in the history
Fixes an issue with ParAnd producing bitmaps with empty containers
  • Loading branch information
lemire authored Oct 22, 2017
2 parents 9fee29c + 23dc3a1 commit a5fe987
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
13 changes: 12 additions & 1 deletion parallel.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,9 @@ func appenderRoutine(bitmapChan chan<- *Bitmap, resultChan <-chan keyedContainer
},
}
for i := range keys {
answer.highlowcontainer.appendContainer(keys[i], containers[i], false)
if containers[i] != nil { // in case a resulting container was empty, see ParAnd function
answer.highlowcontainer.appendContainer(keys[i], containers[i], false)
}
}

bitmapChan <- answer
Expand Down Expand Up @@ -274,8 +276,17 @@ func ParAnd(parallelism int, bitmaps ...*Bitmap) *Bitmap {
for input := range inputChan {
c := input.containers[0].and(input.containers[1])
for _, next := range input.containers[2:] {
if c.getCardinality() == 0 {
break
}
c = c.iand(next)
}

// Send a nil explicitly if the result of the intersection is an empty container
if c.getCardinality() == 0 {
c = nil
}

kx := keyedContainer{
input.key,
c,
Expand Down
9 changes: 9 additions & 0 deletions parallel_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,15 @@ func TestParAggregationsOneEmpty(t *testing.T) {
})
}

func TestParAggregationsDisjointSetIntersection(t *testing.T) {
Convey("Par", t, func() {
rb1 := BitmapOf(1)
rb2 := BitmapOf(2)

So(ParAnd(0, rb1, rb2).Stats().Containers, ShouldEqual, 0)
})
}

func TestParAggregationsReversed3COW(t *testing.T) {
Convey("Par", t, func() {
rb1 := NewBitmap()
Expand Down

0 comments on commit a5fe987

Please sign in to comment.