From 32c4b3540f33d9384e291ce16e481e4384184482 Mon Sep 17 00:00:00 2001 From: Seebs Date: Tue, 13 Nov 2018 12:12:13 -0600 Subject: [PATCH] simplify intersectBitmapRun output to remove a conversion If the total number of things returned was small enough to make an array, intersectBitmapRun converted to an array. This seems possibly-premature; future processing might well prefer a bitmap. We know everything gets optimized before being written out, let's not convert without a specific reason. But also, let's use an array no matter which container is small enough to prove that we can do so safely. Fixes #854. --- roaring/roaring.go | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/roaring/roaring.go b/roaring/roaring.go index 3a4050cea..ced003d37 100644 --- a/roaring/roaring.go +++ b/roaring/roaring.go @@ -2102,12 +2102,12 @@ func intersectRunRun(a, b *Container) *Container { return output } -// intersectBitmapRun returns an array container if the run container's -// cardinality is < ArrayMaxSize. Otherwise it returns a bitmap container. +// intersectBitmapRun returns an array container if either container's +// cardinality is <= ArrayMaxSize. Otherwise it returns a bitmap container. func intersectBitmapRun(a, b *Container) *Container { statsHit("intersect/BitmapRun") var output *Container - if b.n < ArrayMaxSize { + if b.n <= ArrayMaxSize || a.n <= ArrayMaxSize { // output is array container output = &Container{containerType: containerArray} for _, iv := range b.runs { @@ -2161,9 +2161,6 @@ func intersectBitmapRun(a, b *Container) *Container { valast = vastart + 63 } } - if output.n < ArrayMaxSize { - output.bitmapToArray() - } } return output }