lambda-phi/disjoint-set/2.0.0

NOTE: the latest version is 3.1.0

DisjointSet

A disjoint set, also called union-find or merge-find, is a data structure that stores non-overlapping sets.

import Dict
import DisjointSet exposing (DisjointSet, empty, find, union)

-- The preferred way of creating a DisjointSet is with `union`.
abc : DisjointSet String
abc =
    empty
        |> union "a" "b"
        |> union "b" "c"

-- You can also create if from a `Dict`.
xyz : DisjointSet String
xyz =
    [ ("x", "x")
    , ("y", "x")
    , ("z", "y")
    ]
        |> Dict.fromList
        |> DisjointSet.fromDict

-- Finding elements is easy.
find "a" abc --> Just "a"
find "c" abc --> Just "a"
find "x" abc --> Nothing

-- Or you can convert it back to a `Dict`.
DisjointSet.toDict abc --> Dict.fromList [ ("a", "a"), ("b", "a"), ("c","a") ]