o
    ˷eW                     @   s0   d Z ddlmZ ddgZd	ddZd
ddZdS )aY  Routines to find the boundary of a set of nodes.

An edge boundary is a set of edges, each of which has exactly one
endpoint in a given set of nodes (or, in the case of directed graphs,
the set of edges whose source node is in the set).

A node boundary of a set *S* of nodes is the set of (out-)neighbors of
nodes in *S* that are outside *S*.

    )chainedge_boundarynode_boundaryNFc                    st    fdd|D    r j|||d}n j||d}|du r,fdd|D S t|fdd|D S )	am  Returns the edge boundary of `nbunch1`.

    The *edge boundary* of a set *S* with respect to a set *T* is the
    set of edges (*u*, *v*) such that *u* is in *S* and *v* is in *T*.
    If *T* is not specified, it is assumed to be the set of all nodes
    not in *S*.

    Parameters
    ----------
    G : NetworkX graph

    nbunch1 : iterable
        Iterable of nodes in the graph representing the set of nodes
        whose edge boundary will be returned. (This is the set *S* from
        the definition above.)

    nbunch2 : iterable
        Iterable of nodes representing the target (or "exterior") set of
        nodes. (This is the set *T* from the definition above.) If not
        specified, this is assumed to be the set of all nodes in `G`
        not in `nbunch1`.

    keys : bool
        This parameter has the same meaning as in
        :meth:`MultiGraph.edges`.

    data : bool or object
        This parameter has the same meaning as in
        :meth:`MultiGraph.edges`.

    default : object
        This parameter has the same meaning as in
        :meth:`MultiGraph.edges`.

    Returns
    -------
    iterator
        An iterator over the edges in the boundary of `nbunch1` with
        respect to `nbunch2`. If `keys`, `data`, or `default`
        are specified and `G` is a multigraph, then edges are returned
        with keys and/or data, as in :meth:`MultiGraph.edges`.

    Notes
    -----
    Any element of `nbunch` that is not in the graph `G` will be
    ignored.

    `nbunch1` and `nbunch2` are usually meant to be disjoint, but in
    the interest of speed and generality, that is not required here.

    c                       h | ]}| v r|qS  r   .0nGr   S/var/www/ideatree/venv/lib/python3.10/site-packages/networkx/algorithms/boundary.py	<setcomp>D       z edge_boundary.<locals>.<setcomp>)datakeysdefault)r   r   Nc                 3   s,    | ]}|d   v |d  v A r|V  qdS r      Nr   r   e)nset1r   r   	<genexpr>S   s   * z edge_boundary.<locals>.<genexpr>c                 3   sD    | ]}|d   v r|d v s|d  v r|d  v r|V  qdS r   r   r   )r   nset2r   r   r   U   s    0)is_multigraphedgesset)r   nbunch1nbunch2r   r   r   r   r   )r   r   r   r   r      s   4c                    sJ    fdd|D }t t fdd|D | }|dur#|t |M }|S )a|  Returns the node boundary of `nbunch1`.

    The *node boundary* of a set *S* with respect to a set *T* is the
    set of nodes *v* in *T* such that for some *u* in *S*, there is an
    edge joining *u* to *v*. If *T* is not specified, it is assumed to
    be the set of all nodes not in *S*.

    Parameters
    ----------
    G : NetworkX graph

    nbunch1 : iterable
        Iterable of nodes in the graph representing the set of nodes
        whose node boundary will be returned. (This is the set *S* from
        the definition above.)

    nbunch2 : iterable
        Iterable of nodes representing the target (or "exterior") set of
        nodes. (This is the set *T* from the definition above.) If not
        specified, this is assumed to be the set of all nodes in `G`
        not in `nbunch1`.

    Returns
    -------
    set
        The node boundary of `nbunch1` with respect to `nbunch2`.

    Notes
    -----
    Any element of `nbunch` that is not in the graph `G` will be
    ignored.

    `nbunch1` and `nbunch2` are usually meant to be disjoint, but in
    the interest of speed and generality, that is not required here.

    c                    r   r   r   r   r
   r   r   r      r   z node_boundary.<locals>.<setcomp>c                 3   s    | ]} | V  qd S Nr   )r   vr
   r   r   r      s    z node_boundary.<locals>.<genexpr>N)r   r   from_iterable)r   r   r   r   bdyr   r
   r   r   \   s
   % )NFFNr   )__doc__	itertoolsr   __all__r   r   r   r   r   r   <module>   s
    

L