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

pub struct VClock<A: Ord + Clone + Serialize + DeserializeOwned> {
    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 is the mapping from actors to their associated counters

Methods

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

[src]

Returns a new VClock instance.

[src]

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".to_string(), 2);
a.witness("A".to_string(), 0); // ignored because 2 dominates 0
b.witness("A".to_string(), 1);
assert!(a > b);

[src]

For a particular actor, increment the associated counter.

Examples

use crdts::VClock;
let (mut a, mut b) = (VClock::new(), VClock::new());
a.increment("A".to_string());
a.increment("A".to_string());
a.witness("A".to_string(), 0); // ignored because 2 dominates 0
b.increment("A".to_string());
assert!(a > b);

[src]

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".to_string());
b.increment("B".to_string());
c.increment("A".to_string());
c.increment("B".to_string());
a.merge(b);
assert_eq!(a, c);

[src]

Determine if a single element is present and descendent. Generally prefer using the higher-level comparison operators between vclocks over this specific method.

[src]

True if two vector clocks have diverged.

Examples

use crdts::VClock;
let (mut a, mut b) = (VClock::new(), VClock::new());
a.increment("A".to_string());
b.increment("B".to_string());
assert!(a.concurrent(&b));

[src]

Return the associated counter for this actor, if present.

[src]

Returns true if this vector clock contains nothing.

[src]

Return the dots that self dominates compared to another clock.

[src]

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".to_string(), 3);
a.witness("B".to_string(), 2);
a.witness("D".to_string(), 14);
a.witness("G".to_string(), 22);

b.witness("A".to_string(), 4);
b.witness("B".to_string(), 1);
b.witness("C".to_string(), 1);
b.witness("D".to_string(), 14);
b.witness("E".to_string(), 5);
b.witness("F".to_string(), 2);

let dom = a.dominating_vclock(&b);
assert_eq!(dom.get(&"B".to_string()), Some(2));
assert_eq!(dom.get(&"G".to_string()), Some(22));

[src]

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

Trait Implementations

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

[src]

Formats the value using the given formatter.

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

[src]

Returns a copy of the value. Read more

1.0.0
[src]

Performs copy-assignment from source. Read more

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

[src]

This method returns an Ordering between self and other. Read more

1.22.0
[src]

Compares and returns the maximum of two values. Read more

1.22.0
[src]

Compares and returns the minimum of two values. Read more

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

[src]

This method tests for self and other values to be equal, and is used by ==. Read more

[src]

This method tests for !=.

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

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

[src]

Feeds this value into the given [Hasher]. Read more

1.3.0
[src]

Feeds a slice of this type into the given [Hasher]. Read more

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

[src]

This method returns an ordering between self and other values if one exists. Read more

1.0.0
[src]

This method tests less than (for self and other) and is used by the < operator. Read more

1.0.0
[src]

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more

1.0.0
[src]

This method tests greater than (for self and other) and is used by the > operator. Read more

1.0.0
[src]

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more