Skip to content

PNCounter[optional A: (Integer[A] val & Unsigned)]

[Source]

A mutable counter, which can be both increased and decreased.

This data type tracks the state seen from each replica, thus the size of the state will grow proportionally with the number of total replicas. New replicas may be added as peers at any time, provided that they use unique ids. Read-only replicas which never change state and only observe need not use unique ids, and should use an id of zero, by convention.

The counter is implemented as a pair of grow-only counters, with one counter representing growth in the positive direction, and the other counter representing growth in the negative direction, with the total value of the counter being calculated from the difference in magnitude.

Because the data type is composed of a pair of eventually consistent CRDTs, the calculated value of the overall counter is also eventually consistent.

All mutator methods accept and return a convergent delta-state.

class ref PNCounter[optional A: (Integer[A] val & Unsigned)] is
  Comparable[PNCounter[A] ref] ref,
  Convergent[PNCounter[A] ref] ref,
  Replicated ref

Implements


Constructors

create

[Source]

Instantiate the PNCounter under the given unique replica id.

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

Parameters

Returns


Public Functions

is_empty

[Source]

Return true if the data structure contains no information (bottom state).

fun box is_empty()
: Bool val

Returns


apply

[Source]

Return the current value of the counter (the difference in magnitude).

fun box apply()
: A

Returns

  • A

value

[Source]

Return the current value of the counter (the difference in magnitude).

fun box value()
: A

Returns

  • A

increment[optional D: PNCounter[A] ref]

[Source]

Increment the counter by the given value. Accepts and returns a convergent delta-state.

fun ref increment[optional D: PNCounter[A] ref](
  value': A = 1,
  delta': D = recover PNCounter[A](0) end)
: D^

Parameters

  • value': A = 1
  • delta': D = recover PNCounterA end

Returns

  • D^

decrement[optional D: PNCounter[A] ref]

[Source]

Decrement the counter by the given value. Accepts and returns a convergent delta-state.

fun ref decrement[optional D: PNCounter[A] ref](
  value': A = 1,
  delta': D = recover PNCounter[A](0) end)
: D^

Parameters

  • value': A = 1
  • delta': D = recover PNCounterA end

Returns

  • D^

converge

[Source]

Converge from the given PNCounter into this one. We converge the positive and negative counters, pairwise. Returns true if the convergence added new information to the data structure.

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

Parameters

Returns


string

[Source]

Return a best effort at printing the register. If A is Stringable, use the string representation of the value; otherwise print as a question mark.

fun box string()
: String iso^

Returns


eq

[Source]

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

Parameters

Returns


ne

[Source]

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

Parameters

Returns


lt

[Source]

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

Parameters

Returns


le

[Source]

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

Parameters

Returns


gt

[Source]

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

Parameters

Returns


ge

[Source]

fun box ge(
  that: PNCounter[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: PNCounter[A] box)
: Compare

Parameters

Returns