5#include <blockfilter.h>
18#include <unordered_set>
24 const uint64_t x_hi = x >> 32;
25 const uint64_t x_lo = x & 0xFFFFFFFF;
26 const uint64_t n_hi = n >> 32;
27 const uint64_t n_lo = n & 0xFFFFFFFF;
28 const uint64_t ac = x_hi * n_hi;
29 const uint64_t ad = x_hi * n_lo;
30 const uint64_t bc = x_lo * n_hi;
31 const uint64_t bd = x_lo * n_lo;
32 const uint64_t mid34 = (bd >> 32) + (bc & 0xFFFFFFFF) + (ad & 0xFFFFFFFF);
33 const uint64_t upper64 = ac + (bc >> 32) + (ad >> 32) + (mid34 >> 32);
37uint64_t HashToRange(
const std::vector<uint8_t>& element,
const uint64_t f)
39 const uint64_t hash =
CSipHasher(0x0706050403020100ULL, 0x0F0E0D0C0B0A0908ULL)
40 .
Write(element.data(), element.size())
45std::vector<uint64_t> BuildHashedSet(
const std::unordered_set<std::vector<uint8_t>,
ByteVectorHash>& elements,
const uint64_t f)
47 std::vector<uint64_t> hashed_elements;
48 hashed_elements.reserve(elements.size());
49 for (
const std::vector<uint8_t>& element : elements) {
50 hashed_elements.push_back(HashToRange(element, f));
52 std::sort(hashed_elements.begin(), hashed_elements.end());
53 return hashed_elements;
60 std::vector<uint8_t> golomb_rice_data;
61 std::vector<uint64_t> encoded_deltas;
65 for (
int i = 0; i < n; ++i) {
71 if (!elements.empty()) {
72 uint64_t last_value = 0;
73 for (
const uint64_t value : BuildHashedSet(elements,
static_cast<uint64_t
>(elements.size()) *
static_cast<uint64_t
>(
BASIC_FILTER_M))) {
74 const uint64_t delta = value - last_value;
75 encoded_deltas.push_back(delta);
83 std::vector<uint64_t> decoded_deltas;
88 for (uint32_t i = 0; i < n; ++i) {
93 assert(encoded_deltas == decoded_deltas);
101 }
catch (
const std::ios_base::failure&) {
105 for (uint32_t i = 0; i < std::min<uint32_t>(n, 1024); ++i) {
108 }
catch (
const std::ios_base::failure&) {
static uint64_t MapIntoRange(uint64_t x, uint64_t n)
constexpr uint8_t BASIC_FILTER_P
constexpr uint32_t BASIC_FILTER_M
void Flush()
Flush any unwritten bits to the output stream, padding with 0's to the next byte boundary.
Implementation of Hash named requirement for types that internally store a byte array.
uint64_t Finalize() const
Compute the 64-bit SipHash-2-4 of the data written so far.
CSipHasher & Write(uint64_t data)
Hash a 64-bit integer worth of data It is treated as if this was the little-endian interpretation of ...
T ConsumeIntegralInRange(T min, T max)
Minimal stream for reading from an existing vector by reference.
uint64_t GolombRiceDecode(BitStreamReader< IStream > &bitreader, uint8_t P)
void GolombRiceEncode(BitStreamWriter< OStream > &bitwriter, uint8_t P, uint64_t x)
uint64_t ReadCompactSize(Stream &is, bool range_check=true)
Decode a CompactSize-encoded variable-length integer.
void WriteCompactSize(CSizeComputer &os, uint64_t nSize)
std::vector< uint8_t > ConsumeRandomLengthByteVector(FuzzedDataProvider &fuzzed_data_provider, const std::optional< size_t > &max_length=std::nullopt) noexcept