public class UnionFind<T>
extends java.lang.Object
Constructor and Description |
---|
UnionFind(java.util.Set<T> elements)
Creates a UnionFind instance with all of the elements of elements in
seperate sets.
|
Modifier and Type | Method and Description |
---|---|
void |
addElement(T element)
Adds a new element to the data structure in its own set.
|
T |
find(T element)
Returns the representative element of the set that element is in.
|
protected java.util.Map<T,T> |
getParentMap() |
protected java.util.Map<T,java.lang.Integer> |
getRankMap() |
void |
union(T element1,
T element2)
Merges the sets which contain element1 and element2.
|
public UnionFind(java.util.Set<T> elements)
public void addElement(T element)
element
- The element to add.protected java.util.Map<T,java.lang.Integer> getRankMap()
public T find(T element)
element
- The element to find.