Struct crdts::vclock::VClock [−][src]
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]
A: Clone,
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]
A: Clone,
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]
A: Clone,
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
.
fn validate_op(&self, dot: &Self::Op) -> Result<(), Self::Validation>
[src]
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 = Infallible
The validation error returned by validate_merge
.
fn validate_merge(&self, _other: &Self) -> Result<(), Self::Validation>
[src]
fn merge(&mut self, other: Self)
[src]
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]
A: Deserialize<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error> where
__D: Deserializer<'de>,
[src]
__D: Deserializer<'de>,
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]
fn from_iter<I: IntoIterator<Item = Dot<A>>>(iter: I) -> Self
[src]
impl<A: Hash + Ord> Hash for VClock<A>
[src]
fn hash<__H: Hasher>(&self, state: &mut __H)
[src]
pub fn hash_slice<H>(data: &[Self], state: &mut H) where
H: Hasher,
1.3.0[src]
H: Hasher,
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?
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]
fn partial_cmp(&self, other: &VClock<A>) -> Option<Ordering>
[src]
#[must_use]pub fn lt(&self, other: &Rhs) -> bool
1.0.0[src]
#[must_use]pub fn le(&self, other: &Rhs) -> bool
1.0.0[src]
#[must_use]pub fn gt(&self, other: &Rhs) -> bool
1.0.0[src]
#[must_use]pub fn ge(&self, other: &Rhs) -> bool
1.0.0[src]
impl<A: Ord> ResetRemove<A> for VClock<A>
[src]
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]
A: Serialize,
fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error> where
__S: Serializer,
[src]
__S: Serializer,
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,
A: RefUnwindSafe,
impl<A> Send for VClock<A> where
A: Send,
A: Send,
impl<A> Sync for VClock<A> where
A: Sync,
A: Sync,
impl<A> Unpin for VClock<A>
impl<A> UnwindSafe for VClock<A> where
A: RefUnwindSafe,
A: RefUnwindSafe,
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,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> DeserializeOwned for T where
T: for<'de> Deserialize<'de>,
[src]
T: for<'de> 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<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
pub fn to_owned(&self) -> T
[src]
pub fn clone_into(&self, target: &mut T)
[src]
impl<T> ToString for T where
T: Display + ?Sized,
[src]
T: Display + ?Sized,
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.
pub 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>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
pub fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
V: MultiLane<T>,
pub fn vzip(self) -> V
impl<A, T> Val<A> for T where
A: Ord,
T: Clone + Default + ResetRemove<A> + CmRDT,
[src]
A: Ord,
T: Clone + Default + ResetRemove<A> + CmRDT,