UNPKG

ibowankenobi-mergesort

Version:

Merge Sort algorithm implementation without recursion, using cached binary trees

495 lines (141 loc) 6.74 kB
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>JSDoc: Module: Mergesort</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">Module: Mergesort</h1> <section> <header> </header> <article> <div class="container-overview"> <div class="description"><p>Mergesort module</p></div> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="mergesort.0.0.3.evergreen.js.html">mergesort.0.0.3.evergreen.js</a>, <a href="mergesort.0.0.3.evergreen.js.html#line1">line 1</a> </li></ul></dd> </dl> <h4 class="name" id="module:Mergesort"><span class="type-signature"></span>(require("Mergesort"))<span class="signature">(config)</span><span class="type-signature"> &rarr; {<a href="module-Mergesort-instance.html">module:Mergesort~instance</a>}</span></h4> <div class="description"> <p>Returns a <code>Mergesort</code> <code>instance</code></p> <pre class="prettyprint source lang-javascript"><code> let instance = Mergesort(); //switches to insertion sort for array fragments &lt; 16 instance = Mergesort({threshold: 64}); //will switch to insertion sort for fragments &lt; 64 instance = Mergesort({size:999}); //will throw an error if you try to sort arrays with length other than 999 </code></pre> </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>config</code></td> <td class="type"> <span class="param-type"><a href="module-Mergesort.html#~config">module:Mergesort~config</a></span> </td> <td class="description last"><p>a configuration object with optional parameters (default 16)</p></td> </tr> </tbody> </table> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="mergesort.0.0.3.evergreen.js.html">mergesort.0.0.3.evergreen.js</a>, <a href="mergesort.0.0.3.evergreen.js.html#line257">line 257</a> </li></ul></dd> </dl> <h5>Returns:</h5> <dl> <dt> Type </dt> <dd> <span class="param-type"><a href="module-Mergesort-instance.html">module:Mergesort~instance</a></span> </dd> </dl> </div> <h3 class="subsection-title">Namespaces</h3> <dl> <dt><a href="module-Mergesort-instance.html">instance</a></dt> <dd></dd> </dl> <h3 class="subsection-title">Type Definitions</h3> <h4 class="name" id="~config">config</h4> <div class="description"> <p>An optinal configuration object that can be passed to the <code>Mergesort</code> factory function</p> </div> <h5>Type:</h5> <ul> <li> <span class="param-type">Object</span> </li> </ul> <h5 class="subsection-title">Properties:</h5> <table class="props"> <thead> <tr> <th>Name</th> <th>Type</th> <th class="last">Description</th> </tr> </thead> <tbody> <tr> <td class="name"><code>threshold</code></td> <td class="type"> <span class="param-type">number</span> </td> <td class="description last"><p>The threshold below where the algorithm temporarily switches over to insertion sort</p></td> </tr> <tr> <td class="name"><code>size</code></td> <td class="type"> <span class="param-type">number</span> </td> <td class="description last"><p>Use this if you are going to consistently sort arrays of fixed size. Refers to size of the array to be sorted, where a binary tree is precalculated. The tree will be reused for each call of the returned <code>instance</code>. For each use, the tree is <em>walked</em> by setting <code>firstChild</code> properties of leaf nodes to null and then regenerated by setting them again from the <code>lastChild</code> property of their parent. This option results in a performance gain for large (&gt; 1M) arrays, where cost of creating the tree is greater than the cost of walking + regenerating the tree. For small arrays, it has the reverse effect. It is set to off by default.</p></td> </tr> </tbody> </table> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="mergesort.0.0.3.evergreen.js.html">mergesort.0.0.3.evergreen.js</a>, <a href="mergesort.0.0.3.evergreen.js.html#line221">line 221</a> </li></ul></dd> </dl> </article> </section> </div> <nav> <h2><a href="index.html">Home</a></h2><h3>Modules</h3><ul><li><a href="module-Mergesort.html">Mergesort</a></li></ul><h3>Namespaces</h3><ul><li><a href="module-Mergesort-instance.html">instance</a></li></ul> </nav> <br class="clear"> <footer> Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 3.6.7</a> on Tue Aug 10 2021 13:57:42 GMT+0200 (Central European Summer Time) </footer> <script> prettyPrint(); </script> <script src="scripts/linenumber.js"> </script> </body> </html>