-
Notifications
You must be signed in to change notification settings - Fork 0
/
bloomFilter.c
61 lines (49 loc) · 1.4 KB
/
bloomFilter.c
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
#include <stdlib.h>
static int* pruning = NULL;
static int nPruning = 0;
static const int hashMod = sizeof(int) * 8;
void initPruning(const int nGraphs) {
nPruning = nGraphs;
if ((pruning = malloc(nGraphs * sizeof(int)))) {
int i;
for (i=0; i<nGraphs; ++i) {
pruning[i] = 0;
}
}
}
void freePruning() {
free(pruning);
}
int hashID(const int elementID) {
return 1<<(elementID % (hashMod));
}
void addToPruningSet(const int elementID, const int index) {
pruning[index] |= hashID(elementID);
}
void resetPruningSet(const int index) {
pruning[index] = 0;
}
/* if the current index is larger than the pruning array aka. bloom filter array,
double the size of the array. Then add the id hash to the filter. This method is
useful for getVertexAndEdgeHistograms as we might not know the correct number of
graphs in the database */
void initialAddToPruningSet(const int elementID, const int index) {
if (index >= nPruning) {
int i;
pruning = realloc(pruning, 2 * nPruning * sizeof(int));
for (i=nPruning; i<2*nPruning; ++i) {
pruning[i] = 0;
}
nPruning *= 2;
}
addToPruningSet(elementID, index);
}
char containedInPruningSet(const int elementID, const int index) {
return (pruning[index] & hashID(elementID)) != 0;
}
char isSubset(const int fingerPrint, const int index) {
return ((pruning[index] & fingerPrint) == fingerPrint);
}
char isEmpty(const int index) {
return pruning[index] == 0;
}