function dijkstra(g, source, weightFunc, incidentFunc) {
  var results = {},
      pq = new PriorityQueue();

  function updateNeighbors(e) {
    var incidentNodes = g.incidentNodes(e),
        v = incidentNodes[0] !== u ? incidentNodes[0] : incidentNodes[1],
        vEntry = results[v],
        weight = weightFunc(e),
        distance = uEntry.distance + weight;

    if (weight < 0) {
      throw new Error("dijkstra does not allow negative edge weights. Bad edge: " + e + " Weight: " + weight);
    }

    if (distance < vEntry.distance) {
      vEntry.distance = distance;
      vEntry.predecessor = u;
      pq.decrease(v, distance);
    }
  }

  weightFunc = weightFunc || function() { return 1; };
  incidentFunc = incidentFunc || (g.isDirected()
      ? function(u) { return g.outEdges(u); }
      : function(u) { return g.incidentEdges(u); });

  g.nodes().forEach(function(u) {
    var distance = u === source ? 0 : Number.POSITIVE_INFINITY;
    results[u] = { distance: distance };
    pq.add(u, distance);
  });

  var u, uEntry;
  while (pq.size() > 0) {
    u = pq.removeMin();
    uEntry = results[u];
    if (uEntry.distance === Number.POSITIVE_INFINITY) {
      break;
    }

    incidentFunc(u).forEach(updateNeighbors);
  }

  return results;
}
This function is an implementation of [Dijkstra's algorithm][] which finds
the shortest path from **source** to all other nodes in **g**. This
function returns a map of `u -> { distance, predecessor }`. The distance
property holds the sum of the weights from **source** to `u` along the
shortest path or `Number.POSITIVE_INFINITY` if there is no path from
**source**. The predecessor property can be used to walk the individual
elements of the path from **source** to **u** in reverse order.

This function takes an optional `weightFunc(e)` which returns the
weight of the edge `e`. If no weightFunc is supplied then each edge is
assumed to have a weight of 1. This function throws an Error if any of
the traversed edges have a negative edge weight.

This function takes an optional `incidentFunc(u)` which returns the ids of
all edges incident to the node `u` for the purposes of shortest path
traversal. By default this function uses the `g.outEdges` for Digraphs and
`g.incidentEdges` for Graphs.

This function takes `O((|E| + |V|) * log |V|)` time.

[Dijkstra's algorithm]: http://en.wikipedia.org/wiki/Dijkstra%27s_algorithm

@param {Graph} g the graph to search for shortest paths from **source**
@param {Object} source the source from which to start the search
@param {Function} [weightFunc] optional weight function
@param {Function} [incidentFunc] optional incident function