Class UnionFind
java.lang.Object
org.ek9lang.compiler.phase5.UnionFind
Union-Find (Disjoint Set Union) data structure for O(n * alpha(n)) connected components.
Used by LCOM4 cohesion calculation to find groups of methods that share field access.
Uses path compression and union by rank for near-constant time operations. Alpha(n) is the inverse Ackermann function - effectively constant for practical inputs.
Algorithm: Tarjan, R.E. (1975) "Efficiency of a Good But Not Linear Set Union Algorithm"
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescription(package private) voidAdd an element to the union-find structure.(package private) intCount the number of distinct connected components (sets).(package private) StringFind the root of the set containing the element.(package private) voidUnion two elements into the same set.
-
Constructor Details
-
UnionFind
UnionFind()
-
-
Method Details
-
add
Add an element to the union-find structure. Initially, each element is in its own set (parent is itself).- Parameters:
element- the element to add
-
find
-
union
-
countComponents
int countComponents()Count the number of distinct connected components (sets).- Returns:
- the number of distinct roots
-