GPU-Accelerated Cuckoo Filter
Loading...
Searching...
No Matches
Static Public Member Functions | Static Public Attributes | List of all members
cuckoogpu::AddSubAltBucketPolicy< KeyType, TagType, bitsPerTag, bucketSize > Struct Template Reference

Addition/Subtraction-based hashing strategy for cuckoo filters (ASCF). More...

Static Public Member Functions

template<typename H >
static __host__ __device__ uint64_t hash64 (const H &key)
 Computes a 64-bit hash of the key.
 
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 __host__ __device__ size_t getAlternateBucket (size_t bucket, TagType fp, size_t numBuckets)
 Computes alternate bucket using ADD/SUB operations.
 
static size_t calculateNumBuckets (size_t capacity)
 Calculates number of buckets without requiring power of two.
 

Static Public Attributes

static constexpr size_t fpMask = (1ULL << bitsPerTag) - 1
 
static constexpr bool usesChoiceBit = false
 
static constexpr char name [] = "AddSubAltBucketPolicy"
 

Detailed Description

template<typename KeyType, typename TagType, size_t bitsPerTag, size_t bucketSize>
struct cuckoogpu::AddSubAltBucketPolicy< KeyType, TagType, bitsPerTag, bucketSize >

Addition/Subtraction-based hashing strategy for cuckoo filters (ASCF).

This implements the scheme from "Additive and Subtractive Cuckoo Filters" paper which uses ADD/SUB operations instead of XOR, allowing for non-power-of-two bucket counts and better space efficiency.

The filter is conceptually divided into two blocks of equal size.

Definition at line 99 of file bucket_policies.cuh.

Member Function Documentation

◆ calculateNumBuckets()

template<typename KeyType , typename TagType , size_t bitsPerTag, size_t bucketSize>
static size_t cuckoogpu::AddSubAltBucketPolicy< KeyType, TagType, bitsPerTag, bucketSize >::calculateNumBuckets ( size_t  capacity)
inlinestatic

Calculates number of buckets without requiring power of two.

The total number is rounded to ensure it's even (for equal block sizes).

Definition at line 174 of file bucket_policies.cuh.

174 {
175 auto requiredBuckets = std::ceil(static_cast<double>(capacity) / bucketSize);
176
177 // Round up to next even number to ensure equal block sizes
178 if (static_cast<size_t>(requiredBuckets) % 2 != 0) {
179 requiredBuckets += 1;
180 }
181
182 return static_cast<size_t>(requiredBuckets);
183 }

◆ getAlternateBucket()

template<typename KeyType , typename TagType , size_t bitsPerTag, size_t bucketSize>
static __host__ __device__ size_t cuckoogpu::AddSubAltBucketPolicy< KeyType, TagType, bitsPerTag, bucketSize >::getAlternateBucket ( size_t  bucket,
TagType  fp,
size_t  numBuckets 
)
inlinestatic

Computes alternate bucket using ADD/SUB operations.

If current bucket is in block 0, alternate is in block 1 (use ADD). If current bucket is in block 1, alternate is in block 0 (use SUB).

Parameters
bucketCurrent bucket index
fpFingerprint value
numBucketsTotal number of buckets
Returns
Alternate bucket index

Definition at line 159 of file bucket_policies.cuh.

159 {
160 const size_t bucketsPerBlock = numBuckets / 2;
161 const uint64_t fpHash = hash64(fp) % bucketsPerBlock;
162
163 if (bucket < bucketsPerBlock) {
164 return ((bucket + fpHash) % bucketsPerBlock) + bucketsPerBlock;
165 } else {
166 return (bucket - fpHash) % bucketsPerBlock;
167 }
168 }
static __host__ __device__ uint64_t hash64(const H &key)
Computes a 64-bit hash of the key.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ getCandidateBucketsAndFPs()

template<typename KeyType , typename TagType , size_t bitsPerTag, size_t bucketSize>
static __host__ __device__ cuda::std::tuple< size_t, size_t, TagType, TagType > cuckoogpu::AddSubAltBucketPolicy< KeyType, TagType, bitsPerTag, bucketSize >::getCandidateBucketsAndFPs ( const KeyType &  key,
size_t  numBuckets 
)
inlinestatic

Computes fingerprint and candidate buckets using ADD/SUB operations.

The first bucket is in block 0, computed from the hash. The second bucket is in block 1, computed by adding the fingerprint hash to the first bucket index (with wraparound within block 1).

Parameters
keyKey to hash
numBucketsTotal number of buckets (should be even for proper block division)
Returns
A tuple of (bucket1, bucket2, fingerprintForBucket1, fingerprintForBucket2)

Definition at line 129 of file bucket_policies.cuh.

129 {
130 const uint64_t h = hash64(key);
131
132 // Upper 32 bits for the fingerprint
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);
136
137 // Lower 32 bits for bucket index in block 0
138 const uint32_t h_bucket = h & 0xFFFFFFFF;
139 const size_t bucketsPerBlock = numBuckets / 2;
140
141 const size_t i1 = h_bucket % bucketsPerBlock;
142 const size_t i2 = getAlternateBucket(i1, fp, numBuckets);
143
144 return {i1, i2, fp, fp};
145 }
static __host__ __device__ size_t getAlternateBucket(size_t bucket, TagType fp, size_t numBuckets)
Computes alternate bucket using ADD/SUB operations.
Here is the call graph for this function:

◆ hash64()

template<typename KeyType , typename TagType , size_t bitsPerTag, size_t bucketSize>
template<typename H >
static __host__ __device__ uint64_t cuckoogpu::AddSubAltBucketPolicy< KeyType, TagType, bitsPerTag, bucketSize >::hash64 ( const H &  key)
inlinestatic

Computes a 64-bit hash of the key.

Template Parameters
HType of the key.
Parameters
keyThe key to hash.
Returns
uint64_t The 64-bit hash value.

Definition at line 113 of file bucket_policies.cuh.

113 {
114 return xxhash::xxhash64(key);
115 }
__host__ __device__ uint64_t xxhash64(const T &key, uint64_t seed=0)
Definition hashutil.cuh:71
Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

◆ fpMask

template<typename KeyType , typename TagType , size_t bitsPerTag, size_t bucketSize>
constexpr size_t cuckoogpu::AddSubAltBucketPolicy< KeyType, TagType, bitsPerTag, bucketSize >::fpMask = (1ULL << bitsPerTag) - 1
staticconstexpr

Definition at line 100 of file bucket_policies.cuh.

◆ name

template<typename KeyType , typename TagType , size_t bitsPerTag, size_t bucketSize>
constexpr char cuckoogpu::AddSubAltBucketPolicy< KeyType, TagType, bitsPerTag, bucketSize >::name[] = "AddSubAltBucketPolicy"
staticconstexpr

Definition at line 104 of file bucket_policies.cuh.

◆ usesChoiceBit

template<typename KeyType , typename TagType , size_t bitsPerTag, size_t bucketSize>
constexpr bool cuckoogpu::AddSubAltBucketPolicy< KeyType, TagType, bitsPerTag, bucketSize >::usesChoiceBit = false
staticconstexpr

Definition at line 102 of file bucket_policies.cuh.


The documentation for this struct was generated from the following file: