o
    Šåg‚  ã                   @  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„Z	d,d-dd„Zd.d#d$„Zd/d(d)„Zd*S )0z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                 #  sª   � t  t¡}| D ]\}}||  |¡ qt|ƒ}t|ƒ‰ ˆ rSg }|D ]}ˆ  || ¡r0| |¡ q"|s>tdt| |ƒt	|ƒƒ‚ˆ  
|¡ ‡ fdd„|D ƒ}|V  ˆ sd S d S )NzCircular dependency detected.c                   s   g | ]}|ˆ v r|‘qS © r   )Ú.0Út©Útodo_setr   úW/var/www/html/flaskapp/venv/lib/python3.10/site-packages/sqlalchemy/util/topological.pyÚ
<listcomp>6   s    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Údeterministic_orderÚboolúIterator[_T]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   úIterable[Tuple[_T, _T]]úIterable[_T]úSet[_T]c                 C  sÆ   t  t¡}| D ]\}}||  |¡ qt|ƒ}tƒ }|D ]D}|g}| |¡}	|r`|d }
||
 D ])}||v rI|| |¡d … }|	 |¡ | |¡ ||	v rY| |¡ |	 	|¡  nq0| 
¡ }|s(q|S )Néÿÿÿÿ)r   r!   r"   r#   Ú
differenceÚindexr(   Úupdater&   ÚremoveÚpop)r   r   r)   r*   r+   Únodes_to_testr-   r.   Ústackr,   ÚtopÚcycr   r   r   r   M   s0   





ýó€r   r)   úDefaultDict[_T, Set[_T]]úSet[Tuple[_T, _T]]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   s   " z_gen_edges.<locals>.<setcomp>r   rD   r   rD   r   r'   w   s   r'   N)r   r   r   r   r   r   )T)r   r   r   r   r/   r0   r   r1   )r   r3   r   r4   r   r5   )r)   r@   r   rA   )Ú__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(   
ý
*