Skip to main content

Crate mdcs_core

Crate mdcs_core 

Source
Expand description

§mdcs-core

Core CRDT types and traits for the Carnelia Merkle-Delta CRDT Store.

This crate provides the foundational building blocks for conflict-free replicated data types (CRDTs). Every type implements the Lattice trait, which models a join-semilattice and guarantees Strong Eventual Consistency: all replicas converge to the same state regardless of message order.

§Mathematical Foundation

A join-semilattice $(S, \sqcup)$ satisfies three properties:

PropertyDefinition
Commutativity$a \sqcup b = b \sqcup a$
Associativity$(a \sqcup b) \sqcup c = a \sqcup (b \sqcup c)$
Idempotence$a \sqcup a = a$

These guarantees mean that updates can be applied in any order, any number of times, and the result is always deterministic.

§CRDT Types

TypeModuleDescription
GSetgsetGrow-only set — elements can only be added
ORSetorsetObserved-Remove set — add-wins semantics
PNCounterpncounterIncrement/decrement counter
LWWRegisterlwwregLast-Writer-Wins register
MVRegistermvregMulti-Value register — preserves concurrent writes
CRDTMapmapComposable map with shared causal context

§Quick Start

use mdcs_core::prelude::*;

// Create two replicas of a grow-only set
let mut a = GSet::new();
let mut b = GSet::new();

a.insert(1);
b.insert(2);

// Merge — order doesn't matter
let merged = a.join(&b);
assert!(merged.contains(&1));
assert!(merged.contains(&2));

§Feature: Delta-State Support

Types that implement DeltaCRDT support efficient delta-state replication. Instead of shipping full state, only incremental changes (deltas) are transmitted. See the mdcs-delta crate for the anti-entropy protocol that drives synchronization.

Re-exports§

pub use gset::GSet;
pub use lattice::DeltaCRDT;
pub use lattice::Lattice;
pub use lwwreg::LWWRegister;
pub use map::CRDTMap;
pub use map::CausalContext;
pub use map::MapValue;
pub use mvreg::MVRegister;
pub use orset::ORSet;
pub use pncounter::PNCounter;

Modules§

gset
Grow-only Set - elements can only be added, never removed This is the simplest useful CRDT and a good starting point.
lattice
Join-semilattice trait - the mathematical foundation of CRDTs
lwwreg
Last-Write-Wins (LWW) Register CRDT
map
Map CRDT - A composable container for nested CRDTs
mvreg
Multi-Value Register CRDT
orset
Observed-Remove Set (OR-Set / Add-Wins Set)
pncounter
PN-Counter (Positive-Negative Counter) CRDT
prelude
Prelude module — import everything you need with use mdcs_core::prelude::*.