UNPKG

buckets-js

Version:

Buckets is a complete, fully tested and documented data structure library written in pure JavaScript.

1,061 lines (641 loc) 25.4 kB
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <meta http-equiv="content-type" content="text/html; charset=utf-8" /> <meta name="generator" content="JsDoc Toolkit" /> <title>JsDoc Reference - buckets.LinkedList</title> <style type="text/css"> /* default.css */ body { font: 13.5px sans-serif; line-height: 20px; max-width: 950px; -webkit-font-smoothing: antialiased; text-align: justify; } h1 { padding: 0; color: rgb(65, 131, 196); margin: 0 auto; padding-top: 18px; } #index { margin-top: 15px; margin-left: 15px; width: 160px; position: absolute; left: 8px; padding: 8px; background: #fafafa; padding-top: 12px; padding-left: 6px; padding-right: 12px; padding-bottom: 0px; border: 1px solid rgba(0, 0, 0, 0.1); } #content { margin-left: 220px; } .classList li { padding: 0; margin: 0 0 8px 0; } .summaryTable { width: 100%; } h2 { font-size: 110%; } caption, div.sectionTitle { box-sizing: border-box; color: rgb(51, 51, 51); background-color: #fafafa; line-height: 25px; font-family: Helvetica, arial, nimbussansl, liberationsans, freesans, clean, sans-serif, 'Segoe UI Emoji', 'Segoe UI Symbol'; font-size: 14px; font-style: normal; font-variant: normal; font-weight: bold; text-align: left; padding: 2px 6px 2px 6px; border: 1px rgb(216, 216, 216) solid; } div.sectionTitle { margin-bottom: 8px; } .summaryTable thead { display: none; } .summaryTable td { vertical-align: top; padding: 4px; border-bottom: 1px rgb(216, 216, 216) solid; border-right: 1px rgb(216, 216, 216) solid; border-left: 1px rgb(216, 216, 216) solid; } /*col#summaryAttributes {}*/ .summaryTable td.attributes { border-left: 1px; width: 140px; text-align: right; } td.attributes, .fixedFont { color: rgb(2, 74, 8); font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; } .summaryTable td.nameDescription { text-align: left; } .summaryTable { margin-bottom: 8px; } .detailList .heading { font-weight: bold; padding-bottom: 6px; margin-left: 0; } .classList { list-style-type: none; padding: 0; margin: 0 0 0 8px; font-family: sans-serif; font-size: 1em; overflow: auto; } a { color:#4285f4; text-decoration: none; } hr { border: 0; border-top: 1px solid rgb(216, 216, 216); border-bottom: 1px solid rgba(255, 255, 255, 0.3); } td.nameDescription.fixedFont { color: rgb(0, 0, 0); } span.light { color: rgb(148, 149, 155); font-weight: bold; } pre { background: #fafafa; padding-top: 16px; padding-bottom: 16px; padding-left: 16px; padding-right: 16px; /* border: 1px solid rgba(0, 0, 0, 0.1); */ font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; font-style: normal; font-variant: normal; font-weight: normal; border: 1px solid rgba(0, 0, 0, 0.1); color: rgb(124, 19, 0); } </style> </head> <body> <!-- ============================== header ================================= --> <!-- begin static/header.html --> <div id="header"> </div> <!-- end static/header.html --> <!-- ============================== classes index ============================ --> <div id="index"> <!-- begin publish.classesIndex --> <ul class="classList"> <li><a href="../symbols/buckets.arrays.html">buckets.arrays</a></li> <li><a href="../symbols/buckets.Bag.html">buckets.Bag</a></li> <li><a href="../symbols/buckets.BSTree.html">buckets.BSTree</a></li> <li><a href="../symbols/buckets.Dictionary.html">buckets.Dictionary</a></li> <li><a href="../symbols/buckets.Heap.html">buckets.Heap</a></li> <li><a href="../symbols/buckets.LinkedList.html">buckets.LinkedList</a></li> <li><a href="../symbols/buckets.MultiDictionary.html">buckets.MultiDictionary</a></li> <li><a href="../symbols/buckets.PriorityQueue.html">buckets.PriorityQueue</a></li> <li><a href="../symbols/buckets.Queue.html">buckets.Queue</a></li> <li><a href="../symbols/buckets.Set.html">buckets.Set</a></li> <li><a href="../symbols/buckets.Stack.html">buckets.Stack</a></li> </ul> <!-- end publish.classesIndex --> </div> <div id="content"> <!-- ============================== class title ============================ --> <h1 class="classTitle"> Object buckets.LinkedList </h1> <!-- ============================== class summary ========================== --> <p class="description"> A linked list is a sequence of items arranged one after another. The size is not fixed and it can grow or shrink on demand. One of the main benefits of a linked list is that you can add or remove elements at both ends in constant time. One disadvantage of a linked list against an array is that it doesn’t provide constant time random access. </p> <!-- ============================== constructor summary ==================== --> <table class="summaryTable" cellspacing="0" summary="A summary of the constructor documented in the class buckets.LinkedList."> <caption>Object Summary</caption> <thead> <tr> <th scope="col">Constructor Name and Description</th> </tr> </thead> <tbody> <tr> <td class="nameDescription" > <div class="fixedFont"> <b><a href="../symbols/buckets.LinkedList.html#constructor">buckets.LinkedList</a></b>() </div> <div class="description">Creates an empty Linked List.</div> </td> </tr> </tbody> </table> <!-- ============================== properties summary ===================== --> <!-- ============================== methods summary ======================== --> <table class="summaryTable" cellspacing="0" summary="A summary of the methods documented in the class buckets.LinkedList."> <caption>Method Summary</caption> <thead> <tr> <th scope="col">Method Name and Description</th> </tr> </thead> <tbody> <tr> <td class="nameDescription"> <div class="fixedFont">buckets.LinkedList.<b><a href="../symbols/buckets.LinkedList.html#.add">add</a></b>(item, index) </div> <div class="description">Adds an element to the list.</div> </td> </tr> <tr> <td class="nameDescription"> <div class="fixedFont">buckets.LinkedList.<b><a href="../symbols/buckets.LinkedList.html#.clear">clear</a></b>() </div> <div class="description">Removes all the elements from the list.</div> </td> </tr> <tr> <td class="nameDescription"> <div class="fixedFont">buckets.LinkedList.<b><a href="../symbols/buckets.LinkedList.html#.contains">contains</a></b>(item, equalsFunction) </div> <div class="description">Returns true if the list contains the specified element.</div> </td> </tr> <tr> <td class="nameDescription"> <div class="fixedFont">buckets.LinkedList.<b><a href="../symbols/buckets.LinkedList.html#.elementAtIndex">elementAtIndex</a></b>(index) </div> <div class="description">Returns the element at the specified position in the list.</div> </td> </tr> <tr> <td class="nameDescription"> <div class="fixedFont">buckets.LinkedList.<b><a href="../symbols/buckets.LinkedList.html#.equals">equals</a></b>(other, equalsFunction) </div> <div class="description">Returns true if the list is equal to another list.</div> </td> </tr> <tr> <td class="nameDescription"> <div class="fixedFont">buckets.LinkedList.<b><a href="../symbols/buckets.LinkedList.html#.first">first</a></b>() </div> <div class="description">Returns the first element in the list.</div> </td> </tr> <tr> <td class="nameDescription"> <div class="fixedFont">buckets.LinkedList.<b><a href="../symbols/buckets.LinkedList.html#.forEach">forEach</a></b>(callback) </div> <div class="description">Executes the provided function once per element present in the list in order.</div> </td> </tr> <tr> <td class="nameDescription"> <div class="fixedFont">buckets.LinkedList.<b><a href="../symbols/buckets.LinkedList.html#.indexOf">indexOf</a></b>(item, equalsFunction) </div> <div class="description">Returns the index of the first occurrence of the specified element, or -1 if the list does not contain the element.</div> </td> </tr> <tr> <td class="nameDescription"> <div class="fixedFont">buckets.LinkedList.<b><a href="../symbols/buckets.LinkedList.html#.isEmpty">isEmpty</a></b>() </div> <div class="description">Returns true if the list contains no elements.</div> </td> </tr> <tr> <td class="nameDescription"> <div class="fixedFont">buckets.LinkedList.<b><a href="../symbols/buckets.LinkedList.html#.last">last</a></b>() </div> <div class="description">Returns the last element in the list.</div> </td> </tr> <tr> <td class="nameDescription"> <div class="fixedFont">buckets.LinkedList.<b><a href="../symbols/buckets.LinkedList.html#.remove">remove</a></b>(item, equalsFunction) </div> <div class="description">Removes the first occurrence of the specified element in the list.</div> </td> </tr> <tr> <td class="nameDescription"> <div class="fixedFont">buckets.LinkedList.<b><a href="../symbols/buckets.LinkedList.html#.removeElementAtIndex">removeElementAtIndex</a></b>(index) </div> <div class="description">Removes the element at the specified position in the list.</div> </td> </tr> <tr> <td class="nameDescription"> <div class="fixedFont">buckets.LinkedList.<b><a href="../symbols/buckets.LinkedList.html#.reverse">reverse</a></b>() </div> <div class="description">Reverses the order of the elements in the linked list (makes the last element first, and the first element last).</div> </td> </tr> <tr> <td class="nameDescription"> <div class="fixedFont">buckets.LinkedList.<b><a href="../symbols/buckets.LinkedList.html#.size">size</a></b>() </div> <div class="description">Returns the number of elements in the list.</div> </td> </tr> <tr> <td class="nameDescription"> <div class="fixedFont">buckets.LinkedList.<b><a href="../symbols/buckets.LinkedList.html#.toArray">toArray</a></b>() </div> <div class="description">Returns an array containing all the elements in the list in proper sequence.</div> </td> </tr> </tbody> </table> <!-- ============================== events summary ======================== --> <!-- ============================== constructor details ==================== --> <div class="details"><a name="constructor"> </a> <div class="sectionTitle"> Object Detail </div> <div class="fixedFont"> <b>buckets.LinkedList</b>() </div> <div class="description"> Creates an empty Linked List. </div> </div> <!-- ============================== field details ========================== --> <!-- ============================== method details ========================= --> <div class="sectionTitle"> Method Detail </div> <a name=".add"> </a> <div class="fixedFont">&lt;static&gt; <span class="light">{boolean}</span> <span class="light">buckets.LinkedList.</span><b>add</b>(item, index) </div> <div class="description"> Adds an element to the list. </div> <dl class="detailList"> <dt class="heading">Parameters:</dt> <dt> <span class="light fixedFont">{Object}</span> <b>item</b> </dt> <dd>Element to be added.</dd> <dt> <span class="light fixedFont">{number=}</span> <b>index</b> </dt> <dd>Optional index to add the element. If no index is specified the element is added to the end of the list.</dd> </dl> <dl class="detailList"> <dt class="heading">Returns:</dt> <dd><span class="light fixedFont">{boolean}</span> True if the element was added or false if the index is invalid or if the element is undefined.</dd> </dl> <hr /> <a name=".clear"> </a> <div class="fixedFont">&lt;static&gt; <span class="light">buckets.LinkedList.</span><b>clear</b>() </div> <div class="description"> Removes all the elements from the list. </div> <hr /> <a name=".contains"> </a> <div class="fixedFont">&lt;static&gt; <span class="light">{boolean}</span> <span class="light">buckets.LinkedList.</span><b>contains</b>(item, equalsFunction) </div> <div class="description"> Returns true if the list contains the specified element. <p>If the elements inside the list are not comparable with the === operator, a custom equals function should be provided to perform searches, that function must receive two arguments and return true if they are equal, false otherwise. Example:</p> <pre> var petsAreEqualByName = function(pet1, pet2) { return pet1.name === pet2.name; } </pre> </div> <dl class="detailList"> <dt class="heading">Parameters:</dt> <dt> <span class="light fixedFont">{Object}</span> <b>item</b> </dt> <dd>Element to search for.</dd> <dt> <span class="light fixedFont">{function(Object|Object):boolean=}</span> <b>equalsFunction</b> </dt> <dd>Optional function used to check if two elements are equal.</dd> </dl> <dl class="detailList"> <dt class="heading">Returns:</dt> <dd><span class="light fixedFont">{boolean}</span> True if the list contains the specified element, false otherwise.</dd> </dl> <hr /> <a name=".elementAtIndex"> </a> <div class="fixedFont">&lt;static&gt; <span class="light">{*}</span> <span class="light">buckets.LinkedList.</span><b>elementAtIndex</b>(index) </div> <div class="description"> Returns the element at the specified position in the list. </div> <dl class="detailList"> <dt class="heading">Parameters:</dt> <dt> <span class="light fixedFont">{number}</span> <b>index</b> </dt> <dd>Desired index.</dd> </dl> <dl class="detailList"> <dt class="heading">Returns:</dt> <dd><span class="light fixedFont">{*}</span> The element at the given index or undefined if the index is out of bounds.</dd> </dl> <hr /> <a name=".equals"> </a> <div class="fixedFont">&lt;static&gt; <span class="light">{boolean}</span> <span class="light">buckets.LinkedList.</span><b>equals</b>(other, equalsFunction) </div> <div class="description"> Returns true if the list is equal to another list. Two lists are equal if they have the same elements in the same order. </div> <dl class="detailList"> <dt class="heading">Parameters:</dt> <dt> <span class="light fixedFont">{<a href="../symbols/buckets.LinkedList.html">buckets.LinkedList</a>}</span> <b>other</b> </dt> <dd>The other list.</dd> <dt> <span class="light fixedFont">{function(Object|Object):boolean=}</span> <b>equalsFunction</b> </dt> <dd>Optional function to check if two elements are equal. If the elements in the lists are custom objects you should provide a custom equals function, otherwise the === operator is used to check equality between elements.</dd> </dl> <dl class="detailList"> <dt class="heading">Returns:</dt> <dd><span class="light fixedFont">{boolean}</span> true if the list is equal to the given list.</dd> </dl> <hr /> <a name=".first"> </a> <div class="fixedFont">&lt;static&gt; <span class="light">{*}</span> <span class="light">buckets.LinkedList.</span><b>first</b>() </div> <div class="description"> Returns the first element in the list. </div> <dl class="detailList"> <dt class="heading">Returns:</dt> <dd><span class="light fixedFont">{*}</span> The first element in the list or undefined if the list is empty.</dd> </dl> <hr /> <a name=".forEach"> </a> <div class="fixedFont">&lt;static&gt; <span class="light">buckets.LinkedList.</span><b>forEach</b>(callback) </div> <div class="description"> Executes the provided function once per element present in the list in order. </div> <dl class="detailList"> <dt class="heading">Parameters:</dt> <dt> <span class="light fixedFont">{function(Object):*}</span> <b>callback</b> </dt> <dd>Function to execute, it is invoked with one argument: the element value, to break the iteration you can optionally return false inside the callback.</dd> </dl> <hr /> <a name=".indexOf"> </a> <div class="fixedFont">&lt;static&gt; <span class="light">{number}</span> <span class="light">buckets.LinkedList.</span><b>indexOf</b>(item, equalsFunction) </div> <div class="description"> Returns the index of the first occurrence of the specified element, or -1 if the list does not contain the element. <p>If the elements inside the list are not comparable with the === operator, a custom equals function should be provided to perform searches, that function must receive two arguments and return true if they are equal, false otherwise. Example:</p> <pre> var petsAreEqualByName = function(pet1, pet2) { return pet1.name === pet2.name; } </pre> </div> <dl class="detailList"> <dt class="heading">Parameters:</dt> <dt> <span class="light fixedFont">{Object}</span> <b>item</b> </dt> <dd>Element to search for.</dd> <dt> <span class="light fixedFont">{function(Object|Object):boolean=}</span> <b>equalsFunction</b> </dt> <dd>Optional function used to check if two elements are equal.</dd> </dl> <dl class="detailList"> <dt class="heading">Returns:</dt> <dd><span class="light fixedFont">{number}</span> The index in the list of the first occurrence of the specified element, or -1 if the list does not contain the element.</dd> </dl> <hr /> <a name=".isEmpty"> </a> <div class="fixedFont">&lt;static&gt; <span class="light">{boolean}</span> <span class="light">buckets.LinkedList.</span><b>isEmpty</b>() </div> <div class="description"> Returns true if the list contains no elements. </div> <dl class="detailList"> <dt class="heading">Returns:</dt> <dd><span class="light fixedFont">{boolean}</span> true if the list contains no elements.</dd> </dl> <hr /> <a name=".last"> </a> <div class="fixedFont">&lt;static&gt; <span class="light">{*}</span> <span class="light">buckets.LinkedList.</span><b>last</b>() </div> <div class="description"> Returns the last element in the list. </div> <dl class="detailList"> <dt class="heading">Returns:</dt> <dd><span class="light fixedFont">{*}</span> The last element in the list or undefined if the list is empty.</dd> </dl> <hr /> <a name=".remove"> </a> <div class="fixedFont">&lt;static&gt; <span class="light">{boolean}</span> <span class="light">buckets.LinkedList.</span><b>remove</b>(item, equalsFunction) </div> <div class="description"> Removes the first occurrence of the specified element in the list. <p>If the elements inside the list are not comparable with the === operator, a custom equals function should be provided to perform searches, that function must receive two arguments and return true if they are equal, false otherwise. Example:</p> <pre> var petsAreEqualByName = function(pet1, pet2) { return pet1.name === pet2.name; } </pre> </div> <dl class="detailList"> <dt class="heading">Parameters:</dt> <dt> <span class="light fixedFont">{Object}</span> <b>item</b> </dt> <dd>Element to be removed from the list, if present.</dd> <dt> <b>equalsFunction</b> </dt> <dd></dd> </dl> <dl class="detailList"> <dt class="heading">Returns:</dt> <dd><span class="light fixedFont">{boolean}</span> True if the list contained the specified element.</dd> </dl> <hr /> <a name=".removeElementAtIndex"> </a> <div class="fixedFont">&lt;static&gt; <span class="light">{*}</span> <span class="light">buckets.LinkedList.</span><b>removeElementAtIndex</b>(index) </div> <div class="description"> Removes the element at the specified position in the list. </div> <dl class="detailList"> <dt class="heading">Parameters:</dt> <dt> <span class="light fixedFont">{number}</span> <b>index</b> </dt> <dd>Given index.</dd> </dl> <dl class="detailList"> <dt class="heading">Returns:</dt> <dd><span class="light fixedFont">{*}</span> Removed element or undefined if the index is out of bounds.</dd> </dl> <hr /> <a name=".reverse"> </a> <div class="fixedFont">&lt;static&gt; <span class="light">buckets.LinkedList.</span><b>reverse</b>() </div> <div class="description"> Reverses the order of the elements in the linked list (makes the last element first, and the first element last). </div> <hr /> <a name=".size"> </a> <div class="fixedFont">&lt;static&gt; <span class="light">{number}</span> <span class="light">buckets.LinkedList.</span><b>size</b>() </div> <div class="description"> Returns the number of elements in the list. </div> <dl class="detailList"> <dt class="heading">Returns:</dt> <dd><span class="light fixedFont">{number}</span> The number of elements in the list.</dd> </dl> <hr /> <a name=".toArray"> </a> <div class="fixedFont">&lt;static&gt; <span class="light">{Array.<*>}</span> <span class="light">buckets.LinkedList.</span><b>toArray</b>() </div> <div class="description"> Returns an array containing all the elements in the list in proper sequence. </div> <dl class="detailList"> <dt class="heading">Returns:</dt> <dd><span class="light fixedFont">{Array.<*>}</span> An array containing all the elements in the list, in proper sequence.</dd> </dl> <!-- ============================== event details ========================= --> <hr /> </div> </body> </html>