
    &`i                     \    d dl mZmZ  ed          Zdeeef         deeef         fdZdS )    )DictTypeVarKdreturnc                     | si S i }t          |                                           }| D ]N}||v r|}|h}|| v r9| |         }||v rt          d|            |                    |           |}|| v 9|||<   O|S )a  Collapse transitive mappings in a dictionary. Given a mapping like
    {a: b, b: c, c: d}, returns {a: d}, removing intermediate b -> c, c -> d.

    Only keeps mappings where the key is NOT a value in another mapping (i.e., chain starting points).

    Args:
        d: Dictionary representing a mapping

    Returns:
        Dictionary with all transitive mappings collapsed, keeping only KV-pairs,
        such that K and V are starting and terminal point of a chain

    Examples:
        >>> collapse_transitive_map({"a": "b", "b": "c", "c": "d"})
        {'a': 'd'}
        >>> collapse_transitive_map({"a": "b", "x": "y"})
        {'a': 'b', 'x': 'y'}
    z Detected a cycle in the mapping )setvalues
ValueErroradd)r   	collapsed
values_setkcurvisitednexts          r/home/jaya/work/projects/VOICE-AGENT/VIET/agent-env/lib/python3.11/site-packages/ray/data/_internal/collections.pycollapse_transitive_mapr      s    &  	IQXXZZJ   
??% QhhS6Dw !GA!G!GHHHKKC Qhh 	!    N)typingr   r   r   r    r   r   <module>r      sf                   GCLL+tAqDz +d1a4j + + + + + +r   