maca / crdt-replicated-graph / RG.Node

This module implements types and functions to build, find, get values from, and compare nodes


type Node a
    = Node ({ path : Path, children : List (Node a), data : Maybe a })
    | Tombstone ({ path : Path })

Node can be either a branch or leaf Node with optional data or a Tombstone representing a removed Node


type alias Path =
List Basics.Int

The path of the node is represented as a list of integers

init : Maybe a -> Path -> Node a

Build a node

timestamp (node (Just 'a') [0, 1]) == 1
path (node (Just 'a') [0, 1]) == [0, 1]
data (node (Just 'a') [0, 1]) == Just 'a'

root : Node a

Build a root node

timestamp root == 0
path root == []
data root == Nothing

tombstone : Path -> Node a

Build a tombstone providing timestamp and path

timestamp (tombstone [0, 1]) == 1
path (tombstone [0, 1]) == [0, 1]
data (tombstone [0, 1]) == Nothing

children : Node a -> List (Node a)

Return a list of a nodes' children

data : Node a -> Maybe a

Return the data of a node

data (node (Just 'a') [0, 1]) == Just 'a'
data (tombstone [0, 1]) == Nothing

timestamp : Node a -> Basics.Int

Return the timestamp of a node

timestamp (node (Just 'a') [0, 1]) == 1

path : Node a -> Path

Return the path of a node

path (node (Just 'a') [0, 1]) == [0, 1]

descendant : Path -> Node a -> Maybe (Node a)

Return Just a nodes' descendant if found by path or Nothing

hasTimestamp : Basics.Int -> Node a -> Basics.Bool

Determine wether a node has a timestamp

hasTimestamp 1 (node (Just 'a') [0, 1]) == True
hasTimestamp 1 (node (Just 'a') [0, 2]) == False