Shared2018-02-07-160231.ipynbOpen in CoCalc
A1
import numpy as np
import mmh3
import zlib 
from bitarray import bitarray 

class BloomFilter(object):
    
    def__init__(self, size, k):
        self.bits=np.zeros(size)
        self.k=k
        self.size=size
    def__str__(self):
        returnstr(self.bits)
    def add(self, element):
        element=str(element)
        hash_array=[(hash(element*(i+1))^mmh3.hash(element(i+1)))%self.size
                    for i in range(self.k)]
        for idx in hash_array:
            self.bits[idx]=1
    def search(self, element):
        element=str(element)
        hash_array=[(hash(element*(i+1))^mmh3.hash(element*(i+1)))%self.size
                    for i in range(self.k)] 
        for idx in hash_array:
            if self.bits[idx]==0: return False
        return True
bf=BloomFilter(100,5)
    print bf 
    bf.add("Oren")
    print bf 
    bf.search("Oren"), bf.search('Elisa')
File "<ipython-input-3-f4668a52b51c>", line 1 git init ^ SyntaxError: invalid syntax