44[ ![ npm] ( https://img.shields.io/npm/v/@datastructures-js/graph.svg )] ( https://www.npmjs.com/package/@datastructures-js/graph )
55[ ![ npm] ( https://img.shields.io/npm/dm/@datastructures-js/graph.svg )] ( https://www.npmjs.com/package/@datastructures-js/graph ) [ ![ npm] ( https://img.shields.io/badge/node-%3E=%206.0-blue.svg )] ( https://www.npmjs.com/package/@datastructures-js/graph )
66
7+ Graph & Directed Graph implementation in javascript.
8+
9+ <img src =" https://user-images.githubusercontent.com/6517308/121813242-859a9700-cc6b-11eb-99c0-49e5bb63005b.jpg " >
10+
711<table ><tr ><td >
812 <img alt =" graph " src =" https://user-images.githubusercontent.com/6517308/71645678-802cd500-2ca1-11ea-96fb-11a71fd95191.jpg " >
913</td ></tr ></table >
1014
11- # Table of Contents
15+ # Contents
1216* [ Install] ( #install )
17+ * [ require] ( #require )
18+ * [ import] ( #import )
1319* [ API] ( #api )
14- * [ require] ( #require )
15- * [ import] ( #import )
16- * [ new] ( #new )
20+ * [ constructor] ( #constructor )
1721 * [ .addVertex(key, value)] ( #addvertexkey-value )
1822 * [ .hasVertex(key)] ( #hasvvertex-key )
1923 * [ .getVerticesCount()] ( #getverticescount )
3539npm install --save @datastructures-js/graph
3640```
3741
38- ## API
39-
4042### require
4143
4244``` js
@@ -49,15 +51,27 @@ const { Graph, DirectedGraph } = require('@datastructures-js/graph');
4951import { Graph , DirectedGraph } from ' @datastructures-js/graph' ;
5052```
5153
52- ### new
54+ ## API
55+
56+ ### constructor
5357Creates a new graph
5458
59+ ##### JS
5560``` js
5661const directedGraph = new DirectedGraph ();
5762
5863const graph = new Graph ();
5964```
6065
66+ ##### TS
67+ ``` js
68+ // DirectedGraph<T extends number|string, U = undefined>
69+ const directedGraph = new DirectedGraph < number, { id: string, someProp: any }> ();
70+
71+ // Graph<T extends number|string, U = undefined>
72+ const graph = new Graph < string, number> ();
73+ ```
74+
6175### .addVertex(key, value)
6276Adds a vertex to the graph.
6377
@@ -69,11 +83,11 @@ Adds a vertex to the graph.
6983 </tr >
7084 <tr >
7185 <td>
72- key: number | string
86+ key: T ( number | string)
7387 <br />
74- value: any
88+ value: U
7589 </td>
76- <td align="center">Graph | DirectedGraph</td>
90+ <td align="center">Graph<T, U> | DirectedGraph<T, U> </td>
7791 <td align="center">O(1)</td>
7892 </tr >
7993</table >
@@ -105,7 +119,7 @@ Checks if the graph has a vertex by its key.
105119 </tr >
106120 <tr >
107121 <td>
108- key: number | string
122+ key: T ( number | string)
109123 </td>
110124 <td align="center">boolean</td>
111125 <td align="center">O(1)</td>
@@ -147,13 +161,13 @@ Adds a weighted edge between two existings vertices. Default weight is 1 if not
147161 </tr >
148162 <tr >
149163 <td>
150- srcKey: number | string
164+ srcKey: T ( number | string)
151165 <br />
152- destKey: number | string
166+ destKey: T ( number | string)
153167 <br />
154168 weight: number
155169 </td>
156- <td align="center">Graph | DirectedGraph</td>
170+ <td align="center">Graph<T, U> | DirectedGraph<T, U> </td>
157171 <td align="center">O(1)</td>
158172 </tr >
159173</table >
@@ -189,9 +203,9 @@ Checks if the graph has an edge between two existing vertices. In directed graph
189203 </tr >
190204 <tr >
191205 <td>
192- srcKey: number | string
206+ srcKey: T ( number | string)
193207 <br />
194- destKey: number | string
208+ destKey: T ( number | string)
195209 </td>
196210 <td align="center">boolean</td>
197211 <td align="center">O(1)</td>
@@ -236,9 +250,9 @@ Gets the edge's weight between two vertices. If there is no direct edge between
236250 </tr >
237251 <tr >
238252 <td>
239- srcKey: number | string
253+ srcKey: T ( number | string)
240254 <br />
241- destKey: number | string
255+ destKey: T ( number | string)
242256 </td>
243257 <td align="center">number</td>
244258 <td align="center">O(1)</td>
@@ -267,7 +281,7 @@ Removes a vertex with all its edges from the graph.
267281 </tr >
268282 <tr >
269283 <td>
270- key: number | string
284+ key: T ( number | string)
271285 </td>
272286 <td align="center">boolean</td>
273287 <td>
@@ -299,9 +313,9 @@ Removes an edge between two existing vertices
299313 </tr >
300314 <tr >
301315 <td>
302- srcKey: number | string
316+ srcKey: T ( number | string)
303317 <br />
304- destKey: number | string
318+ destKey: T ( number | string)
305319 </td>
306320 <td align="center">boolean</td>
307321 <td align="center">O(1)</td>
@@ -327,7 +341,7 @@ Removes all connected edges to a vertex and returns the number of removed edges.
327341 </tr >
328342 <tr >
329343 <td>
330- key: number | string
344+ key: T ( number | string)
331345 </td>
332346 <td align="center">number</td>
333347 <td>
@@ -367,9 +381,9 @@ Traverses the graph using the depth-first recursive search.
367381 </tr >
368382 <tr >
369383 <td>
370- srcKey: number | string
384+ srcKey: T ( number | string)
371385 <br />
372- cb: function
386+ cb: (key: T, value: U) => void
373387 </td>
374388 <td>
375389 O(V) : V = number of vertices in the graph
@@ -405,9 +419,9 @@ Traverses the graph using the breadth-first search with a queue.
405419 </tr >
406420 <tr >
407421 <td>
408- srcKey: number | string
422+ srcKey: T ( number | string)
409423 <br />
410- cb: function
424+ cb: (key: T, value: U) => void
411425 </td>
412426 <td>
413427 O(V) : V = number of vertices in the graph
0 commit comments