Seen

Struct Seen 

Source
pub struct Seen<Atom: AtomicNumber = AtomicUsize> { /* private fields */ }
Expand description

A kind of a bloom filter inspired counter.

May give false positives (since it is aggregated), does not do false negative.

It is used in crate::dedup::Dedup to prevent repeating values (of crate::PotentialPresence for instance).

It achieves interior mutability with atomic numbers so it can be used behind a ref or Arc.

use std::sync::atomic::AtomicU16;
use std::sync::Arc;
use presence::seen::Seen;
let dedup = Arc::new(Seen::<AtomicU16>::builder().build().into_dedup());
assert_eq!(dedup.check(0,b"something"),Ok(true));
assert_eq!(dedup.check(0,b"something"),Ok(false));
assert_eq!(dedup.ease(),Ok(()));
assert_eq!(dedup.check(0,b"something"),Ok(true));

Implementations§

Source§

impl<Atom: AtomicNumber> Seen<Atom>

Source

pub fn into_dedup<T>(self) -> Dedup<T, Atom>

Source§

impl<Atom: AtomicNumber> Seen<Atom>

Source

pub fn builder() -> SeenBuilder<Atom>

Source§

impl<Atom: AtomicNumber> Seen<Atom>

Source

pub fn insert(&self, occurrence: &[u8]) -> Option<usize>

Adds the occurrence to the filter.

Returns true if max occurrences have not been reached (inserted). False if not inserted (maxed).

Source

pub fn forget_a_bit(&self)

decrement each counter by one

Source

pub fn forget_all(&self)

clear all counters

Source

pub fn contains(&self, occurrence: &[u8]) -> usize

check how many occurrence there may be

Source

pub fn size(&self) -> usize

Source

pub fn atoms(&self) -> usize

Source

pub fn counter_per_atom(&self) -> usize

Source

pub fn counters(&self) -> usize

Trait Implementations§

Source§

impl<Atom: Debug + AtomicNumber> Debug for Seen<Atom>
where Atom::Number: Debug,

Source§

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

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

impl<AFrom: AtomicNumber, ATo: AtomicNumber> From<&SeenBuilder<AFrom>> for Seen<ATo>
where AFrom::Number: Into<ATo::Number>,

Source§

fn from(value: &SeenBuilder<AFrom>) -> Self

Converts to this type from the input type.
Source§

impl<T, Atom: AtomicNumber> From<Seen<Atom>> for Dedup<T, Atom>

Source§

fn from(value: Seen<Atom>) -> Self

Converts to this type from the input type.
Source§

impl<AFrom: AtomicNumber, ATo: AtomicNumber> From<SeenBuilder<AFrom>> for Seen<ATo>
where AFrom::Number: Into<ATo::Number>,

Source§

fn from(value: SeenBuilder<AFrom>) -> Self

Converts to this type from the input type.

Auto Trait Implementations§

§

impl<Atom> Freeze for Seen<Atom>
where <Atom as AtomicNumber>::Number: Freeze,

§

impl<Atom> RefUnwindSafe for Seen<Atom>

§

impl<Atom> Send for Seen<Atom>
where <Atom as AtomicNumber>::Number: Send, Atom: Send,

§

impl<Atom> Sync for Seen<Atom>
where <Atom as AtomicNumber>::Number: Sync, Atom: Sync,

§

impl<Atom> Unpin for Seen<Atom>
where <Atom as AtomicNumber>::Number: Unpin,

§

impl<Atom> UnwindSafe for Seen<Atom>
where <Atom as AtomicNumber>::Number: UnwindSafe, Atom: 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> Same for T

Source§

type Output = T

Should always be Self
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