a �DOge%�@s@ddgZdZdZGdd�d�ZGdd�de�ZGdd�d�ZdS) �TopologicalSorter� CycleError����������c@seZdZdZdd�ZdS)� _NodeInfo��node� npredecessors� successorscCs||_d|_g|_dS�N�r)�selfr�r � /usr/lib64/python3.9/graphlib.py�__init__ sz_NodeInfo.__init__N)�__name__� __module__� __qualname__� __slots__rr r r rrsrc@s eZdZdS)rN)rrrr r r rrs c@s^eZdZddd�Zdd�Zdd�Zdd �Zd d �Zd d �Zdd�Z dd�Z dd�Z dd�Z dS)rNcCsHi|_d|_d|_d|_|durD|��D]\}}|j|g|�R�q(dSr )� _node2info� _ready_nodes� _npassedout� _nfinished�items�add)r Zgraphr� predecessorsr r rr*szTopologicalSorter.__init__cCs*|j�|�}dur&t|�|j|<}|S�N)r�getr)r r�resultr r r� _get_nodeinfo4szTopologicalSorter._get_nodeinfocGsR|jdurtd��|�|�}|jt|�7_|D]}|�|�}|j�|�q2dS)Nz/Nodes cannot be added after a call to prepare())r� ValueErrorrr�lenr �append)r rr�nodeinfoZpredZ pred_infor r rr9s   zTopologicalSorter.addcCsB|jdurtd��dd�|j��D�|_|��}|r>td|��dS)Nzcannot prepare() more than oncecSsg|]}|jdkr|j�qS)r )rr)�.0�ir r r� _sz-TopologicalSorter.prepare..znodes are in a cycle)rrr�values� _find_cycler)r �cycler r r�prepareTs �zTopologicalSorter.preparecCsV|jdurtd��t|j�}|j}|D]}t||_q&|j��|jt|�7_|S�N�prepare() must be called first) rr�tupler� _NODE_OUTr�clearrr )r r�n2irr r r� get_readyjs    zTopologicalSorter.get_readycCs(|jdurtd��|j|jkp&t|j�Sr*)rrrr�bool�r r r r� is_active�s zTopologicalSorter.is_activecCs|��Sr)r3r2r r r�__bool__�szTopologicalSorter.__bool__cGs�|jdurtd��|j}|D]�}|�|�}durBtd|�d���|j}|tkr�|dkrjtd|�d���n|tkr�td|�d���nt|_|jD]0}||}|jd8_|jdkr�|j�|�q�|j d7_ qdS)Nr+znode z was not added using add()r z% was not passed out (still not ready)z was already marked done�) rrrrrr-� _NODE_DONEr r!r)r Znodesr/rr"�stat� successorZsuccessor_infor r r�done�s*  �  zTopologicalSorter.donec Cs�|j}g}g}t�}i}|D]�}||vr*q||vrV||vr�|||d�|gSn6|�|�|�t||j�j�t|�||<|�|�|r�z|d�}Wq*Wq�ty�||� �=|� �Yq�0q�qq*qdS)Nr) r�setrr!�iterr �__next__r � StopIteration�pop)r r/�stackZitstack�seenZ node2stackirr r rr'�s0      zTopologicalSorter._find_cycleccs2|��|��r.|��}|EdH|j|�qdSr)r)r3r0r9)r Z node_groupr r r� static_order�s  zTopologicalSorter.static_order)N) rrrrrrr)r0r3r4r9r'rAr r r rr's /%N)�__all__r-r6rrrrr r r r�s