diff --git a/roaring/roaring.go b/roaring/roaring.go index 0e288d25e..7685f7a94 100644 --- a/roaring/roaring.go +++ b/roaring/roaring.go @@ -407,9 +407,6 @@ func (b *Bitmap) Union(others ...*Bitmap) *Bitmap { // b in place. func (b *Bitmap) UnionInPlace(others ...*Bitmap) { b.unionIntoTarget(b, others...) - // for _, other := range others { - // b.unionIntoTarget(other, b) - // } } type wrapperIter struct { @@ -504,12 +501,15 @@ func (b *Bitmap) unionIntoTarget(target *Bitmap, others ...*Bitmap) { // } // else { // Use a bitmap - buf := make([]uint64, bitmapN) - ob := buf[:bitmapN] - container := &Container{ - bitmap: ob, - n: 0, - containerType: containerBitmap, + container := target.Containers.Get(iKey) + if container == nil { + buf := make([]uint64, bitmapN) + ob := buf[:bitmapN] + container = &Container{ + bitmap: ob, + n: 0, + containerType: containerBitmap, + } } for _, jIter := range otherIters { diff --git a/roaring/roaring_test.go b/roaring/roaring_test.go index f554d1df3..8e389c586 100644 --- a/roaring/roaring_test.go +++ b/roaring/roaring_test.go @@ -1424,12 +1424,12 @@ func BenchmarkUnion(b *testing.B) { } } -// func BenchmarkUnionBulk(b *testing.B) { -// // a1, a2, b, r1, r2 *roaring.Bitmap -// data := getBenchData(b) -// yolo := roaring.NewBitmap() -// for n := 0; n < b.N; n++ { -// yolo. -// BulkUnion(data.a1, data.a2, data.b, data.r1, data.r2) -// } -// } +func BenchmarkUnionBulk(b *testing.B) { + // a1, a2, b, r1, r2 *roaring.Bitmap + data := getBenchData(b) + yolo := roaring.NewBitmap() + for n := 0; n < b.N; n++ { + yolo. + UnionInPlace(data.a1, data.a2, data.b, data.r1, data.r2) + } +}