-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBloomFilter.cpp
More file actions
30 lines (27 loc) · 790 Bytes
/
BloomFilter.cpp
File metadata and controls
30 lines (27 loc) · 790 Bytes
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
#include "BloomFilter.h"
void BloomFilter::add(std::string &key) {
for(int i = 0; i < countOfHashFunction; i++)
table.set(getHash(key, i));
}
bool BloomFilter::count(std::string &key) {
for(int i = 0; i < countOfHashFunction; i++)
if(!table.test(getHash(key, i)))
return false;
return true;
}
int BloomFilter::getHash(std::string &key, int hashNumber) {
int result = 0, f = 1;
for(char c : key) {
if(isdigit(c)) {
result += ((c - '0' + 26) * f) % mod[hashNumber];
result %= mod[hashNumber];
}
else {
result += ((c - 'a') * f) % mod[hashNumber];
result %= mod[hashNumber];
}
f *= p[hashNumber];
f %= mod[hashNumber];
}
return result;
}