-
- All Known Implementing Classes:
UnionFind
,UnionFindRemSP
public interface IntDisjointSets
Interface 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 boolean
equivalent(int x, int y)
Checks if two elements are in the same set.int
find(int x)
Determines the representative element of the set containingx
.int
link(int rx, int ry)
Links (unites) two sets, identified by their representatives.int
size()
Returns the size of the universe.default boolean
union(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:
true
ifx
andy
are in the same set,false
otherwise
-
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, ifx
andy
were already in the same set,false
is returned.Attention: this method returns
true
if and only ifequivalent(x, y)
would have returnedfalse
.- Parameters:
x
- the first elementy
- the second element- Returns:
true
if two disjoint sets have been united as a result,false
otherwise
-
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
rx
orry
).
-
-