Skip to content

Support BitMap64 ranges that end at the maximum value - #154

Open
Shaisolaris wants to merge 1 commit into
Ezibenroc:masterfrom
Shaisolaris:bitmap64-ranges-to-max
Open

Shaisolaris wants to merge 1 commit into
Ezibenroc:masterfrom
Shaisolaris:bitmap64-ranges-to-max

Conversation

@Shaisolaris

Copy link
Copy Markdown

The 64-bit range methods take an exclusive end as uint64_t, so a range that includes the largest value (end 2**64) raises OverflowError, while the 32-bit BitMap handles its own maximum:

from pyroaring import BitMap64
BitMap64().add_range(2**64 - 3, 2**64)          # OverflowError
BitMap64(range(2**64 - 3, 2**64))               # OverflowError

This affects add_range, remove_range, flip, flip_inplace, contains_range, range_cardinality and the range constructor path.

The change calls the closed roaring64_*_closed functions with end - 1, after checking that the end is between 0 and 2**64 and handling empty ranges first. Ends above 2**64, negative ends and non-integers still raise as before.

Tests: added TestRangeToMaximum in test.py. Locally (Python 3.12, Linux x86_64), with the new tests on the current master the 64-bit run has 4 of them failing; with this change they pass. test.py and test_state_machine.py otherwise give the same results before and after for both ROARING_BITSIZE=32 and 64. TestFFI::test_ffi_cardinality fails in my local build both before and after (an undefined symbol via ctypes), so I don't think it's related. I did not run other platforms.

Range methods passed an exclusive uint64 end, so an end of 2**64
overflowed. Use the closed roaring64 range functions instead.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant