Struct crdts::vclock::VClock
[−]
[src]
pub struct VClock<A: Ord + Clone> { pub dots: BTreeMap<A, Counter>, }
A VClock
is a standard vector clock.
It contains a set of "actors" and associated counters.
When a particular actor witnesses a mutation, their associated
counter in a VClock
is incremented. VClock
is typically used
as metadata for associated application data, rather than as the
container for application data. VClock
just tracks causality.
It can tell you if something causally descends something else,
or if different replicas are "concurrent" (were mutated in
isolation, and need to be resolved externally).
Fields
dots: BTreeMap<A, Counter>
dots is the mapping from actors to their associated counters
Methods
impl<A: Ord + Clone> VClock<A>
[src]
fn new() -> VClock<A>
Returns a new VClock
instance.
fn witness(&mut self, actor: A, counter: Counter) -> Result<(), ()>
For a particular actor, possibly store a new counter if it dominates.
Examples
use crdts::VClock; let (mut a, mut b) = (VClock::new(), VClock::new()); a.witness("A", 2); a.witness("A", 0); // ignored because 2 dominates 0 b.witness("A", 1); assert!(a > b);
fn increment(&mut self, actor: A) -> Counter
For a particular actor, increment the associated counter.
Examples
use crdts::VClock; let (mut a, mut b) = (VClock::new(), VClock::new()); a.increment("A"); a.increment("A"); a.witness("A", 0); // ignored because 2 dominates 0 b.increment("A"); assert!(a > b);
fn merge(&mut self, other: VClock<A>)
Merge another vector clock into this one, without regard to dominance.
Examples
use crdts::VClock; let (mut a, mut b, mut c) = (VClock::new(), VClock::new(), VClock::new()); a.increment("A"); b.increment("B"); c.increment("A"); c.increment("B"); a.merge(b); assert_eq!(a, c);
fn contains_descendent_element(&self, actor: &A, counter: &Counter) -> bool
Determine if a single element is present and descendent. Generally prefer using the higher-level comparison operators between vclocks over this specific method.
fn concurrent(&self, other: &VClock<A>) -> bool
True if two vector clocks have diverged.
Examples
use crdts::VClock; let (mut a, mut b) = (VClock::new(), VClock::new()); a.increment("A"); b.increment("B"); assert!(a.concurrent(&b));
fn get(&self, actor: &A) -> Option<Counter>
Return the associated counter for this actor, if present.
fn is_empty(&self) -> bool
Returns true
if this vector clock contains nothing.
fn dominating_dots(&self, dots: BTreeMap<A, Counter>) -> BTreeMap<A, Counter>
Return the dots that self dominates compared to another clock.
fn dominating_vclock(&self, other: VClock<A>) -> VClock<A>
Return a new VClock
that contains the entries for which we have
a counter that dominates another VClock
.
Examples
use crdts::VClock; let (mut a, mut b) = (VClock::new(), VClock::new()); a.witness("A", 3); a.witness("B", 2); a.witness("D", 14); a.witness("G", 22); b.witness("A", 4); b.witness("B", 1); b.witness("C", 1); b.witness("D", 14); b.witness("E", 5); b.witness("F", 2); let dom = a.dominating_vclock(b); assert_eq!(dom.get(&"B"), Some(2)); assert_eq!(dom.get(&"G"), Some(22));
fn intersection(&self, other: VClock<A>) -> VClock<A>
Returns the common elements (same actor and counter)
for two VClock
instances.
Trait Implementations
impl<A: Hash + Ord + Clone> Hash for VClock<A>
[src]
fn hash<__HA: Hasher>(&self, __arg_0: &mut __HA)
Feeds this value into the state given, updating the hasher as necessary.
fn hash_slice<H>(data: &[Self], state: &mut H) where H: Hasher
1.3.0
Feeds a slice of this type into the state provided.
impl<A: Eq + Ord + Clone> Eq for VClock<A>
[src]
impl<A: PartialEq + Ord + Clone> PartialEq for VClock<A>
[src]
fn eq(&self, __arg_0: &VClock<A>) -> bool
This method tests for self
and other
values to be equal, and is used by ==
. Read more
fn ne(&self, __arg_0: &VClock<A>) -> bool
This method tests for !=
.
impl<A: Ord + Ord + Clone> Ord for VClock<A>
[src]
fn cmp(&self, __arg_0: &VClock<A>) -> Ordering
This method returns an Ordering
between self
and other
. Read more
impl<A: Clone + Ord + Clone> Clone for VClock<A>
[src]
fn clone(&self) -> VClock<A>
Returns a copy of the value. Read more
fn clone_from(&mut self, source: &Self)
1.0.0
Performs copy-assignment from source
. Read more
impl<A: Debug + Ord + Clone> Debug for VClock<A>
[src]
impl<A: Ord + Clone> PartialOrd for VClock<A>
[src]
fn partial_cmp(&self, other: &VClock<A>) -> Option<Ordering>
This method returns an ordering between self
and other
values if one exists. Read more
fn lt(&self, other: &Rhs) -> bool
1.0.0
This method tests less than (for self
and other
) and is used by the <
operator. Read more
fn le(&self, other: &Rhs) -> bool
1.0.0
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
fn gt(&self, other: &Rhs) -> bool
1.0.0
This method tests greater than (for self
and other
) and is used by the >
operator. Read more
fn ge(&self, other: &Rhs) -> bool
1.0.0
This method tests greater than or equal to (for self
and other
) and is used by the >=
operator. Read more