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

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

Implementations

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

pub fn new() -> Self[src]

Returns a new TClock instance.

pub fn with_capacitiy(capacity: usize) -> Self[src]

Returns a new TClock instance with a given capacity.

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>, bool)[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, true));
assert_eq!(tclock.threshold_union(2), (vclock_t2, false));
assert_eq!(tclock.threshold_union(3), (vclock_t3, false));

pub fn union(&self) -> (VClock<A>, bool)[src]

Computes the union of all VClock added to the TClock. A boolean is also returned indicating whether all VClock added are equal.

Examples

use threshold::{clock, *};

let vclock_0 = clock::vclock_from_seqs(vec![10, 5, 5]);
let vclock_1 = clock::vclock_from_seqs(vec![9, 8, 7]);

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

let expected = clock::vclock_from_seqs(vec![10, 8, 7]);
assert_eq!(tclock.union(), (expected, false));

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

let expected = clock::vclock_from_seqs(vec![10, 5, 5]);
assert_eq!(tclock.union(), (expected, true));

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(&b, 5);
clock_a.add(&b, 6);

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

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

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

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

Trait Implementations

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

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

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

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

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

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

Auto Trait Implementations

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

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

Blanket Implementations

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

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

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

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

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

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

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

type Error = Infallible

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.