Crates.io | scalable_cuckoo_filter |
lib.rs | scalable_cuckoo_filter |
version | 0.3.2 |
source | src |
created_at | 2018-01-20 08:06:17.24486 |
updated_at | 2024-04-24 08:25:32.897117 |
description | A variant of Cuckoo Filter whose size automatically scales as necessary |
homepage | https://github.com/sile/scalable_cuckoo_filter |
repository | https://github.com/sile/scalable_cuckoo_filter |
max_upload_size | |
id | 47504 |
size | 41,933 |
A variant of Cuckoo Filter whose size automatically scales as necessary.
Basic usage:
use scalable_cuckoo_filter::ScalableCuckooFilter;
let mut filter = ScalableCuckooFilter::new(100, 0.001);
assert!(!filter.contains("foo"));
filter.insert("foo");
assert!(filter.contains("foo"));
Filter grows automatically:
use scalable_cuckoo_filter::ScalableCuckooFilter;
let mut filter = ScalableCuckooFilter::new(100, 0.001);
assert_eq!(filter.capacity(), 128);
for i in 0..1000 {
filter.insert(&i);
}
assert_eq!(filter.capacity(), 1923);
Filter shrinking:
use scalable_cuckoo_filter::ScalableCuckooFilter;
let mut filter = ScalableCuckooFilter::new(1000, 0.001);
for i in 0..100 {
filter.insert(&i);
}
assert_eq!(filter.capacity(), 1024);
assert_eq!(filter.bits(), 14336);
filter.shrink_to_fit();
for i in 0..100 {
assert!(filter.contains(&i));
}
assert_eq!(filter.capacity(), 128);
assert_eq!(filter.bits(), 1792);