From 926295449a12b8fb51632b1823f0ce6995031254 Mon Sep 17 00:00:00 2001 From: Davide Depau Date: Fri, 26 Jan 2018 15:38:14 +0100 Subject: [PATCH] Ensure outgoing edge map is sorted by upstream label --- ffmpeg/dag.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/ffmpeg/dag.py b/ffmpeg/dag.py index 3ce3891..86c695f 100644 --- a/ffmpeg/dag.py +++ b/ffmpeg/dag.py @@ -2,7 +2,7 @@ from __future__ import unicode_literals from ._utils import get_hash, get_hash_int from builtins import object -from collections import namedtuple +from collections import namedtuple, OrderedDict class DagNode(object): @@ -157,7 +157,7 @@ def topo_sort(downstream_nodes): raise RuntimeError('Graph is not a DAG') if downstream_node is not None: - outgoing_edge_map = outgoing_edge_maps.get(upstream_node, {}) + outgoing_edge_map = outgoing_edge_maps.get(upstream_node, OrderedDict()) outgoing_edge_infos = outgoing_edge_map.get(upstream_label, []) outgoing_edge_infos += [(downstream_node, downstream_label)] outgoing_edge_map[upstream_label] = outgoing_edge_infos @@ -174,4 +174,10 @@ def topo_sort(downstream_nodes): while unmarked_nodes: upstream_node, upstream_label = unmarked_nodes.pop() visit(upstream_node, upstream_label, None, None) + + # Sort outgoing edge maps by upstream label + for map in outgoing_edge_maps.values(): + for label in sorted(map.keys()): + map.move_to_end(label) + return sorted_nodes, outgoing_edge_maps