GH-51289: [C++] Add iterator-based bit-run traversal - #51310
Open
akashchamp wants to merge 1 commit into
Open
Conversation
|
|
pitrou
reviewed
Sep 14, 2026
Comment on lines
+532
to
+539
| bool operator==(std::default_sentinel_t) const { return at_end_; } | ||
| bool operator!=(std::default_sentinel_t) const { return !at_end_; } | ||
| friend bool operator==(std::default_sentinel_t, const BitRunIterator& iterator) { | ||
| return iterator.at_end_; | ||
| } | ||
| friend bool operator!=(std::default_sentinel_t, const BitRunIterator& iterator) { | ||
| return !iterator.at_end_; | ||
| } |
Member
There was a problem hiding this comment.
Why both the friend functions and the instance methods? Probably we don't need both; let's just keep the friend ones?
Comment on lines
+635
to
+642
| bool operator==(std::default_sentinel_t) const { return at_end_; } | ||
| bool operator!=(std::default_sentinel_t) const { return !at_end_; } | ||
| friend bool operator==(std::default_sentinel_t, const SetBitRunIterator& iterator) { | ||
| return iterator.at_end_; | ||
| } | ||
| friend bool operator!=(std::default_sentinel_t, const SetBitRunIterator& iterator) { | ||
| return !iterator.at_end_; | ||
| } |
Member
There was a problem hiding this comment.
Same question as in BitRunIterator.
|
|
||
| TwoSetBitRunIterator(const TwoSetBitRunIterator&) = default; | ||
|
|
||
| TwoSetBitRunIterator& operator=(const TwoSetBitRunIterator& other) { |
Member
There was a problem hiding this comment.
Is it important for this class to be copyable?
Comment on lines
+600
to
+602
| SetBitRunIterator(const SetBitRunIterator&) = default; | ||
|
|
||
| SetBitRunIterator& operator=(const SetBitRunIterator& other) { |
Member
There was a problem hiding this comment.
Is it important for this class to be copyable?
Comment on lines
+641
to
+645
| for (const auto run : range) { | ||
| EXPECT_EQ(run.position, 0); | ||
| ++run_count; | ||
| break; | ||
| } |
Member
|
@akashchamp Is it possible to find potential call sites in the codebase that would benefit from these constructs? @HuaHuaY Perhaps you'll be interested in taking a look at this. |
HuaHuaY
self-requested a review
September 14, 2026 15:47
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #51289
Rationale for this change
The callback-based bit-run visitors require callers to route early termination through callback status handling. These ranges allow normal iterator control flow, including breaking once a caller has found the run it needs.
What changes are included in this PR?
IterateBitRuns,IterateSetBitRuns, andIterateTwoSetBitRunsas C++20 input ranges.BitRuntype and introducePositionedBitRunfor full bit runs so iterator values expose position, length, and set state.Are these changes tested?
clang-format --dry-run --Werrorandgit diff --checkarrow-bit-utility-test --gtest_filter='TestSetBitRunReader.Iterate*'(3 tests)arrow-bit-utility-test(217 tests) and its focused CTest entryAre there any user-facing changes?
No public API changes. This adds internal C++ traversal helpers for callers that need iterator control flow.
AI assistance
Assisted-by: Codex
AI assistance was used for the initial implementation and regression tests. I reviewed the final code, kept the change scoped to the requested API, and manually validated the behavior above.