@pipepack/graph
Version:
A graph data structure with pipepack related algorithm.
75 lines (56 loc) • 1.42 kB
Markdown

[](https://coveralls.io/github/pipepack/?branch=master)


A graph data structure with pipepack related algorithm.
This library is distributed only via [NPM](npmjs.com).
```shell
npm install @pipepack/graph;
yarn add @pipepack/graph;
```
Then, use like below:
```javascript
// esm
import { Graph } from '@pipepack/graph';
// commonjs
const { Graph } = require('@pipepack/graph');
```
Serializes the graph with declaration below:
```typescript
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[];
}
```
```javascript
const graph = new Graph();
graph.addEdge('a', 'b');
graph.addEdge('b', 'c');
```
```json
{
"nodes": [{ "id": "a" }, { "id": "b" }, { "id": "c" }],
"links": [
{ "source": "a", "target": "b", "weight": 1 },
{ "source": "b", "target": "c", "weight": 1 }
]
}
```
MIT