public class UnionFind extends ManagedIntArray
array, size
Constructor and Description |
---|
UnionFind()
Constructor using random merge order.
|
UnionFind(boolean noRandom)
Constructor.
|
Modifier and Type | Method and Description |
---|---|
int |
addElement()
Adds a new element to this union find structure and returns its index.
|
protected void |
connectToRepresentative(int element,
int representative)
Connects the given element (must also be representative) to the given
representative.
|
int |
find(int element)
Finds and returns the representative for the given element.
|
void |
union(int element1,
int element2)
Merges the classes in which element1 and element2 are, by giving them the
same representative.
|
addArrayElement, addArrayElements
public UnionFind()
public UnionFind(boolean noRandom)
noRandom
- if this is set to true, randomized merging is disabled. In
general, randomization should be used, as it prevents a linear
time worst case (for each union). However, if the order of
elements passed to the union method is already random (due to
the underlying data) or the size of the union size set is very
small, disabling randomization might cause a huge gain in
performance.public int find(int element)
public void union(int element1, int element2)
protected void connectToRepresentative(int element, int representative)
public int addElement()