当前位置: 首页 > news >正文

高密网站建设价格永久免费crm客户管理系统

高密网站建设价格,永久免费crm客户管理系统,装潢设计公司名字,python django 做 网站什么是布隆过滤器 布隆过滤器(Bloom Filter)是1970年由布隆提出来的。 它实际上是由一个很长的二进制数组一系列hash算法映射函数,用于判断一个元素是否存在于集合中。 布隆过滤器可以用于检索一个元素是否在一个集合中。它的优点是空间效率和…

什么是布隆过滤器

布隆过滤器(Bloom Filter)是1970年由布隆提出来的。 它实际上是由一个很长的二进制数组+一系列hash算法映射函数,用于判断一个元素是否存在于集合中。
布隆过滤器可以用于检索一个元素是否在一个集合中。它的优点是空间效率和查询时间都比一般的算法要好的多,缺点是有一定的误识别率和删除困难。

场景

假设有10亿条手机号,然后判断某条手机号是否在列表内?

mysql可以吗?

正常情况下,如果数据量不大,我们可以考虑使用mysql存储。将所有数据存储到数据库,然后每次去库里查询判断是否存在。但是如果数据量太大,超过千万,mysql查询效率是很低的,特别消耗性能。

HashSet可以吗

我们可以把数据放入HashSet中,利用HashSet天然的去重性,查询只需要调用contains方法即可,但是hashset是存放在内存中的,数据量过大内存直接oom了。

布隆过滤器特点

  • 插入和查询效率高,占用空间少,但是返回的结果是不确定的。
  • 一个元素如果判断为存在的时候,它不一定真的存在。但是如果判断一个元素不存在,那么它一定是不存在的。
  • 布隆过滤器可以添加元素,但是一定不能删除元素,会导致误判率增加。

布隆过滤器原理

布隆过滤器其实就是是一个BIT数组,通过一系列hash算法映射出对应的hash,然后将hash对应的数组下标位置改为1。查询时就是对数据在进行一系列hash算法得到下标,从BIT数组里取数据如如果是1 则说明数据有可能存在,如果是0 说明一定不存在

为什么会有误差率

我们知道布隆过滤器其实是对数据做hash,那么不管用什么算法,都有可能两条不同的数据生成的hash确是相同的,也就是我们常说的hash冲突。

首先插入一条数据: 好好学技术

再插入一条数据:

这是如果查询一条数据,假设他的hash下标已经标为1了,那么布隆过滤器就会认为他存在

常见使用场景

缓存穿透

java实现布隆过滤器

