当前位置:网站首页>0 9 布隆过滤器(Bloom Filter)
0 9 布隆过滤器(Bloom Filter)
2022-07-29 06:46:00 【51CTO】
思考
如果要经常判断 1 个元素是否存在,你会怎么做?
很容易想到使用哈希表(HashSet、HashMap),将元素作为 key 去查找 * 时间复杂度:O(1),但是空间利用率不高,需要占用比较多的内存资源
如果需要编写一个网络爬虫去爬10亿个网站数据,为了避免爬到重复的网站,如何判断某个网站是否爬过?
很显然,HashSet、HashMap 并不是非常好的选择
是否存在时间复杂度低、占用内存较少的方案?
布隆过滤器(Bloom Filter)
布隆过滤器(Bloom Filter)
1970年由布隆提出
它是一个空间效率高的概率型数据结构,可以用来告诉你:一个元素一定不存在或者可能存在
优缺点
优点:空间效率和查询时间都远远超过一般的算法
缺点:有一定的误判率、删除困难
它实质上是一个很长的二进制向量和一系列随机映射函数(Hash函数)
常见应用
网页黑名单系统、垃圾邮件过滤系统、爬虫的网址判重系统、解决缓存穿透问题
布隆过滤器的原理
假设布隆过滤器由 20位二进制、 3 个哈希函数组成,每个元素经过哈希函数处理都能生成一个索引位置
添加元素:将每一个哈希函数生成的索引位置都设为 1
查询元素是否存在
* 如果有一个哈希函数生成的索引位置不为 1,就代表不存在(100%准确)
* 如果每一个哈希函数生成的索引位置都为 1,就代表存在(存在一定的误判率)

添加、查询的时间复杂度都是:O(k) ,k 是哈希函数的个数。空间复杂度是:O(m) ,m 是二进制位的个数
布隆过滤器的误判率

布隆过滤器的实现

Guava: Google Core Libraries For Java
https://mvnrepository.com/artifact/com.google.guava/guava
边栏推荐
- Operator3-设计一个operator
- Cvpr2021 | multi view stereo matching based on self supervised learning (cvpr2021)
- Student status management system based on C language design
- buck电路boot和ph引脚实测
- My personal website doesn't allow access to wechat, so I did this
- When NPM is installed, it is stuck. There are five solutions
- Excel文件读写(创建与解析)
- It's enough for MySQL to have this article (disgusting and crazy typing 37k words, just for Bo Jun's praise!!!)
- Personal blog system (with source code)
- Hj37 statistics of the total number of rabbits per month Fibonacci series
猜你喜欢

H3C_利用设置缺省静态路由优先级实现出口双线路的主备功能

win11系统错误:由于找不到 iertutil.dll,无法继续执行代码。重新安装程序可能会解决此问题

用户列表 圆形头像并跟随小板块

Nodejs安装教程

Kubernetes (V) -- deploy kubernetes dashboard

MySQL 有这一篇就够(呕心狂敲37k字,只为博君一点赞!!!)

Win11vmware turns on the virtual machine and restarts on the blue screen and the solution that cannot be started

js中break与continue和return关键字

Image noise and matrix inversion

2022-07-28: what is the output of the following go language code? A:AA; B:AB; C:BA; D:BB。 package main import ( “fmt“ ) func main() { f
随机推荐
[Charles' daily problems] when you open Charles, you can't use nails
Flink real-time warehouse DWD layer (processing complex data - installation and replacement of streams and tables) template code
WPF嵌套布局案例
Flink real time warehouse DWD layer (traffic domain) template code
实现改变一段文字的部分颜色效果
Error 1045 (28000) access denied for user 'root' @ 'localhost' solution
Tp6 use protobuf
Remote invocation of microservices
Image noise and matrix inversion
Nodejs安装教程
Unity sends a post request to the golang server for parsing and returning
VMware16创建虚拟机:Win11无法安装
Connecting PHP 7.4 to Oracle configuration on Windows
Explanation of suffix automata (SAM) + Luogu p3804 [template] suffix automata (SAM)
MySQL 使用客户端以及SELECT 方式查看 BLOB 类型字段内容总结
CVPR2021| 基于自监督学习的多视图立体匹配 (CVPR2021)
330. 按要求补齐数组
Ethernet interface introduction
最新百亿量化私募名单
基于C语言实现图书借阅管理系统