* "Quasi-succinct indices" (arxiv:1206.4300).
*/
-#ifndef FOLLY_EXPERIMENTAL_ELIAS_FANO_CODING_H
-#define FOLLY_EXPERIMENTAL_ELIAS_FANO_CODING_H
+#pragma once
+#include <algorithm>
#include <cstdlib>
#include <limits>
#include <type_traits>
#include <folly/experimental/Select64.h>
#include <glog/logging.h>
-#ifndef __GNUC__
-#error EliasFanoCoding.h requires GCC
-#endif
-
#if !FOLLY_X64
#error EliasFanoCoding.h requires x86_64
#endif
-#if __BYTE_ORDER__ != __ORDER_LITTLE_ENDIAN__
-#error EliasFanoCoding.h requires little endianness
-#endif
-
namespace folly { namespace compression {
+static_assert(kIsLittleEndian, "EliasFanoCoding.h requires little endianness");
+
template <class Pointer>
struct EliasFanoCompressedListBase {
EliasFanoCompressedListBase() = default;
forwardPointers_(reinterpret_cast<SkipValueType*>(
result.forwardPointers)),
result_(result) {
- memset(result.data.data(), 0, result.data.size());
+ std::fill(result.data.begin(), result.data.end(), 0);
}
EliasFanoEncoderV2(size_t size, ValueType upperBound)
// more serialization-friendly way (upperSizeBits doesn't need
// to be known by this function, unlike upper).
- // '?: 1' is a workaround for false 'division by zero'
- // compile-time error.
- size_t numSkipPointers = (8 * upper - size) / (skipQuantum ?: 1);
+ size_t numSkipPointers = (8 * upper - size) / skipQuantum;
layout.skipPointers = numSkipPointers * sizeof(SkipValueType);
}
// Store (1-indexed) position of every forwardQuantum-th
// 1-bit in upper bits sequence.
/* static */ if (forwardQuantum != 0) {
- size_t numForwardPointers = size / (forwardQuantum ?: 1);
+ size_t numForwardPointers = size / forwardQuantum;
layout.forwardPointers = numForwardPointers * sizeof(SkipValueType);
}
// Use forward pointer.
if (Encoder::forwardQuantum > 0 && n > Encoder::forwardQuantum) {
- // Workaround to avoid 'division by zero' compile-time error.
- constexpr size_t q = Encoder::forwardQuantum ?: 1;
-
- const size_t steps = position_ / q;
+ const size_t steps = position_ / Encoder::forwardQuantum;
const size_t dest =
folly::loadUnaligned<SkipValueType>(
forwardPointers_ + (steps - 1) * sizeof(SkipValueType));
- reposition(dest + steps * q);
- n = position_ + 1 - steps * q; // n is > 0.
+ reposition(dest + steps * Encoder::forwardQuantum);
+ n = position_ + 1 - steps * Encoder::forwardQuantum; // n is > 0.
// Correct inner_ will be set at the end.
}
// Use skip pointer.
if (Encoder::skipQuantum > 0 && v >= value_ + Encoder::skipQuantum) {
- // Workaround to avoid 'division by zero' compile-time error.
- constexpr size_t q = Encoder::skipQuantum ?: 1;
-
- const size_t steps = v / q;
+ const size_t steps = v / Encoder::skipQuantum;
const size_t dest =
folly::loadUnaligned<SkipValueType>(
skipPointers_ + (steps - 1) * sizeof(SkipValueType));
- reposition(dest + q * steps);
+ reposition(dest + Encoder::skipQuantum * steps);
position_ = dest - 1;
// Correct inner_ and value_ will be set during the next()
};
}} // namespaces
-
-#endif // FOLLY_EXPERIMENTAL_ELIAS_FANO_CODING_H