graph
A graph data structure with pipepack related algorithm.
Installing
This library is distributed only via NPM.
# npm
npm install @pipepack/graph;
# yarn
yarn add @pipepack/graph;
Then, use like below:
// esm
import { Graph } from '@pipepack/graph';
// commonjs
const { Graph } = require('@pipepack/graph');
Serialization
Serializes the graph with declaration below:
type NodeID = string;
type EdgeID = string;
type EdgeWeight = string | number;
interface GraphNode {
id: NodeID;
}
interface GraphEdge {
source: NodeID;
target: NodeID;
weight?: EdgeWeight;
}
interface Serialized {
nodes: GraphNode[];
edges: GraphEdge[];
}
const graph = new Graph();
graph.addEdge('a', 'b');
graph.addEdge('b', 'c');
{
"nodes": [{ "id": "a" }, { "id": "b" }, { "id": "c" }],
"links": [
{ "source": "a", "target": "b", "weight": 1 },
{ "source": "b", "target": "c", "weight": 1 }
]
}
Licence
MIT