V
- the type parameter of the element's stored in the union-find data structurepublic class UnionFind<V>
extends java.lang.Object
Constructor and Description |
---|
UnionFind()
Instantiate a new union-find data structure.
|
UnionFind(java.lang.Iterable<V> elements)
Instantiate a new union-find data structure with the given elements as separate sets.
|
Modifier and Type | Method and Description |
---|---|
void |
deleteSet(V root)
Delete the set whose root is the given node.
|
V |
find(V node)
Find method with path compression.
|
java.util.Set<V> |
getPartition(V element)
Returns the partition in which the given element can be found, or null otherwise.
|
java.util.Collection<java.util.Set<V>> |
getPartitions()
Returns all partitions.
|
boolean |
isSameUnion(java.util.Set<V> elements)
Returns if all given elements are in the same partition.
|
V |
makeSet(java.util.Collection<V> nodes)
Creates a new union set from a collection of elements.
|
V |
makeSet(V node)
This method creates a single set containing the given node.
|
V |
union(V x,
V y)
Union by rank implementation of the two sets which contain x and y; x and/or y can be a single element from the
universe.
|
void |
unite(java.util.Set<V> elements)
Places the given elements in to the same partition.
|
public UnionFind()
public UnionFind(java.lang.Iterable<V> elements)
public V makeSet(java.util.Collection<V> nodes)
nodes
- the collection of elementspublic V makeSet(V node)
node
- the root node of the setpublic V find(V node)
node
- the node to findpublic V union(V x, V y)
x
- set or single element of the universey
- set or single element of the universepublic void unite(java.util.Set<V> elements)
public void deleteSet(V root)
root
- the root nodepublic boolean isSameUnion(java.util.Set<V> elements)
public java.util.Set<V> getPartition(V element)
public java.util.Collection<java.util.Set<V>> getPartitions()