Skip to main content

PnCounter

Struct PnCounter 

Source
pub struct PnCounter { /* private fields */ }
Expand description

An increment/decrement counter: a pair of G-Counters (increments P, decrements N), join = componentwise.

Model: Crdt.PNCounter ι = (ι → ℕ) × (ι → ℕ) with the Prod lattice. Deltas bump one side, one coordinate (SafeMesh.deltaBumpP / deltaBumpN); each side accumulates exactly as a delta G-Counter (SafeMesh.deltaPNCounter_correct_P / _N), and equal state gives an equal read (SafeMesh.deltaPNCounter_value_matches).

Implementations§

Source§

impl PnCounter

Source

pub fn new(n: usize) -> Self

Fresh counter for n replicas — the lattice bottom (⊥, ⊥).

Source

pub fn apply_inc(&mut self, replica: usize, tally: u64)

Apply SafeMesh.deltaBumpP replica tally — increment side, one coordinate on the wire, on the other side. Out-of-range indices are ignored; use Self::try_apply_inc for an error.

Source

pub fn try_apply_inc( &mut self, replica: usize, tally: u64, ) -> Result<(), CoordinateError>

Apply an increment-side delta with a checked replica coordinate.

Returns CoordinateError::ReplicaOutOfRange before any mutation if the index is invalid. Both sides remain unchanged on error. Valid input has the same effect as Self::apply_inc.

Source

pub fn apply_dec(&mut self, replica: usize, tally: u64)

Apply SafeMesh.deltaBumpN replica tally — decrement side. Out-of-range indices are ignored; use Self::try_apply_dec for an error.

Source

pub fn try_apply_dec( &mut self, replica: usize, tally: u64, ) -> Result<(), CoordinateError>

Apply a decrement-side delta with a checked replica coordinate.

Returns CoordinateError::ReplicaOutOfRange before any mutation if the index is invalid. Both sides remain unchanged on error. Valid input has the same effect as Self::apply_dec.

Source

pub fn try_merge(&mut self, other: &PnCounter) -> Result<(), MergeError>

Checked full-state merge: componentwise checked G-Counter merge, erroring on a replica-count mismatch on either side instead of silently truncating (WS1). Both sides are length-checked before any mutation, so the operation is all-or-nothing: on error self is left unchanged.

Source

pub fn merge(&mut self, other: &PnCounter)

Full-state merge: componentwise G-Counter merge — Crdt.pncounter_merge_apply.

Infallible variant for the proven equal-length invariant; panics on a replica-count mismatch. Use PnCounter::try_merge for untrusted input.

Source

pub fn p_state(&self) -> &[u64]

Increment-side state.

Source

pub fn n_state(&self) -> &[u64]

Decrement-side state.

Source

pub fn value(&self) -> i64

The counter’s read: (sum of increments) − (sum of decrements) — Crdt.pncounterValue (ℤ in the model, i64 here).

Trait Implementations§

Source§

impl Clone for PnCounter

Source§

fn clone(&self) -> PnCounter

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Crdt for PnCounter

Source§

type Delta = PnCounterDelta

Source§

fn replica_count(&self) -> Option<usize>

Fixed replica domain, or None for CRDTs without a fixed arity.
Source§

fn apply_delta(&mut self, delta: Self::Delta)

Source§

fn validate_record( &self, _id: RecordId, _delta: &Self::Delta, ) -> Result<(), WireError>

Validate decoded records before admission or replay into this carrier.
Source§

impl Debug for PnCounter

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Eq for PnCounter

Source§

impl Mergeable for PnCounter

Source§

fn merge(&mut self, other: &Self)

Source§

impl PartialEq for PnCounter

Source§

fn eq(&self, other: &PnCounter) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl StructuralPartialEq for PnCounter

Auto Trait Implementations§

§

impl Freeze for PnCounter

§

impl RefUnwindSafe for PnCounter

§

impl Send for PnCounter

§

impl Sync for PnCounter

§

impl Unpin for PnCounter

§

impl UnsafeUnpin for PnCounter

§

impl UnwindSafe for PnCounter

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.