def extend_adaptation_space(space, parameter, states):
    """
    Add set of states to an adaptation space for a given parameter.
    If the parameter is not already defined, add it to the space.
    Otherwise, extend the already defined space

    :param space: (out) Space to update
    :type space: dict[Parameter, set]
    :type parameter: Parameter
    :type states: set
    :return: Passed space with updated set
    """
    parameter_space = space.get(parameter, None)
    if parameter_space:
        parameter_space.update(states)
    else:
        space[parameter] = states.copy()
    return space
