|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectorg.deri.iris.utils.DisjointSets<T>
public class DisjointSets<T>
A data structure for representing and managing partitions, i.e. families of disjoint sets. Implemented as a disjoint-set data structure, which uses path compression and union by rank.
Note that the corresponding equals and hashCode
methods of the type T are used to determine the equality
of two representative elements of type T. Therefore, the
equals and hashCode methods have to be implemented
correctly.
Object.equals(java.lang.Object),
java.lang.Object#hashCode(java.lang.Object),
Wikipedia
article about Disjoint-set data structure| Constructor Summary | |
|---|---|
DisjointSets()
Creates a new empty equivalence relation. |
|
| Method Summary | |
|---|---|
boolean |
add(T element)
Adds a new element to the domain of the equivalence relation. |
boolean |
areInSameSet(T x,
T y)
Checks if the two specified objects are in the same set. |
boolean |
equals(Object obj)
|
T |
find(T element)
Retrieves the representative element of the set in which the given element resides. |
int |
getNumberOfSets()
Returns the number of sets. |
Set<T> |
getSetOf(T element)
Returns the set of elements in which the specified element resides. |
Collection<Set<T>> |
getSets()
Returns a collection of all the sets of this disjoint-set. |
int |
hashCode()
|
T |
putInSameSet(T x,
T y)
Merges the two sets of the two specified elements into a single set. |
boolean |
remove(T element)
Removes an element from the disjoint-set. |
String |
toString()
|
| Methods inherited from class java.lang.Object |
|---|
clone, finalize, getClass, notify, notifyAll, wait, wait, wait |
| Constructor Detail |
|---|
public DisjointSets()
| Method Detail |
|---|
public boolean add(T element)
element - The new element.
true if this disjoint-set did not already contain
the specified element, false otherwise.public boolean remove(T element)
element - The element.
public boolean areInSameSet(T x,
T y)
equals method is used to determine the
equality of elements of the given type.
x - The first object.y - The second object.
true if the two given objects are in the same set,
false otherwise.
public T putInSameSet(T x,
T y)
x - The first element.y - The second element.
public T find(T element)
element - The element.
null if the specified element has not
been added yet, i.e. there is no set containing the element.public Collection<Set<T>> getSets()
public Set<T> getSetOf(T element)
element - The element.
public int getNumberOfSets()
public int hashCode()
hashCode in class Objectpublic boolean equals(Object obj)
equals in class Objectpublic String toString()
toString in class Object
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||