Skip to main content

ExpiringAtomicFilter

Struct ExpiringAtomicFilter 

Source
pub struct ExpiringAtomicFilter<H = DefaultHasher>
where H: Hasher + Default,
{ pub ttl: u64, pub expiration_period: u64, pub created: u64, /* private fields */ }
Expand description

A serializable approximate membership query filter supporting lock-free concurrency and time-based expiration.

Fields§

§ttl: u64

Number of seconds each item is expected to remain in the filter. Items may remain up to ttl + expiration_period, but no longer than that. Must be a multiple of expiration_period.

§expiration_period: u64

Maximum number of seconds between expiration events.

§created: u64

Unix timestamp of when the filter was created. Needed to determine which slot in the buffer is selected for insert, lock, and expire operations.

Implementations§

Source§

impl<H> ExpiringAtomicFilter<H>
where H: Hasher + Default,

Source

pub fn insert<T: ?Sized + Hash>(&self, item: &T) -> Result<(), Error>

Insert an item into the filter.

Returns Ok(()) if the item was inserted, or Error::NotEnoughSpace if the filter is full.

https://docs.rs/atomic-cuckoo-filter/*/atomic_cuckoo_filter/struct.CuckooFilter.html#method.insert

Source

pub fn insert_unique<T: ?Sized + Hash>(&self, item: &T) -> Result<bool, Error>

Check if an item is in the filter and insert it if is not present (atomically).

Returns Ok(true) if the item was inserted, Ok(false) if it was already present, or Error::NotEnoughSpace if the filter is full.

https://docs.rs/atomic-cuckoo-filter/*/atomic_cuckoo_filter/struct.CuckooFilter.html#method.insert_unique

Source

pub fn count<T: ?Sized + Hash>(&self, item: &T) -> usize

Source

pub fn remove<T: ?Sized + Hash>(&self, item: &T) -> bool

Attempts to remove an item from the filter.

Returns true if the item was successfully removed, or false if it was not found.

https://docs.rs/atomic-cuckoo-filter/*/atomic_cuckoo_filter/struct.CuckooFilter.html#method.remove

Source

pub fn contains<T: ?Sized + Hash>(&self, item: &T) -> bool

Check if an item is in the filter.

Returns true if the item is possibly in the filter (may have false positives), false if it is definitely not in the filter.

https://docs.rs/atomic-cuckoo-filter/*/atomic_cuckoo_filter/struct.CuckooFilter.html#method.contains

Source

pub fn len(&self) -> usize

Get the number of elements in the filter.

Source

pub fn is_empty(&self) -> bool

Check if the filter is empty.

Source

pub fn capacity(&self) -> usize

Get the capacity of the filter.

Source

pub fn clear(&self)

Clear the filter, removing all elements.

Source

pub fn lock(&self, kind: LockKind) -> Option<Lock<'_>>

Acquires a lock on the filter, if necessary.

Returns Some(Lock) if a lock is needed, or None if no locking is required.

https://docs.rs/atomic-cuckoo-filter/*/atomic_cuckoo_filter/struct.CuckooFilter.html#method.lock

Source

pub fn expire(&self) -> usize

Returns the number of items that were removed.

Source

pub fn expire_as_of(&self, now: u64) -> usize

Returns the number of items that were removed.

Source§

impl ExpiringAtomicFilter<DefaultHasher>

Source

pub fn builder() -> ExpiringAtomicFilterBuilder<DefaultHasher>

Create a new ExpiringAtomicFilterBuilder with default settings

Source

pub fn new() -> ExpiringAtomicFilter<DefaultHasher>

Create a new ExpiringAtomicFilter with default settings

Source

pub fn with_capacity(capacity: usize) -> ExpiringAtomicFilter<DefaultHasher>

Create a new ExpiringAtomicFilter with the specified capacity

Trait Implementations§

Source§

impl<H> Debug for ExpiringAtomicFilter<H>
where H: Hasher + Default + Debug,

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for ExpiringAtomicFilter<DefaultHasher>

Source§

fn default() -> Self

Create a new CuckooFilter with default settings

Source§

impl<'de, H> Deserialize<'de> for ExpiringAtomicFilter<H>
where H: Hasher + Default,

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl<H> Serialize for ExpiringAtomicFilter<H>
where H: Hasher + Default,

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations§

§

impl<H> Freeze for ExpiringAtomicFilter<H>

§

impl<H> RefUnwindSafe for ExpiringAtomicFilter<H>
where H: RefUnwindSafe,

§

impl<H> Send for ExpiringAtomicFilter<H>
where H: Send,

§

impl<H> Sync for ExpiringAtomicFilter<H>
where H: Sync,

§

impl<H> Unpin for ExpiringAtomicFilter<H>
where H: Unpin,

§

impl<H> UnwindSafe for ExpiringAtomicFilter<H>
where H: UnwindSafe,

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

Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,