compressedSparseRowGraph(
options):CompressedSparseRowGraph
Defined in: packages/graph/src/compressed-sparse-row-graph.ts:35
An immutable graph stored as compressed sparse rows: one Int32Array of row
offsets and one flat array of neighbor ids, plus a flat Float64Array of
weights when the graph is weighted.
It is the layout for an edge set known up front: 4(n + 1) + 4m' bytes, plus
8m' when weighted, where m' is the stored arcs (2m undirected). Rows
are contiguous, so a walk reads memory in order. A directed graph counts its
in-degrees into one Int32Array on the first inDegree call, and builds
its transposed rows only on the first forEachPredecessor call, keeping
them and dropping the counts.
Parameters
Section titled “Parameters”options
Section titled “options”The vertex count, the two required flags, the multigraph flags, and the edges.
Returns
Section titled “Returns”Throws
Section titled “Throws”With code 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, or MAX_CAPACITY_EXCEEDED when storage cannot be allocated.
Example
Section titled “Example”const graph = compressedSparseRowGraph({ vertexCount: 4, directed: true, weighted: false, edges: [[0, 1], [0, 2], [1, 3], [2, 3]],})graph.neighbors(0) // Int32Array [1, 2]