LWWRegister

@Serializable
class LWWRegister<V> : Quilted<LWWRegister<V>>

A last-writer-wins register. Each set tags the value with (timestamp, replicaId); piece picks the entry with the largest tag, breaking ties on replicaId lexicographically so the merge is deterministic regardless of arrival order.

Wall-clock or causal time? This register treats whichever monotonically- increasing source the caller passes as timestamp as the truth — wall-clock is the common case but skew can silently drop a value. NTP-class drift will cause surprising silent drops: a write with a lagging timestamp loses to an older write from a faster clock. For semantics that preserve concurrent writes use MVRegister; for correctness under arbitrary clock skew, pair with a Hybrid Logical Clock above this layer.

Samples

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

val left = LWWRegister.empty<String>().set(a, timestamp = 1L, value = "v1")
val right = LWWRegister.empty<String>().set(b, timestamp = 2L, value = "v2")

check(left.piece(right).value == "v2")  // ts=2 wins
check(right.piece(left).value == "v2")  // commutative

Types

Link copied to clipboard
object Companion

Properties

Link copied to clipboard
val value: V?

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
open override fun hashCode(): Int
Link copied to clipboard
open override fun piece(other: LWWRegister<V>): LWWRegister<V>

The join: pick the larger (timestamp, replicaId) tag.

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

Write value tagged with (timestamp, replica).

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