def get_positive_index(index, size):
    """Used for negative indexing"""
    if index < 0:
        index = size + index
        if index < 0:
            raise ValueError('index is out of range')
    if index >= size:
        raise ValueError('index is out of range')
    return index
