watermark

Struct WatermarkSet

Source
pub struct WatermarkSet<T> {
    pub watermark: T,
    pub recently_added: VecDeque<u64>,
}
Expand description

A watermarking set

Allows insert and contains operations.

Fields§

§watermark: T§recently_added: VecDeque<u64>

Implementations§

Source§

impl<T> WatermarkSet<T>

Source

pub fn new(watermark: T) -> WatermarkSet<T>

Create a new benchmarking set containing all elements less than the first parameter.

let wm = watermark::WatermarkSet::new(1385);
assert!(wm.contains(1384));
assert_eq!(wm.contains(1385), false);
assert_eq!(wm.contains(1386), false);
Source§

impl<T: Integer + CheckedSub + CheckedAdd + FromPrimitive + ToPrimitive> WatermarkSet<T>

Source

pub fn insert(&mut self, elem: T)

Insert an element to the collection

§Example
let mut wm = watermark::WatermarkSet::default();
wm.insert(123);
§Panics

If the collection gets completely full, watermark may overflow the bounds of T, resulting in an unwrap panic on a checked_add.

Source§

impl<T: Integer + ToPrimitive> WatermarkSet<T>

Source

pub fn size(&self) -> usize

Check how many items have been added to the collection

§Example
let mut wm = watermark::WatermarkSet::default();
for i in 0..=63 {
    wm.insert(i);
}
for i in (64..80).step_by(3) {
    wm.insert(i);
}
assert_eq!(wm.size(), 64 + 6)
Source§

impl<T: Integer + CheckedSub + ToPrimitive> WatermarkSet<T>

Source

pub fn contains(&self, elem: T) -> bool

Check if an element has been added to the collection

§Example
let mut wm = watermark::WatermarkSet::default();
wm.insert(1);
assert!(wm.contains(1));
assert_eq!(wm.contains(2), false);

Trait Implementations§

Source§

impl<T: Default> Default for WatermarkSet<T>

Source§

fn default() -> WatermarkSet<T>

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl<T> Freeze for WatermarkSet<T>
where T: Freeze,

§

impl<T> RefUnwindSafe for WatermarkSet<T>
where T: RefUnwindSafe,

§

impl<T> Send for WatermarkSet<T>
where T: Send,

§

impl<T> Sync for WatermarkSet<T>
where T: Sync,

§

impl<T> Unpin for WatermarkSet<T>
where T: Unpin,

§

impl<T> UnwindSafe for WatermarkSet<T>
where T: 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.