Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

dag-map

Package Overview
Dependencies
Maintainers
4
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

dag-map

A topologically ordered map of key/value pairs with a simple API for adding constraints.

  • 2.0.2
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
698K
decreased by-2.41%
Maintainers
4
Weekly downloads
 
Created

What is dag-map?

The dag-map npm package provides a data structure for managing directed acyclic graphs (DAGs). It allows you to add nodes and edges, check for cycles, and perform topological sorting. This is useful for scenarios where you need to manage dependencies or represent hierarchical relationships.

What are dag-map's main functionalities?

Add Nodes and Edges

This feature allows you to add nodes and edges to the DAG. In the example, nodes 'a', 'b', and 'c' are added, and edges are created from 'a' to 'b' and from 'b' to 'c'.

const DAGMap = require('dag-map');
const dag = new DAGMap();
dag.add('a');
dag.add('b');
dag.add('c');
dag.addEdge('a', 'b');
dag.addEdge('b', 'c');

Check for Cycles

This feature allows you to check if the DAG contains any cycles. In the example, a cycle is created by adding an edge from 'b' back to 'a', and the `hasCycle` method returns true.

const DAGMap = require('dag-map');
const dag = new DAGMap();
dag.add('a');
dag.add('b');
dag.addEdge('a', 'b');
dag.addEdge('b', 'a');
console.log(dag.hasCycle()); // true

Topological Sorting

This feature allows you to perform a topological sort on the DAG. In the example, the nodes are sorted in topological order, resulting in the array ['a', 'b', 'c'].

const DAGMap = require('dag-map');
const dag = new DAGMap();
dag.add('a');
dag.add('b');
dag.add('c');
dag.addEdge('a', 'b');
dag.addEdge('b', 'c');
console.log(dag.topsort()); // ['a', 'b', 'c']

Other packages similar to dag-map

Keywords

FAQs

Package last updated on 08 Jan 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc