Skip to main content

GCounter

Struct GCounter 

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

A grow-only counter: one tally per replica, join = pointwise max.

Model: Crdt.GCounter ι = ι → ℕ with the Pi join-semilattice. Applying a delta is joining it in, so delivery order and redelivery are irrelevant — SafeMesh.delta_dissemination_sec — and a replica that received bumps B holds, per coordinate, the max over that coordinate’s bumps — SafeMesh.deltaGCounter_correct.

Implementations§

Source§

impl GCounter

Source

pub fn new(n: usize) -> Self

Fresh counter for n replicas — the lattice bottom (all zeros).

Source

pub fn len(&self) -> usize

Number of replica coordinates.

Source

pub fn is_empty(&self) -> bool

Source

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

Apply the delta SafeMesh.deltaBump replica tally — a single coordinate on the wire. Joining the delta is max at that coordinate (Pi.single joined into the state); applying the same bump again is a no-op (idempotence, SafeMesh.delta_dissemination_sec).

Out-of-range replica is ignored (a malformed delta must not corrupt state; the Lean model has no such case — Fin n makes it unrepresentable). Use Self::try_apply_bump to receive an error for an invalid index.

Source

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

Apply a single-coordinate delta, returning an error for an invalid index.

Checks the coordinate before mutation. On error, the entire counter is unchanged; on success, behaves exactly like Self::apply_bump, including accepting an equal or lower tally as a no-op.

Source

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

Checked full-state merge: pointwise max, erroring on a replica-count mismatch instead of silently truncating to the shorter vector (WS1). This is the boundary-safe entry point for state received from an untrusted peer.

Source

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

Full-state merge: pointwise max — Crdt.gcounter_merge_apply. A delta replica and a full-state replica fed the same bumps agree: SafeMesh.deltaGCounter_matches_full.

Infallible variant for the proven equal-length invariant (fixed replica set). Panics on a replica-count mismatch rather than dropping state; use GCounter::try_merge for untrusted input.

Source

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

Per-coordinate state (the ι → ℕ vector).

Source

pub fn value(&self) -> u64

The counter’s read: sum of per-replica tallies — Crdt.gcounterValue.

Trait Implementations§

Source§

impl Clone for GCounter

Source§

fn clone(&self) -> GCounter

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 GCounter

Source§

type Delta = GCounterDelta

Source§

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

Validate decoded records before admission or replay into this carrier.
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§

impl Debug for GCounter

Source§

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

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

impl Eq for GCounter

Source§

impl Mergeable for GCounter

Source§

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

Source§

impl PartialEq for GCounter

Source§

fn eq(&self, other: &GCounter) -> 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 GCounter

Auto Trait Implementations§

§

impl Freeze for GCounter

§

impl RefUnwindSafe for GCounter

§

impl Send for GCounter

§

impl Sync for GCounter

§

impl Unpin for GCounter

§

impl UnsafeUnpin for GCounter

§

impl UnwindSafe for GCounter

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.