From 0701f9b7ddcff7bfb5a9d11bffa0e5fcee62c9cb Mon Sep 17 00:00:00 2001 From: Seebs Date: Mon, 30 Aug 2021 12:09:14 -0500 Subject: [PATCH] fix broken intersectionCallback functions Two of the intersectionCallback functions were broken. In intersectionCallbackArrayArray, when checking to see whether we can skip ahead 8, we need to check whether that last value is lower than the one we're looking for, not whether the first value is. For intersectionCallbackArrayBitmap, actually implement it at all; it had never gotten modified significantly from the original intersectionCount, so it still counted and returned intersections, but never called the callback at all. --- roaring/roaring.go | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/roaring/roaring.go b/roaring/roaring.go index 1cd579593..9567b37fb 100644 --- a/roaring/roaring.go +++ b/roaring/roaring.go @@ -4493,10 +4493,13 @@ func intersectionCallbackArrayArray(a, b *Container, fn func(uint16)) { if (na << 2) < nb { for _, va := range ca { for cb[0] < va { - if len(cb) > 8 && cb[0] < va { + // try to skip ahead a bit faster + for len(cb) > 7 && cb[7] < va { cb = cb[8:] } - cb = cb[1:] + for len(cb) > 0 && cb[0] < va { + cb = cb[1:] + } if len(cb) == 0 { return } @@ -4585,7 +4588,7 @@ func intersectionCallbackBitmapRun(a, b *Container, fn func(uint16)) { } } -func intersectionCallbackArrayBitmap(a, b *Container, fn func(uint16)) (n int32) { +func intersectionCallbackArrayBitmap(a, b *Container, fn func(uint16)) { statsHit("intersectionCount/ArrayBitmap") bitmap := b.bitmap() ln := len(bitmap) @@ -4595,9 +4598,10 @@ func intersectionCallbackArrayBitmap(a, b *Container, fn func(uint16)) (n int32) break } off := val % 64 - n += int32(bitmap[i]>>off) & 1 + if (bitmap[i]>>off) & 1 != 0 { + fn(val) + } } - return n } func intersectionCallbackBitmapBitmap(a, b *Container, fn func(uint16)) {