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 }