Commit d60ba3f
authored
Rank Many Fix + Memory Sanitizer Build Flag (#847)
* Add Memory Sanitizer Option
Memory Sanitizer has some false positives, but it did catch a bug.
Further work with the memory sanitizer should involve automatic
accounting for the false positives.
* Bugfix for roaring_bitmap_rank_many (N in N out)
(Problem found with Memory Sanitizer, fix by Claude Sonnet 4.6)
The interface contract of roaring_bitmap_rank_many() is unambiguous:
for N sorted inputs you should get N ranks out, one per input, in order.
The bug is that the implementation doesn't honor that contract in the
case where one or more trailing input values have xhigh greater than
every key. The loop's exit condition (i < size && iter != end) lets i
run out before iter does, and when that happens the function just
returns early having silently skipped writing to the remaining ans
slots, even though the caller was promised an answer for every input.
What should happen for those leftover values is straightforward: if a
query value's high bits exceed every container key in the bitmap,
that value is greater than every element the bitmap holds, so its rank
is just the bitmap's total cardinality, which is exactly what size
holds once the loop has walked through all containers (each xhigh > key
branch step added that container's cardinality to size).
So the fix just applies the same logic the function already uses
(rank = accumulated size) to the queries that fall off the end.1 parent d81c639 commit d60ba3f
3 files changed
Lines changed: 13 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
52 | 52 | | |
53 | 53 | | |
54 | 54 | | |
| 55 | + | |
55 | 56 | | |
56 | 57 | | |
57 | 58 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
147 | 147 | | |
148 | 148 | | |
149 | 149 | | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2823 | 2823 | | |
2824 | 2824 | | |
2825 | 2825 | | |
| 2826 | + | |
| 2827 | + | |
| 2828 | + | |
| 2829 | + | |
2826 | 2830 | | |
2827 | 2831 | | |
2828 | 2832 | | |
| |||
0 commit comments