MVRegister
此内容尚不支持你的语言。
Defined in: src/crdt/MVRegister.ts:44
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”V
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<MVRegister<V>>
Accessors
Section titled “Accessors”hasConflict
Section titled “hasConflict”Get Signature
Section titled “Get Signature”get hasConflict():
boolean
Defined in: src/crdt/MVRegister.ts:81
true iff values().length > 1 — two or more concurrent writes.
Returns
Section titled “Returns”boolean
Get Signature
Section titled “Get Signature”get size():
number
Defined in: src/crdt/MVRegister.ts:84
Number of currently-live values (typically 1).
Returns
Section titled “Returns”number
Methods
Section titled “Methods”assign()
Section titled “assign()”assign(
replica,value):MVRegister<V>
Defined in: src/crdt/MVRegister.ts:56
Assign value on behalf of replica. Subsumes everything
currently in the register on this replica — the new vector
clock dominates every previous entry’s, so on merge they all
lose. Concurrent assigns on other replicas survive (their
clocks are independent of this one’s tick).
Parameters
Section titled “Parameters”replica
Section titled “replica”string
V
Returns
Section titled “Returns”MVRegister<V>
equals()
Section titled “equals()”equals(
other):boolean
Defined in: src/crdt/MVRegister.ts:164
Parameters
Section titled “Parameters”MVRegister<V>
Returns
Section titled “Returns”boolean
merge()
Section titled “merge()”merge(
other):MVRegister<V>
Defined in: src/crdt/MVRegister.ts:86
Join two replicas. Must be a join-semilattice operation: total, idempotent, commutative, associative.
Parameters
Section titled “Parameters”MVRegister<V>
Returns
Section titled “Returns”MVRegister<V>
Implementation of
Section titled “Implementation of”toJSON()
Section titled “toJSON()”toJSON():
MVRegisterJson<V>
Defined in: src/crdt/MVRegister.ts:131
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.
Returns
Section titled “Returns”Implementation of
Section titled “Implementation of”values()
Section titled “values()”values(): readonly
V[]
Defined in: src/crdt/MVRegister.ts:76
Snapshot of currently-live values. Length is 1 in the common (un-conflicted) case; more than 1 when concurrent writers wrote branches that haven’t yet been subsumed by a later assign.
Returns
Section titled “Returns”readonly V[]
empty()
Section titled “empty()”
staticempty<V>():MVRegister<V>
Defined in: src/crdt/MVRegister.ts:47
Type Parameters
Section titled “Type Parameters”V
Returns
Section titled “Returns”MVRegister<V>
fromJSON()
Section titled “fromJSON()”
staticfromJSON<V>(json):MVRegister<V>
Defined in: src/crdt/MVRegister.ts:141
Type Parameters
Section titled “Type Parameters”V
Parameters
Section titled “Parameters”Returns
Section titled “Returns”MVRegister<V>
