Skip to content

CCounter[optional A: (Integer[A] val & (Unsigned | Signed))]

[Source]

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


Constructors

create

[Source]

Instantiate under the given unique replica id.

new ref create(
  id: ID)
: CCounter[A] ref^

Parameters

Returns


Public Functions

is_empty

[Source]

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.

fun box is_empty()
: Bool val

Returns


apply

[Source]

Return the current value of the counter (the sum of all local values).

fun box apply()
: A

Returns

  • A

value

[Source]

Return the current value of the counter (the sum of all local values).

fun box value()
: A

Returns

  • A

increment[optional D: CCounter[A] ref]

[Source]

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]

[Source]

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]

[Source]

Remove all locally visible changes to the counter, resetting it to zero. Accepts and returns a convergent delta-state.

fun ref clear[optional D: CCounter[A] ref](
  delta': D = recover CCounter[A](0) end)
: D^

Parameters

  • delta': D = recover CCounterA end

Returns

  • D^

converge

[Source]

Converge from the given CCounter into this one. Returns true if the convergence added new information to the data structure.

fun ref converge(
  that: CCounter[A] box)
: Bool val

Parameters

Returns


string

[Source]

Print the value of the counter.

fun box string()
: String iso^

Returns


eq

[Source]

fun box eq(
  that: CCounter[A] box)
: Bool val

Parameters

Returns


ne

[Source]

fun box ne(
  that: CCounter[A] box)
: Bool val

Parameters

Returns


lt

[Source]

fun box lt(
  that: CCounter[A] box)
: Bool val

Parameters

Returns


le

[Source]

fun box le(
  that: CCounter[A] box)
: Bool val

Parameters

Returns


gt

[Source]

fun box gt(
  that: CCounter[A] box)
: Bool val

Parameters

Returns


ge

[Source]

fun box ge(
  that: CCounter[A] box)
: Bool val

Parameters

Returns


from_tokens

[Source]

Deserialize an instance of this data structure from a stream of tokens.

fun ref from_tokens(
  that: TokensIterator ref)
: None val ?

Parameters

Returns


each_token

[Source]

Serialize the data structure, capturing each token into the given Tokens.

fun ref each_token(
  tokens: Tokens ref)
: None val

Parameters

Returns


compare

[Source]

fun box compare(
  that: CCounter[A] box)
: Compare

Parameters

Returns