CRDT v0.2.0 CRDT.GCounter View Source

A grow-only counter

Link to this section Summary

Types

t()

A GCounter with an ID and map of site values

Functions

Incorporate a remote site value into the GCounter

Increment the local site value of the GCounter

Initialize a new GCounter

Get the value of the GCounter

Link to this section Types

Link to this type t() View Source
t() :: %CRDT.GCounter{id: id(), values: %{optional(id()) => value()}}

A GCounter with an ID and map of site values

Link to this section Functions

Link to this function incorporate(g, id, new_val) View Source
incorporate(t(), id(), value()) :: t()

Incorporate a remote site value into the GCounter.

iex> g = GCounter.init(1)
iex> g2 = GCounter.init(2)
iex> g
...> |> GCounter.incorporate(g2.id, GCounter.value(g2))
...> |> GCounter.value
3
Link to this function increment(g) View Source
increment(t()) :: t()

Increment the local site value of the GCounter.

iex> GCounter.init()
...> |> GCounter.increment
...> |> GCounter.value
1
Link to this function init(val \\ 0) View Source
init(value()) :: t()

Initialize a new GCounter.

Accepts an initial value, which defaults to 0.

iex> GCounter.init() |> GCounter.value
0

iex> GCounter.init(1) |> GCounter.value
1
Link to this function value(g) View Source
value(t()) :: value()

Get the value of the GCounter.

iex> g = GCounter.init
iex> g = Enum.reduce(1..100, g, fn (_, g) ->
...>   GCounter.increment(g)
...> end)
iex> GCounter.value(g)
100