|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object br.usp.ime.klava.segmentit.structures.UnionFind
public class UnionFind
Implements the union/find operations over disjoint sets, using the union by rank and path compression heuristics.
Constructor Summary | |
---|---|
UnionFind(int numElements)
Creates an UnionFind structure with numElements elements
(unitary disjoint sets) given by keys ranging from 0 to
numElements - 1 . |
Method Summary | |
---|---|
int |
findSet(int key)
Returns the representative of the set where the element given by key belongs. |
void |
reset()
Undoes all the operations done so far, restoring the structure to its initial state ( numElements - 1 unitary disjoint sets). |
java.lang.String |
toString()
|
int |
union(int key1,
int key2)
Merges the sets where the elements given by the keys key1
and key2 belong. |
Methods inherited from class java.lang.Object |
---|
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Constructor Detail |
---|
public UnionFind(int numElements)
numElements
elements
(unitary disjoint sets) given by keys ranging from 0
to
numElements - 1
.
numElements
- the number of elements to be createdMethod Detail |
---|
public void reset()
numElements - 1
unitary disjoint sets).
public int findSet(int key)
key
belongs.
key
- the key to the element to be localized
key
belongspublic int union(int key1, int key2)
key1
and key2
belong.
key1
- a key of an element from the first set to be mergedkey2
- a key of an element from the second set to be merged
public java.lang.String toString()
toString
in class java.lang.Object
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |