package unionFind

  1. Overview
  2. Docs
Implementations of the union-find data structure

Install

Dune Dependency

Authors

Maintainers

Sources

archive.tar.gz
md5=3311141704584930d9e7358ef0edf2f4
sha512=116dfd8078f697012f8b53f518d6e05fca09b1d57b7ce7724b0789bf6d2ecacc7efa462a6bbcdf486358ce17e84f5d106a7e799d9b44cbc0755e433fdd82b724

doc/unionFind/UnionFind/index.html

Module UnionFindSource

This module offers a union-find data structure based on disjoint set forests, with path compression and linking by rank.

A type of elements, also known as references.

Sourcetype 'a elem

Operations for creating a new reference, reading and writing a reference, and testing whether two references are equivalent. (Two references are considered equivalent after they have been merged by union.)

Sourceval make : 'a -> 'a elem
Sourceval get : 'a elem -> 'a
Sourceval set : 'a elem -> 'a -> unit
Sourceval eq : 'a elem -> 'a elem -> bool

union x y does nothing if the references x and y are equal, and merges them if they are distinct. In the latter case, the content of the merged reference is arbitrarily chosen to be the previous content of x or y.

Sourceval union : 'a elem -> 'a elem -> 'a elem

find x returns the representative element of x's equivalence class.

Sourceval find : 'a elem -> 'a elem

Instead of hard-coding the use of mutable state, we parameterize the module over an implementation S of stores, as described by the signature STORE. This allows the client to choose between many different representations of the store: e.g., based on primitive references, based on a (possibly extensible) primitive array, based on a persistent map, based on a persistent or semi-persistent array, based on transactional references, etc.

The signature provided by this module is also STORE, extended with an operation for merging two references.

Sourcemodule Make (S : sig ... end) : sig ... end
Sourcemodule type STORE = sig ... end
Sourcemodule StoreMap : sig ... end

This module offers an implementation of STORE based on immutable integer maps. The stores thus obtained are persistent.

Sourcemodule StoreRef : sig ... end

This module offers an implementation of STORE based on mutable references.

Sourcemodule StoreTransactionalRef : sig ... end

This module offers an implementation of STORE based on a simple form of mutable transactional references.

Sourcemodule StoreVector : sig ... end

This module offers an implementation of STORE based on a single mutable extensible array.

OCaml

Innovation. Community. Security.