-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCodedBF.h
74 lines (67 loc) · 1.3 KB
/
CodedBF.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#ifndef CODEDBF_H
#define CODEDBF_H
#include "BloomFilter.h"
#include "tools.h"
class CodedBF{
BloomFilter *bf;
int m;
int k;
int setNum;
int codeLen;
public:
int mc_ins, mc_que;
CodedBF();
CodedBF(int _m, int _k, int s);
~CodedBF();
void insert(ELEMENT *elem);
int query(char *elem);
};
CodedBF::CodedBF(){
mc_ins = 0;
mc_que = 0;
}
CodedBF::CodedBF(int _m, int _k, int s){
mc_ins = 0;
mc_que = 0;
m = _m;
k = _k;
setNum = s;
codeLen = NearestLarger2Power(setNum);
bf = new BloomFilter[codeLen];
for(int i = 0; i < codeLen; ++i)
bf[i].create_ary(_m / codeLen);
}
CodedBF::~CodedBF(){
delete[] bf;
}
void CodedBF::insert(ELEMENT *elem){
unsigned int val = (unsigned int)elem->category;
for(int i = 0; i < codeLen; ++i)
if((val & ((unsigned int)1 << (codeLen - 1 - i))) != 0){
for(int j = i * k + 1; j <= (i + 1) * k; ++j)
{
int pos = hash_k(elem->val, j) % (m / codeLen);
bf[i].set_1(pos);
mc_ins++;
}
}
}
int CodedBF::query(char *elem){
unsigned int val = 0;
for(int i = 0; i < codeLen; ++i)
{
int flag = 1;
for(int j = i * k + 1; j <= (i + 1) * k; ++j){
int pos = hash_k(elem, j) % (m / codeLen);
mc_que++;
if(bf[i].query(pos) != 1){
flag = 0;
break;
}
}
if(flag == 1)
val += (unsigned int)1 << (codeLen - 1 - i);
}
return val;
}
#endif