Skip to content

ORSet

Defined in: src/crdt/ORSet.ts:47

Conflict-free Replicated Data Type — a value that converges under replication without coordination. Every implementation is a state-based CvRDT: replicas exchange full state, and merge forms a join-semilattice.

Three properties every implementation must satisfy — tests/unit/crdt verifies them by hand-rolled property tests against generated samples:

  • Idempotent: merge(a, a) === a
  • Commutative: merge(a, b) === merge(b, a)
  • Associative: merge(merge(a, b), c) === merge(a, merge(b, c))

Together these mean: gossip can deliver state updates in any order, deduplicate, retransmit, and the world converges as long as every replica eventually sees every state.

Why state-based and not delta-state. Delta-CRDTs ship only the incremental change rather than the full state — much cheaper on the wire, but the implementation has more moving parts and you need delta acknowledgement protocols. State-based is the simplest thing that converges; we ship it first and revisit if payload size hurts.

E

The concrete CRDT type. F-bounded so subclass merge keeps the right return type without casting at every call site.

get size(): number

Defined in: src/crdt/ORSet.ts:124

number

add(replica, element): ORSet<E>

Defined in: src/crdt/ORSet.ts:74

string

E

ORSet<E>


equals(other): boolean

Defined in: src/crdt/ORSet.ts:207

ORSet<E>

boolean


has(element): boolean

Defined in: src/crdt/ORSet.ts:112

E

boolean


merge(other): ORSet<E>

Defined in: src/crdt/ORSet.ts:130

Join two replicas. Must be a join-semilattice operation: total, idempotent, commutative, associative.

ORSet<E>

ORSet<E>

Crdt.merge


remove(element): ORSet<E>

Defined in: src/crdt/ORSet.ts:96

Remove every tag currently present for element. Concurrent adds carrying tags this replica hasn’t observed survive the merge — that’s the OR-Set “add wins” property.

E

ORSet<E>


toJSON(): ORSetJson

Defined in: src/crdt/ORSet.ts:164

Wire-friendly representation — every CRDT must be JSON-encodable so it can travel through the cluster transport without bespoke codecs. toJSON() is the inverse of the static fromJSON factory each impl exposes.

ORSetJson

Crdt.toJSON


value(): readonly E[]

Defined in: src/crdt/ORSet.ts:116

readonly E[]


static empty<E>(opts?): ORSet<E>

Defined in: src/crdt/ORSet.ts:67

E

ORSetOptions<E> = {}

ORSet<E>


static fromJSON<E>(json, opts?): ORSet<E>

Defined in: src/crdt/ORSet.ts:185

E

ORSetJson

ORSetOptions<E> = {}

ORSet<E>