Skip to content

TReg[A: Comparable[A] val, V: _DefaultValueFn[A] val, optional T: (Integer[T] val & Unsigned), optional B: (BiasGreater val | BiasLesser val)]

[Source]

A mutable register with last-write-wins semantics for updating the value. That is, every update operation includes a logical timestamp (U64 by default, though it may be any unsigned integer type), and update operations are overridden only by those with a higher logical timestamp.

This implies that the timestamps must be correct (or at least logically so) in order for the last-write-wins semantics to hold true.

If the logical timestamp is equal for two compared operations, the tie will be broken by the bias type parameter. BiasGreater implies that the greater of the two compared values will be chosen, while BiasLesser implies the opposite. The default bias is BiasGreater.

Because there is an order-independent way of comparing both the timestamp and the value term of all update operations, all conflicts can be resolved in a commutative way; thus, the result is eventually consistent in all replicas. The same bias must be used on all replicas for tie results to be consistent.

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

class ref TReg[A: Comparable[A] val, V: _DefaultValueFn[A] val, optional T: (Integer[T] val & Unsigned), optional B: (BiasGreater val | BiasLesser val)] is
  Equatable[TReg[A, V, T, B] ref] ref,
  Convergent[TReg[A, V, T, B] ref] ref,
  Replicated ref

Implements


Constructors

create

[Source]

new ref create()
: TReg[A, V, T, B] ref^

Returns

  • TReg[A, V, T, B] ref^

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 register.

fun box apply()
: A

Returns

  • A

value

[Source]

Return the current value of the register.

fun box value()
: A

Returns

  • A

timestamp

[Source]

Return the latest timestamp of the register.

fun box timestamp()
: T

Returns

  • T

update[optional D: TReg[A, V, T, B] ref]

[Source]

Update the value and timestamp of the register, provided that the given timestamp is newer than the current timestamp of the register. If the given timestamp is older, the update is ignored. Accepts and returns a convergent delta-state.

fun ref update[optional D: TReg[A, V, T, B] ref](
  value': A,
  timestamp': T,
  delta': D = D)
: D^

Parameters

  • value': A
  • timestamp': T
  • delta': D = D

Returns

  • D^

converge

[Source]

Converge from the given TReg into this one. For this data type, the convergence is a simple update operation. Returns true if the convergence added new information to the data structure.

fun ref converge(
  that: TReg[A, V, T, B] box)
: Bool val

Parameters

  • that: TReg[A, V, T, B] box

Returns


string

[Source]

Return a best effort at printing the log. If A and T are Stringable, use the string representation of them; otherwise print as question marks.

fun box string()
: String iso^

Returns


eq

[Source]

fun box eq(
  that: TReg[A, V, T, B] box)
: Bool val

Parameters

  • that: TReg[A, V, T, B] box

Returns


ne

[Source]

fun box ne(
  that: TReg[A, V, T, B] box)
: Bool val

Parameters

  • that: TReg[A, V, T, B] box

Returns


lt

[Source]

fun box lt(
  that: TReg[A, V, T, B] box)
: Bool val

Parameters

  • that: TReg[A, V, T, B] box

Returns


le

[Source]

fun box le(
  that: TReg[A, V, T, B] box)
: Bool val

Parameters

  • that: TReg[A, V, T, B] box

Returns


gt

[Source]

fun box gt(
  that: TReg[A, V, T, B] box)
: Bool val

Parameters

  • that: TReg[A, V, T, B] box

Returns


ge

[Source]

fun box ge(
  that: TReg[A, V, T, B] box)
: Bool val

Parameters

  • that: TReg[A, V, T, B] box

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