DotKernelSingle[A: Any val]¶
This class is a reusable abstraction meant for use inside other CRDTs.
It is a variant of the DotKernel class which changes the indexing of the map of active values, such that at most one value per replica is retained. This simplifies the logic for data structures like CCounter which operate with this assumption.
See the docs for the DotKernel class for more information.
Implements¶
- Replicated ref
Constructors¶
create¶
Instantiate under the given unique replica id.
It will only be possible to add dotted values under this replica id,
aside from converging it as external data with the converge function.
Parameters¶
- id': ID
Returns¶
- DotKernelSingle[A] ref^
create_in¶
Instantiate under the given DotContext.
Parameters¶
- ctx': DotContext ref
Returns¶
- DotKernelSingle[A] ref^
Public Functions¶
context¶
Get the underlying DotContext.
Returns¶
- this->DotContext ref
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
values¶
Return an iterator over the active values in this kernel.
Returns¶
- Iterator[A] ref^
update[optional D: DotKernelSingle[A] ref]¶
Update the value for this replica in the map of active values. The next-sequence-numbered dot for this replica will be used, so that the new value has a happens-after causal relationship with the previous value.
fun ref update[optional D: DotKernelSingle[A] ref](
value': A,
delta': D = recover DotKernelSingle[A](0) end)
: D^
Parameters¶
- value': A
- delta': D = recover DotKernelSingleA end
Returns¶
- D^
upsert[optional D: DotKernelSingle[A] ref]¶
Update the value for this replica in the map of active values, using a function to define the strategy for updating an existing value. The next-sequence-numbered dot for this replica will be used, so that the new value has a happens-after causal relationship with the previous value.
fun ref upsert[optional D: DotKernelSingle[A] ref](
value': A,
fn': {(A, A): A^}[A, D] box,
delta': D = recover DotKernelSingle[A](0) end)
: D^
Parameters¶
- value': A
- fn': {(A, A): A^}[A, D] box
- delta': D = recover DotKernelSingleA end
Returns¶
- D^
remove_value[E: EqFn[A] val, optional D: DotKernelSingle[A] ref]¶
Remove all dots with this value from the map of active values, using the given eq_fn for testing equality between pairs of values of type A. They will be retained in the causal context (if they were already present).
This removes the dots and associated value while keeping reminders that we have seen them before, so that we can ignore them if we see them again.
If the value was not present, this function silently does nothing.
Accepts and returns a convergent delta-state.
fun ref remove_value[E: EqFn[A] val, optional D: DotKernelSingle[A] ref](
value': A,
delta': D = recover DotKernelSingle[A](0) end)
: D^
Parameters¶
- value': A
- delta': D = recover DotKernelSingleA end
Returns¶
- D^
remove_all[optional D: DotKernelSingle[A] ref]¶
Remove all dots currently present in the map of active values. They will be retained in the causal context.
This removes the dots and associated values while keeping reminders that we have seen them before, so that we can ignore them if we see them again.
Accepts and returns a convergent delta-state.
fun ref remove_all[optional D: DotKernelSingle[A] ref](
delta': D = recover DotKernelSingle[A](0) end)
: D^
Parameters¶
- delta': D = recover DotKernelSingleA end
Returns¶
- D^
converge¶
Catch up on active values and dot history from that kernel into this one, using the dot history as a context for understanding for which disagreements we are out of date, and for which disagreements the other is out of date.
Parameters¶
- that: DotKernelSingle[A] box
Returns¶
- Bool val
converge_empty_in¶
Optimize for the special case of converging from a peer with an empty map, taking only their DotContext as an argument for resolving disagreements.
Parameters¶
- ctx': DotContext box
Returns¶
- Bool val
string¶
Return a best effort at printing the data structure. This is intended for debugging purposes only.
Returns¶
- String iso^
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