from typing import Set


def _negative_to_positive_state_indexes(indexes: Set[int], n_entries) -> Set[int]:
    """ Convert negative indexes of an iterable to positive ones

    Parameters
    ----------
    indexes: Set[int]
        indexes to check and convert
    n_entries: int
        total number of entries

    Returns
    -------
    new_entries: Set[int]
        the positive indexes
    """

    new_entries: Set[int] = set()
    for _, index in enumerate(indexes):
        new_index = index + n_entries if index < 0 else index
        if new_index >= n_entries:
            err_msg = "State '{0}' exceeds the maximum number of states of '{1}'"
            raise ValueError(err_msg.format(index, n_entries))
        new_entries.add(new_index)
    return new_entries