#include <folly/Portability.h>
#include <folly/Range.h>
#include <folly/experimental/Bits.h>
+#include <folly/experimental/CodingDetail.h>
#include <folly/experimental/Instructions.h>
#include <folly/experimental/Select64.h>
#include <glog/logging.h>
size_t forwardPointers = 0;
};
-template <class Encoder,
- class Instructions = instructions::Default,
- bool kUnchecked = false>
-class BitVectorReader {
+template <
+ class Encoder,
+ class Instructions = instructions::Default,
+ bool kUnchecked = false>
+class BitVectorReader : detail::ForwardPointers<Encoder::forwardQuantum>,
+ detail::SkipPointers<Encoder::skipQuantum> {
public:
typedef Encoder EncoderType;
typedef typename Encoder::ValueType ValueType;
+ // A bitvector can only be as large as its largest value.
+ typedef typename Encoder::ValueType SizeType;
typedef typename Encoder::SkipValueType SkipValueType;
explicit BitVectorReader(const typename Encoder::CompressedList& list)
- : size_(list.size),
+ : detail::ForwardPointers<Encoder::forwardQuantum>(list.forwardPointers),
+ detail::SkipPointers<Encoder::skipQuantum>(list.skipPointers),
bits_(list.bits),
- skipPointers_(list.skipPointers),
- forwardPointers_(list.forwardPointers) {
+ size_(list.size) {
reset();
if (kUnchecked || UNLIKELY(list.size == 0)) {
return setValue(inner);
}
- bool skip(size_t n) {
+ bool skip(SizeType n) {
CHECK_GT(n, 0);
if (!kUnchecked && position() + n >= size_) {
if (Encoder::forwardQuantum > 0 && n > Encoder::forwardQuantum) {
const size_t steps = position_ / Encoder::forwardQuantum;
const size_t dest = folly::loadUnaligned<SkipValueType>(
- forwardPointers_ + (steps - 1) * sizeof(SkipValueType));
+ this->forwardPointers_ + (steps - 1) * sizeof(SkipValueType));
reposition(dest);
n = position_ + 1 - steps * Encoder::forwardQuantum;
if (Encoder::skipQuantum > 0 && v - value_ > Encoder::skipQuantum) {
size_t q = v / Encoder::skipQuantum;
- position_ = size_t(folly::loadUnaligned<SkipValueType>(
- skipPointers_ + (q - 1) * sizeof(SkipValueType))) - 1;
+ auto skipPointer = folly::loadUnaligned<SkipValueType>(
+ this->skipPointers_ + (q - 1) * sizeof(SkipValueType));
+ position_ = static_cast<SizeType>(skipPointer) - 1;
reposition(q * Encoder::skipQuantum);
}
return true;
}
- size_t size() const { return size_; }
+ SizeType size() const {
+ return size_;
+ }
bool valid() const {
return position() < size(); // Also checks that position() != -1.
}
- size_t position() const { return position_; }
+ SizeType position() const {
+ return position_;
+ }
ValueType value() const {
DCHECK(valid());
return value_;
}
- bool jump(size_t n) {
+ bool jump(SizeType n) {
reset();
return skip(n + 1);
}
constexpr static size_t kLinearScanThreshold = 4;
- size_t outer_;
- size_t position_;
+ const uint8_t* const bits_;
uint64_t block_;
+ SizeType outer_;
+ SizeType position_;
ValueType value_;
- size_t size_;
+ SizeType size_;
ValueType upperBound_;
- const uint8_t* const bits_;
- const uint8_t* const skipPointers_;
- const uint8_t* const forwardPointers_;
};
}} // namespaces