Last active
November 2, 2015 12:32
-
-
Save devinivy/a21b879d23d02aebd971 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module.exports = function (graph, root) { | |
var traversal = graph.traverse(); | |
var edges = []; | |
var stack = [root]; | |
var current = null; | |
while (stack.length) { | |
traversal.hop(stack.pop()); | |
current = traversal.currentVertex(); | |
var v; | |
for (var i = 0; i < current.to.length; i++) { | |
v = current.to[i]; | |
if (!traversal.visits(v)) { | |
stack.push(v); | |
edges.push([current.id, v]); | |
} | |
} | |
} | |
return graph.subgraph({ | |
vertices: traversal.sequence, | |
edges: edges | |
}); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment