P2HashSet[A: Any val, H: HashFunction[A] val]¶
An unordered mutable two-phase set that supports one-time removal. That is, once an element has been deleted it may never be inserted again. In other words, the deletion is final, and may not be overridden. Any attempts to insert an already-deleted element will be silently ignored.
This data structure is based on two grow-only sets (GSet); one for insertions and one for deletions. An element is present in the combined logical set if it is present in only the insertion set (not in the deletion set).
Because the set is composed of two grow-only sets that are eventually consistent when converged, the overall result is also eventually consistent.
All mutator methods accept and return a convergent delta-state.
class ref P2HashSet[A: Any val, H: HashFunction[A] val] is
Comparable[P2HashSet[A, H] ref] ref,
Convergent[P2HashSet[A, H] ref] ref,
Replicated ref
Implements¶
- Comparable[P2HashSet[A, H] ref] ref
- Convergent[P2HashSet[A, H] ref] ref
- Replicated ref
Constructors¶
create¶
Returns¶
- P2HashSet[A, 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 value if it's in the set, otherwise raise an error.
Parameters¶
- value: val->A
Returns¶
- val->A ?
contains¶
Check whether the set contains the given value.
Parameters¶
- value: val->A
Returns¶
- Bool val
clear¶
Remove all elements from the set.
Returns¶
- None val
set[optional D: P2HashSet[A, H] ref]¶
Add a value to the set. Accepts and returns a convergent delta-state.
fun ref set[optional D: P2HashSet[A, H] ref](
value: A,
delta: D = recover P2HashSet[A, H] end)
: D^
Parameters¶
- value: A
- delta: D = recover P2HashSet[A, H] end
Returns¶
- D^
unset[optional D: P2HashSet[A, H] ref]¶
Remove a value from the set. Accepts and returns a convergent delta-state.
fun ref unset[optional D: P2HashSet[A, H] ref](
value: A,
delta: D = recover P2HashSet[A, H] end)
: D^
Parameters¶
- value: A
- delta: D = recover P2HashSet[A, H] end
Returns¶
- D^
union[optional D: P2HashSet[A, H] ref]¶
Add everything in the given iterator to the set. Accepts and returns a convergent delta-state.
fun ref union[optional D: P2HashSet[A, H] ref](
that: Iterator[A] ref,
delta: D = recover P2HashSet[A, H] end)
: D^
Parameters¶
- that: Iterator[A] ref
- delta: D = recover P2HashSet[A, H] end
Returns¶
- D^
converge¶
Converge from the given P2Set 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: P2HashSet[A, 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
string¶
Return a best effort at printing the set. If A is a Stringable, use the string representation of each value; otherwise print them as question marks.
Returns¶
- String iso^
eq¶
Parameters¶
- that: P2HashSet[A, H] box
Returns¶
- Bool val
ne¶
Parameters¶
- that: P2HashSet[A, H] box
Returns¶
- Bool val
lt¶
Parameters¶
- that: P2HashSet[A, H] box
Returns¶
- Bool val
le¶
Parameters¶
- that: P2HashSet[A, H] box
Returns¶
- Bool val
gt¶
Parameters¶
- that: P2HashSet[A, H] box
Returns¶
- Bool val
ge¶
Parameters¶
- that: P2HashSet[A, H] box
Returns¶
- Bool val
values¶
Returns¶
- Iterator[A] 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: P2HashSet[A, H] box