lattice/g_set
A grow-only set (G-Set) CRDT.
Elements can be added but never removed. Merge is set union, so any element
added on any replica will eventually appear in all replicas. This is the
simplest set CRDT — use TwoPSet or ORSet if you need removal.
Example
import lattice/g_set
let a = g_set.new() |> g_set.add("alice")
let b = g_set.new() |> g_set.add("bob")
let merged = g_set.merge(a, b)
g_set.contains(merged, "alice") // -> True
g_set.contains(merged, "bob") // -> True
Types
Values
pub fn add(g_set: GSet(a), element: a) -> GSet(a)
Add an element to the set.
This operation is idempotent: adding the same element multiple times is equivalent to adding it once.
pub fn contains(g_set: GSet(a), element: a) -> Bool
Check if the set contains the given element.
Returns True if element was ever added to this set or any merged replica.
pub fn from_json(
json_string: String,
) -> Result(GSet(String), json.DecodeError)
Decode a GSet(String) from a JSON string produced by to_json.
Returns Error if the string is not valid JSON or does not match the
expected format.
pub fn merge(a: GSet(el), b: GSet(el)) -> GSet(el)
Merge two G-Sets by computing their union.
The result contains every element that was ever added to either set. Merge is commutative, associative, and idempotent (a valid CRDT join).