A single bit packed run. Consist of a view on a buffer of bytes that encode integers on ``value_bit_width`` bits (that is the numbers are small enough that high order bits are all zeros and can be omitted). A previous version of this class also stored the value bit width to be self contain, removing it and passing it explicitly when needed proved to speed up decoding up to 10 % on some benchmarks
| 153 | /// removing it and passing it explicitly when needed proved to speed up decoding up to |
| 154 | /// 10 % on some benchmarks. |
| 155 | class BitPackedRun { |
| 156 | public: |
| 157 | constexpr BitPackedRun() noexcept = default; |
| 158 | |
| 159 | constexpr BitPackedRun(const uint8_t* data, rle_size_t values_count, |
| 160 | rle_size_t value_bit_width, rle_size_t max_read_bytes) noexcept |
| 161 | : data_(data), values_count_(values_count), max_read_bytes_(max_read_bytes) { |
| 162 | ARROW_DCHECK_GE(value_bit_width, 0); |
| 163 | ARROW_DCHECK_GE(values_count_, 0); |
| 164 | ARROW_DCHECK(max_read_bytes < 0 || |
| 165 | bit_util::BytesForBits(value_bit_width * values_count) <= |
| 166 | max_read_bytes); |
| 167 | } |
| 168 | |
| 169 | constexpr rle_size_t values_count() const noexcept { return values_count_; } |
| 170 | |
| 171 | constexpr const uint8_t* raw_data_ptr() const noexcept { return data_; } |
| 172 | |
| 173 | constexpr rle_size_t raw_data_size(rle_size_t value_bit_width) const noexcept { |
| 174 | auto out = bit_util::BytesForBits(static_cast<int64_t>(value_bit_width) * |
| 175 | static_cast<int64_t>(values_count_)); |
| 176 | ARROW_DCHECK_LE(out, std::numeric_limits<rle_size_t>::max()); |
| 177 | return static_cast<rle_size_t>(out); |
| 178 | } |
| 179 | |
| 180 | /// Maximum number of bytes allowed to be read in the buffer. |
| 181 | /// This is used for unpacking operations that may need to read more bytes than they |
| 182 | /// extract for performance. |
| 183 | constexpr rle_size_t raw_data_max_size() const noexcept { return max_read_bytes_; } |
| 184 | |
| 185 | private: |
| 186 | /// The pointer to the beginning of the run |
| 187 | const uint8_t* data_ = nullptr; |
| 188 | /// Number of values in this run. |
| 189 | rle_size_t values_count_ = 0; |
| 190 | /// Not the size of the run, but the maximum number of bytes we can read in the buffer. |
| 191 | rle_size_t max_read_bytes_ = -1; |
| 192 | }; |
| 193 | |
| 194 | /// A parser that emits either a ``BitPackedRun`` or a ``RleRun``. |
| 195 | class RleBitPackedParser { |
no outgoing calls