ó
    "Eñiþ  ã                   ó$   • S SK Jr   " S S5      rg)é    )Údequec                   óÊ   • \ rS rSrSrS rS rS rS rS r	\
S 5       r\
S	 5       rS
 rS rS\S\\   4S jrS\S\\   4S jrS\S\4S jrS\S\\   4S jrS\4S jrSrg)ÚDiGraphé   z¨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                 óJ   • 0 U l         0 U l        0 U l        0 U l        SU l        g )Nr   )Ú_nodeÚ_succÚ_predÚ_node_orderÚ_insertion_idx©Úselfs    ÚS/home/mande/repo/quber/.venv/lib/python3.13/site-packages/torch/package/_digraph.pyÚ__init__ÚDiGraph.__init__   s+   € àˆŒ
ð ˆŒ
àˆŒ
ð ˆÔØˆÕó    c                 ó  • XR                   ;  a[  X R                   U'   0 U R                  U'   0 U R                  U'   U R                  U R                  U'   U =R                  S-  sl        gU R                   U   R                  U5        g)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
   r   r   Úupdate)r   ÚnÚkwargss      r   Úadd_nodeÚDiGraph.add_node   sp   € ð —J‘JÓØ"�J‰J�q‰MØˆD�J‰J�q‰MØˆD�J‰J�q‰MØ"&×"5Ñ"5ˆD×Ñ˜QÑØ×Ò 1Ñ$Öà�J‰J�q‰M× Ñ  Õ(r   c                 ó�   • U R                  U5        U R                  U5        SU R                  U   U'   SU R                  U   U'   g)zrAdd an edge to graph between nodes ``u`` and ``v``

``u`` and ``v`` will be created if they do not already exist.
TN)r   r	   r
   )r   ÚuÚvs      r   Úadd_edgeÚDiGraph.add_edge*   sB   € ð 	�‰�aÔØ�‰�aÔð  ˆ�
‰
�1‰�aÑØˆ�
‰
�1‰�aÒr   c                 óx   •  [        U R                  U   5      $ ! [         a  n[        SU S35      UeSnAff = f)z.Returns an iterator over successor nodes of n.ú	The node ú is not in the digraph.N)Úiterr	   ÚKeyErrorÚ
ValueError©r   r   Úes      r   Ú
successorsÚDiGraph.successors7   óD   € ð	LÜ˜Ÿ
™
 1™Ó&Ð&øÜó 	LÜ˜y¨¨Ð+BÐCÓDÈ!ÐKûð	Lúó   ‚ š
9¤4´9c                 óx   •  [        U R                  U   5      $ ! [         a  n[        SU S35      UeSnAff = f)z1Returns an iterator over predecessors nodes of n.r    r!   N)r"   r
   r#   r$   r%   s      r   ÚpredecessorsÚDiGraph.predecessors>   r)   r*   c              #   ón   #   • U R                   R                  5        H  u  pU H  nX4v •  M
     M     g7f)z6Returns an iterator over all edges (u, v) in the graphN)r	   Úitems)r   r   r'   Úsuccs       r   ÚedgesÚDiGraph.edgesE   s1   é € ð "ŸZ™Z×-Ñ-Ö/‰MˆAÛ"�Ø�g”ó #ò 0ùs   ‚35c                 ó   • U R                   $ )z6Returns a dictionary of all nodes to their attributes.)r   r   s    r   ÚnodesÚDiGraph.nodesL   s   € ð �z‰zÐr   c                 ó,   • [        U R                  5      $ )zIterate over the nodes.)r"   r   r   s    r   Ú__iter__ÚDiGraph.__iter__Q   s   € ä�D—J‘JÓÐr   c                 ó@   •  XR                   ;   $ ! [         a     gf = f)z>Returns True if ``n`` is a node in the graph, False otherwise.F)r   Ú	TypeError)r   r   s     r   Ú__contains__ÚDiGraph.__contains__U   s%   € ð	ØŸ
