Skip to content

P2HashSet[A: Any val, H: HashFunction[A] val]

[Source]

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


Constructors

create

[Source]

new ref create()
: P2HashSet[A, H] ref^

Returns


Public Functions

is_empty

[Source]

Return true if the data structure contains no information (bottom state).

fun box is_empty()
: Bool val

Returns


size

[Source]

Return the number of items in the set.

fun box size()
: USize val

Returns


apply

[Source]

Return the value if it's in the set, otherwise raise an error.

fun box apply(
  value: val->A)
: val->A ?

Parameters

  • value: val->A

Returns

  • val->A ?

contains

[Source]

Check whether the set contains the given value.

fun box contains(
  value: val->A)
: Bool val

Parameters

  • value: val->A

Returns


clear

[Source]

Remove all elements from the set.

fun ref clear()
: None val

Returns


set[optional D: P2HashSet[A, H] ref]

[Source]

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]

[Source]

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]

[Source]

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

[Source]

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.

fun ref converge(
  that: P2HashSet[A, H] box)
: Bool val

Parameters

Returns


result

[Source]

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.

fun box result()
: HashSet[A, H] ref

Returns


string

[Source]

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.

fun box string()
: String iso^

Returns


eq

[Source]

fun box eq(
  that: P2HashSet[A, H] box)
: Bool val

Parameters

Returns


ne

[Source]

fun box ne(
  that: P2HashSet[A, H] box)
: Bool val

Parameters

Returns


lt

[Source]

fun box lt(
  that: P2HashSet[A, H] box)
: Bool val

Parameters

Returns


le

[Source]

fun box le(
  that: P2HashSet[A, H] box)
: Bool val

Parameters

Returns


gt

[Source]

fun box gt(
  that: P2HashSet[A, H] box)
: Bool val

Parameters

Returns


ge

[Source]

fun box ge(
  that: P2HashSet[A, H] box)
: Bool val

Parameters

Returns


values

[Source]

fun box values()
: Iterator[A] ref^

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


compare

[Source]

fun box compare(
  that: P2HashSet[A, H] box)
: Compare

Parameters

Returns