@staticmethod
def __group_fragments(fragments):
    """
        For each fragment, we for the complete set of possible destinations
        and associated terminals.  Since it is possible that more than one 
        fragment will lead to the same set of target nodes we group all
        related fragments together.
        """
    groups = {}
    for interval, nts in fragments:
        if len(nts) > 1:
            nodes, terminals = set(), set()
            for n, t in nts:
                nodes.update(n)
                terminals.update(t)
            nodes = frozenset(nodes)
        else:
            nodes, terminals = nts[0]
        if nodes not in groups:
            groups[nodes] = set(), set()
        groups[nodes][0].add(interval)
        groups[nodes][1].update(terminals)
    return groups
