Skip to content
This repository has been archived by the owner on Aug 21, 2020. It is now read-only.

save to file? #1

Open
reneeburton opened this issue May 11, 2019 · 0 comments
Open

save to file? #1

reneeburton opened this issue May 11, 2019 · 0 comments

Comments

@reneeburton
Copy link

reneeburton commented May 11, 2019

thanks for creating the library. i've been using a bloom filter, but need the ability to delete items. how would you recommend saving the filter to disk to preserve state over time? bloom_live has a tofile() method, but I don't see a similar option here. pickle the object?

i have tried pickling the object to a file and later reading it back in. There don't seem to be any issues with the write or load, but the reloaded filter doesn't recognize the objects it is supposed to contain. that is, the length of the filter is correct, but the contains() method will return false for any items i know are in there. running something like the below repeatedly inserts the item in the filter.

`def load_cuckoo_filter(path):
try:
old = pickle.load(open(path, 'rb'))
return old
except:
print("creating new filter")
return cuckoopy.CuckooFilter(10000)

def write_cuckoo_filter(filter, path):
pickle.dump(filter, open(path, 'wb'))
return

def main():
data = load('cuckoo.out')
if data.contains('a'):
print("data contains a")
else:
data.insert('a')
write_cuckoo_filter(data, 'cuckoo.out')
`

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant