CRDT v0.2.0 CRDT.PNCounter View Source

A counter that can both grow and shrink

Link to this section Summary

Types

t()

A PNCounter with an ID and map of site values

Functions

Decrement the local site value of the PNCounter

Incorporate a remote site value into the PNCounter

Increment the local site value of the PNCounter

Initialize a new PNCounter

Get the value of the PNCounter

Link to this section Types

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

A PNCounter with an ID and map of site values

Link to this section Functions

Link to this function decrement(g) View Source
decrement(t()) :: t()

Decrement the local site value of the PNCounter.

iex> PNCounter.init(1)
...> |> PNCounter.decrement
...> |> PNCounter.value
0
Link to this function incorporate(g, id, arg) View Source
incorporate(t(), id(), {value(), value()}) :: t()

Incorporate a remote site value into the PNCounter.

iex> pn = PNCounter.init(1)
iex> pn2 = PNCounter.init(2)
iex> pn = PNCounter.incorporate(pn, pn2.id, pn2.values[pn2.id])
iex> PNCounter.value(pn)
3
Link to this function increment(g) View Source
increment(t()) :: t()

Increment the local site value of the PNCounter.

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

Initialize a new PNCounter.

Accepts an initial value, which defaults to 0.

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

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

Get the value of the PNCounter.

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