pitrou commented on code in PR #50281:
URL: https://github.com/apache/arrow/pull/50281#discussion_r3529779180


##########
cpp/src/arrow/util/bit_run_reader.h:
##########
@@ -536,5 +542,79 @@ inline void VisitSetBitRunsVoid(const 
std::shared_ptr<Buffer>& bitmap, int64_t o
                       std::forward<Visit>(visit));
 }
 
+template <typename Visit>
+inline Status VisitTwoSetBitRuns(const uint8_t* left_bitmap, int64_t 
left_offset,
+                                 const uint8_t* right_bitmap, int64_t 
right_offset,
+                                 int64_t length, Visit&& visit,
+                                 MemoryPool* pool = default_memory_pool()) {
+  if (length == 0) {
+    return Status::OK();
+  }
+  if (left_bitmap == NULLPTR) {
+    return VisitSetBitRuns(right_bitmap, right_offset, length,
+                           std::forward<Visit>(visit));
+  }
+  if (right_bitmap == NULLPTR) {
+    return VisitSetBitRuns(left_bitmap, left_offset, length, 
std::forward<Visit>(visit));
+  }
+
+  ARROW_ASSIGN_OR_RAISE(auto bitmap_and,
+                        BitmapAnd(pool, left_bitmap, left_offset, right_bitmap,
+                                  right_offset, length, /*out_offset=*/0));
+  return VisitSetBitRuns(bitmap_and->data(), /*offset=*/0, length,
+                         std::forward<Visit>(visit));
+}
+
+template <typename Visit>
+inline Status VisitTwoBitRuns(const uint8_t* left_bitmap, int64_t left_offset,
+                              const uint8_t* right_bitmap, int64_t 
right_offset,
+                              int64_t length, Visit&& visit,
+                              MemoryPool* pool = default_memory_pool()) {
+  int64_t output_position = 0;
+  ARROW_RETURN_NOT_OK(VisitTwoSetBitRuns(
+      left_bitmap, left_offset, right_bitmap, right_offset, length,
+      [&](int64_t position, int64_t run_length) {
+        if (output_position < position) {
+          ARROW_RETURN_NOT_OK(visit(output_position, position - 
output_position, false));
+        }
+        ARROW_RETURN_NOT_OK(visit(position, run_length, true));
+        output_position = position + run_length;
+        return Status::OK();
+      },
+      pool));
+  if (output_position < length) {
+    return visit(output_position, length - output_position, false);
+  }
+  return Status::OK();
+}
+
+template <typename Visit>
+inline void VisitTwoBitRunsVoid(const uint8_t* left_bitmap, int64_t 
left_offset,
+                                const uint8_t* right_bitmap, int64_t 
right_offset,
+                                int64_t length, Visit&& visit,
+                                MemoryPool* pool = default_memory_pool()) {
+  ARROW_IGNORE_EXPR(VisitTwoBitRuns(

Review Comment:
   `ARROW_IGNORE_EXPR` implies that we'll ignore any failure allocating the 
temporary bitmap in `BitmapAnd`. We could instead abort but it wouldn't be much 
better.
   



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to