doc: 阅读redis cuckoo filter文档

This commit is contained in:
asahi
2025-09-22 16:13:32 +08:00
parent df43af8900
commit 840ae043d6

View File

@@ -141,6 +141,8 @@
- [Reserving Bloom filters](#reserving-bloom-filters)
- [total size of bloom filter](#total-size-of-bloom-filter)
- [Performance](#performance)
- [Cuckoo filter](#cuckoo-filter)
- [User Cases](#user-cases)
# redis
@@ -2419,3 +2421,16 @@ memory_with_sets = capacity*(192b + value)
对bloom filter执行存在性检查的时间复杂度为`O(K)`或`O(K*n)`针对stacked filters场景`n`为stacked filters的数量
#### Cuckoo filter
Cuckoo filter和Bloom filter类似同样用于检测item在set中是否存在其也提供了`a very fast and space efficient way`。除此之外Cuckoo filter允许对item进行删除且在部分场景下相比Bloom filter而言Cuckoo filter的性能要更好。
Bloom filter和Cuckoo filter的实现逻辑如下
- Bloom filter是一个bit array在`hash function决定的位置bit将会被置为1`。
- 而Cuckoo filter则是一个bucket array`storing the fingerprints of the values in one of the buckets at positions decided by the two hash function`。
- 通过两个hash function能够计算出两个可能的bucket position而item的fingerprint则存储在两个bucket的其中一个
- 对于item x的membership query会针对x的fingerprint查找possible bucket并且在查询到对应的fingerprint时返回true
- 对于Cuckoo filter其`fingerprint size`会决定其false positive rate
##### User Cases
在应用中Cuckoo filter拥有如下使用示例
- `Targeted ad campaigns`: 在该场景下Cuckoo filter主要用于处理`用户是否参与了指定活动`