-
- All Known Implementing Classes:
UnionFind,UnionFindRemSP
public interface IntDisjointSetsInterface for disjoint-set forest implementations that operate on a universe of contiguous integers.
-
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description default booleanequivalent(int x, int y)Checks if two elements are in the same set.intfind(int x)Determines the representative element of the set containingx.intlink(int rx, int ry)Links (unites) two sets, identified by their representatives.intsize()Returns the size of the universe.default booleanunion(int x, int y)Unites the sets containing the respective elements.
-
-
-
Method Detail
-
size
int size()
Returns the size of the universe. The elements of the universe are the integers between0(inclusive) andsize()(exclusive).- Returns:
- the size of the universe
-
equivalent
default boolean equivalent(int x, int y)Checks if two elements are in the same set.- Parameters:
x- the first elementy- the second element- Returns:
trueifxandyare in the same set,falseotherwise
-
find
int find(int x)
Determines the representative element of the set containingx.- Parameters:
x- the element to find- Returns:
- the representative element of the set containing
x.
-
union
default boolean union(int x, int y)Unites the sets containing the respective elements. If two disjoint sets were united, the return value istrue. Otherwise, ifxandywere already in the same set,falseis returned.Attention: this method returns
trueif and only ifequivalent(x, y)would have returnedfalse.- Parameters:
x- the first elementy- the second element- Returns:
trueif two disjoint sets have been united as a result,falseotherwise
-
link
int link(int rx, int ry)Links (unites) two sets, identified by their representatives.- Parameters:
rx- the representative of the first setry- the representative of the second set- Returns:
- the representative of the resulting set (typically either
rxorry).
-
-