
    h                        d Z ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlm	Z	 dd	lm
Z
 dd
lmZ ddlmZ ddlmZ ddlmZ  ede      Zg dZ	 	 	 	 	 	 ddZ	 d	 	 	 	 	 	 	 ddZ	 	 	 	 	 	 ddZddZy)zTopological sorting algorithms.    )annotations)Any)
Collection)DefaultDict)Iterable)Iterator)Sequence)Set)Tuple)TypeVar   )util)CircularDependencyError_T)bound)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
             DD:\EasyAligner\venv\Lib\site-packages\sqlalchemy/util/topological.pyr   r      s      '+&6&6s&;Ee    >D8}H
D""5;/d#  )/FH-5!  	""6*14a1=41  2s%   A+C.A
C8	CCCCc              #  F   K   t        | |      D ]  }|E d{     y7 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_s       r(   r   r   :   s#       1 2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   M   s     '+&6&6s&;Ef%   JMUF ''.)Cc
5=D 1 34C**3/MM#&4<LL&KK% # yy{  " M    c                J    | D ch c]  }| |   D ]  }||f  c}}S c c}}w )N )r    leftrights      r(   r   r   w   s*    &+EedtUDMMeEEEs   N)r   Collection[Tuple[_T, _T]]r   Collection[_T]returnzIterator[Sequence[_T]])T)r   r<   r   r=   r*   boolr>   zIterator[_T])r   zIterable[Tuple[_T, _T]]r   zIterable[_T]r>   zSet[_T])r    zDefaultDict[_T, Set[_T]]r>   zSet[Tuple[_T, _T]])__doc__
__future__r   typingr   r   r   r   r   r	   r
   r   r    r   excr   r   __all__r   r   r   r   r9   r7   r(   <module>rF      s    & "           )T
4%1?> !%%  	&'#'/;''TFr7   