Loom.AWORSet
An add-removed (optimized) observed-remove set (without tombstones).
This CRDT respects adds over removes in the event a simultaneous update. It most naturally matches what most users expect when they add/remove items. It also forms the foundation for other kinds of CRDT’s, such as our AWORMap and MVRegister.
Summary
add(set, actor, value) | Add an element to an AWORSet |
empty(set) | Empties a CRDT of all elements |
join(aworset, aworset) | Join 2 CRDTs together |
member?(aworset, value) | Check to see if an element is a member of a set |
new() | Creates a new AWORSet |
remove(set, value) | Remove an element from an AWORSet |
value(aworset) | Returns a list of set elements |
Functions
Specs:
Add an element to an AWORSet
iex> alias Loom.AWORSet, as: Set
iex> Set.new |> Set.add(:a, 1) |> Set.add(:b, 2) |> Set.value |> Enum.sort
[1,2]
Specs:
Empties a CRDT of all elements
iex> alias Loom.AWORSet, as: Set
iex> Set.new
...> |> Set.add(:a, 1)
...> |> Set.empty
...> |> Set.value
[]
Specs:
Join 2 CRDTs together
iex> alias Loom.AWORSet, as: Set
iex> {a, _} = Set.new |> Set.add(:a, 1)
iex> {b, _} = Set.new |> Set.add(:b, 2)
iex> Set.join(a, b) |> Set.value |> Enum.sort
[1,2]
Specs:
Check to see if an element is a member of a set.
iex> alias Loom.AWORSet, as: Set
iex> Set.new
...> |> Set.add(:a, 1)
...> |> Set.member?(1)
true
Specs:
- new :: t
Creates a new AWORSet
The identity value for this is []
, an empty set.
iex> alias Loom.AWORSet, as: Set
iex> Set.new |> Set.value
[]
Specs:
Remove an element from an AWORSet
iex> alias Loom.AWORSet, as: Set
iex> Set.new
...> |> Set.add(:a, 1)
...> |> Set.add(:a, 2)
...> |> Set.remove(1)
...> |> Set.value
[2]