pub fn join(a: &PatchSet, b: &PatchSet) -> Result<JoinResult, EpochMismatch>Expand description
Join (CRDT merge) two PatchSets that share the same base epoch.
§Precondition
Both patch-sets must share the same base_epoch. If they don’t,
EpochMismatch is returned.
§Algorithm
- Iterate the union of all paths from both patch-sets (
BTreeMapensures sorted, deterministic order). - For each path:
- Present in only one side → take it (disjoint union).
- Present in both, identical → keep one copy (idempotent).
- Present in both, different → classify as compatible or conflicting.
§CRDT guarantees
- Commutativity:
join(a, b) == join(b, a)— ensured by sorting conflict sides canonically. - Associativity:
join(join(a, b), c) == join(a, join(b, c))— ensured by deterministic conflict detection and identical-entry collapse. - Idempotency:
join(a, a) == a— identical entries collapse.