in src/main/java/org/apache/commons/graph/scc/KosarajuSharirAlgorithm.java [66:100]
private List<V> getExpandedVertexList( final V source, final Set<V> visitedVertices )
{
final int size = ( source != null ) ? 13 : graph.getOrder();
final Set<V> vertices = new HashSet<V>( size );
if ( source != null )
{
vertices.add( source );
}
else
{
for ( V vertex : graph.getVertices() )
{
vertices.add( vertex );
}
}
// use an ArrayList so that subList is fast
final ArrayList<V> expandedVertexList = new ArrayList<V>();
int idx = 0;
while ( ! vertices.isEmpty() )
{
// get the next vertex that has not yet been added to the expanded list
final V v = vertices.iterator().next();
searchRecursive( graph, v, expandedVertexList, visitedVertices, true );
// remove all expanded vertices from the list of vertices that have to be
// still processed. To improve performance, only the items that have been
// added to the list since the last iteration are removed
vertices.removeAll( expandedVertexList.subList( idx, expandedVertexList.size() ) );
idx = expandedVertexList.size();
}
return expandedVertexList;
}