布隆过滤器BloomFilter

编程入门 行业动态 更新时间:2024-10-23 11:31:13

布隆<a href=https://www.elefans.com/category/jswz/34/1771166.html style=过滤器BloomFilter"/>

布隆过滤器BloomFilter

应用很多,比如防止缓存击穿,垃圾邮件的检测等等

它的优点是比其他算法查询时间快很多,也有缺点是存在误差。

demo

package com.example.demo.util;import com.googlemon.hash.BloomFilter;
import com.googlemon.hash.Funnels;
import org.apachemons.io.Charsets;public class Test {public static void main(String[] args) {int total=1000000;BloomFilter<String> bf=BloomFilter.create(Funnels.stringFunnel(Charsets.UTF_8),total,0.0003);for(int i=0;i<total;i++){bf.put(""+i);}int count=0;for(int i=0;i<total+1000;i++){if(bf.mightContain(""+i)){count++;}}System.out.println(count);}
}
BloomFilter.create(Funnels.stringFunnel(Charsets.UTF_8),total,0.0003)

0.0003是值误差率,即总数1000000个,结果会有1010000*(0.0003/100)=3.03

输出结果是1000001

 

更多推荐

布隆过滤器BloomFilter

本文发布于:2024-03-09 09:08:15,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1724555.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:过滤器   BloomFilter

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!