Skip to content

Commit

Permalink
Added bfilter_intersect
Browse files Browse the repository at this point in the history
  • Loading branch information
jakogut committed Jun 12, 2011
1 parent a161bd7 commit d40affb
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
13 changes: 12 additions & 1 deletion tinybloom.c
Expand Up @@ -23,7 +23,7 @@ THE SOFTWARE. */
#include <stdlib.h>
#include <string.h>

#include <tinybloom.h>
#include "tinybloom.h"

#define GETBIT(a, n) ((a[n >> 5] & (1 << (n & 31))) > 0)
#define SETBIT(a, n) (a[n >> 5] |= 1 << (n & 31))
Expand Down Expand Up @@ -62,3 +62,14 @@ int bfilter_check(const bloom_filter* bFilter, const unsigned* input)
{
return GETBIT(bFilter->filter, *input % bFilter->num_buckets);
}

int bfilter_intersect(bloom_filter* a, bloom_filter* b)
{
if(a->filter_size != b->filter_size) return 1;

int i;
for(i = 0; i < a->filter_size; i++)
a->filter[i] |= b->filter[i];

return 0;
}
3 changes: 3 additions & 0 deletions tinybloom.h
Expand Up @@ -44,6 +44,9 @@ inline void bfilter_add(const bloom_filter* bFilter, const unsigned* input);
// Checks the bloom filter for potential matches; may return a false positive.
inline int bfilter_check(const bloom_filter* bFilter, const unsigned* input);

// Binary OR for bloom filters
inline int bfilter_intersect(bloom_filter* a, bloom_filter* b);

#ifdef __cplusplus
}
#endif
Expand Down

0 comments on commit d40affb

Please sign in to comment.