高级数据结构之 BloomFilter All In One
高级数据结构之 BloomFilter All In One
布隆过滤器
https://en.wikipedia.org/wiki/Bloom_filter
A Bloom filter is a space-efficient probabilistic data structure, conceived by Burton Howard Bloom in 1970, that is used to test whether an element is a member of a set.
False positive matches are possible, but false negatives are not – in other words, a query returns either "possibly in set" or "definitely not in set".
Elements can be added to the set, but not removed (though this can be addressed with the counting Bloom filter variant); the more items added, the larger the probability of false positives.
布隆过滤器
是一种节省空间的概率数据结构,由伯顿·霍华德·布鲁姆(Burton Howard Bloom)在1970年提出,用于测试元素是否为集合的成员。
可能会出现假阳性匹配,但否定否定匹配-换句话说,查询返回“可能在集合中”或“绝对不在集合中”。
元素可以添加到集合中,但不能删除(尽管可以通过计数Bloom过滤器变体解决); 添加的项目越多,误报的可能性就越大。
布隆过滤器 (缓存穿透/ 缓存击穿)
查找问题,类似于在海量数据
中查找
某个key是否存在,考虑空间复杂度
和时间复杂度
,一般选用布隆过滤器
来实现。
布隆过滤器是个好东西,有非常多的用途,包括:垃圾邮件识别
、搜索蜘蛛爬虫 url 去重
等,主要借助 K个哈希函数
和一个超大的 bit数组
来降低哈希冲突
本身带来的误判,从而提高识别准确性。
布隆过滤器也存在一定的误判,假如判断存在
可能不一定存在
,但是假如判断不存在
就一定不存在
,因此刚好用在解决缓存穿透的key查找场景,事实上很多系统都是基于布隆过滤器来解决缓存穿透
问题的。
Bloom Filter
data structure
hash function
https://www.geeksforgeeks.org/bloom-filters-introduction-and-python-implementation/
https://blog.cloudflare.com/when-bloom-filters-dont-bloom/
refs
BloomFilter & python crawler
https://github.com/cpselvis/zhihu-crawler/blob/master/crawler.py#L33
如何计算算法的复杂度
https://time.geekbang.org/course/detail/100019701-41531
const n = 10**6;
console.time(`for`)
for (let i = 1; i <= n; i++) {
if (i === n) {
console.log(`ok`)
}
}
console.timeEnd(`for`)
// ok
// for: 4.4267578125 ms
console.time(`math`)
const result = (n * (n + 1))/2
console.log(`ok`, result)
console.timeEnd(`math`)
// ok 500000500000
// math: 0.09912109375 ms
refs
©xgqfrms 2012-2020
www.cnblogs.com/xgqfrms 发布文章使用:只允许注册用户才可以访问!
原创文章,版权所有©️xgqfrms, 禁止转载 🈲️,侵权必究⚠️!
本文首发于博客园,作者:xgqfrms,原文链接:https://www.cnblogs.com/xgqfrms/p/13490357.html
未经授权禁止转载,违者必究!
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· DeepSeek 开源周回顾「GitHub 热点速览」
· 记一次.NET内存居高不下排查解决与启示
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· .NET10 - 预览版1新功能体验(一)
2019-08-12 2019 front-end job Interview
2019-08-12 js currying All In One
2019-08-12 how to remove macintosh hd icon from desktop
2019-08-12 HTML5 & files API & input upload image
2018-08-12 learning 2018
2018-08-12 github rename
2018-08-12 MBP 2018 All In One