The number of elements.
The number of disjoint sets.
Adds an element in a set of its own, and returns the element.
Returns the representative of the set that holds element.
Joins the sets of two elements, and returns whether they were two sets.
Whether two elements are in the same set.
A partition of the integers from 0 up to its size into disjoint sets. Every set has one member that stands for it, called its representative.
findcompresses the path to the representative, andunionhangs the tree of lower rank under the other. So a sequence of m operations on n elements takes time O(m α(n)), where α is the inverse Ackermann function, which is below 5 for every n that fits in memory. A partition with a budget charges oneResource.Cellsfor each element.The parents and the ranks live in typed arrays of the capacity that the caller states. The arrays double when
addruns past the capacity, so a caller that knows the final size states it and never copies.