Grove.Set.ORSet (Grove v0.1.1)
View SourceAn Observed-Remove Set (OR-Set) CRDT, also known as Add-Wins Set (AWSet).
Unlike 2P-Set, elements can be removed and re-added. This is achieved by tagging each add operation with a unique identifier (actor + counter). Remove only removes the tags that were observed at removal time.
Semantics
- Add-wins: Concurrent add and remove results in the element being present
- Re-addition: Elements can be added again after removal
- Unique tags: Each add creates a new tag
{actor, counter}
Delta-State Support
This CRDT supports delta-state replication:
delta/1- Returns accumulated changes since last resetreset_delta/1- Clears the delta buffer after synchronization
Example
iex> set = Grove.Set.ORSet.new(:node_a)
iex> set = Grove.Set.ORSet.add(set, "apple")
iex> set = Grove.Set.ORSet.remove(set, "apple")
iex> set = Grove.Set.ORSet.add(set, "apple") # Can re-add!
iex> Grove.Set.ORSet.member?(set, "apple")
true
Summary
Functions
Adds an element to the set.
Returns the accumulated delta since the last reset.
Checks if an element is in the set.
Merges two OR-Sets.
Creates a new OR-Set for the given actor.
Removes an element from the set.
Resets the delta buffer after synchronization.
Returns the number of elements in the set.
Returns the elements as a list.
Returns the current elements as a MapSet.
Types
Functions
Adds an element to the set.
Creates a new unique tag for this add operation.
Returns the accumulated delta since the last reset.
Checks if an element is in the set.
Returns true if the element has at least one tag.
Merges two OR-Sets.
For each element, takes the union of all tags.
Creates a new OR-Set for the given actor.
Removes an element from the set.
Only removes the tags currently observed for this element. Concurrent adds with new tags will still be present after merge. Generates a delta with tombstones for proper replication.
Resets the delta buffer after synchronization.
@spec size(t()) :: non_neg_integer()
Returns the number of elements in the set.
Returns the elements as a list.
Returns the current elements as a MapSet.