pub struct AssociatedData { /* private fields */ }Expand description
Provides access to data associated with an item in the filter.
All data is associated by a fingerprint, meaning that collisions (false positives) will also affect the associated data - it might not be related exactly to the requested item, but just to another item that shared the same fingerprint.
This data is a copy of the data in the filter, meaning it will not be updated when filter data is changed and can be freely moved around.
§Examples
use cuckoo_clock::{CuckooFilter, config::{CuckooConfiguration, LruConfig, TtlConfig}};
let filter = CuckooFilter::new_random(
CuckooConfiguration::builder(100_000)
.with_lru(LruConfig::default())
.with_ttl(TtlConfig {
ttl: 10.try_into()?,
ttl_bits: 8.try_into()?,
})
.build()?
);
filter.insert("example_data");
let data = filter.get_associated_data("example_data").unwrap();
assert_eq!(data.get_stored_ttl_value()?, 10);
// `get_associated_data` also increases LRU counter - it is counted as an access
assert_eq!(data.get_lru_counter()?, 2);
Implementations§
Source§impl AssociatedData
impl AssociatedData
Sourcepub fn get_fingerprint(&self) -> u32
pub fn get_fingerprint(&self) -> u32
Returns the fingerprint for this item.
Generally fingerprint is not very useful on its own, depending on the hasher used for
crate::CuckooFilter.
Sourcepub fn get_lru_counter(&self) -> Result<u32, AccessError>
pub fn get_lru_counter(&self) -> Result<u32, AccessError>
Returns the LRU counter for this item.
Sourcepub fn get_counter(&self) -> Result<u32, AccessError>
pub fn get_counter(&self) -> Result<u32, AccessError>
Returns the generic counter for this item.
Sourcepub fn get_stored_ttl_value(&self) -> Result<u32, AccessError>
pub fn get_stored_ttl_value(&self) -> Result<u32, AccessError>
Returns the stored TTL value for this item.
This is not a time to live in seconds. This is just a TTL counter, that is decremented by 1
each time crate::CuckooFilter::scan_and_update_full is called, until it reaches 0.