@gillesdemey/dag
TypeScript icon, indicating that this package has built-in type declarations

1.0.3 • Public • Published

dag

A directed acyclical graph library

Installation

npm install @gillesdemey/dag

Example

import { Graph } from '@gillesdemey/dag'

/*
 * This will create a DAG that looks like this
 *
 *                           ┌───┐
 *                         ┌▶│ 5 │──┐
 *            ┌───┐  ┌───┐ │ └───┘  │   ┌───┐
 * ┌───┐   ┌─▶│ 2 │─▶│ 4 │─┤        ├──▶│ 8 │
 * │ 1 │───┤  └───┘  └───┘ │  ┌───┐ │   └───┘
 * └───┘   │               └─▶│ 6 │─┘     ▲
 *         │                  └───┘       │
 *         │   ┌───┐  ┌───┐               │
 *         └──▶│ 3 │─▶│ 7 │───────────────┘
 *             └───┘  └───┘
 *
 * ┌───┐       ┌───┐
 * │ 0 │──────▶│ 9 │
 * └───┘       └───┘
 */
const graph = new Graph()

graph.setEdge('1', '2')
graph.setEdge('1', '3')
graph.setEdge('2', '4')
graph.setEdge('3', '7')
graph.setEdge('4', '5')
graph.setEdge('4', '6')
graph.setEdge('5', '8')
graph.setEdge('6', '8')
graph.setEdge('7', '8')
graph.setEdge('0', '9')

graph.sources() // ['1', '0']
graph.sinks()   // ['8', '9']

API

Soon-ish, check out the TypeScript source in the meantime :-)

Acknowledgements

This project started as a fork of https://github.com/dagrejs/graphlib.

The API is inspired by it but is not aiming to be backwards compatible with it.

Readme

Keywords

Package Sidebar

Install

npm i @gillesdemey/dag

Weekly Downloads

1

Version

1.0.3

License

MIT

Unpacked Size

31.2 kB

Total Files

15

Last publish

Collaborators

  • angryunicorn