[][src]Struct threshold::tclock::TClock

pub struct TClock<A: Actor, E: EventSet> { /* fields omitted */ }

Methods

impl<A: Actor, E: EventSet> TClock<A, E>[src]

pub fn new() -> Self[src]

Returns a new TClock instance.

pub fn add(&mut self, clock: Clock<A, E>)[src]

Add a Clock to the TClock.

Examples

use threshold::{clock, *};

let mut tset = TClock::new();

let vclock = clock::vclock_from_seqs(1..10);
tset.add(vclock);

impl<A: Actor> TClock<A, MaxSet>[src]

pub fn threshold_union(&self, threshold: u64) -> VClock<A>[src]

Computes the threshold-union of all VClock added to the TClock.

Assume multiset X is {10: 1, 8: 2, 6: 3, 5: 1}. This means that event 10 was seen once, event 8 twice, and so on.

(Recall that for vector clocks, seeing event 10 means seeing all events from 1 to 10.)

If, for example, we want the event that was seen at least 4 times (i.e. our threshold is 4), we should get event 6.

Assume threshold(u64, X) -> Option<u64> where the first argument is the threshold desired. Then:

  • threshold(1, X) = Some(10)
  • threshold(2, X) = Some(8)
  • threshold(3, X) = Some(8)
  • threshold(4, X) = Some(6)
  • threshold(7, X) = Some(5)
  • threshold(8, X) = None

Examples

use threshold::{clock, *};
let vclock_0 = clock::vclock_from_seqs(vec![10, 5, 5]);
let vclock_1 = clock::vclock_from_seqs(vec![8, 10, 6]);
let vclock_2 = clock::vclock_from_seqs(vec![9, 8, 7]);

let mut tclock = TClock::new();
tclock.add(vclock_0);
tclock.add(vclock_1);
tclock.add(vclock_2);

let vclock_t1 = clock::vclock_from_seqs(vec![10, 10, 7]);
let vclock_t2 = clock::vclock_from_seqs(vec![9, 8, 6]);
let vclock_t3 = clock::vclock_from_seqs(vec![8, 5, 5]);

assert_eq!(tclock.threshold_union(1), vclock_t1);
assert_eq!(tclock.threshold_union(2), vclock_t2);
assert_eq!(tclock.threshold_union(3), vclock_t3);

impl<A: Actor> TClock<A, BelowExSet>[src]

pub fn threshold_union(&self, threshold: u64) -> BEClock<A>[src]

Computes the threshold-union of all BEClock added to the TClock.

Examples

use threshold::*;

let b = String::from("B");
let mut clock_a = BEClock::new();
clock_a.add_dot(&Dot::new(&b, 5));
clock_a.add_dot(&Dot::new(&b, 6));

let mut clock_b = BEClock::new();
clock_b.add_dot(&Dot::new(&b, 5));
clock_b.add_dot(&Dot::new(&b, 7));

let mut tclock = TClock::new();
tclock.add(clock_a);
tclock.add(clock_b);

let mut expected = BEClock::new();
expected.add_dot(&Dot::new(&b, 5));

assert_eq!(tclock.threshold_union(2), expected);

Auto Trait Implementations

impl<A, E> Send for TClock<A, E> where
    A: Send,
    E: Send

impl<A, E> Sync for TClock<A, E> where
    A: Sync,
    E: Sync

impl<A, E> Unpin for TClock<A, E> where
    A: Unpin,
    E: Unpin

impl<A, E> UnwindSafe for TClock<A, E> where
    A: UnwindSafe,
    E: UnwindSafe

impl<A, E> RefUnwindSafe for TClock<A, E> where
    A: RefUnwindSafe,
    E: RefUnwindSafe

Blanket Implementations

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = !

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> Any for T where
    T: 'static + ?Sized
[src]