From ae26a844d60b077501ae5b00c656eb8b755690be Mon Sep 17 00:00:00 2001 From: Micah Kornfield Date: Mon, 4 Feb 2019 23:40:28 -0800 Subject: [PATCH 1/5] Expose no allocating bit utilities --- cpp/src/arrow/util/bit-util-test.cc | 48 +++++++++++++++++++++++++++++ cpp/src/arrow/util/bit-util.cc | 45 ++++++++++++++++++++++----- cpp/src/arrow/util/bit-util.h | 42 +++++++++++++++++++++++++ 3 files changed, 128 insertions(+), 7 deletions(-) diff --git a/cpp/src/arrow/util/bit-util-test.cc b/cpp/src/arrow/util/bit-util-test.cc index 93feb5b35c60..90a0f11b9e93 100644 --- a/cpp/src/arrow/util/bit-util-test.cc +++ b/cpp/src/arrow/util/bit-util-test.cc @@ -379,6 +379,10 @@ struct BitmapOperation { const uint8_t* right, int64_t right_offset, int64_t length, int64_t out_offset, std::shared_ptr* out_buffer) const = 0; + virtual Status Call(const uint8_t* left, int64_t left_offset, + const uint8_t* right, int64_t right_offset, int64_t length, + int64_t out_offset, uint8_t* out_buffer) const = 0; + virtual ~BitmapOperation() = default; }; @@ -389,6 +393,14 @@ struct BitmapAndOp : public BitmapOperation { return BitmapAnd(pool, left, left_offset, right, right_offset, length, out_offset, out_buffer); } + + Status Call(const uint8_t* left, int64_t left_offset, + const uint8_t* right, int64_t right_offset, int64_t length, + int64_t out_offset, uint8_t* out_buffer) const override { + return BitmapAnd(left, left_offset, right, right_offset, length, out_offset, + out_buffer); + } + }; struct BitmapOrOp : public BitmapOperation { @@ -398,6 +410,14 @@ struct BitmapOrOp : public BitmapOperation { return BitmapOr(pool, left, left_offset, right, right_offset, length, out_offset, out_buffer); } + + Status Call(const uint8_t* left, int64_t left_offset, + const uint8_t* right, int64_t right_offset, int64_t length, + int64_t out_offset, uint8_t* out_buffer) const override { + return BitmapOr(left, left_offset, right, right_offset, length, out_offset, + out_buffer); + } + }; struct BitmapXorOp : public BitmapOperation { @@ -407,6 +427,13 @@ struct BitmapXorOp : public BitmapOperation { return BitmapXor(pool, left, left_offset, right, right_offset, length, out_offset, out_buffer); } + + Status Call(const uint8_t* left, int64_t left_offset, + const uint8_t* right, int64_t right_offset, int64_t length, + int64_t out_offset, uint8_t* out_buffer) const override { + return BitmapXor(left, left_offset, right, right_offset, length, out_offset, + out_buffer); + } }; class BitmapOp : public TestBase { @@ -427,6 +454,17 @@ class BitmapOp : public TestBase { &out)); auto reader = internal::BitmapReader(out->mutable_data(), out_offset, length); ASSERT_READER_VALUES(reader, result_bits); + + // Clear out buffer and try non-allocating version + for (int x = out_offset; x < out->length; x++) { + out->mutable_buffer()[x] = 0; + } + op.Call(left->mutable_data(), left_offset, + right->mutable_data(), right_offset, length, out_offset, + out->mutable_buffer()); + auto reader = internal::BitmapReader(out->mutable_data(), out_offset, length); + ASSERT_READER_VALUES(reader, result_bits); + } } } @@ -451,6 +489,16 @@ class BitmapOp : public TestBase { &out)); auto reader = internal::BitmapReader(out->mutable_data(), out_offset, length); ASSERT_READER_VALUES(reader, result_bits); + + // Clear out buffer and try non-allocating version + for (int x = 0; x < out->length; x++) { + out->mutable_buffer()[x] = 0; + } + op.Call(left->mutable_data(), left_offset, + right->mutable_data(), right_offset, length, out_offset, + out->mutable_buffer()); + auto reader = internal::BitmapReader(out->mutable_data(), out_offset, length); + ASSERT_READER_VALUES(reader, result_bits); } } } diff --git a/cpp/src/arrow/util/bit-util.cc b/cpp/src/arrow/util/bit-util.cc index 862b1fd050bc..f4083714372a 100644 --- a/cpp/src/arrow/util/bit-util.cc +++ b/cpp/src/arrow/util/bit-util.cc @@ -296,21 +296,30 @@ void UnalignedBitmapOp(const uint8_t* left, int64_t left_offset, const uint8_t* } template -Status BitmapOp(MemoryPool* pool, const uint8_t* left, int64_t left_offset, +void BitmapOp(const uint8_t* left, int64_t left_offset, const uint8_t* right, int64_t right_offset, int64_t length, - int64_t out_offset, std::shared_ptr* out_buffer) { + int64_t out_offset, uint8_t* dest) { if ((out_offset % 8 == left_offset % 8) && (out_offset % 8 == right_offset % 8)) { // Fast case: can use bytewise AND - const int64_t phys_bits = length + out_offset; - RETURN_NOT_OK(AllocateEmptyBitmap(pool, phys_bits, out_buffer)); AlignedBitmapOp(left, left_offset, right, right_offset, - (*out_buffer)->mutable_data(), out_offset, length); + dest, out_offset, length); } else { // Unaligned - RETURN_NOT_OK(AllocateEmptyBitmap(pool, length + out_offset, out_buffer)); UnalignedBitmapOp(left, left_offset, right, right_offset, - (*out_buffer)->mutable_data(), out_offset, length); + dest, out_offset, length); } +} + + +template +Status BitmapOp(MemoryPool* pool, const uint8_t* left, int64_t left_offset, + const uint8_t* right, int64_t right_offset, int64_t length, + int64_t out_offset, std::shared_ptr* out_buffer) { + + const int64_t phys_bits = length + out_offset; + RETURN_NOT_OK(AllocateEmptyBitmap(pool, phys_bits, out_buffer)); + uint8_t* out = (*out_buffer)->mutable_data(); + BitmapOp(left, left_offset, right, right_offset, length, out_offset, out); return Status::OK(); } @@ -337,5 +346,27 @@ Status BitmapXor(MemoryPool* pool, const uint8_t* left, int64_t left_offset, pool, left, left_offset, right, right_offset, length, out_offset, out_buffer); } +void BitmapAnd(const uint8_t* left, int64_t left_offset, + const uint8_t* right, int64_t right_offset, int64_t length, + int64_t out_offset, uint8_t* out) { + BitmapOp, std::logical_and>( + left, left_offset, right, right_offset, length, out_offset, out); +} + +void BitmapOr(const uint8_t* left, int64_t left_offset, + const uint8_t* right, int64_t right_offset, int64_t length, + int64_t out_offset, uint8_t* out) { + BitmapOp, std::logical_or>( + left, left_offset, right, right_offset, length, out_offset, out); +} + +void BitmapXor(const uint8_t* left, int64_t left_offset, + const uint8_t* right, int64_t right_offset, int64_t length, + int64_t out_offset, uint8_t* out) { + BitmapOp, std::bit_xor>( + left, left_offset, right, right_offset, length, out_offset, out); +} + + } // namespace internal } // namespace arrow diff --git a/cpp/src/arrow/util/bit-util.h b/cpp/src/arrow/util/bit-util.h index 0e4a8640b141..95a3dacd50c2 100644 --- a/cpp/src/arrow/util/bit-util.h +++ b/cpp/src/arrow/util/bit-util.h @@ -743,16 +743,58 @@ Status BitmapAnd(MemoryPool* pool, const uint8_t* left, int64_t left_offset, const uint8_t* right, int64_t right_offset, int64_t length, int64_t out_offset, std::shared_ptr* out_buffer); +/// \brief Do a "bitmap and" on right and left buffers starting at +/// their respective bit-offsets for the given bit-length and put +/// the results in out starting at the given bit-offset. +/// out_buffer will be allocated and initialized to zeros using pool before +/// the operation. +ARROW_EXPORT +void BitmapAnd(const uint8_t* left, int64_t left_offset, + const uint8_t* right, int64_t right_offset, int64_t length, + int64_t out_offset, uint8_t* out); + +/// \brief Do a "bitmap or" for the given bit length on right and left buffers +/// starting at their respective bit-offsets and put the results in out +/// starting at the given bit-offset. +/// +/// out_buffer will be allocated and initialized to zeros using pool before +/// the operation. ARROW_EXPORT Status BitmapOr(MemoryPool* pool, const uint8_t* left, int64_t left_offset, const uint8_t* right, int64_t right_offset, int64_t length, int64_t out_offset, std::shared_ptr* out_buffer); +/// \brief Do a "bitmap or" for the given bit length on right and left buffers +/// starting at their respective bit-offsets and put the results in out +/// starting at the given bit-offset. +ARROW_EXPORT +void BitmapOr(const uint8_t* left, int64_t left_offset, + const uint8_t* right, int64_t right_offset, int64_t length, + int64_t out_offset, uint8_t* out_buffer); + + +/// \brief Do a "bitmap xor" for the given bit-length on right and left +/// buffers starting at their respective bit-offsets and put the results in +/// out_buffer starting at the given bit offset. +/// +/// +/// out_buffer will be allocated and initialized to zeros using pool before +/// the operation. ARROW_EXPORT Status BitmapXor(MemoryPool* pool, const uint8_t* left, int64_t left_offset, const uint8_t* right, int64_t right_offset, int64_t length, int64_t out_offset, std::shared_ptr* out_buffer); + +/// \brief Do a "bitmap xor" for the given bit-length on right and left +/// buffers starting at their respective bit-offsets and put the results in +/// out starting at the given bit offset. +ARROW_EXPORT +void BitmapXor(const uint8_t* left, int64_t left_offset, + const uint8_t* right, int64_t right_offset, int64_t length, + int64_t out_offset, uint8_t* out); + + } // namespace internal } // namespace arrow From f4661fe769471aae792b1ea79a80280de361da8e Mon Sep 17 00:00:00 2001 From: Micah Kornfield Date: Mon, 4 Feb 2019 23:52:50 -0800 Subject: [PATCH 2/5] fixups --- cpp/src/arrow/util/bit-util-test.cc | 67 +++++++++++++---------------- cpp/src/arrow/util/bit-util.cc | 34 ++++++--------- cpp/src/arrow/util/bit-util.h | 23 ++++------ 3 files changed, 54 insertions(+), 70 deletions(-) diff --git a/cpp/src/arrow/util/bit-util-test.cc b/cpp/src/arrow/util/bit-util-test.cc index 90a0f11b9e93..9bc39318e76d 100644 --- a/cpp/src/arrow/util/bit-util-test.cc +++ b/cpp/src/arrow/util/bit-util-test.cc @@ -379,9 +379,9 @@ struct BitmapOperation { const uint8_t* right, int64_t right_offset, int64_t length, int64_t out_offset, std::shared_ptr* out_buffer) const = 0; - virtual Status Call(const uint8_t* left, int64_t left_offset, - const uint8_t* right, int64_t right_offset, int64_t length, - int64_t out_offset, uint8_t* out_buffer) const = 0; + virtual Status Call(const uint8_t* left, int64_t left_offset, const uint8_t* right, + int64_t right_offset, int64_t length, int64_t out_offset, + uint8_t* out_buffer) const = 0; virtual ~BitmapOperation() = default; }; @@ -394,13 +394,12 @@ struct BitmapAndOp : public BitmapOperation { out_buffer); } - Status Call(const uint8_t* left, int64_t left_offset, - const uint8_t* right, int64_t right_offset, int64_t length, - int64_t out_offset, uint8_t* out_buffer) const override { - return BitmapAnd(left, left_offset, right, right_offset, length, out_offset, - out_buffer); + Status Call(const uint8_t* left, int64_t left_offset, const uint8_t* right, + int64_t right_offset, int64_t length, int64_t out_offset, + uint8_t* out_buffer) const override { + BitmapAnd(left, left_offset, right, right_offset, length, out_offset, out_buffer); + return Status::OK(); } - }; struct BitmapOrOp : public BitmapOperation { @@ -411,13 +410,12 @@ struct BitmapOrOp : public BitmapOperation { out_buffer); } - Status Call(const uint8_t* left, int64_t left_offset, - const uint8_t* right, int64_t right_offset, int64_t length, - int64_t out_offset, uint8_t* out_buffer) const override { - return BitmapOr(left, left_offset, right, right_offset, length, out_offset, - out_buffer); + Status Call(const uint8_t* left, int64_t left_offset, const uint8_t* right, + int64_t right_offset, int64_t length, int64_t out_offset, + uint8_t* out_buffer) const override { + BitmapOr(left, left_offset, right, right_offset, length, out_offset, out_buffer); + return Status::OK(); } - }; struct BitmapXorOp : public BitmapOperation { @@ -428,11 +426,11 @@ struct BitmapXorOp : public BitmapOperation { out_buffer); } - Status Call(const uint8_t* left, int64_t left_offset, - const uint8_t* right, int64_t right_offset, int64_t length, - int64_t out_offset, uint8_t* out_buffer) const override { - return BitmapXor(left, left_offset, right, right_offset, length, out_offset, - out_buffer); + Status Call(const uint8_t* left, int64_t left_offset, const uint8_t* right, + int64_t right_offset, int64_t length, int64_t out_offset, + uint8_t* out_buffer) const override { + BitmapXor(left, left_offset, right, right_offset, length, out_offset, out_buffer); + return Status::OK(); } }; @@ -456,15 +454,13 @@ class BitmapOp : public TestBase { ASSERT_READER_VALUES(reader, result_bits); // Clear out buffer and try non-allocating version - for (int x = out_offset; x < out->length; x++) { - out->mutable_buffer()[x] = 0; - } - op.Call(left->mutable_data(), left_offset, - right->mutable_data(), right_offset, length, out_offset, - out->mutable_buffer()); - auto reader = internal::BitmapReader(out->mutable_data(), out_offset, length); + for (int64_t x = out_offset; x < out->size(); x++) { + out->mutable_data()[x] = 0; + } + op.Call(left->mutable_data(), left_offset, right->mutable_data(), right_offset, + length, out_offset, out->mutable_data()); + reader = internal::BitmapReader(out->mutable_data(), out_offset, length); ASSERT_READER_VALUES(reader, result_bits); - } } } @@ -490,14 +486,13 @@ class BitmapOp : public TestBase { auto reader = internal::BitmapReader(out->mutable_data(), out_offset, length); ASSERT_READER_VALUES(reader, result_bits); - // Clear out buffer and try non-allocating version - for (int x = 0; x < out->length; x++) { - out->mutable_buffer()[x] = 0; - } - op.Call(left->mutable_data(), left_offset, - right->mutable_data(), right_offset, length, out_offset, - out->mutable_buffer()); - auto reader = internal::BitmapReader(out->mutable_data(), out_offset, length); + // Clear out buffer and try non-allocating version + for (int x = 0; x < out->size(); x++) { + out->mutable_data()[x] = 0; + } + op.Call(left->mutable_data(), left_offset, right->mutable_data(), right_offset, + length, out_offset, out->mutable_data()); + reader = internal::BitmapReader(out->mutable_data(), out_offset, length); ASSERT_READER_VALUES(reader, result_bits); } } diff --git a/cpp/src/arrow/util/bit-util.cc b/cpp/src/arrow/util/bit-util.cc index f4083714372a..6da57a9049ad 100644 --- a/cpp/src/arrow/util/bit-util.cc +++ b/cpp/src/arrow/util/bit-util.cc @@ -296,30 +296,28 @@ void UnalignedBitmapOp(const uint8_t* left, int64_t left_offset, const uint8_t* } template -void BitmapOp(const uint8_t* left, int64_t left_offset, - const uint8_t* right, int64_t right_offset, int64_t length, - int64_t out_offset, uint8_t* dest) { +void BitmapOp(const uint8_t* left, int64_t left_offset, const uint8_t* right, + int64_t right_offset, int64_t length, int64_t out_offset, uint8_t* dest) { if ((out_offset % 8 == left_offset % 8) && (out_offset % 8 == right_offset % 8)) { // Fast case: can use bytewise AND - AlignedBitmapOp(left, left_offset, right, right_offset, - dest, out_offset, length); + AlignedBitmapOp(left, left_offset, right, right_offset, dest, out_offset, + length); } else { // Unaligned - UnalignedBitmapOp(left, left_offset, right, right_offset, - dest, out_offset, length); + UnalignedBitmapOp(left, left_offset, right, right_offset, dest, out_offset, + length); } } - template Status BitmapOp(MemoryPool* pool, const uint8_t* left, int64_t left_offset, const uint8_t* right, int64_t right_offset, int64_t length, int64_t out_offset, std::shared_ptr* out_buffer) { - const int64_t phys_bits = length + out_offset; RETURN_NOT_OK(AllocateEmptyBitmap(pool, phys_bits, out_buffer)); uint8_t* out = (*out_buffer)->mutable_data(); - BitmapOp(left, left_offset, right, right_offset, length, out_offset, out); + BitmapOp(left, left_offset, right, right_offset, length, out_offset, + out); return Status::OK(); } @@ -346,27 +344,23 @@ Status BitmapXor(MemoryPool* pool, const uint8_t* left, int64_t left_offset, pool, left, left_offset, right, right_offset, length, out_offset, out_buffer); } -void BitmapAnd(const uint8_t* left, int64_t left_offset, - const uint8_t* right, int64_t right_offset, int64_t length, - int64_t out_offset, uint8_t* out) { +void BitmapAnd(const uint8_t* left, int64_t left_offset, const uint8_t* right, + int64_t right_offset, int64_t length, int64_t out_offset, uint8_t* out) { BitmapOp, std::logical_and>( left, left_offset, right, right_offset, length, out_offset, out); } -void BitmapOr(const uint8_t* left, int64_t left_offset, - const uint8_t* right, int64_t right_offset, int64_t length, - int64_t out_offset, uint8_t* out) { +void BitmapOr(const uint8_t* left, int64_t left_offset, const uint8_t* right, + int64_t right_offset, int64_t length, int64_t out_offset, uint8_t* out) { BitmapOp, std::logical_or>( left, left_offset, right, right_offset, length, out_offset, out); } -void BitmapXor(const uint8_t* left, int64_t left_offset, - const uint8_t* right, int64_t right_offset, int64_t length, - int64_t out_offset, uint8_t* out) { +void BitmapXor(const uint8_t* left, int64_t left_offset, const uint8_t* right, + int64_t right_offset, int64_t length, int64_t out_offset, uint8_t* out) { BitmapOp, std::bit_xor>( left, left_offset, right, right_offset, length, out_offset, out); } - } // namespace internal } // namespace arrow diff --git a/cpp/src/arrow/util/bit-util.h b/cpp/src/arrow/util/bit-util.h index 95a3dacd50c2..8eb10f51c807 100644 --- a/cpp/src/arrow/util/bit-util.h +++ b/cpp/src/arrow/util/bit-util.h @@ -749,9 +749,8 @@ Status BitmapAnd(MemoryPool* pool, const uint8_t* left, int64_t left_offset, /// out_buffer will be allocated and initialized to zeros using pool before /// the operation. ARROW_EXPORT -void BitmapAnd(const uint8_t* left, int64_t left_offset, - const uint8_t* right, int64_t right_offset, int64_t length, - int64_t out_offset, uint8_t* out); +void BitmapAnd(const uint8_t* left, int64_t left_offset, const uint8_t* right, + int64_t right_offset, int64_t length, int64_t out_offset, uint8_t* out); /// \brief Do a "bitmap or" for the given bit length on right and left buffers /// starting at their respective bit-offsets and put the results in out @@ -768,15 +767,14 @@ Status BitmapOr(MemoryPool* pool, const uint8_t* left, int64_t left_offset, /// starting at their respective bit-offsets and put the results in out /// starting at the given bit-offset. ARROW_EXPORT -void BitmapOr(const uint8_t* left, int64_t left_offset, - const uint8_t* right, int64_t right_offset, int64_t length, - int64_t out_offset, uint8_t* out_buffer); - +void BitmapOr(const uint8_t* left, int64_t left_offset, const uint8_t* right, + int64_t right_offset, int64_t length, int64_t out_offset, + uint8_t* out_buffer); /// \brief Do a "bitmap xor" for the given bit-length on right and left /// buffers starting at their respective bit-offsets and put the results in -/// out_buffer starting at the given bit offset. -/// +/// out_buffer starting at the given bit offset. +/// /// /// out_buffer will be allocated and initialized to zeros using pool before /// the operation. @@ -785,15 +783,12 @@ Status BitmapXor(MemoryPool* pool, const uint8_t* left, int64_t left_offset, const uint8_t* right, int64_t right_offset, int64_t length, int64_t out_offset, std::shared_ptr* out_buffer); - /// \brief Do a "bitmap xor" for the given bit-length on right and left /// buffers starting at their respective bit-offsets and put the results in /// out starting at the given bit offset. ARROW_EXPORT -void BitmapXor(const uint8_t* left, int64_t left_offset, - const uint8_t* right, int64_t right_offset, int64_t length, - int64_t out_offset, uint8_t* out); - +void BitmapXor(const uint8_t* left, int64_t left_offset, const uint8_t* right, + int64_t right_offset, int64_t length, int64_t out_offset, uint8_t* out); } // namespace internal } // namespace arrow From 73f89aaabc6dc05cfaf9008786a4ad2768fabbaf Mon Sep 17 00:00:00 2001 From: Micah Kornfield Date: Mon, 4 Feb 2019 23:54:25 -0800 Subject: [PATCH 3/5] fixup method order --- cpp/src/arrow/util/bit-util.cc | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/cpp/src/arrow/util/bit-util.cc b/cpp/src/arrow/util/bit-util.cc index 6da57a9049ad..2e7bf2f03d58 100644 --- a/cpp/src/arrow/util/bit-util.cc +++ b/cpp/src/arrow/util/bit-util.cc @@ -330,6 +330,12 @@ Status BitmapAnd(MemoryPool* pool, const uint8_t* left, int64_t left_offset, pool, left, left_offset, right, right_offset, length, out_offset, out_buffer); } +void BitmapAnd(const uint8_t* left, int64_t left_offset, const uint8_t* right, + int64_t right_offset, int64_t length, int64_t out_offset, uint8_t* out) { + BitmapOp, std::logical_and>( + left, left_offset, right, right_offset, length, out_offset, out); +} + Status BitmapOr(MemoryPool* pool, const uint8_t* left, int64_t left_offset, const uint8_t* right, int64_t right_offset, int64_t length, int64_t out_offset, std::shared_ptr* out_buffer) { @@ -337,6 +343,12 @@ Status BitmapOr(MemoryPool* pool, const uint8_t* left, int64_t left_offset, pool, left, left_offset, right, right_offset, length, out_offset, out_buffer); } +void BitmapOr(const uint8_t* left, int64_t left_offset, const uint8_t* right, + int64_t right_offset, int64_t length, int64_t out_offset, uint8_t* out) { + BitmapOp, std::logical_or>( + left, left_offset, right, right_offset, length, out_offset, out); +} + Status BitmapXor(MemoryPool* pool, const uint8_t* left, int64_t left_offset, const uint8_t* right, int64_t right_offset, int64_t length, int64_t out_offset, std::shared_ptr* out_buffer) { @@ -344,18 +356,6 @@ Status BitmapXor(MemoryPool* pool, const uint8_t* left, int64_t left_offset, pool, left, left_offset, right, right_offset, length, out_offset, out_buffer); } -void BitmapAnd(const uint8_t* left, int64_t left_offset, const uint8_t* right, - int64_t right_offset, int64_t length, int64_t out_offset, uint8_t* out) { - BitmapOp, std::logical_and>( - left, left_offset, right, right_offset, length, out_offset, out); -} - -void BitmapOr(const uint8_t* left, int64_t left_offset, const uint8_t* right, - int64_t right_offset, int64_t length, int64_t out_offset, uint8_t* out) { - BitmapOp, std::logical_or>( - left, left_offset, right, right_offset, length, out_offset, out); -} - void BitmapXor(const uint8_t* left, int64_t left_offset, const uint8_t* right, int64_t right_offset, int64_t length, int64_t out_offset, uint8_t* out) { BitmapOp, std::bit_xor>( From f824521c31c62aedd59cb5ec6928fb57606ed963 Mon Sep 17 00:00:00 2001 From: Micah Kornfield Date: Tue, 5 Feb 2019 20:57:17 -0800 Subject: [PATCH 4/5] address review comments --- cpp/src/arrow/util/bit-util-test.cc | 16 ++++++---------- cpp/src/arrow/util/bit-util.h | 13 ++++++++----- 2 files changed, 14 insertions(+), 15 deletions(-) diff --git a/cpp/src/arrow/util/bit-util-test.cc b/cpp/src/arrow/util/bit-util-test.cc index 9bc39318e76d..71585cd86f86 100644 --- a/cpp/src/arrow/util/bit-util-test.cc +++ b/cpp/src/arrow/util/bit-util-test.cc @@ -454,11 +454,9 @@ class BitmapOp : public TestBase { ASSERT_READER_VALUES(reader, result_bits); // Clear out buffer and try non-allocating version - for (int64_t x = out_offset; x < out->size(); x++) { - out->mutable_data()[x] = 0; - } - op.Call(left->mutable_data(), left_offset, right->mutable_data(), right_offset, - length, out_offset, out->mutable_data()); + std::memset(out->mutable_data(), 0, out->size()); + ASSERT_OK(op.Call(left->mutable_data(), left_offset, right->mutable_data(), + right_offset, length, out_offset, out->mutable_data())); reader = internal::BitmapReader(out->mutable_data(), out_offset, length); ASSERT_READER_VALUES(reader, result_bits); } @@ -487,11 +485,9 @@ class BitmapOp : public TestBase { ASSERT_READER_VALUES(reader, result_bits); // Clear out buffer and try non-allocating version - for (int x = 0; x < out->size(); x++) { - out->mutable_data()[x] = 0; - } - op.Call(left->mutable_data(), left_offset, right->mutable_data(), right_offset, - length, out_offset, out->mutable_data()); + std::memset(out->mutable_data(), 0, out->size()); + ASSERT_OK(op.Call(left->mutable_data(), left_offset, right->mutable_data(), + right_offset, length, out_offset, out->mutable_data())); reader = internal::BitmapReader(out->mutable_data(), out_offset, length); ASSERT_READER_VALUES(reader, result_bits); } diff --git a/cpp/src/arrow/util/bit-util.h b/cpp/src/arrow/util/bit-util.h index 8eb10f51c807..23e741d7fb10 100644 --- a/cpp/src/arrow/util/bit-util.h +++ b/cpp/src/arrow/util/bit-util.h @@ -738,6 +738,12 @@ ARROW_EXPORT bool BitmapEquals(const uint8_t* left, int64_t left_offset, const uint8_t* right, int64_t right_offset, int64_t bit_length); +/// \brief Do a "bitmap and" on right and left buffers starting at +/// their respective bit-offsets for the given bit-length and put +/// the results in out_buffer starting at the given bit-offset. +/// +/// out_buffer will be allocated and initialized to zeros using pool before +/// the operation. ARROW_EXPORT Status BitmapAnd(MemoryPool* pool, const uint8_t* left, int64_t left_offset, const uint8_t* right, int64_t right_offset, int64_t length, @@ -746,14 +752,12 @@ Status BitmapAnd(MemoryPool* pool, const uint8_t* left, int64_t left_offset, /// \brief Do a "bitmap and" on right and left buffers starting at /// their respective bit-offsets for the given bit-length and put /// the results in out starting at the given bit-offset. -/// out_buffer will be allocated and initialized to zeros using pool before -/// the operation. ARROW_EXPORT void BitmapAnd(const uint8_t* left, int64_t left_offset, const uint8_t* right, int64_t right_offset, int64_t length, int64_t out_offset, uint8_t* out); /// \brief Do a "bitmap or" for the given bit length on right and left buffers -/// starting at their respective bit-offsets and put the results in out +/// starting at their respective bit-offsets and put the results in out_buffer /// starting at the given bit-offset. /// /// out_buffer will be allocated and initialized to zeros using pool before @@ -769,13 +773,12 @@ Status BitmapOr(MemoryPool* pool, const uint8_t* left, int64_t left_offset, ARROW_EXPORT void BitmapOr(const uint8_t* left, int64_t left_offset, const uint8_t* right, int64_t right_offset, int64_t length, int64_t out_offset, - uint8_t* out_buffer); + uint8_t* out); /// \brief Do a "bitmap xor" for the given bit-length on right and left /// buffers starting at their respective bit-offsets and put the results in /// out_buffer starting at the given bit offset. /// -/// /// out_buffer will be allocated and initialized to zeros using pool before /// the operation. ARROW_EXPORT From 08107f04e10e50740c6c34ccab474a5607dda1ee Mon Sep 17 00:00:00 2001 From: Micah Kornfield Date: Tue, 5 Feb 2019 21:49:00 -0800 Subject: [PATCH 5/5] fix format --- cpp/src/arrow/util/bit-util.h | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/cpp/src/arrow/util/bit-util.h b/cpp/src/arrow/util/bit-util.h index 23e741d7fb10..888b79d794e8 100644 --- a/cpp/src/arrow/util/bit-util.h +++ b/cpp/src/arrow/util/bit-util.h @@ -772,8 +772,7 @@ Status BitmapOr(MemoryPool* pool, const uint8_t* left, int64_t left_offset, /// starting at the given bit-offset. ARROW_EXPORT void BitmapOr(const uint8_t* left, int64_t left_offset, const uint8_t* right, - int64_t right_offset, int64_t length, int64_t out_offset, - uint8_t* out); + int64_t right_offset, int64_t length, int64_t out_offset, uint8_t* out); /// \brief Do a "bitmap xor" for the given bit-length on right and left /// buffers starting at their respective bit-offsets and put the results in