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

Class BitPackedDecoder

cpp/src/arrow/util/rle_encoding_internal.h:579–649  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

577/// The number of values that the decoder can represent is up to 2^31 - 1.
578template <typename T>
579class BitPackedDecoder : private BitPackedRunDecoder<T> {
580 private:
581 using Base = BitPackedRunDecoder<T>;
582
583 public:
584 /// The type in which the data should be decoded.
585 using value_type = T;
586
587 using Base::Advance;
588
589 BitPackedDecoder() noexcept = default;
590
591 /// Create a decoder object.
592 ///
593 /// Unless explicitly given, then number of values is deduced from the data size,
594 /// in which case it may read more values from the input stream than the user
595 /// intended (to reach final byte alignment). This option is mandatory if the
596 /// `value_bit_width` is zero.
597 ///
598 /// @param data and data_size are the raw bytes to decode.
599 /// @param value_bit_width is the size in bits of each encoded value.
600 /// @param value_count is an optional number of values in the run.
601 BitPackedDecoder(const uint8_t* data, rle_size_t data_size, rle_size_t value_bit_width,
602 rle_size_t value_count) noexcept {
603 Reset(data, data_size, value_bit_width, value_count);
604 }
605
606 void Reset(const uint8_t* data, rle_size_t data_size, rle_size_t value_bit_width,
607 rle_size_t value_count) noexcept {
608 ARROW_DCHECK_GE(value_count, 0);
609 ARROW_DCHECK_GE(value_bit_width, 0);
610 ARROW_DCHECK_LE(value_bit_width, 64);
611
612 value_bit_width_ = value_bit_width;
613
614 ARROW_DCHECK_LE(value_count, std::numeric_limits<rle_size_t>::max());
615 const auto run = BitPackedRun{
616 /* data= */ data,
617 /* value_count= */ value_count,
618 /* value_bit_width= */ value_bit_width,
619 /* max_read_bytes= */ data_size,
620 };
621 return Base::Reset(run, value_bit_width);
622 }
623
624 /// Whether there is still values to iterate over.
625 bool exhausted() const { return Base::remaining() == 0; }
626
627 /// Advance and count the number of occurrence of a values.
628 ///
629 /// The count is limited to at most the next `batch_size` items.
630 /// @return The matching value count and number of of element that were processed.
631 RleCountUpToResult CountUpTo(value_type value, rle_size_t batch_size) {
632 return Base::CountUpTo({
633 .value = value,
634 .batch_size = batch_size,
635 .value_bit_width = value_bit_width_,
636 });

Callers 1

SetDataMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected