mmap doesn't work on Python 3
remram44 opened this issue · comments
>>> f = BloomFilter(max_elements=10_000_000, error_rate=0.02, filename=('/tmp/bloom.bin', -1))
>>> f.add('test')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "site-packages/bloom_filter/bloom_filter.py", line 560, in add
self.backend.set(bitno)
File "site-packages/bloom_filter/bloom_filter.py", line 113, in set
byte = ord(char)
TypeError: ord() expected string of length 1, but int found
In Python 3, indexing a bytes
object gives int
, there is no need to call ord()
. You can make the code compatible with both Python 2 and 3 by using a slice instead:
array = b'123'
idx = 1
# PY2
a = ord(array[idx])
# PY3
b = array[idx]
# PY2 or PY3
c = ord(array[idx:idx + 1])
assert a == b == c == 50
This project seems unmaintained, so I fixed this in a fork: https://github.com/remram44/python-bloom-filter
I also added CI, did a bunch of general code fixes, and incorporated #5 and #8.
Note that I dropped PY2 support for convenience.