Skip to content

GH-51289: [C++] Add iterator-based bit-run traversal - #51310

Open
akashchamp wants to merge 1 commit into
apache:mainfrom
akashchamp:GH-51289-bit-run-iterators
Open

GH-51289: [C++] Add iterator-based bit-run traversal#51310
akashchamp wants to merge 1 commit into
apache:mainfrom
akashchamp:GH-51289-bit-run-iterators

Conversation

@akashchamp

@akashchamp akashchamp commented Sep 11, 2026

Copy link
Copy Markdown

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?

  • Add IterateBitRuns, IterateSetBitRuns, and IterateTwoSetBitRuns as C++20 input ranges.
  • Preserve the existing BitRun type and introduce PositionedBitRun for full bit runs so iterator values expose position, length, and set state.
  • Cover offsets, null bitmaps, empty inputs, iterator copying and post-increment, and intersections longer than the legacy visitor's internal chunk size.

Are these changes tested?

  • clang-format --dry-run --Werror and git diff --check
  • Focused arrow-bit-utility-test --gtest_filter='TestSetBitRunReader.Iterate*' (3 tests)
  • Full arrow-bit-utility-test (217 tests) and its focused CTest entry
  • Manual validation with a standalone C++20 program that compared 3,000 randomized bitmap, offset, length, null-bitmap, and early-break cases against independent bit scans.

Are 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.

@akashchamp
akashchamp requested a review from pitrou as a code owner September 11, 2026 22:58
@github-actions

Copy link
Copy Markdown

⚠️ GitHub issue #51289 has been automatically assigned in GitHub to PR creator.

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_;
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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_;
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Same question as in BitRunIterator.


TwoSetBitRunIterator(const TwoSetBitRunIterator&) = default;

TwoSetBitRunIterator& operator=(const TwoSetBitRunIterator& other) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Is it important for this class to be copyable?

Comment on lines +600 to +602
SetBitRunIterator(const SetBitRunIterator&) = default;

SetBitRunIterator& operator=(const SetBitRunIterator& other) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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;
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

What is this testing?

@pitrou

pitrou commented Sep 14, 2026

Copy link
Copy Markdown
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.

@github-actions github-actions Bot added awaiting committer review Awaiting committer review and removed awaiting review Awaiting review labels Sep 14, 2026
@HuaHuaY
HuaHuaY self-requested a review September 14, 2026 15:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[C++] Add iterator-based variants of bit-run visitors

2 participants