[−][src]Struct threshold::clock::Clock
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 is_empty(&self) -> bool
[src]
Checks that a clock is empty.
Examples
use threshold::*; let a = ("A", MaxSet::from_event(10)); let b = ("B", MaxSet::from_event(20)); let mut vclock = Clock::from(vec![a, b]); assert!(!vclock.is_empty()); vclock = VClock::new(); assert!(vclock.is_empty());
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 add_range(&mut self, actor: &A, start: u64, end: u64) -> bool
[src]
Adds a range of events to the clock.
Examples
use threshold::*; let actor_a = "A"; let actor_b = "B"; let mut clock_a = VClock::new(); clock_a.add_range(&actor_a, 10, 20); assert!(clock_a.is_element(&Dot::new(&actor_a, 10))); assert!(clock_a.is_element(&Dot::new(&actor_a, 11))); assert!(!clock_a.is_element(&Dot::new(&actor_a, 21)));
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(3)); assert_eq!(clock.frontier_threshold(2), Some(2)); 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(3)); assert_eq!(clock.frontier_threshold(2), Some(2)); assert_eq!(clock.frontier_threshold(3), Some(1)); let clock = clock::vclock_from_seqs(vec![4, 4, 5, 3, 2]); assert_eq!(clock.frontier_threshold(1), Some(5)); assert_eq!(clock.frontier_threshold(2), Some(4)); assert_eq!(clock.frontier_threshold(3), Some(4)); assert_eq!(clock.frontier_threshold(4), Some(3)); assert_eq!(clock.frontier_threshold(5), Some(2)); 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));
pub fn subtract_iter<S: EventSet>(
&self,
actor: &A,
subtract: S
) -> impl Iterator<Item = u64>
[src]
&self,
actor: &A,
subtract: S
) -> impl Iterator<Item = u64>
Subtracts an event subtract
to the events generated by some actor
.
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(); clock.add_dot(&dot_a1); clock.add_dot(&dot_a2); clock.add_dot(&dot_a3); let subtract = MaxSet::from_event(0); let subtracted: Vec<_> = clock.subtract_iter(&actor_a, subtract).collect(); assert_eq!(subtracted, vec![1, 2, 3]); let subtract = MaxSet::from_event(1); let subtracted: Vec<_> = clock.subtract_iter(&actor_a, subtract).collect(); assert_eq!(subtracted, vec![2, 3]); let subtract = MaxSet::from_event(2); let subtracted: Vec<_> = clock.subtract_iter(&actor_a, subtract).collect(); assert_eq!(subtracted, vec![3]); let subtract = MaxSet::from_event(3); let subtracted: Vec<_> = clock.subtract_iter(&actor_a, subtract).collect(); assert_eq!(subtracted, vec![]);
Trait Implementations
impl<A: Clone + Actor, E: Clone + EventSet> Clone for Clock<A, E>
[src]
impl<A: Debug + Actor, E: Debug + EventSet> Debug for Clock<A, E>
[src]
impl<A: Eq + Actor, E: Eq + EventSet> Eq for Clock<A, E>
[src]
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: Actor, E: EventSet> StructuralEq for Clock<A, E>
[src]
impl<A: Actor, E: EventSet> StructuralPartialEq for Clock<A, E>
[src]
Auto Trait Implementations
impl<A, E> RefUnwindSafe for Clock<A, E> where
A: RefUnwindSafe,
E: RefUnwindSafe,
A: RefUnwindSafe,
E: RefUnwindSafe,
impl<A, E> Send for Clock<A, E> where
A: Send,
E: Send,
A: Send,
E: Send,
impl<A, E> Sync for Clock<A, E> where
A: Sync,
E: Sync,
A: Sync,
E: Sync,
impl<A, E> Unpin for Clock<A, E> where
A: Unpin,
E: Unpin,
A: Unpin,
E: Unpin,
impl<A, E> UnwindSafe for Clock<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<I> IntoIterator for I where
I: Iterator,
[src]
I: Iterator,
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?
fn into_iter(self) -> I
[src]
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T
[src]
fn clone_into(&self, target: &mut T)
[src]
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>,