diff --git a/roaring64/parallel64.go b/roaring64/parallel64.go index 5dadc8de..7bea3c68 100644 --- a/roaring64/parallel64.go +++ b/roaring64/parallel64.go @@ -39,9 +39,13 @@ func ParOr(parallelism int, bitmaps ...*Bitmap) *Bitmap { // on some systems, would block indefinitely. keyRange := uint64(hKey) - uint64(lKey) + 1 if keyRange == 1 { - // revert to FastOr. Since the key range is 0 - // no container-level aggregation parallelism is achievable - return FastOr(bitmaps...) + // All bitmaps have the same key, + // we can merge the 32-bit roaring bitmaps in parallel + var bms32s = make([]*roaring.Bitmap, 0, len(bitmaps)) + for _, b := range bitmaps { + bms32s = append(bms32s, b.highlowcontainer.containers...) + } + return roaring32AsRoaring64(roaring.ParOr(parallelism, bms32s...), lKey) } if parallelism == 0 { diff --git a/roaring64/roaring64.go b/roaring64/roaring64.go index f5a19330..8ce7f4f1 100644 --- a/roaring64/roaring64.go +++ b/roaring64/roaring64.go @@ -1248,9 +1248,13 @@ func (rb *Bitmap) Validate() error { // Roaring32AsRoaring64 inserts a 32-bit roaring bitmap into // a 64-bit roaring bitmap. No copy is made. func Roaring32AsRoaring64(bm32 *roaring.Bitmap) *Bitmap { + return roaring32AsRoaring64(bm32, 0) +} + +func roaring32AsRoaring64(bm32 *roaring.Bitmap, key uint32) *Bitmap { rb := NewBitmap() rb.highlowcontainer.resize(0) - rb.highlowcontainer.keys = append(rb.highlowcontainer.keys, 0) + rb.highlowcontainer.keys = append(rb.highlowcontainer.keys, key) rb.highlowcontainer.containers = append(rb.highlowcontainer.containers, bm32) rb.highlowcontainer.needCopyOnWrite = append(rb.highlowcontainer.needCopyOnWrite, false) return rb