TwoPhaseSet

@Serializable
class TwoPhaseSet<E> : Quilted<TwoPhaseSet<E>>

A set with tombstoned remove: two grow-only sets, the added set and the removed (tombstone) set, both merged by union. An element is present iff it was added and is not tombstoned. Tombstones win permanently — once removed, an element can never be re-added; even a fresh add will be masked.

The pedagogical wart: tombstones grow without bound. The next rung up, ORSet, uses dots + causal context so an add issued after a remove can survive — at the cost of more bookkeeping.

Samples

var s = TwoPhaseSet.empty<String>()
s = s.piece(s.add("alice"))
check(s.contains("alice"))

s = s.piece(s.remove("alice"))
check(!s.contains("alice"))

// Even re-adding won't bring it back — the tombstone wins.
s = s.piece(s.add("alice"))
check(!s.contains("alice"))

Types

Link copied to clipboard
object Companion

Properties

Link copied to clipboard
val added: Set<E>
Link copied to clipboard
val elements: Set<E>

Elements currently present.

Link copied to clipboard
val removed: Set<E>

Functions

Link copied to clipboard
fun add(element: E): Patch<TwoPhaseSet<E>>

Add element (no effect on present-state if it's already tombstoned).

Link copied to clipboard
open fun causalDots(): Set<Dot>

The causal Dots this state has delivered — (author, author-seq) per op.

Link copied to clipboard
fun contains(element: E): Boolean

True if element was added and has not been tombstoned.

Link copied to clipboard
open operator override fun equals(other: Any?): Boolean
Link copied to clipboard
open override fun hashCode(): Int
Link copied to clipboard
open override fun piece(other: TwoPhaseSet<E>): TwoPhaseSet<E>

The join: union both component sets.

Link copied to clipboard
fun remove(element: E): Patch<TwoPhaseSet<E>>

Tombstone element (permanent — even a later add will be masked).

Link copied to clipboard
open override fun toString(): String