Skip to content

Commit 09c46a0

Browse files
authored
Merge pull request #476 from customerio/roaring64_ParOr
roaring64: Use roaring.ParOr when all keys on the roaringArray64 are same
2 parents b705c37 + 90d9862 commit 09c46a0

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

roaring64/parallel64.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,13 @@ func ParOr(parallelism int, bitmaps ...*Bitmap) *Bitmap {
3939
// on some systems, would block indefinitely.
4040
keyRange := uint64(hKey) - uint64(lKey) + 1
4141
if keyRange == 1 {
42-
// revert to FastOr. Since the key range is 0
43-
// no container-level aggregation parallelism is achievable
44-
return FastOr(bitmaps...)
42+
// All bitmaps have the same key,
43+
// we can merge the 32-bit roaring bitmaps in parallel
44+
var bms32s = make([]*roaring.Bitmap, 0, len(bitmaps))
45+
for _, b := range bitmaps {
46+
bms32s = append(bms32s, b.highlowcontainer.containers...)
47+
}
48+
return roaring32AsRoaring64(roaring.ParOr(parallelism, bms32s...), lKey)
4549
}
4650

4751
if parallelism == 0 {

roaring64/roaring64.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1248,9 +1248,13 @@ func (rb *Bitmap) Validate() error {
12481248
// Roaring32AsRoaring64 inserts a 32-bit roaring bitmap into
12491249
// a 64-bit roaring bitmap. No copy is made.
12501250
func Roaring32AsRoaring64(bm32 *roaring.Bitmap) *Bitmap {
1251+
return roaring32AsRoaring64(bm32, 0)
1252+
}
1253+
1254+
func roaring32AsRoaring64(bm32 *roaring.Bitmap, key uint32) *Bitmap {
12511255
rb := NewBitmap()
12521256
rb.highlowcontainer.resize(0)
1253-
rb.highlowcontainer.keys = append(rb.highlowcontainer.keys, 0)
1257+
rb.highlowcontainer.keys = append(rb.highlowcontainer.keys, key)
12541258
rb.highlowcontainer.containers = append(rb.highlowcontainer.containers, bm32)
12551259
rb.highlowcontainer.needCopyOnWrite = append(rb.highlowcontainer.needCopyOnWrite, false)
12561260
return rb

0 commit comments

Comments
 (0)