hecate_or_set (macula v10.19.0)
View SourceObserved-Remove Set CRDT (Part 3 §7.4).
Realm-shared mutable state (member lists, chat threads, directory metadata) converges across nodes without coordination. Each add/2 tags the element with a unique 16-byte random tag; remove/2 tombstones every currently observed tag. Concurrent add+remove of the same element keeps the element (the new tag wasn't observed by the remover) — the property that makes OR-Set the right CRDT for "did Alice add a member just before I removed?" semantics.
State
data :: #{Element => sets:set(Tag)}— currently-active tags per element. An element is "in the set" iff its tag set is non-empty.tombstones :: sets:set(Tag)— tags removed by an observedremove/2. New deltas carrying these tags are suppressed so a delayed re-broadcast of a removed add cannot resurrect the element.
Convergence
Two interfaces:
merge/2— full-state union for catch-up sync. Combines tag sets element-wise, subtracts the unioned tombstone set, drops elements that lose all live tags.apply_delta/2— incremental delta application for per-op gossip over Plumtree. Applies one{add, Element, Tag}or{remove, [Tag]}delta.
Both produce the same final state given the same total set of operations — the OR-Set's strong eventual consistency guarantee.
Reference: plans/PLAN_MACULA_V2_PART3_DISCOVERY.md §7.4; plans/PLAN_PHASE_5_BREAKDOWN.md Session 5.4.
Summary
Functions
Add Element with a fresh tag. Returns the new set plus the delta to broadcast.
Full-state union — element-wise tag union, then subtract the merged tombstones, then drop elements with no live tags.
Remove Element by tombstoning every currently-observed tag. If the element is absent the operation is a no-op (delta carries an empty tag list).
Types
Functions
Add Element with a fresh tag. Returns the new set plus the delta to broadcast.
Apply a single delta (the per-op product of add/2 or remove/2). Idempotent — re-applying the same delta is a no-op. Tombstoned tags are silently suppressed in add deltas so a delayed re-broadcast cannot resurrect a removed element.
Full-state union — element-wise tag union, then subtract the merged tombstones, then drop elements with no live tags.
-spec new() -> or_set().
Remove Element by tombstoning every currently-observed tag. If the element is absent the operation is a no-op (delta carries an empty tag list).
-spec size(or_set()) -> non_neg_integer().
-spec tombstone_count(or_set()) -> non_neg_integer().