TarjanCycleDetect<TNode extends Hashable> class
class TarjanCycleDetect<TNode extends Hashable> { int _index = 0; final List<_TarjanNode> _stack; final List<List<TNode>> _scc; final _TarjanList _list; TarjanCycleDetect._internal(this._list) : _index = 0, _stack = new List<_TarjanNode<TNode>>(), _scc = new List<List<TNode>>(); static List<List> getStronglyConnectedComponents(HashMap graph) { assert(graph != null); var nodes = new _TarjanList(graph); var tarjan = new TarjanCycleDetect._internal(nodes); return tarjan._executeTarjan(); } List<List<TNode>> _executeTarjan() { List<_TarjanNode> nodeList = new List<_TarjanNode>.from(_list.getSourceNodeSet()); for (final node in nodeList) { if(node.index == -1) { _tarjan(node); } } return _scc; } void _tarjan(_TarjanNode<TNode> v){ v.index = _index; v.lowlink = _index; _index++; _stack.insertRange(0, 1, v); for(final n in _list.getAdjacent(v)){ if(n.index == -1){ _tarjan(n); v.lowlink = math.min(v.lowlink, n.lowlink); } else if(_stack.indexOf(n) >= 0){ v.lowlink = math.min(v.lowlink, n.index); } } if(v.lowlink == v.index){ _TarjanNode n; var component = new List<TNode>(); do { n = _stack[0]; _stack.removeRange(0, 1); component.add(n.value); } while(n != v); _scc.add(component); } } }
Constructors
new TarjanCycleDetect._internal(_TarjanList _list) #
TarjanCycleDetect._internal(this._list) : _index = 0, _stack = new List<_TarjanNode<TNode>>(), _scc = new List<List<TNode>>();
Static Methods
List<List> getStronglyConnectedComponents(HashMap graph) #
static List<List> getStronglyConnectedComponents(HashMap graph) { assert(graph != null); var nodes = new _TarjanList(graph); var tarjan = new TarjanCycleDetect._internal(nodes); return tarjan._executeTarjan(); }
Properties
final Type runtimeType #
A representation of the runtime type of the object.
external Type get runtimeType;
Operators
bool operator ==(other) #
The equality operator.
The default behavior for all Object
s is to return true if and
only if this
and
other are the same object.
If a subclass overrides the equality operator it should override
the hashCode
method as well to maintain consistency.
bool operator ==(other) => identical(this, other);
Methods
int hashCode() #
Get a hash code for this object.
All objects have hash codes. Hash codes are guaranteed to be the
same for objects that are equal when compared using the equality
operator ==
. Other than that there are no guarantees about
the hash codes. They will not be consistent between runs and
there are no distribution guarantees.
If a subclass overrides hashCode
it should override the
equality operator as well to maintain consistency.
external int hashCode();
noSuchMethod(String name, List args) #
noSuchMethod
is invoked when users invoke a non-existant method
on an object. The name of the method and the arguments of the
invocation are passed to noSuchMethod
. If noSuchMethod
returns a value, that value becomes the result of the original
invocation.
The default behavior of noSuchMethod
is to throw a
noSuchMethodError
.
external Dynamic noSuchMethod(String name, List args);
const Object() #
Creates a new Object
instance.
Object
instances have no meaningful state, and are only useful
through their identity. An Object
instance is equal to itself
only.
const Object();
new TarjanCycleDetect._internal(_TarjanList _list) #
TarjanCycleDetect._internal(this._list) : _index = 0, _stack = new List<_TarjanNode<TNode>>(), _scc = new List<List<TNode>>();
String toString() #
Returns a string representation of this object.
external String toString();