'Find representative of a class in a union-find data structure.
Used in the implementation of Atkinson\'s algorithm as suggested in [1],
pp. 83-87. After the representative of the class to which ``num``
belongs is found, path compression is performed as an optimization
([7]).
Notes
THIS FUNCTION HAS SIDE EFFECTS: the list of class representatives,
``parents``, is altered due to path compression.
See Also
minimal_block, _union_find_merge
References
[1] Holt, D., Eick, B., O\'Brien, E.
"Handbook of computational group theory"
[7] http://www.algorithmist.com/index.php/Union_Find'

def _union_find_rep(self, num, parents):

    (rep, parent) = (num, parents[num])
    while (parent != rep):
        rep = parent
        parent = parents[rep]
    (temp, parent) = (num, parents[num])
    while (parent != rep):
        parents[temp] = rep
        temp = parent
        parent = parents[temp]
    return rep
