Skip to content

Commit 428bf0e

Browse files
Add bitmap converter function
1 parent 7267ff1 commit 428bf0e

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

libtiledbsoma/src/soma/column_buffer.cc

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,22 @@ void ColumnBuffer::to_bitmap(std::span<uint8_t> bytemap) {
3838
}
3939
}
4040

41+
void ColumnBuffer::to_bitmap(std::span<const uint8_t> bytemap, std::span<uint8_t> bitmap) {
42+
size_t i_dst = 0;
43+
for (size_t i_src = 0; i_src < bytemap.size(); ++i_src) {
44+
// Overwrite every 8 bytes with a one-byte bitmap
45+
if (i_src % 8 == 0) {
46+
// Each bit in the bitmap corresponds to one byte in the bytemap
47+
// Note: the bitmap must be byte-aligned (8 bits)
48+
bitmap[i_dst] = 0;
49+
for (size_t i = i_src; i < i_src + 8 && i < bytemap.size(); i++) {
50+
bitmap[i_dst] |= bytemap[i] << (i % 8);
51+
}
52+
++i_dst;
53+
}
54+
}
55+
}
56+
4157
#pragma endregion
4258

4359
#pragma region public non-static

libtiledbsoma/src/soma/column_buffer.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,12 @@ class ColumnBuffer {
3939
*/
4040
static void to_bitmap(std::span<uint8_t> bytemap);
4141

42+
/**
43+
* @brief Convert a bytemap to a bitmap.
44+
*
45+
*/
46+
static void to_bitmap(std::span<const uint8_t> bytemap, std::span<uint8_t> bitmap);
47+
4248
ColumnBuffer(
4349
std::string_view name,
4450
tiledb_datatype_t type,
@@ -367,6 +373,10 @@ class ReadColumnBuffer : public ColumnBuffer {
367373
ColumnBuffer::to_bitmap(validity());
368374
}
369375

376+
void validity_to_bitmap(std::span<uint8_t> bitmap) const {
377+
ColumnBuffer::to_bitmap(validity(), bitmap);
378+
}
379+
370380
using ColumnBuffer::data;
371381
using ColumnBuffer::offsets;
372382
using ColumnBuffer::validity;

0 commit comments

Comments
 (0)