[−][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.contains(&"A", 9)); assert!(!vclock.contains(&"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(&mut self, actor: &A) -> u64
[src]
Returns the next event for the actor
while updating its entry in the
clock.
Examples
use threshold::*; let actor_a = "A"; let actor_b = "B"; let mut clock = VClock::new(); let next = clock.next(&actor_a); assert_eq!(next, 1); let next = clock.next(&actor_a); assert_eq!(next, 2); let next = clock.next(&actor_a); assert_eq!(next, 3);
pub fn add(&mut self, actor: &A, seq: u64) -> bool
[src]
Adds an event to the clock.
If the clock did not have this event present, true
is returned.
If the clock did have this event present, false
is returned.
Examples
use threshold::*; let actor_a = "A"; let actor_b = "B"; let mut clock = VClock::new(); assert!(!clock.contains(&actor_a, 1)); clock.add(&actor_a, 1); assert!(clock.contains(&actor_a, 1)); assert!(!clock.contains(&actor_b, 1)); clock.add(&actor_b, 1); assert!(clock.contains(&actor_b, 1));
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.contains(&actor_a, 10)); assert!(clock_a.contains(&actor_a, 11)); assert!(!clock_a.contains(&actor_a, 21));
pub fn contains(&self, actor: &A, seq: u64) -> bool
[src]
Checks if an event is part of the clock.
Examples
use threshold::*; let actor_a = "A"; let mut clock = VClock::new(); assert!(!clock.contains(&actor_a, 1)); clock.add(&actor_a, 1); assert!(clock.contains(&actor_a, 1)); assert!(!clock.contains(&actor_a, 2)); clock.add(&actor_a, 3); assert!(clock.contains(&actor_a, 1)); assert!(clock.contains(&actor_a, 2)); assert!(clock.contains(&actor_a, 3));
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(&actor_a); let event = clock_a.next(&actor_a); clock_b.join(&clock_a); assert!(clock_b.contains(&actor_a, event));
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 mut clock = VClock::new(); clock.add(&actor_a, 1); clock.add(&actor_a, 2); clock.add(&actor_a, 3); 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: Default + Actor, E: Default + EventSet> Default for Clock<A, E>
[src]
impl<'de, A: Actor, E: EventSet> Deserialize<'de> for Clock<A, E> where
A: Deserialize<'de>,
E: Deserialize<'de>,
[src]
A: Deserialize<'de>,
E: Deserialize<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error> where
__D: Deserializer<'de>,
[src]
__D: Deserializer<'de>,
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(&"A"); clock.next(&"A"); clock.next(&"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> Serialize for Clock<A, E> where
A: Serialize,
E: Serialize,
[src]
A: Serialize,
E: Serialize,
fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error> where
__S: Serializer,
[src]
__S: Serializer,
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> DeserializeOwned for T where
T: Deserialize<'de>,
[src]
T: Deserialize<'de>,
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>,