File indexing completed on 2025-08-28 08:27:03
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018 #pragma once
0019
0020 #include <cstdint>
0021
0022 #include "arrow/util/bit_util.h"
0023 #include "arrow/util/bitmap_reader.h"
0024
0025 namespace arrow {
0026 namespace internal {
0027
0028
0029
0030
0031 template <class Visitor>
0032 void VisitBits(const uint8_t* bitmap, int64_t start_offset, int64_t length,
0033 Visitor&& visit) {
0034 BitmapReader reader(bitmap, start_offset, length);
0035 for (int64_t index = 0; index < length; ++index) {
0036 visit(reader.IsSet());
0037 reader.Next();
0038 }
0039 }
0040
0041
0042 template <class Visitor>
0043 void VisitBitsUnrolled(const uint8_t* bitmap, int64_t start_offset, int64_t length,
0044 Visitor&& visit) {
0045 if (length == 0) {
0046 return;
0047 }
0048
0049
0050 int64_t num_bits_before_full_bytes =
0051 bit_util::RoundUpToMultipleOf8(start_offset) - start_offset;
0052
0053 if (num_bits_before_full_bytes > length) {
0054 num_bits_before_full_bytes = length;
0055 }
0056
0057 VisitBits<Visitor>(bitmap, start_offset, num_bits_before_full_bytes, visit);
0058
0059
0060
0061 const uint8_t* first_full_byte = bitmap + bit_util::CeilDiv(start_offset, 8);
0062 const int64_t num_full_bytes = (length - num_bits_before_full_bytes) / 8;
0063
0064
0065
0066 for (int64_t byte_index = 0; byte_index < num_full_bytes; ++byte_index) {
0067
0068 const uint8_t byte = *(first_full_byte + byte_index);
0069
0070
0071 visit(bit_util::GetBitFromByte(byte, 0));
0072 visit(bit_util::GetBitFromByte(byte, 1));
0073 visit(bit_util::GetBitFromByte(byte, 2));
0074 visit(bit_util::GetBitFromByte(byte, 3));
0075 visit(bit_util::GetBitFromByte(byte, 4));
0076 visit(bit_util::GetBitFromByte(byte, 5));
0077 visit(bit_util::GetBitFromByte(byte, 6));
0078 visit(bit_util::GetBitFromByte(byte, 7));
0079 }
0080
0081
0082 const int64_t num_bits_after_full_bytes = (length - num_bits_before_full_bytes) % 8;
0083 VisitBits<Visitor>(first_full_byte + num_full_bytes, 0, num_bits_after_full_bytes,
0084 visit);
0085 }
0086
0087 }
0088 }