remove

fun remove(replica: ReplicaId, timestamp: Long, key: K): Patch<LWWMap<K, V>>

Remove key tagged with (timestamp, replica) — a last-writer-wins tombstone (LWWRegister.unset) that competes under merge exactly like a set: a remove at a later tag beats an earlier set, and a set at a later tag revives the key, with the same deterministic (timestamp, replicaId) tie-break. Removed keys disappear from get and entries. Returns the change: one key's tombstone cell, not the whole map.

A removal's delta is a one-cell map, never an empty one. A remove here is a write like any other, so the change to transmit is that tombstone. An empty map is the lattice identity: joining it says nothing at all, and the removal would never leave the replica that made it.

Removing a key that was never set locally still ships a tombstone, so a concurrent earlier-tagged set arriving later loses.

The tombstone cell is retained in state (like every set cell) — this map has no per-key garbage collection.

The tag-uniqueness precondition and the domination domain on set apply equally here.

Samples

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

// Two peers have converged on a settings map.
var alpha = LWWMap.empty<String, String>()
    .piece { it.set(a, timestamp = 1L, key = "lang", value = "en") }
    .piece { it.set(a, timestamp = 2L, key = "tz", value = "UTC") }
    .piece { it.set(a, timestamp = 3L, key = "theme", value = "dark") }
var bravo = alpha

// B changes one setting and puts only that cell on the wire. The frame is the same size
// whether the map holds three keys or ten thousand, and the other keys are untouched.
val change = alpha.set(b, timestamp = 4L, key = "theme", value = "light")
alpha = alpha.piece(change)
bravo = bravo.piece(change)
check(alpha == bravo)
check(alpha["theme"] == "light")
check(alpha["lang"] == "en")

// Per key the higher (timestamp, replica) tag wins, and a remove is a write like any other,
// so its delta is a one-cell tombstone map…
val forget = bravo.remove(b, timestamp = 5L, key = "lang")
check(alpha.piece(forget)["lang"] == null)

// …and never an empty map, which is the lattice identity and carries no removal at all.
check(alpha.piece(LWWMap.empty<String, String>())["lang"] == "en")