a
    •˜ëj{  ã                   @  sö   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d�Zg d¢Zddddœdd„Zd)dddddœdd„Zddd dœd!d"„Zd#d$d%œ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_cycleszCollection[Tuple[_T, _T]]zCollection[_T]zIterator[Sequence[_T]])ÚtuplesÚallitemsÚreturnc                 #  s¢   t  t¡}| D ]\}}||  |¡ qt|ƒ}t|ƒ‰ ˆ ržg }|D ]}ˆ  || ¡rB| |¡ qB|sztdt| |ƒt	|ƒƒ‚ˆ  
|¡ ‡ fdd„|D ƒ}|V  q6d S )NzCircular dependency detected.c                   s   g | ]}|ˆ v r|‘qS © r   )Ú.0Út©Ztodo_setr   úZ/mnt/bigstor/www/usecases/.venv/lib/python3.9/site-packages/sqlalchemy/util/topological.pyÚ
<listcomp>6   ó    z#sort_as_subsets.<locals>.<listcomp>)r   ÚdefaultdictÚsetÚaddÚlistÚ
isdisjointÚappendr   r   Ú
_gen_edgesÚdifference_update)r   r   ÚedgesÚparentÚchildÚtodoÚoutputÚnoder   r   r   r      s&    
ý
r   TÚboolzIterator[_T])r   r   Údeterministic_orderr   c                 c  s   t | |ƒD ]}|E dH  q
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   r-   Úset_r   r   r   r   :   s    r   zIterable[Tuple[_T, _T]]zIterable[_T]zSet[_T]c                 C  sÄ   t  t¡}| D ]\}}||  |¡ qt|ƒ}tƒ }|D ]†}|g}| |¡}	|r8|d }
||
 D ]R}||v r’|| |¡d … }|	 |¡ | |¡ ||	v r`| |¡ |	 	|¡  qLq`| 
¡  qLq8|S )Néÿÿÿÿ)r   r   r   r    Ú
differenceÚindexr%   Úupdater#   ÚremoveÚpop)r   r   r&   r'   r(   Znodes_to_testr*   r+   Ústackr)   ÚtopZcycr   r   r   r   M   s*    





r   zDefaultDict[_T, Set[_T]]zSet[Tuple[_T, _T]])r&   r   c                   s   ‡ fdd„ˆ D ƒS )Nc                   s"   h | ]}ˆ | D ]}||f’qqS r   r   )r   ÚleftÚright©r&   r   r   Ú	<setcomp>x   r   z_gen_edges.<locals>.<setcomp>r   r9   r   r9   r   r$   w   s    r$   N)T)Ú__doc__Ú
__future__r   Útypingr   r   r   r   r   r   r	   r
   r   Ú r   Úexcr   r   Ú__all__r   r   r   r$   r   r   r   r   Ú<module>   s&    ý*