Union-find node type
Instances For
Union-find data structure #
The UnionFind structure is an implementation of disjoint-set data structure
that uses path compression to make the primary operations run in amortized
nearly linear time. The nodes of a UnionFind structure s are natural
numbers smaller than s.size. The structure associates with a canonical
representative from its equivalence class. The structure can be extended
using the push operation and equivalence classes can be updated using the
union operation.
The main operations for UnionFind are:
empty/mkEmptyare used to create a new empty structure.sizereturns the size of the data structure.pushadds a new node to a structure, unlinked to any other node.unionlinks two nodes of the data structure, joining their equivalence classes, and performs path compression.findreturns the canonical representative of a node and updates the data structure using path compression.rootreturns the canonical representative of a node without altering the data structure.checkEquivchecks whether two nodes have the same canonical representative and updates the structure using path compression.
Most use cases should prefer find over root to benefit from the speedup from path-compression.
The main operations use Fin s.size to represent nodes of the union-find structure.
Some alternatives are provided:
unionN,findN,rootN,checkEquivNuseFin nwith a proof thatn = s.size.union!,find!,root!,checkEquiv!useNatand panic when the indices are out of bounds.findD,rootD,checkEquivDuseNatand treat out of bound indices as isolated nodes.
The noncomputable relation UnionFind.Equiv is provided to use the equivalence relation from a
UnionFind structure in the context of proofs.
Array of union-find nodes
Validity for parent nodes
- rankD_lt {i : Nat} : parentD self.arr i ≠ i → rankD self.arr i < rankD self.arr (parentD self.arr i)
Validity for rank
Instances For
Size of union-find structure.
Equations
Instances For
Create an empty union-find structure with specific capacity
Equations
Instances For
Parent of union-find node
Equations
Instances For
Rank of union-find node
Equations
Instances For
Maximum rank of nodes in a union-find structure
Equations
Instances For
Add a new node to a union-find structure, unlinked with any other nodes
Equations
Instances For
Root of a union-find node. Panics if index is out of bounds.
Equations
Instances For
Root of a union-find node. Returns input if index is out of bounds.
Equations
Instances For
Link two union-find nodes, uniting their respective classes. Panics if either index is out of bounds.