[][src]Struct crdts::vclock::VClock

pub struct VClock<A: Ord> {
    pub dots: BTreeMap<A, u64>,
}

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, u64>

dots is the mapping from actors to their associated counters

Implementations

impl<A: Ord> VClock<A>[src]

pub fn new() -> Self[src]

Returns a new VClock instance.

pub fn clone_without(&self, base_clock: &VClock<A>) -> VClock<A> where
    A: Clone
[src]

Returns a clone of self but with information that is older than given clock is forgotten

pub fn inc(&self, actor: A) -> Dot<A> where
    A: Clone
[src]

Generate Op to increment an actor's counter.

Examples

use crdts::{VClock, CmRDT};
let mut a = VClock::new();

// `a.inc()` does not mutate the vclock!
let op = a.inc("A");
assert_eq!(a, VClock::new());

// we must apply the op to the VClock to have
// its edit take effect.
a.apply(op.clone());
assert_eq!(a.get(&"A"), 1);

// Op's can be replicated to another node and
// applied to the local state there.
let mut other_node = VClock::new();
other_node.apply(op);
assert_eq!(other_node.get(&"A"), 1);

pub fn get(&self, actor: &A) -> u64[src]

Return the associated counter for this actor. All actors not in the vclock have an implied count of 0

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

Return the Dot for a given actor

pub fn concurrent(&self, other: &VClock<A>) -> bool[src]

True if two vector clocks have diverged.

Examples

use crdts::{VClock, CmRDT};
let (mut a, mut b) = (VClock::new(), VClock::new());
a.apply(a.inc("A"));
b.apply(b.inc("B"));
assert!(a.concurrent(&b));

pub fn is_empty(&self) -> bool[src]

Returns true if this vector clock contains nothing.

pub fn intersection(left: &VClock<A>, right: &VClock<A>) -> VClock<A> where
    A: Clone
[src]

Returns the common elements (same actor and counter) for two VClock instances.

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

Reduces this VClock to the greatest-lower-bound of the given VClock and itsef, as an example see the following code.

use crdts::{VClock, Dot, ResetRemove, CmRDT};
let mut c = VClock::new();
c.apply(Dot::new(23, 6));
c.apply(Dot::new(89, 14));
let c2 = c.clone();

c.glb(&c2); // this is a no-op since `glb { c, c } = c`
assert_eq!(c, c2);

c.apply(Dot::new(43, 1));
assert_eq!(c.get(&43), 1);
c.glb(&c2); // should remove the 43 => 1 entry
assert_eq!(c.get(&43), 0);

pub fn iter(&self) -> impl Iterator<Item = Dot<&A>>[src]

Returns an iterator over the dots in this vclock

Trait Implementations

impl<A: Ord + Clone + Debug + Arbitrary> Arbitrary for VClock<A>[src]

impl<A: Clone + Ord> Clone for VClock<A>[src]

impl<A: Ord + Clone + Debug> CmRDT for VClock<A>[src]

type Op = Dot<A>

Op defines a mutation to the CRDT. As long as Op's from one actor are replayed in exactly the same order they were generated by that actor, the CRDT will converge. In other words, we must have a total ordering on each actors operations, while requiring only a partial order over all ops. E.g. Read more

type Validation = DotRange<A>

The validation error returned by validate_op.

pub fn apply(&mut self, dot: Self::Op)[src]

Monotonically adds the given actor version to this VClock.

Examples

use crdts::{VClock, Dot, CmRDT};
let mut v = VClock::new();

v.apply(Dot::new("A", 2));

// now all dots applied to `v` from actor `A` where
// the counter is not bigger than 2 are nops.
v.apply(Dot::new("A", 0));
assert_eq!(v.get(&"A"), 2);

impl<A: Ord + Clone + Debug> CvRDT for VClock<A>[src]

type Validation = VacuousValidation

The validation error returned by validate_merge.

impl<A: Debug + Ord> Debug for VClock<A>[src]

impl<A: Ord> Default for VClock<A>[src]

impl<'de, A: Ord> Deserialize<'de> for VClock<A> where
    A: Deserialize<'de>, 
[src]

impl<A: Ord + Display> Display for VClock<A>[src]

impl<A: Eq + Ord> Eq for VClock<A>[src]

impl<A: Ord + Clone + Debug> From<Dot<A>> for VClock<A>[src]

impl<A: Ord + Clone + Debug> FromIterator<Dot<A>> for VClock<A>[src]

impl<A: Hash + Ord> Hash for VClock<A>[src]

impl<A: Ord> IntoIterator for VClock<A>[src]

type Item = Dot<A>

The type of the elements being iterated over.

type IntoIter = IntoIter<A>

Which kind of iterator are we turning this into?

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

Consumes the vclock and returns an iterator over dots in the clock

impl<A: PartialEq + Ord> PartialEq<VClock<A>> for VClock<A>[src]

impl<A: Ord> PartialOrd<VClock<A>> for VClock<A>[src]

impl<A: Ord> ResetRemove<A> for VClock<A>[src]

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

Forget any actors that have smaller counts than the count in the given vclock

impl<A: Ord> Serialize for VClock<A> where
    A: Serialize
[src]

impl<A: Ord> StructuralEq for VClock<A>[src]

impl<A: Ord> StructuralPartialEq for VClock<A>[src]

Auto Trait Implementations

impl<A> RefUnwindSafe for VClock<A> where
    A: RefUnwindSafe
[src]

impl<A> Send for VClock<A> where
    A: Send
[src]

impl<A> Sync for VClock<A> where
    A: Sync
[src]

impl<A> Unpin for VClock<A>[src]

impl<A> UnwindSafe for VClock<A> where
    A: RefUnwindSafe
[src]

Blanket Implementations

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

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

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

impl<T> DeserializeOwned for T where
    T: for<'de> Deserialize<'de>, 
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

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

type Owned = T

The resulting type after obtaining ownership.

impl<T> ToString for T where
    T: Display + ?Sized
[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<V, T> VZip<V> for T where
    V: MultiLane<T>, 

impl<A, T> Val<A> for T where
    A: Ord,
    T: Clone + Default + ResetRemove<A> + CmRDT
[src]