You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 7-8.RSVP
Socket
Socket
Sign inDemoInstall

@dagrejs/graphlib

Package Overview
Dependencies
Maintainers
3
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@dagrejs/graphlib

A directed and undirected multi-graph library


Version published
Weekly downloads
250K
decreased by-1.46%
Maintainers
3
Created
Weekly downloads
 

Package description

What is @dagrejs/graphlib?

@dagrejs/graphlib is a JavaScript library for creating and manipulating directed graphs. It provides a flexible and efficient way to work with graph data structures, including adding and removing nodes and edges, traversing the graph, and performing various graph algorithms.

What are @dagrejs/graphlib's main functionalities?

Creating a Graph

This feature allows you to create a new graph, add nodes, and add edges between nodes. The code sample demonstrates creating a graph, adding two nodes 'a' and 'b', and creating an edge from 'a' to 'b'.

const graphlib = require('@dagrejs/graphlib');
const Graph = graphlib.Graph;
const g = new Graph();
g.setNode('a');
g.setNode('b');
g.setEdge('a', 'b');
console.log(g.nodes()); // ['a', 'b']
console.log(g.edges()); // [{ v: 'a', w: 'b' }]

Graph Traversal

This feature allows you to perform depth-first search (DFS) traversal on the graph. The code sample demonstrates creating a graph with three nodes and two edges, and then performing DFS starting from node 'a'.

const graphlib = require('@dagrejs/graphlib');
const Graph = graphlib.Graph;
const g = new Graph();
g.setNode('a');
g.setNode('b');
g.setNode('c');
g.setEdge('a', 'b');
g.setEdge('b', 'c');
const dfs = graphlib.alg.dfs(g, ['a']);
console.log(dfs); // [{ v: 'a' }, { v: 'b' }, { v: 'c' }]

Finding Shortest Path

This feature allows you to find the shortest path in the graph using Dijkstra's algorithm. The code sample demonstrates creating a graph with three nodes and three weighted edges, and then finding the shortest path from node 'a' to all other nodes.

const graphlib = require('@dagrejs/graphlib');
const Graph = graphlib.Graph;
const g = new Graph();
g.setNode('a');
g.setNode('b');
g.setNode('c');
g.setEdge('a', 'b', { weight: 1 });
g.setEdge('b', 'c', { weight: 2 });
g.setEdge('a', 'c', { weight: 4 });
const dijkstra = graphlib.alg.dijkstra(g, 'a');
console.log(dijkstra); // { a: { distance: 0 }, b: { distance: 1 }, c: { distance: 3 } }

Other packages similar to @dagrejs/graphlib

Readme

Source

English | 中文

Graphlib

Graphlib is a JavaScript library that provides data structures for undirected and directed multi-graphs along with algorithms that can be used with them.

Build Status npm

To learn more see our Wiki.

There are 2 versions on NPM, but only the one in the DagreJs org is receiving updates right now.

License

Graphlib is licensed under the terms of the MIT License. See the LICENSE file for details.

Keywords

FAQs

Package last updated on 17 Jul 2024

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc