An implementation of Union
Find data structure. Union Find is a disjoint-set data structure. It supports two operations:
finding the set a specific element is in, and merging two sets. The implementation uses union by
rank and path compression to achieve an amortized cost of O(a(n)) per operation where a is the
inverse Ackermann function. UnionFind uses the hashCode and equals method of the elements it
Merges the sets which contain element1 and element2. No guarantees are given as to which
element becomes the representative of the resulting (merged) set: this can be either
find(element1) or find(element2).