ó
 ,ľ[c           @   sU   d  Z  d d l Z d j d d g  Z d d d g Z d	   Z d
   Z d   Z d S(   s8   
Functions for identifying isolate (degree zero) nodes.
i˙˙˙˙Ns   
s!   Drew Conway <drew.conway@nyu.edu>s   Aric Hagberg <hagberg@lanl.gov>t
   is_isolatet   isolatest   number_of_isolatesc         C   s   |  j  |  d k S(   s(  Determines whether a node is an isolate.

    An *isolate* is a node with no neighbors (that is, with degree
    zero). For directed graphs, this means no in-neighbors and no
    out-neighbors.

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

    n : node
        A node in `G`.

    Returns
    -------
    is_isolate : bool
       True if and only if `n` has no neighbors.

    Examples
    --------
    >>> G=nx.Graph()
    >>> G.add_edge(1,2)
    >>> G.add_node(3)
    >>> nx.is_isolate(G,2)
    False
    >>> nx.is_isolate(G,3)
    True
    i    (   t   degree(   t   Gt   n(    (    s:   lib/python2.7/site-packages/networkx/algorithms/isolate.pyR       s    c         C   s   d   |  j    D S(   sĐ  Iterator over isolates in the graph.

    An *isolate* is a node with no neighbors (that is, with degree
    zero). For directed graphs, this means no in-neighbors and no
    out-neighbors.

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

    Returns
    -------
    iterator
        An iterator over the isolates of `G`.

    Examples
    --------
    To get a list of all isolates of a graph, use the :class:`list`
    constructor::

        >>> G = nx.Graph()
        >>> G.add_edge(1, 2)
        >>> G.add_node(3)
        >>> list(nx.isolates(G))
        [3]

    To remove all isolates in the graph, first create a list of the
    isolates, then use :meth:`Graph.remove_nodes_from`::

        >>> G.remove_nodes_from(list(nx.isolates(G)))
        >>> list(G)
        [1, 2]

    For digraphs, isolates have zero in-degree and zero out_degre::

        >>> G = nx.DiGraph([(0, 1), (1, 2)])
        >>> G.add_node(3)
        >>> list(nx.isolates(G))
        [3]

    c         s   s'   |  ] \ } } | d  k r | Vq d S(   i    N(    (   t   .0R   t   d(    (    s:   lib/python2.7/site-packages/networkx/algorithms/isolate.pys	   <genexpr>^   s    (   R   (   R   (    (    s:   lib/python2.7/site-packages/networkx/algorithms/isolate.pyR   4   s    *c         C   s   t  d   t |   D  S(   s\  Returns the number of isolates in the graph.

    An *isolate* is a node with no neighbors (that is, with degree
    zero). For directed graphs, this means no in-neighbors and no
    out-neighbors.

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

    Returns
    -------
    int
        The number of degree zero nodes in the graph `G`.

    c         s   s   |  ] } d  Vq d S(   i   N(    (   R   t   v(    (    s:   lib/python2.7/site-packages/networkx/algorithms/isolate.pys	   <genexpr>s   s    (   t   sumR   (   R   (    (    s:   lib/python2.7/site-packages/networkx/algorithms/isolate.pyR   a   s    (	   t   __doc__t   networkxt   nxt   joint
   __author__t   __all__R    R   R   (    (    (    s:   lib/python2.7/site-packages/networkx/algorithms/isolate.pyt   <module>   s   		 	-