Package-level declarations

Types

Link copied to clipboard
data class AddNodeResult<V>(val tree: MovableTree<V>, val nodeId: String, val patch: Patch<MovableTree<V>>)

The result of MovableTree.addNode: the updated tree, the newly minted node id, and the Patch that encodes the insertion delta for delta-propagation to peers.

Link copied to clipboard

A probabilistic, mergeable Bloom filter: an approximate set whose merge is bitwise OR of the underlying bit array — trivially idempotent, commutative, and associative. A Bloom filter records whether elements might have been added and never produces false negatives (every added element always reports present), with a tunable false-positive rate.

Link copied to clipboard
class BloomFilterSerializer : KSerializer<BloomFilter>

Custom KSerializer for BloomFilter that chooses between two wire formats based on density, to keep delta messages O(k) instead of O(m):

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
class CanonicalMapSerializer<K, V>(kSerializer: KSerializer<K>, vSerializer: KSerializer<V>) : KSerializer<Map<K, V>>

KSerializer for a Map that emits entries in key order, so that — subject to the precondition below — two replicas at the same logical state produce identical bytes regardless of merge history or host platform.

Link copied to clipboard
class CanonicalSetSerializer<E>(eSerializer: KSerializer<E>) : KSerializer<Set<E>>

KSerializer for a Set that emits elements in element order, so that — subject to the precondition below — two replicas at the same logical state produce identical bytes regardless of merge order.

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 CellDelta(val row: Int, val col: Int, val value: Long)

A single changed cell in a CountMinSketch sparse delta: the (row, col) position and the new absolute value after increment.

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

A Count-Min sketch: approximate per-item frequency over a stream, in fixed width × depth memory. Think of it as the frequency complement to a Bloom filter — where a Bloom filter answers "is X present?", a Count-Min sketch answers "how often?".

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

A DDSketch quantile estimator: a sketch that answers "what was the median response time?" or "what's the 99th-percentile latency?" from a stream of measurements, using a small amount of memory instead of keeping every value.

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

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

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(with = DotFunSerializer::class)
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
class DotFunSerializer<V>(vSerializer: KSerializer<V>) : KSerializer<DotFun<V>>

Custom KSerializer for DotFun<V> that emits DotFun.values entries sorted by Dot key (lexicographically by replica, then by seq), producing identical bytes for any two replicas at the same logical state regardless of delivery order.

Link copied to clipboard
@Serializable(with = DotMapSerializer::class)
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
class DotMapSerializer<K, S : DotStore<S>>(kSerializer: KSerializer<K>, sSerializer: KSerializer<S>) : KSerializer<DotMap<K, S>>

Custom KSerializer for DotMap<K, S> that emits DotMap.entries in a canonical order, producing identical bytes for any two replicas at the same logical state regardless of delivery order (issue #713).

Link copied to clipboard
@Serializable(with = DotSetSerializer::class)
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
class DotSetSerializer : KSerializer<DotSet>

Custom KSerializer for DotSet that emits DotSet.dots sorted by Dot (lexicographically by replica, then by seq), producing identical bytes for any two replicas at the same logical state regardless of delivery order.

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

A Fugue sequence CRDT: an ordered list with a provable maximal non-interleaving guarantee for concurrent insertions.

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

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

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

An operation on a Fugue sequence.

Link copied to clipboard
@Serializable
enum FugueSide : Enum<FugueSide>

The side a node occupies relative to its FugueNode.parent in the Fugue tree.

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

A gauge: the current level of something — temperature, queue depth, players online, memory in use. Where a counter answers "how many so far?", a gauge answers "what is it right now?" — the reading that a Sum metric cannot express, because levels go up and down and only the latest reading matters.

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 GCounterDouble : Quilted<GCounterDouble>

A grow-only counter over Double — the exact-precision sibling of GCounter.

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
@Serializable
class Histogram : Quilted<Histogram>

An explicit-bucket histogram: you choose the bucket boundaries up front — say [10, 50, 100] milliseconds — and each bucket counts how many recorded values fell in its range. It answers "how are my measurements distributed?" when you already know the ranges you care about (SLA thresholds, size classes), the classic fixed-bucket histogram shape.

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

A HyperLogLog cardinality estimator: a sketch that answers "how many distinct items have been added?" using a fixed, small amount of memory instead of keeping the full set.

Link copied to clipboard

Builds the per-replica clock an EphemeralMap slot is stamped with, packed so that a restarted replica always out-clocks its own dead incarnation.

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 LatticeProduct<A : Quilted<A>, B : Quilted<B>>(val first: A, val second: B) : Quilted<LatticeProduct<A, B>>

The componentwise product of two join-semilattices.

Link copied to clipboard
sealed interface LogOp<out Id>

How one operation is classified, independent of the concrete op-log CRDT.

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 (or remove — a tombstone write) tags one key with (timestamp, replicaId); 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 MovableTree<V> : Quilted<MovableTree<V>>

A replicated tree that supports concurrent move/reparent operations without ever producing a cycle.

Link copied to clipboard
@Serializable
class MoveOp<V>(val ts: Long, val replica: ReplicaId, val node: String, val newParent: String, val value: V?, val seq: Long)

One move operation: "set the parent of node to newParent".

Link copied to clipboard
@Serializable
data class MoveTreeCompact(val droppedDots: Set<Dot>)

Records that the ops identified by droppedDots have been garbage-collected from the move-log.

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
interface OpLogCrdt<Id : Any, V, Op : Any>

An op-log CRDT, viewed as the stream of operations it holds rather than as a value.

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 a key's value is every surviving write to it, pieced together.

Link copied to clipboard
@Serializable(with = ORMapEntrySerializer::class)
class ORMapEntry<S : Quilted<S>>(val contributions: Map<Dot, S> = emptyMap()) : DotStore<ORMapEntry<S>>

An entry of an ORMap: the key's presence tags, each carrying the value that was written under it. The key's observable value is the join of every tag's contribution; the tags are the observed-remove handle for the key.

Link copied to clipboard
class ORMapEntrySerializer<S : Quilted<S>>(valueSerializer: KSerializer<S>) : KSerializer<ORMapEntry<S>>

Custom KSerializer for ORMapEntry<S> that emits ORMapEntry.contributions sorted by Dot key, so two replicas at the same logical state produce identical bytes regardless of the order their merges happened to run in.

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) : Comparable<ReplicaId>

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

A counter that supports reset-to-zero without coordination, using causal context to distinguish increments the resetter has observed (cleared by a reset) from those concurrent with it (which survive the merge).

Link copied to clipboard
@Serializable
class Rga<V> : Quilted<Rga<V>> , OpLogCrdt<RgaId, V, RgaOp<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
inline fun <S : Quilted<S>> S.piece(mutate: (S) -> Patch<S>): S

This state with the delta mutate produces from it absorbed — the delta-mutator law X.piece(mᵟ(X)) spelled once, so a caller need not name X twice.

fun <S : Quilted<S>> S.piece(patch: Patch<S>): S

Absorb a patch into this state via Quilted.piece.