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

namastey-directed-graph

Package Overview
Dependencies
Maintainers
0
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

namastey-directed-graph

A JavaScript package for implementing the Directed Graph data structure with various important methods.

  • 1.0.1
  • latest
  • npm
  • Socket score

Version published
Weekly downloads
0
Maintainers
0
Weekly downloads
 
Created
Source

namastey-directed-graph

Brief Description:
namastey-directed-graph is a JavaScript package that implements a directed graph data structure. It provides various methods to manage and interact with directed graphs.

Features

  • addVertex(vertex):
    Adds a new vertex to the graph. If the vertex already exists, it is not added again.

  • addEdge(vertex1, vertex2):
    Adds a directed edge from vertex1 to vertex2. Both vertices must exist in the graph.

  • removeVertex(vertex):
    Removes the specified vertex and all edges associated with it. Also removes any edges leading to this vertex.

  • removeEdge(vertex1, vertex2):
    Removes the directed edge from vertex1 to vertex2.

  • hasEdge(vertex1, vertex2):
    Checks if there is an edge from vertex1 to vertex2.

  • getVertices():
    Returns an array of all vertices in the graph.

  • getEdges():
    Returns an array of all edges in the graph as pairs of vertices.

  • printGraph():
    Prints the graph to the console in a human-readable format.

Installation

To install the namastey-directed-graph package, use npm:

npm install namastey-directed-graph

Examples

const DirectedGraph = require('namastey-directed-graph');

const graph = new DirectedGraph();

graph.addVertex('A');
graph.addVertex('B');
graph.addVertex('C');

graph.addEdge('A', 'B');
graph.addEdge('B', 'C');

console.log('Vertices:', graph.getVertices()); // Output: Vertices: [ 'A', 'B', 'C' ]
console.log('Edges:', graph.getEdges()); // Output: Edges: [ [ 'A', 'B' ], [ 'B', 'C' ] ]

graph.printGraph();
// Output:
// A -> B
// B -> C

console.log('Has edge from A to B:', graph.hasEdge('A', 'B')); // Output: Has edge from A to B: true
graph.removeEdge('A', 'B');
console.log('Has edge from A to B:', graph.hasEdge('A', 'B')); // Output: Has edge from A to B: false

graph.removeVertex('C');
console.log('Vertices after removing C:', graph.getVertices()); // Output: Vertices after removing C: [ 'A', 'B' ]

Keywords

FAQs

Package last updated on 27 Aug 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

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc