[][src]Struct threshold::clock::Clock

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

Methods

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

pub fn new() -> Self[src]

Returns a new Clock instance.

pub fn with<I: IntoIterator<Item = A>>(iter: I) -> Self[src]

Returns a new Clock mapping each actor to a bottom entry.

Examples

use std::collections::HashMap;
use std::iter::FromIterator;
use threshold::*;

let actors = vec!["A", "B"];
let vclock = VClock::with(actors);
assert_eq!(
    vclock.frontier(),
    HashMap::from_iter(vec![(&"A", 0), (&"B", 0)]),
);

pub fn from<I: IntoIterator<Item = (A, E)>>(iter: I) -> Self[src]

Creates a Clock from an iterator of tuples (actor identifier and event set).

Examples

use threshold::*;

let a = ("A", MaxSet::from_event(10));
let b = ("B", MaxSet::from_event(20));
let vclock = Clock::from(vec![a, b]);

assert!(vclock.is_element(&Dot::new(&"A", 9)));
assert!(!vclock.is_element(&Dot::new(&"A", 11)));

pub fn len(&self) -> usize[src]

Returns the number of actors in the clock.

Examples

use threshold::*;

let a = ("A", MaxSet::from_event(10));
let b = ("B", MaxSet::from_event(20));
let vclock = Clock::from(vec![a, b]);

assert_eq!(vclock.len(), 2);

pub fn next_dot(&mut self, actor: &A) -> Dot<A>[src]

Returns a new Dot for the actor while updating the clock.

Examples

use threshold::*;

let actor_a = "A";
let actor_b = "B";

let mut clock = VClock::new();
let dot_a1 = clock.next_dot(&actor_a);
assert_eq!(Dot::new(&actor_a, 1), dot_a1);

let dot_a2 = clock.next_dot(&actor_a);
assert_eq!(Dot::new(&actor_a, 2), dot_a2);

let dot_b1 = clock.next_dot(&actor_b);
assert_eq!(Dot::new(&actor_b, 1), dot_b1);

pub fn add_dot(&mut self, dot: &Dot<A>) -> bool[src]

Adds a Dot to the clock. If the clock did not have this Dot present, true is returned. If the clock did have this Dot present, false is returned.

Examples

use threshold::*;

let actor_a = "A";
let actor_b = "B";

let mut clock_a = VClock::new();
let mut clock_b = VClock::new();

let dot_a1 = clock_a.next_dot(&actor_a);

assert!(!clock_b.is_element(&dot_a1));
clock_b.add_dot(&dot_a1);
assert!(clock_b.is_element(&dot_a1));

pub fn add(&mut self, actor: &A, seq: u64) -> bool[src]

Similar to add_dot but does not require a Dot instance.

pub fn is_element(&self, dot: &Dot<A>) -> bool[src]

Checks if an Dot is part of the clock.

Examples

use threshold::*;

let actor_a = "A";

let dot_a1 = Dot::new(&actor_a, 1);
let dot_a2 = Dot::new(&actor_a, 2);
let dot_a3 = Dot::new(&actor_a, 3);

let mut clock = VClock::new();
assert!(!clock.is_element(&dot_a1));
clock.add_dot(&dot_a1);
assert!(clock.is_element(&dot_a1));
assert!(!clock.is_element(&dot_a2));

clock.add_dot(&dot_a3);
assert!(clock.is_element(&dot_a1));
assert!(clock.is_element(&dot_a2));
assert!(clock.is_element(&dot_a3));

pub fn frontier(&self) -> HashMap<&A, u64>[src]

Returns the clock frontier.

Examples

use std::collections::HashMap;
use std::iter::FromIterator;
use threshold::*;

let a = ("A", AboveExSet::from_events(vec![1, 2, 4]));
let b = ("B", AboveExSet::from_events(vec![1, 2, 3, 5, 6]));
let clock = Clock::from(vec![a, b]);

assert_eq!(
    clock.frontier(),
    HashMap::from_iter(vec![(&"A", 2), (&"B", 3)])
);

pub fn frontier_threshold(&self, threshold: usize) -> Option<u64>[src]

By looking at this Clock's frontier, it computes the event that's been generated in at least threshold actors.

Examples

use threshold::{clock, *};

let aset = AboveExSet::from_events(vec![1, 2, 4]);
let bset = AboveExSet::from_events(vec![1, 2, 3, 5]);
let clock = Clock::from(vec![("A", aset), ("B", bset)]);
assert_eq!(clock.frontier_threshold(1), Some(2));
assert_eq!(clock.frontier_threshold(2), Some(3));
assert_eq!(clock.frontier_threshold(3), None);

let aset = AboveExSet::from_events(vec![1, 2, 3, 5]);
let bset = AboveExSet::from_events(vec![1, 2, 3, 5]);
let clock = Clock::from(vec![("A", aset), ("B", bset)]);
assert_eq!(clock.frontier_threshold(1), Some(3));
assert_eq!(clock.frontier_threshold(2), Some(3));

let clock = clock::vclock_from_seqs(vec![2, 1, 3]);
assert_eq!(clock.frontier_threshold(1), Some(1));
assert_eq!(clock.frontier_threshold(2), Some(2));
assert_eq!(clock.frontier_threshold(3), Some(3));

let clock = clock::vclock_from_seqs(vec![4, 4, 5, 3, 2]);
assert_eq!(clock.frontier_threshold(1), Some(2));
assert_eq!(clock.frontier_threshold(2), Some(3));
assert_eq!(clock.frontier_threshold(3), Some(4));
assert_eq!(clock.frontier_threshold(4), Some(4));
assert_eq!(clock.frontier_threshold(5), Some(5));
assert_eq!(clock.frontier_threshold(6), None);

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

Merges vector clock other passed as argument into self. After merge, all events in other are events in self.

Examples

use threshold::*;

let actor_a = "A";
let mut clock_a = VClock::new();
let mut clock_b = VClock::new();

clock_a.next_dot(&actor_a);
let dot_a2 = clock_a.next_dot(&actor_a);

clock_b.join(&clock_a);
assert!(clock_b.is_element(&dot_a2));

Trait Implementations

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

fn clone_from(&mut self, source: &Self)1.0.0[src]

Performs copy-assignment from source. Read more

impl<A: Actor, E: EventSet> IntoIterator for Clock<A, E>[src]

type Item = (A, E)

The type of the elements being iterated over.

type IntoIter = IntoIter<A, E>

Which kind of iterator are we turning this into?

fn into_iter(self) -> Self::IntoIter[src]

Returns a Clock into-iterator.

Examples

use threshold::*;

let mut clock = VClock::new();
clock.next_dot(&"A");
clock.next_dot(&"A");
clock.next_dot(&"B");

for (actor, eset) in clock {
    match actor {
        "A" => assert_eq!(eset, MaxSet::from_event(2)),
        "B" => assert_eq!(eset, MaxSet::from_event(1)),
        _ => panic!("unexpected actor name"),
    }
}

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

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

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

Auto Trait Implementations

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

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

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

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

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

Blanket Implementations

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

type Owned = T

The resulting type after obtaining ownership.

impl<I> IntoIterator for I where
    I: Iterator
[src]

type Item = <I as Iterator>::Item

The type of the elements being iterated over.

type IntoIter = I

Which kind of iterator are we turning this into?

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 = 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.

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

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

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