@thi.ng/dgraph
TypeScript icon, indicating that this package has built-in type declarations

2.1.114 • Public • Published

@thi.ng/dgraph

npm version npm downloads Mastodon Follow

[!NOTE] This is one of 192 standalone projects, maintained as part of the @thi.ng/umbrella monorepo and anti-framework.

🚀 Please help me to work full-time on these projects by sponsoring me on GitHub. Thank you! ❤️

About

Type-agnostic directed acyclic graph (DAG), using @thi.ng/associative maps & sets as backend.

Implementation based on Stuart Sierra's Clojure version.

Features

  • cycle detection
  • accessors for direct & transitive dependencies / dependents
  • topological sorting
  • iterable (in topo order)

Status

STABLE - used in production

Search or submit any issues for this package

Support packages

Related packages

  • @thi.ng/adjacency - Sparse & bitwise adjacency matrices, lists and selected traversal algorithms for directed & undirected graphs
  • @thi.ng/dot - Graphviz document abstraction & serialization to DOT format
  • @thi.ng/system - Minimal and explicit dependency-injection & lifecycle container for stateful app components

Installation

yarn add @thi.ng/dgraph

ESM import:

import * as dgr from "@thi.ng/dgraph";

Browser ESM import:

<script type="module" src="https://cdn.skypack.dev/@thi.ng/dgraph"></script>

Skypack documentation

For Node.js REPL:

const dgr = await import("@thi.ng/dgraph");

Package sizes (brotli'd, pre-treeshake): ESM: 868 bytes

Dependencies

Usage examples

One project in this repo's /examples directory is using this package:

Screenshot Description Live demo Source
CLI util to visualize umbrella pkg stats Source

API

Generated API docs

import { defDGraph } from "@thi.ng/dgraph";

g = defDGraph();

// add dependencies (order: a -> b)
g.addDependency([1, 2], [10, 20]);
g.addDependency([3, 4], [30, 40]);
g.addDependency([1, 2], [3, 4]);

// add isolated nodes
g.addNode([100, 200]);

g.sort();
// [[30, 40], [3, 4], [10, 20], [100, 200], [1, 2]]

Authors

If this project contributes to an academic publication, please cite it as:

@misc{thing-dgraph,
  title = "@thi.ng/dgraph",
  author = "Karsten Schmidt",
  note = "https://thi.ng/dgraph",
  year = 2015
}

License

© 2015 - 2024 Karsten Schmidt // Apache License 2.0

Package Sidebar

Install

npm i @thi.ng/dgraph

Weekly Downloads

362

Version

2.1.114

License

Apache-2.0

Unpacked Size

30.4 kB

Total Files

6

Last publish

Collaborators

  • thi.ng