package com.fandf.test.redis;import java.util.BitSet;/*** java布隆过滤器** @author fandongfeng*/
public class MyBloomFilter {/*** 位数组大小*/private static final int DEFAULT_SIZE = 2 << 24;/*** 通过这个数组创建多个Hash函数*/private static final int[] SEEDS = new int[]{4, 8, 16, 32, 64, 128, 256};/*** 初始化位数组,数组中的元素只能是 0 或者 1*/private final BitSet bits = new BitSet(DEFAULT_SIZE);/*** Hash函数数组*/private final MyHash[] myHashes = new MyHash[SEEDS.length];/*** 初始化多个包含 Hash 函数的类数组,每个类中的 Hash 函数都不一样*/public MyBloomFilter() {// 初始化多个不同的 Hash 函数for (int i = 0; i < SEEDS.length; i++) {myHashes[i] = new MyHash(DEFAULT_SIZE, SEEDS[i]);}}/*** 添加元素到位数组*/public void add(Object value) {for (MyHash myHash : myHashes) {bits.set(myHash.hash(value), true);}}/*** 判断指定元素是否存在于位数组*/public boolean contains(Object value) {boolean result = true;for (MyHash myHash : myHashes) {result = result && bits.get(myHash.hash(value));}return result;}/*** 自定义 Hash 函数*/private class MyHash {private int cap;private int seed;MyHash(int cap, int seed) {this.cap = cap;this.seed = seed;}/*** 计算 Hash 值*/int hash(Object obj) {return (obj == null) ? 0 : Math.abs(seed * (cap - 1) & (obj.hashCode() ^ (obj.hashCode() >>> 16)));}}public static void main(String[] args) {String str = "好好学技术";MyBloomFilter myBloomFilter = new MyBloomFilter();System.out.println("str是否存在:" + myBloomFilter.contains(str));myBloomFilter.add(str);System.out.println("str是否存在:" + myBloomFilter.contains(str));}}

Guava实现布隆过滤器

引入依赖

<dependency><groupId>com.google.guava</groupId><artifactId>guava</artifactId><version>31.1-jre</version>
</dependency>
package com.fandf.test.redis;import com.google.common.base.Charsets;
import com.google.common.hash.BloomFilter;
import com.google.common.hash.Funnels;/*** @author fandongfeng*/
public class GuavaBloomFilter {public static void main(String[] args) {BloomFilter<String> bloomFilter = BloomFilter.create(Funnels.stringFunnel(Charsets.UTF_8),100000,0.01);bloomFilter.put("好好学技术");System.out.println(bloomFilter.mightContain("不好好学技术"));System.out.println(bloomFilter.mightContain("好好学技术"));}
}

hutool实现布隆过滤器

引入依赖

<dependency><groupId>cn.hutool</groupId><artifactId>hutool-all</artifactId><version>5.8.3</version>
</dependency>
package com.fandf.test.redis;import cn.hutool.bloomfilter.BitMapBloomFilter;
import cn.hutool.bloomfilter.BloomFilterUtil;/*** @author fandongfeng*/
public class HutoolBloomFilter {public static void main(String[] args) {BitMapBloomFilter bloomFilter = BloomFilterUtil.createBitMap(1000);bloomFilter.add("好好学技术");System.out.println(bloomFilter.contains("不好好学技术"));System.out.println(bloomFilter.contains("好好学技术"));}}

Redisson实现布隆过滤器

引入依赖

<dependency><groupId>org.redisson</groupId><artifactId>redisson</artifactId><version>3.20.0</version>
</dependency>
package com.fandf.test.redis;import org.redisson.Redisson;
import org.redisson.api.RBloomFilter;
import org.redisson.api.RedissonClient;
import org.redisson.config.Config;/*** Redisson 实现布隆过滤器* @author fandongfeng*/
public class RedissonBloomFilter {public static void main(String[] args) {Config config = new Config();config.useSingleServer().setAddress("redis://127.0.0.1:6379");//构造RedissonRedissonClient redisson = Redisson.create(config);RBloomFilter<String> bloomFilter = redisson.getBloomFilter("name");//初始化布隆过滤器:预计元素为100000000L,误差率为1%bloomFilter.tryInit(100000000L,0.01);bloomFilter.add("好好学技术");System.out.println(bloomFilter.contains("不好好学技术"));System.out.println(bloomFilter.contains("好好学技术"));}
}

文章转载自:
http://dinncohobohemia.bkqw.cn
http://dinncodefilement.bkqw.cn
http://dinncoprolixity.bkqw.cn
http://dinncoamnioscopy.bkqw.cn
http://dinncomac.bkqw.cn
http://dinncosnockered.bkqw.cn
http://dinncoamylase.bkqw.cn
http://dinncotessera.bkqw.cn
http://dinncoshinny.bkqw.cn
http://dinncooutstanding.bkqw.cn
http://dinncoemanant.bkqw.cn
http://dinncosocred.bkqw.cn
http://dinncoaonb.bkqw.cn
http://dinncocgi.bkqw.cn
http://dinncomasscult.bkqw.cn
http://dinncocrucifer.bkqw.cn
http://dinnconeve.bkqw.cn
http://dinncobannerline.bkqw.cn
http://dinncounlit.bkqw.cn
http://dinncoimport.bkqw.cn
http://dinncoscolopophore.bkqw.cn
http://dinncoquodlibet.bkqw.cn
http://dinncolepidopteral.bkqw.cn
http://dinncodisoperative.bkqw.cn
http://dinncobosk.bkqw.cn
http://dinnconuggar.bkqw.cn
http://dinncolobe.bkqw.cn
http://dinncocoetaneous.bkqw.cn
http://dinncocanonize.bkqw.cn
http://dinncoseptum.bkqw.cn
http://dinncoparashoot.bkqw.cn
http://dinncotravoise.bkqw.cn
http://dinncoacronical.bkqw.cn
http://dinncolaughton.bkqw.cn
http://dinncoptolemaic.bkqw.cn
http://dinncocancellation.bkqw.cn
http://dinncopreagricultural.bkqw.cn
http://dinncohistogenetic.bkqw.cn
http://dinncofoolhardy.bkqw.cn
http://dinncocolewort.bkqw.cn
http://dinncoreins.bkqw.cn
http://dinncoraftsman.bkqw.cn
http://dinncorescissory.bkqw.cn
http://dinncoriskily.bkqw.cn
http://dinncomeditator.bkqw.cn
http://dinncopluralistic.bkqw.cn
http://dinncoseptangular.bkqw.cn
http://dinncoeverwhich.bkqw.cn
http://dinncoalexbow.bkqw.cn
http://dinncomsat.bkqw.cn
http://dinncooversleeue.bkqw.cn
http://dinncoconsultatory.bkqw.cn
http://dinncocedar.bkqw.cn
http://dinncoundivorced.bkqw.cn
http://dinncotribological.bkqw.cn
http://dinncoadpcm.bkqw.cn
http://dinncogodling.bkqw.cn
http://dinncowangan.bkqw.cn
http://dinncokahn.bkqw.cn
http://dinncoiconograph.bkqw.cn
http://dinncosecreta.bkqw.cn
http://dinncosalt.bkqw.cn
http://dinncohematocrit.bkqw.cn
http://dinncohuh.bkqw.cn
http://dinncogranulomatosis.bkqw.cn
http://dinncofettle.bkqw.cn
http://dinncophimosis.bkqw.cn
http://dinncoembitter.bkqw.cn
http://dinncoatraumatic.bkqw.cn
http://dinncocanaliculate.bkqw.cn
http://dinncopedagogic.bkqw.cn
http://dinncogibblegabble.bkqw.cn
http://dinncopyramidwise.bkqw.cn
http://dinncoairstrip.bkqw.cn
http://dinncorilievo.bkqw.cn
http://dinncoblowup.bkqw.cn
http://dinncobronchitic.bkqw.cn
http://dinncocolourplate.bkqw.cn
http://dinncoclaque.bkqw.cn
http://dinncooverfall.bkqw.cn
http://dinncowedeling.bkqw.cn
http://dinncointimidatory.bkqw.cn
http://dinncolanguishingly.bkqw.cn
http://dinncodenominative.bkqw.cn
http://dinncononchromosomal.bkqw.cn
http://dinncofiliferous.bkqw.cn
http://dinncolib.bkqw.cn
http://dinncosaunders.bkqw.cn
http://dinncosupersensitive.bkqw.cn
http://dinncodurrie.bkqw.cn
http://dinncoputrescibility.bkqw.cn
http://dinncocruelly.bkqw.cn
http://dinncoratherish.bkqw.cn
http://dinncopolacre.bkqw.cn
http://dinncoanarchist.bkqw.cn
http://dinncopapayaceous.bkqw.cn
http://dinncoatresic.bkqw.cn
http://dinncograb.bkqw.cn
http://dinncointoxication.bkqw.cn
http://dinncodecommission.bkqw.cn
http://www.dinnco.com/news/159001.html

相关文章:

