
0c@_à  ã               @   s   Gd  d „  d e  ƒ Z d S)c               @   s¦   e  Z d  Z d Z d d „  Z d d „  Z d d „  Z d d	 „  Z d
 d „  Z d d „  Z	 d d „  Z
 d d „  Z d d „  Z d d „  Z d d „  Z d d „  Z d S)ÚDirectedGraphz+A graph structure with directed edges.
    c             C   s"   t  ƒ  |  _ i  |  _ i  |  _ d  S)N)ÚsetÚ	_verticesÚ	_forwardsÚ
_backwards)Úself© r   ú=/tmp/pip-build-jynh7p1z/pip/pip/_vendor/resolvelib/structs.pyÚ__init__   s    	zDirectedGraph.__init__c             C   s   t  |  j ƒ S)N)Úiterr   )r   r   r   r   Ú__iter__
   s    zDirectedGraph.__iter__c             C   s   t  |  j ƒ S)N)Úlenr   )r   r   r   r   Ú__len__   s    zDirectedGraph.__len__c             C   s   | |  j  k S)N)r   )r   Úkeyr   r   r   Ú__contains__   s    zDirectedGraph.__contains__c             C   s]   t  ƒ  } t |  j ƒ | _ d d „  |  j j ƒ  Dƒ | _ d d „  |  j j ƒ  Dƒ | _ | S)z-Return a shallow copy of this graph.
        c             S   s%   i  |  ] \ } } t  | ƒ | “ q Sr   )r   )Ú.0ÚkÚvr   r   r   ú
<dictcomp>   s   	 z&DirectedGraph.copy.<locals>.<dictcomp>c             S   s%   i  |  ] \ } } t  | ƒ | “ q Sr   )r   )r   r   r   r   r   r   r      s   	 )r   r   r   r   Úitemsr   )r   Úotherr   r   r   Úcopy   s
    	zDirectedGraph.copyc             C   sO   | |  j  k r t d ƒ ‚ |  j  j | ƒ t ƒ  |  j | <t ƒ  |  j | <d S)z'Add a new vertex to the graph.
        zvertex existsN)r   Ú
ValueErrorÚaddr   r   r   )r   r   r   r   r   r      s
    zDirectedGraph.addc             C   sv   |  j  j | ƒ x. |  j j | ƒ D] } |  j | j | ƒ q# Wx. |  j j | ƒ D] } |  j | j | ƒ qT Wd S)zLRemove a vertex from the graph, disconnecting all edges from/to it.
        N)r   Úremover   Úpopr   )r   r   ÚfÚtr   r   r   r   %   s
    zDirectedGraph.removec             C   s$   | |  j  | k o# | |  j | k S)N)r   r   )r   r   r   r   r   r   Ú	connected.   s    zDirectedGraph.connectedc             C   sG   | |  j  k r t | ƒ ‚ |  j | j | ƒ |  j | j | ƒ d S)zgConnect two existing vertices.

        Nothing happens if the vertices are already connected.
        N)r   ÚKeyErrorr   r   r   )r   r   r   r   r   r   Úconnect1   s    zDirectedGraph.connectc             c   s@   x9 |  j  j ƒ  D]( \ } } x | D] } | | f Vq# Wq Wd  S)N)r   r   )r   r   Úchildrenr   r   r   r   Ú
iter_edges;   s    zDirectedGraph.iter_edgesc             C   s   t  |  j | ƒ S)N)r
   r   )r   r   r   r   r   Úiter_children@   s    zDirectedGraph.iter_childrenc             C   s   t  |  j | ƒ S)N)r
   r   )r   r   r   r   r   Úiter_parentsC   s    zDirectedGraph.iter_parentsN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r	   r   r   r   r   r   r   r   r   r!   r"   r#   r   r   r   r   r      s   			
r   N)Úobjectr   r   r   r   r   Ú<module>   s    