From b8d1691aa352be0f636de4c76f0518cbc21d3921 Mon Sep 17 00:00:00 2001 From: tintinthong Date: Tue, 31 Mar 2020 01:55:09 +0800 Subject: [PATCH] Add transpose function --- lib/dep_graph.js | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/lib/dep_graph.js b/lib/dep_graph.js index 1954a62..28ce414 100644 --- a/lib/dep_graph.js +++ b/lib/dep_graph.js @@ -193,6 +193,20 @@ DepGraph.prototype = { }); return result; }, + /** + * Reverse all edges of graph + */ + transpose: function() { + var keys = Object.keys(this.nodes) + var outgoingEdges = this.outgoingEdges + var incomingEdges = this.incomingEdges + console.log(outgoingEdges) + keys.forEach(function(n){ + var p = outgoingEdges[n] + outgoingEdges[n]=incomingEdges[n] + incomingEdges[n] = p + }) + }, /** * Get an array containing the nodes that the specified node depends on (transitively). *