axiomhq / rust-cuckoofilter

Cuckoo Filter: Practically Better Than Bloom (In Rust)
MIT License
271 stars 38 forks source link

Deserialization fails when changing FINGERPRINT_SIZE #39

Closed npazosmendez closed 4 years ago

npazosmendez commented 4 years ago

It seems like From<ExportedCuckooFilter> for CuckooFilter<H> is assuming FINGERPRINT_SIZE is 1 byte, or that BUCKET_SIZE is referring to byte-count rather than fingerprint-count. This does not panic but deserializes the data incorrectly when FINGERPRINT_SIZE is changed.

https://github.com/axiomhq/rust-cuckoofilter/blob/67c9a4e266c4cdfc974226e5427d0a6912d73242/src/lib.rs#L296

To reproduce just change FINGERPRINT_SIZE to 2 and run cargo test.

Changing that line to .chunks(BUCKET_SIZE*FINGERPRINT_SIZE) fixes the bug. Or maybe introduce a separate constant that refers to the bucket size measured in byes. I'll be submitting a small PR if that's fine 🙂