def _sort_mapping(alterations):
    """Maps data types and their values to numeric values used for sorting."""

    n_levels = len(alterations)

    mapping = {}
    for i, (data_type, val_order) in enumerate(alterations):
        multiplier = 10**(n_levels - i)

        for j, (val, _) in enumerate(val_order):
            key = data_type + '_' + val
            mapping[key] = multiplier * (len(val_order) - j)

    return mapping