// SSDLPediapackageil.ac.technion.cs.cs236700.graph;
importstaticjava.lang.Math.min;
importil.ac.technion.cs.cs236700.graph.Graph.Vertex;
importjava.util.Stack;
/** * Implementation of a strong components algorithm. * * <Data> the type of information stored in a graph node * Author: Yossi Gil * See: 28/06/2007 */publicclassStrongComponentProcessor<DataextendsComparable<Data>> extendsEmptyProcessor<Data, Graph<Component<Data>>> {
privateintmax_dfs = 0;
privatefinalStack<Vertex<Data>> stack = newStack<Vertex<Data>>();
privateComponent<Data>[] vertex2Component;
privateint[] dfs;
privateint[] lowlink;
privateboolean[] stacked;
@Overridepublicvoidbefore(finalGraph<Data> g) {
finalintn = g.vertices.length;
dfs = newint[n];
lowlink = newint[n];
stacked = newboolean[n];
@SuppressWarnings("unchecked") finalComponent<Data>[] v2c = newComponent[n];
vertex2Component = v2c;
}
@Overridepublicvoidbefore(finalVertex<Data> v) {
dfs[v.i] = lowlink[v.i] = max_dfs++;
stacked[v.i] = true;
stack.push(v);
}
@Overridepublicvoidafter(finalVertex<Data> from, finalVertex<Data> to) {
lowlink[from.i] = min(lowlink[from.i], lowlink[to.i]);
}
@Overridepublicvoidrevisit(finalVertex<Data> from, finalVertex<Data> to) {
if (stacked[to.i])
lowlink[from.i] = min(lowlink[from.i], dfs[to.i]);
}
@Overridepublicvoidafter(finalVertex<Data> v) {
if (lowlink[v.i] != dfs[v.i])
return;
finalComponent.Builder<Data> b = newComponent.Builder<Data>();
while (true) {
finalGraph.Vertex<Data> u = stack.pop();
stacked[u.i] = false;
b.add(u);
if (u == v)
break;
}
finalComponent<Data> c = b.build();
for (finalGraph.Vertex<Data> u : c.vertices)
vertex2Component[u.i] = c;
}
/** * Create the strongly connected components graph by adding all edges * between between the strong components. There is an arc from a strong * component to another if there is at least one edge from a vertex of one * component to a vertex the other. */@OverridepublicGraph<Component<Data>> after(@SuppressWarnings("unused") finalGraph<Data> _) {
finalGraph.Builder<Component<Data>> $ = newGraph.Builder<Component<Data>>();
for (finalComponent<Data> c : vertex2Component) {
$.newVertex(c);
for (finalGraph.Vertex<Data> v : c.vertices)
for (finalGraph.Vertex<Data> u : v.to)
if (vertex2Component[u.i] != c)
$.newEdge(c, vertex2Component[u.i]);
}
return$.build();
}
}
Metrics
Metric
Value
Acronym
Explanation
LOC
82
Lines Of Code
Total number of lines in the code
SCC
33
SemiColons Count
Total number of semicolon tokens found in the code.
NOT
601
Number Of Tokens
Comments, whitespace and text which cannot be made into a token not included.
VCC
2147
Visible Characters Count
The total number of non-white (i.e., not space, tab, newline, carriage return, form feed) characters.
CCC
1733
Code Characters Count
Total number of non-white characters in tokens. White space characters in string and character literals are not counted.
UIC
49
Unique Identifiers Count
The number of different identifiers found in the code