TReg[A: Comparable[A] val, V: _DefaultValueFn[A] val, optional T: (Integer[T] val & Unsigned), optional B: (BiasGreater val | BiasLesser val)]¶
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¶
- Equatable[TReg[A, V, T, B] ref] ref
- Convergent[TReg[A, V, T, B] ref] ref
- Replicated ref
Constructors¶
create¶
Returns¶
- TReg[A, V, T, B] ref^
Public Functions¶
is_empty¶
Return true if the data structure contains no information (bottom state).
Returns¶
- Bool val
apply¶
Return the current value of the register.
Returns¶
- A
value¶
Return the current value of the register.
Returns¶
- A
timestamp¶
Return the latest timestamp of the register.
Returns¶
- T
update[optional D: TReg[A, V, T, B] ref]¶
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.
Parameters¶
- value': A
- timestamp': T
- delta': D = D
Returns¶
- D^
converge¶
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.
Parameters¶
- that: TReg[A, V, T, B] box
Returns¶
- Bool val
string¶
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.
Returns¶
- String iso^
eq¶
Parameters¶
- that: TReg[A, V, T, B] box
Returns¶
- Bool val
ne¶
Parameters¶
- that: TReg[A, V, T, B] box
Returns¶
- Bool val
lt¶
Parameters¶
- that: TReg[A, V, T, B] box
Returns¶
- Bool val
le¶
Parameters¶
- that: TReg[A, V, T, B] box
Returns¶
- Bool val
gt¶
Parameters¶
- that: TReg[A, V, T, B] box
Returns¶
- Bool val
ge¶
Parameters¶
- that: TReg[A, V, T, B] 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