实现代码
/**
* @Name BuLongDemo
* @Author qzz
* @Date 2022/9/7 17:53
*/
public class BuLongDemo {
//预计要插入多少数据
private static int size = 1000000;
//期望的误判率
private static double fpp = 0.01;
private static BloomFilter<Integer> bloomFilter = BloomFilter.create(Funnels.integerFunnel(), size, fpp);
public static void main(String[] args) {
//插入数据
for (int i = 0; i < 1000000; i++) {
bloomFilter.put(i);
}
int count = 0;
for (int i = 1000000; i < 2000000; i++) {
/**mightContain:判断该元素是否在布隆过滤器中
* 可能在返回true,肯定不在返回false
* */
if (bloomFilter.mightContain(i)) {
count++;
System.out.println(i + "误判了");
}
}
System.out.println("总共的误判数:" + count);
}
}
使用的是Google的Guava类库
执行main方法,发现误判了10314次
标签:count,int,Demo,误判,布隆,private,static,1000000,过滤器 From: https://www.cnblogs.com/qzzzz/p/16863395.html