MCPcopy Create free account
hub / github.com/apache/arrow / ReverseBlockOffsets

Function ReverseBlockOffsets

cpp/src/arrow/util/bitmap_ops.cc:257–298  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

255}
256
257void ReverseBlockOffsets(const uint8_t* data, int64_t offset, int64_t length,
258 int64_t dest_offset, uint8_t* dest) {
259 int64_t num_bytes = bit_util::BytesForBits(offset % 8 + length);
260 // Shift by its byte offset
261 data += offset / 8;
262 dest += dest_offset / 8;
263
264 int64_t j_src = num_bytes - 1;
265 int64_t i_dest = 0;
266
267 while (length > 0) {
268 uint8_t right_trailing_bits_src = (length + offset) % 8;
269 right_trailing_bits_src = !right_trailing_bits_src ? 8 : right_trailing_bits_src;
270
271 uint8_t left_trailing_bits_dest = 8 - dest_offset % 8;
272 uint8_t left_trailing_mask_dest = 0xFF << (8 - left_trailing_bits_dest);
273 if (length <= 8 && (dest_offset % 8) + length < 8) {
274 uint8_t extra_bits = static_cast<uint8_t>(8 - ((dest_offset % 8) + length));
275 left_trailing_mask_dest <<= extra_bits;
276 left_trailing_mask_dest >>= extra_bits;
277 }
278
279 uint8_t right_reversed_block;
280 if (j_src == 0) {
281 right_reversed_block = static_cast<uint8_t>(
282 GetReversedBlock(data[0], data[0], right_trailing_bits_src));
283 } else {
284 right_reversed_block = static_cast<uint8_t>(
285 GetReversedBlock(data[j_src - 1], data[j_src], right_trailing_bits_src));
286 }
287
288 dest[i_dest] &= ~left_trailing_mask_dest;
289 dest[i_dest] |=
290 (right_reversed_block << (8 - left_trailing_bits_dest)) & left_trailing_mask_dest;
291
292 dest_offset += left_trailing_bits_dest;
293 length -= left_trailing_bits_dest;
294
295 if (left_trailing_bits_dest >= right_trailing_bits_src) j_src--;
296 i_dest++;
297 }
298}
299
300template <typename Op>
301Result<std::shared_ptr<Buffer>> MapBitmapUnary(MemoryPool* pool, const uint8_t* data,

Callers 1

ReverseBitmapFunction · 0.85

Calls 2

BytesForBitsFunction · 0.85
GetReversedBlockFunction · 0.85

Tested by

no test coverage detected