
    [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d&S ),zTopological sorting algorithms.    )annotations)Any)
Collection)DefaultDict)Iterable)Iterator)Sequence)Set)Tuple)TypeVar   )util)CircularDependencyError_T)bound)sortsort_as_subsetsfind_cyclestuplesCollection[Tuple[_T, _T]]allitemsCollection[_T]returnIterator[Sequence[_T]]c              #    K   t          j        t                    }| D ] \  }}||                             |           !t	          |          }t          |          rg }|D ]2}                    ||                   r|                    |           3|s,t          dt          | |          t          |                    
                    |           fd|D             }|V  d S d S )NzCircular dependency detected.c                    g | ]}|v |	S  r   ).0ttodo_sets     j/var/www/api.easyaligner.net/htdocs/venv_linux/lib/python3.11/site-packages/sqlalchemy/util/topological.py
<listcomp>z#sort_as_subsets.<locals>.<listcomp>6   s    111a1=====    )r   defaultdictsetaddlist
isdisjointappendr   r   
_gen_edgesdifference_update)	r   r   edgesparentchildtodooutputnoder    s	           @r!   r   r      s1      '+&6s&;&;E ! !e    >>D8}}H
  	$ 	$D""5;// $d### 	)/FH--5!!   	""6***11114111      r#   Tdeterministic_orderboolIterator[_T]c              #  @   K   t          | |          D ]
}|E d{V  dS )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   r2   set_s       r!   r   r   :   s>        11   r#   Iterable[Tuple[_T, _T]]Iterable[_T]Set[_T]c                >   t          j        t                    }| D ] \  }}||                             |           !t          |          }t                      }|D ]}|g}|                    |          }	|r|d         }
||
         D ]}}||v rG||                    |          d          }|	                    |           |                    |           ||	v r,|                    |           |		                    |            n~|
                                }||S )N)r   r$   r%   r&   
differenceindexr+   updater)   removepop)r   r   r,   r-   r.   nodes_to_testr0   r1   stackr/   topcycs               r!   r   r   M   sH    '+&6s&;&;E ! !f%    JJMUUF  # #''.. 	#)Cc
 # #5==D 1 1 3 34C**3///MM#&&&4<<LL&&&KK%%%E  
 yy{{  	# Mr#   r,   DefaultDict[_T, Set[_T]]Set[Tuple[_T, _T]]c                       fd D             S )Nc                .    h | ]}|         D ]}||fS r   r   )r   leftrightr,   s      r!   	<setcomp>z_gen_edges.<locals>.<setcomp>x   s.    EEEdtEEUDMEEEEr#   r   )r,   s   `r!   r*   r*   w   s    EEEEeEEEEr#   N)r   r   r   r   r   r   )T)r   r   r   r   r2   r3   r   r4   )r   r7   r   r8   r   r9   )r,   rE   r   rF   )__doc__
__future__r   typingr   r   r   r   r   r	   r
   r   r    r   excr   r   __all__r   r   r   r*   r   r#   r!   <module>rR      so   & % " " " " " "                                                             ) ) ) ) ) )WT
4
4
4   > !%    &' ' ' 'TF F F F F Fr#   