GCounterMap
Este conteúdo não está disponível em sua língua ainda.
Defined in: src/crdt/GCounterMap.ts:34
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”K
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<GCounterMap<K>>
Accessors
Section titled “Accessors”Get Signature
Section titled “Get Signature”get size():
number
Defined in: src/crdt/GCounterMap.ts:88
Returns
Section titled “Returns”number
Methods
Section titled “Methods”equals()
Section titled “equals()”equals(
other):boolean
Defined in: src/crdt/GCounterMap.ts:140
Parameters
Section titled “Parameters”GCounterMap<K>
Returns
Section titled “Returns”boolean
has(
key):boolean
Defined in: src/crdt/GCounterMap.ts:86
Parameters
Section titled “Parameters”K
Returns
Section titled “Returns”boolean
increment()
Section titled “increment()”increment(
replica,key,delta?):GCounterMap<K>
Defined in: src/crdt/GCounterMap.ts:53
Bump the counter under key by delta (default 1) on replica.
Parameters
Section titled “Parameters”replica
Section titled “replica”string
K
delta?
Section titled “delta?”number = 1
Returns
Section titled “Returns”GCounterMap<K>
keys()
Section titled “keys()”keys(): readonly
K[]
Defined in: src/crdt/GCounterMap.ts:77
Snapshot of all keys currently tracked.
Returns
Section titled “Returns”readonly K[]
merge()
Section titled “merge()”merge(
other):GCounterMap<K>
Defined in: src/crdt/GCounterMap.ts:90
Join two replicas. Must be a join-semilattice operation: total, idempotent, commutative, associative.
Parameters
Section titled “Parameters”GCounterMap<K>
Returns
Section titled “Returns”GCounterMap<K>
Implementation of
Section titled “Implementation of”pairs()
Section titled “pairs()”pairs(): readonly readonly [
K,number][]
Defined in: src/crdt/GCounterMap.ts:82
Snapshot of [key, value] pairs.
Returns
Section titled “Returns”readonly readonly [K, number][]
toJSON()
Section titled “toJSON()”toJSON():
GCounterMapJson
Defined in: src/crdt/GCounterMap.ts:103
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”total()
Section titled “total()”total():
number
Defined in: src/crdt/GCounterMap.ts:70
Sum across every key.
Returns
Section titled “Returns”number
value()
Section titled “value()”value(
key):number
Defined in: src/crdt/GCounterMap.ts:65
Read the counter under key, or 0 if it doesn’t exist.
Parameters
Section titled “Parameters”K
Returns
Section titled “Returns”number
empty()
Section titled “empty()”
staticempty<K>(options?):GCounterMap<K>
Defined in: src/crdt/GCounterMap.ts:45
Type Parameters
Section titled “Type Parameters”K
Parameters
Section titled “Parameters”options?
Section titled “options?”GCounterMapOptions<K> = {}
Returns
Section titled “Returns”GCounterMap<K>
fromJSON()
Section titled “fromJSON()”
staticfromJSON<K>(json,options?):GCounterMap<K>
Defined in: src/crdt/GCounterMap.ts:119
Type Parameters
Section titled “Type Parameters”K
Parameters
Section titled “Parameters”options?
Section titled “options?”GCounterMapOptions<K> = {}
Returns
Section titled “Returns”GCounterMap<K>
