pybloom2 is a fork of https://github.com/jaybaird/python-bloomfilter.
It includes a Bloom Filter data structure along with
an implementation of Scalable Bloom Filter[1].
>>>frompybloom2importBloomFilter>>>f=BloomFilter(capacity=1000, error_rate=0.001)
>>> [f.add(x) forxinrange(10)]
[False, False, False, False, False, False, False, False, False, False]
>>>all([(xinf) forxinrange(10)])
True>>>10infFalse>>>5infTrue>>>f=BloomFilter(capacity=1000, error_rate=0.001)
>>>foriinxrange(0, f.capacity):
... _=f.add(i)
>>> (1.0- (len(f) /float(f.capacity))) <=f.error_rate+2e-18True>>>frompybloom2importScalableBloomFilter>>>sbf=ScalableBloomFilter(mode=ScalableBloomFilter.SMALL_SET_GROWTH)
>>>count=10000>>>foriinxrange(0, count):
... _=sbf.add(i)
...
>>> (1.0- (len(sbf) /float(count))) <=sbf.error_rate+2e-18True# len(sbf) may not equal the entire input length. 0.01% error is well# below the default 0.1% error threshold. As the capacity goes up, the# error will approach 0.1%.[1] P. Almeida, C.Baquero, N. Preguiça, D. Hutchison, Scalable Bloom Filters, (GLOBECOM 2007), IEEE, 2007. http://www.sciencedirect.com/science/article/pii/S0020019006003127