def _remove_identical_contigs(self, containing_contigs, contig_lengths):
        '''Input is dictionary of containing contigs made by self._expand_containing_using_transitivity().
           Removes redundant identical contigs, leaving one representative (the longest) of
           each set of identical contigs.
           Returns new version of dictionary, and a dictionary of contig name => contig it was replaced with'''
        identical_contigs = self._get_identical_contigs(containing_contigs)
        to_replace = {}  # contig name => name to replace it with
        for contig_set in identical_contigs:
            longest_contig = self._longest_contig(contig_set, contig_lengths)
            for name in contig_set - {longest_contig}:
                assert name not in to_replace
                to_replace[name] = longest_contig

        for name, replace_with in to_replace.items():
            if replace_with not in containing_contigs:
                containing_contigs[replace_with] = set()

            if name in containing_contigs:
                containing_contigs[replace_with].update(containing_contigs[name])
                del containing_contigs[name]

        to_delete = set()

        for name, names_set in containing_contigs.items():
            assert name not in to_replace
            new_set = {to_replace.get(x, x) for x in names_set}
            new_set.discard(name)
            if len(new_set) > 0:
                containing_contigs[name] = new_set
            else:
                to_delete.add(name)

        for name in to_delete:
            del containing_contigs[name]

        return containing_contigs, to_replace
Input is dictionary of containing contigs made by self._expand_containing_using_transitivity().
           Removes redundant identical contigs, leaving one representative (the longest) of
           each set of identical contigs.
           Returns new version of dictionary, and a dictionary of contig name => contig it was replaced with