apply
Change the store under key on behalf of replica — and return the change: one key, the fragment mutator wrote, and a context naming exactly the dots it minted, re-carried or retired.
mutator receives a Slot over the key's current store, or bottom when the key is absent. Every new dot comes from Slot.mint, which draws next(c) from this map's shared context and records it. Slot.narrow hands the same minting to a nested store, so an outer mutator can run an inner one. The Change it returns says what the key now holds in this delta and which of the dots it held are retired. Any bottom store nested in the change is left out of the delta, and a change whose whole store is bottom leaves the key out, which is how a nested remove that empties the key reads. Shipping a nested bottom would make the delta change under a join with itself.
The delta is checked, and an invalid one throws IllegalArgumentException rather than shipping. The checks exist because the bug class this type removes is a mutator minting from the wrong context, and every one of them names a shape that bug takes:
every written dot sits at one position: a dot under two nested keys would be retired at both by a write that meant to retire it at one;
every retired dot is held under key, and none of them is also written;
every written dot was minted here or is held under key: no dot from another context, no retired dot coming back;
every minted dot is written;
absorbing the delta keeps exactly the dots it should,
(held − retired) ∪ written, and gives the same store from either side of the join. A dot re-carried at a different position fails the first half; a re-carried dot whose payload cannot be joined (a DotFun value changed in place) fails the second.
Check 5 needs V's equals to be structural and canonical. An equal-payload re-carry at the same position passes, harmlessly: it is a no-op delta.
Check 1 looks inside DotMap, the one in-kuilt store that nests other stores, and counts every other store as flat. A store of your own that nests dots is counted as flat too, so check 1 cannot see a dot repeated inside it.
Cost: O(subtree under key) per delta produced, for the checks. A wide value under one key pays that on every write to it. Absorbing the delta with piece is a separate cost, and it walks every key, as Causal's join always has.
Throws
if bottom is not bottom, or the change fails a check.
if mutator calls Slot.mint when replica's next seq would pass Long.MAX_VALUE, as a decoded context can leave it (#3417). A mutator that mints nothing still runs on such a context.