Skip to content

Conversation

@lemire
Copy link
Member

@lemire lemire commented Nov 5, 2025

Fixes #22

@lemire lemire requested a review from Copilot November 5, 2025 18:29
@lemire lemire mentioned this pull request Nov 5, 2025
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds support for iterating over unset bits in a bitmap within a specified range. The implementation provides a new UnsetIterator method that returns values in [min, max] that are NOT contained in the bitmap, along with a helper Unset function for use with Go 1.23+ range-over-function.

Key changes:

  • Added unsetIterator type with logic to iterate over unset values within a range
  • Added Bitmap.UnsetIterator(min, max) method to create the iterator
  • Added Unset(b, min, max) function for Go 1.23+ range-over-function support
  • Comprehensive test coverage for various edge cases

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
roaring.go Implements unsetIterator struct and UnsetIterator method to iterate over unset bits in a range
iter.go Adds Unset function for Go 1.23+ range-over-function support
iter_test.go Comprehensive tests covering empty bitmaps, sparse bitmaps, edge cases, and early termination

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@rogpeppe
Copy link
Contributor

rogpeppe commented Nov 6, 2025

It would be helpful if this returned IntPeekable. That would make it possible to iterate over all ranges efficiently (see #491 ). Maybe there's another way of doing that that I haven't thought of though?

@lemire
Copy link
Member Author

lemire commented Nov 6, 2025

It would be helpful if this returned IntPeekable

Ok. Done.

@lemire lemire merged commit 2e9b4b9 into master Nov 6, 2025
14 checks passed
@rogpeppe
Copy link
Contributor

rogpeppe commented Nov 7, 2025

Thanks for adding the Peekable capability.

One passing thought after playing with this: it's arguably slightly confusing that this API call uses a uint32 closed range where other calls in the API (e.g. Flip, RemoveRange, etc) use a uint64 closed range. I don't see any other examples in the API where a range is specified as a uint32 closed range, so in the interests of consistency I'd suggest using a uint64 open range for UnsetIterator too.

Also it often simplifies code to be able to use a zero-length interval without special-casing, which isn't possible with this API in general - specifically I don't think there's any way to specify a zero-length interval at the very start, because [0, -1] isn't possible with uint32.

@lemire
Copy link
Member Author

lemire commented Nov 7, 2025

@rogpeppe Given that this is a new feature, we can break the API now. Feel free to issue a pull request.

We can introduce breaking changes at this point.

@rogpeppe
Copy link
Contributor

rogpeppe commented Nov 7, 2025

@rogpeppe Given that this is a new feature, we can break the API now. Feel free to issue a pull request.

We can introduce breaking changes at this point.

sure: #500

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.

Iterate over the unset bits

3 participants