niho / elm-crdt / CRDT.ORSet

An ORSet (Observed Remove Set) is a replicated set in which additions take precedence over removals. For example, if one replica removes and re-adds an element, while another replica concurrently removes the element, then the merged outcome is that the element is in the set.

ORSet


type alias Replica =
String

Each replica that modifies the set is represented by a unique string ID.


type ORSet comparable

ORSet state.

empty : ORSet comparable

Constructor that creates a new empty ORSet.

insert : comparable -> Replica -> ORSet comparable -> ORSet comparable

Insert a value in the set.

remove : comparable -> ORSet comparable -> ORSet comparable

Remove a value from the set.

member : comparable -> ORSet comparable -> Basics.Bool

Determine if a value is in the set.

merge : ORSet comparable -> ORSet comparable -> ORSet comparable

Merge two ORSet states.

fromList : List comparable -> String -> ORSet comparable

Convert a list of values into an ORSet.

toList : ORSet comparable -> List comparable

Convert an ORSet to a list of values.

toSet : ORSet comparable -> Set comparable

Convert an ORSet to a Set.

Operations


type Operation comparable
    = Insert comparable Replica
    | Remove comparable

Operations that will modify the state of the set.

apply : Operation comparable -> ORSet comparable -> ORSet comparable

Apply an operation on an ORSet.

patch : List (Operation comparable) -> ORSet comparable -> ORSet comparable

Apply a list of operations (a patch) on an ORSet.

Serialization

encode : ORSet String -> Json.Encode.Value

Encode an ORSet as JSON.

decoder : Json.Decode.Decoder (ORSet String)

Decode an ORSet from JSON.