Closed AADeLucia closed 2 years ago
After a quick test I was able to load it back successfully, nevermind! But more detailed documentation about the different backends would be helpful.
There is no saving or loading with mmap
@AADeLucia what did you do to load it back? start_fresh = False
still creating new files :(
This test worked for me:
rom bloom_filter2 import BloomFilter
filename = "bloom_test.bin"
bloom = BloomFilter(
max_elements=1000,
error_rate=0.01,
filename=(filename, -1),
start_fresh=True
)
print("Created bloom filter ", filename)
# Add elements
bloom.add("does")
print("Added 'does'")
bloom.add("this")
print("Added 'this'")
bloom.add("work")
print("Added 'work'")
# Delete
del bloom
print("Delete filter from memory")
# Reload
bloom2 = BloomFilter(
max_elements=1000,
error_rate=0.01,
filename=(filename, -1),
start_fresh=False
)
print("Reload filter from ", filename)
# Test
print("'does' should be in bloom: ", "does" in bloom2)
print("'work' should be in bloom: ", "work" in bloom2)
print("'nope' should not be in bloom: ", "not" in bloom2)
Still not sure what
There is no saving or loading with mmap
is about... I suggested better documentation since this is in the README
It still can be pretty useful to save/load to files with the mmap implementation, for example to avoid rebuilding the bloom filter. The mmap functionality also save some memory depending on system settings.
thanks, @AADeLucia !! I guess i just needed to maintain the same max_elements
and error_rate
params as when it was created. :shrug: :smile:
I am unfamiliar with mmap, but I would love to be able to save/load the Bloom filters. I am unclear on how to load a previously created Bloom filter. Do I have to load it back with
mmap
or just theBloomFilter
withstart_fresh=False
?Thanks.