U
    ª9%e]  ã                   @   s†   d Z ddlZddlmZ ddlmZ dddd	gZejed
ƒdd„ ƒƒZ	dd„ Z
ejed
ƒdd„ ƒƒZejed
ƒdd	„ ƒƒZdd„ ZdS )zConnected components.é    N)Únot_implemented_foré   )Úarbitrary_elementÚnumber_connected_componentsÚconnected_componentsÚis_connectedÚnode_connected_componentZdirectedc                 c   s6   t ƒ }| D ]&}||kr
t| |ƒ}| |¡ |V  q
dS )aø  Generate connected components.

    Parameters
    ----------
    G : NetworkX graph
       An undirected graph

    Returns
    -------
    comp : generator of sets
       A generator of sets of nodes, one for each component of G.

    Raises
    ------
    NetworkXNotImplemented
        If G is directed.

    Examples
    --------
    Generate a sorted list of connected components, largest first.

    >>> G = nx.path_graph(4)
    >>> nx.add_path(G, [10, 11, 12])
    >>> [len(c) for c in sorted(nx.connected_components(G), key=len, reverse=True)]
    [4, 3]

    If you only want the largest connected component, it's more
    efficient to use max instead of sort.

    >>> largest_cc = max(nx.connected_components(G), key=len)

    To create the induced subgraph of each component use:

    >>> S = [G.subgraph(c).copy() for c in nx.connected_components(G)]

    See Also
    --------
    strongly_connected_components
    weakly_connected_components

    Notes
    -----
    For undirected graphs only.

    N)ÚsetÚ
_plain_bfsÚupdate)ÚGÚseenÚvÚc© r   úg/var/www/html/Darija-Ai-API/env/lib/python3.8/site-packages/networkx/algorithms/components/connected.pyr      s    0

c                 C   s   t dd„ t| ƒD ƒƒS )a  Returns the number of connected components.

    Parameters
    ----------
    G : NetworkX graph
       An undirected graph.

    Returns
    -------
    n : integer
       Number of connected components

    Examples
    --------
    >>> G = nx.Graph([(0, 1), (1, 2), (5, 6), (3, 4)])
    >>> nx.number_connected_components(G)
    3

    See Also
    --------
    connected_components
    number_weakly_connected_components
    number_strongly_connected_components

    Notes
    -----
    For undirected graphs only.

    c                 s   s   | ]
}d V  qdS ©é   Nr   )Ú.0Úccr   r   r   Ú	<genexpr>e   s     z.number_connected_components.<locals>.<genexpr>)Úsumr   ©r   r   r   r   r   G   s    c                 C   s<   t | ƒdkrt dd¡‚tdd„ t| t| ƒƒD ƒƒt | ƒkS )ag  Returns True if the graph is connected, False otherwise.

    Parameters
    ----------
    G : NetworkX Graph
       An undirected graph.

    Returns
    -------
    connected : bool
      True if the graph is connected, false otherwise.

    Raises
    ------
    NetworkXNotImplemented
        If G is directed.

    Examples
    --------
    >>> G = nx.path_graph(4)
    >>> print(nx.is_connected(G))
    True

    See Also
    --------
    is_strongly_connected
    is_weakly_connected
    is_semiconnected
    is_biconnected
    connected_components

    Notes
    -----
    For undirected graphs only.

    r   zConnectivity is undefined zfor the null graph.c                 s   s   | ]
}d V  qdS r   r   )r   Únoder   r   r   r   “   s     zis_connected.<locals>.<genexpr>)ÚlenÚnxZNetworkXPointlessConceptr   r
   r   r   r   r   r   r   h   s    ' ÿc                 C   s
   t | |ƒS )a•  Returns the set of nodes in the component of graph containing node n.

    Parameters
    ----------
    G : NetworkX Graph
       An undirected graph.

    n : node label
       A node in G

    Returns
    -------
    comp : set
       A set of nodes in the component of G containing node n.

    Raises
    ------
    NetworkXNotImplemented
        If G is directed.

    Examples
    --------
    >>> G = nx.Graph([(0, 1), (1, 2), (5, 6), (3, 4)])
    >>> nx.node_connected_component(G, 0)  # nodes of component that contains node 0
    {0, 1, 2}

    See Also
    --------
    connected_components

    Notes
    -----
    For undirected graphs only.

    )r
   )r   Únr   r   r   r   –   s    &c                 C   sP   | j }tƒ }|h}|rL|}tƒ }|D ]$}||kr$| |¡ | || ¡ q$q|S )zA fast BFS node generator)Zadjr	   Úaddr   )r   ÚsourceZG_adjr   Z	nextlevelZ	thislevelr   r   r   r   r
   ¿   s    
r
   )Ú__doc__Znetworkxr   Znetworkx.utils.decoratorsr   Úutilsr   Ú__all__Ú	_dispatchr   r   r   r   r
   r   r   r   r   Ú<module>   s&   ü6!,'