布隆过滤器

1.初始化
    8 void BloomFilterInit(BloomFilter* bf)
    9 {
   10     if(bf == NULL)
   11     {
   12         return ;
   13     }
   14     BitmapInit(&bf->bm,BitmapMaxSize);
   15     bf->bloom_hash[0] = SDBMHash;
   16     bf->bloom_hash[1] = BKDRHash;
   17     return ;
   18 }
   19 

2.销毁的实现
   21 void BloomFilterDestroy(BloomFilter* bf)
   22 {
   23     if(bf == NULL)
   24     {
   25         return ;
   26     }
   27     bf->bloom_hash[0] = NULL;
   28     bf->bloom_hash[1] = NULL;
   29     BitmapDestroy(&bf->bm);
   30     return ;
   31 }
   32 

3.插入操作
   33 void BloomFilterInsert(BloomFilter* bf,const char* str)
   34 {
   35     if(bf == NULL || str == NULL)
   36     {
   37         return ;
   38     }
   39     size_t i = 0;
   40     for(; i < BloomHashCount ; ++i)
   41     {
   42         uint64_t hash = bf->bloom_hash[i](str)% BitmapMaxSize;
   43         BitmapSet(&bf->bm,hash);
   44     }
   45     return ;
   46 }
   47 

4.判断是否存在
   49 int BloomFilterIsExit(BloomFilter* bf,const char* str)
   50 {
   51     if(bf == NULL || str == NULL)
   52     {
   53         return 0;
   54     }
   55     size_t i =0;
   56     for(;i < BloomHashCount;++i)
   57     {
   58         uint64_t hash = bf->bloom_hash[i](str)% BitmapMaxSize;
   59         int ret = BitmapTest(&bf->bm,hash);
   60         if(ret == 0)
   61         {
   62             return 0;
   63         }
   64     }
   65     return 1;                                                                                                                    
   66 }

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值