5#include <cuda/std/tuple>
16template <
typename KeyType,
typename TagType,
size_t bitsPerTag,
size_t bucketSize>
18 static constexpr size_t fpMask = (1ULL << bitsPerTag) - 1;
22 static constexpr char name[] =
"XorAltBucketPolicy";
31 static __host__ __device__ uint64_t
hash64(
const H& key) {
47 static __host__ __device__ cuda::std::tuple<size_t, size_t, TagType, TagType>
49 const uint64_t h =
hash64(key);
52 const uint32_t h_fp = h >> 32;
53 const uint32_t masked = h_fp &
fpMask;
55 const auto fp = TagType(masked == 0 ? 1 : masked);
58 const uint32_t h_bucket = h & 0xFFFFFFFF;
59 const size_t i1 = h_bucket & (numBuckets - 1);
62 return {i1, i2, fp, fp};
73 static __host__ __device__
size_t
75 return bucket ^ (
hash64(fp) & (numBuckets - 1));
83 auto requiredBuckets = std::ceil(
static_cast<double>(capacity) / bucketSize);
98template <
typename KeyType,
typename TagType,
size_t bitsPerTag,
size_t bucketSize>
100 static constexpr size_t fpMask = (1ULL << bitsPerTag) - 1;
104 static constexpr char name[] =
"AddSubAltBucketPolicy";
112 template <
typename H>
113 static __host__ __device__ uint64_t
hash64(
const H& key) {
128 static __host__ __device__ cuda::std::tuple<size_t, size_t, TagType, TagType>
130 const uint64_t h =
hash64(key);
133 const uint32_t h_fp = h >> 32;
134 const uint32_t masked = h_fp &
fpMask;
135 const auto fp = TagType(masked == 0 ? 1 : masked);
138 const uint32_t h_bucket = h & 0xFFFFFFFF;
139 const size_t bucketsPerBlock = numBuckets / 2;
141 const size_t i1 = h_bucket % bucketsPerBlock;
144 return {i1, i2, fp, fp};
158 static __host__ __device__
size_t
160 const size_t bucketsPerBlock = numBuckets / 2;
161 const uint64_t fpHash =
hash64(fp) % bucketsPerBlock;
163 if (bucket < bucketsPerBlock) {
164 return ((bucket + fpHash) % bucketsPerBlock) + bucketsPerBlock;
166 return (bucket - fpHash) % bucketsPerBlock;
175 auto requiredBuckets = std::ceil(
static_cast<double>(capacity) / bucketSize);
178 if (
static_cast<size_t>(requiredBuckets) % 2 != 0) {
179 requiredBuckets += 1;
182 return static_cast<size_t>(requiredBuckets);
200template <
typename KeyType,
typename TagType,
size_t bitsPerTag,
size_t bucketSize>
202 static_assert(bitsPerTag >= 2,
"bitsPerTag must be at least 2 for choice bit");
208 static constexpr size_t fpMask = (1ULL << bitsPerTag) - 1;
212 static constexpr char name[] =
"OffsetAltBucketPolicy";
217 template <
typename H>
218 static __host__ __device__ uint64_t
hash64(
const H& key) {
239 static __host__ __device__ TagType
setChoiceBit(TagType fp, TagType choice) {
250 static __host__ __device__
size_t computeOffset(TagType pureFp,
size_t numBuckets) {
251 const uint64_t fpHash =
hash64(pureFp);
252 const uint64_t offset = fpHash % numBuckets;
253 return offset == 0 ? 1 : offset;
267 static __host__ __device__ cuda::std::tuple<size_t, size_t, TagType, TagType>
269 const uint64_t h =
hash64(key);
272 const uint32_t h_fp = h >> 32;
275 const TagType pureFp = TagType(masked == 0 ? 1 : masked);
282 const uint32_t h_bucket = h & 0xFFFFFFFF;
283 const size_t i1 = h_bucket % numBuckets;
287 const size_t i2 = (i1 + offset) % numBuckets;
289 return {i1, i2, fp1, fp2};
304 static __host__ __device__
size_t
311 return (bucket + offset) % numBuckets;
313 return (bucket + numBuckets - offset) % numBuckets;
328 static __host__ __device__ cuda::std::tuple<size_t, TagType>
336 alt = (bucket + offset) % numBuckets;
338 alt = (bucket + numBuckets - offset) % numBuckets;
349 auto requiredBuckets = std::ceil(
static_cast<double>(capacity) / bucketSize);
350 return static_cast<size_t>(requiredBuckets);
constexpr size_t nextPowerOfTwo(size_t n)
Calculates the next power of two greater than or equal to n.
__host__ __device__ uint64_t xxhash64(const T &key, uint64_t seed=0)
Addition/Subtraction-based hashing strategy for cuckoo filters (ASCF).
static __host__ __device__ cuda::std::tuple< size_t, size_t, TagType, TagType > getCandidateBucketsAndFPs(const KeyType &key, size_t numBuckets)
Computes fingerprint and candidate buckets using ADD/SUB operations.
static constexpr size_t fpMask
static size_t calculateNumBuckets(size_t capacity)
Calculates number of buckets without requiring power of two.
static __host__ __device__ size_t getAlternateBucket(size_t bucket, TagType fp, size_t numBuckets)
Computes alternate bucket using ADD/SUB operations.
static constexpr char name[]
static __host__ __device__ uint64_t hash64(const H &key)
Computes a 64-bit hash of the key.
static constexpr bool usesChoiceBit
Offset-based alternate bucket policy from "Smaller and More Flexible Cuckoo Filters" by Schmitz,...
static __host__ __device__ TagType getChoiceBit(TagType fp)
Extracts the choice bit (0 or 1).
static __host__ __device__ uint64_t hash64(const H &key)
Computes a 64-bit hash of the key.
static __host__ __device__ size_t getAlternateBucket(size_t bucket, TagType fp, size_t numBuckets)
Computes the alternate bucket index using asymmetric offset.
static constexpr TagType choiceBitMask
static __host__ __device__ TagType setChoiceBit(TagType fp, TagType choice)
Sets the choice bit in a fingerprint.
static constexpr char name[]
static __host__ __device__ cuda::std::tuple< size_t, size_t, TagType, TagType > getCandidateBucketsAndFPs(const KeyType &key, size_t numBuckets)
Computes the primary and alternate bucket indices for a given key.
static size_t calculateNumBuckets(size_t capacity)
Calculates number of buckets without requiring power of two.
static __host__ __device__ TagType getPureFingerprint(TagType fp)
Extracts the pure fingerprint (without choice bit).
static constexpr size_t choiceBitPos
static constexpr bool usesChoiceBit
static __host__ __device__ cuda::std::tuple< size_t, TagType > getAlternateBucketWithNewFp(size_t bucket, TagType fp, size_t numBuckets)
Computes alternate bucket AND updated fingerprint for eviction.
static __host__ __device__ size_t computeOffset(TagType pureFp, size_t numBuckets)
Computes a non-zero offset from a fingerprint (uses pure fp).
static constexpr TagType pureFpMask
static constexpr size_t fpMask
Default XOR-based hashing strategy for cuckoo filters.
static constexpr bool usesChoiceBit
static constexpr size_t fpMask
static __host__ __device__ uint64_t hash64(const H &key)
Computes a 64-bit hash of the key.
static size_t calculateNumBuckets(size_t capacity)
The number of buckets is enforced to be a power of two in order to allow for efficient modulo on the ...
static __host__ __device__ cuda::std::tuple< size_t, size_t, TagType, TagType > getCandidateBucketsAndFPs(const KeyType &key, size_t numBuckets)
Performs partial-key cuckoo hashing to find the fingerprint and both bucket indices for a given key.
static __host__ __device__ size_t getAlternateBucket(size_t bucket, TagType fp, size_t numBuckets)
Computes the alternate bucket index using XOR.
static constexpr char name[]