@@ -33,7 +33,7 @@ abstract class Graph<N> {
3333 bool containsPath (N source, N target) {
3434 Set <N > seen = < N > {};
3535 bool helper (N node) {
36- if (identical ( node, target) ) return true ;
36+ if (node == target) return true ;
3737 if (! seen.add (node)) return false ;
3838 return targetsOf (node).any (helper);
3939 }
@@ -73,7 +73,6 @@ abstract class Graph<N> {
7373 /// the node is not part of a cycle in this graph, then a list containing only
7474 /// the node itself will be returned.
7575 List <N >? findCycleContaining (N node) {
76- assert (node != null );
7776 _SccFinder <N > finder = _SccFinder <N >(this );
7877 return finder._componentContaining (node);
7978 }
@@ -126,12 +125,11 @@ class EdgeListGraph<N> extends Graph<N> {
126125 @override
127126 int get nodeCount => _edges.length;
128127
129- final _empty = < N > {};
130-
131128 @override
132- Iterable <N > targetsOf (N source) => _edges[source] ?? _empty ;
129+ Iterable <N > targetsOf (N source) => _edges[source] ?? const Iterable . empty () ;
133130 @override
134- Iterable <N > sourcesOf (N source) => _revEdges[source] ?? _empty;
131+ Iterable <N > sourcesOf (N source) =>
132+ _revEdges[source] ?? const Iterable .empty ();
135133
136134 void addEdge (N source, N target) {
137135 addNode (source);
@@ -141,7 +139,6 @@ class EdgeListGraph<N> extends Graph<N> {
141139 }
142140
143141 void addNode (N node) {
144- assert (node != null );
145142 _edges.putIfAbsent (node, () => < N > {});
146143 _revEdges.putIfAbsent (node, () => < N > {});
147144 }
@@ -174,7 +171,7 @@ class EdgeListGraph<N> extends Graph<N> {
174171/// been examined. There is an instance of this class per node in the graph.
175172class _NodeInfo <N > {
176173 /// Depth of the node corresponding to this info.
177- int index = 0 ;
174+ final int index;
178175
179176 /// Depth of the first node in a cycle.
180177 int lowlink = 0 ;
@@ -187,7 +184,7 @@ class _NodeInfo<N> {
187184 /// Component that contains the corresponding node.
188185 List <N >? component;
189186
190- _NodeInfo (int depth ) : index = depth, lowlink = depth , onStack = false ;
187+ _NodeInfo (this .index ) : lowlink = index , onStack = false ;
191188}
192189
193190/// Implements Tarjan's Algorithm for finding the strongly connected components
@@ -230,7 +227,7 @@ class _SccFinder<N> {
230227
231228 /// Remove and return the top-most element from the stack.
232229 N _pop () {
233- N node = _stack.removeAt (_stack.length - 1 );
230+ N node = _stack.removeLast ( );
234231 _info[node]! .onStack = false ;
235232 return node;
236233 }
@@ -270,7 +267,7 @@ class _SccFinder<N> {
270267 w = _pop ();
271268 component.add (w);
272269 _info[w]! .component = component;
273- } while (! identical (w, v) );
270+ } while (w != v );
274271 _allComponents.add (component);
275272 }
276273 return vInfo;
0 commit comments