Class StandardUnionFind<E>
java.lang.Object
com.google.javascript.jscomp.graph.StandardUnionFind<E>
- Type Parameters:
E
- element type
- All Implemented Interfaces:
UnionFind<E>
,Serializable
A Union-Find implementation.
This class implements Union-Find algorithm with rank and path compression.
See algorithmist for more detail.
- See Also:
-
Constructor Summary
ConstructorDescriptionCreates an empty UnionFind structure.StandardUnionFind
(UnionFind<E> other) Creates an UnionFind structure being a copy of other structure. -
Method Summary
Modifier and TypeMethodDescriptionvoid
Adds the given element to a new set if it is not already in a set.Collection<Set<E>>
Returns an immutable collection containing all equivalence classes.boolean
areEquivalent
(E a, E b) Returns true ifa
andb
belong to the same equivalence class.elements()
Returns an unmodifiable set of all elements added to the UnionFind.Returns the representative of the equivalence class ofe
.Returns the elements in the same equivalence class asvalue
.Unions the equivalence classes ofa
andb
and returns the representative of the resulting equivalence class.
-
Constructor Details
-
StandardUnionFind
public StandardUnionFind()Creates an empty UnionFind structure. -
StandardUnionFind
Creates an UnionFind structure being a copy of other structure. The created structure is optimal in a sense that the paths to the root from any element will have a length of at most 1.- Parameters:
other
- structure to be copied
-
-
Method Details
-
add
Description copied from interface:UnionFind
Adds the given element to a new set if it is not already in a set. -
union
Description copied from interface:UnionFind
Unions the equivalence classes ofa
andb
and returns the representative of the resulting equivalence class. The elements will be added if they are not already present. -
find
Description copied from interface:UnionFind
Returns the representative of the equivalence class ofe
. -
areEquivalent
Description copied from interface:UnionFind
Returns true ifa
andb
belong to the same equivalence class.- Specified by:
areEquivalent
in interfaceUnionFind<E>
-
elements
Description copied from interface:UnionFind
Returns an unmodifiable set of all elements added to the UnionFind. -
allEquivalenceClasses
Description copied from interface:UnionFind
Returns an immutable collection containing all equivalence classes. The returned collection represents a snapshot of the current state and will not reflect changes made to the data structure.- Specified by:
allEquivalenceClasses
in interfaceUnionFind<E>
-
findAll
Description copied from interface:UnionFind
Returns the elements in the same equivalence class asvalue
.
-