applyOps method
Apply a batch of ops locally (minting dots from clk) and return the
DELTA to ship to peers: the blocks created or grown by this batch, at
their final state.
Because each delta block keeps its original start dot, a peer's join extends the matching block by max-length and OR-merges tombstones — it never creates a second node for an element already implied by a run, so the delta is a well-formed δ-state fragment.
Implementation
Fugue<T> applyOps(List<FugueOp<T>> ops, LamportClock clk) {
final touched = <Dot>{};
for (final op in ops) {
switch (op) {
case FugueInsert<T>(:final at, :final value):
touched.add(insert(at, value, clk.tick()));
case FugueRemoveAt<T>(:final at):
final s = delete(at);
if (s != null) touched.add(s);
}
}
final delta = Fugue<T>();
for (final start in touched) {
final b = _blocks[start];
if (b == null) continue;
final nb = _Block<T>(b.start, b.parent, b.side, List<T>.of(b.values));
nb.deleted.addAll(b.deleted);
delta._index(nb);
}
return delta;
}