Raxol.Swarm.CRDT.ORSet (Raxol v2.3.0)

View Source

Observed-Remove Set CRDT.

Add-wins semantics: concurrent add and remove of the same element results in the element being present. Each add generates a unique dot (node + counter). Remove records all observed dots for that element. An element is present if it has any dot not in the remove set.

Summary

Functions

Adds an element to the set, generating a unique dot.

Returns true if the element is in the set.

Merges two OR-Sets. For each element, union the dots. Union the removed sets. An element survives if it has any dot not in the merged removed set.

Creates an empty OR-Set.

Removes an element from the set by recording all its current dots as removed. Only dots observed at this point are removed -- concurrent adds with new dots will survive.

Returns the number of elements in the set.

Returns all elements currently in the set.

Types

dot()

@type dot() :: {node(), pos_integer()}

t()

@type t() :: %Raxol.Swarm.CRDT.ORSet{
  clock: %{required(node()) => non_neg_integer()},
  entries: %{required(term()) => MapSet.t(dot())},
  removed: MapSet.t(dot())
}

Functions

add(set, element, node \\ Node.self())

@spec add(t(), term(), node()) :: t()

Adds an element to the set, generating a unique dot.

member?(set, element)

@spec member?(t(), term()) :: boolean()

Returns true if the element is in the set.

merge(a, b)

@spec merge(t(), t()) :: t()

Merges two OR-Sets. For each element, union the dots. Union the removed sets. An element survives if it has any dot not in the merged removed set.

new()

@spec new() :: t()

Creates an empty OR-Set.

remove(set, element)

@spec remove(t(), term()) :: t()

Removes an element from the set by recording all its current dots as removed. Only dots observed at this point are removed -- concurrent adds with new dots will survive.

size(set)

@spec size(t()) :: non_neg_integer()

Returns the number of elements in the set.

to_list(set)

@spec to_list(t()) :: [term()]

Returns all elements currently in the set.