a
    Ž¥»aI
  ã                   @   s   G d d„ dƒ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e	dd„ ƒZ
e	dd„ ƒZdd„ Zdd„ ZdS )ÚDiGraphz´Really simple unweighted directed graph data structure to track dependencies.

    The API is pretty much the same as networkx so if you add something just
    copy their API.
    c                 C   s   i | _ i | _i | _d S )N©Ú_nodeÚ_succÚ_pred©Úself© r   úP/home/yuhw/wc/pochoir/venv/lib/python3.9/site-packages/torch/package/_digraph.pyÚ__init__   s    zDiGraph.__init__c                 K   s>   || j vr*|| j |< i | j|< i | j|< n| j |  |¡ dS )zºAdd a node to the graph.

        Args:
            n: the node. Can we any object that is a valid dict key.
            **kwargs: any attributes you want to attach to the node.
        N)r   r   r   Úupdate)r   ÚnÚkwargsr   r   r	   Úadd_node   s
    


zDiGraph.add_nodec                 C   sp   || j vr(i | j |< i | j|< i | j|< || j vrPi | j |< i | j|< i | j|< d| j| |< d| j| |< dS )z‚Add an edge to graph between nodes ``u`` and ``v``

        ``u`` and ``v`` will be created if they do not already exist.
        TNr   )r   ÚuÚvr   r   r	   Úadd_edge   s    







zDiGraph.add_edgec              
   C   sL   zt | j| ƒW S  tyF } ztd|› d�ƒ|‚W Y d}~n
d}~0 0 dS )z.Returns an iterator over successor nodes of n.ú	The node ú is not in the digraph.N)Úiterr   ÚKeyErrorÚ
ValueError©r   r   Úer   r   r	   Ú
successors2   s    zDiGraph.successorsc              
   C   sL   zt | j| ƒW S  tyF } ztd|› d�ƒ|‚W Y d}~n
d}~0 0 dS )z1Returns an iterator over predecessors nodes of n.r   r   N)r   r   r   r   r   r   r   r	   Úpredecessors9   s    zDiGraph.predecessorsc                 c   s,   | j  ¡ D ]\}}|D ]}||fV  qq
dS )z6Returns an iterator over all edges (u, v) in the graphN)r   Úitems)r   r   r   Úsuccr   r   r	   Úedges@   s    zDiGraph.edgesc                 C   s   | j S )z6Returns a dictionary of all nodes to their attributes.)r   r   r   r   r	   ÚnodesG   s    zDiGraph.nodesc                 C   s
   t | jƒS )zIterate over the nodes.)r   r   r   r   r   r	   Ú__iter__L   s    zDiGraph.__iter__c                 C   s&   z|| j v W S  ty    Y dS 0 dS )z>Returns True if ``n`` is a node in the graph, False otherwise.FN)r   Ú	TypeError)r   r   r   r   r	   Ú__contains__P   s    zDiGraph.__contains__N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r
   r   r   r   r   Úpropertyr   r   r   r!   r   r   r   r	   r      s   	

r   N)r   r   r   r   r	   Ú<module>   ó    