implement union-by-rank