public class DisjointSetElement {
private DisjointSetElement representative = this;
public DisjointSetElement getRepresentative() {
if (representative != this) {
representative = representative.getRepresentative();
}
return representative;
}
public void union(DisjointSetElement other) {
other.getRepresentative().representative = getRepresentative();
}
}
The class is usually subclassed with each element holding information about that specific element, and information about the aggregated set. The aggregated information is only used on the representative node