| 544 | |
| 545 | template <typename Visit> |
| 546 | inline Status VisitTwoSetBitRuns(const uint8_t* left_bitmap, int64_t left_offset, |
| 547 | const uint8_t* right_bitmap, int64_t right_offset, |
| 548 | int64_t length, Visit&& visit) { |
| 549 | if (length == 0) { |
| 550 | return Status::OK(); |
| 551 | } |
| 552 | if (left_bitmap == NULLPTR) { |
| 553 | return VisitSetBitRuns(right_bitmap, right_offset, length, |
| 554 | std::forward<Visit>(visit)); |
| 555 | } |
| 556 | if (right_bitmap == NULLPTR) { |
| 557 | return VisitSetBitRuns(left_bitmap, left_offset, length, std::forward<Visit>(visit)); |
| 558 | } |
| 559 | |
| 560 | constexpr int64_t kBitmapChunkLength = 4096; // 512 bytes of scratch space on stack |
| 561 | std::array<uint8_t, bit_util::BytesForBits(kBitmapChunkLength)> bitmap_chunk; |
| 562 | |
| 563 | int64_t offset = 0; |
| 564 | while (offset < length) { |
| 565 | const auto chunk_length = std::min(kBitmapChunkLength, length - offset); |
| 566 | BitmapAnd(left_bitmap, left_offset + offset, right_bitmap, right_offset + offset, |
| 567 | chunk_length, |
| 568 | /*out_offset=*/0, bitmap_chunk.data()); |
| 569 | |
| 570 | auto visit_with_offset = [&](int64_t position_in_chunk, int64_t run_length) { |
| 571 | return visit(position_in_chunk + offset, run_length); |
| 572 | }; |
| 573 | |
| 574 | ARROW_RETURN_NOT_OK(VisitSetBitRuns(bitmap_chunk.data(), /*offset=*/0, chunk_length, |
| 575 | std::move(visit_with_offset))); |
| 576 | offset += chunk_length; |
| 577 | } |
| 578 | return Status::OK(); |
| 579 | } |
| 580 | |
| 581 | template <typename Visit> |
| 582 | inline Status VisitTwoBitRuns(const uint8_t* left_bitmap, int64_t left_offset, |