
    +h+                     B    d Z ddlmZ ddlmZ g dZd Zd
dZd Zd Z	y	)zTopological sorting algorithms.   )util)CircularDependencyError)sortsort_as_subsetsfind_cyclesc              #     K   t        j                  t              }| D ]  \  }}||   j                  |        t	        |      }t        |      }|r~g }|D ](  }|j                  ||         s|j                  |       * |s t        dt        | |      t        |            |j                  |       |D 	cg c]	  }	|	|v s|	 }}	| |r}y y c c}	w w)NzCircular dependency detected.)r   defaultdictsetaddlist
isdisjointappendr   r   
_gen_edgesdifference_update)
tuplesallitemsedgesparentchildtodotodo_setoutputnodets
             N/var/www/html/venv/lib/python3.12/site-packages/sqlalchemy/util/topological.pyr   r      s     S!E !e ! >D8}H
 	$D""5;/d#	$ )/FH-5!  	""6*1a1=11  2s%   A+C.A
C8	CCCCc              #   D   K   t        | |      D ]  }|D ]  }|   yw)a,  sort the given list of items by dependency.

    'tuples' is a list of tuples representing a partial ordering.

    deterministic_order is no longer used, the order is now always
    deterministic given the order of "allitems".    the flag is there
    for backwards compatibility with Alembic.

    N)r   )r   r   deterministic_orderset_ss        r   r   r   +   s2       1  	AG	s    c                    t        j                  t              }| D ]  \  }}||   j                  |        t        |      }t               }|D ]  }|g}|j	                  |      }	|s|d   }
||
   D ]d  }||v r6||j                  |      d  }|	j                  |       |j                  |       ||	v sB|j                  |       |	j                  |        n |j                         }|r |S )N)r   r	   r
   r   
differenceindexr   updater   removepop)r   r   r   r   r   nodes_to_testr   r   stackr   topcycs               r   r   r   ;   s    S!E !f% !JMUF  #''.)Cc
 #5=D 1 34C**3/MM#&4<LL&KK%# yy{ #" M    c           	      \    t        | D cg c]  }| |   D ]  }||f  c}}      S c c}}w )N)r
   )r   leftrights      r   r   r   c   s/    %I$U4[IEIIJJIs   (
N)T)
__doc__ r   excr   __all__r   r   r   r    r+   r   <module>r4      s+    &  )
46 %PKr+   