lattice_crdt

lattice_crdt is an umbrella package that re-exports the core lattice CRDT sub-packages for convenient dependency management. Not every lattice package is included: lattice_fugue, lattice_text_fugue, lattice_text_core, and lattice_presence are separate dependencies.

Sub-packages

Usage

Depend on lattice_crdt to get all sub-packages, or depend on individual sub-packages for minimal dependencies. This module re-exports the primary type from each sub-package so a single import lattice_crdt gives access to the full family of CRDT types; use the sub-package modules directly for their constructors and operations.

// Import from individual sub-packages for constructors and operations:
import lattice_counters/g_counter
import lattice_sets/or_set
import lattice_maps/or_map
import lattice_sequence/sequence
import lattice_text/text

Delta-state replication

Leaf CRDTs expose delta-state mutators alongside their state-based APIs. Infallible operations return a state or #(state, delta). Fallible operations, including counter and sequence edits, return Result around the state or tuple. The delta has the same type as the state and uses the same merge function; leaf CRDTs need no separate apply-delta API.

Sequence and text merges require merge(a, b, replica). The explicit replica identifies the editor that will make subsequent local edits, regardless of operand order. merge_as remains an equivalent alias.

ORMap supports full-value and sparse updates with a dedicated ORMapDelta(a). CrdtDelta(a) distinguishes leaf state deltas from recursively sparse map changes.

Sparse replication requires a baseline or eventual delivery of the required deltas. Duplicate and reordered delivery converges after those dependencies arrive; one later edit does not contain the whole document. See DEV.md for the full convention and usage notes, and the examples/or_map_delta_websocket_example.gleam example for a runnable demo of two replicas exchanging deltas.

Reference: Almeida, Shoker, Baquero — Delta State Replicated Data Types.

Types

A tagged union over leaf CRDTs and recursive map values.

pub type Crdt(a) =
  crdt.Crdt(a)

A leaf state delta or a recursively sparse map change.

pub type CrdtDelta(a) =
  crdt.CrdtDelta(a)

A specification used to auto-create default CRDT values for new keys.

pub type CrdtSpec(a) =
  crdt.CrdtSpec(a)

A causal context of observed dots, used by observed-remove CRDTs.

pub type DotContext =
  dot_context.DotContext

A grow-only counter.

pub type GCounter =
  g_counter.GCounter

A grow-only set.

pub type GSet(a) =
  g_set.GSet(a)

A last-writer-wins map of CRDT children with payload type a.

Each winning assignment replaces its complete child snapshot.

pub type LWWMap(a) =
  crdt.LWWMap(a)

A last-writer-wins register.

pub type LWWRegister(a) =
  lww_register.LWWRegister(a)

A multi-value register that preserves concurrent writes.

pub type MVRegister(a) =
  mv_register.MVRegister(a)

An observed-remove map of CRDT children with one shared specification.

pub type ORMap(a) =
  crdt.ORMap(a)

A generation-aware observed-remove map delta.

pub type ORMapDelta(a) =
  crdt.ORMapDelta(a)

An observed-remove set.

pub type ORSet(a) =
  or_set.ORSet(a)

A positive-negative counter composed of two grow-only counters.

pub type PNCounter =
  pn_counter.PNCounter

A stable identifier for a replica.

pub type ReplicaId =
  replica_id.ReplicaId

A generic sequence CRDT.

pub type Sequence(a) =
  sequence.Sequence(a)

A plain-text CRDT backed by a sequence.

pub type Text =
  text.Text

A two-phase set supporting removal via a tombstone set.

pub type TwoPSet(a) =
  two_p_set.TwoPSet(a)

A version vector for tracking causal history across replicas.

pub type VersionVector =
  version_vector.VersionVector
✨ Search Document