'Extend this multi-path with a new vertex ancestors<-head
@param head: the head node
@param ancestors: the ancestor (multi-)path of the head node'

def extend(self, head, ancestors=None, cut=None):

    if isinstance(ancestors, S3MultiPath):
        extend = self.extend
        for p in ancestors.paths:
            extend(head, p, cut=cut)
        return self
    extensions = []
    Path = self.Path
    append = extensions.append
    for p in self.paths:
        if cut:
            pos = p.find(cut)
            if (pos > 0):
                p.nodes = p.nodes[:(pos - 1)]
        i = p.find(head)
        if (i > 0):
            path = Path(p.nodes[:i]).extend(head, ancestors)
            detour = None
            for tail in self.paths:
                j = tail.find(path.last())
                if (j > 0):
                    detour = Path(path)
                    detour.extend(path.last(), tail[j:])
                    append(detour)
            if (not detour):
                append(path)
    self.paths.extend(extensions)
    return self.clean()
