CRDT v0.2.0 CRDT.PNCounter View Source
A counter that can both grow and shrink
Link to this section Summary
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
Decrement the local site value of the PNCounter.
iex> PNCounter.init(1)
...> |> PNCounter.decrement
...> |> PNCounter.value
0
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
Increment the local site value of the PNCounter.
iex> PNCounter.init()
...> |> PNCounter.increment
...> |> PNCounter.value
1
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
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