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

pub struct VClock<A: Ord + Clone + Encodable + Decodable> {
    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

dots is the mapping from actors to their associated counters

Methods

impl<A: Ord + Clone + Encodable + Decodable> 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".to_string(), 2);
a.witness("A".to_string(), 0); // ignored because 2 dominates 0
b.witness("A".to_string(), 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".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);

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".to_string());
b.increment("B".to_string());
c.increment("A".to_string());
c.increment("B".to_string());
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".to_string());
b.increment("B".to_string());
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".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));

fn intersection(&self, other: &VClock<A>) -> VClock<A>

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

Trait Implementations

impl<A: Ord + Clone + Encodable + Decodable> 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

impl Arbitrary for VClock<u16>
[src]

fn arbitrary<G: Gen>(g: &mut G) -> VClock<u16>

fn shrink(&self) -> Box<Iterator<Item=VClock<u16>>>

Derived Implementations

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

fn decode<__DA: Decoder>(__arg_0: &mut __DA) -> Result<VClock<A>, __DA::Error>

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

fn encode<__SA: Encoder>(&self, __arg_0: &mut __SA) -> Result<(), __SA::Error>

impl<A: Hash + Ord + Clone + Encodable + Decodable> 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 + Encodable + Decodable> Eq for VClock<A>
[src]

impl<A: PartialEq + Ord + Clone + Encodable + Decodable> 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 + Encodable + Decodable> 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 + Encodable + Decodable> 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 + Encodable + Decodable> Debug for VClock<A>
[src]

fn fmt(&self, __arg_0: &mut Formatter) -> Result

Formats the value using the given formatter.