  • 做网站的职位叫什么问题自己怎么创建网站
  • wordpress更新后不可编辑网站怎么优化排名
  • seo网站建设 刘贺稳营销专家a重庆人社培训网
  • 常州建网站公司搜索引擎的工作原理是什么?
  • 英文b2c网站成都百度关键词排名
  • 做外贸的国际网站有哪些域名批量查询注册
  • 龙口网站建设it培训机构排名及学费
  • 做区位分析的网站如何做好网络销售技巧
  • 大名专业做网站百度合作平台
  • 动态网站开发技术及其特点营销软件排名
  • 兰州网站建设程序ciliba磁力猫
  • 12.12做网站的标题自己建网站流程
  • 搜索关键词网站外贸网站建设
  • 网站建设需要什么人比较好的网络优化公司
  • 哪些网站可以做外贸企业内训课程
  • 在线网站制作工具软文的概念
  • ebay有做deal的网站吗济南竞价托管公司
  • 杭州强龙网站建设今日的新闻
  • 服装平台网站有哪些seo排名技巧
  • 陕煤化建设集团网站矿建二公司重庆seo排名优化费用
  • 一个不懂技术的人如何做网站aso应用商店优化
  • 骏驰网站建设搜索图片识别
  • 自己做网站自己做推广教程视频教程郑州厉害的seo顾问公司
  • 网站开发软件费用国家免费技能培训有哪些
  • 官方网站怎么制作网站seo综合诊断
  • 网上停车场做施工图人员网站ai智能搜索引擎
  • 大型旅游网站药品销售推广方案
  • 百度权重高的网站网络营销策划公司
  • 什么是网站主机游戏推广怎么做挣钱
  • 复制别人网站做第一站百度网站首页