| 215 | |
| 216 | template <typename Op> |
| 217 | void MapBitmapUnary(const uint8_t* data, int64_t offset, int64_t length, |
| 218 | int64_t dest_offset, uint8_t* dest) { |
| 219 | const int64_t bit_offset = offset % 8; |
| 220 | const int64_t dest_bit_offset = dest_offset % 8; |
| 221 | |
| 222 | if (bit_offset || dest_bit_offset) { |
| 223 | FastMapReadersWriter<Op>({.data = dest, .offset = dest_offset}, length, |
| 224 | BitmapConstPtr{.data = data, .offset = offset}); |
| 225 | } else if (length > 0) { |
| 226 | const int64_t num_bytes = bit_util::BytesForBits(length); |
| 227 | |
| 228 | // Shift by its byte offset |
| 229 | data += offset / 8; |
| 230 | dest += dest_offset / 8; |
| 231 | |
| 232 | // Take care of the trailing bits in the last byte |
| 233 | // E.g., if trailing_bits = 5, last byte should be |
| 234 | // - low 3 bits: new bits from last byte of data buffer |
| 235 | // - high 5 bits: old bits from last byte of dest buffer |
| 236 | const int64_t trailing_bits = num_bytes * 8 - length; |
| 237 | const uint8_t trail_mask = (1U << (8 - trailing_bits)) - 1; |
| 238 | uint8_t last_data; |
| 239 | |
| 240 | if constexpr (std::is_same_v<std::decay_t<Op>, Identity>) { |
| 241 | std::memcpy(dest, data, static_cast<size_t>(num_bytes - 1)); |
| 242 | last_data = data[num_bytes - 1]; |
| 243 | } else { |
| 244 | constexpr auto op = Op{}; |
| 245 | for (int64_t i = 0; i < num_bytes - 1; i++) { |
| 246 | dest[i] = static_cast<uint8_t>(op(data[i])); |
| 247 | } |
| 248 | last_data = op(data[num_bytes - 1]); |
| 249 | } |
| 250 | |
| 251 | // Set last byte |
| 252 | dest[num_bytes - 1] &= ~trail_mask; |
| 253 | dest[num_bytes - 1] |= last_data & trail_mask; |
| 254 | } |
| 255 | } |
| 256 | |
| 257 | void ReverseBlockOffsets(const uint8_t* data, int64_t offset, int64_t length, |
| 258 | int64_t dest_offset, uint8_t* dest) { |
nothing calls this directly
no test coverage detected