UNPKG

@woosh/meep-engine

Version:

Pure JavaScript game engine. Fully featured and production ready.

24 lines (18 loc) 796 B
import { assert } from "../assert.js"; /** * Builds a matrix with node cardinality for each Node, that is, number of edges attached to each Node * NOTE: does not clear matrix before writing * @template T * @param {Graph<T>} graph * @param {SquareMatrix} result Where to store the result * @param {Map<T,number>} node_indices de-referencing dictionary from Node to unsigned integer index */ export function graph_compute_degree_matrix(graph, result, node_indices) { const nodes = graph.getNodes(); for (const node of nodes) { const node_index = node_indices.get(node); assert.isNonNegativeInteger(node_index, 'index'); const degree = graph.getNodeDegree(node); result.setCellValue(node_index, node_index, degree); } }