JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 133
  • Score
    100M100P100Q78839F
  • License MIT

Simple utilities for processing directed graphs with numerical vertices.

Package Exports

  • simple-digraph

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (simple-digraph) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

Simple Digraph

Library with utilities for directed graphs with numerical vertices.

Initially created for PhyloPic. Functionality may be extended at a later date.

Prerequisites

This project requires npm or yarn.

Usage

Creating a directed graph

import { createGraph } from 'simple-digraph';
const graph = createGraph([[1, 2], [2, 3]], new Set([4]));
console.log(JSON.stringify([[...graph[0]], [...graph[1].values()]]));
// [[1,2,3],[[1,2],[2,3]]]

Immediate Predecessors

import { createGraph, immediatePredecessors } from 'simple-digraph';
const graph = createGraph([[1, 3], [2, 3]]);
const parents = immediatePredecessors(graph, new Set([3]));
console.log(parents);
// Set(2) {1, 2}

Sinks

import { createGraph, sinks } from 'simple-digraph';
const graph = createGraph([[1, 3], [2, 3]]);
const terminals = sinks(graph);
console.log(terminals);
// Set(1) {3}

Subgraph

import { createGraph, subgraph } from 'simple-digraph';
const graph = createGraph([[1, 3], [2, 3]]);
const partial = subgraph(graph, new Set([1, 3]));
console.log(JSON.stringify([[...partial[0]], [...partial[1].values()]]));
// [[1,3],[[1,3]]]

Transitive Closure

import { createGraph, transitiveClosure } from 'simple-digraph';
const graph = createGraph([[1, 3], [2, 3]]);
const closure = transitiveClosure(graph, new Set([1, 3]));
console.log(JSON.stringify([[...closure[0]], [...closure[1].values()]]));

Transitive Reduction

import { createGraph, transitiveReduction } from 'simple-digraph';
const graph = createGraph([[1, 3], [2, 3]]);
const closure = transitiveReduction(graph, new Set([1, 3]));
console.log(JSON.stringify([[...closure[0]], [...closure[1].values()]]));

Running the tests

To run unit tests, use:

yarn test

Linting

To check linting, use:

yarn lint

To fix some errors while linting, use:

yarn lint-fix

Contributing

Please read CONTRIBUTING.md for details on our code of conduct, and the process for submitting pull requests to us.

Versioning

We use SemVer for versioning. For the versions available, see the tags on this repository.

Authors

  • T. Michael Keesey - Creator - keesey

License

This project is licensed under the MIT License - see the LICENSE.md file for details