CCounter[optional A: (Integer[A] val & (Unsigned | Signed))]¶
A mutable counter, which can be both increased and decreased.
This data type has the same general semantics as PNCounter, but instead of being modeled as two GCounters (positive and negative), it is built with the generic "dot kernel" abstraction used for tracking causality of updates.
Each replica tracks its local value as a dot in the dot kernel. When updating the local value, the old dot is removed and a new dot with a happens-after relationship to the old dot (sequence number incremented) is added. When converging, dots that have the same id are trimmed so that only the one with the latest sequence number will remain.
The total value of the counter is the sum of the local values of all replicas.
Because the dot kernel abstraction provides an eventually-consistent set of replica-associated values, and this data structure uses a commutative strategy for folding them into a result, that result is eventually consistent.
All mutator methods accept and return a convergent delta-state.
class ref CCounter[optional A: (Integer[A] val & (Unsigned | Signed))] is
Comparable[CCounter[A] ref] ref,
Causal[CCounter[A] ref] ref
Implements¶
- Comparable[CCounter[A] ref] ref
- Causal[CCounter[A] ref] ref
Constructors¶
create¶
Instantiate under the given unique replica id.
Parameters¶
- id: ID
Returns¶
- CCounter[A] ref^
Public Functions¶
is_empty¶
Return true if there are no values ever recorded from any replica. This is true at creation, after calling the clear method, or after a converge that results in all values being cleared.
Returns¶
- Bool val
apply¶
Return the current value of the counter (the sum of all local values).
Returns¶
- A
value¶
Return the current value of the counter (the sum of all local values).
Returns¶
- A
increment[optional D: CCounter[A] ref]¶
Increment the counter by the given value. Accepts and returns a convergent delta-state.
fun ref increment[optional D: CCounter[A] ref](
value': A = 1,
delta': D = recover CCounter[A](0) end)
: D^
Parameters¶
- value': A = 1
- delta': D = recover CCounterA end
Returns¶
- D^
decrement[optional D: CCounter[A] ref]¶
Decrement the counter by the given value. Accepts and returns a convergent delta-state.
fun ref decrement[optional D: CCounter[A] ref](
value': A = 1,
delta': D = recover CCounter[A](0) end)
: D^
Parameters¶
- value': A = 1
- delta': D = recover CCounterA end
Returns¶
- D^
clear[optional D: CCounter[A] ref]¶
Remove all locally visible changes to the counter, resetting it to zero. Accepts and returns a convergent delta-state.
Parameters¶
- delta': D = recover CCounterA end
Returns¶
- D^
converge¶
Converge from the given CCounter into this one. Returns true if the convergence added new information to the data structure.
Parameters¶
- that: CCounter[A] box
Returns¶
- Bool val
string¶
Print the value of the counter.
Returns¶
- String iso^
eq¶
Parameters¶
- that: CCounter[A] box
Returns¶
- Bool val
ne¶
Parameters¶
- that: CCounter[A] box
Returns¶
- Bool val
lt¶
Parameters¶
- that: CCounter[A] box
Returns¶
- Bool val
le¶
Parameters¶
- that: CCounter[A] box
Returns¶
- Bool val
gt¶
Parameters¶
- that: CCounter[A] box
Returns¶
- Bool val
ge¶
Parameters¶
- that: CCounter[A] box
Returns¶
- Bool val
from_tokens¶
Deserialize an instance of this data structure from a stream of tokens.
Parameters¶
- that: TokensIterator ref
Returns¶
- None val ?
each_token¶
Serialize the data structure, capturing each token into the given Tokens.
Parameters¶
- tokens: Tokens ref
Returns¶
- None val
compare¶
Parameters¶
- that: CCounter[A] box