[][src]Trait threshold::EventSet

pub trait EventSet: IntoIterator + Clone + Debug {
    fn new() -> Self;
fn next_event(&mut self) -> u64;
fn add_event(&mut self, event: u64) -> bool;
fn is_event(&self, event: u64) -> bool;
fn events(&self) -> (u64, Vec<u64>);
fn frontier(&self) -> u64;
fn join(&mut self, other: &Self); fn from_event(event: u64) -> Self { ... }
fn from_event_range(start: u64, end: u64) -> Self { ... }
fn from_events<I: IntoIterator<Item = u64>>(iter: I) -> Self { ... }
fn add_event_range(&mut self, start: u64, end: u64) -> bool { ... } }

EventSet trait to be implemented by MaxSet, BelowExSet and AboveExSet.

Required methods

fn new() -> Self

Returns a new instance.

fn next_event(&mut self) -> u64

Generates the next event.

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

Adds an event to the set.

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

Checks if an event is part of the set.

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

Returns all events seen as a pair.

For MaxSet:

  • the first component is the highest event
  • the second component is empty

For BelowExSet:

  • the first component is the highest event
  • the second component is a set of exceptions

For AboveExSet:

  • the first component is the highest event in a contiguous sequence
  • the second component is a set of outstanding events

If we've seen events [1, 2, 3, 5, 6], this function returns in

  • MaxSet: (6, [])
  • BelowExSet: (6, [4])
  • AboveExSet: (3, [5, 6])

fn frontier(&self) -> u64

Returns the frontier (the highest contiguous event seen).

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

Merges other EventSet into self.

Loading content...

Provided methods

fn from_event(event: u64) -> Self

Creates a new instance from event.

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

Creates a new instance from a range of events.

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

Creates a new instance from several events.

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

Adds a range of events to the set.

Loading content...

Implementors

impl EventSet for AboveExSet[src]

fn new() -> Self[src]

Returns a new AboveExSet instance.

fn next_event(&mut self) -> u64[src]

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

Examples

use threshold::*;

let mut above_exset = AboveExSet::new();
assert_eq!(above_exset.next_event(), 1);
assert_eq!(above_exset.next_event(), 2);

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

Adds an event to the set. Returns true if it's a new event.

Examples

use threshold::*;

let mut above_exset = AboveExSet::new();

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

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

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

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

Checks if an event is part of the set.

Examples

use threshold::*;

let mut above_exset = AboveExSet::new();
let event = above_exset.next_event();
assert!(above_exset.is_event(event));

above_exset.add_event(3);
assert!(!above_exset.is_event(2));
assert!(above_exset.is_event(3));

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

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 above_exset = AboveExSet::new();

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

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

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

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

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

fn frontier(&self) -> u64[src]

Returns the frontier (the highest contiguous event seen).

Examples

use threshold::*;

let mut above_exset = AboveExSet::new();
assert_eq!(above_exset.frontier(), 0);

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

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

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

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

above_exset.add_event(6);
assert_eq!(above_exset.frontier(), 4);

fn join(&mut self, other: &Self)[src]

Merges other AboveExSet into self.

Examples

use threshold::*;

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

above_exset.join(&AboveExSet::from_event(3));
assert_eq!(above_exset.events(), (1, vec![3, 4]));

above_exset.join(&AboveExSet::from_event(5));
assert_eq!(above_exset.events(), (1, vec![3, 4, 5]));

let mut other = AboveExSet::new();
other.add_event(2);
other.add_event(7);
above_exset.join(&other);
assert_eq!(above_exset.events(), (5, vec![7]));

impl EventSet for BelowExSet[src]

fn new() -> Self[src]

Returns a new BelowExSet instance.

fn next_event(&mut self) -> u64[src]

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);

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

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));

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

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));

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

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]));

fn frontier(&self) -> u64[src]

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);

fn join(&mut self, other: &Self)[src]

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]));

impl EventSet for MaxSet[src]

fn new() -> Self[src]

Returns a new MaxSet instance.

fn next_event(&mut self) -> u64[src]

Generates the next event.

Examples

use threshold::*;

let mut maxset = MaxSet::new();
assert_eq!(maxset.next_event(), 1);
assert_eq!(maxset.next_event(), 2);

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

Adds an event to the set. Returns true if it's a new event.

Examples

use threshold::*;

let mut maxset = MaxSet::new();
assert!(!maxset.is_event(9));
assert!(!maxset.is_event(10));

maxset.add_event(10);
assert!(maxset.is_event(9));
assert!(maxset.is_event(10));

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

Adds a range of events to the set. Returns true if a new event was added.

In the case of MaxSet we have that:

  • add_event_range(start, end) == add_event(end)

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

Checks if an event is part of the set.

Examples

use threshold::*;

let mut maxset = MaxSet::new();
let event = maxset.next_event();
assert!(maxset.is_event(event));

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

Returns all events seen.

Examples

use threshold::*;

let mut maxset = MaxSet::new();
maxset.add_event(2);
maxset.add_event(4);
assert_eq!(maxset.events(), (4, vec![]));

fn frontier(&self) -> u64[src]

Returns the frontier (the highest contiguous event seen). For a MaxSet, this is not necessarily the highest contiguous event, but simply the highest event. For exact EventSet representations that will actually return the highest contiguous event, see AboveExSet and BelowExSet.

Examples

use threshold::*;

let mut maxset = MaxSet::new();
assert_eq!(maxset.frontier(), 0);

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

maxset.add_event(3);
assert_eq!(maxset.frontier(), 3);

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

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

maxset.add_event(6);
assert_eq!(maxset.frontier(), 6);

fn join(&mut self, other: &Self)[src]

Merges other MaxSet into self.

Examples

use threshold::*;

let mut maxset = MaxSet::from_event(10);
assert!(!maxset.is_event(20));

maxset.join(&MaxSet::from_event(20));
assert!(maxset.is_event(20));
Loading content...