UNPKG

buckets-js

Version:

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

874 lines (537 loc) 20.9 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.MultiDictionary</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.MultiDictionary </h1> <!-- ============================== class summary ========================== --> <p class="description"> <p>A multi dictionary is a special kind of dictionary that holds multiple values against each key. Setting a value into the dictionary will add the value to a list at that key. Getting a key will return a list holding all the values associated with that key. This implementation accepts any kind of objects as keys.</p> <p>If the keys are custom objects, a function that converts keys to unique strings must be provided at construction time.</p> <p>Example:</p> <pre> function petToString(pet) { return pet.type + ' ' + pet.name; } </pre> <p>If the values are custom objects, a function to check equality between values must be provided.</p> <p>Example:</p> <pre> function petsAreEqualByAge(pet1,pet2) { return pet1.age===pet2.age; } </pre> </p> <!-- ============================== constructor summary ==================== --> <table class="summaryTable" cellspacing="0" summary="A summary of the constructor documented in the class buckets.MultiDictionary."> <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.MultiDictionary.html#constructor">buckets.MultiDictionary</a></b>(toStrFunction, valuesEqualsFunction) </div> <div class="description">Creates an empty multi dictionary.</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.MultiDictionary."> <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.MultiDictionary.<b><a href="../symbols/buckets.MultiDictionary.html#.clear">clear</a></b>() </div> <div class="description">Removes all keys and values from the dictionary.</div> </td> </tr> <tr> <td class="nameDescription"> <div class="fixedFont">buckets.MultiDictionary.<b><a href="../symbols/buckets.MultiDictionary.html#.containsKey">containsKey</a></b>(key) </div> <div class="description">Returns true if the dictionary has at least one value associatted with the specified key.</div> </td> </tr> <tr> <td class="nameDescription"> <div class="fixedFont">buckets.MultiDictionary.<b><a href="../symbols/buckets.MultiDictionary.html#.equals">equals</a></b>(other) </div> <div class="description">Returns true if the multi dictionary is equal to another multi dictionary.</div> </td> </tr> <tr> <td class="nameDescription"> <div class="fixedFont">buckets.MultiDictionary.<b><a href="../symbols/buckets.MultiDictionary.html#.forEach">forEach</a></b>(callback) </div> <div class="description">Executes the provided function once per key present in the multi dictionary.</div> </td> </tr> <tr> <td class="nameDescription"> <div class="fixedFont">buckets.MultiDictionary.<b><a href="../symbols/buckets.MultiDictionary.html#.get">get</a></b>(key) </div> <div class="description">Returns an array holding the values associated with the specified key.</div> </td> </tr> <tr> <td class="nameDescription"> <div class="fixedFont">buckets.MultiDictionary.<b><a href="../symbols/buckets.MultiDictionary.html#.isEmpty">isEmpty</a></b>() </div> <div class="description">Returns true if the dictionary contains no mappings.</div> </td> </tr> <tr> <td class="nameDescription"> <div class="fixedFont">buckets.MultiDictionary.<b><a href="../symbols/buckets.MultiDictionary.html#.keys">keys</a></b>() </div> <div class="description">Returns an array containing all the keys in the dictionary.</div> </td> </tr> <tr> <td class="nameDescription"> <div class="fixedFont">buckets.MultiDictionary.<b><a href="../symbols/buckets.MultiDictionary.html#.remove">remove</a></b>(key, value) </div> <div class="description">Removes the specified value from the list of values associated with the provided key.</div> </td> </tr> <tr> <td class="nameDescription"> <div class="fixedFont">buckets.MultiDictionary.<b><a href="../symbols/buckets.MultiDictionary.html#.set">set</a></b>(key, value) </div> <div class="description">Associates the specified value with the specified key if it's not already present.</div> </td> </tr> <tr> <td class="nameDescription"> <div class="fixedFont">buckets.MultiDictionary.<b><a href="../symbols/buckets.MultiDictionary.html#.size">size</a></b>() </div> <div class="description">Returns the number of keys in the dictionary.</div> </td> </tr> <tr> <td class="nameDescription"> <div class="fixedFont">buckets.MultiDictionary.<b><a href="../symbols/buckets.MultiDictionary.html#.values">values</a></b>() </div> <div class="description">Returns an array containing all the values in the dictionary.</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.MultiDictionary</b>(toStrFunction, valuesEqualsFunction) </div> <div class="description"> Creates an empty multi dictionary. </div> <dl class="detailList"> <dt class="heading">Parameters:</dt> <dt> <span class="light fixedFont">{function(Object):string=}</span> <b>toStrFunction</b> </dt> <dd>optional function to convert keys to strings. If the keys aren't strings or if toString() is not appropriate, a custom function which receives a key and returns a unique string must be provided.</dd> <dt> <span class="light fixedFont">{function(Object|Object):boolean=}</span> <b>valuesEqualsFunction</b> </dt> <dd>optional function to check if two values are equal.</dd> </dl> </div> <!-- ============================== field details ========================== --> <!-- ============================== method details ========================= --> <div class="sectionTitle"> Method Detail </div> <a name=".clear"> </a> <div class="fixedFont">&lt;static&gt; <span class="light">buckets.MultiDictionary.</span><b>clear</b>() </div> <div class="description"> Removes all keys and values from the dictionary. </div> <hr /> <a name=".containsKey"> </a> <div class="fixedFont">&lt;static&gt; <span class="light">{boolean}</span> <span class="light">buckets.MultiDictionary.</span><b>containsKey</b>(key) </div> <div class="description"> Returns true if the dictionary has at least one value associatted with the specified key. </div> <dl class="detailList"> <dt class="heading">Parameters:</dt> <dt> <span class="light fixedFont">{Object}</span> <b>key</b> </dt> <dd>The key.</dd> </dl> <dl class="detailList"> <dt class="heading">Returns:</dt> <dd><span class="light fixedFont">{boolean}</span> True if the dictionary has at least one value associatted the specified key.</dd> </dl> <hr /> <a name=".equals"> </a> <div class="fixedFont">&lt;static&gt; <span class="light">{boolean}</span> <span class="light">buckets.MultiDictionary.</span><b>equals</b>(other) </div> <div class="description"> Returns true if the multi dictionary is equal to another multi dictionary. Two dictionaries are equal if they have the same keys and the same values per key. </div> <dl class="detailList"> <dt class="heading">Parameters:</dt> <dt> <span class="light fixedFont">{<a href="../symbols/buckets.MultiDictionary.html">buckets.MultiDictionary</a>}</span> <b>other</b> </dt> <dd>The other dictionary.</dd> </dl> <dl class="detailList"> <dt class="heading">Returns:</dt> <dd><span class="light fixedFont">{boolean}</span> True if the dictionary is equal to the given dictionary.</dd> </dl> <hr /> <a name=".forEach"> </a> <div class="fixedFont">&lt;static&gt; <span class="light">buckets.MultiDictionary.</span><b>forEach</b>(callback) </div> <div class="description"> Executes the provided function once per key present in the multi dictionary. </div> <dl class="detailList"> <dt class="heading">Parameters:</dt> <dt> <span class="light fixedFont">{function(Object|Array):*}</span> <b>callback</b> </dt> <dd>Function to execute. Receives 2 arguments: key and an array of values. To break the iteration you can optionally return false inside the callback.</dd> </dl> <hr /> <a name=".get"> </a> <div class="fixedFont">&lt;static&gt; <span class="light">{Array}</span> <span class="light">buckets.MultiDictionary.</span><b>get</b>(key) </div> <div class="description"> Returns an array holding the values associated with the specified key. </div> <dl class="detailList"> <dt class="heading">Parameters:</dt> <dt> <span class="light fixedFont">{Object}</span> <b>key</b> </dt> <dd>The key.</dd> </dl> <dl class="detailList"> <dt class="heading">Returns:</dt> <dd><span class="light fixedFont">{Array}</span> An array holding the values or an empty array if the dictionary contains no mappings for the provided key.</dd> </dl> <hr /> <a name=".isEmpty"> </a> <div class="fixedFont">&lt;static&gt; <span class="light">{boolean}</span> <span class="light">buckets.MultiDictionary.</span><b>isEmpty</b>() </div> <div class="description"> Returns true if the dictionary contains no mappings. </div> <dl class="detailList"> <dt class="heading">Returns:</dt> <dd><span class="light fixedFont">{boolean}</span> True if the dictionary contains no mappings.</dd> </dl> <hr /> <a name=".keys"> </a> <div class="fixedFont">&lt;static&gt; <span class="light">{Array}</span> <span class="light">buckets.MultiDictionary.</span><b>keys</b>() </div> <div class="description"> Returns an array containing all the keys in the dictionary. </div> <dl class="detailList"> <dt class="heading">Returns:</dt> <dd><span class="light fixedFont">{Array}</span> An array containing all the keys in the dictionary.</dd> </dl> <hr /> <a name=".remove"> </a> <div class="fixedFont">&lt;static&gt; <span class="light">{*}</span> <span class="light">buckets.MultiDictionary.</span><b>remove</b>(key, value) </div> <div class="description"> Removes the specified value from the list of values associated with the provided key. If a value isn't given, all values associated with the specified key are removed. </div> <dl class="detailList"> <dt class="heading">Parameters:</dt> <dt> <span class="light fixedFont">{Object}</span> <b>key</b> </dt> <dd>The key.</dd> <dt> <span class="light fixedFont">{Object=}</span> <b>value</b> </dt> <dd>Optional argument to specify the element to remove from the list of values associated with the given key.</dd> </dl> <dl class="detailList"> <dt class="heading">Returns:</dt> <dd><span class="light fixedFont">{*}</span> True if the dictionary changed, false if the key doesn't exist or if the specified value isn't associated with the given key.</dd> </dl> <hr /> <a name=".set"> </a> <div class="fixedFont">&lt;static&gt; <span class="light">{boolean}</span> <span class="light">buckets.MultiDictionary.</span><b>set</b>(key, value) </div> <div class="description"> Associates the specified value with the specified key if it's not already present. </div> <dl class="detailList"> <dt class="heading">Parameters:</dt> <dt> <span class="light fixedFont">{Object}</span> <b>key</b> </dt> <dd>The Key.</dd> <dt> <span class="light fixedFont">{Object}</span> <b>value</b> </dt> <dd>The value to associate.</dd> </dl> <dl class="detailList"> <dt class="heading">Returns:</dt> <dd><span class="light fixedFont">{boolean}</span> True if the value was not already associated with that key.</dd> </dl> <hr /> <a name=".size"> </a> <div class="fixedFont">&lt;static&gt; <span class="light">{number}</span> <span class="light">buckets.MultiDictionary.</span><b>size</b>() </div> <div class="description"> Returns the number of keys in the dictionary. </div> <dl class="detailList"> <dt class="heading">Returns:</dt> <dd><span class="light fixedFont">{number}</span> The number of keys in the dictionary.</dd> </dl> <hr /> <a name=".values"> </a> <div class="fixedFont">&lt;static&gt; <span class="light">{Array}</span> <span class="light">buckets.MultiDictionary.</span><b>values</b>() </div> <div class="description"> Returns an array containing all the values in the dictionary. </div> <dl class="detailList"> <dt class="heading">Returns:</dt> <dd><span class="light fixedFont">{Array}</span> An array containing all the values in the dictionary.</dd> </dl> <!-- ============================== event details ========================= --> <hr /> </div> </body> </html>