@graphty/algorithms / index / CSRGraph
Class: CSRGraph<TNodeId> ​
Defined in: optimized/csr-graph.ts:44
Compressed Sparse Row (CSR) graph representation
Provides cache-efficient graph storage with sequential memory access patterns. Optimized for traversal operations and sparse graphs.
Type Parameters ​
TNodeId ​
TNodeId = NodeId
Implements ​
ReadonlyGraph<TNodeId>
Constructors ​
Constructor ​
new CSRGraph<
TNodeId>(adjacencyList,weights?,buildReverse?):CSRGraph<TNodeId>
Defined in: optimized/csr-graph.ts:53
Creates a new CSRGraph from an adjacency list representation.
Parameters ​
adjacencyList ​
Map<TNodeId, TNodeId[]>
Map of node IDs to arrays of neighbor node IDs
weights? ​
Map<string, number>
Optional map of edge weights keyed by "source-target" strings
buildReverse? ​
boolean = true
Whether to build reverse edges for bottom-up BFS (default true)
Returns ​
CSRGraph<TNodeId>
Methods ​
edgeCount() ​
edgeCount():
number
Defined in: optimized/csr-graph.ts:218
Get the total number of edges in the graph.
Returns ​
number
The number of edges
Implementation of ​
ReadonlyGraph.edgeCount
fromGraph() ​
staticfromGraph<TNodeId>(graph):CSRGraph<TNodeId>
Defined in: optimized/csr-graph.ts:490
Create CSR graph from standard Graph interface.
Type Parameters ​
TNodeId ​
TNodeId = NodeId
Parameters ​
graph ​
The graph object to convert, must implement nodes, neighbors, hasNode, and optionally getEdge
getEdge? ​
Optional function that returns edge data including weight
hasNode ​
Function that checks if a node exists in the graph
neighbors ​
Function that returns an iterator over neighbor node IDs
nodes ​
Function that returns an iterator over node objects with id property
Returns ​
CSRGraph<TNodeId>
A new CSRGraph instance
getEdgeWeight() ​
getEdgeWeight(
source,target):number|undefined
Defined in: optimized/csr-graph.ts:420
Get edge weight between two nodes.
Parameters ​
source ​
TNodeId
The source node ID
target ​
TNodeId
The target node ID
Returns ​
number | undefined
The edge weight, or undefined if the edge doesn't exist or has no weight
getNeighborIndices() ​
getNeighborIndices(
nodeIndex):number[]
Defined in: optimized/csr-graph.ts:301
Get neighbors as indices (internal use).
Parameters ​
nodeIndex ​
number
The internal index of the node
Returns ​
number[]
Array of neighbor indices
hasEdge() ​
hasEdge(
source,target):boolean
Defined in: optimized/csr-graph.ts:237
Check if an edge exists between two nodes.
Parameters ​
source ​
TNodeId
The source node ID
target ​
TNodeId
The target node ID
Returns ​
boolean
True if the edge exists, false otherwise
Implementation of ​
ReadonlyGraph.hasEdge
hasNode() ​
hasNode(
nodeId):boolean
Defined in: optimized/csr-graph.ts:227
Check if a node exists in the graph.
Parameters ​
nodeId ​
TNodeId
The node ID to check
Returns ​
boolean
True if the node exists, false otherwise
Implementation of ​
ReadonlyGraph.hasNode
indexToNodeId() ​
indexToNodeId(
index):TNodeId
Defined in: optimized/csr-graph.ts:405
Convert internal index to node ID.
Parameters ​
index ​
number
The internal index to convert
Returns ​
TNodeId
The node ID for the given index
iterateIncomingNeighborIndices() ​
iterateIncomingNeighborIndices(
nodeIndex):Generator<number>
Defined in: optimized/csr-graph.ts:368
Iterator support for incoming neighbor indices (for bottom-up BFS).
Parameters ​
nodeIndex ​
number
The internal index of the node
Returns ​
Generator<number>
Yields ​
The indices of nodes with edges pointing to this node
iterateNeighborIndices() ​
iterateNeighborIndices(
nodeIndex):Generator<number>
Defined in: optimized/csr-graph.ts:349
Iterator support for neighbor indices.
Parameters ​
nodeIndex ​
number
The internal index of the node
Returns ​
Generator<number>
Yields ​
The indices of neighboring nodes
neighbors() ​
neighbors(
nodeId):IterableIterator<TNodeId>
Defined in: optimized/csr-graph.ts:261
Get neighbors of a node as node IDs.
Parameters ​
nodeId ​
TNodeId
The node ID to get neighbors for
Returns ​
IterableIterator<TNodeId>
An iterator over neighbor node IDs
Implementation of ​
ReadonlyGraph.neighbors
nodeCount() ​
nodeCount():
number
Defined in: optimized/csr-graph.ts:210
Get the total number of nodes in the graph.
Returns ​
number
The number of nodes
Implementation of ​
ReadonlyGraph.nodeCount
nodes() ​
nodes():
IterableIterator<TNodeId>
Defined in: optimized/csr-graph.ts:292
Get all nodes in the graph.
Returns ​
IterableIterator<TNodeId>
An iterator over all node IDs
Implementation of ​
ReadonlyGraph.nodes
nodeToIndex() ​
nodeToIndex(
nodeId):number
Defined in: optimized/csr-graph.ts:391
Convert node ID to internal index.
Parameters ​
nodeId ​
TNodeId
The node ID to convert
Returns ​
number
The internal index for the node
outDegree() ​
outDegree(
nodeId):number
Defined in: optimized/csr-graph.ts:320
Get the out-degree (number of outgoing edges) of a node.
Parameters ​
nodeId ​
TNodeId
The node ID to get the out-degree for
Returns ​
number
The number of outgoing edges from the node
Implementation of ​
ReadonlyGraph.outDegree
outDegreeByIndex() ​
outDegreeByIndex(
nodeIndex):number
Defined in: optimized/csr-graph.ts:334
Get out-degree by index (internal use).
Parameters ​
nodeIndex ​
number
The internal index of the node
Returns ​
number
The number of outgoing edges from the node