Grove.Set.TwoPSet (Grove v0.1.1)
View SourceA Two-Phase Set (2P-Set) CRDT.
Elements can be added and removed, but once removed they cannot be re-added. This is implemented using two G-Sets: one for additions and one for removals (tombstones).
The value is the difference: added - removed.
Limitations
- Elements cannot be re-added after removal
- Tombstones grow unboundedly (no garbage collection)
For use cases requiring re-addition, see Grove.Set.ORSet.
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.TwoPSet.new(:node_a)
iex> set = Grove.Set.TwoPSet.add(set, "apple")
iex> set = Grove.Set.TwoPSet.add(set, "banana")
iex> set = Grove.Set.TwoPSet.remove(set, "apple")
iex> Grove.Set.TwoPSet.value(set) |> Enum.sort()
["banana"]
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 2P-Sets.
Creates a new 2P-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
@type actor() :: term()
@type t() :: %Grove.Set.TwoPSet{ actor: actor(), added: Grove.Set.GSet.t(), removed: Grove.Set.GSet.t() }
Functions
Adds an element to the set.
If the element was previously removed, it will NOT be re-added.
Returns the accumulated delta since the last reset.
Checks if an element is in the set.
Returns true if the element has been added and not removed.
Merges two 2P-Sets.
Both the added and removed G-Sets are merged independently.
Creates a new 2P-Set for the given actor.
Removes an element from the set.
Once removed, the element cannot be re-added.
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.
The value is the difference between added and removed elements.