Causal

@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.

Invariant: every dot in store is witnessed by context. The factory paths that build CRDTs on top of Causal maintain it; merges preserve it.

Samples

val a = ReplicaId("A")
val b = ReplicaId("B")

// Alice removed the only dot she saw; her context still remembers (A,1).
val alice = Causal(DotSet(emptySet()), DotContext.of(Dot(a, 1L)))
// Bob concurrently added a fresh dot; he still holds both.
val bob = Causal(
    DotSet(setOf(Dot(a, 1L), Dot(b, 1L))),
    DotContext.of(Dot(a, 1L), Dot(b, 1L)),
)
val merged = alice.piece(bob)
// (A,1): Alice saw & dropped -> gone. (B,1): Alice never saw -> kept.
check(merged.store.dots == setOf(Dot(b, 1L)))
check(!merged.store.isBottom)  // present — add wins

Constructors

Link copied to clipboard
constructor(store: S, context: DotContext)

Properties

Link copied to clipboard
Link copied to clipboard
val store: S

Functions

Link copied to clipboard
open fun causalDots(): Set<Dot>

The causal Dots this state has delivered — (author, author-seq) per op.

Link copied to clipboard
open operator override fun equals(other: Any?): Boolean
Link copied to clipboard
open override fun hashCode(): Int
Link copied to clipboard
open override fun piece(other: Causal<S>): Causal<S>

The join: the least-upper-bound of this and other.

Link copied to clipboard
open override fun toString(): String