Advance and count the number of occurrence of a values. The count is limited to at most the next `batch_size` items. @return The matching value count and number of of element that were processed.
| 389 | /// The count is limited to at most the next `batch_size` items. |
| 390 | /// @return The matching value count and number of of element that were processed. |
| 391 | RleCountUpToResult CountUpTo(const RleCountUpToParams<value_type>& p) { |
| 392 | // Decoding in a stack buffer of 512 values: 1KB for int16_t used in levels |
| 393 | // and up to 4KB for uint64_t. |
| 394 | constexpr rle_size_t kBufferValueCount = 512; |
| 395 | alignas(16) value_type buffer[kBufferValueCount]; // uninitialized |
| 396 | |
| 397 | rle_size_t remaining = p.batch_size; |
| 398 | rle_size_t count = 0; |
| 399 | rle_size_t read_iter = 0; |
| 400 | do { |
| 401 | const auto batch_iter = std::min(remaining, kBufferValueCount); |
| 402 | read_iter = GetBatch(buffer, batch_iter, p.value_bit_width); |
| 403 | count += static_cast<rle_size_t>(std::count(buffer, buffer + read_iter, p.value)); |
| 404 | remaining -= read_iter; |
| 405 | } while (remaining > 0 && read_iter > 0); |
| 406 | |
| 407 | return {.matching_count = count, .processed_count = p.batch_size - remaining}; |
| 408 | } |
| 409 | |
| 410 | /// Get the next value and return false if there are no more. |
| 411 | [[nodiscard]] constexpr bool Get(value_type* out_value, rle_size_t value_bit_width) { |