File: //kunden/lib/python3/dist-packages/breezy/__pycache__/tsort.cpython-39.pyc
a
�*�^:~ � @ sb d Z ddlmZ ddlmZmZmZ g d�Z dd� Z
G dd � d e�Zddd
�Z
G dd� de�Zd
S )zTopological sorting routines.� )�absolute_import� )�errors�graph�revision)� topo_sort�
TopoSorter�
merge_sort�MergeSorterc C s t �t| ��}|�� S )a� Topological sort a graph.
graph -- sequence of pairs of node->parents_list.
The result is a list of node names, such that all parents come before their
children.
node identifiers can be any hashable object, and are typically strings.
This function has the same purpose as the TopoSorter class, but uses a
different algorithm to sort the graph. That means that while both return a
list with parents before their child nodes, the exact ordering can be
different.
topo_sort is faster when the whole list is needed, while when iterating
over a part of the list, TopoSorter.iter_topo_order should be used.
)�
_mod_graphZ
KnownGraph�dictr )r Zkg� r
�./usr/lib/python3/dist-packages/breezy/tsort.pyr s r c @ s$ e Zd Zdd� Zdd� Zdd� ZdS )r c C s t |�| _dS )a Topological sorting of a graph.
:param graph: sequence of pairs of node_name->parent_names_list.
i.e. [('C', ['B']), ('B', ['A']), ('A', [])]
For this input the output from the sort or
iter_topo_order routines will be:
'A', 'B', 'C'
node identifiers can be any hashable object, and are typically strings.
If you have a graph like [('a', ['b']), ('a', ['c'])] this will only use
one of the two values for 'a'.
The graph is sorted lazily: until you iterate or sort the input is
not processed other than to create an internal representation.
iteration or sorting may raise GraphCycleError if a cycle is present
in the graph.
N)r �_graph)�selfr r
r
r �__init__8 s zTopoSorter.__init__c C s t | �� �S �z|Sort the graph and return as a list.
After calling this the sorter is empty and you must create a new one.
��list�iter_topo_order�r r
r
r �sortedO s zTopoSorter.sortedc c s� | j }t|�}g }g }t� }|r�|�� \}}|�|� |�t|�� |r|d }|sv|�� } |�� |�| � | V qD|�� }
|
|v r�qD|
|vr�qDz|�|
�}W n ty� t� |��Y n0 |�|
� |�t|�� qDqdS )��Yield the nodes of the graph in a topological order.
After finishing iteration the sorter is empty and you cannot continue
iteration.
���N)
r �set�popitem�appendr �pop�add�KeyErrorr �GraphCycleError)r r Z visitableZpending_node_stack�pending_parents_stack�completed_node_names� node_name�parents�parents_to_visitZpopped_node�next_node_namer
r
r r ` s6
zTopoSorter.iter_topo_orderN)�__name__�
__module__�__qualname__r r r r
r
r
r r 6 s r NFc C s t | |||��� S )a� Topological sort a graph which groups merges.
:param graph: sequence of pairs of node->parents_list.
:param branch_tip: the tip of the branch to graph. Revisions not
reachable from branch_tip are not included in the
output.
:param mainline_revisions: If not None this forces a mainline to be
used rather than synthesised from the graph.
This must be a valid path through some part
of the graph. If the mainline does not cover all
the revisions, output stops at the start of the
old revision listed in the mainline revisions
list.
The order for this parameter is oldest-first.
:param generate_revno: Optional parameter controlling the generation of
revision number sequences in the output. See the output description of
the MergeSorter docstring for details.
:result: See the MergeSorter docstring for details.
Node identifiers can be any hashable object, and are typically strings.
)r
r )r �
branch_tip�mainline_revisions�generate_revnor
r
r r � s �r c @ s>