Interface UnionFind<E>
-
- Type Parameters:
E- element type
- All Known Implementing Classes:
StandardUnionFind
@GwtCompatible public interface UnionFind<E>Union-Find is a classical algorithm used to find connected components in graph theory.Each equivalence class has a representative element that is chosen arbitrarily and is used to determine if two elements are members of the same class.
See algorithmist for more detail.
-
-
Method Summary
All Methods Instance Methods Abstract 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.com.google.common.collect.ImmutableList<com.google.common.collect.ImmutableSet<E>>allEquivalenceClasses()Returns an immutable collection containing all 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
void add(E e)
Adds the given element to a new set if it is not already in a set.- Throws:
java.lang.UnsupportedOperationException- if the add operation is not supported by this union-find.
-
union
@CanIgnoreReturnValue E union(E a, E b)
Unions the equivalence classes ofaandband returns the representative of the resulting equivalence class. The elements will be added if they are not already present.- Throws:
java.lang.UnsupportedOperationException- if the add operation is not supported by this union-find.
-
areEquivalent
boolean areEquivalent(E a, E b)
Returns true ifaandbbelong to the same equivalence class.- Throws:
java.lang.IllegalArgumentException- if any argument is not an element of this structure.
-
elements
java.util.Set<E> elements()
Returns an unmodifiable set of all elements added to the UnionFind.
-
allEquivalenceClasses
com.google.common.collect.ImmutableList<com.google.common.collect.ImmutableSet<E>> allEquivalenceClasses()
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.
-
findAll
java.util.Set<E> findAll(E value)
Returns the elements in the same equivalence class asvalue.- Returns:
- an unmodifiable view. As equivalence classes are merged, this set will reflect those changes.
- Throws:
java.lang.IllegalArgumentException- if a requested element does not belong to the structure.
-
-