lib/graph.js
/**
     * For non-negative edges.
     *
     * @private
     * @param {number} start
     * @param {number} end
     * @param {Array<number>} distances
     * @param {Array<number>} predecessors
     * @returns {boolean}
     */
For non-negative edges.
For non - negative edges .
searchDijkstra(start, end, distances, predecessors) {
      this.resetColors();
      const heap = new VertexHeap();
      distances[start] = 0;
      heap.push({ e: start, w: this[start] });
      let isFound = false;
      while (heap.length) {
        const vertex = heap.shift();
        if (this.isGray(vertex.e)) continue;
        this.setGray(vertex.e);
        for (const edge of this.outEdges(vertex.e)) {
          const weight = this.getEdge(vertex.e, edge);
          const distance = distances[vertex.e] + weight;
          if (distance < distances[edge]) {
            distances[edge] = distance;
            predecessors[edge] = vertex.e;
            heap.push({ e: edge, w: distance });
          }
          if (edge === end) {
            isFound = true;
          }
        }
      }
      return isFound;
    }
searchDijkstra ( start , end , distances , predecessors ) { this . resetColors ( ) ; const heap = new VertexHeap ( ) ; distances [ start ] = 0 ; heap . push ( { e : start , w : this [ start ] } ) ; let isFound = false ; while ( heap . length ) { const vertex = heap . shift ( ) ; if ( this . isGray ( vertex . e ) ) continue ; this . setGray ( vertex . e ) ; for ( const edge of this . outEdges ( vertex . e ) ) { const weight = this . getEdge ( vertex . e , edge ) ; const distance = distances [ vertex . e ] + weight ; if ( distance < distances [ edge ] ) { distances [ edge ] = distance ; predecessors [ edge ] = vertex . e ; heap . push ( { e : edge , w : distance } ) ; } if ( edge === end ) { isFound = true ; } } } return isFound ; }
For non-negative edges.
For non - negative edges .