[−][src]Struct crdts::vclock::VClock
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
Methods
impl<A: Actor> VClock<A>
[src]
pub fn new() -> Self
[src]
Returns a new VClock
instance.
pub fn clone_without(&self, base_clock: &VClock<A>) -> VClock<A>
[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>
[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 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 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 is_empty(&self) -> bool
[src]
Returns true
if this vector clock contains nothing.
pub fn intersection(left: &VClock<A>, right: &VClock<A>) -> VClock<A>
[src]
Returns the common elements (same actor and counter)
for two VClock
instances.
pub fn glb(&mut self, other: &VClock<A>)
[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, Causal, 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: Actor> CvRDT for VClock<A>
[src]
impl<A: Actor> 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
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: Actor> Causal<A> for VClock<A>
[src]
fn forget(&mut self, other: &VClock<A>)
[src]
Forget any actors that have smaller counts than the count in the given vclock
impl<A: Actor> PartialOrd<VClock<A>> for VClock<A>
[src]
fn partial_cmp(&self, other: &VClock<A>) -> Option<Ordering>
[src]
#[must_use]
fn lt(&self, other: &Rhs) -> bool
1.0.0[src]
This method tests less than (for self
and other
) and is used by the <
operator. Read more
#[must_use]
fn le(&self, other: &Rhs) -> bool
1.0.0[src]
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
#[must_use]
fn gt(&self, other: &Rhs) -> bool
1.0.0[src]
This method tests greater than (for self
and other
) and is used by the >
operator. Read more
#[must_use]
fn ge(&self, other: &Rhs) -> bool
1.0.0[src]
This method tests greater than or equal to (for self
and other
) and is used by the >=
operator. Read more
impl<A: PartialEq + Actor> PartialEq<VClock<A>> for VClock<A>
[src]
impl<A: Actor> 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: Actor> Default for VClock<A>
[src]
impl<A: Clone + Actor> Clone for VClock<A>
[src]
fn clone(&self) -> VClock<A>
[src]
fn clone_from(&mut self, source: &Self)
1.0.0[src]
Performs copy-assignment from source
. Read more
impl<A: Actor> From<Dot<A>> for VClock<A>
[src]
impl<A: Eq + Actor> Eq for VClock<A>
[src]
impl<A: Hash + Actor> Hash for VClock<A>
[src]
fn hash<__HA: Hasher>(&self, state: &mut __HA)
[src]
fn hash_slice<H>(data: &[Self], state: &mut H) where
H: Hasher,
1.3.0[src]
H: Hasher,
Feeds a slice of this type into the given [Hasher
]. Read more
impl<A: Actor + Display> Display for VClock<A>
[src]
impl<A: Debug + Actor> Debug for VClock<A>
[src]
impl<A: Actor> FromIterator<Dot<A>> for VClock<A>
[src]
fn from_iter<I: IntoIterator<Item = Dot<A>>>(iter: I) -> Self
[src]
impl<A: Actor> 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<'de, A: Actor> 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>,
Auto Trait Implementations
impl<A> Sync for VClock<A> where
A: Sync,
A: Sync,
impl<A> Send for VClock<A> where
A: Send,
A: Send,
impl<A> Unpin for VClock<A> where
A: Unpin,
A: Unpin,
impl<A> RefUnwindSafe for VClock<A> where
A: RefUnwindSafe,
A: RefUnwindSafe,
impl<A> UnwindSafe for VClock<A> where
A: RefUnwindSafe + UnwindSafe,
A: RefUnwindSafe + UnwindSafe,
Blanket Implementations
impl<T> Val for T where
T: PartialEq<T> + Clone + Debug,
[src]
T: PartialEq<T> + Clone + Debug,
impl<T> Val for T where
T: Clone + Debug,
[src]
T: Clone + Debug,
impl<T> Member for T where
T: Eq + Clone + Hash + Debug,
[src]
T: Eq + Clone + Hash + Debug,
impl<A, T> Val<A> for T where
A: Actor,
T: Debug + Default + Clone + Causal<A> + CmRDT + CvRDT,
[src]
A: Actor,
T: Debug + Default + Clone + Causal<A> + CmRDT + CvRDT,
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.
fn to_owned(&self) -> T
[src]
fn clone_into(&self, target: &mut T)
[src]
impl<T> ToString for T where
T: Display + ?Sized,
[src]
T: Display + ?Sized,
impl<I> IntoIterator for I where
I: Iterator,
[src]
I: Iterator,
type Item = <I as Iterator>::Item
The type of the elements being iterated over.
type IntoIter = I
Which kind of iterator are we turning this into?
fn into_iter(self) -> I
[src]
impl<T> From<T> for T
[src]
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.
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.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> DeserializeOwned for T where
T: Deserialize<'de>,
[src]
T: Deserialize<'de>,