Struct crdts::pncounter::PNCounter
[−]
[src]
pub struct PNCounter<A: Ord + Clone + Serialize + DeserializeOwned> { /* fields omitted */ }
PNCounter
allows the counter to be both incremented and decremented
by representing the increments (P) and the decrements (N) in separate
internal G-Counters.
Merge is implemented by merging the internal P and N counters. The value of the counter is P minus N.
Examples
use crdts::PNCounter; let mut a = PNCounter::new(); a.increment("A".to_string()); a.increment("A".to_string()); a.decrement("A".to_string()); a.increment("A".to_string()); assert_eq!(a.value(), 2);
Methods
impl<A: Ord + Clone + Serialize + DeserializeOwned> PNCounter<A>
[src]
fn new() -> PNCounter<A>
[src]
Produces a new PNCounter
.
fn increment(&mut self, actor: A)
[src]
Increments a particular actor's counter.
fn decrement(&mut self, actor: A)
[src]
Decrements a particular actor's counter.
fn value(&self) -> i64
[src]
Returns the current value of this counter (P-N).
fn merge(&mut self, other: PNCounter<A>)
[src]
Merge another pncounter into this one, without regard to dominance.
Examples
use crdts::PNCounter; let (mut a, mut b, mut c) = (PNCounter::new(), PNCounter::new(), PNCounter::new()); a.increment("A".to_string()); b.increment("B".to_string()); b.increment("B".to_string()); b.decrement("A".to_string()); c.increment("B".to_string()); c.increment("B".to_string()); a.merge(b); assert_eq!(a, c);
Trait Implementations
impl<A: Debug + Ord + Clone + Serialize + DeserializeOwned> Debug for PNCounter<A>
[src]
impl<A: Eq + Ord + Clone + Serialize + DeserializeOwned> Eq for PNCounter<A>
[src]
impl<A: Clone + Ord + Clone + Serialize + DeserializeOwned> Clone for PNCounter<A>
[src]
fn clone(&self) -> PNCounter<A>
[src]
Returns a copy of the value. Read more
fn clone_from(&mut self, source: &Self)
1.0.0[src]
Performs copy-assignment from source
. Read more
impl<A: Hash + Ord + Clone + Serialize + DeserializeOwned> Hash for PNCounter<A>
[src]
fn hash<__HA: Hasher>(&self, __arg_0: &mut __HA)
[src]
Feeds this value into the given [Hasher
]. Read more
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: Ord + Clone + Serialize + DeserializeOwned> Ord for PNCounter<A>
[src]
fn cmp(&self, other: &PNCounter<A>) -> Ordering
[src]
This method returns an Ordering
between self
and other
. Read more
fn max(self, other: Self) -> Self
1.22.0[src]
Compares and returns the maximum of two values. Read more
fn min(self, other: Self) -> Self
1.22.0[src]
Compares and returns the minimum of two values. Read more
impl<A: Ord + Clone + Serialize + DeserializeOwned> PartialOrd for PNCounter<A>
[src]
fn partial_cmp(&self, other: &PNCounter<A>) -> Option<Ordering>
[src]
This method returns an ordering between self
and other
values if one exists. Read more
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
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
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
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