LWWMap

@Serializable
class LWWMap<K, V> : Quilted<LWWMap<K, V>>

A map from K to last-writer-wins values V: per-key LWWRegisters composed under union-merge of keys. Each set writes one key with a (timestamp, replicaId) tag; merge picks the per-key max tag.

Suited to settings, ready-toggles, and similar small key→latest-value state where surfacing concurrent edits (a la MVRegister) is unwanted.

Clock-skew warning. Wall-clock timestamps work only when clocks are well-synchronized across all replicas. NTP-class drift will cause surprising silent drops: a write with a lagging timestamp loses to an older write from a faster clock. For correctness under arbitrary clock skew, pair this map with a Hybrid Logical Clock above this layer.

Samples

val a = ReplicaId("A")
val b = ReplicaId("B")

val left = LWWMap.empty<String, Int>()
    .set(a, timestamp = 1L, key = "score", value = 10)
val right = LWWMap.empty<String, Int>()
    .set(b, timestamp = 2L, key = "score", value = 20)

val merged = left.piece(right)
check(merged["score"] == 20)  // ts=2 wins for this key

Types

Link copied to clipboard
object Companion

Properties

Link copied to clipboard
val entries: Map<K, V>

All currently-set entries with their values.

Functions

Link copied to clipboard
open fun causalDots(): Set<Dot>

The causal Dots this state has delivered — (author, author-seq) per op.

Link copied to clipboard
open operator override fun equals(other: Any?): Boolean
Link copied to clipboard
operator fun get(key: K): V?

The current value for key, or null if unset.

Link copied to clipboard
open override fun hashCode(): Int
Link copied to clipboard
open override fun piece(other: LWWMap<K, V>): LWWMap<K, V>

The join: per-key max-tag of the underlying registers.

Link copied to clipboard
fun set(replica: ReplicaId, timestamp: Long, key: K, value: V): LWWMap<K, V>

Write value for key tagged with (timestamp, replica).

Link copied to clipboard
open override fun toString(): String