Module Union_find.Make

Parameters

module X : VariableType

Signature

type 'a t
type key = X.t
val pp : 'a Fmt.t -> 'a t Fmt.t
val empty : 'a t
val add : merge:('a -> 'a -> 'a) -> key -> 'a -> 'a t -> 'a t

add ~merge key value uf adds the key key with associated value value to the union-find.

If key is already present in the union-find (including if it is no longer canonical), merge is used to combine the new value with the existing value associated with key.

val find_canonical : key -> 'a t -> key

find_canonical key uf returns the current canonical representative for key.

val find_opt : key -> 'a t -> 'a option

find_opt key uf returns the value associated with key, if any.

key does not need to be canonical.

val find_and_remove_opt : key -> 'a t -> ('a * 'a t) option
val union : merge:('a -> 'a -> 'a) -> key -> key -> 'a t -> 'a t

union ~merge key1 key2 uf merges the equivalence classes associated with key1 and key2, calling merge on the corresponding values.

val explode : 'a t -> 'a list