adjacencyMatrixGraph(
options):AdjacencyMatrixGraph
Defined in: packages/graph/src/adjacency-matrix-graph.ts:40
An immutable graph stored as a dense n × n matrix: one bit per vertex pair
when unweighted, or one Float64Array cell per pair when weighted, with
Infinity for “no edge”.
hasEdge is O(1), and an unweighted dense graph costs n² / 8 bytes
whatever its edge count. A row walk costs O(n / 32 + d) unweighted and
O(n) weighted, so on a sparse graph every traversal pays for the absent
edges. Storage is checked against GRAPH_MAX_MATRIX_BYTES before it is
allocated. One cell per pair means the matrix cannot hold parallel edges.
Parameters
Section titled “Parameters”options
Section titled “options”The vertex count, the two required flags, selfLoops, and the edges.
Returns
Section titled “Returns”Throws
Section titled “Throws”With code PARALLEL_EDGES_UNSUPPORTED for parallelEdges: true;
MAX_CAPACITY_EXCEEDED when the matrix would pass GRAPH_MAX_MATRIX_BYTES or the runtime refuses it; or
INVALID_VERTEX_COUNT, INVALID_FLAG, INVALID_EDGE, INVALID_VERTEX, MISSING_WEIGHT,
UNEXPECTED_WEIGHT, INVALID_WEIGHT, SELF_LOOP, or PARALLEL_EDGE when an option or an edge breaks the
contract.
Example
Section titled “Example”const graph = adjacencyMatrixGraph({ vertexCount: 3, directed: true, weighted: true, edges: [[0, 2, 4]] })graph.hasEdge(0, 2) // true