unweighted.js
function singleSource(graph, source) {
  if (!isGraph(graph))
    throw new Error('graphology-shortest-path: invalid graphology instance.');

  if (arguments.length < 2)
    throw new Error('graphology-shortest-path: invalid number of arguments. Expecting at least 2.');

  if (!graph.hasNode(source))
    throw new Error('graphology-shortest-path: the "' + source + '" source node does not exist in the given graph.');

  source = '' + source;

  var nextLevel = {},
      paths = {},
      currentLevel,
      neighbors,
      v,
      w,
      i,
      l;

  nextLevel[source] = true;
  paths[source] = [source];

  while (Object.keys(nextLevel).length) {
    currentLevel = nextLevel;
    nextLevel = {};

    for (v in currentLevel) {
      neighbors = graph.outNeighbors(v);
      neighbors.push.apply(neighbors, graph.undirectedNeighbors(v));

      for (i = 0, l = neighbors.length; i < l; i++) {
        w = neighbors[i];

        if (!paths[w]) {
          paths[w] = paths[v].concat(w);
          nextLevel[w] = true;
        }
      }
    }
  }

  return paths;
}
function singleSource(graph, source) {
  if (!isGraph(graph))
    throw new Error('graphology-shortest-path: invalid graphology instance.');

  if (arguments.length < 2)
    throw new Error('graphology-shortest-path: invalid number of arguments. Expecting at least 2.');

  if (!graph.hasNode(source))
    throw new Error('graphology-shortest-path: the "' + source + '" source node does not exist in the given graph.');

  source = '' + source;

  var nextLevel = {},
      paths = {},
      currentLevel,
      neighbors,
      v,
      w,
      i,
      l;

  nextLevel[source] = true;
  paths[source] = [source];

  while (Object.keys(nextLevel).length) {
    currentLevel = nextLevel;
    nextLevel = {};

    for (v in currentLevel) {
      neighbors = graph.outNeighbors(v);
      neighbors.push.apply(neighbors, graph.undirectedNeighbors(v));

      for (i = 0, l = neighbors.length; i < l; i++) {
        w = neighbors[i];

        if (!paths[w]) {
          paths[w] = paths[v].concat(w);
          nextLevel[w] = true;
        }
      }
    }
  }

  return paths;
}
function singleSource ( graph , source ) { if ( ! isGraph ( graph ) ) throw new Error ( 'graphology-shortest-path: invalid graphology instance.' ) ; if ( arguments . length < 2 ) throw new Error ( 'graphology-shortest-path: invalid number of arguments. Expecting at least 2.' ) ; if ( ! graph . hasNode ( source ) ) throw new Error ( 'graphology-shortest-path: the "' + source + '" source node does not exist in the given graph.' ) ; source = '' + source ; var nextLevel = { } , paths = { } , currentLevel , neighbors , v , w , i , l ; nextLevel [ source ] = true ; paths [ source ] = [ source ] ; while ( Object . keys ( nextLevel ) . length ) { currentLevel = nextLevel ; nextLevel = { } ; for ( v in currentLevel ) { neighbors = graph . outNeighbors ( v ) ; neighbors . push . apply ( neighbors , graph . undirectedNeighbors ( v ) ) ; for ( i = 0 , l = neighbors . length ; i < l ; i ++ ) { w = neighbors [ i ] ; if ( ! paths [ w ] ) { paths [ w ] = paths [ v ] . concat ( w ) ; nextLevel [ w ] = true ; } } } } return paths ; }
Function attempting to find the shortest path in the graph between the
given source node & all the other nodes.

@param  {Graph}  graph  - Target graph.
@param  {any}    source - Source node.
@return {object}        - The map of found paths.
 TODO: cutoff option
Function attempting to find the shortest path in the graph between the given source node & all the other nodes .