布隆过滤器之Python+Redis
简单的python实现 pip install mmh3 对于安装报错,c++编译错误问题:可以安装 Microsoft Visual C++ Build Tools() 例子转载(https://www.cnblogs.com/naive/p/5815433.html) from bitarray import bitarray # 3rd party import mmh3 class BloomFilter(set): def __init__(self, size, hash_count): super(BloomFilter, self).__init__() self.bit_array = bitarray(size) self.bit_array.setall(0) self.size = size self.hash_count = hash_count def __len__(self): return self.size def __iter__(self): return iter(self.bit_array) def add(self, item): for ii in range(self.hash_count): index = mmh3.hash(item, ii) % self.size self.bit_array[index] = 1