lib/graph.js
/**
     * Does a Breadth-First or Depth-First traversal of the graph.
     *
     * @generator
     * @param {boolean} [isDFS=false] whether to do DFS traversal, does BFS otherwise
     * @param {number} [start=0] the vertex to start at
     * @param {boolean} [gray=true] whether to return vertices upon entering
     * @param {boolean} [white=false] whether to return edges upon first encountering
     * @param {boolean} [black=false] whether to return vertices after processing
     * @yields {number} the vertex at each step
     */
Does a Breadth-First or Depth-First traversal of the graph.
Does a Breadth - First or Depth - First traversal of the graph .
* traverse(isDFS, start = 0, gray = true, white, black) {
      this.resetColors();
      const processing = [start];
      const [push, pull] = isDFS ? ['push', 'pop'] : ['push', 'shift'];
      while (processing.length) {
        const vertex = processing[pull]();
        this.setGray(vertex);
        if (gray) yield vertex;
        for (const edge of this.outEdges(vertex)) {
          if (!this.isGray(edge)) {
            processing[push](edge);
          }
          if (white) yield edge;
        }
        this.setBlack(vertex);
        if (black) yield vertex;
      }
    }
* traverse ( isDFS , start = 0 , gray = true , white , black ) { this . resetColors ( ) ; const processing = [ start ] ; const [ push , pull ] = isDFS ? [ 'push' , 'pop' ] : [ 'push' , 'shift' ] ; while ( processing . length ) { const vertex = processing [ pull ] ( ) ; this . setGray ( vertex ) ; if ( gray ) yield vertex ; for ( const edge of this . outEdges ( vertex ) ) { if ( ! this . isGray ( edge ) ) { processing [ push ] ( edge ) ; } if ( white ) yield edge ; } this . setBlack ( vertex ) ; if ( black ) yield vertex ; } }
Does a Breadth-First or Depth-First traversal of the graph.
Does a Breadth - First or Depth - First traversal of the graph .