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

Types

t

actor :: term

value :: term

Functions

add(set, actor, value)

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]
empty(set)

Specs:

  • empty({t, t}) :: {t, t}
  • empty(t) :: {t, t}

Empties a CRDT of all elements

iex> alias Loom.AWORSet, as: Set
iex> Set.new
...> |> Set.add(:a, 1)
...> |> Set.empty
...> |> Set.value
[]
join(aworset, aworset)

Specs:

  • join(t, t) :: t

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]
member?(aworset, value)

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
new()

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
[]
remove(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]
value(aworset)

Specs:

Returns a list of set elements.

See other examples for details.