Generified union find algorithms