
    Cii9                         d Z ddlmZ ddlZddlmZ ddgZ ed          ej        d                         Z	 ed          ej        d	                         Z
dS )
z
Dominance algorithms.
    )reduceN)not_implemented_forimmediate_dominatorsdominance_frontiers
undirectedc                    || vrt          j        d          |dit          t          j        | |                    }d t	          |          D             |                                 |                                 fd}d}|rGd}|D ]@}t          |fd| j        |         D                       }|vs|         |k    r||<   d}A|G|= S )a  Returns the immediate dominators of all nodes of a directed graph.

    Parameters
    ----------
    G : a DiGraph or MultiDiGraph
        The graph where dominance is to be computed.

    start : node
        The start node of dominance computation.

    Returns
    -------
    idom : dict keyed by nodes
        A dict containing the immediate dominators of each node reachable from
        `start`, except for `start` itself.

    Raises
    ------
    NetworkXNotImplemented
        If `G` is undirected.

    NetworkXError
        If `start` is not in `G`.

    Notes
    -----
    The immediate dominators are the parents of their corresponding nodes in
    the dominator tree. Every node reachable from `start` has an immediate
    dominator, except for `start` itself.

    Examples
    --------
    >>> G = nx.DiGraph([(1, 2), (1, 3), (2, 5), (3, 4), (4, 5)])
    >>> sorted(nx.immediate_dominators(G, 1).items())
    [(2, 1), (3, 1), (4, 3), (5, 1)]

    References
    ----------
    .. [1] Cooper, Keith D., Harvey, Timothy J. and Kennedy, Ken.
           "A simple, fast dominance algorithm." (2006).
           https://hdl.handle.net/1911/96345
    .. [2] Lengauer, Thomas; Tarjan, Robert Endre (July 1979).
           "A fast algorithm for finding dominators in a flowgraph".
           ACM Transactions on Programming Languages and Systems. 1 (1): 121--141.
           https://dl.acm.org/doi/10.1145/357062.357071
    zstart is not in GNc                     i | ]\  }}||	S  r
   ).0ius      c/var/www/html/bet.cuttalo.com/ml/venv/lib/python3.11/site-packages/networkx/algorithms/dominance.py
<dictcomp>z(immediate_dominators.<locals>.<dictcomp>D   s    
-
-
-DAq1a
-
-
-    c                     | |k    r^|          |         k     r|          } |          |         k     |          |         k    r|         }|          |         k    | |k    ^| S Nr
   )r   vdfnidoms     r   	intersectz'immediate_dominators.<locals>.intersectH   sx    1ffa&3q6//G a&3q6//a&3q6//G a&3q6// 1ff
 r   TFc              3   $   K   | ]
}|v |V  d S r   r
   )r   r   r   s     r   	<genexpr>z'immediate_dominators.<locals>.<genexpr>T   s'      )L)L!t))!)))))L)Lr   )	nxNetworkXErrorlistdfs_postorder_nodes	enumeratepopreverser   pred)	Gstartorderr   changedr   new_idomr   r   s	          @@r   r   r      s#   b A~~23334=D'51122E
-
-Ie,,
-
-
-C	IIKKK	MMOOO      G
  	 	Ai)L)L)L)LQVAY)L)L)LMMH}}Q8 3 3"Q   	UKr   c                 B   t          j        | |          |diz  }d |D             }|D ]u}||k    st          | j        |                   dk    rO| j        |         D ]A}||v r;|||         k    r/||                             |           ||         }|||         k    /Bv|S )a  Returns the dominance frontiers of all nodes of a directed graph.

    Parameters
    ----------
    G : a DiGraph or MultiDiGraph
        The graph where dominance is to be computed.

    start : node
        The start node of dominance computation.

    Returns
    -------
    df : dict keyed by nodes
        A dict containing the dominance frontiers of each node reachable from
        `start` as lists.

    Raises
    ------
    NetworkXNotImplemented
        If `G` is undirected.

    NetworkXError
        If `start` is not in `G`.

    Examples
    --------
    >>> G = nx.DiGraph([(1, 2), (1, 3), (2, 5), (3, 4), (4, 5)])
    >>> sorted((u, sorted(df)) for u, df in nx.dominance_frontiers(G, 1).items())
    [(1, []), (2, [5]), (3, [5]), (4, [5]), (5, [])]

    References
    ----------
    .. [1] Cooper, Keith D., Harvey, Timothy J. and Kennedy, Ken.
           "A simple, fast dominance algorithm." (2006).
           https://hdl.handle.net/1911/96345
    Nc                 ,    i | ]}|t                      S r
   )set)r   r   s     r   r   z'dominance_frontiers.<locals>.<dictcomp>   s    	!	!	!q!SUU	!	!	!r      )r   r   lenr    add)r!   r"   r   dfr   r   s         r   r   r   ]   s    N "1e,,t}<D	!	!D	!	!	!B $ $::QVAY1,,VAY $ $99tAw,,1		! G tAw,, Ir   )__doc__	functoolsr   networkxr   networkx.utilsr   __all___dispatchabler   r   r
   r   r   <module>r3      s               . . . . . .!#8
9 \""K K  #"K\ \""/ /  #"/ / /r   