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 void
add(@Nullable E e)
Adds the given element to a new set if it is not already in a set.void
addAll(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.boolean
areEquivalent(@Nullable E a, @Nullable E b)
Returns true ifa
andb
belong to the same equivalence class.java.util.Set<E>
elements()
Returns an unmodifiable set of all elements added to the UnionFind.E
find(@Nullable E e)
Returns the representative of the equivalence class ofe
.java.util.Set<E>
findAll(@Nullable E value)
Returns the elements in the same equivalence class asvalue
.E
union(@Nullable E a, @Nullable E b)
Unions the equivalence classes ofa
andb
and returns the representative of the resulting equivalence class.
-
-
-
Method Detail
-
add
public void add(@Nullable E e)
Description copied from interface:UnionFind
Adds 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:UnionFind
Unions the equivalence classes ofa
andb
and 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:UnionFind
Returns the representative of the equivalence class ofe
.
-
areEquivalent
public boolean areEquivalent(@Nullable E a, @Nullable E b)
Description copied from interface:UnionFind
Returns true ifa
andb
belong to the same equivalence class.- Specified by:
areEquivalent
in interfaceUnionFind<E>
-
elements
public java.util.Set<E> elements()
Description copied from interface:UnionFind
Returns 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:UnionFind
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.- Specified by:
allEquivalenceClasses
in 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.
-
-