E - element type@GwtCompatible public class StandardUnionFind<E> extends java.lang.Object implements java.io.Serializable, UnionFind<E>
This class implements Union-Find algorithm with rank and path compression.
See algorithmist for more detail.
| Constructor and Description |
|---|
StandardUnionFind()
Creates an empty UnionFind structure.
|
StandardUnionFind(UnionFind<E> other)
Creates an UnionFind structure being a copy of other structure.
|
| Modifier and Type | Method and Description |
|---|---|
void |
add(E e)
Adds the given element to a new set if it is not already in a set.
|
com.google.common.collect.ImmutableList<com.google.common.collect.ImmutableSet<E>> |
allEquivalenceClasses()
Returns an immutable collection containing all equivalence classes.
|
boolean |
areEquivalent(E a,
E b)
Returns true if
a and b belong to the same equivalence
class. |
java.util.Set<E> |
elements()
Returns an unmodifiable set of all elements added to the UnionFind.
|
E |
find(E e)
Returns the representative of the equivalence class of
e. |
java.util.Set<E> |
findAll(E value)
Returns the elements in the same equivalence class as
value. |
E |
union(E a,
E b)
Unions the equivalence classes of
a and b and returns the representative of the
resulting equivalence class. |
public StandardUnionFind()
public void add(@Nullable
E e)
UnionFind@CanIgnoreReturnValue public E union(@Nullable E a, @Nullable E b)
UnionFinda and b and returns the representative of the
resulting equivalence class. The elements will be added if they are not already present.public E find(@Nullable E e)
UnionFinde.public boolean areEquivalent(@Nullable
E a,
@Nullable
E b)
UnionFinda and b belong to the same equivalence
class.areEquivalent in interface UnionFind<E>public java.util.Set<E> elements()
UnionFindpublic com.google.common.collect.ImmutableList<com.google.common.collect.ImmutableSet<E>> allEquivalenceClasses()
UnionFindallEquivalenceClasses in interface UnionFind<E>Copyright © 2009-2020 Google. All Rights Reserved.