GSet
Defined in: src/crdt/GSet.ts:39
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.
Type Parameters
Section titled “Type Parameters”E
The concrete CRDT type. F-bounded so subclass
merge keeps the right return type without casting at every call
site.
Implements
Section titled “Implements”Crdt<GSet<E>>
Accessors
Section titled “Accessors”Get Signature
Section titled “Get Signature”get size():
number
Defined in: src/crdt/GSet.ts:69
Returns
Section titled “Returns”number
Methods
Section titled “Methods”add(
element):GSet<E>
Defined in: src/crdt/GSet.ts:52
Parameters
Section titled “Parameters”element
Section titled “element”E
Returns
Section titled “Returns”GSet<E>
equals()
Section titled “equals()”equals(
other):boolean
Defined in: src/crdt/GSet.ts:106
Parameters
Section titled “Parameters”GSet<E>
Returns
Section titled “Returns”boolean
has(
element):boolean
Defined in: src/crdt/GSet.ts:60
Parameters
Section titled “Parameters”element
Section titled “element”E
Returns
Section titled “Returns”boolean
merge()
Section titled “merge()”merge(
other):GSet<E>
Defined in: src/crdt/GSet.ts:71
Join two replicas. Must be a join-semilattice operation: total, idempotent, commutative, associative.
Parameters
Section titled “Parameters”GSet<E>
Returns
Section titled “Returns”GSet<E>
Implementation of
Section titled “Implementation of”toJSON()
Section titled “toJSON()”toJSON():
GSetJson
Defined in: src/crdt/GSet.ts:88
Wire shape: array of JSON-stringified elements. Custom identity
is NOT serialised — fromJSON callers must pass the matching
identity option to reconstruct a set with the same dedup rule.
For default identity the JSON-string IS the identity key, so a
round-trip produces the same internal state.
Returns
Section titled “Returns”Implementation of
Section titled “Implementation of”value()
Section titled “value()”value(): readonly
E[]
Defined in: src/crdt/GSet.ts:65
Snapshot of every element currently in the set.
Returns
Section titled “Returns”readonly E[]
empty()
Section titled “empty()”
staticempty<E>(opts?):GSet<E>
Defined in: src/crdt/GSet.ts:48
Type Parameters
Section titled “Type Parameters”E
Parameters
Section titled “Parameters”GSetOptions<E> = {}
Returns
Section titled “Returns”GSet<E>
fromJSON()
Section titled “fromJSON()”
staticfromJSON<E>(json,opts?):GSet<E>
Defined in: src/crdt/GSet.ts:95
Type Parameters
Section titled “Type Parameters”E
Parameters
Section titled “Parameters”GSetOptions<E> = {}
Returns
Section titled “Returns”GSet<E>