E - the type of elements to be contained by the disjoint sets.public class DisjointSets<E>
extends java.lang.Object
| Constructor and Description |
|---|
DisjointSets()
Default Constructor.
|
DisjointSets(java.util.Collection<E> initialElements)
Constructor.
|
DisjointSets(E... elements)
Constructor.
|
| Modifier and Type | Method and Description |
|---|---|
void |
clear()
Remove all the disjoint sets.
|
java.util.Set<E> |
find(E element)
Find the disjoint set that an element belongs to.
|
java.util.Set<java.util.Set<E>> |
getDisjointSets() |
java.util.Map<E,java.util.Set<E>> |
getElementToDisjointSet() |
void |
makeSet(E element)
Create a disjoint set for the element passed in.
|
int |
numberDisjointSets() |
void |
union(E element1,
E element2)
Union two disjoint sets together if the arguments currently belong to two
different sets.
|
public DisjointSets()
public DisjointSets(java.util.Collection<E> initialElements)
initialElements - a collection of elements, each of which will be assigned to
their own disjoint set via makeSet().public DisjointSets(E... elements)
initialElements - a collection of elements, each of which will be assigned to
their own disjoint set via makeSet().public void makeSet(E element)
element - the element for which a new disjoint set should be
constructed.public void union(E element1, E element2)
element1 - element2 - java.lang.IllegalArgumentException - if element1 or element 2 is not already associated with a
disjoint set (i.e. makeSet() was not called for the argument
beforehand).public java.util.Set<E> find(E element)
element - the element whose disjoint set is being sought.public java.util.Map<E,java.util.Set<E>> getElementToDisjointSet()
public java.util.Set<java.util.Set<E>> getDisjointSets()
public int numberDisjointSets()
public void clear()