
    Hwg                     &     G d  de       Zd Zd Zy)c                       e Zd Zy)CyclicDependencyErrorN)__name__
__module____qualname__     T/var/www/horilla/myenv/lib/python3.12/site-packages/django/utils/topological_sort.pyr   r      s    r   r   c           	   #   v  K   | j                         }|r|j                         D ch c]
  \  }}|r	| }}}|s>t        dj                  dj	                  d |j                         D                          | |j                         D ci c]  \  }}||vr|||z
   }}}|ryyc c}}w c c}}w w)ag  
    Variation of Kahn's algorithm (1962) that returns sets.

    Take a dependency graph as a dictionary of node => dependencies.

    Yield sets of items in topological order, where the first set contains
    all nodes without dependencies, and each following set contains all
    nodes that may depend on the nodes only in the previously yielded sets.
    zCyclic dependency in graph: {}z, c              3   2   K   | ]  }t        |        y wN)repr).0xs     r	   	<genexpr>z+topological_sort_as_sets.<locals>.<genexpr>   s     <!d1g<s   N)copyitemsr   formatjoin)dependency_graphtodonodedepscurrentdependenciess         r	   topological_sort_as_setsr      s        "D
*.**,CJD$d4CC'077II<tzz|<<  
 '+jjl
"l7" <'))
 
 C
s'   &B9
B-B-AB9B3%B9+B9c                 d    g }t        |      D ]  }| D ]  }||v s|j                  |        ! |S r   )r   append)nodesr   resultlayerr   s        r	   stable_topological_sortr!   $   sE    F)*:; $ 	$Du}d#	$$ Mr   N)
ValueErrorr   r   r!   r   r   r	   <module>r#      s   	J 	
>r   