def _calcClassDefDeletionAndRemap(before, after):
    """
        >>> _calcClassDefDeletionAndRemap(set([1, 2, 3]), set([1, 2, 3]))
        ([], {0: 0, 1: 1, 2: 2, 3: 3})
        >>> _calcClassDefDeletionAndRemap(set([1, 2, 3]), set([1, 3]))
        ([2], {0: 0, 1: 1, 3: 2})
        >>> _calcClassDefDeletionAndRemap(set([1, 2, 3, 4, 5, 6]), set([1, 3, 4, 6]))
        ([5, 2], {0: 0, 1: 1, 3: 2, 4: 3, 6: 4})
        >>> _calcClassDefDeletionAndRemap(set([1, 2, 3, 4, 5, 6]), set([]))
        ([6, 5, 4, 3, 2, 1], {0: 0})
        >>> _calcClassDefDeletionAndRemap(set([0, 1, 2, 3]), set([1, 2]))
        ([3, 0], {1: 0, 2: 1})
        >>> _calcClassDefDeletionAndRemap(set([0, 1, 2, 3]), set([]))
        ([3, 2, 1, 0], {})
        >>> _calcClassDefDeletionAndRemap(set([]), set([]))
        ([], {})
    """
    assert not after - before
    if not before:
        return [], {}
    delete = sorted(before - after, reverse=True)
    rng = list(range(max(before) + 1))
    for i in delete:
        del rng[i]
    if not rng:
        return delete, {}
    if after:
        assert max(rng) == max(after)
    else:
        assert max(rng) == 0
    remap = dict(zip(rng, range(max(rng) + 1)))
    return delete, remap
