BelowExSet

Struct BelowExSet 

Source
pub struct BelowExSet { /* private fields */ }

Implementations§

Source§

impl BelowExSet

Source

pub fn from<I: IntoIterator<Item = u64>>(max: u64, iter: I) -> Self

Creates a new instance from the highest event, and a sequence of exceptions.

§Examples
use threshold::*;

let below_exset = BelowExSet::from(5, vec![1, 3]);
assert!(!below_exset.is_event(1));
assert!(below_exset.is_event(2));
assert!(!below_exset.is_event(3));
assert!(below_exset.is_event(4));
assert!(below_exset.is_event(5));
assert!(!below_exset.is_event(6));

Trait Implementations§

Source§

impl Clone for BelowExSet

Source§

fn clone(&self) -> BelowExSet

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for BelowExSet

Source§

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

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

impl Default for BelowExSet

Source§

fn default() -> BelowExSet

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

impl<'de> Deserialize<'de> for BelowExSet

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 EventSet for BelowExSet

Source§

fn new() -> Self

Returns a new BelowExSet instance.

Source§

fn next_event(&mut self) -> u64

Generates the next event. There should be no exceptions when calling this.

§Examples
use threshold::*;

let mut below_exset = BelowExSet::new();
assert_eq!(below_exset.next_event(), 1);
assert_eq!(below_exset.next_event(), 2);
Source§

fn add_event(&mut self, event: u64) -> bool

Adds an event to the set.

§Examples
use threshold::*;

let mut below_exset = BelowExSet::new();

below_exset.add_event(1);
assert!(below_exset.is_event(1));
assert!(!below_exset.is_event(2));

below_exset.add_event(3);
assert!(below_exset.is_event(1));
assert!(!below_exset.is_event(2));
assert!(below_exset.is_event(3));

below_exset.add_event(2);
assert!(below_exset.is_event(1));
assert!(below_exset.is_event(2));
assert!(below_exset.is_event(3));
Source§

fn is_event(&self, event: u64) -> bool

Checks if an event is part of the set.

§Examples
use threshold::*;

let mut below_exset = BelowExSet::new();
let event = below_exset.next_event();
assert!(below_exset.is_event(event));

below_exset.add_event(3);
assert!(!below_exset.is_event(2));
assert!(below_exset.is_event(3));
Source§

fn events(&self) -> (u64, Vec<u64>)

Returns all events seen as a tuple. The first component is the highest event seen, while the second is a vector with the exceptions (in no specific order).

§Examples
use threshold::*;

let mut below_exset = BelowExSet::new();

below_exset.add_event(1);
assert_eq!(below_exset.events(), (1, vec![]));

below_exset.add_event(3);
assert_eq!(below_exset.events(), (3, vec![2]));

below_exset.add_event(2);
assert_eq!(below_exset.events(), (3, vec![]));

below_exset.add_event(4);
assert_eq!(below_exset.events(), (4, vec![]));

below_exset.add_event(6);
assert_eq!(below_exset.events(), (6, vec![5]));
Source§

fn frontier(&self) -> u64

Returns the frontier (the highest contiguous event seen).

Note: this method’s implementation will sort all exceptions on each call, and with that, the performance will not be great. If this becomes a problem, we could cache the frontier (as in AboveExSet) so that it doesn’t have to be computed here on each call.

§Examples
use threshold::*;

let mut below_exset = BelowExSet::new();
assert_eq!(below_exset.frontier(), 0);

below_exset.add_event(1);
assert_eq!(below_exset.frontier(), 1);

below_exset.add_event(3);
assert_eq!(below_exset.frontier(), 1);

below_exset.add_event(2);
assert_eq!(below_exset.frontier(), 3);

below_exset.add_event(4);
assert_eq!(below_exset.frontier(), 4);

below_exset.add_event(6);
assert_eq!(below_exset.frontier(), 4);
Source§

fn join(&mut self, other: &Self)

Merges other BelowExSet into self.

§Examples
use threshold::*;

let mut below_exset = BelowExSet::new();
below_exset.add_event(1);
below_exset.add_event(3);
below_exset.add_event(4);
assert_eq!(below_exset.events(), (4, vec![2]));

below_exset.join(&BelowExSet::from_event(3));
assert_eq!(below_exset.events(), (4, vec![2]));

below_exset.join(&BelowExSet::from_event(5));
assert_eq!(below_exset.events(), (5, vec![2]));

let mut other = BelowExSet::new();
other.add_event(2);
other.add_event(7);
below_exset.join(&other);
assert_eq!(below_exset.events(), (7, vec![6]));
Source§

fn event_iter(self) -> Self::EventIter

Returns a BelowExSet event iterator with all events from lowest to highest.

§Examples
use threshold::*;

let mut below_exset = BelowExSet::new();
below_exset.add_event(3);
below_exset.add_event(5);

let mut iter = below_exset.event_iter();
assert_eq!(iter.next(), Some(3));
assert_eq!(iter.next(), Some(5));
assert_eq!(iter.next(), None);
Source§

type EventIter = EventIter

Source§

fn meet(&mut self, _other: &Self)

Intersects other EventSet with self.
Source§

fn subtracted(&self, _other: &Self) -> Vec<u64>

Return a list of events that remain when other is subtracted from self.
Source§

fn from_event(event: u64) -> Self

Creates a new instance from event.
Source§

fn from_event_range(start: u64, end: u64) -> Self

Creates a new instance from a range of events.
Source§

fn from_events<I: IntoIterator<Item = u64>>(iter: I) -> Self

Creates a new instance from several events.
Source§

fn add_event_range(&mut self, start: u64, end: u64) -> bool

Adds a range of events to the set.
Source§

impl PartialEq for BelowExSet

Source§

fn eq(&self, other: &BelowExSet) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Serialize for BelowExSet

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
Source§

impl Eq for BelowExSet

Source§

impl StructuralPartialEq for BelowExSet

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,