[−][src]Struct threshold::tclock::TClock
Methods
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
Auto Trait Implementations
impl<A, E> RefUnwindSafe for TClock<A, E> where
A: RefUnwindSafe,
E: RefUnwindSafe,
A: RefUnwindSafe,
E: RefUnwindSafe,
impl<A, E> Send for TClock<A, E> where
A: Send,
E: Send,
A: Send,
E: Send,
impl<A, E> Sync for TClock<A, E> where
A: Sync,
E: Sync,
A: Sync,
E: Sync,
impl<A, E> Unpin for TClock<A, E> where
A: Unpin,
E: Unpin,
A: Unpin,
E: Unpin,
impl<A, E> UnwindSafe for TClock<A, E> where
A: UnwindSafe,
E: UnwindSafe,
A: UnwindSafe,
E: UnwindSafe,
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,