BitMap和布隆过滤器

package csdn.cn.dsa;

import java.util.Random;

public class BitMap {
    int ARRNUM = 100;
    int mmin = 10000000;
    int mmax= 99999999;
    int N = (mmax - mmin) + 1;
    int BITS_PER_WORD = 32;

    public static void main(String[] args) {
        new BitMap().sort();
    }
    int word_offset(int b){
        return b / BITS_PER_WORD;
    }
    int bit_offset(int b){
        return b % BITS_PER_WORD;
    }
    public void setBit(int[] words, int n){
        n -= mmin;
        words[word_offset(n)] |= (1 << bit_offset(n));
    }
    public void clearBit(int[] words, int n){
        words[word_offset(n)] &= ~(1 << bit_offset(n));
    }

    public boolean getBit(int[] words, int n){
        int bit = words[word_offset(n)] & (1 << bit_offset(n));
        return bit != 0;
    }
    public void sort(){
        int i;
        int j;
        int arr[] = new int[ARRNUM];
        System.out.println("数组大小:" + ARRNUM);
        int[] words = new int[1 + N / BITS_PER_WORD];
        int count = 0;
        Random r = new Random();
        for(j = 0; j < ARRNUM;j++){
            arr[j] = r.nextInt(N);
            arr[j] += mmin;
            System.out.println(arr[j] + " ");
        }
        System.out.println();
        for(j = 0; j < ARRNUM; j++){
            setBit(words, arr[j]);
        }
        System.out.println("排序后的结果是:");
        for(i = 0; i < N; i++){
            if(getBit(words, i)){
                System.out.println(i + mmin + " ");
                count ++;
            }
        }
        System.out.println();
        System.out.println("总个数为:" + count);
    }
}

布隆过滤器

 

布隆过滤器判断存在的不一定存在,但是判断不存在的一定不存在

False is always false, True is maybe true

如何减少布隆过滤器的误判率?

布隆过滤器的特点

  1. 由于存放的不是完整的数据,所以占用的内存很少,而且新增,查询速度够快;

    2.多个hash,增大随机性,减少hash碰撞的概率; 

    3.扩大数组范围,使hash值均匀分布,进一步减少hash碰撞的概率。随着数据的增加,误判率随之增加;

     4.返回的结果是概率性的,不是确切的。只能判断数据是否一定不存在,而无法判断数据是否一定存在; 

      5.删除很麻烦。

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值