# python 2.7.10
from array import array

class BloomFilter:
    # http://en.wikipedia.org/wiki/Bloom_filter (Ack.: Wikipedia)
    # http://bit.ly/bloom_filter (Ack.: Raymond Hettinger)
    # http://code.activestate.com/recipes/577686/ (me)

    def __init__(self, num_bits, num_probes, probe_func):
        self.num_bits= num_bits
        num_words = (num_bits + 31) // 32
        self.arr = array('L', [0]) * num_words
        self.num_probes = num_probes
        self.probe_func = get_probes

    def add(self, key):
        for i, mask in self.probe_func(self, key):
            self.arr[i] |= mask

    def match_template(self, bfilter):
        return (self.num_bits == bfilter.num_bits \
            and self.num_probes == bfilter.num_probes \
            and self.probe_func == bfilter.probe_func)

    def union(self, bfilter):
        if self.match_template(bfilter):
            self.arr = [a | b for a, b in zip(self.arr, bfilter.arr)]
        else:
            # Union b/w two unrelated bloom filter raises this
            raise ValueError("Mismatched bloom filters")

    def intersection(self, bfilter):
        if self.match_template(bfilter):
            self.arr = [a & b for a, b in zip(self.arr, bfilter.arr)]
        else:
            # Intersection b/w two unrelated bloom filter raises this
            raise ValueError("Mismatched bloom filters")

    def __contains__(self, key):
        return all(self.arr[i] & mask for i, mask in self.probe_func(self, key))
## @ashumeow

@@ -8,16 +8,26 @@
 n 2.7.10
+%0A%0A# import
 %0Afrom ar
@@ -241,14 +241,24 @@
 686/
- (me)%0A
+%0A    %0A    # init
 %0A   
@@ -507,17 +507,31 @@
 _probes%0A
+    %0A    # add
 %0A
-
     def 
@@ -630,16 +630,31 @@
 = mask%0A%0A
+    # matching%0A
     def 
@@ -848,16 +848,28 @@
 _func)%0A%0A
+    # union%0A
     def 
@@ -1128,32 +1128,51 @@
 loom filters%22)%0A%0A
+    # intersection%0A
     def intersec
@@ -1441,24 +1441,41 @@
  filters%22)%0A%0A
+    # finally...%0A
     def __co
@@ -1487,32 +1487,32 @@
 s__(self, key):%0A
-
         return a
@@ -1576,16 +1576,17 @@
 , key))%0A
+%0A
 ## @ashu

Update bloomfilters.py