-
Notifications
You must be signed in to change notification settings - Fork 4
/
bloomfilter.cc
90 lines (82 loc) · 1.75 KB
/
bloomfilter.cc
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#include "bloomfilter.h"
void BloomFilter::setBit(ifstream &f)
{
string line;
while(f >> line)
{
setBit(line);
}
}
bool BloomFilter::checkBit(ifstream &f)
{
string line;
while(f >> line)
{
if(!checkBit(line))
cout << line << endl;
}
}
void BloomFilter::setBit(const string &s)
{
unsigned int bitpos = 0;
const char *str = s.c_str();
int len = s.size();
bitpos = RSHash(str, len);
setBit(bitpos);
bitpos = JSHash(str, len);
setBit(bitpos);
bitpos = PJWHash(str, len);
setBit(bitpos);
bitpos = ELFHash(str, len);
setBit(bitpos);
bitpos = BKDRHash(str, len);
setBit(bitpos);
bitpos = SDBMHash(str, len);
setBit(bitpos);
bitpos = DJBHash(str, len);
setBit(bitpos);
bitpos = DEKHash(str, len);
setBit(bitpos);
bitpos = BPHash(str, len);
setBit(bitpos);
bitpos = FNVHash(str, len);
setBit(bitpos);
}
bool BloomFilter::checkBit(const string &s)
{
unsigned int bitpos = 0;
const char *str = s.c_str();
int len = s.size();
bool rev = true;
bitpos = RSHash(str, len);
rev &= checkBit(bitpos);
bitpos = JSHash(str, len);
rev &= checkBit(bitpos);
bitpos = PJWHash(str, len);
rev &= checkBit(bitpos);
bitpos = ELFHash(str, len);
rev &= checkBit(bitpos);
bitpos = BKDRHash(str, len);
rev &= checkBit(bitpos);
bitpos = SDBMHash(str, len);
rev &= checkBit(bitpos);
bitpos = DJBHash(str, len);
rev &= checkBit(bitpos);
bitpos = DEKHash(str, len);
rev &= checkBit(bitpos);
bitpos = BPHash(str, len);
rev &= checkBit(bitpos);
bitpos = FNVHash(str, len);
rev &= checkBit(bitpos);
return rev;
}
void BloomFilter::setBit(unsigned int count)
{
count = count % (SIZE * 8);
vec[count / 8] |= (1 << (count % 8));
}
bool BloomFilter::checkBit(unsigned int count)
{
count = count % (SIZE * 8);
return vec[count / 8] &= (1 << (count % 8));
}