™
‘?Ð"øÜó 	Ùð	ús   ‚ �
œÚsrcÚreturnc                 ó  • [        U5      n[        U5      n[        U5      S:”  ab  UR                  5       nU R	                  U5       H,  nXR;  d  M
  UR                  U5        UR                  U5        M.     [        U5      S:”  a  Mb  U$ )z2Returns a set of nodes that are reachable from srcr   )Úsetr   ÚlenÚpopleftr'   ÚaddÚappend©r   r=   ÚresultÚworking_setÚcurr   s         r   Úforward_transitive_closureÚ"DiGraph.forward_transitive_closure\   sx   € ô �S“ˆÜ˜C“jˆÜ�+Ó Ó"Ø×%Ñ%Ó'ˆCØ—_‘_ SÖ)�Ø•?Ø—J‘J˜q”MØ×&Ñ& qÖ)ñ *ô �+Ó Õ"ð ˆr   c                 ó  • [        U5      n[        U5      n[        U5      S:”  ab  UR                  5       nU R	                  U5       H,  nXR;  d  M
  UR                  U5        UR                  U5        M.     [        U5      S:”  a  Mb  U$ )zGReturns a set of nodes that are reachable from src in reverse directionr   )r@   r   rA   rB   r,   rC   rD   rE   s         r   Úbackward_transitive_closureÚ#DiGraph.backward_transitive_closurei   sz   € ô �S“ˆÜ˜C“jˆÜ�+Ó Ó"Ø×%Ñ%Ó'ˆCØ×&Ñ& sÖ+�Ø•?Ø—J‘J˜q”MØ×&Ñ& qÖ)ñ ,ô �+Ó Õ"ð ˆr   Údstc                 ó^  • [        5       nU R                  U5      nX$;  a  U$ [        U5      n[        U5      S:”  ab  UR	                  5       nU R                  U5       H,  nXt;   d  M
  UR                  Xv5        UR                  U5        M.     [        U5      S:”  a  Mb  UR                  5       $ )zAReturns a subgraph rooted at src that shows all the paths to dst.r   )	r   rI   r   rA   rB   r,   r   rD   Úto_dot)r   r=   rN   Úresult_graphÚforward_reachable_from_srcrG   rH   r   s           r   Ú	all_pathsÚDiGraph.all_pathsv   s¥   € ô “yˆà%)×%DÑ%DÀSÓ%IÐ"àÓ0ØÐô
 ˜C“jˆÜ�+Ó Ó"Ø×%Ñ%Ó'ˆCØ×&Ñ& sÖ+�ØÕ2Ø ×)Ñ)¨!Ô1à×&Ñ& qÖ)ñ	 ,ô �+Ó Õ"ð ×"Ñ"Ó$Ð$r   c                 ó"  • / nU(       as  UR                  U5        U R                  U   R                  5       nSu  pU H2  nU R                  R	                  US5      nUc    OUb  Xd:  d  M.  UnUnM4     U(       a  Ms  [        [        U5      5      $ )z_Returns a list of nodes that show the first path that resulted in dst being added to the graph.)Ú NN)rD   r
   Úkeysr   ÚgetÚlistÚreversed)r   rN   ÚpathÚ
candidatesÚmin_idxÚ	candidateÚidxs          r   Ú
first_pathÚDiGraph.first_pathŽ   sˆ   € àˆæØ�K‰K˜ÔØŸ™ C™×-Ñ-Ó/ˆJØ#‰LˆCÛ'�	Ø×&Ñ&×*Ñ*¨9°dÓ;�Ø‘;ÙØ‘? c¥mØ!�GØ#’Cñ (÷	 ˆcô ”H˜T“NÓ#Ð#r   c                 óR   • SR                  S U R                   5       5      nSU S3$ )z^Returns the dot representation of the graph.

Returns:
    A dot representation of the graph.
Ú
c              3   ó8   #   • U  H  u  pS U SU S3v •  M     g7f)Ú"z" -> "z";N© )Ú.0ÚfÚts      r   Ú	<genexpr>Ú!DiGraph.to_dot.<locals>.<genexpr>¦   s!   é € ÐDº±°˜A˜a˜S  q c¨Õ,ºùs   ‚z,digraph G {
rankdir = LR;
node [shape=box];
z
}
)Újoinr1   )r   r1   s     r   rP   ÚDiGraph.to_dot    s7   € ð —	‘	ÑD¸¿ºÓDÓDˆðð €ð ð	ð 	r   )r   r   r   r
   r	   N)Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Ú__doc__r   r   r   r'   r,   Úpropertyr1   r4   r7   r;   Ústrr@   rI   rL   rS   rY   r`   rP   Ú__static_attributes__rf   r   r   r   r      s¸   † ñò ò)ò  òLòLð ñó ðð ñó ðò òð¨cð °c¸#±hô ð¨sð °s¸3±xô ð%˜Sð % sô %ð0$˜cð $ d¨3¡iô $ð$˜÷ r   r   N)Úcollectionsr   r   rf   r   r   Ú<module>rw      s   ðå ÷hò hr   