o
    @a                     @   s@   d Z G dd deZG dd deZdd Zdd Zd	d
 ZdS )z
Minimal directed graph replacement for networkx.DiGraph

This has the sole advantage of being a standalone file that doesn't bring any
dependency with it.
c                   @   sh   e Zd Zdd Zdd Zdd Zdd Zd	d
 Zedd Z	dd Z
dd Zdd Zdd Zdd ZdS )DiGraphc                 C   s   i | _ i | _d S N)
_adjacency_edgesself r   //usr/lib/python3/dist-packages/pythran/graph.py__init__	   s   
zDiGraph.__init__c                 C   s   dd | j | D S )Nc                 s   s    | ]}|V  qd S r   r   ).0nr   r   r   	<genexpr>   s    z%DiGraph.successors.<locals>.<genexpr>r   r   noder   r   r   
successors      zDiGraph.successorsc                    s    fdd| j  D S )Nc                 3   s     | ]\}} |v r|V  qd S r   r   )r
   kvr   r   r   r      s    z'DiGraph.predecessors.<locals>.<genexpr>)r   itemsr   r   r   r   predecessors      zDiGraph.predecessorsc                 C   s   | j |t  d S r   )r   
setdefaultsetr   r   r   r   add_node   r   zDiGraph.add_nodec                 K   s2   |  | | j|t | || j||f< d S r   )r   r   r   r   addr   )r   srcdestZpropsr   r   r   add_edge   s   
zDiGraph.add_edgec                 C   s   | j S r   )r   r   r   r   r   edges   s   zDiGraph.edgesc                 C   s    | j | | | j||f= d S r   )r   remover   )r   r   r   r   r   r   remove_edge    s   zDiGraph.remove_edgec                 C   s
   t | jS r   )lenr   r   r   r   r   __len__$      
zDiGraph.__len__c                 C   s   t | j S r   )iterr   keysr   r   r   r   __iter__'   s   zDiGraph.__iter__c                 C   s
   || j v S r   r   )r   valuer   r   r   __contains__*   r$   zDiGraph.__contains__c                 C   s
   | j | S r   r   r   r   r   r   __getitem__-   r$   zDiGraph.__getitem__N)__name__
__module____qualname__r	   r   r   r   r   propertyr   r!   r#   r'   r)   r*   r   r   r   r   r      s    
r   c                   @   s   e Zd ZdS )
UnfeasibleN)r+   r,   r-   r   r   r   r   r/   0   s    r/   c                 C   sV   t  }|g}|r)| }||v rq|| || |v rdS || | |sdS )NTF)r   popr   r   extend)graphr   r   visitedZworklistZcurrentr   r   r   has_path3   s   
r4   c           	      c   s    t |g}t| | g}|r~|d }t|d }|d u r&|  |  nTt||k rX||v r1q||v r=t||g V  d ||< |t|	  rS|
t| |  n'|  n"|t||hB @ t|	  D ]
}t||g V  qg|  |  |sd S d S )N)dictfromkeysr%   nextr0   popitemr"   listr   r&   append)	Gsourcetargetscutoffr3   stackchildrenchildtargetr   r   r   _all_simple_paths_graphh   s.   


"rD   c                 C   s   t | ||ht| d S )N   )rD   r"   )r2   r   rC   r   r   r   all_simple_paths   r   rF   N)__doc__objectr   RuntimeErrorr/   r4   rD   rF   r   r   r   r   <module>   s    (5