@datastructures-js/graph
Advanced tools
Comparing version 5.0.1 to 5.1.0
@@ -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 |
@@ -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<T, U> | DirectedGraph<T, U></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<T, U> | DirectedGraph<T, U></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; |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
32694
21
609
479