Module Classic.ArrayWithCopy
Reference implementation: this implements union-find as a mutable array. Warning: it is NOT persistent, but provides a copy function
Parameters
module Config : Parameters.ARRAY_CONFIGmodule Node : Parameters.NODE_WITH_COMPARESignature
type node = Node.tthe type of nodes, i.e. elements of the union-find.
Union-find operations
val make : int -> tmake n creates a new union-find supporting up to n nodes:
PatriciaTreeimplementations disregard thisnand can always support any number of nodes.ArrayWithCopywill crash if used withnodewhoseNODE.to_intis>= n.PersistentArraywill usento set the initial array size. IfPERSISTENT_ARRAY_CONFIG.extendableistrue(the default), the array may then grow beyond that size if needed. Otherwise it will fail.
union uf a b returns a new version of uf where the classes of a and b have been merged.
check_related uf a b is true if and only if a and b are in the same equivalence class in uf.
Lattice operations
incl uf_a uf_b is lattice inclusion, uf_a <= uf_b, i.e. forall x y, if check_related uf_b x y then check_related uf_a x y
join uf_a uf_b is the least upper-bound of uf_a and uf_b, i.e. forall x y, check_related (join uf_a uf_b) x y iff check_related uf_b x y and check_related uf_a x y
meet uf_a uf_b is the greatest lower bound of uf_a and uf_b, its relation check_related (meet uf_a uf_b) is the transitive closure of check_related uf_a or check_related uf_b.
Testing and debugging
To compare persistent union-find with non-persistent version, we need an explicit copy operation. This is Fun.id for all persistent versions.
val check_invariants : t -> string optionFor testing, check_invariant uf returns None if all internal invariants hold. Otherwise, it returns Some error_msg.
val pretty : Stdlib.Format.formatter -> t -> unitpretty printer.