We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
n
k
m
fp = fingerprint(x) p1 = hash1(x) % len p2 = hash2(x) % len
fp = fingerprint(x) p1 = hash(x) p2 = p1 ^ hash(fp) // 异或
p1 = p2 ^ hash(fp)
type bucket [4]byte // 一个桶,4 个座位 type cuckoo_filter struct { buckets [size]bucket // 一维数组 nums int // 容纳的元素的个数 kick_max // 最大挤兑次数 }
def insert(x): fp = fingerprint(x) p1 = hash(x) p2 = p1 ^ hash(fp) // 尝试加入第一个位置 if !buckets[p1].full(): buckets[p1].add(fp) nums++ return true // 尝试加入第二个位置 if !buckets[p2].full(): buckets[p2].add(fp) nums++ return true // 随机挤兑一个位置 p = rand(p1, p2) c = 0 while c < kick_max: // 挤兑 old_fp = buckets[p].replace_with(fp) fp = old_fp // 计算对偶位置 p = p ^ hash(fp) // 尝试加入对偶位置 if !buckets[p].full(): buckets[p].add(fp) nums++ return true return false
def contains(x): fp = fingerprint(x) p1 = hash(x) p2 = p1 ^ hash(fp) return buckets[p1].contains(fp) || buckets[p2].contains(fp)
def delete(x): fp = fingerprint(x) p1 = hash(x) p2 = p1 ^ hash(fp) ok = buckets[p1].delete(fp) || buckets[p2].delete(fp) if ok: nums-- return ok
#type/system #public
The text was updated successfully, but these errors were encountered:
No branches or pull requests
参考资料
求最大,最多的 top K
海量数据前 n 大,并且 n 比较小,堆能放入内存
布隆过滤器
误判原因
误判率:
n
是已经添加元素的数量;k
哈希的次数;m
布隆过滤器的长度(如比特数组的大小)。缺点:
应用
布谷鸟哈希
查找算法
删除算法
#type/system #public
The text was updated successfully, but these errors were encountered: