e
and f
ENSURE: in_same_subset(e,f)
# Combine the subsets of `e` and `f`
# ENSURE: `in_same_subset(e,f)`
fun union(e,f:E)
do
var ne = find(e)
var nf = find(f)
if ne == nf then return
# merge them using *union by rank*
# attach the smaller tree to the root of the deeper tree
var er = ne.rank
var fr = nf.rank
if er < fr then
ne.parent = nf
nodes[e] = nf
else
nf.parent = ne
nodes[f] = ne
if er == fr then
# The only case where the deep is increased is when both are equals
ne.rank = er+1
end
end
number_of_subsets -= 1
end
lib/core/collection/union_find.nit:199,2--223,4