pub struct PNCounter<K: Ord + Clone> { /* private fields */ }Expand description
A Positive-Negative Counter CRDT
Supports both increment and decrement by maintaining two separate counters. Value = sum(increments) - sum(decrements)
Implementations§
Source§impl<K: Ord + Clone> PNCounter<K>
impl<K: Ord + Clone> PNCounter<K>
Sourcepub fn increment(&mut self, replica_id: K, amount: u64)
pub fn increment(&mut self, replica_id: K, amount: u64)
Increment the counter for a specific replica
Sourcepub fn decrement(&mut self, replica_id: K, amount: u64)
pub fn decrement(&mut self, replica_id: K, amount: u64)
Decrement the counter for a specific replica
Sourcepub fn get_increment(&self, replica_id: &K) -> u64
pub fn get_increment(&self, replica_id: &K) -> u64
Get the increment counter for a replica
Sourcepub fn get_decrement(&self, replica_id: &K) -> u64
pub fn get_decrement(&self, replica_id: &K) -> u64
Get the decrement counter for a replica
Sourcepub fn increments(&self) -> &BTreeMap<K, u64>
pub fn increments(&self) -> &BTreeMap<K, u64>
Get a reference to all increment counters
Sourcepub fn decrements(&self) -> &BTreeMap<K, u64>
pub fn decrements(&self) -> &BTreeMap<K, u64>
Get a reference to all decrement counters
Trait Implementations§
Source§impl<'de, K> Deserialize<'de> for PNCounter<K>
impl<'de, K> Deserialize<'de> for PNCounter<K>
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Source§impl<K: Ord + Clone> Lattice for PNCounter<K>
impl<K: Ord + Clone> Lattice for PNCounter<K>
Source§fn join(&self, other: &Self) -> Self
fn join(&self, other: &Self) -> Self
Join operation performs component-wise max on both counters This ensures that concurrent updates always converge to the same value
Source§fn partial_cmp_lattice(&self, other: &Self) -> Option<Ordering>
fn partial_cmp_lattice(&self, other: &Self) -> Option<Ordering>
Partial order derived from join: a ≤ b iff a ⊔ b = b
Source§fn join_assign(&mut self, other: &Self)
fn join_assign(&mut self, other: &Self)
Join-assign: self = self ⊔ other
impl<K: Eq + Ord + Clone> Eq for PNCounter<K>
impl<K: Ord + Clone> StructuralPartialEq for PNCounter<K>
Auto Trait Implementations§
impl<K> Freeze for PNCounter<K>
impl<K> RefUnwindSafe for PNCounter<K>where
K: RefUnwindSafe,
impl<K> Send for PNCounter<K>where
K: Send,
impl<K> Sync for PNCounter<K>where
K: Sync,
impl<K> Unpin for PNCounter<K>
impl<K> UnwindSafe for PNCounter<K>where
K: RefUnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more