lib/unweighted-adjacency-matrix.js
/**
   * Creates an adjacency matrix from a given adjacency list.
   *
   * @param {UnweightedAdjacencyList} list
   * @returns {UnweightedAdjacencyMatrix}
   */
Creates an adjacency matrix from a given adjacency list.
Creates an adjacency matrix from a given adjacency list .
static fromList(list) {
    const { vertices } = list;
    const graph = new this({ vertices });
    for (let i = 0; i < vertices; i++) {
      const offset = list[i];
      const nextOffset = list[i + 1];
      if (offset === nextOffset) continue;
      for (let j = nextOffset - 1; j >= offset; j--) {
        graph.addEdge(i, list[j]);
      }
    }
    return graph;
  }
static fromList ( list ) { const { vertices } = list ; const graph = new this ( { vertices } ) ; for ( let i = 0 ; i < vertices ; i ++ ) { const offset = list [ i ] ; const nextOffset = list [ i + 1 ] ; if ( offset === nextOffset ) continue ; for ( let j = nextOffset - 1 ; j >= offset ; j -- ) { graph . addEdge ( i , list [ j ] ) ; } } return graph ; }
Creates an adjacency matrix from a given adjacency list.
Creates an adjacency matrix from a given adjacency list .