UNPKG

esds

Version:

ES6 JS lightweight data structures (Priority Queue, Binary Search Tree (BST), Graph, Bloom Filters, Trie, Queue, Stack, Linked-List)

2,425 lines (640 loc) 26.3 kB
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>JSDoc: Class: Graph</title> <script src="scripts/prettify/prettify.js"> </script> <script src="scripts/prettify/lang-css.js"> </script> <!--[if lt IE 9]> <script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script> <![endif]--> <link type="text/css" rel="stylesheet" href="styles/prettify-tomorrow.css"> <link type="text/css" rel="stylesheet" href="styles/jsdoc-default.css"> </head> <body> <div id="main"> <h1 class="page-title">Class: Graph</h1> <section> <header> <h2><span class="attribs"><span class="type-signature"></span></span>Graph<span class="signature">()</span><span class="type-signature"></span></h2> <div class="class-description">Graph Class</div> </header> <article> <div class="container-overview"> <h2>Constructor</h2> <h4 class="name" id="Graph"><span class="type-signature"></span>new Graph<span class="signature">()</span><span class="type-signature"></span></h4> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="Graph.mjs.html">Graph.mjs</a>, <a href="Graph.mjs.html#line19">line 19</a> </li></ul></dd> </dl> </div> <h3 class="subsection-title">Members</h3> <h4 class="name" id="edges"><span class="type-signature"></span>edges<span class="type-signature"></span></h4> <div class="description"> Returns number of edges in the graph </div> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="Graph.mjs.html">Graph.mjs</a>, <a href="Graph.mjs.html#line235">line 235</a> </li></ul></dd> </dl> <h4 class="name" id="size"><span class="type-signature"></span>size<span class="type-signature"></span></h4> <div class="description"> Returns number of nodes in the graph </div> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="Graph.mjs.html">Graph.mjs</a>, <a href="Graph.mjs.html#line228">line 228</a> </li></ul></dd> </dl> <h3 class="subsection-title">Methods</h3> <h4 class="name" id="addEdge"><span class="type-signature"></span>addEdge<span class="signature">(nodeA, nodeB, weight<span class="signature-attributes">opt</span>)</span><span class="type-signature"></span></h4> <div class="description"> Adds a new edge between two nodes </div> <h5>Parameters:</h5> <table class="params"> <thead> <tr> <th>Name</th> <th>Type</th> <th>Attributes</th> <th>Default</th> <th class="last">Description</th> </tr> </thead> <tbody> <tr> <td class="name"><code>nodeA</code></td> <td class="type"> <span class="param-type">number</span> | <span class="param-type">string</span> </td> <td class="attributes"> </td> <td class="default"> </td> <td class="description last"></td> </tr> <tr> <td class="name"><code>nodeB</code></td> <td class="type"> <span class="param-type">number</span> | <span class="param-type">string</span> </td> <td class="attributes"> </td> <td class="default"> </td> <td class="description last"></td> </tr> <tr> <td class="name"><code>weight</code></td> <td class="type"> <span class="param-type">any</span> </td> <td class="attributes"> &lt;optional><br> </td> <td class="default"> 1 </td> <td class="description last">Optional, default 1 if not provided</td> </tr> </tbody> </table> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="Graph.mjs.html">Graph.mjs</a>, <a href="Graph.mjs.html#line90">line 90</a> </li></ul></dd> </dl> <h4 class="name" id="addNode"><span class="type-signature"></span>addNode<span class="signature">(id, val<span class="signature-attributes">opt</span>)</span><span class="type-signature"></span></h4> <div class="description"> Adds a new node to the graph </div> <h5>Parameters:</h5> <table class="params"> <thead> <tr> <th>Name</th> <th>Type</th> <th>Attributes</th> <th class="last">Description</th> </tr> </thead> <tbody> <tr> <td class="name"><code>id</code></td> <td class="type"> <span class="param-type">number</span> | <span class="param-type">string</span> </td> <td class="attributes"> </td> <td class="description last"></td> </tr> <tr> <td class="name"><code>val</code></td> <td class="type"> <span class="param-type">any</span> </td> <td class="attributes"> &lt;optional><br> </td> <td class="description last"></td> </tr> </tbody> </table> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="Graph.mjs.html">Graph.mjs</a>, <a href="Graph.mjs.html#line34">line 34</a> </li></ul></dd> </dl> <h4 class="name" id="getNode"><span class="type-signature"></span>getNode<span class="signature">(id)</span><span class="type-signature"> &rarr; {any}</span></h4> <div class="description"> Returns value of node </div> <h5>Parameters:</h5> <table class="params"> <thead> <tr> <th>Name</th> <th>Type</th> <th class="last">Description</th> </tr> </thead> <tbody> <tr> <td class="name"><code>id</code></td> <td class="type"> <span class="param-type">number</span> | <span class="param-type">string</span> </td> <td class="description last"></td> </tr> </tbody> </table> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="Graph.mjs.html">Graph.mjs</a>, <a href="Graph.mjs.html#line141">line 141</a> </li></ul></dd> </dl> <h5>Returns:</h5> <div class="param-desc"> - Value </div> <dl> <dt> Type </dt> <dd> <span class="param-type">any</span> </dd> </dl> <h4 class="name" id="getPath"><span class="type-signature"></span>getPath<span class="signature">(nodeA, nodeB)</span><span class="type-signature"> &rarr; {Array.&lt;Array>}</span></h4> <div class="description"> Returns array of the shortest path between two nodes Based on the shortest number of intermediate nodes </div> <h5>Parameters:</h5> <table class="params"> <thead> <tr> <th>Name</th> <th>Type</th> <th class="last">Description</th> </tr> </thead> <tbody> <tr> <td class="name"><code>nodeA</code></td> <td class="type"> <span class="param-type">number</span> | <span class="param-type">string</span> </td> <td class="description last"></td> </tr> <tr> <td class="name"><code>nodeB</code></td> <td class="type"> <span class="param-type">number</span> | <span class="param-type">string</span> </td> <td class="description last"></td> </tr> </tbody> </table> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="Graph.mjs.html">Graph.mjs</a>, <a href="Graph.mjs.html#line193">line 193</a> </li></ul></dd> </dl> <h5>Returns:</h5> <div class="param-desc"> - [{node, weight}] </div> <dl> <dt> Type </dt> <dd> <span class="param-type">Array.&lt;Array></span> </dd> </dl> <h4 class="name" id="getPathWeighted"><span class="type-signature"></span>getPathWeighted<span class="signature">(nodeA, nodeB)</span><span class="type-signature"> &rarr; {Array.&lt;Array>}</span></h4> <div class="description"> Returns array of the shortest weighted path between two nodes (Dijkstra algorithm) Based on the shortest number of intermediate nodes </div> <h5>Parameters:</h5> <table class="params"> <thead> <tr> <th>Name</th> <th>Type</th> <th class="last">Description</th> </tr> </thead> <tbody> <tr> <td class="name"><code>nodeA</code></td> <td class="type"> <span class="param-type">number</span> | <span class="param-type">string</span> </td> <td class="description last"></td> </tr> <tr> <td class="name"><code>nodeB</code></td> <td class="type"> <span class="param-type">number</span> | <span class="param-type">string</span> </td> <td class="description last"></td> </tr> </tbody> </table> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="Graph.mjs.html">Graph.mjs</a>, <a href="Graph.mjs.html#line152">line 152</a> </li></ul></dd> </dl> <h5>Returns:</h5> <div class="param-desc"> - [{nodes: [], distance: number}] </div> <dl> <dt> Type </dt> <dd> <span class="param-type">Array.&lt;Array></span> </dd> </dl> <h4 class="name" id="getWeight"><span class="type-signature"></span>getWeight<span class="signature">(nodeA, nodeB)</span><span class="type-signature"> &rarr; {number}</span></h4> <div class="description"> Returns the sum of weights between two nodes, including intermediate ones. Based on the shortest number of intermediate nodes </div> <h5>Parameters:</h5> <table class="params"> <thead> <tr> <th>Name</th> <th>Type</th> <th class="last">Description</th> </tr> </thead> <tbody> <tr> <td class="name"><code>nodeA</code></td> <td class="type"> <span class="param-type">number</span> | <span class="param-type">string</span> </td> <td class="description last"></td> </tr> <tr> <td class="name"><code>nodeB</code></td> <td class="type"> <span class="param-type">number</span> | <span class="param-type">string</span> </td> <td class="description last"></td> </tr> </tbody> </table> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="Graph.mjs.html">Graph.mjs</a>, <a href="Graph.mjs.html#line245">line 245</a> </li></ul></dd> </dl> <h5>Returns:</h5> <dl> <dt> Type </dt> <dd> <span class="param-type">number</span> </dd> </dl> <h4 class="name" id="nodesConnected"><span class="type-signature"></span>nodesConnected<span class="signature">(nodeA, nodeB)</span><span class="type-signature"> &rarr; {boolean}</span></h4> <div class="description"> Returns true/false if edge exists between two nodes </div> <h5>Parameters:</h5> <table class="params"> <thead> <tr> <th>Name</th> <th>Type</th> <th class="last">Description</th> </tr> </thead> <tbody> <tr> <td class="name"><code>nodeA</code></td> <td class="type"> <span class="param-type">number</span> | <span class="param-type">string</span> </td> <td class="description last"></td> </tr> <tr> <td class="name"><code>nodeB</code></td> <td class="type"> <span class="param-type">number</span> | <span class="param-type">string</span> </td> <td class="description last"></td> </tr> </tbody> </table> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="Graph.mjs.html">Graph.mjs</a>, <a href="Graph.mjs.html#line79">line 79</a> </li></ul></dd> </dl> <h5>Returns:</h5> <div class="param-desc"> - True/False if connection exists between nodes </div> <dl> <dt> Type </dt> <dd> <span class="param-type">boolean</span> </dd> </dl> <h4 class="name" id="removeEdge"><span class="type-signature"></span>removeEdge<span class="signature">(nodeA, nodeB)</span><span class="type-signature"> &rarr; {boolean}</span></h4> <div class="description"> Removes an existing edge between two nodes </div> <h5>Parameters:</h5> <table class="params"> <thead> <tr> <th>Name</th> <th>Type</th> <th class="last">Description</th> </tr> </thead> <tbody> <tr> <td class="name"><code>nodeA</code></td> <td class="type"> <span class="param-type">number</span> | <span class="param-type">string</span> </td> <td class="description last"></td> </tr> <tr> <td class="name"><code>nodeB</code></td> <td class="type"> <span class="param-type">number</span> | <span class="param-type">string</span> </td> <td class="description last"></td> </tr> </tbody> </table> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="Graph.mjs.html">Graph.mjs</a>, <a href="Graph.mjs.html#line125">line 125</a> </li></ul></dd> </dl> <h5>Returns:</h5> <dl> <dt> Type </dt> <dd> <span class="param-type">boolean</span> </dd> </dl> <h4 class="name" id="removeNode"><span class="type-signature"></span>removeNode<span class="signature">(id)</span><span class="type-signature"> &rarr; {boolean}</span></h4> <div class="description"> Remove the node, and its edges across all the nodes </div> <h5>Parameters:</h5> <table class="params"> <thead> <tr> <th>Name</th> <th>Type</th> <th class="last">Description</th> </tr> </thead> <tbody> <tr> <td class="name"><code>id</code></td> <td class="type"> <span class="param-type">number</span> | <span class="param-type">string</span> </td> <td class="description last"></td> </tr> </tbody> </table> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="Graph.mjs.html">Graph.mjs</a>, <a href="Graph.mjs.html#line57">line 57</a> </li></ul></dd> </dl> <h5>Returns:</h5> <dl> <dt> Type </dt> <dd> <span class="param-type">boolean</span> </dd> </dl> <h4 class="name" id="updateEdge"><span class="type-signature"></span>updateEdge<span class="signature">(nodeA, nodeB, weight<span class="signature-attributes">opt</span>)</span><span class="type-signature"> &rarr; {boolean}</span></h4> <div class="description"> Updates the weight of an existing edge between two nodes </div> <h5>Parameters:</h5> <table class="params"> <thead> <tr> <th>Name</th> <th>Type</th> <th>Attributes</th> <th>Default</th> <th class="last">Description</th> </tr> </thead> <tbody> <tr> <td class="name"><code>nodeA</code></td> <td class="type"> <span class="param-type">number</span> | <span class="param-type">string</span> </td> <td class="attributes"> </td> <td class="default"> </td> <td class="description last"></td> </tr> <tr> <td class="name"><code>nodeB</code></td> <td class="type"> <span class="param-type">number</span> | <span class="param-type">string</span> </td> <td class="attributes"> </td> <td class="default"> </td> <td class="description last"></td> </tr> <tr> <td class="name"><code>weight</code></td> <td class="type"> <span class="param-type">weight</span> </td> <td class="attributes"> &lt;optional><br> </td> <td class="default"> 1 </td> <td class="description last">Optional, default 1 if not provided</td> </tr> </tbody> </table> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="Graph.mjs.html">Graph.mjs</a>, <a href="Graph.mjs.html#line108">line 108</a> </li></ul></dd> </dl> <h5>Returns:</h5> <dl> <dt> Type </dt> <dd> <span class="param-type">boolean</span> </dd> </dl> <h4 class="name" id="updateNode"><span class="type-signature"></span>updateNode<span class="signature">(id, val<span class="signature-attributes">opt</span>)</span><span class="type-signature"> &rarr; {boolean}</span></h4> <div class="description"> Updates value for an existing node </div> <h5>Parameters:</h5> <table class="params"> <thead> <tr> <th>Name</th> <th>Type</th> <th>Attributes</th> <th class="last">Description</th> </tr> </thead> <tbody> <tr> <td class="name"><code>id</code></td> <td class="type"> <span class="param-type">number</span> | <span class="param-type">string</span> </td> <td class="attributes"> </td> <td class="description last"></td> </tr> <tr> <td class="name"><code>val</code></td> <td class="type"> <span class="param-type">any</span> </td> <td class="attributes"> &lt;optional><br> </td> <td class="description last"></td> </tr> </tbody> </table> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="Graph.mjs.html">Graph.mjs</a>, <a href="Graph.mjs.html#line47">line 47</a> </li></ul></dd> </dl> <h5>Returns:</h5> <dl> <dt> Type </dt> <dd> <span class="param-type">boolean</span> </dd> </dl> </article> </section> </div> <nav> <h2><a href="index.html">Home</a></h2><h3>Classes</h3><ul><li><a href="BloomFilter.html">BloomFilter</a></li><li><a href="BST.html">BST</a></li><li><a href="Element.html">Element</a></li><li><a href="Graph.html">Graph</a></li><li><a href="List.html">List</a></li><li><a href="Node.html">Node</a></li><li><a href="PriorityQueue.html">PriorityQueue</a></li><li><a href="Queue.html">Queue</a></li><li><a href="Stack.html">Stack</a></li><li><a href="TreeElement.html">TreeElement</a></li><li><a href="Trie.html">Trie</a></li></ul> </nav> <br class="clear"> <footer> Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 3.6.7</a> on Thu Sep 23 2021 00:49:18 GMT-0700 (Pacific Daylight Time) </footer> <script> prettyPrint(); </script> <script src="scripts/linenumber.js"> </script> </body> </html>