Class GSet<E>
java.lang.Object
com.loomcache.server.datastructures.crdt.GSet<E>
Grow-only Set CRDT (G-Set).
A G-Set is a state-based CRDT that represents a set where elements can only be added, never removed. Concurrent adds and removals are handled by semantics where only adds win.
Key properties:
- Elements can only be added, never removed
- Merge: union of all sets from all replicas
- Simple and highly available (no need for tracking tombstones)
- Convergent: all nodes reach the same state given the same history
- Since:
- 1.3
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidAdd an element to the set.booleanCheck if an element is in the set.elements()Get an immutable copy of all elements in the set.@NonNull StringgetName()@NonNull StringbooleanisEmpty()Check if the set is empty.voidMerge another G-Set into this one (anti-entropy).voidreset()Reset is NOT supported for G-Sets.intsize()Get the number of elements in the set.
-
Constructor Details
-
GSet
-
-
Method Details
-
getName
-
getNodeId
-
add
Add an element to the set. In a G-Set, this is the only mutation allowed.- Parameters:
element- the element to add- Throws:
NullPointerException- if element is null
-
contains
Check if an element is in the set.- Parameters:
element- the element to check- Returns:
- true if the element is in the set
-
size
public int size()Get the number of elements in the set.- Returns:
- the set size
-
elements
-
isEmpty
public boolean isEmpty()Check if the set is empty.- Returns:
- true if no elements are in the set
-
merge
Merge another G-Set into this one (anti-entropy). Merge operation is a union of sets. Merge is idempotent and commutative.- Parameters:
other- the other G-Set to merge- Throws:
IllegalArgumentException- if names don't match
-
reset
public void reset()Reset is NOT supported for G-Sets. G-Set state is a join-semilattice under set union; clearing is non-monotonic and will be silently reversed on the next merge with any replica that has the old state.- Throws:
UnsupportedOperationException- always — reset violates CRDT merge invariants
-