E - element typepublic final class StandardUnionFind<E> extends Object implements 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.
|
Collection<Set<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. |
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. |
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(E e)
UnionFindpublic E union(E a, 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(E e)
UnionFinde.public boolean areEquivalent(E a, E b)
UnionFinda and b belong to the same equivalence
class.areEquivalent in interface UnionFind<E>public Set<E> elements()
UnionFindpublic Collection<Set<E>> allEquivalenceClasses()
UnionFindallEquivalenceClasses in interface UnionFind<E>Copyright © 2009-2015 Google. All Rights Reserved.