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
ConstructorsConstructorDescriptionCreates an empty UnionFind structure.StandardUnionFind(UnionFind<E> other) Creates an UnionFind structure being a copy of other structure. -
Method Summary
Modifier and TypeMethodDescriptionvoidAdds 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.booleanareEquivalent(E a, E b) Returns true ifaandbbelong 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 ofaandband 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:UnionFindAdds the given element to a new set if it is not already in a set. -
union
Description copied from interface:UnionFindUnions the equivalence classes ofaandband returns the representative of the resulting equivalence class. The elements will be added if they are not already present. -
find
Description copied from interface:UnionFindReturns the representative of the equivalence class ofe. -
areEquivalent
Description copied from interface:UnionFindReturns true ifaandbbelong to the same equivalence class.- Specified by:
areEquivalentin interfaceUnionFind<E>
-
elements
Description copied from interface:UnionFindReturns an unmodifiable set of all elements added to the UnionFind. -
allEquivalenceClasses
Description copied from interface:UnionFindReturns 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:
allEquivalenceClassesin interfaceUnionFind<E>
-
findAll
Description copied from interface:UnionFindReturns the elements in the same equivalence class asvalue.
-