From 13dbe22b18163d1e4d3759b4c06b3f80b8c24234 Mon Sep 17 00:00:00 2001 From: Richard Artoul Date: Thu, 29 Nov 2018 13:53:10 -0500 Subject: [PATCH] Move next logic into helper --- roaring/roaring.go | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/roaring/roaring.go b/roaring/roaring.go index b2b6fdf39..bbafbae69 100644 --- a/roaring/roaring.go +++ b/roaring/roaring.go @@ -420,11 +420,28 @@ type wrapperIter struct { handled bool } +type wrappedIters []wrapperIter + +func (w wrappedIters) next() bool { + hasNext := false + + for i, wrapped := range w { + next := wrapped.iter.Next() + w[i].hasNext = next + w[i].handled = false + if next { + hasNext = true + } + } + + return hasNext +} + // unionIntoTarget stores the union of b and other into target. b and other will // be left unchanged, but target will be modified in place. Used to share // the union logic between the copy-on-write and in-place functions. func (b *Bitmap) unionIntoTarget(target *Bitmap, others ...*Bitmap) { - otherIters := make([]wrapperIter, 0, len(others)+1) + otherIters := make(wrappedIters, 0, len(others)+1) bIter, _ := b.Containers.Iterator(0) next := bIter.Next() if next { @@ -541,15 +558,7 @@ func (b *Bitmap) unionIntoTarget(target *Bitmap, others ...*Bitmap) { } } - hasNext = false - for i, otherIter := range otherIters { - next := otherIter.iter.Next() - otherIters[i].hasNext = next - otherIters[i].handled = false - if next { - hasNext = true - } - } + hasNext = otherIters.next() if !hasNext { // None of the iters had any more values, we're done.