THashSet[A: Any val, T: Comparable[T] val, B: (BiasInsert val | BiasDelete val), H: HashFunction[A] val]¶
A mutable set with last-write-wins semantics for insertion and deletion. That is, every insertion and deletion operation includes a logical timestamp (U64 by default, though it may be any Comparable immutable type), and 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.
This data structure is conceptually composed of two grow-only sets (GSet); one for insertions and one for deletions. Both sets include the logical timestamp for each element. An element is present in the combined logical set if it is present in only the insertion set (not in the deletion set), or if the logical timestamp of the insertion is higher than that of the deletion.
The actual implementation is a bit more memory-optimized than a literal pair of GSets - it stores the data as a map with the elements as keys and each value being a 2-tuple with the highest logical timestamp so far and a boolean indicating whether that timestamp represents an insertion or a deletion.
If the logical timestamp is equal for two compared operations, the tie will be broken by the bias type parameter. BiasInsert implies that inserts will override deletions in a tie, while BiasDelete implies the opposite. The default bias is BiasInsert.
Because the set is composed of two grow-only sets that are eventually consistent when converged, the overall result is also eventually consistent. 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 THashSet[A: Any val, T: Comparable[T] val, B: (BiasInsert val | BiasDelete val), H: HashFunction[A] val] is
Comparable[THashSet[A, T, B, H] ref] ref,
Convergent[THashSet[A, T, B, H] ref] ref,
Replicated ref
Implements¶
- Comparable[THashSet[A, T, B, H] ref] ref
- Convergent[THashSet[A, T, B, H] ref] ref
- Replicated ref
Constructors¶
create¶
Returns¶
- THashSet[A, T, B, H] ref^
Public Functions¶
is_empty¶
Return true if the data structure contains no information (bottom state).
Returns¶
- Bool val
size¶
Return the number of items in the set.
Returns¶
- USize val
apply¶
Return the logical timestamp if it's in the set, otherwise raise an error.
Parameters¶
- value: val->A
Returns¶
- T ?
contains¶
Check whether the set contains the given value.
Parameters¶
- value: val->A
Returns¶
- Bool val
clear[optional D: THashSet[A, T, B, H] ref]¶
Remove all elements from the set. Accepts and returns a convergent delta-state.
fun ref clear[optional D: THashSet[A, T, B, H] ref](
timestamp: T,
delta: D = recover THashSet[A, T, B, H] end)
: D^
Parameters¶
- timestamp: T
- delta: D = recover THashSet[A, T, B, H] end
Returns¶
- D^
set[optional D: THashSet[A, T, B, H] ref]¶
Add a value to the set. Accepts and returns a convergent delta-state.
fun ref set[optional D: THashSet[A, T, B, H] ref](
value: A,
timestamp: T,
delta: D = recover THashSet[A, T, B, H] end)
: D^
Parameters¶
- value: A
- timestamp: T
- delta: D = recover THashSet[A, T, B, H] end
Returns¶
- D^
unset[optional D: THashSet[A, T, B, H] ref]¶
Remove a value from the set. Accepts and returns a convergent delta-state.
fun ref unset[optional D: THashSet[A, T, B, H] ref](
value: box->A!,
timestamp: T,
delta: D = recover THashSet[A, T, B, H] end)
: D^
Parameters¶
- value: box->A!
- timestamp: T
- delta: D = recover THashSet[A, T, B, H] end
Returns¶
- D^
union[optional D: THashSet[A, T, B, H] ref]¶
Add everything in the given iterator to the set. Accepts and returns a convergent delta-state.
fun ref union[optional D: THashSet[A, T, B, H] ref](
that: Iterator[(A , T)] ref,
delta: D = recover THashSet[A, T, B, H] end)
: D^
Parameters¶
- that: Iterator[(A , T)] ref
- delta: D = recover THashSet[A, T, B, H] end
Returns¶
- D^
converge¶
Converge from the given TSet into this one. For this data type, the convergence is the union of both constituent sets. Returns true if the convergence added new information to the data structure.
Parameters¶
- that: THashSet[A, T, B, H] box
Returns¶
- Bool val
result¶
Return the elements of the resulting logical set as a single flat set. Information about specific deletions is discarded, so that the case of a deleted element is indistinct from that of an element never inserted.
Returns¶
- HashSet[A, H] ref
map¶
Return the elements of the resulting logical set as a single flat map, with the elements as keys and logical timestamps of the insertion as timestamps. Information about specific deletions is discarded, so that the case of a deleted element is indistinct from that of an element never inserted.
Returns¶
- HashMap[A, T, H] ref
string¶
Return a best effort at printing the set. If A is a Stringable box, use the string representation of each value; otherwise print the as question marks.
Returns¶
- String iso^
eq¶
Parameters¶
- that: THashSet[A, T, B, H] box
Returns¶
- Bool val
ne¶
Parameters¶
- that: THashSet[A, T, B, H] box
Returns¶
- Bool val
lt¶
Parameters¶
- that: THashSet[A, T, B, H] box
Returns¶
- Bool val
le¶
Parameters¶
- that: THashSet[A, T, B, H] box
Returns¶
- Bool val
gt¶
Parameters¶
- that: THashSet[A, T, B, H] box
Returns¶
- Bool val
ge¶
Parameters¶
- that: THashSet[A, T, B, H] box
Returns¶
- Bool val
values¶
Returns¶
- Iterator[A] ref^
timestamps¶
Returns¶
- Iterator[T] ref^
pairs¶
Returns¶
- Iterator[(A , T)] ref^
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
compare¶
Parameters¶
- that: THashSet[A, T, B, H] box