From c495d08d1b9a42a46811c6dd907cac241e04a441 Mon Sep 17 00:00:00 2001 From: Richard Artoul Date: Mon, 3 Dec 2018 15:30:54 -0500 Subject: [PATCH] simplify logic by removing concept or target --- roaring/roaring.go | 23 +++-------------------- 1 file changed, 3 insertions(+), 20 deletions(-) diff --git a/roaring/roaring.go b/roaring/roaring.go index f78f98fba..2c38cfea2 100644 --- a/roaring/roaring.go +++ b/roaring/roaring.go @@ -415,7 +415,7 @@ func (b *Bitmap) Union(others ...*Bitmap) *Bitmap { // UnionInPlace returns the bitwise union of b and others, modifying // b in place. func (b *Bitmap) UnionInPlace(others ...*Bitmap) { - b.unionIntoTarget(b, others...) + b.unionInPlace(others...) } func (b *Bitmap) unionIntoTargetSingle(target *Bitmap, other *Bitmap) { @@ -543,19 +543,15 @@ func (b *Bitmap) unionIntoTargetSingle(target *Bitmap, other *Bitmap) { // ---------------------------- | ---------------------------- | ---------------------------- // Bitmap 4 |___X_______________________| | |___X_______________________| | |___X_______________________| // _ -func (b *Bitmap) unionIntoTarget(target *Bitmap, others ...*Bitmap) { +func (b *Bitmap) unionInPlace(others ...*Bitmap) { var ( requiredSliceSize = len(others) // To avoid having to allocate a slice everytime, if the number of bitmaps // being unioned is small enough we can just use this stack-allocated array. staticHandledIters = [20]handledIter{} bitmapIters handledIters + target = b ) - if b != target { - // If b and target are not the same, we will need to union b into target which - // means we need room for one more iter. - requiredSliceSize++ - } if requiredSliceSize <= 20 { bitmapIters = staticHandledIters[:0] @@ -563,19 +559,6 @@ func (b *Bitmap) unionIntoTarget(target *Bitmap, others ...*Bitmap) { bitmapIters = make(handledIters, 0, requiredSliceSize) } - // Only include b in the list of iters if its not the same as target to avoid - // a wasteful self union. - if b != target { - bIter, _ := b.Containers.Iterator(0) - if bIter.Next() { - bitmapIters = append(bitmapIters, handledIter{ - iter: bIter, - hasNext: true, - handled: false, - }) - } - } - for _, other := range others { otherIter, _ := other.Containers.Iterator(0) if otherIter.Next() {