ORSet

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

Built as a thin wrapper over Causal<DotMap<E, DotSet>>: each element key maps to the set of dots that added it; it is present iff that set is non-empty.

Immutable: add/remove return a new set. piece is the causal merge.

Samples

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

// Shared start: "alice" is present on both replicas.
val start = ORSet.empty<String>().add(a, "alice")

val alice = start.remove("alice")       // Alice concurrently removes
val bob = start.add(b, "alice")         // Bob concurrently re-adds

val merged = alice.piece(bob)
check(merged.contains("alice"))         // add-wins

Types

Link copied to clipboard
object Companion

Properties

Link copied to clipboard
val elements: Set<E>

The elements currently present.

Functions

Link copied to clipboard
fun add(replica: ReplicaId, element: E): ORSet<E>

Add element on behalf of replica, minting a fresh dot. The new dot supersedes this element's prior dots locally; concurrent adds on other replicas still survive the merge.

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
fun contains(element: E): Boolean

True if element is currently present.

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: ORSet<E>): ORSet<E>

The causal merge of two replicas of this set.

Link copied to clipboard
fun remove(element: E): ORSet<E>

Remove element: drop the dots currently on it. The context is unchanged (those dots stay witnessed, so the removal propagates on merge).

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