首页 > 其他分享 >bloomFilter_demo

bloomFilter_demo

时间:2023-06-04 21:36:20浏览次数:49  
标签:count INSERT ++ demo System NUM EXPECTED bloomFilter

参考博客:(14条消息) 布隆(Bloom Filter)过滤器入门_布隆过滤器入门_qq_39093474的博客-CSDN博客

5 分钟搞懂布隆过滤器,亿级数据过滤算法你值得拥有! - 知乎 (zhihu.com)

BloomFilterTest.java

package com.hmb;

import com.google.common.hash.BloomFilter;
import com.google.common.hash.Funnels;

import java.util.HashSet;
import java.util.Set;

public class BloomFilterTest {
    private static Integer EXPECTED_INSERT_NUM = 10000000;
    private static double fpp = 0.01;

    private static BloomFilter<Integer> bloomFilter = BloomFilter.create(Funnels.integerFunnel(),
            EXPECTED_INSERT_NUM, fpp);

    private static Set<Integer> set = new HashSet<>();
    public static void main(String[] args) {
        long stime = System.currentTimeMillis();
        for (int i = 0; i < EXPECTED_INSERT_NUM; i++) {
            bloomFilter.put(i);
        }

        int count = 0;
        for (int i = EXPECTED_INSERT_NUM; i < EXPECTED_INSERT_NUM * 2; i++) {
            if (bloomFilter.mightContain(i)) {
                count++;
            }
        }
        long etime = System.currentTimeMillis();
        System.out.println("incorrect judge num: " + count);
        System.out.println("spend time: " + (etime - stime) + " ms");

        stime = System.currentTimeMillis();
        for (int i = 0; i < EXPECTED_INSERT_NUM; i++) {
            set.add(i);
        }
        count = 0;
        for (int i = EXPECTED_INSERT_NUM; i < EXPECTED_INSERT_NUM * 2; i++) {
            if (set.contains(i)) {
                count++;
            }
        }
        etime = System.currentTimeMillis();
        System.out.println("incorrect judge num: " + count);
        System.out.println("spend time: " + (etime - stime) + " ms");
    }
}

  

笔者拿bloomFilter跟set进行了对比,当EXPECTED_INSERT_NUM<=10000000时,发现都是set更快,当EXPECTED_INSERT_NUM==100000000时,set就会报OOM了

 

标签:count,INSERT,++,demo,System,NUM,EXPECTED,bloomFilter
From: https://www.cnblogs.com/hemeiwolong/p/17456374.html

相关文章

  • netty入门demo
    参考博客:(14条消息)【Netty整理01-快速入门】Netty简单使用Demo(已验证)_the_fool_的博客-CSDN博客ServerHandler.javapackagecom.hmb;importio.netty.buffer.ByteBuf;importio.netty.channel.ChannelHandlerContext;importio.netty.channel.ChannelInboundHandlerAdapt......
  • 异步爬虫demo2
    importreimportaiohttpimportasyncioclassAsyn:def__init__(self):self.__headers={'user-agent':'Mozilla/5.0(WindowsNT10.0;Win64;x64)AppleWebKit/537.36(KHTML,likeGecko)Chrome/112.0.0.0Safari/537......
  • EasyCVR使用SDK接入,设备全部离线,但是SDK DEMO接入正常是什么原因?
    EasyCVR视频融合平台基于云边端一体化架构,具有强大的数据接入、处理及分发能力,平台支持多协议、多类型的设备接入,包括主流标准协议国标GB28181、RTSP/Onvif、RTMP等,以及厂家私有协议与SDK接入,包括海康Ehome、海大宇等设备的SDK等。有用户反馈,EasyCVR平台中,使用SDK接入的设备显示......
  • EasyCVR使用SDK接入,设备全部离线,但是SDK DEMO接入正常是什么原因?
    EasyCVR视频融合平台基于云边端一体化架构,具有强大的数据接入、处理及分发能力,平台支持多协议、多类型的设备接入,包括主流标准协议国标GB28181、RTSP/Onvif、RTMP等,以及厂家私有协议与SDK接入,包括海康Ehome、海大宇等设备的SDK等。有用户反馈,EasyCVR平台中,使用SDK接入的设备显示全......
  • Hazelcast分布式计算的demo
    下面是一个使用Java实现的Hazelcast分布式计算的示例代码:importcom.hazelcast.core.Hazelcast;importcom.hazelcast.core.HazelcastInstance;importcom.hazelcast.core.IExecutorService;importcom.hazelcast.core.Member;importjava.io.Serializable;importjava.util......
  • python spark 随机森林入门demo
    class pyspark.mllib.tree.RandomForest[source]Learningalgorithmforarandomforestmodelforclassificationorregression.Newinversion1.2.0.supportedFeatureSubsetStrategies =('auto','all','sqrt','log2',......
  • python spark 决策树 入门demo
    Refertothe DecisionTree and DecisionTreeModel formoredetailsontheAPI.frompyspark.mllib.treeimportDecisionTree,DecisionTreeModelfrompyspark.mllib.utilimportMLUtils#LoadandparsethedatafileintoanRDDofLabeledPoint.data=MLUtils.l......
  • python spark kmeans demo
    官方的demofromnumpyimportarrayfrommathimportsqrtfrompysparkimportSparkContextfrompyspark.mllib.clusteringimportKMeans,KMeansModelsc=SparkContext(appName="clusteringExample")#Loadandparsethedatadata=sc.textFile("/......
  • 微信开源组件WCDB漫谈及Demo
    前言移动端的数据库选型一直是一个难题,直到前段时间看到了WeMobileDev(微信前端团队)放出了第三个开源组件-WCDBWCDB(WeChatDataBase)是微信官方的移动端数据库组件,致力于提供一个高效、易用、完整的移动端存储方案项目目录微信团队怎么说基于SQLCipherWCDB-iOS/MacWCDB-Android数......
  • 最规范的汇编函数传参demo
    assumecs:code;记忆点:1.主函数,子函数都需要自己维护bp和sp(当然不维护也行,但是非常容易出bug,所以还是要强烈按照下面子函数头,子函数尾.主函数头尾这么写,最安全.)2.函数ip都有压栈出站自动维护但是自己要算明白栈的偏移量.codesegmentraddprocpus......