Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(144)

Unified Diff: lib/src/graph.dart

Issue 1412903002: include fields in verify_deps, refactor graph dfs (Closed) Base URL: git@github.com:dart-lang/dart2js_info.git@master
Patch Set: Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « bin/verify_deps.dart ('k') | pubspec.yaml » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/src/graph.dart
diff --git a/lib/src/graph.dart b/lib/src/graph.dart
index 4bb7f4b78c3daf17c132088dbe5b041fae918b64..bea74558a103581569894c5317f47786de4fe2d9 100644
--- a/lib/src/graph.dart
+++ b/lib/src/graph.dart
@@ -3,7 +3,7 @@
// BSD-style license that can be found in the LICENSE file.
/// A library to work with graphs. It contains a couple algorithms, including
-/// Tarjan's algorithm to compute strongest connected components in a graph and
+/// Tarjan's algorithm to compute strongly connected components in a graph and
/// Cooper et al's dominator algorithm.
///
/// Portions of the code in this library was adapted from
@@ -53,9 +53,21 @@ abstract class Graph<N> {
return result;
}
- /// Return a list of nodes that form a cycle containing the given node. If the
- /// node is not part of a cycle in this graph, then a list containing only the
- /// node itself will be returned.
+ /// Returns an iterable of all nodes reachable from [root].
Siggi Cherem (dart-lang) 2015/10/16 23:07:41 maybe indicate that they are in preorder?
Harry Terkelsen 2015/10/19 22:11:12 Done.
+ Iterable<N> reachableFrom(N root) sync* {
Siggi Cherem (dart-lang) 2015/10/16 23:07:41 maybe rename this and/or `postOrder` above so we h
Harry Terkelsen 2015/10/19 22:11:12 Done.
+ var seen = new Set<N>();
+ var stack = <N>[root];
+ while (!stack.isEmpty) {
+ var next = stack.removeLast();
+ seen.add(next);
+ yield next;
Siggi Cherem (dart-lang) 2015/10/16 23:07:41 nice use of sync*/yield :)
Harry Terkelsen 2015/10/19 22:11:12 thanks!
+ stack.addAll(targetsOf(next).where((x) => !seen.contains(x)));
+ }
+ }
+
+ /// Returns a list of nodes that form a cycle containing the given node. If
+ /// the node is not part of a cycle in this graph, then a list containing only
+ /// the node itself will be returned.
List<N> findCycleContaining(N node) {
assert(node != null);
_SccFinder<N> finder = new _SccFinder<N>(this);
« no previous file with comments | « bin/verify_deps.dart ('k') | pubspec.yaml » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698