"use strict" module.exports = stronglyConnectedComponents function stronglyConnectedComponents(adjList) { var numVertices = adjList.length; var index = new Array(numVertices) var lowValue = new Array(numVertices) var active = new Array(numVertices) var child = new Array(numVertices) var scc = new Array(numVertices) var sccLinks = new Array(numVertices) //Initialize tables for(var i=0; i 0) { v = T[T.length-1] var e = adjList[v] if (child[v] < e.length) { // If we're not done iterating over the children, first try finishing that. for(var i=child[v]; i= 0) { // Node v is not yet assigned an scc, but once it is that scc can apparently reach scc[u]. sccLinks[v].push(scc[u]) } } child[v] = i // Remember where we left off. } else { // If we're done iterating over the children, check whether we have an scc. if(lowValue[v] === index[v]) { // TODO: It /might/ be true that T is always a prefix of S (at this point!!!), and if so, this could be used here. var component = [] var links = [], linkCount = 0 for(var i=S.length-1; i>=0; --i) { var w = S[i] active[w] = false component.push(w) links.push(sccLinks[w]) linkCount += sccLinks[w].length scc[w] = components.length if(w === v) { S.length = i break } } components.push(component) var allLinks = new Array(linkCount) for(var i=0; i