skipPointers(reinterpret_cast<Pointer>(other.skipPointers)),
forwardPointers(reinterpret_cast<Pointer>(other.forwardPointers)) {}
- void free() { ::free(const_cast<unsigned char*>(data.data())); }
-
- size_t getUpperBound() const { return upperBound; }
+ template <class T = Pointer>
+ auto free() -> decltype(::free(T(nullptr))) {
+ return ::free(data.data());
+ }
size_t size = 0;
size_t upperBound = 0;
"Value should be unsigned integral");
typedef BitVectorCompressedList CompressedList;
+ typedef MutableBitVectorCompressedList MutableCompressedList;
typedef Value ValueType;
typedef SkipValue SkipValueType;
static constexpr size_t forwardQuantum = kForwardQuantum;
template <class RandomAccessIterator>
- static BitVectorCompressedList encode(RandomAccessIterator begin,
- RandomAccessIterator end) {
+ static MutableCompressedList encode(RandomAccessIterator begin,
+ RandomAccessIterator end) {
if (begin == end) {
- return BitVectorCompressedList();
+ return MutableCompressedList();
}
BitVectorEncoder encoder(end - begin, *(end - 1));
for (; begin != end; ++begin) {
return encoder.finish();
}
- explicit BitVectorEncoder(const MutableBitVectorCompressedList& result)
+ explicit BitVectorEncoder(const MutableCompressedList& result)
: bits_(result.bits),
skipPointers_(result.skipPointers),
forwardPointers_(result.forwardPointers),
while (skipPointersSize_ < nextSkipPointerSize) {
auto pos = skipPointersSize_++;
folly::storeUnaligned<SkipValueType>(
- skipPointers_ + pos * sizeof(SkipValueType), size_);
+ skipPointers_ + pos * sizeof(SkipValueType), size_);
}
}
if (forwardQuantum != 0) {
- if ( size_ != 0 && (size_ % (forwardQuantum ?: 1) == 0)) {
+ if (size_ != 0 && (size_ % (forwardQuantum ?: 1) == 0)) {
const auto pos = size_ / (forwardQuantum ?: 1) - 1;
folly::storeUnaligned<SkipValueType>(
- forwardPointers_ + pos * sizeof(SkipValueType), value);
+ forwardPointers_ + pos * sizeof(SkipValueType), value);
}
}
++size_;
}
- const BitVectorCompressedList& finish() const {
+ const MutableCompressedList& finish() const {
CHECK_EQ(size_, result_.size);
// TODO(ott): Relax this assumption.
- CHECK_EQ(result_.getUpperBound(), lastValue_);
+ CHECK_EQ(result_.upperBound, lastValue_);
return result_;
}
size_t size_ = 0;
size_t skipPointersSize_ = 0;
- BitVectorCompressedList result_;
+ MutableCompressedList result_;
};
template <class Value,
size_t bytes() const { return bits + skipPointers + forwardPointers; }
- template <typename Range>
+ template <class Range>
BitVectorCompressedListBase<typename Range::iterator> openList(
Range& buf) const {
BitVectorCompressedListBase<typename Range::iterator> result;
return result;
}
- MutableBitVectorCompressedList allocList() const {
+ MutableCompressedList allocList() const {
uint8_t* buf = nullptr;
if (size > 0) {
buf = static_cast<uint8_t*>(malloc(bytes() + 7));
typedef typename Encoder::ValueType ValueType;
typedef typename Encoder::SkipValueType SkipValueType;
- explicit BitVectorReader(const BitVectorCompressedList& list)
+ explicit BitVectorReader(const typename Encoder::CompressedList& list)
: size_(list.size),
bits_(list.bits),
skipPointers_(list.skipPointers),
return;
}
- upperBound_ = list.getUpperBound();
+ upperBound_ = list.upperBound;
}
void reset() {
size_t size() const { return size_; }
size_t position() const { return position_; }
-
ValueType value() const { return value_; }
bool jump(size_t n) {
const uint8_t* const forwardPointers_;
};
-}} // namespaces
+}} // namespaces
-#endif // FOLLY_EXPERIMENTAL_BIT_VECTOR_CODING_H
+#endif // FOLLY_EXPERIMENTAL_BIT_VECTOR_CODING_H
template <class OtherPointer>
EliasFanoCompressedListBase(
- const EliasFanoCompressedListBase<OtherPointer>& other)
+ const EliasFanoCompressedListBase<OtherPointer>& other)
: size(other.size),
numLowerBits(other.numLowerBits),
data(other.data),
skipPointers(reinterpret_cast<Pointer>(other.skipPointers)),
forwardPointers(reinterpret_cast<Pointer>(other.forwardPointers)),
lower(reinterpret_cast<Pointer>(other.lower)),
- upper(reinterpret_cast<Pointer>(other.upper)) {
- }
+ upper(reinterpret_cast<Pointer>(other.upper)) { }
- void free() {
- ::free(const_cast<unsigned char*>(data.data()));
+ template <class T = Pointer>
+ auto free() -> decltype(::free(T(nullptr))) {
+ return ::free(data.data());
}
- size_t upperSize() const {
- return data.end() - upper;
- }
+ size_t upperSize() const { return data.end() - upper; }
size_t size = 0;
uint8_t numLowerBits = 0;
size_t kForwardQuantum = 0> // 0 = disabled
struct EliasFanoEncoderV2 {
static_assert(std::is_integral<Value>::value &&
- std::is_unsigned<Value>::value,
+ std::is_unsigned<Value>::value,
"Value should be unsigned integral");
typedef EliasFanoCompressedList CompressedList;
+ typedef MutableEliasFanoCompressedList MutableCompressedList;
typedef Value ValueType;
typedef SkipValue SkipValueType;
// EliasFanoCompressedList has no ownership of it, you need to call
// free() explicitly.
template <class RandomAccessIterator>
- static EliasFanoCompressedList encode(RandomAccessIterator begin,
- RandomAccessIterator end) {
+ static MutableCompressedList encode(RandomAccessIterator begin,
+ RandomAccessIterator end) {
if (begin == end) {
- return EliasFanoCompressedList();
+ return MutableCompressedList();
}
EliasFanoEncoderV2 encoder(end - begin, *(end - 1));
for (; begin != end; ++begin) {
return encoder.finish();
}
- explicit EliasFanoEncoderV2(const MutableEliasFanoCompressedList& result)
+ explicit EliasFanoEncoderV2(const MutableCompressedList& result)
: lower_(result.lower),
upper_(result.upper),
skipPointers_(reinterpret_cast<SkipValueType*>(
- result.skipPointers)),
+ result.skipPointers)),
forwardPointers_(reinterpret_cast<SkipValueType*>(
- result.forwardPointers)),
+ result.forwardPointers)),
result_(result) {
memset(result.data.data(), 0, result.data.size());
}
EliasFanoEncoderV2(size_t size, ValueType upperBound)
: EliasFanoEncoderV2(
- Layout::fromUpperBoundAndSize(upperBound, size).allocList()) {
- }
+ Layout::fromUpperBoundAndSize(upperBound, size).allocList()) { }
void add(ValueType value) {
CHECK_GE(value, lastValue_);
++size_;
}
- const EliasFanoCompressedList& finish() const {
+ const MutableCompressedList& finish() const {
CHECK_EQ(size_, result_.size);
return result_;
}
size_t size_ = 0;
size_t skipPointersSize_ = 0;
- EliasFanoCompressedList result_;
+ MutableCompressedList result_;
};
template <class Value,
return lower + upper + skipPointers + forwardPointers;
}
- template <typename Range>
+ template <class Range>
EliasFanoCompressedListBase<typename Range::iterator>
openList(Range& buf) const {
EliasFanoCompressedListBase<typename Range::iterator> result;
return result;
}
- MutableEliasFanoCompressedList allocList() const {
+ MutableCompressedList allocList() const {
uint8_t* buf = nullptr;
// WARNING: Current read/write logic assumes that the 7 bytes
// following the last byte of lower and upper sequences are
public:
typedef typename Encoder::ValueType ValueType;
- explicit UpperBitsReader(const EliasFanoCompressedList& list)
- : forwardPointers_(list.forwardPointers),
- skipPointers_(list.skipPointers),
- start_(list.upper) {
+ explicit UpperBitsReader(const typename Encoder::CompressedList& list)
+ : forwardPointers_(list.forwardPointers),
+ skipPointers_(list.skipPointers),
+ start_(list.upper) {
reset();
}
typedef Encoder EncoderType;
typedef typename Encoder::ValueType ValueType;
- explicit EliasFanoReader(const EliasFanoCompressedList& list)
+ explicit EliasFanoReader(const typename Encoder::CompressedList& list)
: size_(list.size),
lower_(list.lower),
upper_(list),