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

@datastructures-js/graph

Package Overview
Dependencies
Maintainers
1
Versions
19
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@datastructures-js/graph - npm Package Compare versions

Comparing version 5.0.1 to 5.1.0

src/directedGraph.d.ts

4

CHANGELOG.md

@@ -8,2 +8,6 @@ # Changelog

## [Unreleased]
## [v5.1.0] - 2021-06-20
### Added
- typescript.
## [v5.0.1] - 2021-04-15

@@ -10,0 +14,0 @@ ### Fixed

7

index.js

@@ -1,4 +0,5 @@

const Graph = require('./src/graph');
const DirectedGraph = require('./src/directedGraph');
const { Graph } = require('./src/graph');
const { DirectedGraph } = require('./src/directedGraph');
module.exports = { Graph, DirectedGraph };
exports.Graph = Graph;
exports.DirectedGraph = DirectedGraph;
{
"name": "@datastructures-js/graph",
"version": "5.0.1",
"version": "5.1.0",
"description": "graph & directed graph implementation in javascript",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -7,2 +7,6 @@ # @datastructures-js/graph

Graph & Directed Graph implementation in javascript.
<img src="https://user-images.githubusercontent.com/6517308/121813242-859a9700-cc6b-11eb-99c0-49e5bb63005b.jpg">
<table><tr><td>

@@ -12,8 +16,8 @@ <img alt="graph" src="https://user-images.githubusercontent.com/6517308/71645678-802cd500-2ca1-11ea-96fb-11a71fd95191.jpg">

# Table of Contents
# Contents
* [Install](#install)
* [require](#require)
* [import](#import)
* [API](#api)
* [require](#require)
* [import](#import)
* [new](#new)
* [constructor](#constructor)
* [.addVertex(key, value)](#addvertexkey-value)

@@ -40,4 +44,2 @@ * [.hasVertex(key)](#hasvvertex-key)

## API
### require

@@ -55,5 +57,8 @@

### new
## API
### constructor
Creates a new graph
##### JS
```js

@@ -65,2 +70,11 @@ const directedGraph = new DirectedGraph();

##### TS
```js
// DirectedGraph<T extends number|string, U = undefined>
const directedGraph = new DirectedGraph<number, { id: string, someProp: any }>();
// Graph<T extends number|string, U = undefined>
const graph = new Graph<string, number>();
```
### .addVertex(key, value)

@@ -77,7 +91,7 @@ Adds a vertex to the graph.

<td>
key: number | string
key: T (number | string)
<br />
value: any
value: U
</td>
<td align="center">Graph | DirectedGraph</td>
<td align="center">Graph&lt;T, U&gt; | DirectedGraph&lt;T, U&gt;</td>
<td align="center">O(1)</td>

@@ -114,3 +128,3 @@ </tr>

<td>
key: number | string
key: T (number | string)
</td>

@@ -157,9 +171,9 @@ <td align="center">boolean</td>

<td>
srcKey: number | string
srcKey: T (number | string)
<br />
destKey: number | string
destKey: T (number | string)
<br />
weight: number
</td>
<td align="center">Graph | DirectedGraph</td>
<td align="center">Graph&lt;T, U&gt; | DirectedGraph&lt;T, U&gt;</td>
<td align="center">O(1)</td>

@@ -200,5 +214,5 @@ </tr>

<td>
srcKey: number | string
srcKey: T (number | string)
<br />
destKey: number | string
destKey: T (number | string)
</td>

@@ -248,5 +262,5 @@ <td align="center">boolean</td>

<td>
srcKey: number | string
srcKey: T (number | string)
<br />
destKey: number | string
destKey: T (number | string)
</td>

@@ -280,3 +294,3 @@ <td align="center">number</td>

<td>
key: number | string
key: T (number | string)
</td>

@@ -313,5 +327,5 @@ <td align="center">boolean</td>

<td>
srcKey: number | string
srcKey: T (number | string)
<br />
destKey: number | string
destKey: T (number | string)
</td>

@@ -342,3 +356,3 @@ <td align="center">boolean</td>

<td>
key: number | string
key: T (number | string)
</td>

@@ -383,5 +397,5 @@ <td align="center">number</td>

<td>
srcKey: number | string
srcKey: T (number | string)
<br />
cb: function
cb: (key: T, value: U) => void
</td>

@@ -422,5 +436,5 @@ <td>

<td>
srcKey: number | string
srcKey: T (number | string)
<br />
cb: function
cb: (key: T, value: U) => void
</td>

@@ -427,0 +441,0 @@ <td>

@@ -182,11 +182,14 @@ /**

*/
traverseDfs(srcKey, cb, visited = new Set()) {
if (!this.hasVertex(srcKey) || visited.has(srcKey)) return;
traverseDfs(srcKey, cb) {
const traverseDfsRecursive = (key, visited = new Set()) => {
if (!this.hasVertex(key) || visited.has(key)) return;
cb(srcKey, this._vertices.get(srcKey));
visited.add(srcKey);
cb(key, this._vertices.get(key));
visited.add(key);
this._edges.get(srcKey).forEach((weight, destKey) => {
this.traverseDfs(destKey, cb, visited);
});
this._edges.get(key).forEach((weight, destKey) => {
traverseDfsRecursive(destKey, visited);
});
};
traverseDfsRecursive(srcKey);
}

@@ -229,2 +232,2 @@

module.exports = DirectedGraph;
exports.DirectedGraph = DirectedGraph;

@@ -7,3 +7,3 @@ /**

const DirectedGraph = require('./directedGraph');
const { DirectedGraph } = require('./directedGraph');

@@ -75,2 +75,2 @@ /**

module.exports = Graph;
exports.Graph = Graph;
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