Class StandardUnionFind<E>
- java.lang.Object
-
- com.google.javascript.jscomp.graph.StandardUnionFind<E>
-
- Type Parameters:
E- element type
- All Implemented Interfaces:
UnionFind<E>,java.io.Serializable
@GwtCompatible public class StandardUnionFind<E> extends java.lang.Object implements java.io.Serializable, UnionFind<E>
A Union-Find implementation.This class implements Union-Find algorithm with rank and path compression.
See algorithmist for more detail.
- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor Description StandardUnionFind()Creates an empty UnionFind structure.StandardUnionFind(UnionFind<E> other)Creates an UnionFind structure being a copy of other structure.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidadd(E e)Adds the given element to a new set if it is not already in a set.voidaddAll(java.lang.Iterable<E> es)com.google.common.collect.ImmutableList<com.google.common.collect.ImmutableSet<E>>allEquivalenceClasses()Returns an immutable collection containing all equivalence classes.com.google.common.collect.ImmutableSet<E>allRepresentatives()Return the reprsentative elements of all the equivalence classes.booleanareEquivalent(E a, E b)Returns true ifaandbbelong to the same equivalence class.java.util.Set<E>elements()Returns an unmodifiable set of all elements added to the UnionFind.Efind(E e)Returns the representative of the equivalence class ofe.java.util.Set<E>findAll(E value)Returns the elements in the same equivalence class asvalue.Eunion(E a, E b)Unions the equivalence classes ofaandband returns the representative of the resulting equivalence class.
-
-
-
Method Detail
-
add
public void add(@Nullable E e)Description copied from interface:UnionFindAdds the given element to a new set if it is not already in a set.
-
addAll
public void addAll(java.lang.Iterable<E> es)
-
union
@CanIgnoreReturnValue public E union(@Nullable E a, @Nullable E b)
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
public E find(@Nullable E e)
Description copied from interface:UnionFindReturns the representative of the equivalence class ofe.
-
areEquivalent
public boolean areEquivalent(@Nullable E a, @Nullable E b)Description copied from interface:UnionFindReturns true ifaandbbelong to the same equivalence class.- Specified by:
areEquivalentin interfaceUnionFind<E>
-
elements
public java.util.Set<E> elements()
Description copied from interface:UnionFindReturns an unmodifiable set of all elements added to the UnionFind.
-
allEquivalenceClasses
public com.google.common.collect.ImmutableList<com.google.common.collect.ImmutableSet<E>> 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>
-
allRepresentatives
public com.google.common.collect.ImmutableSet<E> allRepresentatives()
Return the reprsentative elements of all the equivalence classes.This is a "snapshot" view of the representatives at the time the method was called.
-
-