xgqfrms™, xgqfrms® : xgqfrms's offical website of cnblogs! xgqfrms™, xgqfrms® : xgqfrms's offical website of GitHub!

高级数据结构之 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, 禁止转载 🈲️,侵权必究⚠️!


posted @ 2020-08-12 14:23  xgqfrms  阅读(196)  评论(5编辑  收藏  举报