Pular para o conteúdo
Português (BR)

LWWMap

Este conteúdo não está disponível em sua língua ainda.

Defined in: src/crdt/LWWMap.ts:46

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.

K

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

V

  • Crdt<LWWMap<K, V>>

get size(): number

Defined in: src/crdt/LWWMap.ts:128

Number of currently-live keys (tombstones excluded).

number

entriesArray(): readonly readonly [K, V][]

Defined in: src/crdt/LWWMap.ts:118

Snapshot of currently-live [key, value] pairs.

readonly readonly [K, V][]


equals(other): boolean

Defined in: src/crdt/LWWMap.ts:186

LWWMap<K, V>

boolean


get(key): V | undefined

Defined in: src/crdt/LWWMap.ts:97

Read keyundefined for missing keys or tombstones.

K

V | undefined


has(key): boolean

Defined in: src/crdt/LWWMap.ts:106

K

boolean


keys(): readonly K[]

Defined in: src/crdt/LWWMap.ts:109

Snapshot of currently-live keys (tombstones excluded).

readonly K[]


merge(other): LWWMap<K, V>

Defined in: src/crdt/LWWMap.ts:134

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

LWWMap<K, V>

LWWMap<K, V>

Crdt.merge


put(replica, key, value, timestamp?): LWWMap<K, V>

Defined in: src/crdt/LWWMap.ts:68

Set key to value on behalf of replica, stamped at timestamp.

string

K

V

number = ...

LWWMap<K, V>


remove(replica, key, timestamp?): LWWMap<K, V>

Defined in: src/crdt/LWWMap.ts:83

Tombstone key on behalf of replica. Internally an assign with a null value at the given timestamp — older values are displaced; concurrent values with newer timestamps still win.

string

K

number = ...

LWWMap<K, V>


toJSON(): LWWMapJson<V>

Defined in: src/crdt/LWWMap.ts:147

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.

LWWMapJson<V>

Crdt.toJSON


static empty<K, V>(options?): LWWMap<K, V>

Defined in: src/crdt/LWWMap.ts:60

K

V

LWWMapOptions<K> = {}

LWWMap<K, V>


static fromJSON<K, V>(json, options?): LWWMap<K, V>

Defined in: src/crdt/LWWMap.ts:163

K

V

LWWMapJson<V>

LWWMapOptions<K> = {}

LWWMap<K, V>