
    \Mhz                         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j        d	             Z
dS )
z
Dominance algorithms.
    )reduceN)not_implemented_forimmediate_dominatorsdominance_frontiers
undirectedc                    || vrt          j        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 )a1  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`.

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

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

    Notes
    -----
    Except for `start`, the immediate dominators are the parents of their
    corresponding nodes in the dominator tree.

    Examples
    --------
    >>> G = nx.DiGraph([(1, 2), (1, 3), (2, 5), (3, 4), (4, 5)])
    >>> sorted(nx.immediate_dominators(G, 1).items())
    [(1, 1), (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
    zstart is not in Gc                     i | ]\  }}||	S  r
   ).0ius      ]/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/networkx/algorithms/dominance.py
<dictcomp>z(immediate_dominators.<locals>.<dictcomp>?   s    
-
-
-DAq1a
-
-
-    c                     | |k    r^|          |         k     r|          } |          |         k     |          |         k    r|         }|          |         k    | |k    ^| S Nr
   )r   vdfnidoms     r   	intersectz'immediate_dominators.<locals>.intersectC   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>O   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   X A~~23335>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   Kr   c                 ,   t          j        | |          }d |D             }|D ]o}t          | j        |                   dk    rO| j        |         D ]A}||v r;|||         k    r/||                             |           ||         }|||         k    /Bp|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
    c                 ,    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   W   s    L "1e,,D	!	!D	!	!	!B $ $qvay>>QVAY $ $99tAw,,1		! G tAw,, Ir   )__doc__	functoolsr   networkxr   networkx.utilsr   __all___dispatchabler   r   r
   r   r   <module>r3      s               . . . . . .!#8
9 \""E E  #"EP / / / / /r   