Skip to main content

AssociatedData

Struct AssociatedData 

Source
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

Source

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.

Source

pub fn get_lru_counter(&self) -> Result<u32, AccessError>

Returns the LRU counter for this item.

Source

pub fn get_counter(&self) -> Result<u32, AccessError>

Returns the generic counter for this item.

Source

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.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V