Package-level declarations

Types

Link copied to clipboard
@Serializable
class BoundedCounter : Quilted<BoundedCounter>

A bounded / escrow counter: a shared budget pre-divided into per-replica quotas, with the invariant quota(r) >= 0 enforced locally and the derived global invariant "total spent <= total received" held by construction. No coordination is required for the local check — only for redistributing quota via transfer.

Link copied to clipboard
@Serializable
class Causal<S : DotStore<S>>(val store: S, val context: DotContext) : Quilted<Causal<S>>

A full delta-state CRDT built from a DotStore and the DotContext that adjudicates its dots. piece is the causal join: merge the stores using both contexts, then union the contexts. This is the glue that turns any DotStore shape (DotSet now; DotFun/DotMap later) into a Quilted.

Link copied to clipboard
@Serializable
data class Dot(val replica: ReplicaId, val seq: Long)

A clock-free unique name for a single operation: the issuing replica paired with that replica's own monotonically-increasing seq (1, 2, 3…).

Link copied to clipboard
@Serializable
class DotContext : Quilted<DotContext>

The causal history of a replica: every Dot it has ever witnessed, live or already removed. It is the memory that outlives a delete — that is what lets a merge tell "I saw that dot and dropped it on purpose" from "I just haven't seen it yet".

Link copied to clipboard
@Serializable
class DotFun<V>(val values: Map<Dot, V> = emptyMap()) : DotStore<DotFun<V>>

A DotStore mapping each Dot to a value V. Because a dot is minted once and never reused, a dot in both stores carries the same value, so the causal join needs no value-level conflict resolution — surviving dots simply keep their value. As Causal<DotFun<V>> this is a Multi-Value Register: concurrent writes each keep their (dot, value), surfacing the conflict rather than hiding it.

Link copied to clipboard
@Serializable
class DotMap<K, S : DotStore<S>>(val entries: Map<K, S> = emptyMap()) : DotStore<DotMap<K, S>>

A DotStore mapping keys K to nested DotStores S. The causal join is applied per key, recursively, using the surrounding contexts; a key whose nested store becomes bottom (empty) is dropped. Causal<DotMap<E, DotSet>> is an OR-Set; a richer nested store gives an OR-Map.

Link copied to clipboard
@Serializable
class DotSet(val dots: Set<Dot> = emptySet()) : DotStore<DotSet>

The simplest DotStore: a bare set of dots carrying no payload. Presence is "non-empty". As Causal<DotSet> it is an enable-wins flag / set of opaque adds; nested inside a DotMap it becomes the per-element store of an OR-Set.

Link copied to clipboard
interface DotStore<S : DotStore<S>>

A container of Dots, optionally each carrying a payload. The shapes — DotSet (presence), and later DotFun (dot → value) and DotMap (key → store) — all share the one causal join defined here in spirit; pairing any of them with a DotContext inside a Causal yields a full delta-state CRDT.

Link copied to clipboard
@Serializable
class EphemeralEntry<V>(val value: V?, val clock: Long)

An entry in an EphemeralMap: a nullable value tagged with a per-replica monotonic clock.

Link copied to clipboard
@Serializable
class EphemeralMap<V> : Quilted<EphemeralMap<V>>

A presence/awareness CRDT.

Link copied to clipboard
class EphemeralMapTracker<V>(val ttlMs: Long, clock: () -> Long = defaultClock())

A stateful wrapper around EphemeralMap that stamps local receive times and drives TTL eviction.

Link copied to clipboard
@Serializable
class GCounter : Quilted<GCounter>

A grow-only counter: a per-replica map of counts that only ever increase. Each replica increments its own slot; piece is elementwise max, so the merged value is the sum of every replica's highest-seen count.

Link copied to clipboard
@Serializable
class GSet<E> : Quilted<GSet<E>>

A grow-only set of E. add returns a Patch carrying a one-element set; piece is union. Once added, an element cannot be removed — for remove-supporting sets see TwoPhaseSet (tombstones) or ORSet (causal).

Link copied to clipboard

A CRDT-backed JSON document: a recursive, convergent, arbitrary-depth JSON value that merges correctly under concurrent edits from multiple replicas.

Link copied to clipboard
sealed class JsonNode : Quilted<JsonNode>

A node in a JsonCrdt document.

Link copied to clipboard
@Serializable
sealed class JsonValue

