Skip to content

Clamp the end before checking for an empty cardinality range - #600

Merged
lemire merged 1 commit into
RoaringBitmap:masterfrom
yxshee:fix/cardinality-range-clamp
Dec 1, 2026
Merged

lemire merged 1 commit into
RoaringBitmap:masterfrom
yxshee:fix/cardinality-range-clamp

Conversation

@yxshee

@yxshee yxshee commented Nov 21, 2026

Copy link
Copy Markdown
Contributor

Description

CardinalityInRange can count low IDs when the query lies entirely above the bitmap's 32-bit ID domain. On master, this example returns 3 instead of 0.

rb := roaring.BitmapOf(0, 7, 0xffffffff)
fmt.Println(rb.CardinalityInRange(1<<32, (1<<32)+1))
expected: 0x0
actual  : 0x3

Type of Change

  • Bug fix (non-breaking change which fixes an issue)

Changes Made

What was changed?

Cap the exclusive end before testing for an empty range.

Why was it changed?

A start outside the 32-bit domain can wrap to a low ID when cast to uint32.

How was it changed?

Check the adjusted interval before narrowing either endpoint.

Testing

The Go 1.24 package and appengine tests passed. The focused regression passed 30 runs. A sorted-input oracle matched all 5,296 queries with the fix.

Formatting

gofmt -s -l and go tool unconvert ./... passed.

Fuzzing

The template's corpus command generated a seed. Go reported testing: warning: no fuzz tests to fuzz when asked to run FuzzSmat.

Performance Impact

Six runs of each of nine range-count benchmarks recorded zero allocations on both revisions. Median timings ranged from 9.0% faster to 6.8% slower.

Related Issues

Related to #513.

@lemire
lemire merged commit b7c7a71 into RoaringBitmap:master Dec 1, 2026
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants