def METHOD_NAME(self, val):
    parent = self.lookup[val]
    while val is not parent:
        # path splitting optimization
        grandparent = self.lookup[parent]
        self.lookup[val] = grandparent
        val, parent = parent, grandparent
    return val