A JSON scalar value held by a JsonNode.Leaf.

Link copied to clipboard
@Serializable
class LWWMap<K, V> : Quilted<LWWMap<K, V>>

A map from K to last-writer-wins values V: per-key LWWRegisters composed under union-merge of keys. Each set writes one key with a (timestamp, replicaId) tag; merge picks the per-key max tag.

Link copied to clipboard
@Serializable
class LWWRegister<V> : Quilted<LWWRegister<V>>

A last-writer-wins register. Each set tags the value with (timestamp, replicaId); piece picks the entry with the largest tag, breaking ties on replicaId lexicographically so the merge is deterministic regardless of arrival order.

Link copied to clipboard
@Serializable
class MVRegister<V> : Quilted<MVRegister<V>>

A multi-value register holding the value(s) last written. A single write yields one value; concurrent writes from different replicas are all retained until a later write observes and supersedes them — surfacing the conflict rather than silently picking a winner.

Link copied to clipboard
@Serializable
class ORMap<K, S : Quilted<S>> : Quilted<ORMap<K, S>>

An observed-remove map: keys K each carry a Quilted value S that merges via its own Quilted.piece. A concurrent put of the same key survives a remove (add-wins on the key), and when both replicas hold the key the values are pieced together.

Link copied to clipboard
@Serializable
class ORMapEntry<S : Quilted<S>>(val tags: DotSet, val value: S) : DotStore<ORMapEntry<S>>

An entry of an ORMap: a DotSet of "presence tags" plus a Quilted value. The tag set is the observed-remove handle for the key; the value merges via its own Quilted.piece when both sides hold it.

Link copied to clipboard
@Serializable
class ORSet<E> : Quilted<ORSet<E>>

An observed-remove (add-wins) set of E. Concurrent add and remove of the same element resolve in favour of the add: a remove only cancels the adds it has actually witnessed (the Dots currently on the element), so an add the remover never saw survives. This is the usable form of the dots + causal context machinery — e.g. a presence set of who is currently online.

Link copied to clipboard
value class Patch<S : Quilted<S>>(val delta: S)

A delta produced by a mutator: a small element of the same lattice as S. A delta is a state fragment, so it is absorbed by the very same Quilted.piece join — see piece.

Link copied to clipboard
@Serializable
class PNCounter : Quilted<PNCounter>

A positive/negative counter: two GCounter halves composed in a product lattice. One half tracks all increments, the other all decrements.

Link copied to clipboard
interface Quilted<S : Quilted<S>>

A delta-state CRDT: a value living in a join-semilattice.

Link copied to clipboard
@Serializable
value class ReplicaId(val value: String)

Identity of one replica (peer) in a CRDT. Used to namespace Dots so every operation gets a globally-unique name with no coordination and no clock.

Link copied to clipboard
@Serializable
class Rga<V> : Quilted<Rga<V>>

A Replicated Growable Array (RGA): an op-based sequence CRDT for ordered collections such as chat messages or collaborative text.

Link copied to clipboard
@Serializable
data class RgaId(val lamport: Long, val replicaId: ReplicaId, val seq: Long) : Comparable<RgaId>

A unique, totally-ordered identity for a single RGA element.

Link copied to clipboard
@Serializable
sealed interface RgaOp<out V>

An operation on an Rga sequence.

Link copied to clipboard
class RgaOpSerializer<V>(vSerializer: KSerializer<V>) : KSerializer<RgaOp<V>>

Custom KSerializer for RgaOp<V> that correctly threads vSerializer through to RgaOp.Insert.value, bypassing the limitation in the compiler-generated sealed-class serializer where the V type parameter defaults to PolymorphicSerializer(Any::class).

Link copied to clipboard
@Serializable
class TwoPhaseSet<E> : Quilted<TwoPhaseSet<E>>

A set with tombstoned remove: two grow-only sets, the added set and the removed (tombstone) set, both merged by union. An element is present iff it was added and is not tombstoned. Tombstones win permanently — once removed, an element can never be re-added; even a fresh add will be masked.

Link copied to clipboard
@Serializable
data class VersionVector(val entries: Map<ReplicaId, Long> = emptyMap())

A per-author high-water version vector: replicaId → highest contiguous seq.

Functions

Link copied to clipboard
fun <S : Quilted<S>> S.piece(patch: Patch<S>): S

Absorb a patch into this state via Quilted.piece.