You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@arrow.apache.org by ks...@apache.org on 2020/04/20 19:22:05 UTC
[arrow] 23/28: ARROW-8515: [C++] Bitmap::ToString should group by
bytes
This is an automated email from the ASF dual-hosted git repository.
kszucs pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/arrow.git
commit b5aaed894845c5cad3cf782901293a8aaee07d2c
Author: Micah Kornfield <em...@gmail.com>
AuthorDate: Mon Apr 20 11:10:36 2020 +0200
ARROW-8515: [C++] Bitmap::ToString should group by bytes
Closes #6987 from emkornfield/grouped_binary
Authored-by: Micah Kornfield <em...@gmail.com>
Signed-off-by: Antoine Pitrou <an...@python.org>
---
cpp/src/arrow/util/bit_util.cc | 4 ++--
cpp/src/arrow/util/bit_util_test.cc | 11 +++++++++++
2 files changed, 13 insertions(+), 2 deletions(-)
diff --git a/cpp/src/arrow/util/bit_util.cc b/cpp/src/arrow/util/bit_util.cc
index 15bc561..319af78 100644
--- a/cpp/src/arrow/util/bit_util.cc
+++ b/cpp/src/arrow/util/bit_util.cc
@@ -323,9 +323,9 @@ Result<std::shared_ptr<Buffer>> BitmapOp(MemoryPool* pool, const uint8_t* left,
} // namespace
std::string Bitmap::ToString() const {
- std::string out(length_, '0');
+ std::string out(length_ + ((length_ - 1) / 8), ' ');
for (int64_t i = 0; i < length_; ++i) {
- out[i] = GetBit(i) ? '1' : '0';
+ out[i + (i / 8)] = GetBit(i) ? '1' : '0';
}
return out;
}
diff --git a/cpp/src/arrow/util/bit_util_test.cc b/cpp/src/arrow/util/bit_util_test.cc
index a8e6279..40f2a33 100644
--- a/cpp/src/arrow/util/bit_util_test.cc
+++ b/cpp/src/arrow/util/bit_util_test.cc
@@ -1240,6 +1240,17 @@ TEST(Bitmap, VisitPartialWords) {
#endif // ARROW_VALGRIND
+TEST(Bitmap, ToString) {
+ uint64_t bitmap_value = 0xCAAC;
+ uint8_t* bitmap = reinterpret_cast<uint8_t*>(&bitmap_value);
+ EXPECT_EQ(Bitmap(bitmap, /*bit_offset*/ 0, /*length=*/34).ToString(),
+ "00110101 01010011 00000000 00000000 00");
+ EXPECT_EQ(Bitmap(bitmap, /*bit_offset*/ 0, /*length=*/16).ToString(),
+ "00110101 01010011");
+ EXPECT_EQ(Bitmap(bitmap, /*bit_offset*/ 0, /*length=*/11).ToString(), "00110101 010");
+ EXPECT_EQ(Bitmap(bitmap, /*bit_offset*/ 3, /*length=*/8).ToString(), "10101010");
+}
+
// compute bitwise AND of bitmaps using word-wise visit
TEST(Bitmap, VisitWordsAnd) {
constexpr int64_t nbytes = 1 << 10;