diff --git a/.gitignore b/.gitignore deleted file mode 100644 index 0053193..0000000 --- a/.gitignore +++ /dev/null @@ -1,222 +0,0 @@ -################# -## IntelliJIdea -################# - -.idea - -################# -## Eclipse -################# - -*.pydevproject -.project -.metadata -bin/ -tmp/ -*.tmp -*.bak -*.swp -*~.nib -local.properties -.classpath -.settings/ -.loadpath - -# External tool builders -.externalToolBuilders/ - -# Locally stored "Eclipse launch configurations" -*.launch - -# CDT-specific -.cproject - -# PDT-specific -.buildpath - - -################# -## Visual Studio -################# - -## Ignore Visual Studio temporary files, build results, and -## files generated by popular Visual Studio add-ons. - -# User-specific files -*.suo -*.user -*.sln.docstates - -# Build results - -[Dd]ebug/ -[Rr]elease/ -x64/ -build/ -[Bb]in/ -[Oo]bj/ - -# MSTest test Results -[Tt]est[Rr]esult*/ -[Bb]uild[Ll]og.* - -*_i.c -*_p.c -*.ilk -*.meta -*.obj -*.pch -*.pdb -*.pgc -*.pgd -*.rsp -*.sbr -*.tlb -*.tli -*.tlh -*.tmp -*.tmp_proj -*.log -*.vspscc -*.vssscc -.builds -*.pidb -*.log -*.scc - -# Visual C++ cache files -ipch/ -*.aps -*.ncb -*.opensdf -*.sdf -*.cachefile - -# Visual Studio profiler -*.psess -*.vsp -*.vspx - -# Guidance Automation Toolkit -*.gpState - -# ReSharper is a .NET coding add-in -_ReSharper*/ -*.[Rr]e[Ss]harper - -# TeamCity is a build add-in -_TeamCity* - -# DotCover is a Code Coverage Tool -*.dotCover - -# NCrunch -*.ncrunch* -.*crunch*.local.xml - -# Installshield output folder -[Ee]xpress/ - -# DocProject is a documentation generator add-in -DocProject/buildhelp/ -DocProject/Help/*.HxT -DocProject/Help/*.HxC -DocProject/Help/*.hhc -DocProject/Help/*.hhk -DocProject/Help/*.hhp -DocProject/Help/Html2 -DocProject/Help/html - -# Click-Once directory -publish/ - -# Publish Web Output -*.Publish.xml -*.pubxml -*.publishproj - -# NuGet Packages Directory -## TODO: If you have NuGet Package Restore enabled, uncomment the next line -#packages/ - -# Windows Azure Build Output -csx -*.build.csdef - -# Windows Store app package directory -AppPackages/ - -# Others -sql/ -*.Cache -ClientBin/ -[Ss]tyle[Cc]op.* -~$* -*~ -*.dbmdl -*.[Pp]ublish.xml -*.pfx -*.publishsettings - -# RIA/Silverlight projects -Generated_Code/ - -# Backup & report files from converting an old project file to a newer -# Visual Studio version. Backup files are not needed, because we have git ;-) -_UpgradeReport_Files/ -Backup*/ -UpgradeLog*.XML -UpgradeLog*.htm - -# SQL Server files -App_Data/*.mdf -App_Data/*.ldf - -############# -## Windows detritus -############# - -# Windows image file caches -Thumbs.db -ehthumbs.db - -# Folder config file -Desktop.ini - -# Recycle Bin used on file shares -$RECYCLE.BIN/ - -# Mac crap -.DS_Store - - -############# -## Python -############# - -*.py[cod] - -# Packages -*.egg -*.egg-info -dist/ -build/ -eggs/ -parts/ -var/ -sdist/ -develop-eggs/ -.installed.cfg - -# Installer logs -pip-log.txt - -# Unit test / coverage reports -.coverage -.tox - -#Translations -*.mo - -#Mr Developer -.mr.developer.cfg diff --git a/.gitignore_global b/.gitignore_global deleted file mode 100644 index 723ef36..0000000 --- a/.gitignore_global +++ /dev/null @@ -1 +0,0 @@ -.idea \ No newline at end of file diff --git a/DataStructures.js b/DataStructures.js deleted file mode 100644 index 01cd4a8..0000000 --- a/DataStructures.js +++ /dev/null @@ -1,5449 +0,0 @@ -/** - * Interface for managing a generic data structure. - * @constructor - * @interface - */ -function Aggregate() { - -} - -/** - * Returns the iterator relative to the aggregate. - * @abstract - * @return {Iterator} The iterator. - */ -Aggregate.prototype.getIterator = function () { -}; - -/** - * Interface for managing an iterator for an aggregate. - * @constructor - * @interface - */ -function Iterator() { - -} - -/** - * Moves the iterator to the first position of the aggregate. - * @abstract - * @return {void} - */ -Iterator.prototype.first = function () { - -}; - -/** - * Moves the iterator to the next item. - * @abstract - * @return {void} - */ -Iterator.prototype.next = function () { - -}; - -/** - * Moves the iterator to the last position of the aggregate. - * @abstract - * @return {void} - */ -Iterator.prototype.last = function () { - -}; - -/** - * Moves the iterator to the previous item. - * @abstract - * @return {void} - */ -Iterator.prototype.previous = function () { - -}; - -/** - * Checks if the iterator is out of the bounds of the aggregate. - * @abstract - * @return {boolean} It return true if the iterator is out of the bounds of the aggregate, otherwise false. - */ -Iterator.prototype.isDone = function () { - -}; - -/** - * Returns the item stored at the position pointed by the iterator. - * @abstract - * @return {*} The item stored or undefined if it's out of the bounds. - */ -Iterator.prototype.getItem = function () { - -}; - -/** - * Class for managing a binary search tree. - * @constructor - */ -function BSTree() { - /** - * The root of the tree. - * @type {BSNode|null} - */ - this.root = null; -} - -/** - * Returns the iterator relative to the aggregate. - * @return {Iterator} The iterator. - */ -BSTree.prototype.getIterator = function () { - return new BSTreeIterator(this); -}; - -/** - * Inserts the item relatives to the key value in the tree. - * @param key {number} The key to store. - * @param item {*} The item to store. - * @return {void} - */ -BSTree.prototype.insert = function (key, item) { - var node = new BSNode(key, item); - var p = this.root; - for (var n = this.root; n;) { - p = n; - if (key < n.key) - n = n.left; - else - n = n.right; - } - node.parent = p; - if (!p) - this.root = node; - else if (key < p.key) - p.left = node; - else - p.right = node; -}; - -/** - * Searches the item relatives to the key. - * @param key {Number} The key to find. - * @param [node = root] {BSNode} The node from which start the search. - * @return {*} The item found or undefined if there isn't the key in the tree. - */ -BSTree.prototype.search = function (key, node) { - node = node || this.root; - while (node && key !== node.key) - if (key < node.key) - node = node.left; - else - node = node.right; - if (node) - return node.item; - return undefined; -}; - -/** - * Gets the item relatives to the minimum key stored in the tree. - * @param [node = root] {Node} The node from which start the search. - * @return {BSNode} The node found. - */ -BSTree.prototype.minimum = function (node) { - node = node || this.root; - while (node && node.left) - node = node.left; - return node; -}; - -/** - * Gets the item relatives to the maximum key stored in the tree. - * @param [node = root] {Node} The node from which start the search. - * @return {BSNode} The node found. - */ -BSTree.prototype.maximum = function (node) { - node = node || this.root; - while (node && node.right) - node = node.right; - return node; -}; - -/** - * Gets the node with the key next to the param node key. - * @param node {BSNode} The node of which search the successor. - * @return {BSNode} The node found. - */ -BSTree.prototype.successor = function (node) { - if (node.right) - return this.minimum(node.right); - var parent = node.parent; - while (parent && node === parent.right) { - node = parent; - parent = parent.parent; - } - return parent; -}; - -/** - * Gets the node with the key previous to the param node key. - * @param node {BSNode} The node of which search the predecessor. - * @return {BSNode} The node found. - */ -BSTree.prototype.predecessor = function (node) { - if (node.left) - return this.maximum(node.left); - var parent = node.parent; - while (parent && node === parent.left) { - node = parent; - parent = parent.parent; - } - return parent; -}; - -/** - * Deletes the node from the tree. - * @param node {BSNode} The node to delete. - * @return {void} - */ -BSTree.prototype.deleteNode = function (node) { - if (!node.left && !node.right) { - if (node === this.root) - this.root = null; - else if (node.parent.left === node) - node.parent.left = null; - else - node.parent.right = null; - } else if (node.left && node.right) { - var next = this.successor(node); - node.key = next.key; - node.item = next.item; - if (next.parent.left === next) - next.parent.left = null; - else - next.parent.right = null; - } else { - if (node.right) { - if (node === this.root) { - this.root = node.right; - node.right.parent = null; - } else { - node.parent.right = node.right; - node.right.parent = node.parent; - } - } else { - if (node === this.root) { - this.root = node.left; - node.left.parent = null; - } else { - node.parent.left = node.left; - node.left.parent = node.parent; - } - } - } -}; - -/** - * Class that implements the iterator for a binary search tree. - * @param aggregate {BSTree} The aggregate to scan. - * @constructor - */ -function BSTreeIterator(aggregate) { - /** - * The aggregate relates to this iterator. - * @type {BSTree} - */ - this.aggregate = aggregate; - - /** - * The pointer to the position. - * @type {BSNode|null} - */ - this.pointer = null; -} - -/** - * Moves the iterator to the first position of the aggregate. - * @return {void} - */ -BSTreeIterator.prototype.first = function () { - this.pointer = this.aggregate.minimum(); -}; - -/** - * Moves the iterator to the next item. - * @return {void} - */ -BSTreeIterator.prototype.next = function () { - this.pointer = this.aggregate.successor(this.pointer); -}; - -/** - * Moves the iterator to the last position of the aggregate. - * @return {void} - */ -BSTreeIterator.prototype.last = function () { - this.pointer = this.aggregate.maximum(); -}; - -/** - * Moves the iterator to the previous item. - * @return {void} - */ -BSTreeIterator.prototype.previous = function () { - this.pointer = this.aggregate.predecessor(this.pointer); -}; - -/** - * Checks if the iterator is out of the bounds of the aggregate. - * @return {boolean} It return true if the iterator is out of the bounds of the aggregate, otherwise false. - */ -BSTreeIterator.prototype.isDone = function () { - return !this.pointer; -}; - -/** - * Returns the item stored at the position pointed by the iterator. - * @return {*} The item stored or undefined if it's out of the bounds. - */ -BSTreeIterator.prototype.getItem = function () { - return this.pointer.item; -}; - -/** - * Returns the node stored at the position pointed by the iterator. - * @return {BSNode|null} The node stored or null if it's out of the bounds. - */ -BSTreeIterator.prototype.getNode = function () { - return this.pointer; -}; - -/** - * Class for managing a B-Tree. - * @param minimumDegree {number} The minimum number of keys of a node. - * @constructor - */ -function BTree(minimumDegree) { - /** - * The root of the tree. - * @type {BNode} - */ - this.root = new BNode(); - - /** - * The minimum number of the keys of a node. - * @type {number} - */ - this.t = minimumDegree; - - /** - * The number of items stored in the tree. - * @type {number} - */ - this.size = 0; -} - -/** - * Returns the iterator relative to the aggregate. - * @return {Iterator} The iterator. - */ -BTree.prototype.getIterator = function () { - return new BTreeIterator(this); -}; - -/** - * Inserts the item relatives to the key value in the tree. - * @param key {number} The key to store. - * @param item {*} The item to store. - * @return {void} - */ -BTree.prototype.insert = function (key, item) { - var node = this.root; - if (node.keys.length === 2 * this.t - 1) { - var newNode = new BNode(); - newNode.childs.push(node); - this.root = newNode; - this.splitChild(newNode, 0); - node = newNode; - } - this.size++; - this.insertNonFull(node, key, item); -}; - -/** - * Inserts the new node in the right position if the node is not full. - * @param node {BNode} The node from which start to check the insertion. - * @param key {number} The key to store. - * @param item {*} The item to store. - * @return {void} - */ -BTree.prototype.insertNonFull = function (node, key, item) { - while (node) { - var i = node.keys.length - 1; - if (!node.childs.length) { - for (; i > -1 && key < node.keys[i]; i--) { - node.keys[i + 1] = node.keys[i]; - node.items[i + 1] = node.items[i]; - } - node.keys[i + 1] = key; - node.items[i + 1] = item; - return; - } else { - var j = 0; - i++; - while (j < i) { - var m = Math.floor((j + i) / 2); - if (key <= node.keys[m]) - i = m; - else - j = m + 1; - } - if (node.childs[j].keys.length === 2 * this.t - 1) { - this.splitChild(node, j); - if (key > node.keys[j]) - j++; - } - node = node.childs[j]; - } - } -}; - -/** - * Searches the item relatives to the key that satisfy the condition represented by the callback function. - * @param key {Number} The key to find. - * @param [node = root] {RBNode} The node from which start the search. - * @param [callback = function(node,index){return(node.keys[index]===key);}] The condition to satisfy. The callback must accept the current node to check and optionally the position of the key. - * @return {*} The item found or undefined if there isn't the key in the tree. - */ -BTree.prototype.search = function (key, node, callback) { - node = node || this.root; - callback = callback || function (node, index) { - return node.keys[index] === key; - }; - while (node) { - var n = node.keys.length; - var i = 0, j = n; - while (i < j) { - var m = Math.floor((i + j) / 2); - if (key <= node.keys[m]) - j = m; - else - i = m + 1; - } - if (i < n && callback(node, i)) - return node.items[i]; - else if (!node.childs.length) - return undefined; - else - node = node.childs[i]; - } -}; - -/** - * Splits the child of the node at the position index. - * @param node {BNode} The parent of the child to split. - * @param index {number} The position of the child to split. - * @return {void} - */ -BTree.prototype.splitChild = function (node, index) { - var newNode = new BNode(); - var child = node.childs[index]; - //copy of the last t - 1 keys and items in the new node - for (var i = 0; i < this.t - 1; i++) { - newNode.keys[i] = child.keys[i + this.t]; - newNode.items[i] = child.items[i + this.t]; - } - if (child.childs.length) - //copy of the last t child in the new node - for (var j = 0; j < this.t; j++) - newNode.childs[j] = child.childs[j + this.t]; - //shift the children from index + 1 position - for (var l = node.keys.length; l > index; l--) - node.childs[l + 1] = node.childs[l]; - //set the index position as the position t of the child - node.childs[index + 1] = newNode; - //shift the keys and the items from index position - for (var k = node.keys.length - 1; k > index - 1; k--) { - node.keys[k + 1] = node.keys[k]; - node.items[k + 1] = node.items[k]; - } - node.keys[index] = child.keys[this.t - 1]; - node.items[index] = child.items[this.t - 1]; - //remove keys, items and child in the old node. - child.keys.splice(child.keys.length - this.t); - child.items.splice(child.items.length - this.t); - child.childs.splice(child.childs.length - this.t); -}; - -/** - * Deletes the key from the tree. - * @param key {*} The key to delete. - * @return {void} - */ -BTree.prototype.deleteKey = function (key) { - if (this.root.keys.length) { - this.deleteNonMin(this.root, key); - if (!this.root.keys.length && this.root.childs.length) - this.root = this.root.childs[0]; - this.size--; - } -}; - -/** - * Deletes a node that's a number of keys greater than the minimum for a node. - * @param node {BNode} The node to delete. - * @param key {number} The key to delete. - * @return {void} - */ -BTree.prototype.deleteNonMin = function (node, key) { - var i = 0, j = node.keys.length; - while (i < j) { - var m = Math.floor((i + j) / 2); - if (key <= node.keys[m]) - j = m; - else - i = m + 1; - } - //key is in the node - if (i < node.keys.length && key === node.keys[i]) { - //the node is a leaf - if (!node.childs.length) { - //remove the key - for (j = i + 1; j < node.keys.length; j++) { - node.keys[j - 1] = node.keys[j]; - node.items[j - 1] = node.items[j]; - } - node.keys.pop(); - node.items.pop(); - } else { - //the node is not a leaf - //the node has the minimum number of keys - if (node.childs[i].length === this.t - 1) { - //increase the number of the keys of the node - this.augmentChild(node, i); - if (i === node.keys.length + 1) - i--; - } - //check if the key is moved in the child - if (node.keys[i] !== key) - this.deleteNonMin(node.childs[i], key); - else - this.deleteMax(node, i); - } - //the key is not in the node - } else { - //check if the child i has the minimum number of keys - if (node.childs[i].keys.length === this.t - 1) { - this.augmentChild(node, i); - if (i === node.keys.length + 2) - i--; - } - this.deleteNonMin(node.childs[i], key); - } -}; - -/** - * Deletes a node that have the maximum number of keys for node. - * @param node {BNode} The node to delete. - * @param index {number} The key to delete in the node. - * @return {void} - */ -BTree.prototype.deleteMax = function (node, index) { - var child = node.childs[index]; - var goAhead = true; - while (goAhead) { - if (!child.childs.length) { - node.keys[index] = child.keys[child.keys.length - 1]; - node.items[index] = child.items[child.items.length - 1]; - child.keys.pop(); - child.items.pop(); - goAhead = false; - } else { - var last = child.childs[child.keys.length]; - if (last.keys.length === this.t - 1) - this.augmentChild(child, child.keys.length); - child = child.childs[child.keys.length]; - } - } -}; - -/** - * Augments the number of keys stored in the node preserving the order. - * @param node {BNode} The node to delete. - * @param index {number} The index of the position to augment. - * @return {void} - */ -BTree.prototype.augmentChild = function (node, index) { - var child = node.childs[index]; - var brother; - if (index) - brother = node.childs[index - 1]; - if (index && brother.keys.length > this.t - 1) { - if (child.childs.length) { - for (var j = this.keys.length + 1; j > 0; j--) - child.childs[j] = child.childs[j - 1]; - child.childs[0] = brother.childs[brother.keys.length]; - for (var i = child.keys.length; i > 0; i--) { - child.keys[i] = child.keys[i - 1]; - child.items[i] = child.items[i - 1]; - } - child.keys[0] = node.keys[index - 1]; - child.items[0] = node.items[index - 1]; - node.keys[index - 1] = brother.keys[brother.keys.length - 1]; - node.items[index - 1] = brother.items[brother.items.length - 1]; - } - } else { - if (index < node.keys.length) - brother = node.childs[index + 1]; - if (index < node.keys.length && brother.keys.length > this.t - 1) { - if (brother.childs.length) { - child.childs[child.keys.length + 1] = brother.childs[0]; - for (var l = 1; l < brother.keys.length + 1; l++) - brother.childs[l - 1] = brother.childs[l]; - brother.childs.pop(); - } - child.keys[child.keys.length] = node.keys[index]; - child.items[child.items.length] = node.items[index]; - node.keys[index] = brother.keys[0]; - node.items[index] = brother.items[0]; - for (var k = 1; k < brother.keys.length; k++) { - brother.keys[k - 1] = brother.keys[k]; - brother.items[k - 1] = brother.items[k]; - } - brother.keys.pop(); - brother.items.pop(); - } else { - if (index < node.keys.length) { - child.keys[this.t - 1] = node.keys[index]; - child.items[this.t - 1] = node.items[index]; - for (var m = index + 2; m < node.keys.length + 1; m++) - node.childs[m - 1] = node.childs[m]; - node.childs.pop(); - for (var n = index + 1; n < node.keys.length; n++) { - node.keys[n - 1] = node.keys[n]; - node.items[n - 1] = node.items[n]; - } - node.keys.pop(); - node.items.pop(); - if (brother.childs.length) - for (var y = 0; y < brother.keys.length + 1; y++) - child.childs[this.t + y] = brother.childs[y]; - for (var x = 0; x < brother.keys.length; x++) { - child.keys[x + this.t] = brother.keys[x]; - child.items[x + this.t] = brother.items[x]; - } - } else { - if (brother.childs.length) - for (var w = 0; w < child.keys.length + 1; w++) - brother.childs[this.t + w] = child.childs[w]; - brother.keys[this.t - 1] = node.keys[node.keys.length - 1]; - brother.items[this.t - 1] = node.items[node.keys.length - 1]; - for (var z = 0; z < child.keys.length; z++) { - brother.keys[z + this.t] = child.keys[z]; - brother.items[z + this.t] = child.items[z]; - } - } - } - } -}; - -/** - * Checks if the tree contains the key. - * @param key {number} The key to find. - * @param [callback = function(node,index){return(node.keys[index]===key);}] The condition to satisfy. The callback must accept the current node to check and optionally the position of the key. - * @return {boolean} True if the tree contains the key. - */ -BTree.prototype.contains = function (key, callback) { - return this.search(key, null, callback) !== undefined; -}; - -/** - * Checks if the tree contains a node that satisfy the condition represented by the callback function. - * This method check all the tree avoiding the binary search. - * @param callback {function} The condition to satisfy. The callback must accept the current node to check. - * @return {boolean} True if the tree contains the node that satisfy the condition, false otherwise. - */ -BTree.prototype.fullContains = function (callback) { - var key = this.minimumKey(); - while (key !== null && !callback(this.search(key))) - key = this.successor(key); - return key !== null; -}; - -/** - * Gets the key next to the param node key. - * @param key {number} The key of which search the successor. - * @param [node = root] The node from start the search of the successor. - * @return {number} The key found. - */ -BTree.prototype.successor = function (key, node) { - node = node || this.root; - var i = 0, j = node.keys.length; - //search the key in the node - while (i < j) { - var m = Math.floor((i + j) / 2); - if (key <= node.keys[m]) - j = m; - else - i = m + 1; - } - //check if the key has been found - if (node.keys[i] === key) - //in this case the successor is the next key - i++; - //if it's a leaf - if (!node.childs.length) { - //check if the key hasn't been found - if (i > node.keys.length - 1) - return null; - else - return node.keys[i]; - } - //if it's not a leaf check if the successor is in the i-child - var successor = this.successor(key, node.childs[i]); - //if it's not in the child and has been found a key then return it - if (successor === null && i < node.keys.length) - return node.keys[i]; - //return the value of the successor even if it's null - return successor; -}; - -/** - * Gets the key previous to the param key. - * @param key {number} The key of which search the predecessor. - * @param [node = root] The node from start the search of the predecessor. - * @return {number} The key found. - */ -BTree.prototype.predecessor = function (key, node) { - node = node || this.root; - var i = 0, j = node.keys.length; - //search the key in the node - while (i < j) { - var m = Math.floor((i + j) / 2); - if (key <= node.keys[m]) - j = m; - else - i = m + 1; - } - i--; - //check if the node is a leaf - if (!node.childs.length) { - //check if a predecessor has been found - if (i < 0) - return null; - else - return node.keys[i]; - } - var predecessor = this.predecessor(key, node.childs[i + 1]); - if (predecessor === null && key > node.keys[0]) { - return node.keys[i]; - } - return predecessor; -}; - -/** - * Gets the minimum key stored in the tree. - * @return {number} The key found. - */ -BTree.prototype.minimumKey = function () { - var node = this.root; - while (node.childs.length) - node = node.childs[0]; - if (node) - return node.keys[0]; - return null; -}; - -/** - * Gets the maximum key stored in the tree. - * @return {number} The key found. - */ -BTree.prototype.maximumKey = function () { - var node = this.root; - while (node.childs.length) - node = node.childs[node.childs.length - 1]; - if (node) - return node.keys[node.keys.length - 1]; - return null; -}; - -/** - * Gets the item relatives to the minimum key stored in the tree. - * @return {number} The item found. - */ -BTree.prototype.minimum = function () { - var node = this.root; - while (node.childs.length) - node = node.childs[0]; - return node.items[0]; -}; - -/** - * Gets the item relatives to the maximum key stored in the tree. - * @return {node} The item found. - */ -BTree.prototype.maximum = function () { - var node = this.root; - while (node.childs.length) - node = node.childs[node.childs.length - 1]; - return node.items[node.items.length - 1]; -}; - -/** - * Returns the size of the tree. - * @return {number} The size of the tree. - */ -BTree.prototype.getSize = function () { - return this.size; -}; - -/** - * Checks if the tree is empty. - * @return {boolean} True if the tree is empty, false otherwise. - */ -BTree.prototype.isEmpty = function () { - return !this.size; -}; - -/** - * Executes the callback function for each item of the tree. - * This method modifies the tree so if you don't need to modify it you must return the same item of the array. - * @param callback {function} The function to execute for each item. The function must accept the current item on which execute the function. - * @return {void} - */ -BTree.prototype.execute = function (callback) { - var node = arguments[1] || this.root; - for (var i = 0; i < node.items.length; i++) - node.items[i] = callback(node.items[i]); - for (var j = 0; j < node.childs.length; j++) - this.execute(callback, node.childs[j]); -}; - -/** - * Removes all the items stored in the tree. - * @return {void} - */ -BTree.prototype.clear = function () { - this.root = null; - this.size = 0; -}; - -/** - * Returns the items that satisfy the condition determined by the callback. - * @param callback {function} The function that implements the condition. - * @return {Array<*>} The array that contains the items that satisfy the condition. - */ -BTree.prototype.filter = function (callback) { - var result = []; - var node = arguments[1] || this.root; - for (var i = 0; i < node.items.length; i++) { - if (node.childs.length) - result = result.concat(this.filter(callback, node.childs[i])); - if (callback(node.items[i])) - result.push(node.items[i]); - } - if (node.childs.length) - result = result.concat(this.filter(callback, node.childs[node.childs.length - 1])); - return result; -}; - -/** - * Clones the tree into a new tree. - * @return {BTree} The tree cloned from this tree. - */ -BTree.prototype.clone = function () { - var tree = new BTree(this.t); - var it = this.getIterator(); - for (it.first(); !it.isDone(); it.next()) { - var item = it.getItem(); - if (item.clone) - item = item.clone(); - tree.insert(it.getKey(), item); - } - return tree; -}; - -/** - * Clones the tree into a new tree without cloning duplicated items. - * @return {BTree} The tree cloned from this tree. - */ -BTree.prototype.cloneDistinct = function () { - var tree = new BTree(this.t); - var it = this.getIterator(); - for (it.first(); !it.isDone(); it.next()) { - var callback = function (item) { - return item === it.getItem(); - }; - if (!tree.fullContains(callback)) { - if (it.getItem().cloneDistinct) - tree.insert(it.getKey(), it.getItem().cloneDistinct()); - else if (it.getItem().clone) - tree.insert(it.getKey(), it.getItem().clone()); - else - tree.insert(it.getKey(), it.getItem()); - } - } - return tree; -}; - -/** - * Transforms the tree into an array without preserving keys. - * @return {Array<*>} The array that represents the tree. - */ -BTree.prototype.toArray = function () { - var result = []; - var it = this.getIterator(); - for (it.first(); !it.isDone(); it.next()) - result.push(it.getItem()); - return result; -}; - -/** - * Returns the first position of the item in the tree. - * @param item {*} The item to search. - * @param [callback = function(item){return(it===item);}] The condition to satisfy. The callback must accept the current item to check. - * @return {number} The first position of the item. - */ -BTree.prototype.indexOf = function (item, callback) { - callback = callback || function (it) { - return it === item; - }; - var i = 0, key = this.minimumKey(); - while (key !== null) { - if (callback(this.search(key))) - return i; - key = this.successor(key); - i++; - } - return -1; -}; - -/** - * Returns the last position of the item in the tree. - * @param item {*} The item to search. - * @param [callback = function(item){return(it===item);}] The condition to satisfy. The callback must accept the current item to check. - * @return {number} The last position of the item. - */ -BTree.prototype.lastIndexOf = function (item, callback) { - callback = callback || function (it) { - return it === item; - }; - var i = this.size - 1, key = this.maximumKey(); - while (key !== null) { - if (callback(this.search(key))) - return i; - i--; - key = this.predecessor(key); - } - return -1; -}; - -/** - * Returns all the position in which the item has been found in the tree. - * @param item {*} The item to search. - * @param [callback = function(item){return(it===item);}] The condition to satisfy. The callback must accept the current item to check. - * @return {Array} The positions in which the item has been found. - */ -BTree.prototype.allIndexesOf = function (item, callback) { - callback = callback || function (it) { - return it === item; - }; - var i = 0, key = this.minimumKey(); - var indexes = []; - while (key !== null) { - if (callback(this.search(key))) - indexes.push(i); - i++; - key = this.successor(key); - } - return indexes; -}; - -/** - * Returns the item at the position index. - * @param index {number} The position of the item. - * @return {*} The item at the position. It's undefined if index isn't in the tree bounds. - */ -BTree.prototype.getItem = function (index) { - if (index < 0 || index > this.size - 1) - return undefined; - var key = this.minimum(); - for (var i = 0; i < index; i++) - key = this.successor(key); - return this.search(key); -}; - -/** - * Class that implements the iterator for a binary search tree. - * @param aggregate {BTree} The aggregate to scan. - * @constructor - */ -function BTreeIterator(aggregate) { - /** - * The aggregate relates to this iterator. - * @type {BTree} - */ - this.aggregate = aggregate; - - /** - * The pointer to the position. - * @type {number} - */ - this.pointer = null; -} - -/** - * Moves the iterator to the first position of the aggregate. - * @return {void} - */ -BTreeIterator.prototype.first = function () { - this.pointer = this.aggregate.minimumKey(); -}; - -/** - * Moves the iterator to the next item. - * @return {void} - */ -BTreeIterator.prototype.next = function () { - this.pointer = this.aggregate.successor(this.pointer); -}; - -/** - * Moves the iterator to the last position of the aggregate. - * @return {void} - */ -BTreeIterator.prototype.last = function () { - this.pointer = this.aggregate.maximumKey(); -}; - -/** - * Moves the iterator to the previous item. - * @return {void} - */ -BTreeIterator.prototype.previous = function () { - this.pointer = this.aggregate.predecessor(this.pointer); -}; - -/** - * Checks if the iterator is out of the bounds of the aggregate. - * @return {boolean} It return true if the iterator is out of the bounds of the aggregate, otherwise false. - */ -BTreeIterator.prototype.isDone = function () { - return this.pointer === null; -}; - -/** - * Returns the item stored at the position pointed by the iterator. - * @return {*} The item stored or undefined if it's out of the bounds. - */ -BTreeIterator.prototype.getItem = function () { - return this.aggregate.search(this.pointer); -}; - -/** - * Returns the key stored at the position pointed by the iterator. - * @return {number} The key stored or null if it's out of the bounds. - */ -BTreeIterator.prototype.getKey = function () { - return this.pointer; -}; - -/** - * Class for managing a circular buffer. - * @param size {Number} The size of the buffer. - * @constructor - */ -function CircularBuffer(size) { - /** - * The index of the position of the head of the buffer. - * @type {number} - */ - this.head = 0; - /** - * The index of the position of the tail of the buffer. - * @type {number} - */ - this.tail = 0; - /** - * The items stored in the buffer. - * @type {Array<*>} - */ - this.items = new Array(size); - /** - * Is true if buffer is empty, false otherwise. - * @type {boolean} - */ - this.empty = true; - /** - * Is false if buffer is full, false otherwise. - * @type {boolean} - */ - this.full = false; - /** - * The size of the buffer. - * @type {Number} - */ - this.size = size; -} - -/** - * Returns the iterator relative to the aggregate. - * @return {Iterator} The iterator. - */ -CircularBuffer.prototype.getIterator = function () { - return new CircularBufferIterator(this); -}; - -/** - * Writes the item at the head of the buffer. - * @param item {*} The item to write. - * @return {void} - */ -CircularBuffer.prototype.write = function (item) { - this.empty = false; - if (this.full) - //if buffer is full tail must be set forward - this.tail = (this.tail + 1) % this.size; - this.items[this.head] = item; - //head is set forward - this.head = (this.head + 1) % this.size; - if (this.tail === this.head) - this.full = true; -}; - -/** - * Frees the buffer between indexes from and to. - * If from > to, positions between from and the end of the buffer and between the start and to will be free. - * @param from {Number} The index from which start to free (inclusive index) - * @param to {Number} The index where stop to free (exclusive index) - * @return {void} - */ -CircularBuffer.prototype.free = function (from, to) { - if (from < 0) - from = 0; - if (from > this.size - 1) - from = this.size - 1; - if (to < 0) - to = 0; - if (to > this.size - 1) - to = this.size - 1; - //if from < to then will be free allocation between from and to - //otherwise will be free allocations between from and the end and between the start and to - for (var i = from; i < to; i = (i + 1) % this.size) - delete this.items[i]; - - //adjust the position of the tail and of the head - if (this.tail > from - 1 || this.tail < to) - if (this.tail < this.head) { - this.tail = (from - 1) % this.size; - } else { - this.tail = to; - } - if (this.head > from || this.head < to) - if (this.tail < this.head) { - this.head = to; - } else { - this.head = from; - } - //check if something is free - if (from !== to) - this.full = false; - //free could make buffer empty - for (var j = 0; j < this.size; j++) - if (this.items[j] !== undefined) { - this.empty = false; - return; - } - this.empty = true; -}; - -/** - * Frees all the buffer. - * @return {void} - */ -CircularBuffer.prototype.freeAll = function () { - for (var i = 0; i < this.size; i++) - delete this.items[i]; - this.empty = true; - this.head = 0; - this.tail = 0; -}; - -/** - * Reads the item stored at the position index. - * @param index {Number} The position of the item to read. - * @return {*} The item read. - */ -CircularBuffer.prototype.read = function (index) { - return this.items[index % this.size]; -}; - -/** - * Returns true if the buffer is empty, false otherwise. - * @return {boolean} - */ -CircularBuffer.prototype.isEmpty = function () { - return this.empty; -}; - -/** - * Returns true if the buffer is full, false otherwise. - * @return {boolean} - */ -CircularBuffer.prototype.isFull = function () { - return this.full; -}; - -/** - * Clones the circular buffer into a new circular buffer. - * @return {CircularBuffer} The circular buffer cloned from this circular buffer. - */ -CircularBuffer.prototype.clone = function () { - var buffer = new CircularBuffer(this.size); - buffer.head = this.head; - buffer.tail = this.tail; - for (var i = 0; i < this.items.length; i++) - buffer.items[i] = this.items[i]; - buffer.empty = this.empty; - buffer.full = this.full; - return buffer; -}; - -/** - * Resize the buffer. - * @param size {number} The new size of the buffer. - * @return {void} - */ -CircularBuffer.prototype.resize = function (size) { - if (this.size < size) { - if (this.head < this.tail + 1) { - for (var i = 0; i < this.head; i++) { - this.items[(i + this.size) % size] = this.items[i]; - delete this.items[i]; - } - this.head = (this.head + this.size) % size; - } - } else if (this.size > size) { - if (this.head < this.tail + 1) { - //check if the tail is after the size - var start = size; - if (this.tail > size - 1) { - start = this.tail; - this.tail = 0; - } - //the items stored must be shift to a valid position - var step = this.size - start; - for (var j = this.head - step - 1; j > start - 1 || j < this.head - step; j--) { - this.items[(j + step) % this.size] = this.items[j]; - if (!j) - j = this.size; - } - this.head = (this.head + step) % this.size; - } - } - this.size = size; -}; - -/** - * Class that implements the iterator for a circular buffer. - * @param aggregate {CircularBuffer} The aggregate to scan. - * @constructor - */ -function CircularBufferIterator(aggregate) { - /** - * The aggregate relates to this iterator. - * @type {CircularBuffer} - */ - this.aggregate = aggregate; - - /** - * The pointer to the position. - * @type {number|null} - */ - this.pointer = null; - /** - * Discriminator for full buffer - * @type {bool} - */ - this.start = true; -} - -/** - * Moves the iterator to the first position of the aggregate. - * @return {void} - */ -CircularBufferIterator.prototype.first = function () { - this.pointer = this.aggregate.tail; - this.start = true; -}; - -/** - * Moves the iterator to the next item. - * @return {void} - */ -CircularBufferIterator.prototype.next = function () { - this.pointer = (this.pointer + 1) % this.aggregate.size; - this.start = false; -}; - -/** - * Moves the iterator to the last position of the aggregate. - * @return {void} - */ -CircularBufferIterator.prototype.last = function () { - this.pointer = (this.aggregate.head - 1) % this.aggregate.size; - this.start = true; -}; - -/** - * Moves the iterator to the previous item. - * @return {void} - */ -CircularBufferIterator.prototype.previous = function () { - this.pointer = (this.pointer - 1) % this.aggregate.size; - this.start = false; -}; - -/** - * Checks if the iterator is out of the bounds of the aggregate. - * @return {boolean} It return true if the iterator is out of the bounds of the aggregate, otherwise false. - */ -CircularBufferIterator.prototype.isDone = function () { - return (this.pointer === this.aggregate.head && !this.start) || (this.pointer === this.aggregate.tail - 1) % this.aggregate.size || this.aggregate.isEmpty(); -}; - -/** - * Returns the item stored at the position pointed by the iterator. - * @return {*} The item stored or undefined if it's out of the bounds. - */ -CircularBufferIterator.prototype.getItem = function () { - return this.aggregate.read(this.pointer); -}; - -/** - * Class for managing a double linked list. - * @param {...*} [args] The items for initializing the list. - * @constructor - */ -function DoubleLinkedList(args) { - /** - * The first node of the list. - * @type {DLLNode|null} - */ - this.first = null; - /** - * The last node of the list. - * @type {DLLNode|null} - */ - this.last = null; - /** - * The length of the list. - * @type {number} - */ - this.length = 0; - //builds the list from the parameters of the constructor - this.fromArray(arguments); -} - -/** - * Returns the iterator relative to the aggregate. - * @return {Iterator} The iterator. - */ -DoubleLinkedList.prototype.getIterator = function () { - return new DoubleLinkedListIterator(this); -}; - -/** - * Adds an item at the head of the list. - * @param item {*} The item to add. - * @return {void} - */ -DoubleLinkedList.prototype.pushFront = function (item) { - var node = new DLLNode(item); - node.next = this.first; - this.first = node; - //link the next node to the new node - if (node.next) - node.next.previous = node; - else - this.last = node; - this.length++; -}; - -/** - * Adds an item at the tail of the list. - * @param item {*} The item to add. - * @return {void} - */ -DoubleLinkedList.prototype.pushBack = function (item) { - var node = new DLLNode(item); - node.previous = this.last; - this.last = node; - //link the previous node to the new node - if (node.previous) - node.previous.next = node; - else - this.first = node; - this.length++; -}; - -/** - * Removes the first item of the list. - * @return {*} The item removed. It's undefined if the list is empty. - */ -DoubleLinkedList.prototype.popFront = function () { - if (this.length) { - var node = this.first; - this.first = node.next; - if (node.next) - node.next.previous = null; - this.length--; - node.next = null; - return node.item; - } - return undefined; -}; - -/** - * Removes the last item of the list. - * @return {*} The item removed. It's undefined if the list is empty. - */ -DoubleLinkedList.prototype.popBack = function () { - if (this.length) { - var node = this.last; - this.last = node.previous; - if (node.previous) - node.previous.next = null; - this.length--; - node.previous = null; - return node.item; - } - return undefined; -}; - -/** - * Removes the first times items of the list. - * @param times {number} The number of times to repeat the popFront method. - * @return {*} The item removed. It's undefined if the list is empty. - */ -DoubleLinkedList.prototype.multiPopFront = function (times) { - var result = []; - for (var i = 0; i < times && this.length; i++) - result.push(this.popFront()); - return result; -}; - -/** - * Removes the last times items of the list. - * @param times {number} The number of times to repeat the popBack method. - * @return {*} The items removed. - */ -DoubleLinkedList.prototype.multiPopBack = function (times) { - var result = []; - for (var i = 0; i < times && this.length; i++) - result.push(this.popBack()); - return result; -}; - -/** - * Returns the first item of the list without remove it. - * @return {*} The item at the top of the list. It's undefined if the list is empty. - */ -DoubleLinkedList.prototype.peek = function () { - if (!this.length) - return undefined; - return this.first.item; -}; - -/** - * Adds the item at the index position. - * @param item {*} The item to add. - * @param index {number} The position where to add the item. If index is negative, the item won't be added. - * @return {void} - */ -DoubleLinkedList.prototype.addAt = function (item, index) { - if (index < 0) - return; - if (!index) { - this.pushFront(item); - return; - } - if (index === this.length) { - this.pushBack(item); - return; - } - var node = this.first; - if (!node && index > 0) - this.pushBack(undefined); - for (var i = 0; i < index - 1; i++, node = node.next) { - if (node === this.last) - this.pushBack(undefined); - } - if (node === this.last) - this.pushBack(item); - else if (node === this.first) - this.pushFront(item); - else { - var newNode = new DLLNode(item); - newNode.next = node.next; - newNode.previous = node; - node.next = newNode; - if (newNode.next) - newNode.next.previous = newNode; - this.length++; - } -}; - -/** - * Removes the item at the position index. - * @param index {Number} The position of the item to remove. - * @return {*} The item stored at the position index. It's undefined if the index is out of bounds. - */ -DoubleLinkedList.prototype.removeAt = function (index) { - if (index < 0 || index > this.length - 1) - return undefined; - if (index === 0) - return this.popFront(); - if (index === this.length - 1) - return this.popBack(); - var node = this.first; - for (; index > 0; index--) - node = node.next; - //now node is the node to remove - node.previous.next = node.next; - node.next.previous = node.previous; - node.next = null; - node.previous = null; - this.length--; - return node.item; -}; - -/** - * Removes the item from the list. - * @param item {*} The item to remove. - * @param [callback = function(item){return(it===item);}] The condition to satisfy. The callback must accept the current item to check. - * @return {void} - */ -DoubleLinkedList.prototype.remove = function (item, callback) { - callback = callback || function (it) { - return it === item; - }; - var node = this.first; - var previous = null; - while (node) { - if (callback(node.item)) { - if (node === this.first) - this.first = node.next; - if (node === this.last) - this.last = previous; - if (previous) { - previous.next = node.next; - if (node.next) - node.next.previous = previous; - } - return; - } - previous = node; - node = node.next; - } -}; - -/** - * Removes all the item from the list. - * @param item {*} The item to remove. - * @param [callback = function(item){return(it===item);}] The condition to satisfy. The callback must accept the current item to check. - * @return {void} - */ -DoubleLinkedList.prototype.removeAll = function (item, callback) { - callback = callback || function (it) { - return it === item; - }; - var node = this.first; - var previous = null; - while (node) { - if (callback(node.item)) { - if (node === this.first) - this.first = node.next; - if (node === this.last) - this.last = previous; - if (previous) { - previous.next = node.next; - if (node.next) - node.next.previous = previous; - } - } else - previous = node; - node = node.next; - } -}; - -/** - * Removes all the items stored from the from position to the to position. - * If from > to, the method will remove all the items up to the end. - * @param from {number} The position where start to remove the items. The from position is included. - * @param to {number} The position where stop to remove the items. The to position is included. - * @return {Array<*>} The items removed. - */ -DoubleLinkedList.prototype.removeSegment = function (from, to) { - var result = []; - if (to > -1 && from < this.length) { - if (from === 0) - return this.multiPopFront(to + 1); - if (to === this.length - 1 || from > to) - return this.multiPopBack(Math.max(to - from, this.length - from)).reverse(); - var node = this.first; - for (var i = 0; i < from - 1; i++) - node = node.next; - //now node is the node before the node to remove - //node to remove - var next = node.next; - for (var j = from; j < to + 1 && j < this.length; j++) { - result.push(next.item); - next = next.next; - } - this.length -= Math.min(to - from + 1, this.length - from); - node.next = next; - next.previous = node; - } - return result; -}; - -/** - * Changes the item stored in the index position. If the index is out of bound, the node won't be updated. - * @param index {number} The position of the node to modify. - * @param item {*} The new item stored in the node. - * @return {void} - */ -DoubleLinkedList.prototype.modifyAt = function (index, item) { - var node = this.getNode(index); - if (node) - node.item = item; -}; - -/** - * Removes all the items stored in the list. - * @return {void} - */ -DoubleLinkedList.prototype.clear = function () { - this.first = null; - this.last = null; - this.length = 0; -}; - -/** - * Checks if the list contains an item that satisfy the condition represented by the callback function. - * @param item {*} The item to find. - * @param [callback = function(item){return(it===item);}] The condition to satisfy. The callback must accept the current item to check. - * @return {boolean} True if the list contains the item that satisfy the condition, false otherwise. - */ -DoubleLinkedList.prototype.contains = function (item, callback) { - callback = callback || function (it) { - return it === item; - }; - var i = 0; - var node = this.first; - while (i < this.length && !callback(node.item)) { - i++; - node = node.next; - } - return i < this.length; -}; - -/** - * Executes the callback function for each item of the stack. - * This method modifies the list so if you don't need to modify it you must return the same item of the array. - * @param callback {function} The function to execute for each item. The function must accept the current item on which execute the function. - * @return {void} - */ -DoubleLinkedList.prototype.execute = function (callback) { - var node = this.first; - while (node) { - node.item = callback(node.item); - node = node.next; - } -}; - -/** - * Deletes the node from the list. - * @param node {DLLNode} The node to delete. - * @return {void} - */ -DoubleLinkedList.prototype.deleteNode = function (node) { - if (node === this.first) { - this.popFront(); - return; - } - if (node === this.last) { - this.popBack(); - return; - } - node.previous.next = node.next; - node.next.previous = node.previous; - this.length--; -}; - -/** - * Gets the node at the position index relative from the node. - * @param index {Number} The index, relative to the node, of the node to return. - * @param [node = first] {DLLNode} The node from which start the search. - * @return {DLLNode} The node at the position index. - */ -DoubleLinkedList.prototype.getNode = function (index, node) { - if (index < 0 || index > this.length - 1) - return undefined; - var m = Math.floor(this.length / 2); - //if the index is less than the middle, the search start from the head of the list, otherwise from the tail of the list - if (index < m || node) { - node = node || this.first; - for (; index > 0; index--) - node = node.next; - } else - for (index = this.length - index - 1, node = this.last; index > 0; index--) - node = node.previous; - return node; -}; - -/** - * Gets the item at the position index. - * @param index {Number} The position of the item. - * @return {*}. It's undefined if index isn't in the queue bounds. - */ -DoubleLinkedList.prototype.getItem = function (index) { - if (index < 0 || index > this.length - 1) - return undefined; - var node; - var m = Math.floor(this.length / 2); - if (index < m) //if the index is less than the middle, the search start from the head of the list, otherwise from the tail of the list - for (node = this.first; index > 0; index--) - node = node.next; - else - for (index = this.length - index - 1, node = this.last; index > 0; index--) - node = node.previous; - return node.item; -}; - -/** - * Sorts the list using web workers. - * Using this method is discouraged. Many web browser set a limit to the maximum number of workers instantiated. - * The items of the list, due to web workers implementation, will be serialized so they will lost own methods. - * @return {void} - */ -DoubleLinkedList.prototype.parallelSort = function () { - - var workers = []; - var _array = this.toArray(); - console.log(_array); - - function partialSort(_from, _to, _id) { - if (_from < _to) { - var m = Math.floor((_from + _to) / 2); - var workerLeft = new Worker("DoubleLinkedList/WorkerSort.js"); - var workerRight = new Worker("DoubleLinkedList/WorkerSort.js"); - workers.push(workerLeft); - workers.push(workerRight); - var length = workers.length; - workerLeft.postMessage({cmd: 'start', from: _from, to: m, worker: _id}); - workerRight.postMessage({cmd: 'start', from: m + 1, to: _to, worker: _id}); - partialSort(_from, m, length - 2); - partialSort(m + 1, _to, length - 1); - workerLeft.onmessage = function (event) { - var data = event.data; - switch (data.cmd) { - case 'finished': - workers[data.worker].postMessage({cmd: 'finished', array: _array}); - break; - case 'replace': - _array[data.index] = data.value; - break; - } - }; - workerRight.onmessage = function (event) { - var data = event.data; - switch (data.cmd) { - case 'finished': - workers[data.worker].postMessage({cmd: 'finished', array: _array}); - break; - case 'replace': - _array[data.index] = data.value; - break; - } - } - } - } - - var outerThis = this; - - var mainWorker = new Worker("DoubleLinkedList/WorkerSort.js"); - workers.push(mainWorker); - mainWorker.postMessage({cmd: 'start', from: 0, to: this.length - 1, worker: -1, array: _array}); - mainWorker.onmessage = function (event) { - var data = event.data; - switch (data.cmd) { - case 'finished': - outerThis.fromArray(_array); - console.log(outerThis); - break; - case 'replace': - _array[data.index] = data.value; - } - }; - partialSort(0, this.length - 1, 0); -}; - -/** - * Sorts the list. - * @param [callback = function(item){return(item);}] {function} The function invoked in order to get the value for the evaluation of the sort criteria. - * @example - * callback = function(item) {return -item.key;} - * This function callback will return the opposite of the attribute key of the item. In this case the list will be sorted in descending order. - * @return {void} - */ -DoubleLinkedList.prototype.sort = function (callback) { - - if (!callback) - callback = function (item) { - return item; - }; - - var outerThis = this; - - function partialSort(from, to, fromNode, toNode) { - if (from < to) { - var m = Math.floor((from + to) / 2); - var mNode = outerThis.getNode(m - from, fromNode); - partialSort(from, m, fromNode, mNode); - partialSort(m + 1, to, mNode.next, toNode); - merge(from, m, to, fromNode); - } - } - - function merge(from, m, to, fromNode) { - var left = []; - var right = []; - var node = fromNode; - for (var i = 0; i < m - from + 1; i++, node = node.next) - left[i] = node.item; - for (var j = 0; j < to - m; j++, node = node.next) - right[j] = node.item; - var x = 0, y = 0; - for (var k = from; k < to + 1; k++, fromNode = fromNode.next) { - if (y > to - m - 1 || (callback(left[x]) <= callback(right[y]) && x < m - from + 1)) { - fromNode.item = left[x]; - x++; - } else { - fromNode.item = right[y]; - y++; - } - } - } - - partialSort(0, this.length - 1, this.first, this.last); -}; - -/** - * Transforms the list into an array. - * @return {Array<*>} The array built. - */ -DoubleLinkedList.prototype.toArray = function () { - var array = []; - for (var node = this.first, i = 0; node; node = node.next, i++) - array[i] = node.item; - return array; -}; - -/** - * Returns the length of the list. - * @return {Number} The length of the list. - */ -DoubleLinkedList.prototype.getLength = function () { - return this.length; -}; - -/** - * Builds the list from the array. - * @param array {Array<*>} The array from which build the list. - * @return {void} - */ -DoubleLinkedList.prototype.fromArray = function (array) { - var node = this.first; - for (var i = 0; i < Math.min(this.length, array.length); i++, node = node.next) - node.item = array[i]; - if (this.length < array.length) - for (var j = this.length; j < array.length; j++) - this.pushBack(array[j]); - else - for (var k = array.length; k < this.length;) - this.popBack(); -}; - -/** - * Returns the items that satisfy the condition determined by the callback. - * @param callback {function} The function that implements the condition. - * @return {Array} The array that contains the items that satisfy the condition. - */ -DoubleLinkedList.prototype.filter = function (callback) { - var result = []; - for (var node = this.first; node; node = node.next) { - if (callback(node.item)) - result.push(node.item); - } - return result; -}; - -/** - * Reverses the list. This method reverses only the items, not the nodes. - * @return {void} - */ -DoubleLinkedList.prototype.reverse = function () { - for (var start = this.first, end = this.last; start !== end && start.previous !== end; start = start.next, end = end.previous) { - var item = start.item; - start.item = end.item; - end.item = item; - } -}; - -/** - * Checks if the list is empty. - * @return {boolean} True if the list is empty, false otherwise. - */ -DoubleLinkedList.prototype.isEmpty = function () { - return !this.length; -}; - -/** - * Returns the first position of the item in the list. - * @param item {*} The item to search. - * @param [callback = function(item){return(it===item);}] The condition to satisfy. The callback must accept the current item to check. - * @return {number} The first position of the item. - */ -DoubleLinkedList.prototype.indexOf = function (item, callback) { - callback = callback || function (it) { - return it === item; - }; - var i = 0; - var node = this.first; - while (node) { - if (callback(node.item)) - return i; - i++; - node = node.next; - } - return -1; -}; - -/** - * Returns the last position of the item in the list. - * @param item {*} The item to search. - * @param [callback = function(item){return(it===item);}] The condition to satisfy. The callback must accept the current item to check. - * @return {number} The last position of the item. - */ -DoubleLinkedList.prototype.lastIndexOf = function (item, callback) { - callback = callback || function (it) { - return it === item; - }; - var i = this.length - 1; - var node = this.last; - while (node) { - if (callback(node.item)) - return i; - i--; - node = node.previous; - } - return -1; -}; - -/** - * Returns all the position in which the item has been found in the list. - * @param item {*} The item to search. - * @param [callback = function(item){return(it===item);}] The condition to satisfy. The callback must accept the current item to check. - * @return {Array} The positions in which the item has been found. - */ -DoubleLinkedList.prototype.allIndexesOf = function (item, callback) { - callback = callback || function (it) { - return it === item; - }; - var i = 0; - var node = this.first; - var indexes = []; - while (node) { - if (callback(node.item)) - indexes.push(i); - i++; - node = node.next; - } - return indexes; -}; - -/** - * Adds the list at the end of this list. - * @param list {DoubleLinkedList} The list to join. - * @return {void} - */ -DoubleLinkedList.prototype.join = function (list) { - if (this.last) - this.last.next = list.first; - else - this.first = list.first; - if (list.first) - list.first.previous = this.last; - this.last = list.last; - this.length += list.length; -}; - -/** - * Divides the list at the index position. The node at the index position is the first new node of the list. - * @param index {number} The position where to divide the list. - * @return {DoubleLinkedList} The list formed by the nodes from the index position then. If the index is out of bound, the list will be empty. - */ -DoubleLinkedList.prototype.divide = function (index) { - var list = new DoubleLinkedList(); - if (index > -1 && index < this.length) { - var node = this.first; - var previous = null; - for (var i = 0; i < index; i++) { - previous = node; - node = node.next; - } - if (node === this.first) { - list.first = this.first; - list.last = this.last; - this.first = null; - this.last = null; - } else { - list.first = node; - list.last = this.last; - this.last = previous; - previous.next = null; - node.previous = null; - } - list.length = this.length - index; - this.length = index; - } - return list; -}; - -/** - * Clones the list into a new list. - * @return {DoubleLinkedList} The list cloned from this list. - */ -DoubleLinkedList.prototype.clone = function () { - var list = new DoubleLinkedList(); - var node = this.first; - for (var i = 0; i < this.length; i++, node = node.next) - if (node.item.clone) - list.pushBack(node.item.clone()); - else - list.pushBack(node.item); - return list; -}; - -/** - * Clones the list into a new list without cloning duplicated items. - * @return {DoubleLinkedList} The list cloned from this list. - */ -DoubleLinkedList.prototype.cloneDistinct = function () { - var list = new DoubleLinkedList(); - var node = this.first; - for (var i = 0; i < this.length; i++, node = node.next) - if (!list.contains(node.item)) - if (node.item.cloneDistinct) - list.pushBack(node.item.cloneDistinct()); - else if (node.item.clone) - list.pushBack(node.item.clone()); - else - list.pushBack(node.item); - return list; -}; - -/** - * Splits the list into lists of desired size. - * @param size {number} The size of the lists. - * @return {Array} The lists created by splitting the list. - */ -DoubleLinkedList.prototype.split = function (size) { - var length = this.length; - var lists = [this]; - for (var i = size; i < length; i += size) - lists.push(lists[lists.length - 1].divide(size)); - return lists; -}; - -/** - * Returns the number of items that satisfy the represented by the callback function. - * @param callback {function} The condition to satisfy. - * @return {number} The number of items that satisfy the condition. - */ -DoubleLinkedList.prototype.count = function (callback) { - var count = 0; - var node = this.first; - while (node) { - if (callback(node.item)) - count++; - node = node.next; - } - return count; -}; - -/** - * Class that implements the iterator for a double linked list. - * @param aggregate {DoubleLinkedList} The aggregate to scan. - * @constructor - */ -function DoubleLinkedListIterator(aggregate) { - /** - * The aggregate relates to this iterator. - * @type {DoubleLinkedList} - */ - this.aggregate = aggregate; - - /** - * The pointer to the position. - * @type {Node|null} - */ - this.pointer = null; -} - -/** - * Moves the iterator to the first position of the aggregate. - * @return {void} - */ -DoubleLinkedListIterator.prototype.first = function () { - this.pointer = this.aggregate.first; -}; - -/** - * Moves the iterator to the next item. - * @return {void} - */ -DoubleLinkedListIterator.prototype.next = function () { - this.pointer = this.pointer.next; -}; - -/** - * Moves the iterator to the last position of the aggregate. - * @return {void} - */ -DoubleLinkedListIterator.prototype.last = function () { - this.pointer = this.aggregate.last; -}; - -/** - * Moves the iterator to the previous item. - * @return {void} - */ -DoubleLinkedListIterator.prototype.previous = function () { - this.pointer = this.pointer.previous; -}; - -/** - * Checks if the iterator is out of the bounds of the aggregate. - * @return {boolean} It return true if the iterator is out of the bounds of the aggregate, otherwise false. - */ -DoubleLinkedListIterator.prototype.isDone = function () { - return !this.pointer; -}; - -/** - * Returns the item stored at the position pointed by the iterator. - * @abstract - * @return {*} The item stored or undefined if it's out of the bounds. - */ -DoubleLinkedListIterator.prototype.getItem = function () { - return this.pointer.item; -}; - -/** - * Returns the node stored at the position pointed by the iterator. - * @abstract - * @return {DLLNode|null} The node stored or null if it's out of the bounds. - */ -DoubleLinkedListIterator.prototype.getNode = function () { - return this.pointer; -}; - -/** - * Class for managing an hash table. - * @param size {number} The size of the table. - * @constructor - */ -function HashTable(size) { - /** - * The size of the table - * @type {number} - */ - this.size = size; - - this.p = 1000; - - this.a = Math.floor(Math.random() * this.p); - - this.b = Math.floor(Math.random() * this.p); - - /** - * Calculate the hash of the param key. - * @param key {number} The key to hash. - * @return {number} The hash of the key. - */ - this.hash = function (key) { - return ((this.a * key + this.b) % this.p) % this.size; - }; - - /** - * The items stored in the hash table. - * @type {Array} - */ - this.items = []; - - /** - * The number of keys stored in the hash table. - * @type {number} - */ - this.keyLength = 0; - - this.clear(); -} - -/** - * Stores the item with its key. - * @param key {number} The key relatives to the item. - * @param item {*} The item to store. - */ -HashTable.prototype.insert = function (key, item) { - this.keyLength++; - this.items[this.hash(key)].pushBack({key: key, item: item}); -}; - -/** - * Deletes the first item relatives to the key value. - * @param key {number} The key to delete. - * @return {void} - */ -HashTable.prototype.deleteKey = function (key) { - var list = this.items[this.hash(key)]; - var it = list.getIterator(); - for (it.first(); !it.isDone() && it.getItem().key !== key;) - it.next(); - if (!it.isDone()) { - list.deleteNode(it.getNode()); - this.keyLength--; - } -}; - -/** - * Deletes all the items relative to the key value. - * @param key {number} The key to delete. - * @return {void} - */ -HashTable.prototype.deleteAllKey = function (key) { - var list = this.items[this.hash(key)]; - var it = list.getIterator(); - var keysRemoved = 0; - for (it.first(); !it.isDone(); it.next()) - if (it.getItem().key === key) { - list.deleteNode(it.getNode()); - keysRemoved++; - } - this.keyLength -= keysRemoved; -}; - -/** - * Searches the item relative to the key value. - * @param key {number} The key of the item to search. - * @return {*|undefined} The item found or undefined if the key does not exist. - */ -HashTable.prototype.search = function (key) { - var list = this.items[this.hash(key)]; - var it = list.getIterator(); - for (it.first(); !it.isDone(); it.next()) - if (it.getItem().key === key) - return it.getItem().item; - return undefined; -}; - -/** - * Checks if the hash table contains a key that satisfy the condition represented by the callback function. - * @param key {number} The key to find. - * @param [callback = function(k){return(k===key);}] The condition to satisfy. The callback must accept the current key to check. - * @return {boolean} True if the hash table contains the key that satisfy the condition, false otherwise. - */ -HashTable.prototype.containsKey = function (key, callback) { - callback = callback || function (k) { - return k === key; - }; - var list = this.items[this.hash(key)]; - var it = list.getIterator(); - for (it.first(); !it.isDone(); it.next()) - if (callback(it.getItem().key)) - return true; - return false; -}; - -/** - * Searches all the items relative to the key value. - * @param key {number} The key of the items to search. - * @return {Array.<*>} An array with the items found. - */ -HashTable.prototype.searchAll = function (key) { - var list = this.items[this.hash(key)]; - var it = list.getIterator(); - var array = []; - for (it.first(); !it.isDone(); it.next()) - if (it.getItem().key === key) - array.push(it.getItem().item); - return array; -}; - -/** - * Returns the keys stored in the hash table. - * @return {Array} The keys stored in the table. - */ -HashTable.prototype.getKeys = function () { - var keys = []; - for (var i = 0; i < this.size; i++) { - var it = this.items[i].getIterator(); - for (it.first(); !it.isDone(); it.next()) - keys.push(it.getItem().key); - } - return keys; -}; - -/** - * Returns the items stored in the hash table. - * @return {Array<*>} The items stored in the table. - */ -HashTable.prototype.getItems = function () { - var items = []; - for (var i = 0; i < this.size; i++) { - var it = this.items[i].getIterator(); - for (it.first(); !it.isDone(); it.next()) - items.push(it.getItem().item); - } - return items; -}; - -/** - * Removes all the keys and the items stored in the hash table. - * @return {void} - */ -HashTable.prototype.clear = function () { - this.items = []; - for (var i = 0; i < this.size; i++) - this.items[i] = new DoubleLinkedList(); - this.keyLength = 0; -}; - -/** - * Returns the number of keys stored in the hash table. - * @return {number} The number of keys stored. - */ -HashTable.prototype.getNumberOfKeys = function () { - return this.keyLength; -}; - -/** - * Checks if the hash table is empty. - * @return {boolean} True if the hash table is empty, false otherwise. - */ -HashTable.prototype.isEmpty = function () { - return !this.keyLength; -}; - -/** - * Executes the callback function for each item of the hash table. - * This method modifies the hash table so if you don't need to modify it you must return the same item stored. - * @param callback {function} The function to execute for each item. The function must accept the current item on which execute the function. - * @return {void} - */ -HashTable.prototype.execute = function (callback) { - for (var i = 0; i < this.size; i++) - this.items[i].execute(callback); -}; - -/** - * Returns the items that satisfy the condition determined by the callback. - * @param callback {function} The function that implements the condition. - * @return {Array<*>} The array that contains the items that satisfy the condition. - */ -HashTable.prototype.filter = function (callback) { - var result = []; - for (var i = 0; i < this.size; i++) - result.concat(this.items[i].filter(callback)); - return result; -}; - -/** - * Returns the size of the hash table. - * @return {number} The size of the hash table. - */ -HashTable.prototype.getSize = function () { - return this.size; -}; - -/** - * Clones the hash table into a new hash table. - * @return {HashTable} The hash table cloned from this hash table. - */ -HashTable.prototype.clone = function () { - var table = new HashTable(this.size); - for (var i = 0; i < this.size; i++) - for (var node = this.items[i].first; node; node = node.next) - table.insert(node.key, node.item); - return table; -}; - -/** - * Class for managing a linked list. - * @param {...*} [args] The items for initializing the list. - * @constructor - */ -function LinkedList(args) { - /** - * The first node of the list. - * @type {LLNode|null} - */ - this.first = null; - /** - * The last node of the list. - * @type {LLNode|null} - */ - this.last = null; - /** - * The length of the list. - * @type {number} - */ - this.length = 0; - //builds the list from the parameters of the constructor - this.fromArray(arguments); -} - -/** - * Returns the iterator relative to the aggregate. - * @return {Iterator} The iterator. - */ -LinkedList.prototype.getIterator = function () { - return new LinkedListIterator(this); -}; - -/** - * Adds an item at the head of the list. - * @param item {*} The item to add. - * @return {void} - */ -LinkedList.prototype.pushFront = function (item) { - var node = new LLNode(item); - node.next = this.first; - this.first = node; - if (!this.last) - this.last = node; - this.length++; -}; - -/** - * Adds an item at the tail of the list. - * @param item {*} The item to add. - * @return {void} - */ -LinkedList.prototype.pushBack = function (item) { - var node = new LLNode(item); - if (this.last) - this.last.next = node; - else - this.first = node; - this.last = node; - this.length++; -}; - -/** - * Removes the first item of the list. - * @return {*} The item removed. It's undefined if the list is empty. - */ -LinkedList.prototype.popFront = function () { - if (this.length) { - var node = this.first; - this.first = this.first.next; - this.length--; - node.next = null; - return node.item; - } - return undefined; -}; - -/** - * Removes the last item of the list. - * @return {*} The item removed. It's undefined if the list is empty. - */ -LinkedList.prototype.popBack = function () { - if (this.length) { - var node = this.last; - var next = this.first; - while (next.next && next.next.next) { - next = next.next; - } - if (node === next) - this.last = null; - else - this.last = next; - next.next = null; - this.length--; - return node.item; - } - return undefined; -}; - -/** - * Removes the first times items of the list. - * @param times {number} The number of times to repeat the popFront method. - * @return {*} The item removed. It's undefined if the list is empty. - */ -LinkedList.prototype.multiPopFront = function (times) { - var result = []; - for (var i = 0; i < times && this.length; i++) - result.push(this.popFront()); - return result; -}; - -/** - * Removes the last times items of the list. - * @param times {number} The number of times to repeat the popBack method. - * @return {*} The items removed. - */ -LinkedList.prototype.multiPopBack = function (times) { - var result = []; - for (var i = 0; i < times && this.length; i++) - result.push(this.popBack()); - return result; -}; - -/** - * Returns the first item of the list without remove it. - * @return {*} The item at the top of the list. It's undefined if the list is empty. - */ -LinkedList.prototype.peek = function () { - if (!this.length) - return undefined; - return this.first.item; -}; - -/** - * Adds the item at the index position. - * @param item {*} The item to add. - * @param index {number} The position where to add the item. If index is negative, the item won't be added. - * @return {void} - */ -LinkedList.prototype.addAt = function (item, index) { - if (index < 0) - return; - if (!index) { - this.pushFront(item); - return; - } - if (index === this.length) { - this.pushBack(item); - return; - } - var node = this.first; - if (!node && index > 0) - this.pushBack(undefined); - for (var i = 0; i < index - 1; i++, node = node.next) { - if (node === this.last) - this.pushBack(undefined); - } - if (node === this.last) - this.pushBack(item); - else if (node === this.first) - this.pushFront(item); - else { - var newNode = new LLNode(item); - newNode.next = node.next; - node.next = newNode; - this.length++; - } -}; - -/** - * Removes the item at the index position. - * @param index {number} The position of the item to remove. - * @return {*} The item stored at the position index. It's undefined if the index is out of bounds. - */ -LinkedList.prototype.removeAt = function (index) { - if (index < 0 || index > this.length - 1) - return undefined; - if (index === 0) - return this.popFront(); - if (index === this.length - 1) - return this.popBack(); - var node = this.first; - for (; index > 1; index--) - node = node.next; - //now node is the node before the node to remove - //node to remove - var next = node.next; - node.next = next.next; - this.length--; - return next.item; -}; - -/** - * Removes the item from the list. - * @param item {*} The item to remove. - * @param [callback = function(item){return(it===item);}] The condition to satisfy. The callback must accept the current item to check. - * @return {void} - */ -LinkedList.prototype.remove = function (item, callback) { - callback = callback || function (it) { - return it === item; - }; - var node = this.first; - var previous = null; - while (node) { - if (callback(node.item)) { - if (node === this.first) - this.first = node.next; - if (node === this.last) - this.last = previous; - if (previous) - previous.next = node.next; - return; - } - previous = node; - node = node.next; - } -}; - -/** - * Removes all the item from the list. - * @param item {*} The item to remove. - * @param [callback = function(item){return(it===item);}] The condition to satisfy. The callback must accept the current item to check. - * @return {void} - */ -LinkedList.prototype.removeAll = function (item, callback) { - callback = callback || function (it) { - return it === item; - }; - var node = this.first; - var previous = null; - while (node) { - if (callback(node.item)) { - if (node === this.first) - this.first = node.next; - if (node === this.last) - this.last = previous; - if (previous) - previous.next = node.next; - } else - previous = node; - node = node.next; - } -}; - -/** - * Removes all the items stored from the from position to the to position. - * If from > to, the method will remove all the items up to the end. - * @param from {number} The position where start to remove the items. The from position is included. - * @param to {number} The position where stop to remove the items. The to position is included. - * @return {Array<*>} The items removed. - */ -LinkedList.prototype.removeSegment = function (from, to) { - var result = []; - if (to > -1 && from < this.length) { - if (from === 0) - return this.multiPopFront(to + 1); - if (to === this.length - 1 || from > to) - return this.multiPopBack(Math.max(to - from, this.length - from)).reverse(); - var node = this.first; - for (var i = 0; i < from - 1; i++) - node = node.next; - //now node is the node before the node to remove - //node to remove - var next = node.next; - for (var j = from; j < to + 1 && j < this.length; j++) { - result.push(next.item); - next = next.next; - } - this.length -= Math.min(to - from + 1, this.length - from); - node.next = next; - } - return result; -}; - -/** - * Changes the item stored in the index position. If the index is out of bound, the node won't be updated. - * @param index {number} The position of the node to modify. - * @param item {*} The new item stored in the node. - * @return {void} - */ -LinkedList.prototype.modifyAt = function (index, item) { - var node = this.getNode(index); - if (node) - node.item = item; -}; - -/** - * Removes all the items stored in the list. - * @return {void} - */ -LinkedList.prototype.clear = function () { - this.first = null; - this.last = null; - this.length = 0; -}; - -/** - * Checks if the list contains an item that satisfy the condition represented by the callback function. - * @param item {*} The item to find. - * @param [callback = function(item){return(it===item);}] The condition to satisfy. The callback must accept the current item to check. - * @return {boolean} True if the list contains the item that satisfy the condition, false otherwise. - */ -LinkedList.prototype.contains = function (item, callback) { - callback = callback || function (it) { - return it === item; - }; - var i = 0; - var node = this.first; - while (i < this.length && !callback(node.item)) { - i++; - node = node.next; - } - return i < this.length; -}; - -/** - * Executes the callback function for each item of the stack. - * This method modifies the list so if you don't need to modify it you must return the same item of the array. - * @param callback {function} The function to execute for each item. The function must accept the current item on which execute the function. - * @return {void} - */ -LinkedList.prototype.execute = function (callback) { - var node = this.first; - while (node) { - node.item = callback(node.item); - node = node.next; - } -}; - -/** - * Returns the node at the position index. - * @param index {number} The position of the node. - * @return {LLNode} The node stored at the position index. It's undefined if index isn't in the list bounds. - */ -LinkedList.prototype.getNode = function (index) { - if (index < 0 || index > this.length - 1) - return undefined; - var node = this.first; - for (; index > 0; index--) - node = node.next; - return node; -}; - -/** - * Returns the item at the position index. - * @param index {number} The position of the item. - * @return {*} The item stored at the position index. It's undefined if index isn't in the list bounds. - */ -LinkedList.prototype.getItem = function (index) { - if (index < 0 || index > this.length - 1) - return undefined; - var node = this.first; - for (; index > 0; index--) - node = node.next; - return node.item; -}; - -/** - * Transforms the list into an array. - * @return {Array<*>} The array built. - */ -LinkedList.prototype.toArray = function () { - var array = []; - for (var node = this.first, i = 0; node; node = node.next, i++) - array[i] = node.item; - return array; -}; - -/** - * Returns the length of the list. - * @return {Number} The length of the list. - */ -LinkedList.prototype.getLength = function () { - return this.length; -}; - -/** - * Builds the list from the array. - * @param array {Array<*>} The array from which build the list. - * @return {void} - */ -LinkedList.prototype.fromArray = function (array) { - var node = this.first; - for (var i = 0; i < Math.min(this.length, array.length); i++, node = node.next) - node.item = array[i]; - if (this.length < array.length) - for (var j = this.length; j < array.length; j++) - this.pushBack(array[j]); - else - for (var k = array.length; k < this.length;) - this.popBack(); -}; - -/** - * Returns the items that satisfy the condition determined by the callback. - * @param callback {function} The function that implements the condition. - * @return {Array<*>} The array that contains the items that satisfy the condition. - */ -LinkedList.prototype.filter = function (callback) { - var result = []; - for (var node = this.first; node; node = node.next) { - if (callback(node.item)) - result.push(node.item); - } - return result; -}; - -/** - * Checks if the list is empty. - * @return {boolean} True if the list is empty, false otherwise. - */ -LinkedList.prototype.isEmpty = function () { - return !this.length; -}; - -/** - * Returns the first position of the item in the list. - * @param item {*} The item to search. - * @param [callback = function(item){return(it===item);}] The condition to satisfy. The callback must accept the current item to check. - * @return {number} The first position of the item. - */ -LinkedList.prototype.indexOf = function (item, callback) { - callback = callback || function (it) { - return it === item; - }; - var i = 0; - var node = this.first; - while (node) { - if (callback(node.item)) - return i; - i++; - node = node.next; - } - return -1; -}; - -/** - * Returns the last position of the item in the list. - * @param item {*} The item to search. - * @param [callback = function(item){return(it===item);}] The condition to satisfy. The callback must accept the current item to check. - * @return {number} The last position of the item. - */ -LinkedList.prototype.lastIndexOf = function (item, callback) { - callback = callback || function (it) { - return it === item; - }; - var i = 0; - var node = this.first; - var index = -1; - while (node) { - if (callback(node.item)) - index = i; - i++; - node = node.next; - } - return index; -}; - -/** - * Returns all the position in which the item has been found in the list. - * @param item {*} The item to search. - * @param [callback = function(item){return(it===item);}] The condition to satisfy. The callback must accept the current item to check. - * @return {Array} The positions in which the item has been found. - */ -LinkedList.prototype.allIndexesOf = function (item, callback) { - callback = callback || function (it) { - return it === item; - }; - var i = 0; - var node = this.first; - var indexes = []; - while (node) { - if (callback(node.item)) - indexes.push(i); - i++; - node = node.next; - } - return indexes; -}; - -/** - * Joins the list at the end of this list. - * @param list {LinkedList} The list to join. - * @return {void} - */ -LinkedList.prototype.join = function (list) { - if (this.last) - this.last.next = list.first; - else - this.first = list.first; - this.last = list.last; - this.length += list.length; -}; - -/** - * Divides the list at the index position. The node at the index position is the first new node of the list. - * @param index {number} The position where to divide the list. - * @return {LinkedList} The list formed by the nodes from the index position then. If the index is out of bound, the list will be empty. - */ -LinkedList.prototype.divide = function (index) { - var list = new LinkedList(); - if (index > -1 && index < this.length) { - var node = this.first; - var previous = null; - for (var i = 0; i < index; i++) { - previous = node; - node = node.next; - } - if (node === this.first) { - list.first = this.first; - list.last = this.last; - this.first = null; - this.last = null; - } else { - list.first = node; - list.last = this.last; - this.last = previous; - previous.next = null; - } - list.length = this.length - index; - this.length = index; - } - return list; -}; - -/** - * Clones the list into a new list. - * @return {LinkedList} The list cloned from this list. - */ -LinkedList.prototype.clone = function () { - var list = new LinkedList(); - var node = this.first; - for (var i = 0; i < this.length; i++, node = node.next) - if (node.item.clone) - list.pushBack(node.item.clone()); - else - list.pushBack(node.item); - return list; -}; - -/** - * Clones the list into a new list without cloning duplicated items. - * @return {LinkedList} The list cloned from this list. - */ -LinkedList.prototype.cloneDistinct = function () { - var list = new LinkedList(); - var node = this.first; - for (var i = 0; i < this.length; i++, node = node.next) - if (!list.contains(node.item)) - if (node.item.cloneDistinct) - list.pushBack(node.item.cloneDistinct()); - else if (node.item.clone) - list.pushBack(node.item.clone()); - else - list.pushBack(node.item); - return list; -}; - -/** - * Splits the list into lists of desired size. - * @param size {number} The size of the lists. - * @return {Array} The lists created by splitting the list. - */ -LinkedList.prototype.split = function (size) { - var length = this.length; - var lists = [this]; - for (var i = size; i < length; i += size) - lists.push(lists[lists.length - 1].divide(size)); - return lists; -}; - -/** - * Returns the number of items that satisfy the represented by the callback function. - * @param callback {function} The condition to satisfy. - * @return {number} The number of items that satisfy the condition. - */ -LinkedList.prototype.count = function (callback) { - var count = 0; - var node = this.first; - while (node) { - if (callback(node.item)) - count++; - node = node.next; - } - return count; -}; - -/** - * Class that implements the iterator for a linked list. - * @param aggregate {LinkedList} The aggregate to scan. - * @constructor - */ -function LinkedListIterator(aggregate) { - /** - * The aggregate relates to this iterator. - * @type {LinkedList} - */ - this.aggregate = aggregate; - - /** - * The pointer to the position. - * @type {Node|null} - */ - this.pointer = null; -} - -/** - * Moves the iterator to the first position of the aggregate. - * @return {void} - */ -LinkedListIterator.prototype.first = function () { - this.pointer = this.aggregate.first; -}; - -/** - * Moves the iterator to the next item. - * @return {void} - */ -LinkedListIterator.prototype.next = function () { - this.pointer = this.pointer.next; -}; - -/** - * Moves the iterator to the last position of the aggregate. - * @return {void} - */ -LinkedListIterator.prototype.last = function () { - this.pointer = this.aggregate.last; -}; - -/** - * Moves the iterator to the previous item. - * @return {void} - */ -LinkedListIterator.prototype.previous = function () { - var node = this.pointer; - for (this.pointer = this.first(); this.pointer.next !== node;) - this.next(); -}; - -/** - * Checks if the iterator is out of the bounds of the aggregate. - * @return {boolean} It return true if the iterator is out of the bounds of the aggregate, otherwise false. - */ -LinkedListIterator.prototype.isDone = function () { - return !this.pointer; -}; - -/** - * Returns the item stored at the position pointed by the iterator. - * @return {*} The item stored or undefined if it's out of the bounds. - */ -LinkedListIterator.prototype.getItem = function () { - return this.pointer.item; -}; - -/** - * Returns the node stored at the position pointed by the iterator. - * @abstract - * @return {Node|null} The node stored or null if it's out of the bounds. - */ -LinkedListIterator.prototype.getNode = function () { - return this.pointer; -}; - -/** - * Class for managing a priority queue. - * @constructor - */ -function PriorityQueue() { - /** - * The list of the items in the queue. - * @type {RBTreeList} - */ - this.items = new RBTreeList(); - /** - * The length of the queue. - * @type {number} - */ - this.length = 0; -} - -/** - * Returns the iterator relative to the aggregate. - * @return {Iterator} The iterator. - */ -PriorityQueue.prototype.getIterator = function () { - return new PriorityQueueIterator(this); -}; - -/** - * Adds the item at the tail of the queue. - * @param priority {number} The priority of the item. - * @param item {*} The item to add. - * @return {void} - */ -PriorityQueue.prototype.enqueue = function (priority, item) { - var queue = this.items.search(priority); - if (!queue) { - queue = new Queue(); - this.items.insert(priority, queue); - } - queue.enqueue(item); - this.length++; -}; - -/** - * Adds the items with the same priority at the tail of the queue. - * @param priority {number} The priority of the items. - * @param items {Array<*>} The items to add. - * @return {void} - */ -PriorityQueue.prototype.multiEnqueue = function (priority, items) { - for (var i = 0; i < items.length; i++) - this.enqueue(priority, items[i]); -}; - -/** - * Removes the item at the head of the queue. - * @return {*} The item at the head of the queue. It's undefined if the queue is empty. - */ -PriorityQueue.prototype.dequeue = function () { - var node = this.items.maximum(); - var item = undefined; - if (node) { - var queue = node.item; - item = queue.dequeue(); - if (queue.isEmpty()) - this.items.deleteNode(node); - this.length--; - } - return item; -}; - -/** - * Removes the items at the head of the queue. - * @param times {number} The number of times to repeat the dequeue method. - * @return {Array<*>} The items at the head of the queue. - */ -PriorityQueue.prototype.multiDequeue = function (times) { - var items = []; - for (var i = 0; i < times && this.length; i++) - items.push(this.dequeue()); - return items; -}; - -/** - * Removes the first length items from the position index. - * @param index {number} The position where to start to remove the items. - * @param [length = 1] {number} The number of items to remove. - * @return {void} - */ -PriorityQueue.prototype.remove = function (index, length) { - length = length || 1; - var it = this.items.getIterator(); - for (it.last(); !it.isDone() && length > 0; it.previous()) { - var queue = it.getItem(); - if (index > -1 && index < queue.getLength()) { - var oldLength = queue.getLength(); - queue.remove(index, length); - length -= oldLength - index; - index = 0; - if (!queue.getLength()) - this.items.deleteNode(it.getNode()); - } else - index = index - queue.getLength(); - } -}; - -/** - * Returns the item at the position index. - * @param index {number} The index of the item. - * @return {*} The item found. It's undefined if the position index is out of bounds. - */ -PriorityQueue.prototype.getItem = function (index) { - var it = this.items.getIterator(); - for (it.last(); !it.isDone(); it.previous()) { - var queue = it.getItem(); - if (index > -1 && index < queue.getLength()) - return queue.getItem(index); - index = index - queue.getLength(); - } - return undefined; -}; - -/** - * Returns the items relatives to the priority. - * @param priority {number} The priority of the items. - * @return {Array<*>} The items found. - */ -PriorityQueue.prototype.getItems = function (priority) { - var items = this.items.search(priority); - if (items) - return items.items; - return []; -}; - -/** - * Returns the first item in the queue. The item is not removed. - * @return {*} The first item. It's undefined if the queue is empty. - */ -PriorityQueue.prototype.peek = function () { - return this.items.maximum().item.peek(); -}; - -/** - * Returns the length of the queue. - * @return {number} The length of the queue. - */ -PriorityQueue.prototype.getLength = function () { - return this.length; -}; - -/** - * Checks if the queue is empty. - * @return {boolean} True if the queue is empty, false otherwise. - */ -PriorityQueue.prototype.isEmpty = function () { - return !this.length; -}; - -/** - * Removes all the items stored in the queue. - * @return {void} - */ -PriorityQueue.prototype.clear = function () { - this.items = new RBTreeList(); - this.length = 0; -}; - -/** - * Checks if the queue contains a priority that satisfy the condition represented by the callback function. - * @param priority {number} The priority to find. - * @param [callback = function(p){return(p===priority);}] The condition to satisfy. The callback must accept the current priority to check. - * @return {boolean} True if the queue contains the priority that satisfy the condition, false otherwise. - */ -PriorityQueue.prototype.containsPriority = function (priority, callback) { - if (callback) - return this.items.fullContains(callback); - else - return this.items.contains(priority); -}; - -/** - * Returns the queue created by the priority queue with the items in the same order but without the priority. - * @return {Queue} The queue created. - */ -PriorityQueue.prototype.toQueue = function () { - var queue = new Queue(); - var it = this.items.getIterator(); - for (it.last(); !it.isDone(); it.previous()) { - var item = it.getItem(); - var itQ = item.getIterator(); - for (itQ.first(); !itQ.isDone(); itQ.next()) - queue.enqueue(itQ.getItem()); - } - return queue; -}; - -/** - * Executes the callback function for each item of the queue. - * This method modifies the queue so if you don't need to modify it you must return the same item of the array. - * @param callback {function} The function to execute for each item. The function must accept the current item on which execute the function. - * @return {void} - */ -PriorityQueue.prototype.execute = function (callback) { - var it = this.items.getIterator(); - for (it.last(); !it.isDone(); it.previous()) - it.getItem().execute(callback); -}; - -/** - * Changes the priority of the item at the position index. - * @param index {number} The position of the item of which increase the priority. - * @param newPriority {number} The new priority. - * @return {void} - */ -PriorityQueue.prototype.changePriority = function (index, newPriority) { - var item = this.getItem(index); - this.remove(index); - this.enqueue(newPriority, item); -}; - -/** - * Returns the items that satisfy the condition determined by the callback. - * @param callback {function} The function that implements the condition. - * @return {Array<*>} The array that contains the items that satisfy the condition. - */ -PriorityQueue.prototype.filter = function (callback) { - var result = []; - var it = this.items.getIterator(); - for (it.last(); !it.isDone(); it.previous()) { - var itQ = it.getItem().getIterator(); - for (itQ.first(); !itQ.isDone(); itQ.next()) { - if (callback(itQ.getItem())) - result.push(itQ.getItem()); - } - } - return result; -}; - -/** - * Clones the queue into a new queue. - * @return {PriorityQueue} The queue cloned from this queue. - */ -PriorityQueue.prototype.clone = function () { - var queue = new PriorityQueue(); - queue.items = this.items.clone(); - queue.length = this.length; - return queue; -}; - -/** - * Clones the queue into a new queue without cloning duplicated items. - * @return {PriorityQueue} The queue cloned from this queue. - */ -PriorityQueue.prototype.cloneDistinct = function () { - var queue = new PriorityQueue(); - queue.items = this.items.cloneDistinct(); - queue.length = queue.items.getSize(); - return queue; -}; - -/** - * Class that implements the iterator for a priority queue. - * @param aggregate {PriorityQueue} The aggregate to scan. - * @constructor - */ -function PriorityQueueIterator(aggregate) { - /** - * The aggregate relates to this iterator. - * @type {PriorityQueue} - */ - this.aggregate = aggregate; - - /** - * The pointer to the position of the node. - * @type {RBLNode|null} - */ - this.pointerNode = null; - /** - * The pointer to the position in the node. - * @type {number} - */ - this.pointerPosition = -1; -} - -/** - * Moves the iterator to the first position of the aggregate. - * @return {void} - */ -PriorityQueueIterator.prototype.first = function () { - this.pointerNode = this.aggregate.items.maximum(); - this.pointerPosition = 0; -}; - -/** - * Moves the iterator to the next item. - * @return {void} - */ -PriorityQueueIterator.prototype.next = function () { - this.pointerPosition++; - if (this.pointerPosition > this.pointerNode.item.getLength() - 1) { - this.pointerNode = this.pointerNode.previous; - this.pointerPosition = 0; - } -}; - -/** - * Moves the iterator to the last position of the aggregate. - * @return {void} - */ -PriorityQueueIterator.prototype.last = function () { - this.pointerNode = this.aggregate.items.minimum(); - this.pointerPosition = this.pointerNode.item.getLength() - 1; -}; - -/** - * Moves the iterator to the previous item. - * @return {void} - */ -PriorityQueueIterator.prototype.previous = function () { - this.pointerPosition--; - if (this.pointerPosition < 0) { - this.pointerNode = this.pointerNode.next; - if (this.pointerNode) - this.pointerPosition = this.pointerNode.item.getLength() - 1; - } -}; - -/** - * Checks if the iterator is out of the bounds of the aggregate. - * @return {boolean} It return true if the iterator is out of the bounds of the aggregate, otherwise false. - */ -PriorityQueueIterator.prototype.isDone = function () { - return !this.pointerNode; -}; - -/** - * Returns the item stored at the position pointed by the iterator. - * @return {*} The item stored or undefined if it's out of the bounds. - */ -PriorityQueueIterator.prototype.getItem = function () { - return this.pointerNode.item.items[this.pointerPosition]; -}; - -/** - * Class for managing a queue. - * @param {...*} [args] The items for initializing the queue. - * @constructor - */ -function Queue(args) { - /** - * The list of the items in the queue. - * @type {Array<*>} - */ - this.items = []; - - //builds the queue from the parameters of the constructor - this.multiEnqueue(arguments); -} - -/** - * Returns the iterator relative to the aggregate. - * @return {Iterator} The iterator. - */ -Queue.prototype.getIterator = function () { - return new QueueIterator(this); -}; - -/** - * Adds the item at the tail of the queue. - * @param item {*} The item to add. - * @return {void} - */ -Queue.prototype.enqueue = function (item) { - this.items.push(item); -}; - -/** - * Adds the items at the tail of the queue. - * @param items {Array<*>} The items to add. - * @return {void} - */ -Queue.prototype.multiEnqueue = function (items) { - for (var i = 0; i < items.length; i++) - this.items.push(items[i]); -}; - -/** - * Removes the item at the head of the queue. - * @return {*} The item at the head of the queue. It's undefined if the queue is empty. - */ -Queue.prototype.dequeue = function () { - if (!this.items.length) - return undefined; - return this.items.splice(0, 1)[0]; //remove the first item and return it -}; - -/** - * Removes the items at the head of the queue. - * @param times {number} The number of times to repeat the dequeue method. - * @return {Array<*>} The items at the head of the queue. - */ -Queue.prototype.multiDequeue = function (times) { - return this.items.splice(0, times); //removes the last times item and returns the array -}; - -/** - * Removes the first length items from the position index. - * @param index {number} The position where to start to remove the items. - * @param [length = 1] {number} The number of items to remove. - * @return {void} - */ -Queue.prototype.remove = function (index, length) { - length = length || 1; - this.items.splice(index, length); -}; - -/** - * Returns the item at the position index. - * @param index {number} The position of the item. - * @return {*} The item at the position. It's undefined if index isn't in the queue bounds. - */ -Queue.prototype.getItem = function (index) { - if (index < 0 || index > this.items.length - 1) - return undefined; - return this.items[index]; -}; - -/** - * Returns the first item in the queue. The item is not removed. - * @return {*} The first item. It's undefined if the queue is empty. - */ -Queue.prototype.peek = function () { - if (this.items.length) - return this.items[0]; - return undefined -}; - -/** - * Removes all the items stored in the queue. - * @return {void} - */ -Queue.prototype.clear = function () { - this.items = []; -}; - -/** - * Checks if the queue contains an item that satisfy the condition represented by the callback function. - * @param item {*} The item to find. - * @param [callback = function(item){return(it===item);}] The condition to satisfy. The callback must accept the current item to check. - * @return {boolean} True if the queue contains the item that satisfy the condition, false otherwise. - */ -Queue.prototype.contains = function (item, callback) { - callback = callback || function (it) { - return it === item; - }; - var i = 0; - while (i < this.items.length && !callback(this.items[i])) - i++; - return i < this.items.length; -}; - -/** - * Executes the callback function for each item of the queue. - * This method modifies the queue so if you don't need to modify it you must return the same item of the array. - * @param callback {function} The function to execute for each item. The function must accept the current item on which execute the function. - * @return {void} - */ -Queue.prototype.execute = function (callback) { - for (var i = 0; i < this.items.length; i++) - this.items[i] = callback(this.items[i]); -}; - -/** - * Returns the length of the queue. - * @return {number} The length of the queue. - */ -Queue.prototype.getLength = function () { - return this.items.length; -}; - -/** - * Checks if the queue is empty. - * @return {boolean} True if the queue is empty, false otherwise. - */ -Queue.prototype.isEmpty = function () { - return !this.items.length; -}; - -/** - * Returns the items that satisfy the condition determined by the callback. - * @param callback {function} The function that implements the condition. - * @return {Array<*>} The array that contains the items that satisfy the condition. - */ -Queue.prototype.filter = function (callback) { - var result = []; - for (var i = 0; i < this.items.length; i++) - if (callback(this.items[i])) - result.push(this.items[i]); - return result; -}; - -/** - * Returns the first position of the item in the queue. - * @param item {*} The item to search. - * @param [callback = function(item){return(it===item);}] The condition to satisfy. The callback must accept the current item to check. - * @return {number} The first position of the item. - */ -Queue.prototype.indexOf = function (item, callback) { - callback = callback || function (it) { - return it === item; - }; - var i = 0; - while (i < this.items.length) { - if (callback(this.items[i])) - return i; - i++; - } - return -1; -}; - -/** - * Returns the last position of the item in the queue. - * @param item {*} The item to search. - * @param [callback = function(item){return(it===item);}] The condition to satisfy. The callback must accept the current item to check. - * @return {number} The last position of the item. - */ -Queue.prototype.lastIndexOf = function (item, callback) { - callback = callback || function (it) { - return it === item; - }; - var i = this.items.length - 1; - while (i > -1) { - if (callback(this.items[i])) - return i; - i--; - } - return -1; -}; - -/** - * Returns all the position in which the item has been found in the queue. - * @param item {*} The item to search. - * @param [callback = function(item){return(it===item);}] The condition to satisfy. The callback must accept the current item to check. - * @return {Array} The positions in which the item has been found. - */ -Queue.prototype.allIndexesOf = function (item, callback) { - callback = callback || function (it) { - return it === item; - }; - var i = 0; - var indexes = []; - while (i < this.items.length) { - if (callback(this.items[i])) - indexes.push(i); - i++; - } - return indexes; -}; - -/** - * Clones the queue into a new queue. - * @return {Queue} The queue cloned from this queue. - */ -Queue.prototype.clone = function () { - var queue = new Queue(); - for (var i = 0; i < this.items.length; i++) - if (this.items[i].clone) - queue.enqueue(this.items[i].clone()); - else - queue.enqueue(this.items[i]); - - return queue; -}; - -/** - * Clones the queue into a new queue without cloning duplicated items. - * @return {Queue} The queue cloned from this queue. - */ -Queue.prototype.cloneDistinct = function () { - var queue = new Queue(); - for (var i = 0; i < this.items.length; i++) - if (!queue.contains(this.items[i])) - if (this.items[i].cloneDistinct) - queue.enqueue(this.items[i].cloneDistinct()); - else if (this.items[i].clone) - queue.enqueue(this.items[i].clone()); - else - queue.enqueue(this.items[i]); - return queue; -}; - -/** - * Class that implements the iterator for a linked list. - * @param aggregate {Queue} The aggregate to scan. - * @constructor - */ -function QueueIterator(aggregate) { - /** - * The aggregate relates to this iterator. - * @type {Queue} - */ - this.aggregate = aggregate; - - /** - * The pointer to the position. - * @type {number} - */ - this.pointer = -1; -} - -/** - * Moves the iterator to the first position of the aggregate. - * @return {void} - */ -QueueIterator.prototype.first = function () { - this.pointer = 0; -}; - -/** - * Moves the iterator to the next item. - * @return {void} - */ -QueueIterator.prototype.next = function () { - this.pointer++; -}; - -/** - * Moves the iterator to the last position of the aggregate. - * @return {void} - */ -QueueIterator.prototype.last = function () { - this.pointer = this.aggregate.items.length - 1; -}; - -/** - * Moves the iterator to the previous item. - * @return {void} - */ -QueueIterator.prototype.previous = function () { - this.pointer--; -}; - -/** - * Checks if the iterator is out of the bounds of the aggregate. - * @return {boolean} It return true if the iterator is out of the bounds of the aggregate, otherwise false. - */ -QueueIterator.prototype.isDone = function () { - return this.pointer < 0 || this.pointer > this.aggregate.items.length - 1; -}; - -/** - * Returns the item stored at the position pointed by the iterator. - * @return {*} The item stored or undefined if it's out of the bounds. - */ -QueueIterator.prototype.getItem = function () { - return this.aggregate.getItem(this.pointer); -}; - -/** - * Class for managing a red-black tree. - * @constructor - */ -function RBTree() { - /** - * The root of the tree. - * @type {RBNode|null} - */ - this.root = null; - /** - * The number of items stored in the tree. - * @type {number} - */ - this.size = 0; -} - -/** - * Returns the iterator relative to the aggregate. - * @return {Iterator} The iterator. - */ -RBTree.prototype.getIterator = function () { - return new RBTreeIterator(this); -}; - -/** - * Inserts the item relatives to the key value in the tree. - * @param key {number} The key to store. - * @param item {*} The item to store. - * @return {void} - */ -RBTree.prototype.insert = function (key, item) { - var node = new RBNode(key, item); - this.size++; - if (!this.root) { - this.root = node; - node.type = 'b'; - return; - } - var p = this.root; - for (var n = this.root; n;) { - p = n; - if (key < n.key) - n = n.left; - else - n = n.right; - } - node.parent = p; - if (!p) - this.root = node; - else if (key < p.key) - p.left = node; - else - p.right = node; - - this.insertFixUp(node); -}; - -/** - * Preserves the properties of the tree after an insert. - * @param node {RBNode} The node to insert. - * @return {void} - */ -RBTree.prototype.insertFixUp = function (node) { - for (var parent = node.parent; parent && parent.type === 'r'; parent = node.parent) { - if (parent === parent.parent.left) { - var uncle = parent.parent.right; - if (uncle && uncle.type === 'r') { - parent.type = 'b'; - uncle.type = 'b'; - parent.parent.type = 'r'; - node = parent.parent; - } else if (node === parent.right) { - node = parent; - this.leftRotate(node); - } else { - parent.type = 'b'; - parent.parent.type = 'r'; - this.rightRotate(parent.parent); - } - } else { - var uncle = parent.parent.left; - if (uncle && uncle.type === 'r') { - parent.type = 'b'; - uncle.type = 'b'; - parent.parent.type = 'r'; - node = parent.parent; - } else if (node === parent.left) { - node = parent; - this.rightRotate(node); - } else { - parent.type = 'b'; - parent.parent.type = 'r'; - this.leftRotate(parent.parent); - } - } - } - this.root.type = 'b'; -}; - -/** - * Deletes the node from the tree. - * @param node {RBNode} The node to delete. - * @return {void} - */ -RBTree.prototype.deleteNode = function (node) { - var successor; - this.size--; - if (!node.left || !node.right) - successor = node; - else { - successor = this.successor(node); - node.key = successor.key; - node.item = successor.item; - } - var child; - if (!successor.left) - child = successor.right; - else - child = successor.left; - if (child) - child.parent = successor.parent; - if (!successor.parent) - this.root = child; - else if (successor === successor.parent.left) - successor.parent.left = child; - else - successor.parent.right = child; - - if (successor.type === 'b') - this.deleteFixUp(child, successor.parent); -}; - -/** - * Preserves the properties of the tree after a deletion. - * @param node {RBNode} The node to delete. - * @param parent {RBNode} The parent of the node. - * @return {void} - */ -RBTree.prototype.deleteFixUp = function (node, parent) { - while (node !== this.root && (!node || node.type === 'b')) { - if (node === parent.left) { - var brother = parent.right; - if (brother && brother.type === 'r') { - brother.type = 'b'; - parent.type = 'r'; - this.leftRotate(parent); - brother = parent.right; - } - if (brother && (!brother.left || brother.left.type === 'b') && (!brother.right || brother.right.type === 'b')) { - brother.type = 'r'; - node = parent; - } else { - if (!brother.right || brother.right.type === 'b') { - brother.left.type = 'b'; - brother.type = 'r'; - this.rightRotate(brother); - brother = parent.right; - } - brother.type = parent.type; - parent.type = 'b'; - brother.right.type = 'b'; - this.leftRotate(parent); - node = this.root; - } - } else { - var brother = parent.left; - if (brother && brother.type === 'r') { - brother.type = 'b'; - parent.type = 'r'; - this.rightRotate(parent); - brother = parent.left; - } - if (brother && (!brother.left || brother.left.type === 'b') && (!brother.right || brother.right.type === 'b')) { - brother.type = 'r'; - node = parent; - } else { - if (!brother.left || brother.left.type === 'b') { - brother.right.type = 'b'; - brother.type = 'r'; - this.leftRotate(brother); - brother = parent.left; - } - brother.type = parent.type; - parent.type = 'b'; - brother.left.type = 'b'; - this.rightRotate(parent); - node = this.root; - } - } - parent = node.parent; - } - if (node) - node.type = 'b'; -}; - -/** - * Gets the node with the key next to the param node key. - * @param node {RBNode} The node of which search the successor. - * @return {RBNode} The node found. - */ -RBTree.prototype.successor = function (node) { - if (node.right) - return this.minimum(node.right); - var parent = node.parent; - while (parent && node === parent.right) { - node = parent; - parent = parent.parent; - } - return parent; -}; - -/** - * Gets the node with the key previous to the param node key. - * @param node {RBNode} The node of which search the predecessor. - * @return {RBNode} The node found. - */ -RBTree.prototype.predecessor = function (node) { - if (node.left) - return this.maximum(node.left); - var parent = node.parent; - while (parent && node === parent.left) { - node = parent; - parent = parent.parent; - } - return parent; -}; - -/** - * Searches the item relatives to the key and to the nodes that satisfy the condition represented by the callback function. - * @param key {number} The key to find. - * @param [node = root] {RBNode} The node from which start the search. - * @param [callback = function(node){return(node.key===key);}] The condition to satisfy. The callback must accept the current node to check. - * @return {*} The item found or undefined if there isn't the key in the tree. - */ -RBTree.prototype.search = function (key, node, callback) { - node = node || this.root; - callback = callback || function (node) { - return node.key === key; - }; - while (node && !callback(node)) - if (key < node.key) - node = node.left; - else - node = node.right; - if (node) - return node.item; - return undefined; -}; - -/** - * Checks if the tree contains a key or a node that satisfy the condition represented by the callback function. - * This method avoid to search in branches where the key won't be found. - * @param key {*} The key to find. - * @param [callback = function(node){return(node.key===key);}] The condition to satisfy. The callback must accept the current node to check. - * @return {boolean} True if the tree contains the key or a node that satisfy the condition, false otherwise. - */ -RBTree.prototype.contains = function (key, callback) { - return this.search(key, null, callback) !== undefined; -}; - -/** - * Checks if the tree contains a node that satisfy the condition represented by the callback function. - * This method check all the tree avoiding the binary search. - * @param callback {function} The condition to satisfy. The callback must accept the current node to check. - * @return {boolean} True if the tree contains the node that satisfy the condition, false otherwise. - */ -RBTree.prototype.fullContains = function (callback) { - var node = this.minimum(); - while (node && !callback(node.key)) - node = this.successor(node); - return node !== null; -}; - -/** - * Gets the item relatives to the minimum key stored in the tree. - * @param [node = root] {Node} The node from which start the search. - * @return {RBNode} The node found. - */ -RBTree.prototype.minimum = function (node) { - node = node || this.root; - while (node && node.left) - node = node.left; - return node; -}; - -/** - * Gets the item relatives to the maximum key stored in the tree. - * @param [node = root] {Node} The node from which start the search. - * @return {RBNode} The node found. - */ -RBTree.prototype.maximum = function (node) { - node = node || this.root; - while (node && node.right) - node = node.right; - return node; -}; - -/** - * Rotates the node with its right child. - * @param node {RBNode} The node to rotate. - * @return {void} - */ -RBTree.prototype.leftRotate = function (node) { - var child = node.right; - node.right = child.left; - if (child.left !== null) - child.left.parent = node; - child.parent = node.parent; - if (node.parent === null) - this.root = child; - else if (node === node.parent.left) - node.parent.left = child; - else - node.parent.right = child; - node.parent = child; - child.left = node; -}; - -/** - * Rotates the node with its left child. - * @param node {RBNode} The node to rotate. - * @return {void} - */ -RBTree.prototype.rightRotate = function (node) { - var child = node.left; - node.left = child.right; - if (child.right !== null) - child.right.parent = node; - child.parent = node.parent; - if (node.parent === null) - this.root = child; - else if (node === node.parent.left) - node.parent.left = child; - else - node.parent.right = child; - node.parent = child; - child.right = node; -}; - -/** - * Returns the size of the tree. - * @return {number} The size of the tree. - */ -RBTree.prototype.getSize = function () { - return this.size; -}; - -/** - * Clones the queue into a new queue. - * @return {RBTree} The tree cloned from this queue. - */ -RBTree.prototype.clone = function () { - var tree = new RBTree(); - var it = this.getIterator(); - for (it.first(); !it.isDone(); it.next()) - if (it.getNode().item.clone) - tree.insert(it.getNode().key, it.getNode().item.clone()); - else - tree.insert(it.getNode().key, it.getNode().item); - - return tree; -}; - -/** - * Clones the tree into a new tree without cloning duplicated items. - * @return {RBTree} The tree cloned from this tree. - */ -RBTree.prototype.cloneDistinct = function () { - var tree = new RBTree(); - var it = this.getIterator(); - for (it.first(); !it.isDone(); it.next()) { - var callback = function (node) { - return node.key === it.getNode().key && node.item === it.getNode().item; - }; - if (!tree.contains(it.getNode().key, callback)) { - if (it.getNode().item.cloneDistinct) - tree.insert(it.getNode().key, it.getNode().item.cloneDistinct()); - else if (it.getNode().item.clone) - tree.insert(it.getNode().key, it.getNode().item.clone()); - else - tree.insert(it.getNode().key, it.getNode().item); - } - } - return tree; -}; - -/** - * Transforms the tree into an array without preserving keys. - * @return {Array<*>} The array that represents the tree. - */ -RBTree.prototype.toArray = function () { - var result = []; - for (var node = this.minimum(); node; node = this.successor(node)) - result.push(node.item); - return result; -}; - -/** - * Removes all the items stored in the tree. - * @return {void} - */ -RBTree.prototype.clear = function () { - this.root = null; - this.size = 0; -}; - -/** - * Checks if the tree is empty. - * @return {boolean} True if the tree is empty, false otherwise. - */ -RBTree.prototype.isEmpty = function () { - return !this.size; -}; - -/** - * Executes the callback function for each item of the tree. - * This method modifies the tree so if you don't need to modify it you must return the same item stored. - * @param callback {function} The function to execute for each item. The function must accept the current item on which execute the function. - * @return {void} - */ -RBTree.prototype.execute = function (callback) { - for (var node = this.minimum(); node; node = this.successor(node)) - node.item = callback(node.item); -}; - -/** - * Returns the items that satisfy the condition determined by the callback. - * @param callback {function} The function that implements the condition. - * @return {Array<*>} The array that contains the items that satisfy the condition. - */ -RBTree.prototype.filter = function (callback) { - var result = []; - for (var node = this.minimum(); node; node = this.successor(node)) - if (callback(node.item)) - result.push(node.item); - return result; -}; - -/** - * Returns the first position of the item in the tree. - * @param item {*} The item to search. - * @param [callback = function(item){return(it===item);}] The condition to satisfy. The callback must accept the current item to check. - * @return {number} The first position of the item. - */ -RBTree.prototype.indexOf = function (item, callback) { - callback = callback || function (it) { - return it === item; - }; - var i = 0, node = this.minimum(); - while (node) { - if (callback(node.item)) - return i; - node = this.successor(node); - i++; - } - return -1; -}; - -/** - * Returns the last position of the item in the tree. - * @param item {*} The item to search. - * @param [callback = function(item){return(it===item);}] The condition to satisfy. The callback must accept the current item to check. - * @return {number} The last position of the item. - */ -RBTree.prototype.lastIndexOf = function (item, callback) { - callback = callback || function (it) { - return it === item; - }; - var i = this.size - 1, node = this.maximum(); - while (node) { - if (callback(node.item)) - return i; - i--; - node = this.predecessor(node); - } - return -1; -}; - -/** - * Returns all the position in which the item has been found in the tree. - * @param item {*} The item to search. - * @param [callback = function(item){return(it===item);}] The condition to satisfy. The callback must accept the current item to check. - * @return {Array} The positions in which the item has been found. - */ -RBTree.prototype.allIndexesOf = function (item, callback) { - callback = callback || function (it) { - return it === item; - }; - var i = 0, node = this.minimum(); - var indexes = []; - while (node) { - if (callback(node.item)) - indexes.push(i); - i++; - node = this.successor(node); - } - return indexes; -}; - -/** - * Returns the item at the position index. - * @param index {number} The position of the item. - * @return {*} The item at the position. It's undefined if index isn't in the tree bounds. - */ -RBTree.prototype.getItem = function (index) { - if (index < 0 || index > this.size - 1) - return undefined; - for (var node = this.minimum(), i = 0; i < index; node = this.successor(node)) - i++; - return node.item; -}; - -/** - * Class that implements the iterator for a red-black tree. - * @param aggregate {RBTree} The aggregate to scan. - * @constructor - */ -function RBTreeIterator(aggregate) { - /** - * The aggregate relates to this iterator. - * @type {RBTree} - */ - this.aggregate = aggregate; - - /** - * The pointer to the position. - * @type {RBNode|null} - */ - this.pointer = null; -} - -/** - * Moves the iterator to the first position of the aggregate. - * @return {void} - */ -RBTreeIterator.prototype.first = function () { - this.pointer = this.aggregate.minimum(); -}; - -/** - * Moves the iterator to the next item. - * @return {void} - */ -RBTreeIterator.prototype.next = function () { - this.pointer = this.aggregate.successor(this.pointer); -}; - -/** - * Moves the iterator to the last position of the aggregate. - * @return {void} - */ -RBTreeIterator.prototype.last = function () { - this.pointer = this.aggregate.maximum(); -}; - -/** - * Moves the iterator to the previous item. - * @return {void} - */ -RBTreeIterator.prototype.previous = function () { - this.pointer = this.aggregate.predecessor(this.pointer); -}; - -/** - * Checks if the iterator is out of the bounds of the aggregate. - * @return {boolean} It return true if the iterator is out of the bounds of the aggregate, otherwise false. - */ -RBTreeIterator.prototype.isDone = function () { - return !this.pointer; -}; - -/** - * Returns the item stored at the position pointed by the iterator. - * @return {Object|undefined} The item stored or undefined if it's out of the bounds. - */ -RBTreeIterator.prototype.getItem = function () { - return this.pointer.item; -}; - -/** - * Returns the node stored at the position pointed by the iterator. - * @return {RBNode|null} The node stored or null if it's out of the bounds. - */ -RBTreeIterator.prototype.getNode = function () { - return this.pointer; -}; - -/** - * Class for managing a red-black tree where nodes are also in a list. - * @constructor - */ -function RBTreeList() { - /** - * The root of the tree. - * @type {RBLNode|null} - */ - this.root = null; - /** - * The first node of the tree. - * @type {RBLNode|null} - */ - this.first = null; - /** - * The last node of the tree. - * @type {RBLNode|null} - */ - this.last = null; - /** - * The size of the tree. - * @type {number} - */ - this.size = 0; -} - -/** - * Returns the iterator relative to the aggregate. - * @return {Iterator} The iterator. - */ -RBTreeList.prototype.getIterator = function () { - return new RBTreeListIterator(this); -}; - -/** - * Inserts the item relatives to the key value in the tree. - * @param key {number} The key to store. - * @param item {*} The item to store. - * @return {void} - */ -RBTreeList.prototype.insert = function (key, item) { - var node = new RBLNode(key, item); - this.size++; - if (!this.root) { - this.root = node; - this.first = node; - this.last = node; - node.type = 'b'; - return; - } - var p = this.root; - for (var n = this.root; n;) { - p = n; - if (key < n.key) - n = n.left; - else - n = n.right; - } - node.parent = p; - if (!p) - this.root = node; - else if (key < p.key) - p.left = node; - else - p.right = node; - - node.next = this.successor(node); - if (node.next) { - if (node.next.previous) - node.next.previous.next = node; - else - this.first = node; - node.previous = node.next.previous; - node.next.previous = node; - } else { - this.last = node; - node.previous = this.predecessor(node); - if (node.previous) - node.previous.next = node; - else - this.first = node; - } - - this.insertFixUp(node); -}; - -/** - * Preserves the properties of the tree after an insert. - * @param node {RBLNode} The node to insert. - * @return {void} - */ -RBTreeList.prototype.insertFixUp = function (node) { - for (var parent = node.parent; parent && parent.type === 'r'; parent = node.parent) { - if (parent === parent.parent.left) { - var uncle = parent.parent.right; - if (uncle && uncle.type === 'r') { - parent.type = 'b'; - uncle.type = 'b'; - parent.parent.type = 'r'; - node = parent.parent; - } else if (node === parent.right) { - node = parent; - this.leftRotate(node); - } else { - parent.type = 'b'; - parent.parent.type = 'r'; - this.rightRotate(parent.parent); - } - } else { - var uncle = parent.parent.left; - if (uncle && uncle.type === 'r') { - parent.type = 'b'; - uncle.type = 'b'; - parent.parent.type = 'r'; - node = parent.parent; - } else if (node === parent.left) { - node = parent; - this.rightRotate(node); - } else { - parent.type = 'b'; - parent.parent.type = 'r'; - this.leftRotate(parent.parent); - } - } - } - this.root.type = 'b'; -}; - -/** - * Deletes the node from the tree. - * @param node {RBLNode} The node to delete. - * @return {void} - */ -RBTreeList.prototype.deleteNode = function (node) { - this.size--; - var successor; - if (!node.left || !node.right) - successor = node; - else { - successor = this.successor(node); - node.key = successor.key; - node.item = successor.item; - } - var child; - if (!successor.left) - child = successor.right; - else - child = successor.left; - if (child) - child.parent = successor.parent; - if (!successor.parent) - this.root = child; - else if (successor === successor.parent.left) - successor.parent.left = child; - else - successor.parent.right = child; - - if (successor.next) - successor.next.previous = successor.previous; - else - this.last = successor.previous; - if (successor.previous) - successor.previous.next = successor.next; - else - this.first = successor.next; - - if (successor.type === 'b') - this.deleteFixUp(child, successor.parent); -}; - -/** - * Preserves the properties of the tree after a deletion. - * @param node {RBLNode} The node to delete. - * @param parent {RBLNode} The parent of the node. - * @return {void} - */ -RBTreeList.prototype.deleteFixUp = function (node, parent) { - while (node !== this.root && (!node || node.type === 'b')) { - if (node === parent.left) { - var brother = parent.right; - if (brother && brother.type === 'r') { - brother.type = 'b'; - parent.type = 'r'; - this.leftRotate(parent); - brother = parent.right; - } - if (brother && (!brother.left || brother.left.type === 'b') && (!brother.right || brother.right.type === 'b')) { - brother.type = 'r'; - node = parent; - } else { - if (!brother.right || brother.right.type === 'b') { - brother.left.type = 'b'; - brother.type = 'r'; - this.rightRotate(brother); - brother = parent.right; - } - brother.type = parent.type; - parent.type = 'b'; - brother.right.type = 'b'; - this.leftRotate(parent); - node = this.root; - } - } else { - var brother = parent.left; - if (brother && brother.type === 'r') { - brother.type = 'b'; - parent.type = 'r'; - this.rightRotate(parent); - brother = parent.left; - } - if (brother && (!brother.left || brother.left.type === 'b') && (!brother.right || brother.right.type === 'b')) { - brother.type = 'r'; - node = parent; - } else { - if (!brother.left || brother.left.type === 'b') { - brother.right.type = 'b'; - brother.type = 'r'; - this.leftRotate(brother); - brother = parent.left; - } - brother.type = parent.type; - parent.type = 'b'; - brother.left.type = 'b'; - this.rightRotate(parent); - node = this.root; - } - } - parent = node.parent; - } - if (node) - node.type = 'b'; -}; - -/** - * Gets the node with the key next to the param node key. - * @param node {RBLNode} The node of which search the successor. - * @return {RBLNode} The node found. - */ -RBTreeList.prototype.successor = function (node) { - if (node.next || node === this.last) - return node.next; - if (node.right) - return this.minimum(node.right); - var parent = node.parent; - while (parent && node === parent.right) { - node = parent; - parent = parent.parent; - } - return parent; -}; - -/** - * Gets the node with the key previous to the param node key. - * @param node {RBLNode} The node of which search the predecessor. - * @return {RBLNode} The node found. - */ -RBTreeList.prototype.predecessor = function (node) { - if (node.previous || node === this.first) - return node.previous; - if (node.left) - return this.maximum(node.left); - var parent = node.parent; - while (parent && node === parent.left) { - node = parent; - parent = parent.parent; - } - return parent; -}; - -/** - * Searches the item relatives to the key that satisfy the condition represented by the callback function. - * @param key {number} The key to find. - * @param [node = root] {RBNode} The node from which start the search. - * @param [callback = function(k){return(k===key);}] The condition to satisfy. The callback must accept the current key to check. - * @return {*} The item found or undefined if there isn't the key in the tree. - */ -RBTreeList.prototype.search = function (key, node, callback) { - node = node || this.root; - callback = callback || function (node) { - return node.key === key; - }; - while (node && !callback(node)) - if (key < node.key) - node = node.left; - else - node = node.right; - if (node) - return node.item; - return undefined; -}; - -/** - * Checks if the tree contains a key or a node that satisfy the condition represented by the callback function. - * This method avoid to search in branches where the key won't be found. - * @param key {*} The key to find. - * @param [callback = function(node){return(node.key===key);}] The condition to satisfy. The callback must accept the current node to check. - * @return {boolean} True if the tree contains the key or a node that satisfy the condition, false otherwise. - */ -RBTreeList.prototype.contains = function (key, callback) { - return this.search(key, null, callback) !== undefined; -}; - -/** - * Checks if the tree contains a node that satisfy the condition represented by the callback function. - * This method check all the tree avoiding the binary search. - * @param callback {function} The condition to satisfy. The callback must accept the current node to check. - * @return {boolean} True if the tree contains the node that satisfy the condition, false otherwise. - */ -RBTreeList.prototype.fullContains = function (callback) { - var node = this.first; - while (node && !callback(node.key)) - node = node.next; - return node !== null; -}; - -/** - * Gets the item relatives to the minimum key stored in the tree. - * @param [node = root] {Node} The node from which start the search. - * @return {RBLNode} The node found. - */ -RBTreeList.prototype.minimum = function (node) { - if (node) - while (node && node.left) - node = node.left; - else - return this.first; - return node; -}; - -/** - * Gets the item relatives to the maximum key stored in the tree. - * @param [node = root] {Node} The node from which start the search. - * @return {RBLNode} The node found. - */ -RBTreeList.prototype.maximum = function (node) { - if (node) - while (node && node.right) - node = node.right; - else - return this.last; - return node; -}; - -/** - * Rotates the node with its right child. - * @param node {RBLNode} The node to rotate. - * @return {void} - */ -RBTreeList.prototype.leftRotate = function (node) { - var child = node.right; - node.right = child.left; - if (child.left !== null) - child.left.parent = node; - child.parent = node.parent; - if (node.parent === null) - this.root = child; - else if (node === node.parent.left) - node.parent.left = child; - else - node.parent.right = child; - node.parent = child; - child.left = node; -}; - -/** - * Rotates the node with its left child. - * @param node {RBLNode} The node to rotate. - * @return {void} - */ -RBTreeList.prototype.rightRotate = function (node) { - var child = node.left; - node.left = child.right; - if (child.right !== null) - child.right.parent = node; - child.parent = node.parent; - if (node.parent === null) - this.root = child; - else if (node === node.parent.left) - node.parent.left = child; - else - node.parent.right = child; - node.parent = child; - child.right = node; -}; - -/** - * Returns the size of the tree. - * @return {number} The size of the tree. - */ -RBTreeList.prototype.getSize = function () { - return this.size; -}; - -/** - * Clones the tree into a new tree. - * @return {RBTreeList} The tree cloned from this tree. - */ -RBTreeList.prototype.clone = function () { - var tree = new RBTreeList(); - var it = this.getIterator(); - for (it.first(); !it.isDone(); it.next()) - tree.insert(it.getNode().key, it.getNode().item); - return tree; -}; - -/** - * Clones the tree into a new tree without cloning duplicated items. - * @return {RBTreeList} The tree cloned from this tree. - */ -RBTreeList.prototype.cloneDistinct = function () { - var tree = new RBTreeList(); - var it = this.getIterator(); - for (it.first(); !it.isDone(); it.next()) { - var callback = function (node) { - return node.key === it.getNode().key && node.item === it.getNode().item; - }; - if (!tree.contains(it.getNode().key, callback)) { - if (it.getNode().item.cloneDistinct) - tree.insert(it.getNode().key, it.getNode().item.cloneDistinct()); - else if (it.getNode().item.clone) - tree.insert(it.getNode().key, it.getNode().item.clone()); - else - tree.insert(it.getNode().key, it.getNode().item); - } - } - return tree; -}; - -/** - * Transforms the tree into an array without preserving keys. - * @return {Array<*>} The array that represents the tree. - */ -RBTreeList.prototype.toArray = function () { - var result = []; - for (var node = this.first; node; node = node.next) - result.push(node.item); - return result; -}; - -/** - * Removes all the items stored in the tree. - * @return {void} - */ -RBTreeList.prototype.clear = function () { - this.root = null; - this.first = null; - this.last = null; - this.size = 0; -}; - -/** - * Checks if the tree is empty. - * @return {boolean} True if the tree is empty, false otherwise. - */ -RBTreeList.prototype.isEmpty = function () { - return !this.size; -}; - -/** - * Executes the callback function for each item of the tree. - * This method modifies the tree so if you don't need to modify it you must return the same item stored. - * @param callback {function} The function to execute for each item. The function must accept the current item on which execute the function. - * @return {void} - */ -RBTreeList.prototype.execute = function (callback) { - for (var node = this.first; node; node = node.next) - node.item = callback(node.item); -}; - -/** - * Returns the items that satisfy the condition determined by the callback. - * @param callback {function} The function that implements the condition. - * @return {Array<*>} The array that contains the items that satisfy the condition. - */ -RBTreeList.prototype.filter = function (callback) { - var result = []; - for (var node = this.first; node; node = node.next) - if (callback(node.item)) - result.push(node.item); - return result; -}; - -/** - * Returns the first position of the item in the tree. - * @param item {*} The item to search. - * @param [callback = function(item){return(it===item);}] The condition to satisfy. The callback must accept the current item to check. - * @return {number} The first position of the item. - */ -RBTreeList.prototype.indexOf = function (item, callback) { - callback = callback || function (it) { - return it === item; - }; - var i = 0, node = this.first; - while (node) { - if (callback(node.item)) - return i; - node = node.next; - i++; - } - return -1; -}; - -/** - * Returns the last position of the item in the tree. - * @param item {*} The item to search. - * @param [callback = function(item){return(it===item);}] The condition to satisfy. The callback must accept the current item to check. - * @return {number} The last position of the item. - */ -RBTreeList.prototype.lastIndexOf = function (item, callback) { - callback = callback || function (it) { - return it === item; - }; - var i = this.size - 1, node = this.last; - while (node) { - if (callback(node.item)) - return i; - i--; - node = node.previous; - } - return -1; -}; - -/** - * Returns all the position in which the item has been found in the tree. - * @param item {*} The item to search. - * @param [callback = function(item){return(it===item);}] The condition to satisfy. The callback must accept the current item to check. - * @return {Array} The positions in which the item has been found. - */ -RBTreeList.prototype.allIndexesOf = function (item, callback) { - callback = callback || function (it) { - return it === item; - }; - var i = 0, node = this.first; - var indexes = []; - while (node) { - if (callback(node.item)) - indexes.push(i); - i++; - node = node.next; - } - return indexes; -}; - -/** - * Returns the item at the position index. - * @param index {number} The position of the item. - * @return {*} The item at the position. It's undefined if index isn't in the tree bounds. - */ -RBTreeList.prototype.getItem = function (index) { - if (index < 0 || index > this.size - 1) - return undefined; - for (var node = this.first, i = 0; i < index; node = node.next) - i++; - return node.item; -}; - -/** - * Class that implements the iterator for a red-black tree. - * @param aggregate {RBTreeList} The aggregate to scan. - * @constructor - */ -function RBTreeListIterator(aggregate) { - /** - * The aggregate relates to this iterator. - * @type {RBTreeList} - */ - this.aggregate = aggregate; - /** - * The pointer to the position. - * @type {RBLNode|null} - */ - this.pointer = null; -} - -/** - * Moves the iterator to the first position of the aggregate. - * @return {void} - */ -RBTreeListIterator.prototype.first = function () { - this.pointer = this.aggregate.first; -}; - -/** - * Moves the iterator to the next item. - * @return {void} - */ -RBTreeListIterator.prototype.next = function () { - this.pointer = this.pointer.next; -}; - -/** - * Moves the iterator to the last position of the aggregate. - * @return {void} - */ -RBTreeListIterator.prototype.last = function () { - this.pointer = this.aggregate.last; -}; - -/** - * Moves the iterator to the previous item. - * @return {void} - */ -RBTreeListIterator.prototype.previous = function () { - this.pointer = this.pointer.previous; -}; - -/** - * Checks if the iterator is out of the bounds of the aggregate. - * @return {boolean} It return true if the iterator is out of the bounds of the aggregate, otherwise false. - */ -RBTreeListIterator.prototype.isDone = function () { - return !this.pointer; -}; - -/** - * Returns the item stored at the position pointed by the iterator. - * @return {*} The item stored or undefined if it's out of the bounds. - */ -RBTreeListIterator.prototype.getItem = function () { - return this.pointer.item; -}; - -/** - * Returns the node stored at the position pointed by the iterator. - * @abstract - * @return {RBNode|null} The node stored or null if it's out of the bounds. - */ -RBTreeListIterator.prototype.getNode = function () { - return this.pointer; -}; - -/** - * Class for managing a set. - * @constructor - */ -function Set() { - /** - * The parents of the set. - * @type {DoubleLinkedList} - */ - this.parents = new DoubleLinkedList(); - /** - * The elements stored. - * @type {DoubleLinkedList} - */ - this.elements = new DoubleLinkedList(); - /** - * The subsets of this set. - * @type {DoubleLinkedList} - */ - this.sets = new DoubleLinkedList(); - /** - * The size of the set. It's equal to his cardinality. - * @type {number} - */ - this.size = 0; -} - -/** - * Adds the element to the set. - * @param element {Element} The element to add. - * @return {void} - */ -Set.prototype.insert = function (element) { - this.elements.pushBack(element); - element.parents.pushBack(this); - this.size++; -}; - -/** - * Adds the elements to the set. - * @param elements {Array} The elements to add. - * @return {void} - */ -Set.prototype.multiInsert = function (elements) { - for (var i = 0; i < elements.length; i++) { - this.elements.pushBack(elements[i]); - elements[i].parents.pushBack(this); - } - this.size += elements.length; -}; - -/** - * Returns the set that represents the union of two sets. - * @param set {Set} The set with make the union. - * @return {Set} The set that represents the union. - */ -Set.prototype.union = function (set) { - var parent = new Set(); - parent.addSubsets([this, set]); - this.parents.pushBack(parent); - set.parents.pushBack(parent); - //change the parent of the subset - var that = this; - var f = function (item) { - if (item === that) - return parent; - }; - var it = this.sets.getIterator(); - for (it.first(); !it.isDone(); it.next()) - it.getItem().parents.execute(f); - f = function (item) { - if (item === set) - return parent; - }; - it = set.sets.getIterator(); - for (it.first(); !it.isDone(); it.next()) - it.getItem().parents.execute(f); - return parent; -}; - -/** - * Returns the set that represents the intersection of two sets. - * @param set {Set} The set to intersect with this. - * @return {Set} The set that represents the intersection. - */ -Set.prototype.intersect = function (set) { - var intersection = new Set(); - //intersect this set with the set - var el = this.elements.getIterator(); - for (el.first(); !el.isDone(); el.next()) - if (el.getItem().parents.contains(set)) - intersection.insert(el.getItem()); - - //intersect the subsets with the set - var it = this.sets.getIterator(); - for (it.first(); !it.isDone(); it.next()) { - el = it.getItem().getIterator(); - for (el.first(); !el.isDone(); el.next()) - if (el.getItem().parents.contains(set)) - intersection.insert(el.getItem()); - } - return intersection; -}; - -/** - * Returns the set that represents the difference of two sets. - * @param set {Set} The set to difference with this. - * @return {Set} The set that represents the difference. - */ -Set.prototype.difference = function (set) { - var diff = new Set(); - //intersect this set with the set - var el = this.elements.getIterator(); - for (el.first(); !el.isDone(); el.next()) - if (!el.getItem().parents.contains(set)) - diff.insert(el.getItem()); - - //intersect the subsets with the set - var it = this.sets.getIterator(); - for (it.first(); !it.isDone(); it.next()) { - el = it.getItem().getIterator(); - for (el.first(); !el.isDone(); el.next()) - if (!el.getItem().parents.contains(set)) - diff.insert(el.getItem()); - } - return diff; -}; - -/** - * Returns the set that represents the cartesian product of two sets. - * @param set {Set} The set to make the cartesian product with this. - * @return {Set} The set that represents the cartesian product . - */ -Set.prototype.cartesianProduct = function (set) { - var el1 = this.getItems(); - var el2 = set.getItems(); - var product = new Set(); - for (var i = 0; i < el1.length; i++) - for (var j = 0; j < el2.length; j++) - product.insert(new Element([el1[i], el2[j]])); - return product; -}; - -/** - * Adds the subset. - * @param set {Set} The subset. - */ -Set.prototype.addSubset = function (set) { - this.sets.pushBack(set); - this.size += set.size; -}; - -/** - * Adds the subsets. - * @param sets {Array} The subsets. - */ -Set.prototype.addSubsets = function (sets) { - for (var i = 0; i < sets.length; i++) - this.addSubset(sets[i]); -}; - -/** - * Returns the items that are stored in the set. - * @return {Array} The items stored. - */ -Set.prototype.getItems = function () { - var array = []; - //get the items stored in the set - var el = this.elements.getIterator(); - for (el.first(); !el.isDone(); el.next()) - array.push(el.getItem().item); - - //get the items stored in the subsets - var it = this.sets.getIterator(); - for (it.first(); !it.isDone(); it.next()) { - el = it.getItem().getIterator(); - for (el.first(); !el.isDone(); el.next()) - array.push(el.getItem().item); - } - return array; -}; - -/** - * Returns the cardinality of the set. - * @return {number} The cardinality of the set. - */ -Set.prototype.getCardinality = function () { - return this.size; -}; - -/** - * Checks if the set is empty. - * @return {boolean} True if the set is empty, false otherwise. - */ -Set.prototype.isEmpty = function () { - return !this.size; -}; - -/** - * Clones the set into a new set. - * @return {Set} The set cloned from this set. - */ -Set.prototype.clone = function () { - var s = new Set(); - s.parents = this.parents.clone(); - s.elements = this.elements.clone(); - s.sets = this.sets.clone(); - s.size = this.size; - return s; -}; - -/** - * Class for managing a stack. - * @param {...*} [args] The items for initializing the stack. - * @constructor - */ -function Stack(args) { - /** - * The list of the items in the stack. - * @type {Array<*>} - */ - this.items = []; - - //builds the stack from the parameters of the constructor - this.multiPush(arguments); -} - -/** - * Returns the iterator relative to the aggregate. - * @return {Iterator} The iterator. - */ -Stack.prototype.getIterator = function () { - return new StackIterator(this); -}; - -/** - * Adds the item at the top of the stack. - * @param item {*} The item to add. - * return {void} - */ -Stack.prototype.push = function (item) { - this.items.push(item); -}; - -/** - * Adds the items at the top of the stack. - * @param items {Array<*>} The items to add. - * @return {void} - */ -Stack.prototype.multiPush = function (items) { - for (var i = 0; i < items.length; i++) - this.push(items[i]); -}; - -/** - * Removes the item at the top of the stack. - * @return {*} The item at the top of the stack. It's undefined if the stack is empty. - */ -Stack.prototype.pop = function () { - if (!this.items.length) - return undefined; - return this.items.pop(); -}; - -/** - * Removes the more item at the top of the stack. - * @param times {number} The number of times to repeat the pop method. - * @return {Array<*>} The items at the top of the stack. - */ -Stack.prototype.multiPop = function (times) { - var result = []; - for (var i = 0; i < times && this.items.length; i++) - result.push(this.pop()); - return result; -}; - -/** - * Returns the item at the top of the stack without remove it. - * @return {*} The item at the top of the stack. It's undefined if the stack is empty. - */ -Stack.prototype.peek = function () { - if (!this.items.length) - return undefined; - return this.items[this.items.length - 1]; -}; - -/** - * Removes all the items stored in the stack. - * @return {void} - */ -Stack.prototype.clear = function () { - this.items = []; -}; - -/** - * Checks if the stack contains an item that satisfy the condition represented by the callback function. - * @param item {*} The item to find. - * @param [callback = function(item){return(it===item);}] The condition to satisfy. The callback must accept the current item to check. - * @return {boolean} True if the stack contains the item that satisfy the condition, false otherwise. - */ -Stack.prototype.contains = function (item, callback) { - callback = callback || function (it) { - return it === item; - }; - var i = 0; - while (i < this.items.length && !callback(this.items[i])) - i++; - return i < this.items.length; -}; - -/** - * Executes the callback function for each item of the stack. - * This method modifies the stack so if you don't need to modify it you must return the same item of the array. - * @param callback {function} The function to execute for each item. The function must accept the current item on which execute the function. - * @return {void} - */ -Stack.prototype.execute = function (callback) { - for (var i = this.items.length - 1; i > -1; i--) - this.items[i] = callback(this.items[i]); -}; - -/** - * Returns the item at the position index. - * @param index The position of the item. - * @return {*} The item at the position. It's undefined if index isn't in the stack bounds. - */ -Stack.prototype.getItem = function (index) { - if (index < 0 || index > this.items.length - 1) - return undefined; - return this.items[this.items.length - index - 1]; -}; - -/** - * Returns the length of the stack. - * @return {Number} The length of the stack. - */ -Stack.prototype.getLength = function () { - return this.items.length; -}; - -/** - * Checks if the stack is empty. - * @return {boolean} True if the stack is empty, false otherwise. - */ -Stack.prototype.isEmpty = function () { - return !this.items.length; -}; - -/** - * Returns the items that satisfy the condition determined by the callback. - * @param callback {function} The function that implements the condition. - * @return {Array<*>} The array that contains the items that satisfy the condition. - */ -Stack.prototype.filter = function (callback) { - var result = []; - for (var i = this.items.length - 1; i > -1; i--) { - if (callback(this.items[i])) - result.push(this.items[i]); - } - return result; -}; - -/** - * Returns the first position of the item in the stack. - * @param item {*} The item to search. - * @param [callback = function(item){return(it===item);}] The condition to satisfy. The callback must accept the current item to check. - * @return {number} The first position of the item. - */ -Stack.prototype.indexOf = function (item, callback) { - callback = callback || function (it) { - return it === item; - }; - var i = this.items.length - 1; - while (i > -1) { - if (callback(this.items[i])) - return i; - i--; - } - return -1; -}; - -/** - * Returns the last position of the item in the stack. - * @param item {*} The item to search. - * @param [callback = function(item){return(it===item);}] The condition to satisfy. The callback must accept the current item to check. - * @return {number} The last position of the item. - */ -Stack.prototype.lastIndexOf = function (item, callback) { - callback = callback || function (it) { - return it === item; - }; - var i = 0; - while (i < this.items.length) { - if (callback(this.items[i])) - return i; - i++; - } - return -1; -}; - -/** - * Returns all the position in which the item has been found in the stack. - * @param item {*} The item to search. - * @param [callback = function(item){return(it===item);}] The condition to satisfy. The callback must accept the current item to check. - * @return {Array} The positions in which the item has been found. - */ -Stack.prototype.allIndexesOf = function (item, callback) { - callback = callback || function (it) { - return it === item; - }; - var i = this.items.length - 1; - var indexes = []; - while (i > -1) { - if (callback(this.items[i])) - indexes.push(i); - i--; - } - return indexes; -}; - -/** - * Clones the stack into a new stack. - * @return {Stack} The stack cloned from this stack. - */ -Stack.prototype.clone = function () { - var stack = new Stack(); - for (var i = 0; i < this.items.length; i++) - if (this.items[i].clone) - stack.push(this.items[i].clone()); - else - stack.push(this.items[i]); - return stack; -}; - -/** - * Clones the stack into a new stack without cloning duplicated items. - * @return {Stack} The stack cloned from this stack. - */ -Stack.prototype.cloneDistinct = function () { - var stack = new Stack(); - for (var i = 0; i < this.items.length; i++) - if (!stack.contains(this.items[i])) { - if (this.items[i].cloneDistinct) - stack.push(this.items[i].cloneDistinct()); - else if (this.items[i].clone) - stack.push(this.items[i].clone()); - else - stack.push(this.items[i]); - } - return stack; -}; - -/** - * Class that implements the iterator for a linked list. - * @param aggregate {Stack} The aggregate to scan. - * @constructor - */ -function StackIterator(aggregate) { - /** - * The aggregate relates to this iterator. - * @type {Stack} - */ - this.aggregate = aggregate; - - /** - * The pointer to the position. - * @type {number} - */ - this.pointer = -1; -} - -/** - * Moves the iterator to the first position of the aggregate. - * @return {void} - */ -StackIterator.prototype.first = function () { - this.pointer = this.aggregate.items.length - 1; -}; - -/** - * Moves the iterator to the next item. - * @return {void} - */ -StackIterator.prototype.next = function () { - this.pointer--; -}; - -/** - * Moves the iterator to the last position of the aggregate. - * @return {void} - */ -StackIterator.prototype.last = function () { - this.pointer = 0; -}; - -/** - * Moves the iterator to the previous item. - * @return {void} - */ -StackIterator.prototype.previous = function () { - this.pointer++; -}; - -/** - * Checks if the iterator is out of the bounds of the aggregate. - * @return {boolean} It return true if the iterator is out of the bounds of the aggregate, otherwise false. - */ -StackIterator.prototype.isDone = function () { - return this.pointer < 0 || this.pointer > this.aggregate.items.length - 1; -}; - -/** - * Returns the item stored at the position pointed by the iterator. - * @return {*} The item stored or undefined if it's out of the bounds. - */ -StackIterator.prototype.getItem = function () { - return this.aggregate.items[this.pointer]; -}; diff --git a/DataStructuresMinimized.js b/DataStructuresMinimized.js deleted file mode 100644 index 4a727e1..0000000 --- a/DataStructuresMinimized.js +++ /dev/null @@ -1,2751 +0,0 @@ -function Aggregate() { -} -function Iterator() { -} -function BSNode(e, t) { - this.item = t; - this.key = e; - this.parent = null; - this.left = null; - this.right = null -} -function BSTree() { - this.root = null -} -function BSTreeIterator(e) { - this.aggregate = e; - this.pointer = null -} -function BNode() { - this.keys = []; - this.items = []; - this.childs = [] -} -function BTree(e) { - this.root = new BNode; - this.t = e; - this.size = 0 -} -function BTreeIterator(e) { - this.aggregate = e; - this.pointer = null -} -function CircularBufferIterator(e) { - this.aggregate = e; - this.pointer = null; - this.start = true -} -function CircularBuffer(e) { - this.head = 0; - this.tail = 0; - this.items = new Array(e); - this.empty = true; - this.full = false; - this.size = e -} -function DLLNode(e) { - this.item = e; - this.next = null; - this.previous = null -} -function DoubleLinkedList(e) { - this.first = null; - this.last = null; - this.length = 0; - this.fromArray(arguments) -} -function DoubleLinkedListIterator(e) { - this.aggregate = e; - this.pointer = null -} -function merge(e, t, n) { - var r = Math.floor((e + t) / 2); - var i = []; - var s = []; - for (var o = 0; o < r - e + 1; o++)i[o] = n[e + o]; - for (var u = 0; u < t - r; u++)s[u] = n[r + u + 1]; - var a = 0, f = 0; - for (var l = e; l < t + 1; l++) { - if (f > t - r - 1 || i[a] <= s[f] && a < r - e + 1) { - this.postMessage({cmd: "replace", index: l, value: i[a]}); - a++ - } else { - this.postMessage({cmd: "replace", index: l, value: s[f]}); - f++ - } - } -} -function HashTable(e) { - this.size = e; - this.p = 1e3; - this.a = Math.floor(Math.random() * this.p); - this.b = Math.floor(Math.random() * this.p); - this.hash = function (e) { - return(this.a * e + this.b) % this.p % this.size - }; - this.items = []; - this.keyLength = 0; - this.clear() -} -function LLNode(e) { - this.item = e; - this.next = null -} -function LinkedList(e) { - this.first = null; - this.last = null; - this.length = 0; - this.fromArray(arguments) -} -function LinkedListIterator(e) { - this.aggregate = e; - this.pointer = null -} -function PriorityQueue() { - this.items = new RBTreeList; - this.length = 0 -} -function PriorityQueueIterator(e) { - this.aggregate = e; - this.pointerNode = null; - this.pointerPosition = -1 -} -function Queue(e) { - this.items = []; - this.multiEnqueue(arguments) -} -function QueueIterator(e) { - this.aggregate = e; - this.pointer = -1 -} -function RBNode(e, t) { - this.item = t; - this.key = e; - this.parent = null; - this.left = null; - this.right = null; - this.type = "r" -} -function RBTree() { - this.root = null; - this.size = 0 -} -function RBTreeIterator(e) { - this.aggregate = e; - this.pointer = null -} -function RBLNode(e, t) { - this.item = t; - this.key = e; - this.parent = null; - this.left = null; - this.right = null; - this.next = null; - this.previous = null; - this.type = "r" -} -function RBTreeList() { - this.root = null; - this.first = null; - this.last = null; - this.size = 0 -} -function RBTreeListIterator(e) { - this.aggregate = e; - this.pointer = null -} -function Element(e) { - this.parents = new DoubleLinkedList; - this.item = e -} -function Set() { - this.parents = new DoubleLinkedList; - this.elements = new DoubleLinkedList; - this.sets = new DoubleLinkedList; - this.size = 0 -} -function Stack(e) { - this.items = []; - this.multiPush(arguments) -} -function StackIterator(e) { - this.aggregate = e; - this.pointer = -1 -} -Aggregate.prototype.getIterator = function () { -}; -Iterator.prototype.first = function () { -}; -Iterator.prototype.next = function () { -}; -Iterator.prototype.last = function () { -}; -Iterator.prototype.previous = function () { -}; -Iterator.prototype.isDone = function () { -}; -Iterator.prototype.getItem = function () { -}; -BSTree.prototype = new Aggregate; -BSTree.prototype.constructor = BSTree; -BSTree.prototype.getIterator = function () { - return new BSTreeIterator(this) -}; -BSTree.prototype.insert = function (e, t) { - var n = new BSNode(e, t); - var r = this.root; - for (var i = this.root; i;) { - r = i; - if (e < i.key)i = i.left; else i = i.right - } - n.parent = r; - if (!r)this.root = n; else if (e < r.key)r.left = n; else r.right = n -}; -BSTree.prototype.search = function (e, t) { - t = t || this.root; - while (t && e !== t.key)if (e < t.key)t = t.left; else t = t.right; - if (t)return t.item; - return undefined -}; -BSTree.prototype.minimum = function (e) { - e = e || this.root; - while (e && e.left)e = e.left; - return e -}; -BSTree.prototype.maximum = function (e) { - e = e || this.root; - while (e && e.right)e = e.right; - return e -}; -BSTree.prototype.successor = function (e) { - if (e.right)return this.minimum(e.right); - var t = e.parent; - while (t && e === t.right) { - e = t; - t = t.parent - } - return t -}; -BSTree.prototype.predecessor = function (e) { - if (e.left)return this.maximum(e.left); - var t = e.parent; - while (t && e === t.left) { - e = t; - t = t.parent - } - return t -}; -BSTree.prototype.deleteNode = function (e) { - if (!e.left && !e.right) { - if (e === this.root)this.root = null; else if (e.parent.left === e)e.parent.left = null; else e.parent.right = null - } else if (e.left && e.right) { - var t = this.successor(e); - e.key = t.key; - e.item = t.item; - if (t.parent.left === t)t.parent.left = null; else t.parent.right = null - } else { - if (e.right) { - if (e === this.root) { - this.root = e.right; - e.right.parent = null - } else { - e.parent.right = e.right; - e.right.parent = e.parent - } - } else { - if (e === this.root) { - this.root = e.left; - e.left.parent = null - } else { - e.parent.left = e.left; - e.left.parent = e.parent - } - } - } -}; -BSTreeIterator.prototype = new Iterator; -BSTreeIterator.prototype.constructor = BSTreeIterator; -BSTreeIterator.prototype.first = function () { - this.pointer = this.aggregate.minimum() -}; -BSTreeIterator.prototype.next = function () { - this.pointer = this.aggregate.successor(this.pointer) -}; -BSTreeIterator.prototype.last = function () { - this.pointer = this.aggregate.maximum() -}; -BSTreeIterator.prototype.previous = function () { - this.pointer = this.aggregate.predecessor(this.pointer) -}; -BSTreeIterator.prototype.isDone = function () { - return!this.pointer -}; -BSTreeIterator.prototype.getItem = function () { - return this.pointer.item -}; -BSTreeIterator.prototype.getNode = function () { - return this.pointer -}; -BTree.prototype = new Aggregate; -BTree.prototype.constructor = BTree; -BTree.prototype.getIterator = function () { - return new BTreeIterator(this) -}; -BTree.prototype.insert = function (e, t) { - var n = this.root; - if (n.keys.length === 2 * this.t - 1) { - var r = new BNode; - r.childs.push(n); - this.root = r; - this.splitChild(r, 0); - n = r - } - this.size++; - this.insertNonFull(n, e, t) -}; -BTree.prototype.insertNonFull = function (e, t, n) { - while (e) { - var r = e.keys.length - 1; - if (!e.childs.length) { - for (; r > -1 && t < e.keys[r]; r--) { - e.keys[r + 1] = e.keys[r]; - e.items[r + 1] = e.items[r] - } - e.keys[r + 1] = t; - e.items[r + 1] = n; - return - } else { - var i = 0; - r++; - while (i < r) { - var s = Math.floor((i + r) / 2); - if (t <= e.keys[s])r = s; else i = s + 1 - } - if (e.childs[i].keys.length === 2 * this.t - 1) { - this.splitChild(e, i); - if (t > e.keys[i])i++ - } - e = e.childs[i] - } - } -}; -BTree.prototype.search = function (e, t, n) { - t = t || this.root; - n = n || function (t, n) { - return t.keys[n] === e - }; - while (t) { - var r = t.keys.length; - var i = 0, s = r; - while (i < s) { - var o = Math.floor((i + s) / 2); - if (e <= t.keys[o])s = o; else i = o + 1 - } - if (i < r && n(t, i))return t.items[i]; else if (!t.childs.length)return undefined; else t = t.childs[i] - } -}; -BTree.prototype.splitChild = function (e, t) { - var n = new BNode; - var r = e.childs[t]; - for (var i = 0; i < this.t - 1; i++) { - n.keys[i] = r.keys[i + this.t]; - n.items[i] = r.items[i + this.t] - } - if (r.childs.length)for (var s = 0; s < this.t; s++)n.childs[s] = r.childs[s + this.t]; - for (var o = e.keys.length; o > t; o--)e.childs[o + 1] = e.childs[o]; - e.childs[t + 1] = n; - for (var u = e.keys.length - 1; u > t - 1; u--) { - e.keys[u + 1] = e.keys[u]; - e.items[u + 1] = e.items[u] - } - e.keys[t] = r.keys[this.t - 1]; - e.items[t] = r.items[this.t - 1]; - r.keys.splice(r.keys.length - this.t); - r.items.splice(r.items.length - this.t); - r.childs.splice(r.childs.length - this.t) -}; -BTree.prototype.deleteKey = function (e) { - if (this.root.keys.length) { - this.deleteNonMin(this.root, e); - if (!this.root.keys.length && this.root.childs.length)this.root = this.root.childs[0]; - this.size-- - } -}; -BTree.prototype.deleteNonMin = function (e, t) { - var n = 0, r = e.keys.length; - while (n < r) { - var i = Math.floor((n + r) / 2); - if (t <= e.keys[i])r = i; else n = i + 1 - } - if (n < e.keys.length && t === e.keys[n]) { - if (!e.childs.length) { - for (r = n + 1; r < e.keys.length; r++) { - e.keys[r - 1] = e.keys[r]; - e.items[r - 1] = e.items[r] - } - e.keys.pop(); - e.items.pop() - } else { - if (e.childs[n].length === this.t - 1) { - this.augmentChild(e, n); - if (n === e.keys.length + 1)n-- - } - if (e.keys[n] !== t)this.deleteNonMin(e.childs[n], t); else this.deleteMax(e, n) - } - } else { - if (e.childs[n].keys.length === this.t - 1) { - this.augmentChild(e, n); - if (n === e.keys.length + 2)n-- - } - this.deleteNonMin(e.childs[n], t) - } -}; -BTree.prototype.deleteMax = function (e, t) { - var n = e.childs[t]; - var r = true; - while (r) { - if (!n.childs.length) { - e.keys[t] = n.keys[n.keys.length - 1]; - e.items[t] = n.items[n.items.length - 1]; - n.keys.pop(); - n.items.pop(); - r = false - } else { - var i = n.childs[n.keys.length]; - if (i.keys.length === this.t - 1)this.augmentChild(n, n.keys.length); - n = n.childs[n.keys.length] - } - } -}; -BTree.prototype.augmentChild = function (e, t) { - var n = e.childs[t]; - var r; - if (t)r = e.childs[t - 1]; - if (t && r.keys.length > this.t - 1) { - if (n.childs.length) { - for (var i = this.keys.length + 1; i > 0; i--)n.childs[i] = n.childs[i - 1]; - n.childs[0] = r.childs[r.keys.length]; - for (var s = n.keys.length; s > 0; s--) { - n.keys[s] = n.keys[s - 1]; - n.items[s] = n.items[s - 1] - } - n.keys[0] = e.keys[t - 1]; - n.items[0] = e.items[t - 1]; - e.keys[t - 1] = r.keys[r.keys.length - 1]; - e.items[t - 1] = r.items[r.items.length - 1] - } - } else { - if (t < e.keys.length)r = e.childs[t + 1]; - if (t < e.keys.length && r.keys.length > this.t - 1) { - if (r.childs.length) { - n.childs[n.keys.length + 1] = r.childs[0]; - for (var o = 1; o < r.keys.length + 1; o++)r.childs[o - 1] = r.childs[o]; - r.childs.pop() - } - n.keys[n.keys.length] = e.keys[t]; - n.items[n.items.length] = e.items[t]; - e.keys[t] = r.keys[0]; - e.items[t] = r.items[0]; - for (var u = 1; u < r.keys.length; u++) { - r.keys[u - 1] = r.keys[u]; - r.items[u - 1] = r.items[u] - } - r.keys.pop(); - r.items.pop() - } else { - if (t < e.keys.length) { - n.keys[this.t - 1] = e.keys[t]; - n.items[this.t - 1] = e.items[t]; - for (var a = t + 2; a < e.keys.length + 1; a++)e.childs[a - 1] = e.childs[a]; - e.childs.pop(); - for (var f = t + 1; f < e.keys.length; f++) { - e.keys[f - 1] = e.keys[f]; - e.items[f - 1] = e.items[f] - } - e.keys.pop(); - e.items.pop(); - if (r.childs.length)for (var l = 0; l < r.keys.length + 1; l++)n.childs[this.t + l] = r.childs[l]; - for (var c = 0; c < r.keys.length; c++) { - n.keys[c + this.t] = r.keys[c]; - n.items[c + this.t] = r.items[c] - } - } else { - if (r.childs.length)for (var h = 0; h < n.keys.length + 1; h++)r.childs[this.t + h] = n.childs[h]; - r.keys[this.t - 1] = e.keys[e.keys.length - 1]; - r.items[this.t - 1] = e.items[e.keys.length - 1]; - for (var p = 0; p < n.keys.length; p++) { - r.keys[p + this.t] = n.keys[p]; - r.items[p + this.t] = n.items[p] - } - } - } - } -}; -BTree.prototype.contains = function (e, t) { - return this.search(e, null, t) !== undefined -}; -BTree.prototype.fullContains = function (e) { - var t = this.minimumKey(); - while (t !== null && !e(this.search(t)))t = this.successor(t); - return t !== null -}; -BTree.prototype.successor = function (e, t) { - t = t || this.root; - var n = 0, r = t.keys.length; - while (n < r) { - var i = Math.floor((n + r) / 2); - if (e <= t.keys[i])r = i; else n = i + 1 - } - if (t.keys[n] === e)n++; - if (!t.childs.length) { - if (n > t.keys.length - 1)return null; else return t.keys[n] - } - var s = this.successor(e, t.childs[n]); - if (s === null && n < t.keys.length)return t.keys[n]; - return s -}; -BTree.prototype.predecessor = function (e, t) { - t = t || this.root; - var n = 0, r = t.keys.length; - while (n < r) { - var i = Math.floor((n + r) / 2); - if (e <= t.keys[i])r = i; else n = i + 1 - } - n--; - if (!t.childs.length) { - if (n < 0)return null; else return t.keys[n] - } - var s = this.predecessor(e, t.childs[n + 1]); - if (s === null && e > t.keys[0]) { - return t.keys[n] - } - return s -}; -BTree.prototype.minimumKey = function () { - var e = this.root; - while (e.childs.length)e = e.childs[0]; - if (e)return e.keys[0]; - return null -}; -BTree.prototype.maximumKey = function () { - var e = this.root; - while (e.childs.length)e = e.childs[e.childs.length - 1]; - if (e)return e.keys[e.keys.length - 1]; - return null -}; -BTree.prototype.minimum = function () { - var e = this.root; - while (e.childs.length)e = e.childs[0]; - return e.items[0] -}; -BTree.prototype.maximum = function () { - var e = this.root; - while (e.childs.length)e = e.childs[e.childs.length - 1]; - return e.items[e.items.length - 1] -}; -BTree.prototype.getSize = function () { - return this.size -}; -BTree.prototype.isEmpty = function () { - return!this.size -}; -BTree.prototype.execute = function (e) { - var t = arguments[1] || this.root; - for (var n = 0; n < t.items.length; n++)t.items[n] = e(t.items[n]); - for (var r = 0; r < t.childs.length; r++)this.execute(e, t.childs[r]) -}; -BTree.prototype.clear = function () { - this.root = null; - this.size = 0 -}; -BTree.prototype.filter = function (e) { - var t = []; - var n = arguments[1] || this.root; - for (var r = 0; r < n.items.length; r++) { - if (n.childs.length)t = t.concat(this.filter(e, n.childs[r])); - if (e(n.items[r]))t.push(n.items[r]) - } - if (n.childs.length)t = t.concat(this.filter(e, n.childs[n.childs.length - 1])); - return t -}; -BTree.prototype.clone = function () { - var e = new BTree(this.t); - var t = this.getIterator(); - for (t.first(); !t.isDone(); t.next()) { - var n = t.getItem(); - if (n.clone)n = n.clone(); - e.insert(t.getKey(), n) - } - return e -}; -BTree.prototype.cloneDistinct = function () { - var e = new BTree(this.t); - var t = this.getIterator(); - for (t.first(); !t.isDone(); t.next()) { - var n = function (e) { - return e === t.getItem() - }; - if (!e.fullContains(n)) { - if (t.getItem().cloneDistinct)e.insert(t.getKey(), t.getItem().cloneDistinct()); else if (t.getItem().clone)e.insert(t.getKey(), t.getItem().clone()); else e.insert(t.getKey(), t.getItem()) - } - } - return e -}; -BTree.prototype.toArray = function () { - var e = []; - var t = this.getIterator(); - for (t.first(); !t.isDone(); t.next())e.push(t.getItem()); - return e -}; -BTree.prototype.indexOf = function (e, t) { - t = t || function (t) { - return t === e - }; - var n = 0, r = this.minimumKey(); - while (r !== null) { - if (t(this.search(r)))return n; - r = this.successor(r); - n++ - } - return-1 -}; -BTree.prototype.lastIndexOf = function (e, t) { - t = t || function (t) { - return t === e - }; - var n = this.size - 1, r = this.maximumKey(); - while (r !== null) { - if (t(this.search(r)))return n; - n--; - r = this.predecessor(r) - } - return-1 -}; -BTree.prototype.allIndexesOf = function (e, t) { - t = t || function (t) { - return t === e - }; - var n = 0, r = this.minimumKey(); - var i = []; - while (r !== null) { - if (t(this.search(r)))i.push(n); - n++; - r = this.successor(r) - } - return i -}; -BTree.prototype.getItem = function (e) { - if (e < 0 || e > this.size - 1)return undefined; - var t = this.minimum(); - for (var n = 0; n < e; n++)t = this.successor(t); - return this.search(t) -}; -BTreeIterator.prototype = new Iterator; -BTreeIterator.prototype.constructor = BTreeIterator; -BTreeIterator.prototype.first = function () { - this.pointer = this.aggregate.minimumKey() -}; -BTreeIterator.prototype.next = function () { - this.pointer = this.aggregate.successor(this.pointer) -}; -BTreeIterator.prototype.last = function () { - this.pointer = this.aggregate.maximumKey() -}; -BTreeIterator.prototype.previous = function () { - this.pointer = this.aggregate.predecessor(this.pointer) -}; -BTreeIterator.prototype.isDone = function () { - return this.pointer === null -}; -BTreeIterator.prototype.getItem = function () { - return this.aggregate.search(this.pointer) -}; -BTreeIterator.prototype.getKey = function () { - return this.pointer -}; -CircularBufferIterator.prototype = new Iterator; -CircularBufferIterator.prototype.constructor = CircularBufferIterator; -CircularBufferIterator.prototype.first = function () { - this.pointer = this.aggregate.tail; - this.start = true -}; -CircularBufferIterator.prototype.next = function () { - this.pointer = (this.pointer + 1) % this.aggregate.size; - this.start = false -}; -CircularBufferIterator.prototype.last = function () { - this.pointer = (this.aggregate.head - 1) % this.aggregate.size; - this.start = true -}; -CircularBufferIterator.prototype.previous = function () { - this.pointer = (this.pointer - 1) % this.aggregate.size; - this.start = false -}; -CircularBufferIterator.prototype.isDone = function () { - return this.pointer === this.aggregate.head && !this.start || (this.pointer === this.aggregate.tail - 1) % this.aggregate.size || this.aggregate.isEmpty() -}; -CircularBufferIterator.prototype.getItem = function () { - return this.aggregate.read(this.pointer) -}; -CircularBuffer.prototype = new Aggregate; -CircularBuffer.prototype.constructor = CircularBuffer; -CircularBuffer.prototype.getIterator = function () { - return new CircularBufferIterator(this) -}; -CircularBuffer.prototype.write = function (e) { - this.empty = false; - if (this.full)this.tail = (this.tail + 1) % this.size; - this.items[this.head] = e; - this.head = (this.head + 1) % this.size; - if (this.tail === this.head)this.full = true -}; -CircularBuffer.prototype.free = function (e, t) { - if (e < 0)e = 0; - if (e > this.size - 1)e = this.size - 1; - if (t < 0)t = 0; - if (t > this.size - 1)t = this.size - 1; - for (var n = e; n < t; n = (n + 1) % this.size)delete this.items[n]; - if (this.tail > e - 1 || this.tail < t)if (this.tail < this.head) { - this.tail = (e - 1) % this.size - } else { - this.tail = t - } - if (this.head > e || this.head < t)if (this.tail < this.head) { - this.head = t - } else { - this.head = e - } - if (e !== t)this.full = false; - for (var r = 0; r < this.size; r++)if (this.items[r] !== undefined) { - this.empty = false; - return - } - this.empty = true -}; -CircularBuffer.prototype.freeAll = function () { - for (var e = 0; e < this.size; e++)delete this.items[e]; - this.empty = true; - this.head = 0; - this.tail = 0 -}; -CircularBuffer.prototype.read = function (e) { - return this.items[e % this.size] -}; -CircularBuffer.prototype.isEmpty = function () { - return this.empty -}; -CircularBuffer.prototype.isFull = function () { - return this.full -}; -CircularBuffer.prototype.clone = function () { - var e = new CircularBuffer(this.size); - e.head = this.head; - e.tail = this.tail; - for (var t = 0; t < this.items.length; t++)e.items[t] = this.items[t]; - e.empty = this.empty; - e.full = this.full; - return e -}; -CircularBuffer.prototype.resize = function (e) { - if (this.size < e) { - if (this.head < this.tail + 1) { - for (var t = 0; t < this.head; t++) { - this.items[(t + this.size) % e] = this.items[t]; - delete this.items[t] - } - this.head = (this.head + this.size) % e - } - } else if (this.size > e) { - if (this.head < this.tail + 1) { - var n = e; - if (this.tail > e - 1) { - n = this.tail; - this.tail = 0 - } - var r = this.size - n; - for (var i = this.head - r - 1; i > n - 1 || i < this.head - r; i--) { - this.items[(i + r) % this.size] = this.items[i]; - if (!i)i = this.size - } - this.head = (this.head + r) % this.size - } - } - this.size = e -}; -DoubleLinkedList.prototype = new Aggregate; -DoubleLinkedList.prototype.constructor = DoubleLinkedList; -DoubleLinkedList.prototype.getIterator = function () { - return new DoubleLinkedListIterator(this) -}; -DoubleLinkedList.prototype.pushFront = function (e) { - var t = new DLLNode(e); - t.next = this.first; - this.first = t; - if (t.next)t.next.previous = t; else this.last = t; - this.length++ -}; -DoubleLinkedList.prototype.pushBack = function (e) { - var t = new DLLNode(e); - t.previous = this.last; - this.last = t; - if (t.previous)t.previous.next = t; else this.first = t; - this.length++ -}; -DoubleLinkedList.prototype.popFront = function () { - if (this.length) { - var e = this.first; - this.first = e.next; - if (e.next)e.next.previous = null; - this.length--; - e.next = null; - return e.item - } - return undefined -}; -DoubleLinkedList.prototype.popBack = function () { - if (this.length) { - var e = this.last; - this.last = e.previous; - if (e.previous)e.previous.next = null; - this.length--; - e.previous = null; - return e.item - } - return undefined -}; -DoubleLinkedList.prototype.multiPopFront = function (e) { - var t = []; - for (var n = 0; n < e && this.length; n++)t.push(this.popFront()); - return t -}; -DoubleLinkedList.prototype.multiPopBack = function (e) { - var t = []; - for (var n = 0; n < e && this.length; n++)t.push(this.popBack()); - return t -}; -DoubleLinkedList.prototype.peek = function () { - if (!this.length)return undefined; - return this.first.item -}; -DoubleLinkedList.prototype.addAt = function (e, t) { - if (t < 0)return; - if (!t) { - this.pushFront(e); - return - } - if (t === this.length) { - this.pushBack(e); - return - } - var n = this.first; - if (!n && t > 0)this.pushBack(undefined); - for (var r = 0; r < t - 1; r++, n = n.next) { - if (n === this.last)this.pushBack(undefined) - } - if (n === this.last)this.pushBack(e); else if (n === this.first)this.pushFront(e); else { - var i = new DLLNode(e); - i.next = n.next; - i.previous = n; - n.next = i; - if (i.next)i.next.previous = i; - this.length++ - } -}; -DoubleLinkedList.prototype.removeAt = function (e) { - if (e < 0 || e > this.length - 1)return undefined; - if (e === 0)return this.popFront(); - if (e === this.length - 1)return this.popBack(); - var t = this.first; - for (; e > 0; e--)t = t.next; - t.previous.next = t.next; - t.next.previous = t.previous; - t.next = null; - t.previous = null; - this.length--; - return t.item -}; -DoubleLinkedList.prototype.remove = function (e, t) { - t = t || function (t) { - return t === e - }; - var n = this.first; - var r = null; - while (n) { - if (t(n.item)) { - if (n === this.first)this.first = n.next; - if (n === this.last)this.last = r; - if (r) { - r.next = n.next; - if (n.next)n.next.previous = r - } - return - } - r = n; - n = n.next - } -}; -DoubleLinkedList.prototype.removeAll = function (e, t) { - t = t || function (t) { - return t === e - }; - var n = this.first; - var r = null; - while (n) { - if (t(n.item)) { - if (n === this.first)this.first = n.next; - if (n === this.last)this.last = r; - if (r) { - r.next = n.next; - if (n.next)n.next.previous = r - } - } else r = n; - n = n.next - } -}; -DoubleLinkedList.prototype.removeSegment = function (e, t) { - var n = []; - if (t > -1 && e < this.length) { - if (e === 0)return this.multiPopFront(t + 1); - if (t === this.length - 1 || e > t)return this.multiPopBack(Math.max(t - e, this.length - e)).reverse(); - var r = this.first; - for (var i = 0; i < e - 1; i++)r = r.next; - var s = r.next; - for (var o = e; o < t + 1 && o < this.length; o++) { - n.push(s.item); - s = s.next - } - this.length -= Math.min(t - e + 1, this.length - e); - r.next = s; - s.previous = r - } - return n -}; -DoubleLinkedList.prototype.modifyAt = function (e, t) { - var n = this.getNode(e); - if (n)n.item = t -}; -DoubleLinkedList.prototype.clear = function () { - this.first = null; - this.last = null; - this.length = 0 -}; -DoubleLinkedList.prototype.contains = function (e, t) { - t = t || function (t) { - return t === e - }; - var n = 0; - var r = this.first; - while (n < this.length && !t(r.item)) { - n++; - r = r.next - } - return n < this.length -}; -DoubleLinkedList.prototype.execute = function (e) { - var t = this.first; - while (t) { - t.item = e(t.item); - t = t.next - } -}; -DoubleLinkedList.prototype.deleteNode = function (e) { - if (e === this.first) { - this.popFront(); - return - } - if (e === this.last) { - this.popBack(); - return - } - e.previous.next = e.next; - e.next.previous = e.previous; - this.length-- -}; -DoubleLinkedList.prototype.getNode = function (e, t) { - if (e < 0 || e > this.length - 1)return undefined; - var n = Math.floor(this.length / 2); - if (e < n || t) { - t = t || this.first; - for (; e > 0; e--)t = t.next - } else for (e = this.length - e - 1, t = this.last; e > 0; e--)t = t.previous; - return t -}; -DoubleLinkedList.prototype.getItem = function (e) { - if (e < 0 || e > this.length - 1)return undefined; - var t; - var n = Math.floor(this.length / 2); - if (e < n)for (t = this.first; e > 0; e--)t = t.next; else for (e = this.length - e - 1, t = this.last; e > 0; e--)t = t.previous; - return t.item -}; -DoubleLinkedList.prototype.parallelSort = function () { - function n(r, i, s) { - if (r < i) { - var o = Math.floor((r + i) / 2); - var u = new Worker("DoubleLinkedList/WorkerSort.js"); - var a = new Worker("DoubleLinkedList/WorkerSort.js"); - e.push(u); - e.push(a); - var f = e.length; - u.postMessage({cmd: "start", from: r, to: o, worker: s}); - a.postMessage({cmd: "start", from: o + 1, to: i, worker: s}); - n(r, o, f - 2); - n(o + 1, i, f - 1); - u.onmessage = function (n) { - var r = n.data; - switch (r.cmd) { - case"finished": - e[r.worker].postMessage({cmd: "finished", array: t}); - break; - case"replace": - t[r.index] = r.value; - break - } - }; - a.onmessage = function (n) { - var r = n.data; - switch (r.cmd) { - case"finished": - e[r.worker].postMessage({cmd: "finished", array: t}); - break; - case"replace": - t[r.index] = r.value; - break - } - } - } - } - - var e = []; - var t = this.toArray(); - console.log(t); - var r = this; - var i = new Worker("DoubleLinkedList/WorkerSort.js"); - e.push(i); - i.postMessage({cmd: "start", from: 0, to: this.length - 1, worker: -1, array: t}); - i.onmessage = function (e) { - var n = e.data; - switch (n.cmd) { - case"finished": - r.fromArray(t); - console.log(r); - break; - case"replace": - t[n.index] = n.value - } - }; - n(0, this.length - 1, 0) -}; -DoubleLinkedList.prototype.sort = function (e) { - function n(e, i, s, o) { - if (e < i) { - var u = Math.floor((e + i) / 2); - var a = t.getNode(u - e, s); - n(e, u, s, a); - n(u + 1, i, a.next, o); - r(e, u, i, s) - } - } - - function r(t, n, r, i) { - var s = []; - var o = []; - var u = i; - for (var a = 0; a < n - t + 1; a++, u = u.next)s[a] = u.item; - for (var f = 0; f < r - n; f++, u = u.next)o[f] = u.item; - var l = 0, c = 0; - for (var h = t; h < r + 1; h++, i = i.next) { - if (c > r - n - 1 || e(s[l]) <= e(o[c]) && l < n - t + 1) { - i.item = s[l]; - l++ - } else { - i.item = o[c]; - c++ - } - } - } - - if (!e)e = function (e) { - return e - }; - var t = this; - n(0, this.length - 1, this.first, this.last) -}; -DoubleLinkedList.prototype.toArray = function () { - var e = []; - for (var t = this.first, n = 0; t; t = t.next, n++)e[n] = t.item; - return e -}; -DoubleLinkedList.prototype.getLength = function () { - return this.length -}; -DoubleLinkedList.prototype.fromArray = function (e) { - var t = this.first; - for (var n = 0; n < Math.min(this.length, e.length); n++, t = t.next)t.item = e[n]; - if (this.length < e.length)for (var r = this.length; r < e.length; r++)this.pushBack(e[r]); else for (var i = e.length; i < this.length;)this.popBack() -}; -DoubleLinkedList.prototype.filter = function (e) { - var t = []; - for (var n = this.first; n; n = n.next) { - if (e(n.item))t.push(n.item) - } - return t -}; -DoubleLinkedList.prototype.reverse = function () { - for (var e = this.first, t = this.last; e !== t && e.previous !== t; e = e.next, t = t.previous) { - var n = e.item; - e.item = t.item; - t.item = n - } -}; -DoubleLinkedList.prototype.isEmpty = function () { - return!this.length -}; -DoubleLinkedList.prototype.indexOf = function (e, t) { - t = t || function (t) { - return t === e - }; - var n = 0; - var r = this.first; - while (r) { - if (t(r.item))return n; - n++; - r = r.next - } - return-1 -}; -DoubleLinkedList.prototype.lastIndexOf = function (e, t) { - t = t || function (t) { - return t === e - }; - var n = this.length - 1; - var r = this.last; - while (r) { - if (t(r.item))return n; - n--; - r = r.previous - } - return-1 -}; -DoubleLinkedList.prototype.allIndexesOf = function (e, t) { - t = t || function (t) { - return t === e - }; - var n = 0; - var r = this.first; - var i = []; - while (r) { - if (t(r.item))i.push(n); - n++; - r = r.next - } - return i -}; -DoubleLinkedList.prototype.join = function (e) { - if (this.last)this.last.next = e.first; else this.first = e.first; - if (e.first)e.first.previous = this.last; - this.last = e.last; - this.length += e.length -}; -DoubleLinkedList.prototype.divide = function (e) { - var t = new DoubleLinkedList; - if (e > -1 && e < this.length) { - var n = this.first; - var r = null; - for (var i = 0; i < e; i++) { - r = n; - n = n.next - } - if (n === this.first) { - t.first = this.first; - t.last = this.last; - this.first = null; - this.last = null - } else { - t.first = n; - t.last = this.last; - this.last = r; - r.next = null; - n.previous = null - } - t.length = this.length - e; - this.length = e - } - return t -}; -DoubleLinkedList.prototype.clone = function () { - var e = new DoubleLinkedList; - var t = this.first; - for (var n = 0; n < this.length; n++, t = t.next)if (t.item.clone)e.pushBack(t.item.clone()); else e.pushBack(t.item); - return e -}; -DoubleLinkedList.prototype.cloneDistinct = function () { - var e = new DoubleLinkedList; - var t = this.first; - for (var n = 0; n < this.length; n++, t = t.next)if (!e.contains(t.item))if (t.item.cloneDistinct)e.pushBack(t.item.cloneDistinct()); else if (t.item.clone)e.pushBack(t.item.clone()); else e.pushBack(t.item); - return e -}; -DoubleLinkedList.prototype.split = function (e) { - var t = this.length; - var n = [this]; - for (var r = e; r < t; r += e)n.push(n[n.length - 1].divide(e)); - return n -}; -DoubleLinkedList.prototype.count = function (e) { - var t = 0; - var n = this.first; - while (n) { - if (e(n.item))t++; - n = n.next - } - return t -}; -DoubleLinkedListIterator.prototype = new Iterator; -DoubleLinkedListIterator.prototype.constructor = DoubleLinkedListIterator; -DoubleLinkedListIterator.prototype.first = function () { - this.pointer = this.aggregate.first -}; -DoubleLinkedListIterator.prototype.next = function () { - this.pointer = this.pointer.next -}; -DoubleLinkedListIterator.prototype.last = function () { - this.pointer = this.aggregate.last -}; -DoubleLinkedListIterator.prototype.previous = function () { - this.pointer = this.pointer.previous -}; -DoubleLinkedListIterator.prototype.isDone = function () { - return!this.pointer -}; -DoubleLinkedListIterator.prototype.getItem = function () { - return this.pointer.item -}; -DoubleLinkedListIterator.prototype.getNode = function () { - return this.pointer -}; -onmessage = function (e) { - var t = e.data; - switch (t.cmd) { - case"start": - this.finished = 0; - this.from = t.from; - this.to = t.to; - this.worker = t.worker; - if (this.from === this.to) { - this.postMessage({cmd: "finished", worker: this.worker}); - close() - } - break; - case"finished": - this.finished++; - if (this.finished > 1) { - this.array = t.array; - merge(this.from, this.to, this.array); - this.postMessage({cmd: "finished", worker: this.worker}); - close() - } - break; - default: - this.postMessage("Something went wrong") - } -}; -HashTable.prototype.insert = function (e, t) { - this.keyLength++; - this.items[this.hash(e)].pushBack({key: e, item: t}) -}; -HashTable.prototype.deleteKey = function (e) { - var t = this.items[this.hash(e)]; - var n = t.getIterator(); - for (n.first(); !n.isDone() && n.getItem().key !== e;)n.next(); - if (!n.isDone()) { - t.deleteNode(n.getNode()); - this.keyLength-- - } -}; -HashTable.prototype.deleteAllKey = function (e) { - var t = this.items[this.hash(e)]; - var n = t.getIterator(); - var r = 0; - for (n.first(); !n.isDone(); n.next())if (n.getItem().key === e) { - t.deleteNode(n.getNode()); - r++ - } - this.keyLength -= r -}; -HashTable.prototype.search = function (e) { - var t = this.items[this.hash(e)]; - var n = t.getIterator(); - for (n.first(); !n.isDone(); n.next())if (n.getItem().key === e)return n.getItem().item; - return undefined -}; -HashTable.prototype.containsKey = function (e, t) { - t = t || function (t) { - return t === e - }; - var n = this.items[this.hash(e)]; - var r = n.getIterator(); - for (r.first(); !r.isDone(); r.next())if (t(r.getItem().key))return true; - return false -}; -HashTable.prototype.searchAll = function (e) { - var t = this.items[this.hash(e)]; - var n = t.getIterator(); - var r = []; - for (n.first(); !n.isDone(); n.next())if (n.getItem().key === e)r.push(n.getItem().item); - return r -}; -HashTable.prototype.getKeys = function () { - var e = []; - for (var t = 0; t < this.size; t++) { - var n = this.items[t].getIterator(); - for (n.first(); !n.isDone(); n.next())e.push(n.getItem().key) - } - return e -}; -HashTable.prototype.getItems = function () { - var e = []; - for (var t = 0; t < this.size; t++) { - var n = this.items[t].getIterator(); - for (n.first(); !n.isDone(); n.next())e.push(n.getItem().item) - } - return e -}; -HashTable.prototype.clear = function () { - this.items = []; - for (var e = 0; e < this.size; e++)this.items[e] = new DoubleLinkedList; - this.keyLength = 0 -}; -HashTable.prototype.getNumberOfKeys = function () { - return this.keyLength -}; -HashTable.prototype.isEmpty = function () { - return!this.keyLength -}; -HashTable.prototype.execute = function (e) { - for (var t = 0; t < this.size; t++)this.items[t].execute(e) -}; -HashTable.prototype.filter = function (e) { - var t = []; - for (var n = 0; n < this.size; n++)t.concat(this.items[n].filter(e)); - return t -}; -HashTable.prototype.getSize = function () { - return this.size -}; -HashTable.prototype.clone = function () { - var e = new HashTable(this.size); - for (var t = 0; t < this.size; t++)for (var n = this.items[t].first; n; n = n.next)e.insert(n.key, n.item); - return e -}; -LinkedList.prototype = new Aggregate; -LinkedList.prototype.constructor = LinkedList; -LinkedList.prototype.getIterator = function () { - return new LinkedListIterator(this) -}; -LinkedList.prototype.pushFront = function (e) { - var t = new LLNode(e); - t.next = this.first; - this.first = t; - if (!this.last)this.last = t; - this.length++ -}; -LinkedList.prototype.pushBack = function (e) { - var t = new LLNode(e); - if (this.last)this.last.next = t; else this.first = t; - this.last = t; - this.length++ -}; -LinkedList.prototype.popFront = function () { - if (this.length) { - var e = this.first; - this.first = this.first.next; - this.length--; - e.next = null; - return e.item - } - return undefined -}; -LinkedList.prototype.popBack = function () { - if (this.length) { - var e = this.last; - var t = this.first; - while (t.next && t.next.next) { - t = t.next - } - if (e === t)this.last = null; else this.last = t; - t.next = null; - this.length--; - return e.item - } - return undefined -}; -LinkedList.prototype.multiPopFront = function (e) { - var t = []; - for (var n = 0; n < e && this.length; n++)t.push(this.popFront()); - return t -}; -LinkedList.prototype.multiPopBack = function (e) { - var t = []; - for (var n = 0; n < e && this.length; n++)t.push(this.popBack()); - return t -}; -LinkedList.prototype.peek = function () { - if (!this.length)return undefined; - return this.first.item -}; -LinkedList.prototype.addAt = function (e, t) { - if (t < 0)return; - if (!t) { - this.pushFront(e); - return - } - if (t === this.length) { - this.pushBack(e); - return - } - var n = this.first; - if (!n && t > 0)this.pushBack(undefined); - for (var r = 0; r < t - 1; r++, n = n.next) { - if (n === this.last)this.pushBack(undefined) - } - if (n === this.last)this.pushBack(e); else if (n === this.first)this.pushFront(e); else { - var i = new LLNode(e); - i.next = n.next; - n.next = i; - this.length++ - } -}; -LinkedList.prototype.removeAt = function (e) { - if (e < 0 || e > this.length - 1)return undefined; - if (e === 0)return this.popFront(); - if (e === this.length - 1)return this.popBack(); - var t = this.first; - for (; e > 1; e--)t = t.next; - var n = t.next; - t.next = n.next; - this.length--; - return n.item -}; -LinkedList.prototype.remove = function (e, t) { - t = t || function (t) { - return t === e - }; - var n = this.first; - var r = null; - while (n) { - if (t(n.item)) { - if (n === this.first)this.first = n.next; - if (n === this.last)this.last = r; - if (r)r.next = n.next; - return - } - r = n; - n = n.next - } -}; -LinkedList.prototype.removeAll = function (e, t) { - t = t || function (t) { - return t === e - }; - var n = this.first; - var r = null; - while (n) { - if (t(n.item)) { - if (n === this.first)this.first = n.next; - if (n === this.last)this.last = r; - if (r)r.next = n.next - } else r = n; - n = n.next - } -}; -LinkedList.prototype.removeSegment = function (e, t) { - var n = []; - if (t > -1 && e < this.length) { - if (e === 0)return this.multiPopFront(t + 1); - if (t === this.length - 1 || e > t)return this.multiPopBack(Math.max(t - e, this.length - e)).reverse(); - var r = this.first; - for (var i = 0; i < e - 1; i++)r = r.next; - var s = r.next; - for (var o = e; o < t + 1 && o < this.length; o++) { - n.push(s.item); - s = s.next - } - this.length -= Math.min(t - e + 1, this.length - e); - r.next = s - } - return n -}; -LinkedList.prototype.modifyAt = function (e, t) { - var n = this.getNode(e); - if (n)n.item = t -}; -LinkedList.prototype.clear = function () { - this.first = null; - this.last = null; - this.length = 0 -}; -LinkedList.prototype.contains = function (e, t) { - t = t || function (t) { - return t === e - }; - var n = 0; - var r = this.first; - while (n < this.length && !t(r.item)) { - n++; - r = r.next - } - return n < this.length -}; -LinkedList.prototype.execute = function (e) { - var t = this.first; - while (t) { - t.item = e(t.item); - t = t.next - } -}; -LinkedList.prototype.getNode = function (e) { - if (e < 0 || e > this.length - 1)return undefined; - var t = this.first; - for (; e > 0; e--)t = t.next; - return t -}; -LinkedList.prototype.getItem = function (e) { - if (e < 0 || e > this.length - 1)return undefined; - var t = this.first; - for (; e > 0; e--)t = t.next; - return t.item -}; -LinkedList.prototype.toArray = function () { - var e = []; - for (var t = this.first, n = 0; t; t = t.next, n++)e[n] = t.item; - return e -}; -LinkedList.prototype.getLength = function () { - return this.length -}; -LinkedList.prototype.fromArray = function (e) { - var t = this.first; - for (var n = 0; n < Math.min(this.length, e.length); n++, t = t.next)t.item = e[n]; - if (this.length < e.length)for (var r = this.length; r < e.length; r++)this.pushBack(e[r]); else for (var i = e.length; i < this.length;)this.popBack() -}; -LinkedList.prototype.filter = function (e) { - var t = []; - for (var n = this.first; n; n = n.next) { - if (e(n.item))t.push(n.item) - } - return t -}; -LinkedList.prototype.isEmpty = function () { - return!this.length -}; -LinkedList.prototype.indexOf = function (e, t) { - t = t || function (t) { - return t === e - }; - var n = 0; - var r = this.first; - while (r) { - if (t(r.item))return n; - n++; - r = r.next - } - return-1 -}; -LinkedList.prototype.lastIndexOf = function (e, t) { - t = t || function (t) { - return t === e - }; - var n = 0; - var r = this.first; - var i = -1; - while (r) { - if (t(r.item))i = n; - n++; - r = r.next - } - return i -}; -LinkedList.prototype.allIndexesOf = function (e, t) { - t = t || function (t) { - return t === e - }; - var n = 0; - var r = this.first; - var i = []; - while (r) { - if (t(r.item))i.push(n); - n++; - r = r.next - } - return i -}; -LinkedList.prototype.join = function (e) { - if (this.last)this.last.next = e.first; else this.first = e.first; - this.last = e.last; - this.length += e.length -}; -LinkedList.prototype.divide = function (e) { - var t = new LinkedList; - if (e > -1 && e < this.length) { - var n = this.first; - var r = null; - for (var i = 0; i < e; i++) { - r = n; - n = n.next - } - if (n === this.first) { - t.first = this.first; - t.last = this.last; - this.first = null; - this.last = null - } else { - t.first = n; - t.last = this.last; - this.last = r; - r.next = null - } - t.length = this.length - e; - this.length = e - } - return t -}; -LinkedList.prototype.clone = function () { - var e = new LinkedList; - var t = this.first; - for (var n = 0; n < this.length; n++, t = t.next)if (t.item.clone)e.pushBack(t.item.clone()); else e.pushBack(t.item); - return e -}; -LinkedList.prototype.cloneDistinct = function () { - var e = new LinkedList; - var t = this.first; - for (var n = 0; n < this.length; n++, t = t.next)if (!e.contains(t.item))if (t.item.cloneDistinct)e.pushBack(t.item.cloneDistinct()); else if (t.item.clone)e.pushBack(t.item.clone()); else e.pushBack(t.item); - return e -}; -LinkedList.prototype.split = function (e) { - var t = this.length; - var n = [this]; - for (var r = e; r < t; r += e)n.push(n[n.length - 1].divide(e)); - return n -}; -LinkedList.prototype.count = function (e) { - var t = 0; - var n = this.first; - while (n) { - if (e(n.item))t++; - n = n.next - } - return t -}; -LinkedListIterator.prototype = new Iterator; -LinkedListIterator.prototype.constructor = LinkedListIterator; -LinkedListIterator.prototype.first = function () { - this.pointer = this.aggregate.first -}; -LinkedListIterator.prototype.next = function () { - this.pointer = this.pointer.next -}; -LinkedListIterator.prototype.last = function () { - this.pointer = this.aggregate.last -}; -LinkedListIterator.prototype.previous = function () { - var e = this.pointer; - for (this.pointer = this.first(); this.pointer.next !== e;)this.next() -}; -LinkedListIterator.prototype.isDone = function () { - return!this.pointer -}; -LinkedListIterator.prototype.getItem = function () { - return this.pointer.item -}; -LinkedListIterator.prototype.getNode = function () { - return this.pointer -}; -PriorityQueue.prototype = new Aggregate; -PriorityQueue.prototype.constructor = PriorityQueue; -PriorityQueue.prototype.getIterator = function () { - return new PriorityQueueIterator(this) -}; -PriorityQueue.prototype.enqueue = function (e, t) { - var n = this.items.search(e); - if (!n) { - n = new Queue; - this.items.insert(e, n) - } - n.enqueue(t); - this.length++ -}; -PriorityQueue.prototype.multiEnqueue = function (e, t) { - for (var n = 0; n < t.length; n++)this.enqueue(e, t[n]) -}; -PriorityQueue.prototype.dequeue = function () { - var e = this.items.maximum(); - var t = undefined; - if (e) { - var n = e.item; - t = n.dequeue(); - if (n.isEmpty())this.items.deleteNode(e); - this.length-- - } - return t -}; -PriorityQueue.prototype.multiDequeue = function (e) { - var t = []; - for (var n = 0; n < e && this.length; n++)t.push(this.dequeue()); - return t -}; -PriorityQueue.prototype.remove = function (e, t) { - t = t || 1; - var n = this.items.getIterator(); - for (n.last(); !n.isDone() && t > 0; n.previous()) { - var r = n.getItem(); - if (e > -1 && e < r.getLength()) { - var i = r.getLength(); - r.remove(e, t); - t -= i - e; - e = 0; - if (!r.getLength())this.items.deleteNode(n.getNode()) - } else e = e - r.getLength() - } -}; -PriorityQueue.prototype.getItem = function (e) { - var t = this.items.getIterator(); - for (t.last(); !t.isDone(); t.previous()) { - var n = t.getItem(); - if (e > -1 && e < n.getLength())return n.getItem(e); - e = e - n.getLength() - } - return undefined -}; -PriorityQueue.prototype.getItems = function (e) { - var t = this.items.search(e); - if (t)return t.items; - return[] -}; -PriorityQueue.prototype.peek = function () { - return this.items.maximum().item.peek() -}; -PriorityQueue.prototype.getLength = function () { - return this.length -}; -PriorityQueue.prototype.isEmpty = function () { - return!this.length -}; -PriorityQueue.prototype.clear = function () { - this.items = new RBTreeList; - this.length = 0 -}; -PriorityQueue.prototype.containsPriority = function (e, t) { - if (t)return this.items.fullContains(t); else return this.items.contains(e) -}; -PriorityQueue.prototype.toQueue = function () { - var e = new Queue; - var t = this.items.getIterator(); - for (t.last(); !t.isDone(); t.previous()) { - var n = t.getItem(); - var r = n.getIterator(); - for (r.first(); !r.isDone(); r.next())e.enqueue(r.getItem()) - } - return e -}; -PriorityQueue.prototype.execute = function (e) { - var t = this.items.getIterator(); - for (t.last(); !t.isDone(); t.previous())t.getItem().execute(e) -}; -PriorityQueue.prototype.changePriority = function (e, t) { - var n = this.getItem(e); - this.remove(e); - this.enqueue(t, n) -}; -PriorityQueue.prototype.filter = function (e) { - var t = []; - var n = this.items.getIterator(); - for (n.last(); !n.isDone(); n.previous()) { - var r = n.getItem().getIterator(); - for (r.first(); !r.isDone(); r.next()) { - if (e(r.getItem()))t.push(r.getItem()) - } - } - return t -}; -PriorityQueue.prototype.clone = function () { - var e = new PriorityQueue; - e.items = this.items.clone(); - e.length = this.length; - return e -}; -PriorityQueue.prototype.cloneDistinct = function () { - var e = new PriorityQueue; - e.items = this.items.cloneDistinct(); - e.length = e.items.getSize(); - return e -}; -PriorityQueueIterator.prototype = new Iterator; -PriorityQueueIterator.prototype.constructor = PriorityQueueIterator; -PriorityQueueIterator.prototype.first = function () { - this.pointerNode = this.aggregate.items.maximum(); - this.pointerPosition = 0 -}; -PriorityQueueIterator.prototype.next = function () { - this.pointerPosition++; - if (this.pointerPosition > this.pointerNode.item.getLength() - 1) { - this.pointerNode = this.pointerNode.previous; - this.pointerPosition = 0 - } -}; -PriorityQueueIterator.prototype.last = function () { - this.pointerNode = this.aggregate.items.minimum(); - this.pointerPosition = this.pointerNode.item.getLength() - 1 -}; -PriorityQueueIterator.prototype.previous = function () { - this.pointerPosition--; - if (this.pointerPosition < 0) { - this.pointerNode = this.pointerNode.next; - if (this.pointerNode)this.pointerPosition = this.pointerNode.item.getLength() - 1 - } -}; -PriorityQueueIterator.prototype.isDone = function () { - return!this.pointerNode -}; -PriorityQueueIterator.prototype.getItem = function () { - return this.pointerNode.item.items[this.pointerPosition] -}; -Queue.prototype = new Aggregate; -Queue.prototype.constructor = Queue; -Queue.prototype.getIterator = function () { - return new QueueIterator(this) -}; -Queue.prototype.enqueue = function (e) { - this.items.push(e) -}; -Queue.prototype.multiEnqueue = function (e) { - for (var t = 0; t < e.length; t++)this.items.push(e[t]) -}; -Queue.prototype.dequeue = function () { - if (!this.items.length)return undefined; - return this.items.splice(0, 1)[0] -}; -Queue.prototype.multiDequeue = function (e) { - return this.items.splice(0, e) -}; -Queue.prototype.remove = function (e, t) { - t = t || 1; - this.items.splice(e, t) -}; -Queue.prototype.getItem = function (e) { - if (e < 0 || e > this.items.length - 1)return undefined; - return this.items[e] -}; -Queue.prototype.peek = function () { - if (this.items.length)return this.items[0]; - return undefined -}; -Queue.prototype.clear = function () { - this.items = [] -}; -Queue.prototype.contains = function (e, t) { - t = t || function (t) { - return t === e - }; - var n = 0; - while (n < this.items.length && !t(this.items[n]))n++; - return n < this.items.length -}; -Queue.prototype.execute = function (e) { - for (var t = 0; t < this.items.length; t++)this.items[t] = e(this.items[t]) -}; -Queue.prototype.getLength = function () { - return this.items.length -}; -Queue.prototype.isEmpty = function () { - return!this.items.length -}; -Queue.prototype.filter = function (e) { - var t = []; - for (var n = 0; n < this.items.length; n++)if (e(this.items[n]))t.push(this.items[n]); - return t -}; -Queue.prototype.indexOf = function (e, t) { - t = t || function (t) { - return t === e - }; - var n = 0; - while (n < this.items.length) { - if (t(this.items[n]))return n; - n++ - } - return-1 -}; -Queue.prototype.lastIndexOf = function (e, t) { - t = t || function (t) { - return t === e - }; - var n = this.items.length - 1; - while (n > -1) { - if (t(this.items[n]))return n; - n-- - } - return-1 -}; -Queue.prototype.allIndexesOf = function (e, t) { - t = t || function (t) { - return t === e - }; - var n = 0; - var r = []; - while (n < this.items.length) { - if (t(this.items[n]))r.push(n); - n++ - } - return r -}; -Queue.prototype.clone = function () { - var e = new Queue; - for (var t = 0; t < this.items.length; t++)if (this.items[t].clone)e.enqueue(this.items[t].clone()); else e.enqueue(this.items[t]); - return e -}; -Queue.prototype.cloneDistinct = function () { - var e = new Queue; - for (var t = 0; t < this.items.length; t++)if (!e.contains(this.items[t]))if (this.items[t].cloneDistinct)e.enqueue(this.items[t].cloneDistinct()); else if (this.items[t].clone)e.enqueue(this.items[t].clone()); else e.enqueue(this.items[t]); - return e -}; -QueueIterator.prototype = new Iterator; -QueueIterator.prototype.constructor = QueueIterator; -QueueIterator.prototype.first = function () { - this.pointer = 0 -}; -QueueIterator.prototype.next = function () { - this.pointer++ -}; -QueueIterator.prototype.last = function () { - this.pointer = this.aggregate.items.length - 1 -}; -QueueIterator.prototype.previous = function () { - this.pointer-- -}; -QueueIterator.prototype.isDone = function () { - return this.pointer < 0 || this.pointer > this.aggregate.items.length - 1 -}; -QueueIterator.prototype.getItem = function () { - return this.aggregate.getItem(this.pointer) -}; -RBTree.prototype = new Aggregate; -RBTree.prototype.constructor = RBTree; -RBTree.prototype.getIterator = function () { - return new RBTreeIterator(this) -}; -RBTree.prototype.insert = function (e, t) { - var n = new RBNode(e, t); - this.size++; - if (!this.root) { - this.root = n; - n.type = "b"; - return - } - var r = this.root; - for (var i = this.root; i;) { - r = i; - if (e < i.key)i = i.left; else i = i.right - } - n.parent = r; - if (!r)this.root = n; else if (e < r.key)r.left = n; else r.right = n; - this.insertFixUp(n) -}; -RBTree.prototype.insertFixUp = function (e) { - for (var t = e.parent; t && t.type === "r"; t = e.parent) { - if (t === t.parent.left) { - var n = t.parent.right; - if (n && n.type === "r") { - t.type = "b"; - n.type = "b"; - t.parent.type = "r"; - e = t.parent - } else if (e === t.right) { - e = t; - this.leftRotate(e) - } else { - t.type = "b"; - t.parent.type = "r"; - this.rightRotate(t.parent) - } - } else { - var n = t.parent.left; - if (n && n.type === "r") { - t.type = "b"; - n.type = "b"; - t.parent.type = "r"; - e = t.parent - } else if (e === t.left) { - e = t; - this.rightRotate(e) - } else { - t.type = "b"; - t.parent.type = "r"; - this.leftRotate(t.parent) - } - } - } - this.root.type = "b" -}; -RBTree.prototype.deleteNode = function (e) { - var t; - this.size--; - if (!e.left || !e.right)t = e; else { - t = this.successor(e); - e.key = t.key; - e.item = t.item - } - var n; - if (!t.left)n = t.right; else n = t.left; - if (n)n.parent = t.parent; - if (!t.parent)this.root = n; else if (t === t.parent.left)t.parent.left = n; else t.parent.right = n; - if (t.type === "b")this.deleteFixUp(n, t.parent) -}; -RBTree.prototype.deleteFixUp = function (e, t) { - while (e !== this.root && (!e || e.type === "b")) { - if (e === t.left) { - var n = t.right; - if (n && n.type === "r") { - n.type = "b"; - t.type = "r"; - this.leftRotate(t); - n = t.right - } - if (n && (!n.left || n.left.type === "b") && (!n.right || n.right.type === "b")) { - n.type = "r"; - e = t - } else { - if (!n.right || n.right.type === "b") { - n.left.type = "b"; - n.type = "r"; - this.rightRotate(n); - n = t.right - } - n.type = t.type; - t.type = "b"; - n.right.type = "b"; - this.leftRotate(t); - e = this.root - } - } else { - var n = t.left; - if (n && n.type === "r") { - n.type = "b"; - t.type = "r"; - this.rightRotate(t); - n = t.left - } - if (n && (!n.left || n.left.type === "b") && (!n.right || n.right.type === "b")) { - n.type = "r"; - e = t - } else { - if (!n.left || n.left.type === "b") { - n.right.type = "b"; - n.type = "r"; - this.leftRotate(n); - n = t.left - } - n.type = t.type; - t.type = "b"; - n.left.type = "b"; - this.rightRotate(t); - e = this.root - } - } - t = e.parent - } - if (e)e.type = "b" -}; -RBTree.prototype.successor = function (e) { - if (e.right)return this.minimum(e.right); - var t = e.parent; - while (t && e === t.right) { - e = t; - t = t.parent - } - return t -}; -RBTree.prototype.predecessor = function (e) { - if (e.left)return this.maximum(e.left); - var t = e.parent; - while (t && e === t.left) { - e = t; - t = t.parent - } - return t -}; -RBTree.prototype.search = function (e, t, n) { - t = t || this.root; - n = n || function (t) { - return t.key === e - }; - while (t && !n(t))if (e < t.key)t = t.left; else t = t.right; - if (t)return t.item; - return undefined -}; -RBTree.prototype.contains = function (e, t) { - return this.search(e, null, t) !== undefined -}; -RBTree.prototype.fullContains = function (e) { - var t = this.minimum(); - while (t && !e(t.key))t = this.successor(t); - return t !== null -}; -RBTree.prototype.minimum = function (e) { - e = e || this.root; - while (e && e.left)e = e.left; - return e -}; -RBTree.prototype.maximum = function (e) { - e = e || this.root; - while (e && e.right)e = e.right; - return e -}; -RBTree.prototype.leftRotate = function (e) { - var t = e.right; - e.right = t.left; - if (t.left !== null)t.left.parent = e; - t.parent = e.parent; - if (e.parent === null)this.root = t; else if (e === e.parent.left)e.parent.left = t; else e.parent.right = t; - e.parent = t; - t.left = e -}; -RBTree.prototype.rightRotate = function (e) { - var t = e.left; - e.left = t.right; - if (t.right !== null)t.right.parent = e; - t.parent = e.parent; - if (e.parent === null)this.root = t; else if (e === e.parent.left)e.parent.left = t; else e.parent.right = t; - e.parent = t; - t.right = e -}; -RBTree.prototype.getSize = function () { - return this.size -}; -RBTree.prototype.clone = function () { - var e = new RBTree; - var t = this.getIterator(); - for (t.first(); !t.isDone(); t.next())if (t.getNode().item.clone)e.insert(t.getNode().key, t.getNode().item.clone()); else e.insert(t.getNode().key, t.getNode().item); - return e -}; -RBTree.prototype.cloneDistinct = function () { - var e = new RBTree; - var t = this.getIterator(); - for (t.first(); !t.isDone(); t.next()) { - var n = function (e) { - return e.key === t.getNode().key && e.item === t.getNode().item - }; - if (!e.contains(t.getNode().key, n)) { - if (t.getNode().item.cloneDistinct)e.insert(t.getNode().key, t.getNode().item.cloneDistinct()); else if (t.getNode().item.clone)e.insert(t.getNode().key, t.getNode().item.clone()); else e.insert(t.getNode().key, t.getNode().item) - } - } - return e -}; -RBTree.prototype.toArray = function () { - var e = []; - for (var t = this.minimum(); t; t = this.successor(t))e.push(t.item); - return e -}; -RBTree.prototype.clear = function () { - this.root = null; - this.size = 0 -}; -RBTree.prototype.isEmpty = function () { - return!this.size -}; -RBTree.prototype.execute = function (e) { - for (var t = this.minimum(); t; t = this.successor(t))t.item = e(t.item) -}; -RBTree.prototype.filter = function (e) { - var t = []; - for (var n = this.minimum(); n; n = this.successor(n))if (e(n.item))t.push(n.item); - return t -}; -RBTree.prototype.indexOf = function (e, t) { - t = t || function (t) { - return t === e - }; - var n = 0, r = this.minimum(); - while (r) { - if (t(r.item))return n; - r = this.successor(r); - n++ - } - return-1 -}; -RBTree.prototype.lastIndexOf = function (e, t) { - t = t || function (t) { - return t === e - }; - var n = this.size - 1, r = this.maximum(); - while (r) { - if (t(r.item))return n; - n--; - r = this.predecessor(r) - } - return-1 -}; -RBTree.prototype.allIndexesOf = function (e, t) { - t = t || function (t) { - return t === e - }; - var n = 0, r = this.minimum(); - var i = []; - while (r) { - if (t(r.item))i.push(n); - n++; - r = this.successor(r) - } - return i -}; -RBTree.prototype.getItem = function (e) { - if (e < 0 || e > this.size - 1)return undefined; - for (var t = this.minimum(), n = 0; n < e; t = this.successor(t))n++; - return t.item -}; -RBTreeIterator.prototype = new Iterator; -RBTreeIterator.prototype.constructor = RBTreeIterator; -RBTreeIterator.prototype.first = function () { - this.pointer = this.aggregate.minimum() -}; -RBTreeIterator.prototype.next = function () { - this.pointer = this.aggregate.successor(this.pointer) -}; -RBTreeIterator.prototype.last = function () { - this.pointer = this.aggregate.maximum() -}; -RBTreeIterator.prototype.previous = function () { - this.pointer = this.aggregate.predecessor(this.pointer) -}; -RBTreeIterator.prototype.isDone = function () { - return!this.pointer -}; -RBTreeIterator.prototype.getItem = function () { - return this.pointer.item -}; -RBTreeIterator.prototype.getNode = function () { - return this.pointer -}; -RBTreeList.prototype = new Aggregate; -RBTreeList.prototype.constructor = RBTreeList; -RBTreeList.prototype.getIterator = function () { - return new RBTreeListIterator(this) -}; -RBTreeList.prototype.insert = function (e, t) { - var n = new RBLNode(e, t); - this.size++; - if (!this.root) { - this.root = n; - this.first = n; - this.last = n; - n.type = "b"; - return - } - var r = this.root; - for (var i = this.root; i;) { - r = i; - if (e < i.key)i = i.left; else i = i.right - } - n.parent = r; - if (!r)this.root = n; else if (e < r.key)r.left = n; else r.right = n; - n.next = this.successor(n); - if (n.next) { - if (n.next.previous)n.next.previous.next = n; else this.first = n; - n.previous = n.next.previous; - n.next.previous = n - } else { - this.last = n; - n.previous = this.predecessor(n); - if (n.previous)n.previous.next = n; else this.first = n - } - this.insertFixUp(n) -}; -RBTreeList.prototype.insertFixUp = function (e) { - for (var t = e.parent; t && t.type === "r"; t = e.parent) { - if (t === t.parent.left) { - var n = t.parent.right; - if (n && n.type === "r") { - t.type = "b"; - n.type = "b"; - t.parent.type = "r"; - e = t.parent - } else if (e === t.right) { - e = t; - this.leftRotate(e) - } else { - t.type = "b"; - t.parent.type = "r"; - this.rightRotate(t.parent) - } - } else { - var n = t.parent.left; - if (n && n.type === "r") { - t.type = "b"; - n.type = "b"; - t.parent.type = "r"; - e = t.parent - } else if (e === t.left) { - e = t; - this.rightRotate(e) - } else { - t.type = "b"; - t.parent.type = "r"; - this.leftRotate(t.parent) - } - } - } - this.root.type = "b" -}; -RBTreeList.prototype.deleteNode = function (e) { - this.size--; - var t; - if (!e.left || !e.right)t = e; else { - t = this.successor(e); - e.key = t.key; - e.item = t.item - } - var n; - if (!t.left)n = t.right; else n = t.left; - if (n)n.parent = t.parent; - if (!t.parent)this.root = n; else if (t === t.parent.left)t.parent.left = n; else t.parent.right = n; - if (t.next)t.next.previous = t.previous; else this.last = t.previous; - if (t.previous)t.previous.next = t.next; else this.first = t.next; - if (t.type === "b")this.deleteFixUp(n, t.parent) -}; -RBTreeList.prototype.deleteFixUp = function (e, t) { - while (e !== this.root && (!e || e.type === "b")) { - if (e === t.left) { - var n = t.right; - if (n && n.type === "r") { - n.type = "b"; - t.type = "r"; - this.leftRotate(t); - n = t.right - } - if (n && (!n.left || n.left.type === "b") && (!n.right || n.right.type === "b")) { - n.type = "r"; - e = t - } else { - if (!n.right || n.right.type === "b") { - n.left.type = "b"; - n.type = "r"; - this.rightRotate(n); - n = t.right - } - n.type = t.type; - t.type = "b"; - n.right.type = "b"; - this.leftRotate(t); - e = this.root - } - } else { - var n = t.left; - if (n && n.type === "r") { - n.type = "b"; - t.type = "r"; - this.rightRotate(t); - n = t.left - } - if (n && (!n.left || n.left.type === "b") && (!n.right || n.right.type === "b")) { - n.type = "r"; - e = t - } else { - if (!n.left || n.left.type === "b") { - n.right.type = "b"; - n.type = "r"; - this.leftRotate(n); - n = t.left - } - n.type = t.type; - t.type = "b"; - n.left.type = "b"; - this.rightRotate(t); - e = this.root - } - } - t = e.parent - } - if (e)e.type = "b" -}; -RBTreeList.prototype.successor = function (e) { - if (e.next || e === this.last)return e.next; - if (e.right)return this.minimum(e.right); - var t = e.parent; - while (t && e === t.right) { - e = t; - t = t.parent - } - return t -}; -RBTreeList.prototype.predecessor = function (e) { - if (e.previous || e === this.first)return e.previous; - if (e.left)return this.maximum(e.left); - var t = e.parent; - while (t && e === t.left) { - e = t; - t = t.parent - } - return t -}; -RBTreeList.prototype.search = function (e, t, n) { - t = t || this.root; - n = n || function (t) { - return t.key === e - }; - while (t && !n(t))if (e < t.key)t = t.left; else t = t.right; - if (t)return t.item; - return undefined -}; -RBTreeList.prototype.contains = function (e, t) { - return this.search(e, null, t) !== undefined -}; -RBTreeList.prototype.fullContains = function (e) { - var t = this.first; - while (t && !e(t.key))t = t.next; - return t !== null -}; -RBTreeList.prototype.minimum = function (e) { - if (e)while (e && e.left)e = e.left; else return this.first; - return e -}; -RBTreeList.prototype.maximum = function (e) { - if (e)while (e && e.right)e = e.right; else return this.last; - return e -}; -RBTreeList.prototype.leftRotate = function (e) { - var t = e.right; - e.right = t.left; - if (t.left !== null)t.left.parent = e; - t.parent = e.parent; - if (e.parent === null)this.root = t; else if (e === e.parent.left)e.parent.left = t; else e.parent.right = t; - e.parent = t; - t.left = e -}; -RBTreeList.prototype.rightRotate = function (e) { - var t = e.left; - e.left = t.right; - if (t.right !== null)t.right.parent = e; - t.parent = e.parent; - if (e.parent === null)this.root = t; else if (e === e.parent.left)e.parent.left = t; else e.parent.right = t; - e.parent = t; - t.right = e -}; -RBTreeList.prototype.getSize = function () { - return this.size -}; -RBTreeList.prototype.clone = function () { - var e = new RBTreeList; - var t = this.getIterator(); - for (t.first(); !t.isDone(); t.next())e.insert(t.getNode().key, t.getNode().item); - return e -}; -RBTreeList.prototype.cloneDistinct = function () { - var e = new RBTreeList; - var t = this.getIterator(); - for (t.first(); !t.isDone(); t.next()) { - var n = function (e) { - return e.key === t.getNode().key && e.item === t.getNode().item - }; - if (!e.contains(t.getNode().key, n)) { - if (t.getNode().item.cloneDistinct)e.insert(t.getNode().key, t.getNode().item.cloneDistinct()); else if (t.getNode().item.clone)e.insert(t.getNode().key, t.getNode().item.clone()); else e.insert(t.getNode().key, t.getNode().item) - } - } - return e -}; -RBTreeList.prototype.toArray = function () { - var e = []; - for (var t = this.first; t; t = t.next)e.push(t.item); - return e -}; -RBTreeList.prototype.clear = function () { - this.root = null; - this.first = null; - this.last = null; - this.size = 0 -}; -RBTreeList.prototype.isEmpty = function () { - return!this.size -}; -RBTreeList.prototype.execute = function (e) { - for (var t = this.first; t; t = t.next)t.item = e(t.item) -}; -RBTreeList.prototype.filter = function (e) { - var t = []; - for (var n = this.first; n; n = n.next)if (e(n.item))t.push(n.item); - return t -}; -RBTreeList.prototype.indexOf = function (e, t) { - t = t || function (t) { - return t === e - }; - var n = 0, r = this.first; - while (r) { - if (t(r.item))return n; - r = r.next; - n++ - } - return-1 -}; -RBTreeList.prototype.lastIndexOf = function (e, t) { - t = t || function (t) { - return t === e - }; - var n = this.size - 1, r = this.last; - while (r) { - if (t(r.item))return n; - n--; - r = r.previous - } - return-1 -}; -RBTreeList.prototype.allIndexesOf = function (e, t) { - t = t || function (t) { - return t === e - }; - var n = 0, r = this.first; - var i = []; - while (r) { - if (t(r.item))i.push(n); - n++; - r = r.next - } - return i -}; -RBTreeList.prototype.getItem = function (e) { - if (e < 0 || e > this.size - 1)return undefined; - for (var t = this.first, n = 0; n < e; t = t.next)n++; - return t.item -}; -RBTreeListIterator.prototype = new Iterator; -RBTreeListIterator.prototype.constructor = RBTreeListIterator; -RBTreeListIterator.prototype.first = function () { - this.pointer = this.aggregate.first -}; -RBTreeListIterator.prototype.next = function () { - this.pointer = this.pointer.next -}; -RBTreeListIterator.prototype.last = function () { - this.pointer = this.aggregate.last -}; -RBTreeListIterator.prototype.previous = function () { - this.pointer = this.pointer.previous -}; -RBTreeListIterator.prototype.isDone = function () { - return!this.pointer -}; -RBTreeListIterator.prototype.getItem = function () { - return this.pointer.item -}; -RBTreeListIterator.prototype.getNode = function () { - return this.pointer -}; -Set.prototype.insert = function (e) { - this.elements.pushBack(e); - e.parents.pushBack(this); - this.size++ -}; -Set.prototype.multiInsert = function (e) { - for (var t = 0; t < e.length; t++) { - this.elements.pushBack(e[t]); - e[t].parents.pushBack(this) - } - this.size += e.length -}; -Set.prototype.union = function (e) { - var t = new Set; - t.addSubsets([this, e]); - this.parents.pushBack(t); - e.parents.pushBack(t); - var n = this; - var r = function (e) { - if (e === n)return t - }; - var i = this.sets.getIterator(); - for (i.first(); !i.isDone(); i.next())i.getItem().parents.execute(r); - r = function (n) { - if (n === e)return t - }; - i = e.sets.getIterator(); - for (i.first(); !i.isDone(); i.next())i.getItem().parents.execute(r); - return t -}; -Set.prototype.intersect = function (e) { - var t = new Set; - var n = this.elements.getIterator(); - for (n.first(); !n.isDone(); n.next())if (n.getItem().parents.contains(e))t.insert(n.getItem()); - var r = this.sets.getIterator(); - for (r.first(); !r.isDone(); r.next()) { - n = r.getItem().getIterator(); - for (n.first(); !n.isDone(); n.next())if (n.getItem().parents.contains(e))t.insert(n.getItem()) - } - return t -}; -Set.prototype.difference = function (e) { - var t = new Set; - var n = this.elements.getIterator(); - for (n.first(); !n.isDone(); n.next())if (!n.getItem().parents.contains(e))t.insert(n.getItem()); - var r = this.sets.getIterator(); - for (r.first(); !r.isDone(); r.next()) { - n = r.getItem().getIterator(); - for (n.first(); !n.isDone(); n.next())if (!n.getItem().parents.contains(e))t.insert(n.getItem()) - } - return t -}; -Set.prototype.cartesianProduct = function (e) { - var t = this.getItems(); - var n = e.getItems(); - var r = new Set; - for (var i = 0; i < t.length; i++)for (var s = 0; s < n.length; s++)r.insert(new Element([t[i], n[s]])); - return r -}; -Set.prototype.addSubset = function (e) { - this.sets.pushBack(e); - this.size += e.size -}; -Set.prototype.addSubsets = function (e) { - for (var t = 0; t < e.length; t++)this.addSubset(e[t]) -}; -Set.prototype.getItems = function () { - var e = []; - var t = this.elements.getIterator(); - for (t.first(); !t.isDone(); t.next())e.push(t.getItem().item); - var n = this.sets.getIterator(); - for (n.first(); !n.isDone(); n.next()) { - t = n.getItem().getIterator(); - for (t.first(); !t.isDone(); t.next())e.push(t.getItem().item) - } - return e -}; -Set.prototype.getCardinality = function () { - return this.size -}; -Set.prototype.isEmpty = function () { - return!this.size -}; -Set.prototype.clone = function () { - var e = new Set; - e.parents = this.parents.clone(); - e.elements = this.elements.clone(); - e.sets = this.sets.clone(); - e.size = this.size; - return e -}; -Stack.prototype = new Aggregate; -Stack.prototype.constructor = Stack; -Stack.prototype.getIterator = function () { - return new StackIterator(this) -}; -Stack.prototype.push = function (e) { - this.items.push(e) -}; -Stack.prototype.multiPush = function (e) { - for (var t = 0; t < e.length; t++)this.push(e[t]) -}; -Stack.prototype.pop = function () { - if (!this.items.length)return undefined; - return this.items.pop() -}; -Stack.prototype.multiPop = function (e) { - var t = []; - for (var n = 0; n < e && this.items.length; n++)t.push(this.pop()); - return t -}; -Stack.prototype.peek = function () { - if (!this.items.length)return undefined; - return this.items[this.items.length - 1] -}; -Stack.prototype.clear = function () { - this.items = [] -}; -Stack.prototype.contains = function (e, t) { - t = t || function (t) { - return t === e - }; - var n = 0; - while (n < this.items.length && !t(this.items[n]))n++; - return n < this.items.length -}; -Stack.prototype.execute = function (e) { - for (var t = this.items.length - 1; t > -1; t--)this.items[t] = e(this.items[t]) -}; -Stack.prototype.getItem = function (e) { - if (e < 0 || e > this.items.length - 1)return undefined; - return this.items[this.items.length - e - 1] -}; -Stack.prototype.getLength = function () { - return this.items.length -}; -Stack.prototype.isEmpty = function () { - return!this.items.length -}; -Stack.prototype.filter = function (e) { - var t = []; - for (var n = this.items.length - 1; n > -1; n--) { - if (e(this.items[n]))t.push(this.items[n]) - } - return t -}; -Stack.prototype.indexOf = function (e, t) { - t = t || function (t) { - return t === e - }; - var n = this.items.length - 1; - while (n > -1) { - if (t(this.items[n]))return n; - n-- - } - return-1 -}; -Stack.prototype.lastIndexOf = function (e, t) { - t = t || function (t) { - return t === e - }; - var n = 0; - while (n < this.items.length) { - if (t(this.items[n]))return n; - n++ - } - return-1 -}; -Stack.prototype.allIndexesOf = function (e, t) { - t = t || function (t) { - return t === e - }; - var n = this.items.length - 1; - var r = []; - while (n > -1) { - if (t(this.items[n]))r.push(n); - n-- - } - return r -}; -Stack.prototype.clone = function () { - var e = new Stack; - for (var t = 0; t < this.items.length; t++)if (this.items[t].clone)e.push(this.items[t].clone()); else e.push(this.items[t]); - return e -}; -Stack.prototype.cloneDistinct = function () { - var e = new Stack; - for (var t = 0; t < this.items.length; t++)if (!e.contains(this.items[t])) { - if (this.items[t].cloneDistinct)e.push(this.items[t].cloneDistinct()); else if (this.items[t].clone)e.push(this.items[t].clone()); else e.push(this.items[t]) - } - return e -}; -StackIterator.prototype = new Iterator; -StackIterator.prototype.constructor = StackIterator; -StackIterator.prototype.first = function () { - this.pointer = this.aggregate.items.length - 1 -}; -StackIterator.prototype.next = function () { - this.pointer-- -}; -StackIterator.prototype.last = function () { - this.pointer = 0 -}; -StackIterator.prototype.previous = function () { - this.pointer++ -}; -StackIterator.prototype.isDone = function () { - return this.pointer < 0 || this.pointer > this.aggregate.items.length - 1 -}; -StackIterator.prototype.getItem = function () { - return this.aggregate.items[this.pointer] -} diff --git a/LICENSE.md b/LICENSE.md deleted file mode 100644 index 5c304d1..0000000 --- a/LICENSE.md +++ /dev/null @@ -1,201 +0,0 @@ -Apache License - Version 2.0, January 2004 - http://www.apache.org/licenses/ - - TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION - - 1. Definitions. - - "License" shall mean the terms and conditions for use, reproduction, - and distribution as defined by Sections 1 through 9 of this document. - - "Licensor" shall mean the copyright owner or entity authorized by - the copyright owner that is granting the License. - - "Legal Entity" shall mean the union of the acting entity and all - other entities that control, are controlled by, or are under common - control with that entity. For the purposes of this definition, - "control" means (i) the power, direct or indirect, to cause the - direction or management of such entity, whether by contract or - otherwise, or (ii) ownership of fifty percent (50%) or more of the - outstanding shares, or (iii) beneficial ownership of such entity. - - "You" (or "Your") shall mean an individual or Legal Entity - exercising permissions granted by this License. - - "Source" form shall mean the preferred form for making modifications, - including but not limited to software source code, documentation - source, and configuration files. - - "Object" form shall mean any form resulting from mechanical - transformation or translation of a Source form, including but - not limited to compiled object code, generated documentation, - and conversions to other media types. - - "Work" shall mean the work of authorship, whether in Source or - Object form, made available under the License, as indicated by a - copyright notice that is included in or attached to the work - (an example is provided in the Appendix below). - - "Derivative Works" shall mean any work, whether in Source or Object - form, that is based on (or derived from) the Work and for which the - editorial revisions, annotations, elaborations, or other modifications - represent, as a whole, an original work of authorship. For the purposes - of this License, Derivative Works shall not include works that remain - separable from, or merely link (or bind by name) to the interfaces of, - the Work and Derivative Works thereof. - - "Contribution" shall mean any work of authorship, including - the original version of the Work and any modifications or additions - to that Work or Derivative Works thereof, that is intentionally - submitted to Licensor for inclusion in the Work by the copyright owner - or by an individual or Legal Entity authorized to submit on behalf of - the copyright owner. For the purposes of this definition, "submitted" - means any form of electronic, verbal, or written communication sent - to the Licensor or its representatives, including but not limited to - communication on electronic mailing lists, source code control systems, - and issue tracking systems that are managed by, or on behalf of, the - Licensor for the purpose of discussing and improving the Work, but - excluding communication that is conspicuously marked or otherwise - designated in writing by the copyright owner as "Not a Contribution." - - "Contributor" shall mean Licensor and any individual or Legal Entity - on behalf of whom a Contribution has been received by Licensor and - subsequently incorporated within the Work. - - 2. Grant of Copyright License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - copyright license to reproduce, prepare Derivative Works of, - publicly display, publicly perform, sublicense, and distribute the - Work and such Derivative Works in Source or Object form. - - 3. Grant of Patent License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - (except as stated in this section) patent license to make, have made, - use, offer to sell, sell, import, and otherwise transfer the Work, - where such license applies only to those patent claims licensable - by such Contributor that are necessarily infringed by their - Contribution(s) alone or by combination of their Contribution(s) - with the Work to which such Contribution(s) was submitted. If You - institute patent litigation against any entity (including a - cross-claim or counterclaim in a lawsuit) alleging that the Work - or a Contribution incorporated within the Work constitutes direct - or contributory patent infringement, then any patent licenses - granted to You under this License for that Work shall terminate - as of the date such litigation is filed. - - 4. Redistribution. You may reproduce and distribute copies of the - Work or Derivative Works thereof in any medium, with or without - modifications, and in Source or Object form, provided that You - meet the following conditions: - - (a) You must give any other recipients of the Work or - Derivative Works a copy of this License; and - - (b) You must cause any modified files to carry prominent notices - stating that You changed the files; and - - (c) You must retain, in the Source form of any Derivative Works - that You distribute, all copyright, patent, trademark, and - attribution notices from the Source form of the Work, - excluding those notices that do not pertain to any part of - the Derivative Works; and - - (d) If the Work includes a "NOTICE" text file as part of its - distribution, then any Derivative Works that You distribute must - include a readable copy of the attribution notices contained - within such NOTICE file, excluding those notices that do not - pertain to any part of the Derivative Works, in at least one - of the following places: within a NOTICE text file distributed - as part of the Derivative Works; within the Source form or - documentation, if provided along with the Derivative Works; or, - within a display generated by the Derivative Works, if and - wherever such third-party notices normally appear. The contents - of the NOTICE file are for informational purposes only and - do not modify the License. You may add Your own attribution - notices within Derivative Works that You distribute, alongside - or as an addendum to the NOTICE text from the Work, provided - that such additional attribution notices cannot be construed - as modifying the License. - - You may add Your own copyright statement to Your modifications and - may provide additional or different license terms and conditions - for use, reproduction, or distribution of Your modifications, or - for any such Derivative Works as a whole, provided Your use, - reproduction, and distribution of the Work otherwise complies with - the conditions stated in this License. - - 5. Submission of Contributions. Unless You explicitly state otherwise, - any Contribution intentionally submitted for inclusion in the Work - by You to the Licensor shall be under the terms and conditions of - this License, without any additional terms or conditions. - Notwithstanding the above, nothing herein shall supersede or modify - the terms of any separate license agreement you may have executed - with Licensor regarding such Contributions. - - 6. Trademarks. This License does not grant permission to use the trade - names, trademarks, service marks, or product names of the Licensor, - except as required for reasonable and customary use in describing the - origin of the Work and reproducing the content of the NOTICE file. - - 7. Disclaimer of Warranty. Unless required by applicable law or - agreed to in writing, Licensor provides the Work (and each - Contributor provides its Contributions) on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - implied, including, without limitation, any warranties or conditions - of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A - PARTICULAR PURPOSE. You are solely responsible for determining the - appropriateness of using or redistributing the Work and assume any - risks associated with Your exercise of permissions under this License. - - 8. Limitation of Liability. In no event and under no legal theory, - whether in tort (including negligence), contract, or otherwise, - unless required by applicable law (such as deliberate and grossly - negligent acts) or agreed to in writing, shall any Contributor be - liable to You for damages, including any direct, indirect, special, - incidental, or consequential damages of any character arising as a - result of this License or out of the use or inability to use the - Work (including but not limited to damages for loss of goodwill, - work stoppage, computer failure or malfunction, or any and all - other commercial damages or losses), even if such Contributor - has been advised of the possibility of such damages. - - 9. Accepting Warranty or Additional Liability. While redistributing - the Work or Derivative Works thereof, You may choose to offer, - and charge a fee for, acceptance of support, warranty, indemnity, - or other liability obligations and/or rights consistent with this - License. However, in accepting such obligations, You may act only - on Your own behalf and on Your sole responsibility, not on behalf - of any other Contributor, and only if You agree to indemnify, - defend, and hold each Contributor harmless for any liability - incurred by, or claims asserted against, such Contributor by reason - of your accepting any such warranty or additional liability. - - END OF TERMS AND CONDITIONS - - APPENDIX: How to apply the Apache License to your work. - - To apply the Apache License to your work, attach the following - boilerplate notice, with the fields enclosed by brackets "{}" - replaced with your own identifying information. (Don't include - the brackets!) The text should be enclosed in the appropriate - comment syntax for the file format. We also recommend that a - file or class name and description of purpose be included on the - same "printed page" as the copyright notice for easier - identification within third-party archives. - - Copyright {yyyy} {name of copyright owner} - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. diff --git a/README.md b/README.md deleted file mode 100644 index 99199ef..0000000 --- a/README.md +++ /dev/null @@ -1,53 +0,0 @@ -[Data Structures](https://github.com/Bishop92/JavaScript-Data-Structures) -================= -**A library for data structures in JavaScript** - -DataStructures is a JavaScript library where you can find the most common data structures and also other data -structures more advanced. Various method are also provided in order to manipulate data structures. - -This library implements the [iterator] (http://en.wikipedia.org/wiki/Iterator_pattern) pattern in order to hide -the data structure that work for storing your data. - -Supported data structures -------------------------- -- [Stack](https://github.com/Bishop92/JavaScript-Data-Structures/wiki/Stack) -- [Queue](https://github.com/Bishop92/JavaScript-Data-Structures/wiki/Queue) -- [Priority Queue](https://github.com/Bishop92/JavaScript-Data-Structures/wiki/Priority-Queue) -- [Circular Buffer](https://github.com/Bishop92/JavaScript-Data-Structures/wiki/Circular-Buffer) -- [Hash Table](https://github.com/Bishop92/JavaScript-Data-Structures/wiki/Hash-Table) -- [Linked List](https://github.com/Bishop92/JavaScript-Data-Structures/wiki/Linked-List) -- [Double Linked List](https://github.com/Bishop92/JavaScript-Data-Structures/wiki/Double-Linked-List) -- [Binary search Tree](https://github.com/Bishop92/JavaScript-Data-Structures/wiki/Binary-search-tree) -- [Red-Black Tree](https://github.com/Bishop92/JavaScript-Data-Structures/wiki/Red-Black-Tree) -- [Red-Black Tree List](https://github.com/Bishop92/JavaScript-Data-Structures/wiki/Red-Black-Tree-List) -- [B-Tree](https://github.com/Bishop92/JavaScript-Data-Structures/wiki/B-Tree) -- [Set](https://github.com/Bishop92/JavaScript-Data-Structures/wiki/Set) -- [Trie](https://github.com/Bishop92/JavaScript-Data-Structures/wiki/Trie) - -How to use ----------- -1. Download the minimized library [here](https://raw.githubusercontent.com/Bishop92/JavaScript-Data-Structures/master/DataStructuresMinimized.js) (right click and save as...); - -2. Include the file in your project; - -3. Start to use it as any other class. - -Example - -```JavaScript -var listA = new DoubleLinkedList(); -var listB = new DoubleLinkedList(); -listA.fromArray([0, 1]); -listB.fromArray([2, 3]); -listA.join(listB); -listA.toArray(); // [0, 1, 2, 3] -``` - -Documentation -------------- -Follow this [link](https://github.com/Bishop92/JavaScript-Data-Structures/wiki) to read the full documentation. -Follow this [link](https://rawgit.com/Bishop92/JavaScript-Data-Structures/master/doc/index.html) to read the JSDoc. - -Support -------- -Battistella Stefano, [stefano.battistella.92@gmail.com](mailto:stefano.battistella.92@gmail.com) diff --git a/Tests/BSTree_Test.js b/Tests/BSTree_Test.js deleted file mode 100644 index 9be2a60..0000000 --- a/Tests/BSTree_Test.js +++ /dev/null @@ -1,82 +0,0 @@ -/** - * Created by Stefano on 06/04/14. - */ - -test("BSTree - Insert test", function () { - var tree = new BSTree(); - var keys = []; - for (var i = 0; i < 20; i++) { - keys.push(Math.random()); - tree.insert(keys[i], i); - } - for (var j = 0; j < 20; j++) - deepEqual(tree.search(keys[j]), j, "Insert node"); -}); - -test("BSTree - Minimum test", function () { - var tree = new BSTree(); - var keys = []; - var min = 10; - for (var i = 0; i < 20; i++) { - keys.push(Math.random()); - tree.insert(keys[i], i); - if (keys[i] < min) - min = keys[i]; - } - deepEqual(tree.minimum().item, tree.search(min), "Minimum"); -}); - -test("BSTree - Maximum test", function () { - var tree = new BSTree(); - var keys = []; - var max = -1; - for (var i = 0; i < 20; i++) { - keys.push(Math.random()); - tree.insert(keys[i], i); - if (keys[i] > max) - max = keys[i]; - } - deepEqual(tree.maximum().item, tree.search(max), "Maximum"); -}); - -test("BSTree - Successor test", function () { - var tree = new BSTree(); - for (var i = 0; i < 20; i++) - tree.insert(i, i); - var it = tree.getIterator(); - var j = 1; - for (it.first(); !it.isDone(); it.next(), j++) { - var successor = tree.successor(it.getNode()); - if (successor) - deepEqual(successor.item, j, "Successor"); - else - deepEqual(successor, null, "No successor"); - } -}); - -test("BSTree - Predecessor test", function () { - var tree = new BSTree(); - for (var i = 0; i < 20; i++) - tree.insert(i, i); - var it = tree.getIterator(); - var j = 18; - for (it.last(); !it.isDone(); it.previous(), j--) { - var predecessor = tree.predecessor(it.getNode()); - if (predecessor) - deepEqual(predecessor.item, j, "Predecessor"); - else - deepEqual(predecessor, null, "No predecessor"); - } -}); - -test("BSTree - Delete node test", function () { - var tree = new BSTree(); - for (var i = 0; i < 20; i++) - tree.insert(i, i); - var j = 0; - while (tree.minimum()) { - deepEqual(tree.minimum().item, j, "Deletion"); - tree.deleteNode(tree.minimum()); - j++; - } -}); \ No newline at end of file diff --git a/Tests/BTree_Test.js b/Tests/BTree_Test.js deleted file mode 100644 index de73fc6..0000000 --- a/Tests/BTree_Test.js +++ /dev/null @@ -1,190 +0,0 @@ -/** - * Created by Stefano on 06/04/14. - */ - -test("BTree - Insert test", function () { - var tree = new BTree(100); - for (var i = 0; i < 100; i++) - tree.insert(i, i); - for (var j = 0; j < 100; j++) { - deepEqual(tree.search(j), j, "Insert node"); - deepEqual(tree.getItem(j), j, "Insert node"); - } -}); - -test("BTree - Delete node test", function () { - var tree = new BTree(3); - for (var i = 0; i < 20; i++) - tree.insert(i, i); - tree.deleteKey(6); - deepEqual(tree.search(6), undefined, "Delete node 6"); -}); - -test("BTree - Successor test", function () { - var tree = new BTree(3); - for (var i = 0; i < 20; i++) - tree.insert(i, i); - for (var j = -1; j < 19; j++) - deepEqual(tree.successor(j), j + 1, "Successor found"); - deepEqual(tree.successor(19), null, "Successor not found"); -}); - -test("BTree - Predecessor test", function () { - var tree = new BTree(4); - for (var i = 0; i < 40; i++) - tree.insert(i, i); - for (var j = 40; j > 0; j--) - deepEqual(tree.predecessor(j), j - 1, "Predecessor"); - deepEqual(tree.predecessor(0), null, "Predecessor not found"); -}); - -test("BTree - Minimum test", function () { - var tree = new BTree(3); - var keys = []; - var min = 10; - for (var i = 0; i < 20; i++) { - keys.push(Math.random()); - tree.insert(keys[i], i); - if (keys[i] < min) - min = keys[i]; - } - deepEqual(tree.minimum(), tree.search(min), "Minimum item"); - deepEqual(tree.minimumKey(), min, "Minimum key"); -}); - -test("BTree - Maximum test", function () { - var tree = new BTree(3); - var keys = []; - var max = -1; - for (var i = 0; i < 20; i++) { - keys.push(Math.random()); - tree.insert(keys[i], i); - if (keys[i] > max) - max = keys[i]; - } - deepEqual(tree.maximum(), tree.search(max), "Maximum item"); - deepEqual(tree.maximumKey(), max, "Maximum key"); -}); - -test("BTree - To array test", function () { - var tree = new BTree(3); - for (var i = 0; i < 5; i++) - tree.insert(i, i); - deepEqual(tree.toArray(), [0, 1, 2, 3, 4], "To array"); -}); - -test("BTree - Filter test", function () { - var tree = new BTree(3); - - for (var i = 0; i < 10; i++) - tree.insert(i, i); - - var result = tree.filter(function (item) { - return 1 - item % 2; - }); - deepEqual(result, [0, 2, 4, 6, 8], "Filter on the even values"); -}); - -test("BTree - Clear test", function () { - var tree = new BTree(3); - tree.insert(0, 0); - tree.insert(2, 2); - tree.clear(); - deepEqual(tree.isEmpty(), true, "Clear tree"); -}); - -test("BTree - Is empty test", function () { - var tree = new BTree(3); - tree.insert(0, 0); - tree.insert(2, 2); - deepEqual(tree.isEmpty(), false, "Is not empty"); - tree.clear(); - deepEqual(tree.isEmpty(), true, "Is empty"); -}); - -test("BTree - Contains test", function () { - var tree = new BTree(3); - tree.insert(0, 0); - tree.insert(2, 2); - deepEqual(tree.contains(0), true, "Contains 0"); - deepEqual(tree.contains(2), true, "Contains 2"); - deepEqual(tree.contains(1), false, "Not contains 1"); - var callback = function (item) { - return item > 0; - }; - deepEqual(tree.fullContains(callback), true, "Contains a value > 0"); - callback = function (item) { - return item < 0; - }; - deepEqual(tree.fullContains(callback), false, "Contains a value < 0"); -}); - -test("BTree - Execute test", function () { - var tree = new BTree(); - tree.insert(0, 0); - tree.insert(2, 2); - var callback = function (item) { - return item * 2; - }; - tree.execute(callback); - deepEqual(tree.search(0), 0, "Execute for key 0"); - deepEqual(tree.search(2), 4, "Execute for key 1"); -}); - -test("BTree - Index of test", function () { - var tree = new BTree(3); - for (var i = 0; i < 10; i++) - tree.insert(i, i); - var callback = function (item) { - return !(item % 2) && item > 5; - }; - deepEqual(tree.indexOf(0), 0, "Index of 0"); - deepEqual(tree.indexOf(15), -1, "Index of 15"); - deepEqual(tree.indexOf(5), 5, "Index of 5"); - deepEqual(tree.indexOf(null, callback), 6, "Index of the first even number greater than 5"); -}); - -test("BTree - Last index of test", function () { - var tree = new BTree(3); - for (var i = 0; i < 10; i++) - tree.insert(i, i); - var callback = function (item) { - return !(item % 2) && item > 5; - }; - deepEqual(tree.lastIndexOf(0), 0, "Last index of 0"); - deepEqual(tree.lastIndexOf(15), -1, "Last index of 15"); - deepEqual(tree.lastIndexOf(5), 5, "Last index of 5"); - deepEqual(tree.lastIndexOf(null, callback), 8, "Index of the last even number greater than 5"); -}); - -test("BTree - Indexes of test", function () { - var tree = new BTree(3); - for (var i = 0; i < 30; i++) - tree.insert(i, i % 10); - var callback = function (item) { - return !(item % 2) && item > 5; - }; - deepEqual(tree.allIndexesOf(0), [0, 10, 20], "Indexes of 0"); - deepEqual(tree.allIndexesOf(15), [], "Indexes of 15"); - deepEqual(tree.allIndexesOf(5), [5, 15, 25], "Indexes of 5"); - deepEqual(tree.allIndexesOf(null, callback), [6, 8, 16, 18, 26, 28], "Indexes of the even numbers greater than 5"); -}); - -test("BTree - Clone test", function () { - var tree = new BTree(3); - for (var i = 0; i < 10; i++) - tree.insert(i, i); - var clone = tree.clone(); - var it = clone.getIterator(); - var j = 0; - for (it.first(); !it.isDone(); it.next(), j++) - deepEqual(it.getItem(), j, "Clone of the tree"); -}); - -test("BTree - Clone distinct test", function () { - var tree = new BTree(3); - for (var i = 0; i < 20; i++) - tree.insert(i, i % 10); - var clone = tree.cloneDistinct(); - deepEqual(clone.allIndexesOf(2), [2], "Clone of the tree"); -}); \ No newline at end of file diff --git a/Tests/CircularBuffer_Test.js b/Tests/CircularBuffer_Test.js deleted file mode 100644 index 8a1a752..0000000 --- a/Tests/CircularBuffer_Test.js +++ /dev/null @@ -1,122 +0,0 @@ -/** - * Created by Battistella Stefano on 31/03/14. - */ - -test("CircularBuffer - Write test", function () { - var buffer = new CircularBuffer(10); - buffer.write(0); - buffer.write(0); - buffer.write(0); - buffer.write(0); - for (var i = 0; i < 4; i++) - deepEqual(buffer.read(i), 0, "Write 0"); - for (var j = 4; j < 10; j++) - deepEqual(buffer.read(j), undefined, "Write 0"); - buffer.write(1); - buffer.write(1); - buffer.write(1); - buffer.write(1); - buffer.write(1); - buffer.write(1); - buffer.write(1); - buffer.write(1); - for (var m = 4; m < 12; m++) - deepEqual(buffer.read(m), 1, "Write 1"); - for (var n = 2; n < 4; n++) - deepEqual(buffer.read(n), 0, "Write 1"); - deepEqual(buffer.isFull(), true, "Is full"); -}); - -test("CircularBuffer - Free test", function () { - var buffer = new CircularBuffer(10); - for (var k = 0; k < 12; k++) - buffer.write(k); - buffer.free(2, 8); - for (var i = 2; i < 8; i++) - deepEqual(buffer.read(i), undefined, "Free 2...8"); - deepEqual(buffer.head, 2, "Free 2...8"); - deepEqual(buffer.tail, 8, "Free 2...8"); - - for (var l = 0; l < 12; l++) - buffer.write(l); - deepEqual(buffer.head, 4, "Write 12 items"); - deepEqual(buffer.tail, 4, "Write 12 items"); - - buffer.free(8, 6); - for (var m = 8; m < 6; m = (m + 1) % 10) - deepEqual(buffer.read(m), undefined, "Free 8...6"); - deepEqual(buffer.head, 8, "Free 8...6"); - deepEqual(buffer.tail, 6, "Free 8...6"); - - buffer.freeAll(); - for (var j = 0; j < 10; j++) - deepEqual(buffer.read(j), undefined, "Free all"); - deepEqual(buffer.isEmpty(), true, "Is empty"); -}); - -test("CircularBuffer - Empty test", function () { - var buffer = new CircularBuffer(10); - buffer.write(0); - buffer.write(0); - buffer.write(0); - deepEqual(buffer.isEmpty(), false, "Is not empty"); - buffer.free(0, 8); - deepEqual(buffer.isEmpty(), true, "Is empty"); -}); - -test("CircularBuffer - Clone test", function () { - var buffer = new CircularBuffer(10); - for (var i = 0; i < 15; i++) - buffer.write(i); - var clone = buffer.clone(); - for (var j = 0; j < 9; j++) - deepEqual(clone.read(j), buffer.read(j), "Check items"); - deepEqual(clone.head, buffer.head, "Check head position"); - deepEqual(clone.tail, buffer.tail, "Check tail position"); - deepEqual(clone.isEmpty(), buffer.isEmpty(), "Check empty"); - deepEqual(clone.isFull(), buffer.isFull(), "Check empty"); -}); - -test("CircularBuffer - Resize test", function () { - var buffer = new CircularBuffer(5); - for (var i = 0; i < 8; i++) - buffer.write(i); - var clone = buffer.clone(); - buffer.resize(10); - deepEqual(buffer.head, 8, "Check head position"); - deepEqual(buffer.tail, 3, "Check tail position"); - for (var j = 0; j < 10; j++) - if (j < 3 || j > 7) - deepEqual(buffer.read(j), undefined, "Increase size"); - else - deepEqual(buffer.read(j), j, "Augment resize"); - buffer = clone; - buffer.resize(3); - deepEqual(buffer.head, 0, "Check head position"); - deepEqual(buffer.tail, 0, "Check tail position"); - for (var k = 0; k < 3; k++) - deepEqual(buffer.read(k), k + 3, "Decrease size"); -}); - -test("CircularBuffer - Iterator test", function () { - var buffer = new CircularBuffer(10); - var it = buffer.getIterator(); - it.first(); - deepEqual(it.isDone(), true, "Check empty buffer iterator"); - buffer.write(0); - buffer.write(0); - buffer.write(0); - buffer.write(0); - buffer.write(1); - buffer.write(1); - buffer.write(1); - buffer.write(1); - buffer.write(1); - buffer.write(1); - buffer.write(1); - buffer.write(1); - var result = [0, 0, 1, 1, 1, 1, 1, 1, 1, 1]; - var i = 0; - for (it.first(); !it.isDone(); it.next(), i++) - deepEqual(it.getItem(), result[i], "Check iterator"); -}); \ No newline at end of file diff --git a/Tests/DoubleLinkedList_Test.js b/Tests/DoubleLinkedList_Test.js deleted file mode 100644 index 7e7fb45..0000000 --- a/Tests/DoubleLinkedList_Test.js +++ /dev/null @@ -1,420 +0,0 @@ -/** - * Created by Stefano on 31/03/14. - */ - -test("DoubleLinkedList - Init test", function () { - var list = new DoubleLinkedList(0, 1, 2); - deepEqual(list.toArray(), [0, 1, 2], "Init list"); - list = new DoubleLinkedList(2); - deepEqual(list.toArray(), [2], "Init list"); -}); - -test("DoubleLinkedList - Init range test", function () { - var list = new DoubleLinkedList(Range(0, 2)); - deepEqual(list.toArray(), [0, 1, 2], "Init list"); - list = new DoubleLinkedList(Range(2, -2, -0.5)); - deepEqual(list.toArray(), [2, 1.5, 1, 0.5, 0, -0.5, -1, -1.5, -2], "Init list"); -}); - -test("DoubleLinkedList - Push test", function () { - var list = new DoubleLinkedList(); - list.pushFront(0); - list.pushFront(1); - list.pushBack(2); - list.pushBack(3); - deepEqual(list.getItem(0), 1, "Push front 1"); - deepEqual(list.getItem(1), 0, "Push front 0"); - deepEqual(list.getItem(2), 2, "Push back 2"); - deepEqual(list.getItem(3), 3, "Push back 3"); -}); - -test("DoubleLinkedList - Pop test", function () { - var list = new DoubleLinkedList(); - list.pushFront(0); - list.pushFront(1); - list.pushBack(2); - list.pushBack(3); - deepEqual(list.popBack(), 3, "Pop back 3"); - deepEqual(list.popFront(), 1, "Pop front 1"); - deepEqual(list.popBack(), 2, "Pop back 2"); - deepEqual(list.popFront(), 0, "Pop front 0"); -}); - -test("DoubleLinkedList - Remove at test", function () { - var list = new DoubleLinkedList(); - list.pushFront(0); - list.pushFront(1); - list.pushBack(2); - list.pushBack(3); - deepEqual(list.removeAt(1), 0, "Remove at 1"); - deepEqual(list.removeAt(1), 2, "Remove at 1"); - deepEqual(list.removeAt(1), 3, "Remove at 1"); - deepEqual(list.removeAt(0), 1, "Remove at 0"); -}); - -test("DoubleLinkedList - Remove test", function () { - var list = new DoubleLinkedList(); - for (var i = 0; i < 30; i++) - list.pushBack(i % 10); - list.pushBack(15); - var callback = function (item) { - return !(item % 2) && item > 5; - }; - list.remove(0); - deepEqual(list.indexOf(0), 9, "Remove 0"); - list.remove(15); - deepEqual(list.indexOf(15), -1, "Remove 15"); - list.remove(9); - list.remove(9); - list.remove(9); - deepEqual(list.indexOf(9), -1, "Remove 9"); - list.remove(0, callback); - deepEqual(list.indexOf(6), 13, "Remove the first even numbers greater than 5"); -}); - -test("DoubleLinkedList - Remove all test", function () { - var list = new DoubleLinkedList(); - for (var i = 0; i < 30; i++) - list.pushBack(i % 10); - var callback = function (item) { - return !(item % 2) && item > 5; - }; - list.removeAll(0); - deepEqual(list.indexOf(0), -1, "Remove all 0"); - list.removeAll(9); - deepEqual(list.indexOf(9), -1, "Remove all 9"); - list.removeAll(0, callback); - deepEqual(list.indexOf(8), -1, "Remove all the even numbers greater than 5"); -}); - -test("DoubleLinkedList - Remove segment test", function () { - var list = new DoubleLinkedList(); - for (var i = 0; i < 10; i++) - list.pushBack(i); - deepEqual(list.removeSegment(2, 6), [2, 3, 4, 5, 6], "Remove the segment from the list"); - deepEqual(list.toArray(), [0, 1, 7, 8, 9], "Remove the segment from the list"); - deepEqual(list.getLength(), 5, "Remove the segment from the list"); - deepEqual(list.removeSegment(2, 1), [7, 8, 9], "Remove the segment from the list"); - deepEqual(list.toArray(), [0, 1], "Remove the segment from the list"); - deepEqual(list.getLength(), 2, "Remove the segment from the list"); -}); - -test("DoubleLinkedList - Modify at test", function () { - var list = new DoubleLinkedList(); - for (var i = 0; i < 4; i++) - list.pushBack(i); - list.modifyAt(2, 6); - deepEqual(list.toArray(), [0, 1, 6, 3], "Change at valid position"); - list.modifyAt(5, 5); - deepEqual(list.toArray(), [0, 1, 6, 3], "Change at non valid position"); -}); - -test("DoubleLinkedList - Delete node test", function () { - var list = new DoubleLinkedList(); - list.pushFront(0); - list.pushFront(1); - list.pushBack(2); - list.pushBack(3); - var it = list.getIterator(); - for (it.first(); !it.isDone(); it.next()) - if (it.getItem()) - list.deleteNode(it.getNode()); - deepEqual(list.getItem(0), 0, "Delete node"); -}); - -test("DoubleLinkedList - Sort test", function () { - var list = new DoubleLinkedList(); - const length = 100; - for (var i = 0; i < length; i++) - list.pushFront(i); - - list.sort(); - deepEqual(list.getItem(0), 0, "Sort"); - deepEqual(list.getItem(length - 1), length - 1, "Sort"); -}); - -test("DoubleLinkedList - Sort with callback test", function () { - var list = new DoubleLinkedList(); - const length = 100; - - for (var i = 0; i < length; i++) - list.pushFront(i); - - list.sort( - function (item) { - return -item; - } - ); - deepEqual(list.getItem(0), length - 1, "Sort with callback"); - deepEqual(list.getItem(length - 1), 0, "Sort with callback"); -}); - -test("DoubleLinkedList - Filter test", function () { - var list = new DoubleLinkedList(); - const length = 100; - - for (var i = 0; i < length; i++) - list.pushFront(i); - - var result = list.filter(function (item) { - return 1 - item % 2; - }); - - deepEqual(result[0], 98, "Filter of the even values"); - deepEqual(result[result.length - 1], 0, "Filter on the even values"); -}); - -test("DoubleLinkedList - Reverse test", function () { - var list = new DoubleLinkedList(); - const length = 100; - - for (var i = 0; i < length; i++) - list.pushFront(i); - - list.reverse(); - - deepEqual(list.getItem(0), 0, "Reverse"); - deepEqual(list.getItem(length - 1), 99, "Reverse"); -}); - -test("DoubleLinkedList - Iterator test", function () { - var list = new DoubleLinkedList(); - - for (var i = 0; i < 100; i++) - list.pushBack(i); - - var it = list.getIterator(); - - var j = 0; - for (it.first(); !it.isDone(); it.next(), j++) { - deepEqual(it.getItem(), j, "Check iterator position"); - } - for (it.last(); !it.isDone(); it.previous(), j--) { - deepEqual(it.getItem(), j - 1, "Check iterator position"); - } - -}); - -test("DoubleLinkedList - Add at test", function () { - var list = new DoubleLinkedList(); - list.addAt(5, 0); - deepEqual(list.peek(), 5, "Add at 0"); - list.addAt(2, 1); - deepEqual(list.getItem(1), 2, "Add at 1"); - list.addAt(15, 6); - deepEqual(list.getItem(2), undefined, "Add at 6"); - deepEqual(list.getItem(5), undefined, "Add at 6"); - deepEqual(list.getItem(6), 15, "Add at 6"); - list.addAt(30, 6); - deepEqual(list.getItem(6), 30, "Add at 6"); - deepEqual(list.getItem(7), 15, "Add at 6"); - list.addAt(6, 0); - deepEqual(list.peek(), 6, "Add at 0"); -}); - -test("DoubleLinkedList - MultiPop test", function () { - var list = new DoubleLinkedList(); - list.pushFront(0); - list.pushFront(1); - list.pushBack(2); - list.pushBack(3); - deepEqual(list.multiPopBack(2), [3, 2], "Multi pop back"); - deepEqual(list.multiPopFront(2), [1, 0], "Multi pop front"); -}); - -test("DoubleLinkedList - Get length test", function () { - var list = new DoubleLinkedList(); - deepEqual(list.getLength(), 0, "Get length empty"); - list.pushFront(0); - list.pushFront(1); - list.pushBack(2); - list.pushBack(3); - deepEqual(list.getLength(), 4, "Get length"); - list.multiPopBack(2); - deepEqual(list.getLength(), 2, "Get length"); - -}); - -test("DoubleLinkedList - Peek test", function () { - var list = new DoubleLinkedList(); - list.pushFront(0); - deepEqual(list.peek(), 0, "Peek"); - list.pushFront(1); - list.pushBack(2); - deepEqual(list.peek(), 1, "Peek"); - list.pushBack(3); - deepEqual(list.peek(), 1, "Peek"); -}); - -test("DoubleLinkedList - Clear test", function () { - var list = new DoubleLinkedList(); - list.pushFront(0); - list.pushFront(1); - list.pushBack(2); - list.pushBack(3); - list.clear(); - deepEqual(list.getLength(), 0, "Clear the list"); - -}); - -test("DoubleLinkedList - Is empty test", function () { - var list = new DoubleLinkedList(); - deepEqual(list.isEmpty(), true, "Is empty"); - list.pushFront(0); - list.pushFront(1); - list.pushBack(2); - list.pushBack(3); - deepEqual(list.isEmpty(), false, "Is not empty"); - list.clear(); - deepEqual(list.isEmpty(), true, "Is empty"); -}); - -test("DoubleLinkedList - contains", function () { - var list = new DoubleLinkedList(); - list.pushBack(0); - list.pushBack(2); - deepEqual(list.contains(0), true, "Contains 0"); - deepEqual(list.contains(2), true, "Contains 2"); - deepEqual(list.contains(1), false, "Not contains 1"); - var callback = function (item) { - return item > 0; - }; - deepEqual(list.contains(null, callback), true, "Contains a value > 0"); - callback = function (item) { - return item < 0; - }; - deepEqual(list.contains(null, callback), false, "Contains a value < 0"); -}); - -test("DoubleLinkedList - execute", function () { - var list = new DoubleLinkedList(); - list.pushBack(0); - list.pushBack(2); - var callback = function (item) { - return item * 2; - }; - list.execute(callback); - deepEqual(list.getItem(0), 0, "Execute for item 0"); - deepEqual(list.getItem(1), 4, "Execute for item 1"); -}); - -test("DoubleLinkedList - Index of test", function () { - var list = new DoubleLinkedList(); - for (var i = 0; i < 10; i++) - list.pushBack(i); - var callback = function (item) { - return !(item % 2) && item > 5; - }; - deepEqual(list.indexOf(0), 0, "Index of 0"); - deepEqual(list.indexOf(15), -1, "Index of 15"); - deepEqual(list.indexOf(5), 5, "Index of 5"); - list.removeAt(5); - deepEqual(list.indexOf(6), 5, "Index of 6"); - deepEqual(list.indexOf(null, callback), 5, "Index of the first even number greater than 5"); -}); - -test("DoubleLinkedList - Last index of test", function () { - var list = new DoubleLinkedList(); - for (var i = 0; i < 10; i++) - list.pushBack(i); - var callback = function (item) { - return !(item % 2) && item > 5; - }; - deepEqual(list.lastIndexOf(0), 0, "Last index of 0"); - deepEqual(list.lastIndexOf(15), -1, "Last index of 15"); - deepEqual(list.lastIndexOf(5), 5, "Last index of 5"); - list.removeAt(5); - deepEqual(list.lastIndexOf(6), 5, "Last index of 6"); - deepEqual(list.lastIndexOf(null, callback), 7, "Index of the last even number greater than 5"); -}); - -test("DoubleLinkedList - Indexes of test", function () { - var list = new DoubleLinkedList(); - for (var i = 0; i < 30; i++) - list.pushBack(i % 10); - var callback = function (item) { - return !(item % 2) && item > 5; - }; - deepEqual(list.allIndexesOf(0), [0, 10, 20], "Indexes of 0"); - deepEqual(list.allIndexesOf(15), [], "Indexes of 15"); - deepEqual(list.allIndexesOf(5), [5, 15, 25], "Indexes of 5"); - list.removeAt(5); - deepEqual(list.allIndexesOf(5), [14, 24], "Indexes of 5"); - deepEqual(list.allIndexesOf(6), [5, 15, 25], "Indexes of 6"); - deepEqual(list.allIndexesOf(null, callback), [5, 7, 15, 17, 25, 27], "Indexes of the even numbers greater than 5"); -}); - -test("DoubleLinkedList - Join test", function () { - var listA = new DoubleLinkedList(); - var listB = new DoubleLinkedList(); - for (var i = 0; i < 5; i++) { - listA.pushBack(i); - listB.pushBack(i); - } - listA.join(listB); - deepEqual(listA.allIndexesOf(3), [3, 8], "Join of the lists"); - deepEqual(listA.getLength(), 10, "Check the length of the list"); -}); - -test("DoubleLinkedList - Divide test", function () { - var list = new DoubleLinkedList(); - for (var i = 0; i < 10; i++) - list.pushBack(i); - var listA = list.divide(-1); - deepEqual(listA.isEmpty(), true, "Divide before start"); - var listB = list.divide(10); - deepEqual(listB.isEmpty(), true, "Divide after end"); - var listC = list.divide(8); - deepEqual(listC.getItem(0), 8, "Divide at valid position"); - deepEqual(listC.getItem(1), 9, "Divide at valid position"); - deepEqual(listC.getLength(), 2, "Divide at valid position"); - deepEqual(list.getItem(8), undefined, "Divide at valid position"); - deepEqual(list.getLength(), 8, "Divide at valid position"); - var listD = list.divide(0); - deepEqual(listD.getLength(), 8, "Divide at the first position"); - deepEqual(listD.getItem(0), 0, "Divide at the first position"); - deepEqual(listD.getItem(8), undefined, "Divide at the first position"); - deepEqual(listD.getItem(7), 7, "Divide at the first position"); - deepEqual(list.getLength(), 0, "Divide at the first position"); - deepEqual(list.getItem(0), undefined, "Divide at the first position"); -}); - -test("DoubleLinkedList - Clone test", function () { - var list = new DoubleLinkedList(); - for (var i = 0; i < 10; i++) - list.pushBack(i); - var clone = list.clone(); - var it = clone.getIterator(); - var j = 0; - for (it.first(); !it.isDone(); it.next(), j++) - deepEqual(it.getItem(), j, "Clone of the list"); -}); - -test("DoubleLinkedList - Clone distinct test", function () { - var list = new DoubleLinkedList(); - for (var i = 0; i < 20; i++) - list.pushBack(i % 10); - var clone = list.cloneDistinct(); - deepEqual(clone.allIndexesOf(2), [2], "Clone of the list"); -}); - -test("DoubleLinkedList - Split test", function () { - var list = new DoubleLinkedList(); - for (var i = 0; i < 7; i++) - list.pushBack(i); - var lists = list.split(3); - deepEqual(lists.length, 3, "Check the number of lists created"); - deepEqual(lists[0].toArray(), [0, 1, 2], "Check the items in the lists created"); - deepEqual(lists[1].toArray(), [3, 4, 5], "Check the items in the lists created"); - deepEqual(lists[2].toArray(), [6], "Check the items in the lists created"); -}); - -test("DoubleLinkedList - Count test", function () { - var list = new DoubleLinkedList(); - for (var i = 0; i < 10; i++) - list.pushBack(i); - var callback = function (item) { - return item > 4; - }; - deepEqual(list.count(callback), 5, "Count the items that are greater than 4"); -}); \ No newline at end of file diff --git a/Tests/HashTable_Test.js b/Tests/HashTable_Test.js deleted file mode 100644 index 4605f18..0000000 --- a/Tests/HashTable_Test.js +++ /dev/null @@ -1,94 +0,0 @@ -/** - * Created by Stefano on 31/03/14. - */ - -test("HashTable - Insert test", function () { - var table = new HashTable(4); - for (var i = 0; i < 20; i++) - table.insert(i, "Insert # " + i); - for (var j = 0; j < 20; j++) - deepEqual(table.search(j), "Insert # " + j, "Insert " + j); -}); - -test("HashTable - Delete key test", function () { - var table = new HashTable(4); - for (var i = 0; i < 20; i++) - table.insert(i, i); - table.deleteKey(6); - deepEqual(table.search(6), undefined, "Delete key"); -}); - -test("HashTable - Delete all key test", function () { - var table = new HashTable(4); - for (var i = 0; i < 100; i++) - table.insert(i % 20, {value: i % 20}); - table.deleteAllKey(13); - deepEqual(table.searchAll(13).length, 0, "Delete all key"); -}); - -test("HashTable - Get keys test", function () { - var table = new HashTable(50); - var keys = []; - for (var i = 0; i < 100; i++) { - table.insert(i, {value: i % 20}); - keys.push(i); - } - keys.sort(); - var storedKeys = table.getKeys().sort(); - deepEqual(storedKeys, keys, "Get stored keys"); -}); - -test("HashTable - Get items test", function () { - var table = new HashTable(50); - var items = []; - for (var i = 0; i < 100; i++) { - table.insert(i, i % 20); - items.push(i % 20); - } - items.sort(); - var storedKeys = table.getItems().sort(); - deepEqual(storedKeys, items, "Get stored items"); -}); - -test("HashTable - Contains key test", function () { - var table = new HashTable(50); - for (var i = 0; i < 100; i++) - table.insert(i, i % 20); - deepEqual(table.containsKey(4), true, "Contains key"); - deepEqual(table.containsKey(200), false, "Not contains key"); - var callback = function (k) { - return k > 20; - }; - deepEqual(table.containsKey(0, callback), true, "Contains key greater than 20"); - callback = function (k) { - return k < 0; - }; - deepEqual(table.containsKey(0, callback), false, "Not contains negative key"); -}); - -test("HashTable - Clear test", function () { - var table = new HashTable(50); - for (var i = 0; i < 100; i++) - table.insert(i, i % 20); - deepEqual(table.isEmpty(), false, "Before clear"); - table.clear(); - deepEqual(table.isEmpty(), true, "After clear"); -}); - -test("HashTable - Get number of keys test", function () { - var table = new HashTable(50); - deepEqual(table.getNumberOfKeys(), 0, "Before insertion"); - for (var i = 0; i < 100; i++) - table.insert(i, i % 20); - deepEqual(table.getNumberOfKeys(), 100, "After insertion"); -}); - -test("HashTable - Is empty test", function () { - var table = new HashTable(50); - deepEqual(table.isEmpty(), true, "Before insertion"); - for (var i = 0; i < 100; i++) - table.insert(i, i % 20); - deepEqual(table.isEmpty(), false, "Before clear"); - table.clear(); - deepEqual(table.isEmpty(), true, "After clear"); -}); diff --git a/Tests/LinkedList_Test.js b/Tests/LinkedList_Test.js deleted file mode 100644 index dfcd8fb..0000000 --- a/Tests/LinkedList_Test.js +++ /dev/null @@ -1,385 +0,0 @@ -/** - * Created by Stefano on 31/03/14. - */ - -test("LinkedList - Init test", function () { - var list = new LinkedList(0, 1, 2); - deepEqual(list.toArray(), [0, 1, 2], "Init list"); - list = new LinkedList(0); - deepEqual(list.toArray(), [0], "Init list"); -}); - -test("LinkedList - Init test with range", function () { - var list = new LinkedList(new Range(0, 5)); - deepEqual(list.toArray(), [0, 1, 2, 3, 4, 5], "Init list with range"); -}); - -test("LinkedList - Push test", function () { - var list = new LinkedList(); - list.pushFront(0); - list.pushFront(1); - list.pushBack(2); - list.pushBack(3); - deepEqual(list.getItem(0), 1, "Push front 1"); - deepEqual(list.getItem(1), 0, "Push front 0"); - deepEqual(list.getItem(2), 2, "Push back 2"); - deepEqual(list.getItem(3), 3, "Push back 3"); -}); - -test("LinkedList - Pop test", function () { - var list = new LinkedList(); - list.pushFront(0); - list.pushFront(1); - list.pushBack(2); - list.pushBack(3); - deepEqual(list.popBack(), 3, "Pop back 3"); - deepEqual(list.popFront(), 1, "Pop front 1"); - deepEqual(list.popBack(), 2, "Pop back 2"); - deepEqual(list.popFront(), 0, "Pop front 0"); -}); - -test("LinkedList - Remove at test", function () { - var list = new LinkedList(); - list.pushFront(0); - list.pushFront(1); - list.pushBack(2); - list.pushBack(3); - deepEqual(list.removeAt(1), 0, "Remove at 1"); - deepEqual(list.removeAt(1), 2, "Remove at 1"); - deepEqual(list.removeAt(1), 3, "Remove at 1"); - deepEqual(list.removeAt(0), 1, "Remove at 0"); -}); - -test("LinkedList - Remove test", function () { - var list = new LinkedList(); - for (var i = 0; i < 30; i++) - list.pushBack(i % 10); - list.pushBack(15); - var callback = function (item) { - return !(item % 2) && item > 5; - }; - list.remove(0); - deepEqual(list.indexOf(0), 9, "Remove 0"); - list.remove(15); - deepEqual(list.indexOf(15), -1, "Remove 15"); - list.remove(9); - list.remove(9); - list.remove(9); - deepEqual(list.indexOf(9), -1, "Remove 9"); - list.remove(0, callback); - deepEqual(list.indexOf(6), 13, "Remove the first even numbers greater than 5"); -}); - -test("LinkedList - Remove all test", function () { - var list = new LinkedList(); - for (var i = 0; i < 30; i++) - list.pushBack(i % 10); - var callback = function (item) { - return !(item % 2) && item > 5; - }; - list.removeAll(0); - deepEqual(list.indexOf(0), -1, "Remove all 0"); - list.removeAll(9); - deepEqual(list.indexOf(9), -1, "Remove all 9"); - list.removeAll(0, callback); - deepEqual(list.indexOf(8), -1, "Remove all the even numbers greater than 5"); -}); - -test("LinkedList - Remove segment test", function () { - var list = new LinkedList(); - for (var i = 0; i < 10; i++) - list.pushBack(i); - deepEqual(list.removeSegment(2, 6), [2, 3, 4, 5, 6], "Remove the segment from the list"); - deepEqual(list.toArray(), [0, 1, 7, 8, 9], "Remove the segment from the list"); - deepEqual(list.getLength(), 5, "Remove the segment from the list"); - deepEqual(list.removeSegment(2, 1), [7, 8, 9], "Remove the segment from the list"); - deepEqual(list.toArray(), [0, 1], "Remove the segment from the list"); - deepEqual(list.getLength(), 2, "Remove the segment from the list"); -}); - -test("LinkedList - Modify at test", function () { - var list = new LinkedList(); - for (var i = 0; i < 4; i++) - list.pushBack(i); - list.modifyAt(2, 6); - deepEqual(list.toArray(), [0, 1, 6, 3], "Change at valid position"); - list.modifyAt(5, 5); - deepEqual(list.toArray(), [0, 1, 6, 3], "Change at non valid position"); -}); - -test("LinkedList - To array test", function () { - var list = new LinkedList(); - list.pushFront(0); - list.pushFront(1); - list.pushBack(2); - list.pushBack(3); - var array = list.toArray(); - deepEqual(array[0], 1, "To array"); - deepEqual(array[1], 0, "To array"); - deepEqual(array[2], 2, "To array"); - deepEqual(array[3], 3, "To array"); -}); - -test("LinkedList - From array test", function () { - var array = [5, 2, 6, 4]; - var list = new LinkedList(); - list.fromArray(array); - deepEqual(list.getItem(0), 5, "From array"); - deepEqual(list.getItem(1), 2, "From array"); - deepEqual(list.getItem(2), 6, "From array"); - deepEqual(list.getItem(3), 4, "From array"); -}); - -test("LinkedList - Filter test", function () { - var list = new LinkedList(); - const length = 100; - - for (var i = 0; i < length; i++) - list.pushFront(i); - - var result = list.filter(function (item) { - return 1 - item % 2; - }); - - deepEqual(result[0], 98, "Filter of the even values"); - deepEqual(result[result.length - 1], 0, "Filter on the even values"); -}); - -test("LinkedList - Iterator test", function () { - var list = new LinkedList(); - - for (var i = 0; i < 100; i++) - list.pushBack(i); - - var it = list.getIterator(); - - var j = 0; - for (it.first(); !it.isDone(); it.next(), j++) { - deepEqual(it.getItem(), j, "Check iterator position"); - } - -}); - -test("LinkedList - Add at test", function () { - var list = new LinkedList(); - list.addAt(5, 0); - deepEqual(list.peek(), 5, "Add at 0"); - list.addAt(2, 1); - deepEqual(list.getItem(1), 2, "Add at 1"); - list.addAt(15, 6); - deepEqual(list.getItem(2), undefined, "Add at 6"); - deepEqual(list.getItem(5), undefined, "Add at 6"); - deepEqual(list.getItem(6), 15, "Add at 6"); - list.addAt(30, 6); - deepEqual(list.getItem(6), 30, "Add at 6"); - deepEqual(list.getItem(7), 15, "Add at 6"); - list.addAt(6, 0); - deepEqual(list.peek(), 6, "Add at 0"); -}); - -test("LinkedList - MultiPop test", function () { - var list = new LinkedList(); - list.pushFront(0); - list.pushFront(1); - list.pushBack(2); - list.pushBack(3); - deepEqual(list.multiPopBack(2), [3, 2], "Multi pop back"); - deepEqual(list.multiPopFront(2), [1, 0], "Multi pop front"); -}); - -test("LinkedList - Get length test", function () { - var list = new LinkedList(); - deepEqual(list.getLength(), 0, "Get length empty"); - list.pushFront(0); - list.pushFront(1); - list.pushBack(2); - list.pushBack(3); - deepEqual(list.getLength(), 4, "Get length"); - list.multiPopBack(2); - deepEqual(list.getLength(), 2, "Get length"); - -}); - -test("LinkedList - Peek test", function () { - var list = new LinkedList(); - list.pushFront(0); - deepEqual(list.peek(), 0, "Peek"); - list.pushFront(1); - list.pushBack(2); - deepEqual(list.peek(), 1, "Peek"); - list.pushBack(3); - deepEqual(list.peek(), 1, "Peek"); -}); - -test("LinkedList - Clear test", function () { - var list = new LinkedList(); - list.pushFront(0); - list.pushFront(1); - list.pushBack(2); - list.pushBack(3); - list.clear(); - deepEqual(list.getLength(), 0, "Clear the list"); - -}); - -test("LinkedList - Is empty test", function () { - var list = new LinkedList(); - deepEqual(list.isEmpty(), true, "Is empty"); - list.pushFront(0); - list.pushFront(1); - list.pushBack(2); - list.pushBack(3); - deepEqual(list.isEmpty(), false, "Is not empty"); - list.clear(); - deepEqual(list.isEmpty(), true, "Is empty"); -}); - -test("LinkedList - Contains test", function () { - var list = new LinkedList(); - list.pushBack(0); - list.pushBack(2); - deepEqual(list.contains(0), true, "Contains 0"); - deepEqual(list.contains(2), true, "Contains 2"); - deepEqual(list.contains(1), false, "Not contains 1"); - var callback = function (item) { - return item > 0; - }; - deepEqual(list.contains(null, callback), true, "Contains a value > 0"); - callback = function (item) { - return item < 0; - }; - deepEqual(list.contains(null, callback), false, "Contains a value < 0"); -}); - -test("LinkedList - Execute test", function () { - var list = new LinkedList(); - list.pushBack(0); - list.pushBack(2); - var callback = function (item) { - return item * 2; - }; - list.execute(callback); - deepEqual(list.getItem(0), 0, "Execute for item 0"); - deepEqual(list.getItem(1), 4, "Execute for item 1"); -}); - -test("LinkedList - Index of test", function () { - var list = new LinkedList(); - for (var i = 0; i < 10; i++) - list.pushBack(i); - var callback = function (item) { - return !(item % 2) && item > 5; - }; - deepEqual(list.indexOf(0), 0, "Index of 0"); - deepEqual(list.indexOf(15), -1, "Index of 15"); - deepEqual(list.indexOf(5), 5, "Index of 5"); - list.removeAt(5); - deepEqual(list.indexOf(6), 5, "Index of 6"); - deepEqual(list.indexOf(null, callback), 5, "Index of the first even number greater than 5"); -}); - -test("LinkedList - Last index of test", function () { - var list = new LinkedList(); - for (var i = 0; i < 10; i++) - list.pushBack(i); - var callback = function (item) { - return !(item % 2) && item > 5; - }; - deepEqual(list.lastIndexOf(0), 0, "Last index of 0"); - deepEqual(list.lastIndexOf(15), -1, "Last index of 15"); - deepEqual(list.lastIndexOf(5), 5, "Last index of 5"); - list.removeAt(5); - deepEqual(list.lastIndexOf(6), 5, "Last index of 6"); - deepEqual(list.lastIndexOf(null, callback), 7, "Index of the last even number greater than 5"); -}); - -test("LinkedList - Indexes of test", function () { - var list = new LinkedList(); - for (var i = 0; i < 30; i++) - list.pushBack(i % 10); - var callback = function (item) { - return !(item % 2) && item > 5; - }; - deepEqual(list.allIndexesOf(0), [0, 10, 20], "Indexes of 0"); - deepEqual(list.allIndexesOf(15), [], "Indexes of 15"); - deepEqual(list.allIndexesOf(5), [5, 15, 25], "Indexes of 5"); - list.removeAt(5); - deepEqual(list.allIndexesOf(5), [14, 24], "Indexes of 5"); - deepEqual(list.allIndexesOf(6), [5, 15, 25], "Indexes of 6"); - deepEqual(list.allIndexesOf(null, callback), [5, 7, 15, 17, 25, 27], "Indexes of the even numbers greater than 5"); -}); - -test("LinkedList - Join test", function () { - var listA = new LinkedList(); - var listB = new LinkedList(); - for (var i = 0; i < 5; i++) { - listA.pushBack(i); - listB.pushBack(i); - } - listA.join(listB); - deepEqual(listA.allIndexesOf(3), [3, 8], "Join of the lists"); - deepEqual(listA.getLength(), 10, "Check the length of the list"); -}); - -test("LinkedList - Divide test", function () { - var list = new LinkedList(); - for (var i = 0; i < 10; i++) - list.pushBack(i); - var listA = list.divide(-1); - deepEqual(listA.isEmpty(), true, "Divide before start"); - var listB = list.divide(10); - deepEqual(listB.isEmpty(), true, "Divide after end"); - var listC = list.divide(8); - deepEqual(listC.getItem(0), 8, "Divide at valid position"); - deepEqual(listC.getItem(1), 9, "Divide at valid position"); - deepEqual(listC.getLength(), 2, "Divide at valid position"); - deepEqual(list.getItem(8), undefined, "Divide at valid position"); - deepEqual(list.getLength(), 8, "Divide at valid position"); - var listD = list.divide(0); - deepEqual(listD.getLength(), 8, "Divide at the first position"); - deepEqual(listD.getItem(0), 0, "Divide at the first position"); - deepEqual(listD.getItem(8), undefined, "Divide at the first position"); - deepEqual(listD.getItem(7), 7, "Divide at the first position"); - deepEqual(list.getLength(), 0, "Divide at the first position"); - deepEqual(list.getItem(0), undefined, "Divide at the first position"); -}); - -test("LinkedList - Clone test", function () { - var list = new LinkedList(); - for (var i = 0; i < 10; i++) - list.pushBack(i); - var clone = list.clone(); - var it = clone.getIterator(); - var j = 0; - for (it.first(); !it.isDone(); it.next(), j++) - deepEqual(it.getItem(), j, "Clone of the list"); -}); - -test("LinkedList - Clone distinct test", function () { - var list = new LinkedList(); - for (var i = 0; i < 20; i++) - list.pushBack(i % 10); - var clone = list.cloneDistinct(); - deepEqual(clone.allIndexesOf(2), [2], "Clone of the list"); -}); - -test("LinkedList - Split test", function () { - var list = new LinkedList(); - for (var i = 0; i < 7; i++) - list.pushBack(i); - var lists = list.split(3); - deepEqual(lists.length, 3, "Check the number of lists created"); - deepEqual(lists[0].toArray(), [0, 1, 2], "Check the items in the lists created"); - deepEqual(lists[1].toArray(), [3, 4, 5], "Check the items in the lists created"); - deepEqual(lists[2].toArray(), [6], "Check the items in the lists created"); -}); - -test("LinkedList - Count test", function () { - var list = new LinkedList(); - for (var i = 0; i < 10; i++) - list.pushBack(i); - var callback = function (item) { - return item > 4; - }; - deepEqual(list.count(callback), 5, "Count the items that are greater than 4"); -}); \ No newline at end of file diff --git a/Tests/PriorityQueue_Test.js b/Tests/PriorityQueue_Test.js deleted file mode 100644 index 09c2b86..0000000 --- a/Tests/PriorityQueue_Test.js +++ /dev/null @@ -1,197 +0,0 @@ -/** - * Created by Battistella Stefano on 31/03/14. - */ - -test("PriorityQueue - Enqueue test", function () { - var queue = new PriorityQueue(); - queue.enqueue(5, 0); - deepEqual(queue.peek(), 0, "Enqueue 0"); - queue.enqueue(2, 6); - deepEqual(queue.getItem(0), 0, "Enqueue 6"); - deepEqual(queue.getItem(1), 6, "Enqueue 6"); -}); - -test("PriorityQueue - MultiEnqueue test", function () { - var queue = new PriorityQueue(); - queue.multiEnqueue(3, [0, 2]); - deepEqual(queue.multiDequeue(2), [0, 2], "MultiEnqueue 2 items"); - queue.multiEnqueue(4, [2]); - queue.multiEnqueue(5, [4, 5, 8]); - deepEqual(queue.multiDequeue(4), [4, 5, 8, 2], "MultiDequeue 4 items"); - queue.multiEnqueue(0, []); - deepEqual(queue.multiDequeue(1), [], "MultiEnqueue 0 items"); -}); - -test("PriorityQueue - Dequeue test", function () { - var queue = new PriorityQueue(); - queue.enqueue(5, 0); - queue.enqueue(2, 2); - deepEqual(queue.dequeue(), 0, "Dequeue"); - deepEqual(queue.dequeue(), 2, "Dequeue"); - deepEqual(queue.dequeue(), undefined, "Check length if too much dequeue"); -}); - -test("PriorityQueue - MultiDequeue test", function () { - var queue = new PriorityQueue(); - queue.enqueue(10, 0); - queue.enqueue(8, 2); - deepEqual(queue.multiDequeue(1), [0], "MultiDequeue 1 time"); - deepEqual(queue.getLength(), 1, "MultiDequeue 1 time check length"); - queue.enqueue(9, 4); - queue.enqueue(4, 5); - queue.enqueue(6, 8); - deepEqual(queue.multiDequeue(7), [4, 2, 8, 5], "MultiDequeue 7 times"); - deepEqual(queue.getLength(), 0, "MultiDequeue 7 time check length"); - deepEqual(queue.multiDequeue(1), [], "MultiDequeue 1 time with queue empty"); -}); - -test("PriorityQueue - Remove test", function () { - var queue = new PriorityQueue(); - queue.enqueue(4, 0); - queue.enqueue(3, 2); - queue.enqueue(2, 4); - queue.enqueue(1, 5); - queue.enqueue(0, 8); - queue.remove(2, 2); - deepEqual(queue.multiDequeue(3), [0, 2, 8], "Remove from position 2 for 2"); -}); - -test("PriorityQueue - Is empty test", function () { - var queue = new PriorityQueue(); - queue.enqueue(5, 0); - queue.enqueue(2, 2); - deepEqual(queue.isEmpty(), false, "Is empty"); - queue.clear(); - deepEqual(queue.isEmpty(), true, "Is empty"); -}); - -test("PriorityQueue - Clear test", function () { - var queue = new PriorityQueue(); - queue.enqueue(5, 0); - queue.enqueue(5, 2); - queue.clear(); - deepEqual(queue.isEmpty(), true, "Clear queue"); -}); - -test("PriorityQueue - Iterator test", function () { - var queue = new PriorityQueue(); - for (var i = 0; i < 10; i++) - queue.enqueue(10 - Math.floor(i / 2), i); - var j = 0; - var it = queue.getIterator(); - for (it.first(); !it.isDone(); it.next(), j++) - deepEqual(it.getItem(), j, "Get next item " + j); - j--; - for (it.last(); !it.isDone(); it.previous(), j--) - deepEqual(it.getItem(), j, "Get previous item " + j); -}); - -test("PriorityQueue - Contains priority test", function () { - var queue = new PriorityQueue(); - queue.enqueue(5, 0); - queue.enqueue(2, 2); - deepEqual(queue.containsPriority(5), true, "Contains priority 5"); - deepEqual(queue.containsPriority(2), true, "Contains priority 2"); - deepEqual(queue.containsPriority(1), false, "Not contains priority 1"); - var callback = function (item) { - return item > 3; - }; - deepEqual(queue.containsPriority(null, callback), true, "Contains a priority > 3"); - callback = function (item) { - return item < 2; - }; - deepEqual(queue.containsPriority(null, callback), false, "Contains a priority < 2"); -}); - -test("PriorityQueue - Get items test", function () { - var queue = new PriorityQueue(); - queue.enqueue(5, 0); - queue.enqueue(5, 2); - queue.enqueue(5, 5); - deepEqual(queue.getItems(5), [0, 2, 5], "Get items with priority 5"); - deepEqual(queue.getItems(1), [], "Get items with priority 1"); -}); - -test("PriorityQueue - To queue test", function () { - var priorityQueue = new PriorityQueue(); - priorityQueue.enqueue(5, 0); - priorityQueue.enqueue(5, 2); - priorityQueue.enqueue(5, 5); - var queue = priorityQueue.toQueue(); - deepEqual(queue.items, [0, 2, 5], "Check the to queue method"); -}); - -test("PriorityQueue - Execute test", function () { - var queue = new PriorityQueue(); - queue.enqueue(4, 0); - queue.enqueue(3, 2); - var callback = function (item) { - return item * 2; - }; - queue.execute(callback); - deepEqual(queue.getItem(0), 0, "Execute for item 0"); - deepEqual(queue.getItem(1), 4, "Execute for item 1"); -}); - -test("PriorityQueue - Remove test", function () { - var queue = new PriorityQueue(); - queue.enqueue(4, 0); - queue.enqueue(3, 1); - queue.enqueue(2, 2); - queue.enqueue(1, 3); - queue.enqueue(0, 4); - for (var i = 0; i < 5; i++) - deepEqual(queue.getItem(i), i, "Check queue correctness"); - queue.changePriority(3, 8); - for (var j = 0; j < 5; j++) { - if (!j) - deepEqual(queue.getItem(j), 3, "Check increase priority"); - else if (j < 4) - deepEqual(queue.getItem(j), j - 1, "Check increase priority"); - else - deepEqual(queue.getItem(j), j, "Check increase priority"); - } - queue.changePriority(3, -4); - for (var k = 0; k < 5; k++) { - if (!k) - deepEqual(queue.getItem(k), 3, "Check decrease priority"); - else if (k < 3) - deepEqual(queue.getItem(k), k - 1, "Check decrease priority"); - else if (k === 3) - deepEqual(queue.getItem(k), 4, "Check decrease priority"); - else - deepEqual(queue.getItem(k), 2, "Check decrease priority"); - } - -}); - -test("PriorityQueue - Filter test", function () { - var queue = new PriorityQueue(); - const length = 100; - - for (var i = 0; i < length; i++) - queue.enqueue(i, i); - - var result = queue.filter(function (item) { - return 1 - item % 2; - }); - - deepEqual(result[0], 98, "Filter of the even values"); - deepEqual(result[result.length - 1], 0, "Filter on the even values"); -}); - -test("PriorityQueue - Clone test", function () { - var queue = new PriorityQueue(); - for (var i = 0; i < 10; i++) - queue.enqueue(i, i); - var clone = queue.clone(); - deepEqual(clone.multiDequeue(10), [9, 8, 7, 6, 5, 4, 3, 2, 1, 0], "Clone of the queue"); -}); - -test("PriorityQueue - Clone distinct test", function () { - var queue = new PriorityQueue(); - for (var i = 0; i < 40; i++) - queue.enqueue(i % 20, i % 10); - var clone = queue.cloneDistinct(); - deepEqual(clone.multiDequeue(10), [9, 8, 7, 6, 5, 4, 3, 2, 1, 0], "Clone of the queue"); -}); \ No newline at end of file diff --git a/Tests/Queue_Test.js b/Tests/Queue_Test.js deleted file mode 100644 index 1081ded..0000000 --- a/Tests/Queue_Test.js +++ /dev/null @@ -1,220 +0,0 @@ -/** - * Created by Battistella Stefano on 31/03/14. - */ - -test("Queue - Init test", function () { - var queue = new Queue(0, 2, 4, 6); - deepEqual(queue.multiDequeue(4), [0, 2, 4, 6], "Initializing"); - queue = new Queue(0); - deepEqual(queue.multiDequeue(4), [0], "Initializing"); -}); - -test("Queue - Init range test", function () { - var queue = new Queue(Range(0, 6, 2)); - deepEqual(queue.multiDequeue(4), [0, 2, 4, 6], "Initializing"); -}); - -test("Queue - Enqueue test", function () { - var queue = new Queue(); - queue.enqueue(0); - deepEqual(queue.peek(), 0, "Enqueue 0"); - queue.enqueue(2); - deepEqual(queue.getItem(0), 0, "Enqueue 2"); - deepEqual(queue.getItem(1), 2, "Enqueue 2"); -}); - -test("Queue - MultiEnqueue test", function () { - var queue = new Queue(); - queue.multiEnqueue([0, 2]); - deepEqual(queue.multiDequeue(2), [0, 2], "MultiEnqueue 2 items"); - queue.multiEnqueue([2]); - queue.multiEnqueue([4, 5, 8]); - deepEqual(queue.multiDequeue(4), [2, 4, 5, 8], "MultiDequeue 4 items"); - queue.multiEnqueue([]); - deepEqual(queue.multiDequeue(1), [], "MultiEnqueue 0 items"); -}); - -test("Queue - Dequeue test", function () { - var queue = new Queue(); - queue.enqueue(0); - queue.enqueue(2); - deepEqual(queue.dequeue(), 0, "Dequeue"); - deepEqual(queue.dequeue(), 2, "Dequeue"); - deepEqual(queue.dequeue(), undefined, "Check length if too much dequeue"); -}); - -test("Queue - MultiDequeue test", function () { - var queue = new Queue(); - queue.enqueue(0); - queue.enqueue(2); - deepEqual(queue.multiDequeue(1), [0], "MultiDequeue 1 time"); - queue.enqueue(4); - queue.enqueue(5); - queue.enqueue(8); - deepEqual(queue.multiDequeue(7), [2, 4, 5, 8], "MultiDequeue 7 times"); - deepEqual(queue.multiDequeue(1), [], "MultiDequeue 1 time with queue empty"); -}); - -test("Queue - Remove test", function () { - var queue = new Queue(); - queue.enqueue(0); - queue.enqueue(2); - queue.enqueue(4); - queue.enqueue(5); - queue.enqueue(8); - queue.remove(2, 2); - deepEqual(queue.multiDequeue(3), [0, 2, 8], "Remove from position 2 for 2"); -}); - -test("Queue - Iterator test", function () { - var queue = new Queue(); - for (var i = 0; i < 10; i++) - queue.enqueue(i); - var j = 0; - var it = queue.getIterator(); - for (it.first(); !it.isDone(); it.next(), j++) - deepEqual(it.getItem(), j, "Get next item " + j); - j--; - for (it.last(); !it.isDone(); it.previous(), j--) - deepEqual(it.getItem(), j, "Get previous item " + j); -}); - -test("Queue - Get length test", function () { - var queue = new Queue(); - deepEqual(queue.getLength(), 0, "Length 0"); - queue.enqueue(0); - deepEqual(queue.getLength(), 1, "Length 1"); - queue.enqueue(2); - deepEqual(queue.getLength(), 2, "Length 2"); - queue.dequeue(); - queue.dequeue(); - deepEqual(queue.getLength(), 0, "Length 0"); - -}); - -test("Queue - Peek test", function () { - var queue = new Queue(); - queue.enqueue(0); - deepEqual(queue.peek(), 0, "Peek 0"); - queue.enqueue(2); - deepEqual(queue.peek(), 0, "Peek 0"); -}); - -test("Queue - Clear test", function () { - var queue = new Queue(); - queue.enqueue(0); - queue.enqueue(2); - queue.clear(); - deepEqual(queue.isEmpty(), true, "Clear queue"); -}); - -test("Queue - Is empty test", function () { - var queue = new Queue(); - queue.enqueue(0); - queue.enqueue(2); - deepEqual(queue.isEmpty(), false, "Is not empty"); - queue.clear(); - deepEqual(queue.isEmpty(), true, "Is empty"); -}); - -test("Queue - Contains test", function () { - var queue = new Queue(); - queue.enqueue(0); - queue.enqueue(2); - deepEqual(queue.contains(0), true, "Contains 0"); - deepEqual(queue.contains(2), true, "Contains 2"); - deepEqual(queue.contains(1), false, "Not contains 1"); - var callback = function (item) { - return item > 0; - }; - deepEqual(queue.contains(null, callback), true, "Contains a value > 0"); - callback = function (item) { - return item < 0; - }; - deepEqual(queue.contains(null, callback), false, "Contains a value < 0"); -}); - -test("Queue - Execute test", function () { - var queue = new Queue(); - queue.enqueue(0); - queue.enqueue(2); - var callback = function (item) { - return item * 2; - }; - queue.execute(callback); - deepEqual(queue.getItem(0), 0, "Execute for item 0"); - deepEqual(queue.getItem(1), 4, "Execute for item 1"); -}); - -test("Queue - Index of test", function () { - var queue = new Queue(); - for (var i = 0; i < 10; i++) - queue.enqueue(i); - var callback = function (item) { - return !(item % 2) && item > 5; - }; - deepEqual(queue.indexOf(0), 0, "Index of 0"); - deepEqual(queue.indexOf(15), -1, "Index of 15"); - deepEqual(queue.indexOf(5), 5, "Index of 5"); - deepEqual(queue.indexOf(null, callback), 6, "Index of the first even number greater than 5"); -}); - -test("Queue - Last index of test", function () { - var queue = new Queue(); - for (var i = 0; i < 10; i++) - queue.enqueue(i); - var callback = function (item) { - return !(item % 2) && item > 5; - }; - deepEqual(queue.lastIndexOf(0), 0, "Last index of 0"); - deepEqual(queue.lastIndexOf(15), -1, "Last index of 15"); - deepEqual(queue.lastIndexOf(5), 5, "Last index of 5"); - deepEqual(queue.lastIndexOf(null, callback), 8, "Index of the last even number greater than 5"); -}); - -test("Queue - Indexes of test", function () { - var queue = new Queue(); - for (var i = 0; i < 30; i++) - queue.enqueue(i % 10); - var callback = function (item) { - return !(item % 2) && item > 5; - }; - deepEqual(queue.allIndexesOf(0), [0, 10, 20], "Indexes of 0"); - deepEqual(queue.allIndexesOf(15), [], "Indexes of 15"); - deepEqual(queue.allIndexesOf(5), [5, 15, 25], "Indexes of 5"); - deepEqual(queue.allIndexesOf(null, callback), [6, 8, 16, 18, 26, 28], "Indexes of the even numbers greater than 5"); -}); - -test("Queue - Clone test", function () { - var queue = new Queue(); - for (var i = 0; i < 10; i++) - queue.enqueue(i); - var clone = queue.clone(); - var it = clone.getIterator(); - var j = 0; - for (it.first(); !it.isDone(); it.next(), j++) - deepEqual(it.getItem(), j, "Clone of the queue"); -}); - -test("Queue - Clone distinct test", function () { - var queue = new Queue(); - for (var i = 0; i < 20; i++) - queue.enqueue(i % 10); - var clone = queue.cloneDistinct(); - deepEqual(clone.allIndexesOf(2), [2], "Clone of the queue"); -}); - -test("Queue - Filter test", function () { - var queue = new Queue(); - const length = 100; - - for (var i = 0; i < length; i++) - queue.enqueue(i); - - var result = queue.filter(function (item) { - return 1 - item % 2; - }); - - deepEqual(result[0], 0, "Filter of the even values"); - deepEqual(result[result.length - 1], 98, "Filter on the even values"); -}); \ No newline at end of file diff --git a/Tests/RBTreeList_Test.js b/Tests/RBTreeList_Test.js deleted file mode 100644 index f1f96ea..0000000 --- a/Tests/RBTreeList_Test.js +++ /dev/null @@ -1,207 +0,0 @@ -/** - * Created by Stefano on 06/04/14. - */ - -test("RBTreeList - Insert test", function () { - var tree = new RBTreeList(); - var keys = []; - for (var i = 0; i < 20; i++) { - keys.push(Math.random()); - tree.insert(keys[i], i); - } - for (var j = 0; j < 20; j++) - deepEqual(tree.search(keys[j]), j, "Insert node"); -}); - -test("RBTreeList - Minimum test", function () { - var tree = new RBTreeList(); - var keys = []; - var min = 10; - for (var i = 0; i < 20; i++) { - keys.push(Math.random()); - tree.insert(keys[i], i); - if (keys[i] < min) - min = keys[i]; - } - deepEqual(tree.minimum().item, tree.search(min), "Minimum"); -}); - -test("RBTreeList - Maximum test", function () { - var tree = new RBTreeList(); - var keys = []; - var max = -1; - for (var i = 0; i < 20; i++) { - keys.push(Math.random()); - tree.insert(keys[i], i); - if (keys[i] > max) - max = keys[i]; - } - deepEqual(tree.maximum().item, tree.search(max), "Maximum"); -}); - -test("RBTreeList - Successor test", function () { - var tree = new RBTreeList(); - for (var i = 0; i < 20; i++) - tree.insert(i, i); - var it = tree.getIterator(); - var j = 1; - for (it.first(); !it.isDone(); it.next(), j++) { - var successor = tree.successor(it.getNode()); - if (successor) - deepEqual(successor.item, j, "Successor"); - else - deepEqual(successor, null, "No successor"); - } -}); - -test("RBTreeList - Predecessor test", function () { - var tree = new RBTreeList(); - for (var i = 0; i < 20; i++) - tree.insert(i, i); - var it = tree.getIterator(); - var j = 18; - for (it.last(); !it.isDone(); it.previous(), j--) { - var predecessor = tree.predecessor(it.getNode()); - if (predecessor) - deepEqual(predecessor.item, j, "Predecessor"); - else - deepEqual(predecessor, null, "No predecessor"); - } -}); - -test("RBTreeList - Delete node test", function () { - var tree = new RBTreeList(); - for (var i = 0; i < 20; i++) - tree.insert(i, i); - var j = 0; - while (tree.minimum()) { - deepEqual(tree.minimum().item, j, "Deletion"); - tree.deleteNode(tree.minimum()); - j++; - } -}); - -test("RBTreeList - To array test", function () { - var tree = new RBTreeList(); - for (var i = 0; i < 5; i++) - tree.insert(i, i); - deepEqual(tree.toArray(), [0, 1, 2, 3, 4], "To array"); -}); - -test("RBTreeList - Filter test", function () { - var tree = new RBTreeList(); - - for (var i = 0; i < 100; i++) - tree.insert(i, i); - - var result = tree.filter(function (item) { - return 1 - item % 2; - }); - - deepEqual(result[0], 0, "Filter of the even values"); - deepEqual(result[result.length - 1], 98, "Filter on the even values"); -}); - -test("RBTreeList - Clear test", function () { - var tree = new RBTreeList(); - tree.insert(0, 0); - tree.insert(2, 2); - tree.clear(); - deepEqual(tree.isEmpty(), true, "Clear tree"); -}); - -test("RBTreeList - Is empty test", function () { - var tree = new RBTreeList(); - tree.insert(0, 0); - tree.insert(2, 2); - deepEqual(tree.isEmpty(), false, "Is not empty"); - tree.clear(); - deepEqual(tree.isEmpty(), true, "Is empty"); -}); - -test("RBTreeList - Contains test", function () { - var tree = new RBTreeList(); - tree.insert(0, 0); - tree.insert(2, 2); - deepEqual(tree.contains(0), true, "Contains 0"); - deepEqual(tree.contains(2), true, "Contains 2"); - deepEqual(tree.contains(1), false, "Not contains 1"); - var callback = function (item) { - return item > 0; - }; - deepEqual(tree.fullContains(callback), true, "Contains a value > 0"); - callback = function (item) { - return item < 0; - }; - deepEqual(tree.fullContains(callback), false, "Contains a value < 0"); -}); - -test("RBTreeList - Execute test", function () { - var tree = new RBTreeList(); - tree.insert(0, 0); - tree.insert(2, 2); - var callback = function (item) { - return item * 2; - }; - tree.execute(callback); - deepEqual(tree.search(0), 0, "Execute for key 0"); - deepEqual(tree.search(2), 4, "Execute for key 1"); -}); - -test("RBTreeList - Index of test", function () { - var tree = new RBTreeList(); - for (var i = 0; i < 10; i++) - tree.insert(i, i); - var callback = function (item) { - return !(item % 2) && item > 5; - }; - deepEqual(tree.indexOf(0), 0, "Index of 0"); - deepEqual(tree.indexOf(15), -1, "Index of 15"); - deepEqual(tree.indexOf(5), 5, "Index of 5"); - deepEqual(tree.indexOf(null, callback), 6, "Index of the first even number greater than 5"); -}); - -test("RBTreeList - Last index of test", function () { - var tree = new RBTreeList(); - for (var i = 0; i < 10; i++) - tree.insert(i, i); - var callback = function (item) { - return !(item % 2) && item > 5; - }; - deepEqual(tree.lastIndexOf(0), 0, "Last index of 0"); - deepEqual(tree.lastIndexOf(15), -1, "Last index of 15"); - deepEqual(tree.lastIndexOf(5), 5, "Last index of 5"); - deepEqual(tree.lastIndexOf(null, callback), 8, "Index of the last even number greater than 5"); -}); - -test("RBTreeList - Indexes of test", function () { - var tree = new RBTreeList(); - for (var i = 0; i < 30; i++) - tree.insert(i, i % 10); - var callback = function (item) { - return !(item % 2) && item > 5; - }; - deepEqual(tree.allIndexesOf(0), [0, 10, 20], "Indexes of 0"); - deepEqual(tree.allIndexesOf(15), [], "Indexes of 15"); - deepEqual(tree.allIndexesOf(5), [5, 15, 25], "Indexes of 5"); - deepEqual(tree.allIndexesOf(null, callback), [6, 8, 16, 18, 26, 28], "Indexes of the even numbers greater than 5"); -}); - -test("RBTreeList - Clone test", function () { - var tree = new RBTreeList(); - for (var i = 0; i < 10; i++) - tree.insert(i, i); - var clone = tree.clone(); - var it = clone.getIterator(); - var j = 0; - for (it.first(); !it.isDone(); it.next(), j++) - deepEqual(it.getItem(), j, "Clone of the tree"); -}); - -test("RBTreeList - Clone distinct test", function () { - var tree = new RBTreeList(); - for (var i = 0; i < 20; i++) - tree.insert(i % 10, i % 10); - var clone = tree.cloneDistinct(); - deepEqual(clone.allIndexesOf(2), [2], "Clone of the tree"); -}); \ No newline at end of file diff --git a/Tests/RBTree_Test.js b/Tests/RBTree_Test.js deleted file mode 100644 index 404636c..0000000 --- a/Tests/RBTree_Test.js +++ /dev/null @@ -1,211 +0,0 @@ -/** - * Created by Stefano on 06/04/14. - */ - -test("RBTree - Insert test", function () { - var tree = new RBTree(); - var keys = []; - for (var i = 0; i < 20; i++) { - keys.push(Math.random()); - tree.insert(keys[i], keys[i]); - } - for (var j = 0; j < 20; j++) - deepEqual(tree.search(keys[j]), keys[j], "Insert node"); - keys.sort(); - for (var k = 0; k < 20; k++) - deepEqual(tree.getItem(k), keys[k], "Insert node"); -}); - -test("RBTree - Minimum test", function () { - var tree = new RBTree(); - var keys = []; - var min = 10; - for (var i = 0; i < 20; i++) { - keys.push(Math.random()); - tree.insert(keys[i], i); - if (keys[i] < min) - min = keys[i]; - } - deepEqual(tree.minimum().item, tree.search(min), "Minimum"); -}); - -test("RBTree - Maximum test", function () { - var tree = new RBTree(); - var keys = []; - var max = -1; - for (var i = 0; i < 20; i++) { - keys.push(Math.random()); - tree.insert(keys[i], i); - if (keys[i] > max) - max = keys[i]; - } - deepEqual(tree.maximum().item, tree.search(max), "Maximum"); -}); - -test("RBTree - Successor test", function () { - var tree = new RBTree(); - for (var i = 0; i < 20; i++) - tree.insert(i, i); - var it = tree.getIterator(); - var j = 1; - for (it.first(); !it.isDone(); it.next(), j++) { - var successor = tree.successor(it.getNode()); - if (successor) - deepEqual(successor.item, j, "Successor"); - else - deepEqual(successor, null, "No successor"); - } -}); - -test("RBTree - Predecessor test", function () { - var tree = new RBTree(); - for (var i = 0; i < 20; i++) - tree.insert(i, i); - var it = tree.getIterator(); - var j = 18; - for (it.last(); !it.isDone(); it.previous(), j--) { - var predecessor = tree.predecessor(it.getNode()); - if (predecessor) - deepEqual(predecessor.item, j, "Predecessor"); - else - deepEqual(predecessor, null, "No predecessor"); - } -}); - -test("RBTree - Delete node test", function () { - var tree = new RBTree(); - for (var i = 0; i < 20; i++) - tree.insert(i, i); - var j = 0; - while (tree.minimum()) { - deepEqual(tree.minimum().item, j, "Deletion"); - tree.deleteNode(tree.minimum()); - j++; - } -}); - -test("RBTree - To array test", function () { - var tree = new RBTree(); - for (var i = 0; i < 5; i++) - tree.insert(i, i); - deepEqual(tree.toArray(), [0, 1, 2, 3, 4], "To array"); -}); - -test("RBTree - Filter test", function () { - var tree = new RBTree(); - const length = 100; - - for (var i = 0; i < length; i++) - tree.insert(i, i); - - var result = tree.filter(function (item) { - return 1 - item % 2; - }); - - deepEqual(result[0], 0, "Filter of the even values"); - deepEqual(result[result.length - 1], 98, "Filter on the even values"); -}); - -test("RBTree - Clear test", function () { - var tree = new RBTreeList(); - tree.insert(0, 0); - tree.insert(2, 2); - tree.clear(); - deepEqual(tree.isEmpty(), true, "Clear tree"); -}); - -test("RBTree - Is empty test", function () { - var tree = new RBTree(); - tree.insert(0, 0); - tree.insert(2, 2); - deepEqual(tree.isEmpty(), false, "Is not empty"); - tree.clear(); - deepEqual(tree.isEmpty(), true, "Is empty"); -}); - -test("RBTree - Contains test", function () { - var tree = new RBTree(); - tree.insert(0, 0); - tree.insert(2, 2); - deepEqual(tree.contains(0), true, "Contains 0"); - deepEqual(tree.contains(2), true, "Contains 2"); - deepEqual(tree.contains(1), false, "Not contains 1"); - var callback = function (item) { - return item > 0; - }; - deepEqual(tree.fullContains(callback), true, "Contains a value > 0"); - callback = function (item) { - return item < 0; - }; - deepEqual(tree.fullContains(callback), false, "Contains a value < 0"); -}); - -test("RBTree - Execute test", function () { - var tree = new RBTree(); - tree.insert(0, 0); - tree.insert(2, 2); - var callback = function (item) { - return item * 2; - }; - tree.execute(callback); - deepEqual(tree.search(0), 0, "Execute for key 0"); - deepEqual(tree.search(2), 4, "Execute for key 1"); -}); - -test("RBTree - Index of test", function () { - var tree = new RBTree(); - for (var i = 0; i < 10; i++) - tree.insert(i, i); - var callback = function (item) { - return !(item % 2) && item > 5; - }; - deepEqual(tree.indexOf(0), 0, "Index of 0"); - deepEqual(tree.indexOf(15), -1, "Index of 15"); - deepEqual(tree.indexOf(5), 5, "Index of 5"); - deepEqual(tree.indexOf(null, callback), 6, "Index of the first even number greater than 5"); -}); - -test("RBTree - Last index of test", function () { - var tree = new RBTree(); - for (var i = 0; i < 10; i++) - tree.insert(i, i); - var callback = function (item) { - return !(item % 2) && item > 5; - }; - deepEqual(tree.lastIndexOf(0), 0, "Last index of 0"); - deepEqual(tree.lastIndexOf(15), -1, "Last index of 15"); - deepEqual(tree.lastIndexOf(5), 5, "Last index of 5"); - deepEqual(tree.lastIndexOf(null, callback), 8, "Index of the last even number greater than 5"); -}); - -test("RBTree - Indexes of test", function () { - var tree = new RBTree(); - for (var i = 0; i < 30; i++) - tree.insert(i, i % 10); - var callback = function (item) { - return !(item % 2) && item > 5; - }; - deepEqual(tree.allIndexesOf(0), [0, 10, 20], "Indexes of 0"); - deepEqual(tree.allIndexesOf(15), [], "Indexes of 15"); - deepEqual(tree.allIndexesOf(5), [5, 15, 25], "Indexes of 5"); - deepEqual(tree.allIndexesOf(null, callback), [6, 8, 16, 18, 26, 28], "Indexes of the even numbers greater than 5"); -}); - -test("RBTree - Clone test", function () { - var tree = new RBTree(); - for (var i = 0; i < 10; i++) - tree.insert(i, i); - var clone = tree.clone(); - var it = clone.getIterator(); - var j = 0; - for (it.first(); !it.isDone(); it.next(), j++) - deepEqual(it.getItem(), j, "Clone of the tree"); -}); - -test("RBTree - Clone distinct test", function () { - var tree = new RBTree(); - for (var i = 0; i < 20; i++) - tree.insert(i % 10, i % 10); - var clone = tree.cloneDistinct(); - deepEqual(clone.allIndexesOf(2), [2], "Clone of the tree"); -}); \ No newline at end of file diff --git a/Tests/Range_Test.js b/Tests/Range_Test.js deleted file mode 100644 index fc201ff..0000000 --- a/Tests/Range_Test.js +++ /dev/null @@ -1,31 +0,0 @@ -/** - * Created by Stefano on 06/04/14. - */ - -test("Range - Create linear test", function () { - var range = Range(0, 5); - for (var j = 0; j < range.length; j++) { - deepEqual(range[j], j, "Check range values"); - } -}); - -test("Range - Create inverse test", function () { - var range = Range(5, 0, -1); - for (var j = 0; j < range.length; j++) { - deepEqual(range[j], 5 - j, "Check range values"); - } -}); - -test("Range - Create step test", function () { - var range = Range(0, 15, 4); - for (var j = 0; j < range.length; j++) { - deepEqual(range[j], j * 4, "Check range values"); - } -}); - -test("Range - Create inverse step test", function () { - var range = Range(15, 4, -2); - for (var j = 0; j < range.length; j++) { - deepEqual(range[j], 15 - j * 2, "Check range values"); - } -}); \ No newline at end of file diff --git a/Tests/Set_Test.js b/Tests/Set_Test.js deleted file mode 100644 index 5720f03..0000000 --- a/Tests/Set_Test.js +++ /dev/null @@ -1,104 +0,0 @@ -/** - * Created by Stefano on 06/04/14. - */ - -test("Set - Insert test", function () { - var setA = new Set(); - var e0 = new Element(0); - var e1 = new Element(1); - setA.multiInsert([e0, e1]); - deepEqual(setA.getItems(), [0, 1], "Insert elements"); - deepEqual(setA.getCardinality(), 2, "Insert elements"); -}); - -test("Set - Union test", function () { - var setA = new Set(); - var setB = new Set(); - var e0 = new Element(0); - var e1 = new Element(1); - var e2 = new Element(2); - var e3 = new Element(3); - setA.multiInsert([e0, e1]); - setA.multiInsert([e2, e3]); - var union = setA.union(setB); - deepEqual(setA.parents.contains(union), true, "Union of sets"); - deepEqual(setB.parents.contains(union), true, "Union of sets"); - deepEqual(union.getCardinality(), 4, "Union of sets"); -}); - -test("Set - Intersection test", function () { - var setA = new Set(); - var setB = new Set(); - var e = []; - for (var i = 0; i < 6; i++) { - e.push(new Element(i)); - if (i < 4) - setA.insert(e[i]); - if (i > 1) - setB.insert(e[i]); - } - var intersection = setA.intersect(setB); - for (var k = 0; k < 2; k++) - deepEqual(intersection.elements.getItem(k).item, k + 2, "Intersection of sets"); - deepEqual(intersection.getCardinality(), 2, "Intersection of sets"); -}); - -test("Set - Difference test", function () { - var setA = new Set(); - var setB = new Set(); - var e = []; - for (var i = 0; i < 6; i++) { - e.push(new Element(i)); - if (i < 4) - setA.insert(e[i]); - if (i > 1) - setB.insert(e[i]); - } - var diffA = setA.difference(setB); - var diffB = setB.difference(setA); - for (var j = 0; j < 2; j++) - deepEqual(diffA.elements.getItem(j).item, j, "Difference of sets"); - deepEqual(diffA.getCardinality(), 2, "Difference of sets"); - for (var k = 0; k < 2; k++) - deepEqual(diffB.elements.getItem(k).item, k + 4, "Difference of sets"); - deepEqual(diffB.getCardinality(), 2, "Difference of sets"); -}); - -test("Set - Cartesian product test", function () { - var setA = new Set(); - var setB = new Set(); - var e = []; - for (var i = 0; i < 6; i++) { - e.push(new Element(i)); - if (i < 3) - setA.insert(e[i]); - if (i > 2) - setB.insert(e[i]); - } - var productA = setA.cartesianProduct(setB); - var productB = setB.cartesianProduct(setA); - deepEqual(productA.getItems(), [ - [0, 3], - [0, 4], - [0, 5], - [1, 3], - [1, 4], - [1, 5], - [2, 3], - [2, 4], - [2, 5] - ], "Cartesian product of sets"); - deepEqual(productA.getCardinality(), 9, "Cartesian product of sets"); - deepEqual(productB.getItems(), [ - [3, 0], - [3, 1], - [3, 2], - [4, 0], - [4, 1], - [4, 2], - [5, 0], - [5, 1], - [5, 2] - ], "Cartesian product of sets"); - deepEqual(productB.getCardinality(), 9, "Cartesian product of sets"); -}); \ No newline at end of file diff --git a/Tests/Stack_Test.js b/Tests/Stack_Test.js deleted file mode 100644 index 57cae5d..0000000 --- a/Tests/Stack_Test.js +++ /dev/null @@ -1,198 +0,0 @@ -/** - * Created by Battistella Stefano on 31/03/14. - */ - -test("Stack - Init test", function () { - var stack = new Stack(0, 2, 4, 6); - deepEqual(stack.multiPop(4), [6, 4, 2, 0], "Initializing"); - stack = new Stack(0); - deepEqual(stack.multiPop(4), [0], "Initializing"); -}); - -test("Stack - Init range test", function () { - var stack = new Stack(Range(0, 6, 2)); - deepEqual(stack.multiPop(4), [6, 4, 2, 0], "Initializing"); -}); - -test("Stack - Push test", function () { - var stack = new Stack(); - stack.push(0); - deepEqual(stack.getItem(0), 0, "Push 0"); - stack.push(2); - deepEqual(stack.getItem(0), 2, "Push 2"); - deepEqual(stack.getItem(1), 0, "Push 2"); -}); - -test("Stack - Pop test", function () { - var stack = new Stack(); - stack.push(0); - stack.push(2); - deepEqual(stack.pop(), 2, "Pop"); - deepEqual(stack.pop(), 0, "Check length"); - deepEqual(stack.pop(), undefined, "Check length if too much pop"); -}); - -test("Stack - MultiPop test", function () { - var stack = new Stack(); - stack.push(0); - stack.push(2); - deepEqual(stack.multiPop(1), [2], "MultiPop 1 time"); - stack.push(4); - stack.push(5); - stack.push(8); - deepEqual(stack.multiPop(7), [8, 5, 4, 0], "MultiPop 7 times"); - deepEqual(stack.multiPop(1), [], "MultiPop 1 time with stack empty"); -}); - -test("Stack - Iterator test", function () { - var stack = new Stack(); - for (var i = 0; i < 10; i++) - stack.push(i); - var j = 9; - var it = stack.getIterator(); - for (it.first(); !it.isDone(); it.next(), j--) - deepEqual(it.getItem(), j, "Get next item " + (10 - j)); - j++; - for (it.last(); !it.isDone(); it.previous(), j++) - deepEqual(it.getItem(), j, "Get previous item " + (10 - j)); -}); - -test("Stack - Get length test", function () { - var stack = new Stack(); - deepEqual(stack.getLength(), 0, "Length 0"); - stack.push(0); - deepEqual(stack.getLength(), 1, "Length 1"); - stack.push(2); - deepEqual(stack.getLength(), 2, "Length 2"); - stack.pop(); - stack.pop(); - deepEqual(stack.getLength(), 0, "Length 0"); - -}); - -test("Stack - Peek test", function () { - var stack = new Stack(); - stack.push(0); - deepEqual(stack.peek(), 0, "Peek 0"); - stack.push(2); - deepEqual(stack.peek(), 2, "Peek 2"); -}); - -test("Stack - Clear test", function () { - var stack = new Stack(); - stack.push(0); - stack.push(2); - stack.clear(); - deepEqual(stack.isEmpty(), true, "Clear stack"); -}); - -test("Stack - Is empty test", function () { - var stack = new Stack(); - stack.push(0); - stack.push(2); - deepEqual(stack.isEmpty(), false, "Is empty"); - stack.clear(); - deepEqual(stack.isEmpty(), true, "Is empty"); -}); - -test("Stack - contains", function () { - var stack = new Stack(); - stack.push(0); - stack.push(2); - deepEqual(stack.contains(0), true, "Contains 0"); - deepEqual(stack.contains(2), true, "Contains 2"); - deepEqual(stack.contains(1), false, "Not contains 1"); - var callback = function (item) { - return item > 0; - }; - deepEqual(stack.contains(null, callback), true, "Contains a value > 0"); - callback = function (item) { - return item < 0; - }; - deepEqual(stack.contains(null, callback), false, "Contains a value < 0"); -}); - -test("Stack - execute", function () { - var stack = new Stack(); - stack.push(0); - stack.push(2); - var callback = function (item) { - return item * 2; - }; - stack.execute(callback); - deepEqual(stack.getItem(0), 4, "Execute for item 1"); - deepEqual(stack.getItem(1), 0, "Execute for item 0"); -}); - -test("Stack - Index of test", function () { - var stack = new Stack(); - for (var i = 0; i < 10; i++) - stack.push(i); - var callback = function (item) { - return !(item % 2) && item > 5; - }; - deepEqual(stack.indexOf(0), 0, "Index of 0"); - deepEqual(stack.indexOf(15), -1, "Index of 15"); - deepEqual(stack.indexOf(5), 5, "Index of 5"); - deepEqual(stack.indexOf(null, callback), 8, "Index of the first even number greater than 5"); -}); - -test("Stack - Last index of test", function () { - var stack = new Stack(); - for (var i = 0; i < 10; i++) - stack.push(i); - var callback = function (item) { - return !(item % 2) && item > 5; - }; - deepEqual(stack.lastIndexOf(0), 0, "Last index of 0"); - deepEqual(stack.lastIndexOf(15), -1, "Last index of 15"); - deepEqual(stack.lastIndexOf(5), 5, "Last index of 5"); - deepEqual(stack.lastIndexOf(null, callback), 6, "Index of the last even number greater than 5"); -}); - -test("Stack - Indexes of test", function () { - var stack = new Stack(); - for (var i = 0; i < 30; i++) - stack.push(i % 10); - var callback = function (item) { - return !(item % 2) && item > 5; - }; - deepEqual(stack.allIndexesOf(0), [20, 10, 0], "Indexes of 0"); - deepEqual(stack.allIndexesOf(15), [], "Indexes of 15"); - deepEqual(stack.allIndexesOf(5), [25, 15, 5], "Indexes of 5"); - deepEqual(stack.allIndexesOf(null, callback), [28, 26, 18, 16, 8, 6], "Indexes of the even numbers greater than 5"); -}); - -test("Stack - Clone test", function () { - var stack = new Stack(); - for (var i = 0; i < 10; i++) - stack.push(i); - var clone = stack.clone(); - var it = clone.getIterator(); - var j = 9; - for (it.first(); !it.isDone(); it.next(), j--) - deepEqual(it.getItem(), j, "Clone of the list"); -}); - -test("Stack - Clone distinct test", function () { - var stack = new Stack(); - for (var i = 0; i < 20; i++) - stack.push(i % 10); - var clone = stack.cloneDistinct(); - deepEqual(clone.allIndexesOf(2), [2], "Clone of the list"); -}); - -test("Stack - Filter test", function () { - var stack = new Stack(); - const length = 100; - - for (var i = 0; i < length; i++) - stack.push(i); - - var result = stack.filter(function (item) { - return 1 - item % 2; - }); - - deepEqual(result[0], 98, "Filter of the even values"); - deepEqual(result[result.length - 1], 0, "Filter on the even values"); -}); \ No newline at end of file diff --git a/Tests/Trie_Test.js b/Tests/Trie_Test.js deleted file mode 100644 index 5a4b894..0000000 --- a/Tests/Trie_Test.js +++ /dev/null @@ -1,52 +0,0 @@ -/** - * Created by Stefano on 06/04/14. - */ - -test("Trie - Insert test", function () { - var trie = new Trie(); - trie.insert("Blue"); - trie.insert("Bleu"); - var strings = []; - trie.stringsToArray(strings); - deepEqual(strings, ["Bleu","Blue"], "Insert node"); - trie.insert("Abba", 0); - trie.insert("Hello", 0); - trie.insert("World", 0); - deepEqual(trie.getItem("Abba"), 0, "Insert node"); - deepEqual(trie.getItem("Hello"), 0, "Insert node"); - deepEqual(trie.getItem("World"), 0, "Insert node"); -}); - -test("Trie - Suggest test", function () { - var trie = new Trie(); - trie.insert("Blue"); - trie.insert("Boing"); - trie.insert("Yellow"); - trie.insert("Hello"); - trie.insert("He"); - trie.insert("Hola"); - deepEqual(trie.suggest(""), ["Blue","Boing", "He", "Hello", "Hola", "Yellow"], "Suggest empty string"); - deepEqual(trie.suggest("B"), ["Blue","Boing"], "Suggest B string"); - deepEqual(trie.suggest("Bo"), ["Boing"], "Suggest Bo string"); - deepEqual(trie.suggest("Ho"), ["Hola"], "Suggest Ho string"); - deepEqual(trie.suggest("A"), [], "Suggest A string"); - deepEqual(trie.suggest("Ready"), [], "Suggest Ready string"); -}); - -test("Trie - Update Item test", function () { - var trie = new Trie(); - trie.insert("Blue", 0); - trie.insert("Boing", 0); - trie.insert("Yellow", 0); - trie.insert("Hello", 0); - trie.insert("He", 0); - trie.insert("Hola", 0); - var callback = function(item) { - return item+1; - }; - var strings = trie.suggest(""); - for(var i = 0; i < strings.length; ++i) { - trie.updateItem(strings[i], callback); - deepEqual(trie.getItem(strings[i]), 1, "Value Updated"); - } -}); \ No newline at end of file diff --git a/Tests/tester.html b/Tests/tester.html deleted file mode 100644 index e79e53f..0000000 --- a/Tests/tester.html +++ /dev/null @@ -1,68 +0,0 @@ - - - - - QUnit basic example - - - -
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/bower.json b/bower.json deleted file mode 100644 index 07e8955..0000000 --- a/bower.json +++ /dev/null @@ -1,18 +0,0 @@ -{ - "name": "javascript-data-structure", - "version": "1.0.0", - "homepage": "https://github.com/Bishop92/JavaScript-Data-Structures", - "authors": [ - "Bishop" - ], - "description": "Datastructures in JS", - "main": "DataStructuresMinimized.js", - "license": "MIT", - "ignore": [ - "**/.*", - "node_modules", - "bower_components", - "test", - "tests" - ] -} diff --git a/doc/files.html b/doc/files.html deleted file mode 100644 index 87ba799..0000000 --- a/doc/files.html +++ /dev/null @@ -1,258 +0,0 @@ - - - - - - JsDoc Reference - File Index - - - - - - - - - - -
-

File Index

- - - -
- - -
-
- - Documentation generated by JsDoc Toolkit - 2.4.0 on Wed Apr 23 2014 22:40:59 GMT+0200 (CEST) -
- - \ No newline at end of file diff --git a/doc/index.html b/doc/index.html deleted file mode 100644 index ee62b1a..0000000 --- a/doc/index.html +++ /dev/null @@ -1,398 +0,0 @@ - - - - - - JsDoc Reference - Index - - - - - - - - - - -
-

Class Index

- - -
-

_global_

- -
-
- -
-

Aggregate

- -
-
- -
-

BSTree

- -
-
- - -
- -
-

BTree

- -
-
- - -
- - -
- - -
- - -
- - -
- -
-

HashTable

- -
-
- -
-

Iterator

- -
-
- -
-

LinkedList

- -
-
- - -
- - -
- - -
- -
-

Queue

- -
-
- - -
- -
-

RBTree

- -
-
- - -
- -
-

RBTreeList

- -
-
- - -
- -
-

Set

- -
-
- -
-

Stack

- -
-
- - -
- - -
-
- - Documentation generated by JsDoc Toolkit - 2.4.0 on Wed Apr 23 2014 22:40:59 GMT+0200 (CEST) -
- - \ No newline at end of file diff --git a/doc/symbols/Aggregate.html b/doc/symbols/Aggregate.html deleted file mode 100644 index e44f39c..0000000 --- a/doc/symbols/Aggregate.html +++ /dev/null @@ -1,381 +0,0 @@ - - - - - - - JsDoc Reference - Aggregate - - - - - - - - - - - - - -
- -

- - Class Aggregate -

- - -

- - -
Defined in: DataStructures.js. - -

- - - - - - - - - - - - - - - - - -
Class Summary
Constructor AttributesConstructor Name and Description
  -
- Aggregate() -
-
Interface for managing a generic data structure.
-
- - - - - - - - - - - - - - - - - - - - - - - - -
Method Summary
Method AttributesMethod Name and Description
  - -
Returns the iterator relative to the aggregate.
-
- - - - - - - -
- -
- Class Detail -
- -
- Aggregate() -
- -
- Interface for managing a generic data structure. - -
- - -
- - - - - - - -
- Method Detail -
- - - -
- - {Iterator} - getIterator() - -
-
- Returns the iterator relative to the aggregate. - - -
- - -
-
Returns:
- -
{Iterator} The iterator.
- -
- - - - - -
-
- - - -
- - Documentation generated by JsDoc Toolkit 2.4.0 - on Wed Apr 23 2014 22:40:58 GMT+0200 (CEST) -
- - diff --git a/doc/symbols/BSTree.html b/doc/symbols/BSTree.html deleted file mode 100644 index e4dc8d6..0000000 --- a/doc/symbols/BSTree.html +++ /dev/null @@ -1,756 +0,0 @@ - - - - - - - JsDoc Reference - BSTree - - - - - - - - - - - - - -
- -

- - Class BSTree -

- - -

- - -
Defined in: DataStructures.js. - -

- - - - - - - - - - - - - - - - - -
Class Summary
Constructor AttributesConstructor Name and Description
  -
- BSTree() -
-
Class for managing a binary search tree.
-
- - - - - - - - - - - - - - - - - - - - - -
Field Summary
Field AttributesField Name and Description
  -
- root -
-
The root of the tree.
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Method Summary
Method AttributesMethod Name and Description
  -
deleteNode(node) -
-
Deletes the node from the tree.
-
  - -
Returns the iterator relative to the aggregate.
-
  -
insert(key, item) -
-
Inserts the item relatives to the key value in the tree.
-
  -
maximum(node) -
-
Gets the item relatives to the maximum key stored in the tree.
-
  -
minimum(node) -
-
Gets the item relatives to the minimum key stored in the tree.
-
  -
predecessor(node) -
-
Gets the node with the key previous to the param node key.
-
  -
search(key, node) -
-
Searches the item relatives to the key.
-
  -
successor(node) -
-
Gets the node with the key next to the param node key.
-
- - - - - - - -
- -
- Class Detail -
- -
- BSTree() -
- -
- Class for managing a binary search tree. - -
- - -
- - - - -
- Field Detail -
- - - -
- - - root - -
-
- The root of the tree. - - -
- - - - -
- Method Detail -
- - - -
- - {void} - deleteNode(node) - -
-
- Deletes the node from the tree. - - -
- - -
-
Parameters:
- -
- node - -
-
{BSNode} The node to delete.
- -
- - -
-
Returns:
- -
{void}
- -
- - -
- - - -
- - {Iterator} - getIterator() - -
-
- Returns the iterator relative to the aggregate. - - -
- - -
-
Returns:
- -
{Iterator} The iterator.
- -
- - -
- - - -
- - {void} - insert(key, item) - -
-
- Inserts the item relatives to the key value in the tree. - - -
- - -
-
Parameters:
- -
- key - -
-
{number} The key to store.
- -
- item - -
-
{*} The item to store.
- -
- - -
-
Returns:
- -
{void}
- -
- - -
- - - -
- - {BSNode} - maximum(node) - -
-
- Gets the item relatives to the maximum key stored in the tree. - - -
- - -
-
Parameters:
- -
- node - Optional, Default: root -
-
{Node} The node from which start the search.
- -
- - -
-
Returns:
- -
{BSNode} The node found.
- -
- - -
- - - -
- - {BSNode} - minimum(node) - -
-
- Gets the item relatives to the minimum key stored in the tree. - - -
- - -
-
Parameters:
- -
- node - Optional, Default: root -
-
{Node} The node from which start the search.
- -
- - -
-
Returns:
- -
{BSNode} The node found.
- -
- - -
- - - -
- - {BSNode} - predecessor(node) - -
-
- Gets the node with the key previous to the param node key. - - -
- - -
-
Parameters:
- -
- node - -
-
{BSNode} The node of which search the predecessor.
- -
- - -
-
Returns:
- -
{BSNode} The node found.
- -
- - -
- - - -
- - {*} - search(key, node) - -
-
- Searches the item relatives to the key. - - -
- - -
-
Parameters:
- -
- key - -
-
{Number} The key to find.
- -
- node - Optional, Default: root -
-
{BSNode} The node from which start the search.
- -
- - -
-
Returns:
- -
{*} The item found or undefined if there isn't the key in the tree.
- -
- - -
- - - -
- - {BSNode} - successor(node) - -
-
- Gets the node with the key next to the param node key. - - -
- - -
-
Parameters:
- -
- node - -
-
{BSNode} The node of which search the successor.
- -
- - -
-
Returns:
- -
{BSNode} The node found.
- -
- - - - - -
-
- - - -
- - Documentation generated by JsDoc Toolkit 2.4.0 - on Wed Apr 23 2014 22:40:58 GMT+0200 (CEST) -
- - diff --git a/doc/symbols/BSTreeIterator.html b/doc/symbols/BSTreeIterator.html deleted file mode 100644 index 9c851f7..0000000 --- a/doc/symbols/BSTreeIterator.html +++ /dev/null @@ -1,668 +0,0 @@ - - - - - - - JsDoc Reference - BSTreeIterator - - - - - - - - - - - - - -
- -

- - Class BSTreeIterator -

- - -

- - -
Defined in: DataStructures.js. - -

- - - - - - - - - - - - - - - - - -
Class Summary
Constructor AttributesConstructor Name and Description
  -
- BSTreeIterator(aggregate) -
-
Class that implements the iterator for a binary search tree.
-
- - - - - - - - - - - - - - - - - - - - - - - - - - -
Field Summary
Field AttributesField Name and Description
  -
- aggregate -
-
The aggregate relates to this iterator.
-
  -
- pointer -
-
The pointer to the position.
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Method Summary
Method AttributesMethod Name and Description
  -
first() -
-
Moves the iterator to the first position of the aggregate.
-
  -
getItem() -
-
Returns the item stored at the position pointed by the iterator.
-
  -
getNode() -
-
Returns the node stored at the position pointed by the iterator.
-
  -
isDone() -
-
Checks if the iterator is out of the bounds of the aggregate.
-
  -
last() -
-
Moves the iterator to the last position of the aggregate.
-
  -
next() -
-
Moves the iterator to the next item.
-
  - -
Moves the iterator to the previous item.
-
- - - - - - - -
- -
- Class Detail -
- -
- BSTreeIterator(aggregate) -
- -
- Class that implements the iterator for a binary search tree. - -
- - -
-
Parameters:
- -
- aggregate - -
-
{BSTree} The aggregate to scan.
- -
- - -
- - - - -
- Field Detail -
- - - -
- - - aggregate - -
-
- The aggregate relates to this iterator. - - -
- - -
- - - -
- - - pointer - -
-
- The pointer to the position. - - -
- - - - -
- Method Detail -
- - - -
- - {void} - first() - -
-
- Moves the iterator to the first position of the aggregate. - - -
- - -
-
Returns:
- -
{void}
- -
- - -
- - - -
- - {*} - getItem() - -
-
- Returns the item stored at the position pointed by the iterator. - - -
- - -
-
Returns:
- -
{*} The item stored or undefined if it's out of the bounds.
- -
- - -
- - - -
- - {BSNode|null} - getNode() - -
-
- Returns the node stored at the position pointed by the iterator. - - -
- - -
-
Returns:
- -
{BSNode|null} The node stored or null if it's out of the bounds.
- -
- - -
- - - -
- - {boolean} - isDone() - -
-
- Checks if the iterator is out of the bounds of the aggregate. - - -
- - -
-
Returns:
- -
{boolean} It return true if the iterator is out of the bounds of the - aggregate, otherwise false. -
- -
- - -
- - - -
- - {void} - last() - -
-
- Moves the iterator to the last position of the aggregate. - - -
- - -
-
Returns:
- -
{void}
- -
- - -
- - - -
- - {void} - next() - -
-
- Moves the iterator to the next item. - - -
- - -
-
Returns:
- -
{void}
- -
- - -
- - - -
- - {void} - previous() - -
-
- Moves the iterator to the previous item. - - -
- - -
-
Returns:
- -
{void}
- -
- - - - - -
-
- - - -
- - Documentation generated by JsDoc Toolkit 2.4.0 - on Wed Apr 23 2014 22:40:58 GMT+0200 (CEST) -
- - diff --git a/doc/symbols/BTree.html b/doc/symbols/BTree.html deleted file mode 100644 index 44d3cd5..0000000 --- a/doc/symbols/BTree.html +++ /dev/null @@ -1,1765 +0,0 @@ - - - - - - - JsDoc Reference - BTree - - - - - - - - - - - - - -
- -

- - Class BTree -

- - -

- - -
Defined in: DataStructures.js. - -

- - - - - - - - - - - - - - - - - -
Class Summary
Constructor AttributesConstructor Name and Description
  -
- BTree(minimumDegree) -
-
Class for managing a B-Tree.
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Field Summary
Field AttributesField Name and Description
  -
- root -
-
The root of the tree.
-
  -
- size -
-
The number of items stored in the tree.
-
  -
- t -
-
The minimum number of the keys of a node.
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Method Summary
Method AttributesMethod Name and Description
  -
allIndexesOf(item, callback) -
-
Returns all the position in which the item has been found in the tree.
-
  -
augmentChild(node, index) -
-
Augments the number of keys stored in the node preserving the order.
-
  -
clear() -
-
Removes all the items stored in the tree.
-
  -
clone() -
-
Clones the tree into a new tree.
-
  - -
Clones the tree into a new tree without cloning duplicated items.
-
  -
contains(key, callback) -
-
Checks if the tree contains the key.
-
  -
deleteKey(key) -
-
Deletes the key from the tree.
-
  -
deleteMax(node, index) -
-
Deletes a node that have the maximum number of keys for node.
-
  -
deleteNonMin(node, key) -
-
Deletes a node that's a number of keys greater than the minimum for a node.
-
  -
execute(callback) -
-
Executes the callback function for each item of the tree.
-
  -
filter(callback) -
-
Returns the items that satisfy the condition determined by the callback.
-
  -
fullContains(callback) -
-
Checks if the tree contains a node that satisfy the condition represented by the - callback function. -
-
  -
getItem(index) -
-
Returns the item at the position index.
-
  - -
Returns the iterator relative to the aggregate.
-
  -
getSize() -
-
Returns the size of the tree.
-
  -
indexOf(item, callback) -
-
Returns the first position of the item in the tree.
-
  -
insert(key, item) -
-
Inserts the item relatives to the key value in the tree.
-
  -
insertNonFull(node, key, item) -
-
Inserts the new node in the right position if the node is not full.
-
  -
isEmpty() -
-
Checks if the tree is empty.
-
  -
lastIndexOf(item, callback) -
-
Returns the last position of the item in the tree.
-
  -
maximum() -
-
Gets the item relatives to the maximum key stored in the tree.
-
  - -
Gets the maximum key stored in the tree.
-
  -
minimum() -
-
Gets the item relatives to the minimum key stored in the tree.
-
  - -
Gets the minimum key stored in the tree.
-
  -
predecessor(key, node) -
-
Gets the key previous to the param key.
-
  -
search(key, node, callback) -
-
Searches the item relatives to the key that satisfy the condition represented by the - callback function. -
-
  -
splitChild(node, index) -
-
Splits the child of the node at the position index.
-
  -
successor(key, node) -
-
Gets the key next to the param node key.
-
  -
toArray() -
-
Transforms the tree into an array without preserving keys.
-
- - - - - - - -
- -
- Class Detail -
- -
- BTree(minimumDegree) -
- -
- Class for managing a B-Tree. - -
- - -
-
Parameters:
- -
- minimumDegree - -
-
{number} The minimum number of keys of a node.
- -
- - -
- - - - -
- Field Detail -
- - - -
- - - root - -
-
- The root of the tree. - - -
- - -
- - - -
- - - size - -
-
- The number of items stored in the tree. - - -
- - -
- - - -
- - - t - -
-
- The minimum number of the keys of a node. - - -
- - - - -
- Method Detail -
- - - -
- - {Array} - allIndexesOf(item, callback) - -
-
- Returns all the position in which the item has been found in the tree. - - -
- - -
-
Parameters:
- -
- item - -
-
{*} The item to search.
- -
- callback - Optional, Default: function(item){return(it===item);} -
-
The condition to satisfy. The callback must accept the current item to check.
- -
- - -
-
Returns:
- -
{Array} The positions in which the item has been found.
- -
- - -
- - - -
- - {void} - augmentChild(node, index) - -
-
- Augments the number of keys stored in the node preserving the order. - - -
- - -
-
Parameters:
- -
- node - -
-
{BNode} The node to delete.
- -
- index - -
-
{number} The index of the position to augment.
- -
- - -
-
Returns:
- -
{void}
- -
- - -
- - - -
- - {void} - clear() - -
-
- Removes all the items stored in the tree. - - -
- - -
-
Returns:
- -
{void}
- -
- - -
- - - -
- - {BTree} - clone() - -
-
- Clones the tree into a new tree. - - -
- - -
-
Returns:
- -
{BTree} The tree cloned from this tree. -
- -
- - -
- - - -
- - {BTree} - cloneDistinct() - -
-
- Clones the tree into a new tree without cloning duplicated items. - - -
- - -
-
Returns:
- -
{BTree} The tree cloned from this tree. -
- -
- - -
- - - -
- - {boolean} - contains(key, callback) - -
-
- Checks if the tree contains the key. - - -
- - -
-
Parameters:
- -
- key - -
-
{number} The key to find.
- -
- callback - Optional, Default: function(node,index){return(node.keys[index]===key);} -
-
The condition to satisfy. The callback must accept the current node to check and optionally the position of the - key. -
- -
- - -
-
Returns:
- -
{boolean} True if the tree contains the key.
- -
- - -
- - - -
- - {void} - deleteKey(key) - -
-
- Deletes the key from the tree. - - -
- - -
-
Parameters:
- -
- key - -
-
{*} The key to delete.
- -
- - -
-
Returns:
- -
{void}
- -
- - -
- - - -
- - {void} - deleteMax(node, index) - -
-
- Deletes a node that have the maximum number of keys for node. - - -
- - -
-
Parameters:
- -
- node - -
-
{BNode} The node to delete.
- -
- index - -
-
{number} The key to delete in the node.
- -
- - -
-
Returns:
- -
{void}
- -
- - -
- - - -
- - {void} - deleteNonMin(node, key) - -
-
- Deletes a node that's a number of keys greater than the minimum for a node. - - -
- - -
-
Parameters:
- -
- node - -
-
{BNode} The node to delete.
- -
- key - -
-
{number} The key to delete.
- -
- - -
-
Returns:
- -
{void}
- -
- - -
- - - -
- - {void} - execute(callback) - -
-
- Executes the callback function for each item of the tree. - This method modifies the tree so if you don't need to modify it you must return the same item of the array. - - -
- - -
-
Parameters:
- -
- callback - -
-
{function} The function to execute for each item. The function must accept the current item on which execute the - function. -
- -
- - -
-
Returns:
- -
{void}
- -
- - -
- - - -
- - {Array<*>} - filter(callback) - -
-
- Returns the items that satisfy the condition determined by the callback. - - -
- - -
-
Parameters:
- -
- callback - -
-
{function} The function that implements the condition.
- -
- - -
-
Returns:
- -
{Array<*>} The array that contains the items that satisfy the condition. -
- -
- - -
- - - -
- - {boolean} - fullContains(callback) - -
-
- Checks if the tree contains a node that satisfy the condition represented by the callback function. - This method check all the tree avoiding the binary search. - - -
- - -
-
Parameters:
- -
- callback - -
-
{function} The condition to satisfy. The callback must accept the current node to check.
- -
- - -
-
Returns:
- -
{boolean} True if the tree contains the node that satisfy the condition, - false otherwise. -
- -
- - -
- - - -
- - {*} - getItem(index) - -
-
- Returns the item at the position index. - - -
- - -
-
Parameters:
- -
- index - -
-
{number} The position of the item.
- -
- - -
-
Returns:
- -
{*} The item at the position. It's undefined if index isn't in the tree - bounds. -
- -
- - -
- - - -
- - {Iterator} - getIterator() - -
-
- Returns the iterator relative to the aggregate. - - -
- - -
-
Returns:
- -
{Iterator} The iterator.
- -
- - -
- - - -
- - {number} - getSize() - -
-
- Returns the size of the tree. - - -
- - -
-
Returns:
- -
{number} The size of the tree.
- -
- - -
- - - -
- - {number} - indexOf(item, callback) - -
-
- Returns the first position of the item in the tree. - - -
- - -
-
Parameters:
- -
- item - -
-
{*} The item to search.
- -
- callback - Optional, Default: function(item){return(it===item);} -
-
The condition to satisfy. The callback must accept the current item to check.
- -
- - -
-
Returns:
- -
{number} The first position of the item.
- -
- - -
- - - -
- - {void} - insert(key, item) - -
-
- Inserts the item relatives to the key value in the tree. - - -
- - -
-
Parameters:
- -
- key - -
-
{number} The key to store.
- -
- item - -
-
{*} The item to store.
- -
- - -
-
Returns:
- -
{void}
- -
- - -
- - - -
- - {void} - insertNonFull(node, key, item) - -
-
- Inserts the new node in the right position if the node is not full. - - -
- - -
-
Parameters:
- -
- node - -
-
{BNode} The node from which start to check the insertion.
- -
- key - -
-
{number} The key to store.
- -
- item - -
-
{*} The item to store.
- -
- - -
-
Returns:
- -
{void}
- -
- - -
- - - -
- - {boolean} - isEmpty() - -
-
- Checks if the tree is empty. - - -
- - -
-
Returns:
- -
{boolean} True if the tree is empty, false otherwise.
- -
- - -
- - - -
- - {number} - lastIndexOf(item, callback) - -
-
- Returns the last position of the item in the tree. - - -
- - -
-
Parameters:
- -
- item - -
-
{*} The item to search.
- -
- callback - Optional, Default: function(item){return(it===item);} -
-
The condition to satisfy. The callback must accept the current item to check.
- -
- - -
-
Returns:
- -
{number} The last position of the item.
- -
- - -
- - - -
- - {node} - maximum() - -
-
- Gets the item relatives to the maximum key stored in the tree. - - -
- - -
-
Returns:
- -
{node} The item found.
- -
- - -
- - - -
- - {number} - maximumKey() - -
-
- Gets the maximum key stored in the tree. - - -
- - -
-
Returns:
- -
{number} The key found.
- -
- - -
- - - -
- - {number} - minimum() - -
-
- Gets the item relatives to the minimum key stored in the tree. - - -
- - -
-
Returns:
- -
{number} The item found.
- -
- - -
- - - -
- - {number} - minimumKey() - -
-
- Gets the minimum key stored in the tree. - - -
- - -
-
Returns:
- -
{number} The key found.
- -
- - -
- - - -
- - {number} - predecessor(key, node) - -
-
- Gets the key previous to the param key. - - -
- - -
-
Parameters:
- -
- key - -
-
{number} The key of which search the predecessor.
- -
- node - Optional, Default: root -
-
The node from start the search of the predecessor.
- -
- - -
-
Returns:
- -
{number} The key found.
- -
- - -
- - - -
- - {*} - search(key, node, callback) - -
-
- Searches the item relatives to the key that satisfy the condition represented by the callback function. - - -
- - -
-
Parameters:
- -
- key - -
-
{Number} The key to find.
- -
- node - Optional, Default: root -
-
{RBNode} The node from which start the search.
- -
- callback - Optional, Default: function(node,index){return(node.keys[index]===key);} -
-
The condition to satisfy. The callback must accept the current node to check and optionally the position of the - key. -
- -
- - -
-
Returns:
- -
{*} The item found or undefined if there isn't the key in the tree.
- -
- - -
- - - -
- - {void} - splitChild(node, index) - -
-
- Splits the child of the node at the position index. - - -
- - -
-
Parameters:
- -
- node - -
-
{BNode} The parent of the child to split.
- -
- index - -
-
{number} The position of the child to split.
- -
- - -
-
Returns:
- -
{void}
- -
- - -
- - - -
- - {number} - successor(key, node) - -
-
- Gets the key next to the param node key. - - -
- - -
-
Parameters:
- -
- key - -
-
{number} The key of which search the successor.
- -
- node - Optional, Default: root -
-
The node from start the search of the successor.
- -
- - -
-
Returns:
- -
{number} The key found.
- -
- - -
- - - -
- - {Array<*>} - toArray() - -
-
- Transforms the tree into an array without preserving keys. - - -
- - -
-
Returns:
- -
{Array<*>} The array that represents the tree.
- -
- - - - - -
-
- - - -
- - Documentation generated by JsDoc Toolkit 2.4.0 - on Wed Apr 23 2014 22:40:58 GMT+0200 (CEST) -
- - diff --git a/doc/symbols/BTreeIterator.html b/doc/symbols/BTreeIterator.html deleted file mode 100644 index b1846da..0000000 --- a/doc/symbols/BTreeIterator.html +++ /dev/null @@ -1,668 +0,0 @@ - - - - - - - JsDoc Reference - BTreeIterator - - - - - - - - - - - - - -
- -

- - Class BTreeIterator -

- - -

- - -
Defined in: DataStructures.js. - -

- - - - - - - - - - - - - - - - - -
Class Summary
Constructor AttributesConstructor Name and Description
  -
- BTreeIterator(aggregate) -
-
Class that implements the iterator for a binary search tree.
-
- - - - - - - - - - - - - - - - - - - - - - - - - - -
Field Summary
Field AttributesField Name and Description
  -
- aggregate -
-
The aggregate relates to this iterator.
-
  -
- pointer -
-
The pointer to the position.
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Method Summary
Method AttributesMethod Name and Description
  -
first() -
-
Moves the iterator to the first position of the aggregate.
-
  -
getItem() -
-
Returns the item stored at the position pointed by the iterator.
-
  -
getKey() -
-
Returns the key stored at the position pointed by the iterator.
-
  -
isDone() -
-
Checks if the iterator is out of the bounds of the aggregate.
-
  -
last() -
-
Moves the iterator to the last position of the aggregate.
-
  -
next() -
-
Moves the iterator to the next item.
-
  - -
Moves the iterator to the previous item.
-
- - - - - - - -
- -
- Class Detail -
- -
- BTreeIterator(aggregate) -
- -
- Class that implements the iterator for a binary search tree. - -
- - -
-
Parameters:
- -
- aggregate - -
-
{BTree} The aggregate to scan.
- -
- - -
- - - - -
- Field Detail -
- - - -
- - - aggregate - -
-
- The aggregate relates to this iterator. - - -
- - -
- - - -
- - - pointer - -
-
- The pointer to the position. - - -
- - - - -
- Method Detail -
- - - -
- - {void} - first() - -
-
- Moves the iterator to the first position of the aggregate. - - -
- - -
-
Returns:
- -
{void}
- -
- - -
- - - -
- - {*} - getItem() - -
-
- Returns the item stored at the position pointed by the iterator. - - -
- - -
-
Returns:
- -
{*} The item stored or undefined if it's out of the bounds.
- -
- - -
- - - -
- - {number} - getKey() - -
-
- Returns the key stored at the position pointed by the iterator. - - -
- - -
-
Returns:
- -
{number} The key stored or null if it's out of the bounds.
- -
- - -
- - - -
- - {boolean} - isDone() - -
-
- Checks if the iterator is out of the bounds of the aggregate. - - -
- - -
-
Returns:
- -
{boolean} It return true if the iterator is out of the bounds of the - aggregate, otherwise false. -
- -
- - -
- - - -
- - {void} - last() - -
-
- Moves the iterator to the last position of the aggregate. - - -
- - -
-
Returns:
- -
{void}
- -
- - -
- - - -
- - {void} - next() - -
-
- Moves the iterator to the next item. - - -
- - -
-
Returns:
- -
{void}
- -
- - -
- - - -
- - {void} - previous() - -
-
- Moves the iterator to the previous item. - - -
- - -
-
Returns:
- -
{void}
- -
- - - - - -
-
- - - -
- - Documentation generated by JsDoc Toolkit 2.4.0 - on Wed Apr 23 2014 22:40:58 GMT+0200 (CEST) -
- - diff --git a/doc/symbols/CircularBuffer.html b/doc/symbols/CircularBuffer.html deleted file mode 100644 index 3e8651b..0000000 --- a/doc/symbols/CircularBuffer.html +++ /dev/null @@ -1,899 +0,0 @@ - - - - - - - JsDoc Reference - CircularBuffer - - - - - - - - - - - - - -
- -

- - Class CircularBuffer -

- - -

- - -
Defined in: DataStructures.js. - -

- - - - - - - - - - - - - - - - - -
Class Summary
Constructor AttributesConstructor Name and Description
  -
- CircularBuffer(size) -
-
Class for managing a circular buffer.
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Field Summary
Field AttributesField Name and Description
  -
- empty -
-
Is true if buffer is empty, false otherwise.
-
  -
- full -
-
Is true if buffer is full, false otherwise.
-
  -
- head -
-
The index of the position of the head of the buffer.
-
  -
- items -
-
The items stored in the buffer.
-
  -
- size -
-
The size of the buffer.
-
  -
- tail -
-
The index of the position of the tail of the buffer.
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Method Summary
Method AttributesMethod Name and Description
  -
clone() -
-
Clones the circular buffer into a new circular buffer.
-
  -
free(from, to) -
-
Frees the buffer between indexes from and to.
-
  -
freeAll() -
-
Frees all the buffer.
-
  - -
Returns the iterator relative to the aggregate.
-
  -
isEmpty() -
-
Returns true if the buffer is empty, false otherwise.
-
  -
isFull() -
-
Returns true if the buffer is full, false otherwise.
-
  -
read(index) -
-
Reads the item stored at the position index.
-
  -
resize(size) -
-
Resize the buffer.
-
  -
write(item) -
-
Writes the item at the head of the buffer.
-
- - - - - - - -
- -
- Class Detail -
- -
- CircularBuffer(size) -
- -
- Class for managing a circular buffer. - -
- - -
-
Parameters:
- -
- size - -
-
{Number} The size of the buffer.
- -
- - -
- - - - -
- Field Detail -
- - - -
- - - empty - -
-
- Is true if buffer is empty, false otherwise. - - -
- - -
- - - -
- - - full - -
-
- Is false if buffer is full, false otherwise. - - -
- - -
- - - -
- - - head - -
-
- The index of the position of the head of the buffer. - - -
- - -
- - - -
- - - items - -
-
- The items stored in the buffer. - - -
- - -
- - - -
- - - size - -
-
- The size of the buffer. - - -
- - -
- - - -
- - - tail - -
-
- The index of the position of the tail of the buffer. - - -
- - - - -
- Method Detail -
- - - -
- - {CircularBuffer} - clone() - -
-
- Clones the circular buffer into a new circular buffer. - - -
- - -
-
Returns:
- -
{CircularBuffer} The circular - buffer cloned from this circular buffer. -
- -
- - -
- - - -
- - {void} - free(from, to) - -
-
- Frees the buffer between indexes from and to. - If from > to, positions between from and the end of the buffer and between the start and to will be free. - - -
- - -
-
Parameters:
- -
- from - -
-
{Number} The index from which start to free (inclusive index)
- -
- to - -
-
{Number} The index where stop to free (exclusive index)
- -
- - -
-
Returns:
- -
{void}
- -
- - -
- - - -
- - {void} - freeAll() - -
-
- Frees all the buffer. - - -
- - -
-
Returns:
- -
{void}
- -
- - -
- - - -
- - {Iterator} - getIterator() - -
-
- Returns the iterator relative to the aggregate. - - -
- - -
-
Returns:
- -
{Iterator} The iterator.
- -
- - -
- - - -
- - {boolean} - isEmpty() - -
-
- Returns true if the buffer is empty, false otherwise. - - -
- - -
-
Returns:
- -
{boolean}
- -
- - -
- - - -
- - {boolean} - isFull() - -
-
- Returns true if the buffer is full, false otherwise. - - -
- - -
-
Returns:
- -
{boolean}
- -
- - -
- - - -
- - {*} - read(index) - -
-
- Reads the item stored at the position index. - - -
- - -
-
Parameters:
- -
- index - -
-
{Number} The position of the item to read.
- -
- - -
-
Returns:
- -
{*} The item read.
- -
- - -
- - - -
- - {void} - resize(size) - -
-
- Resize the buffer. - - -
- - -
-
Parameters:
- -
- size - -
-
{number} The new size of the buffer.
- -
- - -
-
Returns:
- -
{void}
- -
- - -
- - - -
- - {void} - write(item) - -
-
- Writes the item at the head of the buffer. - - -
- - -
-
Parameters:
- -
- item - -
-
{*} The item to write.
- -
- - -
-
Returns:
- -
{void}
- -
- - - - - -
-
- - - -
- - Documentation generated by JsDoc Toolkit 2.4.0 - on Wed Apr 23 2014 22:40:58 GMT+0200 (CEST) -
- - diff --git a/doc/symbols/CircularBufferIterator.html b/doc/symbols/CircularBufferIterator.html deleted file mode 100644 index 7f74a48..0000000 --- a/doc/symbols/CircularBufferIterator.html +++ /dev/null @@ -1,663 +0,0 @@ - - - - - - - JsDoc Reference - CircularBufferIterator - - - - - - - - - - - - - -
- -

- - Class CircularBufferIterator -

- - -

- - -
Defined in: DataStructures.js. - -

- - - - - - - - - - - - - - - - - -
Class Summary
Constructor AttributesConstructor Name and Description
  -
- CircularBufferIterator(aggregate) -
-
Class that implements the iterator for a circular buffer.
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Field Summary
Field AttributesField Name and Description
  -
- aggregate -
-
The aggregate relates to this iterator.
-
  -
- pointer -
-
The pointer to the position.
-
  -
- start -
-
Discriminator for full buffer
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Method Summary
Method AttributesMethod Name and Description
  -
first() -
-
Moves the iterator to the first position of the aggregate.
-
  -
getItem() -
-
Returns the item stored at the position pointed by the iterator.
-
  -
isDone() -
-
Checks if the iterator is out of the bounds of the aggregate.
-
  -
last() -
-
Moves the iterator to the last position of the aggregate.
-
  -
next() -
-
Moves the iterator to the next item.
-
  - -
Moves the iterator to the previous item.
-
- - - - - - - -
- -
- Class Detail -
- -
- CircularBufferIterator(aggregate) -
- -
- Class that implements the iterator for a circular buffer. - -
- - -
-
Parameters:
- -
- aggregate - -
-
{CircularBuffer} The aggregate to scan.
- -
- - -
- - - - -
- Field Detail -
- - - -
- - - aggregate - -
-
- The aggregate relates to this iterator. - - -
- - -
- - - -
- - - pointer - -
-
- The pointer to the position. - - -
- - -
- - - -
- - - start - -
-
- Discriminator for full buffer - - -
- - - - -
- Method Detail -
- - - -
- - {void} - first() - -
-
- Moves the iterator to the first position of the aggregate. - - -
- - -
-
Returns:
- -
{void}
- -
- - -
- - - -
- - {*} - getItem() - -
-
- Returns the item stored at the position pointed by the iterator. - - -
- - -
-
Returns:
- -
{*} The item stored or undefined if it's out of the bounds.
- -
- - -
- - - -
- - {boolean} - isDone() - -
-
- Checks if the iterator is out of the bounds of the aggregate. - - -
- - -
-
Returns:
- -
{boolean} It return true if the iterator is out of the bounds of the - aggregate, otherwise false. -
- -
- - -
- - - -
- - {void} - last() - -
-
- Moves the iterator to the last position of the aggregate. - - -
- - -
-
Returns:
- -
{void}
- -
- - -
- - - -
- - {void} - next() - -
-
- Moves the iterator to the next item. - - -
- - -
-
Returns:
- -
{void}
- -
- - -
- - - -
- - {void} - previous() - -
-
- Moves the iterator to the previous item. - - -
- - -
-
Returns:
- -
{void}
- -
- - - - - -
-
- - - -
- - Documentation generated by JsDoc Toolkit 2.4.0 - on Wed Apr 23 2014 22:40:58 GMT+0200 (CEST) -
- - diff --git a/doc/symbols/DoubleLinkedList.html b/doc/symbols/DoubleLinkedList.html deleted file mode 100644 index aa065ca..0000000 --- a/doc/symbols/DoubleLinkedList.html +++ /dev/null @@ -1,2104 +0,0 @@ - - - - - - - JsDoc Reference - DoubleLinkedList - - - - - - - - - - - - - -
- -

- - Class DoubleLinkedList -

- - -

- - -
Defined in: DataStructures.js. - -

- - - - - - - - - - - - - - - - - -
Class Summary
Constructor AttributesConstructor Name and Description
  -
- DoubleLinkedList(args) -
-
Class for managing a double linked list.
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Field Summary
Field AttributesField Name and Description
  -
- first -
-
The first node of the list.
-
  -
- last -
-
The last node of the list.
-
  -
- length -
-
The length of the list.
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Method Summary
Method AttributesMethod Name and Description
  -
addAt(item, index) -
-
Adds the item at the index position.
-
  -
allIndexesOf(item, - callback) -
-
Returns all the position in which the item has been found in the list.
-
  -
clear() -
-
Removes all the items stored in the list.
-
  -
clone() -
-
Clones the list into a new list.
-
  - -
Clones the list into a new list without cloning duplicated items.
-
  -
contains(item, callback) -
-
Checks if the list contains an item that satisfy the condition represented by the - callback function. -
-
  -
count(callback) -
-
Returns the number of items that satisfy the represented by the callback function. -
-
  -
deleteNode(node) -
-
Deletes the node from the list.
-
  -
divide(index) -
-
Divides the list at the index position.
-
  -
execute(callback) -
-
Executes the callback function for each item of the stack.
-
  -
filter(callback) -
-
Returns the items that satisfy the condition determined by the callback.
-
  -
fromArray(array) -
-
Builds the list from the array.
-
  -
getItem(index) -
-
Gets the item at the position index.
-
  - -
Returns the iterator relative to the aggregate.
-
  - -
Returns the length of the list.
-
  -
getNode(index, node) -
-
Gets the node at the position index relative from the node.
-
  -
indexOf(item, callback) -
-
Returns the first position of the item in the list.
-
  -
isEmpty() -
-
Checks if the list is empty.
-
  -
join(list) -
-
Adds the list at the end of this list.
-
  -
lastIndexOf(item, - callback) -
-
Returns the last position of the item in the list.
-
  -
modifyAt(index, item) -
-
Changes the item stored in the index position.
-
  -
multiPopBack(times) -
-
Removes the last times items of the list.
-
  -
multiPopFront(times) -
-
Removes the first times items of the list.
-
  - -
Sorts the list using web workers.
-
  -
peek() -
-
Returns the first item of the list without remove it.
-
  -
popBack() -
-
Removes the last item of the list.
-
  - -
Removes the first item of the list.
-
  -
pushBack(item) -
-
Adds an item at the tail of the list.
-
  -
pushFront(item) -
-
Adds an item at the head of the list.
-
  -
remove(item, callback) -
-
Removes the item from the list.
-
  -
removeAll(item, callback) -
-
Removes all the item from the list.
-
  -
removeAt(index) -
-
Removes the item at the position index.
-
  -
removeSegment(from, - to) -
-
Removes all the items stored from the from position to the to position.
-
  -
reverse() -
-
Reverses the list.
-
  -
sort(callback) -
-
Sorts the list.
-
  -
split(size) -
-
Splits the list into lists of desired size.
-
  -
toArray() -
-
Transforms the list into an array.
-
- - - - - - - -
- -
- Class Detail -
- -
- DoubleLinkedList(args) -
- -
- Class for managing a double linked list. - -
- - -
-
Parameters:
- -
- {...*} args - Optional -
-
The items for initializing the list.
- -
- - -
- - - - -
- Field Detail -
- - - -
- - - first - -
-
- The first node of the list. - - -
- - -
- - - -
- - - last - -
-
- The last node of the list. - - -
- - -
- - - -
- - - length - -
-
- The length of the list. - - -
- - - - -
- Method Detail -
- - - -
- - {void} - addAt(item, index) - -
-
- Adds the item at the index position. - - -
- - -
-
Parameters:
- -
- item - -
-
{*} The item to add.
- -
- index - -
-
{number} The position where to add the item. If index is negative, the item won't be added.
- -
- - -
-
Returns:
- -
{void}
- -
- - -
- - - -
- - {Array} - allIndexesOf(item, callback) - -
-
- Returns all the position in which the item has been found in the list. - - -
- - -
-
Parameters:
- -
- item - -
-
{*} The item to search.
- -
- callback - Optional, Default: function(item){return(it===item);} -
-
The condition to satisfy. The callback must accept the current item to check.
- -
- - -
-
Returns:
- -
{Array} The positions in which the item has been found.
- -
- - -
- - - -
- - {void} - clear() - -
-
- Removes all the items stored in the list. - - -
- - -
-
Returns:
- -
{void}
- -
- - -
- - - -
- - {DoubleLinkedList} - clone() - -
-
- Clones the list into a new list. - - -
- - -
-
Returns:
- -
{DoubleLinkedList} The list - cloned from this list. -
- -
- - -
- - - -
- - {DoubleLinkedList} - cloneDistinct() - -
-
- Clones the list into a new list without cloning duplicated items. - - -
- - -
-
Returns:
- -
{DoubleLinkedList} The list - cloned from this list. -
- -
- - -
- - - -
- - {boolean} - contains(item, callback) - -
-
- Checks if the list contains an item that satisfy the condition represented by the callback function. - - -
- - -
-
Parameters:
- -
- item - -
-
{*} The item to find.
- -
- callback - Optional, Default: function(item){return(it===item);} -
-
The condition to satisfy. The callback must accept the current item to check.
- -
- - -
-
Returns:
- -
{boolean} True if the list contains the item that satisfy the condition, - false otherwise. -
- -
- - -
- - - -
- - {number} - count(callback) - -
-
- Returns the number of items that satisfy the represented by the callback function. - - -
- - -
-
Parameters:
- -
- callback - -
-
{function} The condition to satisfy.
- -
- - -
-
Returns:
- -
{number} The number of items that satisfy the condition.
- -
- - -
- - - -
- - {void} - deleteNode(node) - -
-
- Deletes the node from the list. - - -
- - -
-
Parameters:
- -
- node - -
-
{DLLNode} The node to delete.
- -
- - -
-
Returns:
- -
{void}
- -
- - -
- - - -
- - {DoubleLinkedList} - divide(index) - -
-
- Divides the list at the index position. The node at the index position is the first new node of the list. - - -
- - -
-
Parameters:
- -
- index - -
-
{number} The position where to divide the list.
- -
- - -
-
Returns:
- -
{DoubleLinkedList} The list - formed by the nodes from the index position then. If the index is out of bound, the list will be empty. -
- -
- - -
- - - -
- - {void} - execute(callback) - -
-
- Executes the callback function for each item of the stack. - This method modifies the list so if you don't need to modify it you must return the same item of the array. - - -
- - -
-
Parameters:
- -
- callback - -
-
{function} The function to execute for each item. The function must accept the current item on which execute the - function. -
- -
- - -
-
Returns:
- -
{void}
- -
- - -
- - - -
- - {Array} - filter(callback) - - -
- Returns the items that satisfy the condition determined by the callback. - - -
- - -
-
Parameters:
- -
- callback - -
-
{function} The function that implements the condition.
- -
- - -
-
Returns:
- -
{Array} The array that contains the items that satisfy the - condition. - - - - - -
- - - -
- - {void} - fromArray(array) - -
-
- Builds the list from the array. - - -
- - -
-
Parameters:
- -
- array - -
-
{Array<*>} The array from which build the list.
- -
- - -
-
Returns:
- -
{void}
- -
- - -
- - - -
- - {*} - getItem(index) - -
-
- Gets the item at the position index. - - -
- - -
-
Parameters:
- -
- index - -
-
{Number} The position of the item.
- -
- - -
-
Returns:
- -
{*} . It's undefined if index isn't in the queue bounds.
- -
- - -
- - - -
- - {Iterator} - getIterator() - -
-
- Returns the iterator relative to the aggregate. - - -
- - -
-
Returns:
- -
{Iterator} The iterator.
- -
- - -
- - - -
- - {Number} - getLength() - -
-
- Returns the length of the list. - - -
- - -
-
Returns:
- -
{Number} The length of the list.
- -
- - -
- - - -
- - {DLLNode} - getNode(index, node) - -
-
- Gets the node at the position index relative from the node. - - -
- - -
-
Parameters:
- -
- index - -
-
{Number} The index, relative to the node, of the node to return.
- -
- node - Optional, Default: first -
-
{DLLNode} The node from which start the search.
- -
- - -
-
Returns:
- -
{DLLNode} The node at the position index.
- -
- - -
- - - -
- - {number} - indexOf(item, callback) - -
-
- Returns the first position of the item in the list. - - -
- - -
-
Parameters:
- -
- item - -
-
{*} The item to search.
- -
- callback - Optional, Default: function(item){return(it===item);} -
-
The condition to satisfy. The callback must accept the current item to check.
- -
- - -
-
Returns:
- -
{number} The first position of the item.
- -
- - -
- - - -
- - {boolean} - isEmpty() - -
-
- Checks if the list is empty. - - -
- - -
-
Returns:
- -
{boolean} True if the list is empty, false otherwise.
- -
- - -
- - - -
- - {void} - join(list) - -
-
- Adds the list at the end of this list. - - -
- - -
-
Parameters:
- -
- list - -
-
{DoubleLinkedList} The list to join.
- -
- - -
-
Returns:
- -
{void}
- -
- - -
- - - -
- - {number} - lastIndexOf(item, callback) - -
-
- Returns the last position of the item in the list. - - -
- - -
-
Parameters:
- -
- item - -
-
{*} The item to search.
- -
- callback - Optional, Default: function(item){return(it===item);} -
-
The condition to satisfy. The callback must accept the current item to check.
- -
- - -
-
Returns:
- -
{number} The last position of the item.
- -
- - -
- - - -
- - {void} - modifyAt(index, item) - -
-
- Changes the item stored in the index position. If the index is out of bound, the node won't be updated. - - -
- - -
-
Parameters:
- -
- index - -
-
{number} The position of the node to modify.
- -
- item - -
-
{*} The new item stored in the node.
- -
- - -
-
Returns:
- -
{void}
- -
- - -
- - - -
- - {*} - multiPopBack(times) - -
-
- Removes the last times items of the list. - - -
- - -
-
Parameters:
- -
- times - -
-
{number} The number of times to repeat the popBack method.
- -
- - -
-
Returns:
- -
{*} The items removed.
- -
- - -
- - - -
- - {*} - multiPopFront(times) - -
-
- Removes the first times items of the list. - - -
- - -
-
Parameters:
- -
- times - -
-
{number} The number of times to repeat the popFront method.
- -
- - -
-
Returns:
- -
{*} The item removed. It's undefined if the list is empty.
- -
- - -
- - - -
- - {void} - parallelSort() - -
-
- Sorts the list using web workers. - Using this method is discouraged. Many web browser set a limit to the maximum number of workers instantiated. - The items of the list, due to web workers implementation, will be serialized so they will lost own methods. - - -
- - -
-
Returns:
- -
{void}
- -
- - -
- - - -
- - {*} - peek() - -
-
- Returns the first item of the list without remove it. - - -
- - -
-
Returns:
- -
{*} The item at the top of the list. It's undefined if the list is empty. -
- -
- - -
- - - -
- - {*} - popBack() - -
-
- Removes the last item of the list. - - -
- - -
-
Returns:
- -
{*} The item removed. It's undefined if the list is empty.
- -
- - -
- - - -
- - {*} - popFront() - -
-
- Removes the first item of the list. - - -
- - -
-
Returns:
- -
{*} The item removed. It's undefined if the list is empty.
- -
- - -
- - - -
- - {void} - pushBack(item) - -
-
- Adds an item at the tail of the list. - - -
- - -
-
Parameters:
- -
- item - -
-
{*} The item to add.
- -
- - -
-
Returns:
- -
{void}
- -
- - -
- - - -
- - {void} - pushFront(item) - -
-
- Adds an item at the head of the list. - - -
- - -
-
Parameters:
- -
- item - -
-
{*} The item to add.
- -
- - -
-
Returns:
- -
{void}
- -
- - -
- - - -
- - {void} - remove(item, callback) - -
-
- Removes the item from the list. - - -
- - -
-
Parameters:
- -
- item - -
-
{*} The item to remove.
- -
- callback - Optional, Default: function(item){return(it===item);} -
-
The condition to satisfy. The callback must accept the current item to check.
- -
- - -
-
Returns:
- -
{void}
- -
- - -
- - - -
- - {void} - removeAll(item, callback) - -
-
- Removes all the item from the list. - - -
- - -
-
Parameters:
- -
- item - -
-
{*} The item to remove.
- -
- callback - Optional, Default: function(item){return(it===item);} -
-
The condition to satisfy. The callback must accept the current item to check.
- -
- - -
-
Returns:
- -
{void}
- -
- - -
- - - -
- - {*} - removeAt(index) - -
-
- Removes the item at the position index. - - -
- - -
-
Parameters:
- -
- index - -
-
{Number} The position of the item to remove.
- -
- - -
-
Returns:
- -
{*} The item stored at the position index. It's undefined if the index is - out of bounds. -
- -
- - -
- - - -
- - {Array<*>} - removeSegment(from, to) - -
-
- Removes all the items stored from the from position to the to position. - If from > to, the method will remove all the items up to the end. - - -
- - -
-
Parameters:
- -
- from - -
-
{number} The position where start to remove the items. The from position is included.
- -
- to - -
-
{number} The position where stop to remove the items. The to position is included.
- -
- - -
-
Returns:
- -
{Array<*>} The items removed.
- -
- - -
- - - -
- - {void} - reverse() - -
-
- Reverses the list. This method reverses only the items, not the nodes. - - -
- - -
-
Returns:
- -
{void}
- -
- - -
- - - -
- - {void} - sort(callback) - -
-
- Sorts the list. - - -
- - - -
callback = function(item) {return -item.key;}
-This function callback will return the opposite of the attribute key of the item. In this case the list will be sorted in descending order.
- - -
-
Parameters:
- -
- callback - Optional, Default: function(item){return(item);} -
-
{function} The function invoked in order to get the value for the evaluation of the sort criteria.
- -
- - -
-
Returns:
- -
{void}
- -
- - -
- - - -
- - {Array} - split(size) - -
-
- Splits the list into lists of desired size. - - -
- - -
-
Parameters:
- -
- size - -
-
{number} The size of the lists.
- -
- - -
-
Returns:
- -
{Array} The lists created by splitting the list.
- -
- - -
- - - -
- - {Array<*>} - toArray() - -
-
- Transforms the list into an array. - - -
- - -
-
Returns:
- -
{Array<*>} The array built.
- -
- - - - - -
- - - - -
- - Documentation generated by JsDoc Toolkit 2.4.0 - on Wed Apr 23 2014 22:40:58 GMT+0200 (CEST) -
- - diff --git a/doc/symbols/DoubleLinkedListIterator.html b/doc/symbols/DoubleLinkedListIterator.html deleted file mode 100644 index e822350..0000000 --- a/doc/symbols/DoubleLinkedListIterator.html +++ /dev/null @@ -1,670 +0,0 @@ - - - - - - - JsDoc Reference - DoubleLinkedListIterator - - - - - - - - - - - - - -
- -

- - Class DoubleLinkedListIterator -

- - -

- - -
Defined in: DataStructures.js. - -

- - - - - - - - - - - - - - - - - -
Class Summary
Constructor AttributesConstructor Name and Description
  -
- DoubleLinkedListIterator(aggregate) -
-
Class that implements the iterator for a double linked list.
-
- - - - - - - - - - - - - - - - - - - - - - - - - - -
Field Summary
Field AttributesField Name and Description
  -
- aggregate -
-
The aggregate relates to this iterator.
-
  -
- pointer -
-
The pointer to the position.
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Method Summary
Method AttributesMethod Name and Description
  -
first() -
-
Moves the iterator to the first position of the aggregate.
-
  -
getItem() -
-
Returns the item stored at the position pointed by the iterator.
-
  -
getNode() -
-
Returns the node stored at the position pointed by the iterator.
-
  -
isDone() -
-
Checks if the iterator is out of the bounds of the aggregate.
-
  -
last() -
-
Moves the iterator to the last position of the aggregate.
-
  -
next() -
-
Moves the iterator to the next item.
-
  - -
Moves the iterator to the previous item.
-
- - - - - - - -
- -
- Class Detail -
- -
- DoubleLinkedListIterator(aggregate) -
- -
- Class that implements the iterator for a double linked list. - -
- - -
-
Parameters:
- -
- aggregate - -
-
{DoubleLinkedList} The aggregate to scan.
- -
- - -
- - - - -
- Field Detail -
- - - -
- - - aggregate - -
-
- The aggregate relates to this iterator. - - -
- - -
- - - -
- - - pointer - -
-
- The pointer to the position. - - -
- - - - -
- Method Detail -
- - - -
- - {void} - first() - -
-
- Moves the iterator to the first position of the aggregate. - - -
- - -
-
Returns:
- -
{void}
- -
- - -
- - - -
- - {*} - getItem() - -
-
- Returns the item stored at the position pointed by the iterator. - - -
- - -
-
Returns:
- -
{*} The item stored or undefined if it's out of the bounds.
- -
- - -
- - - -
- - {DLLNode|null} - getNode() - -
-
- Returns the node stored at the position pointed by the iterator. - - -
- - -
-
Returns:
- -
{DLLNode|null} The node stored or null if it's out of the bounds.
- -
- - -
- - - -
- - {boolean} - isDone() - -
-
- Checks if the iterator is out of the bounds of the aggregate. - - -
- - -
-
Returns:
- -
{boolean} It return true if the iterator is out of the bounds of the - aggregate, otherwise false. -
- -
- - -
- - - -
- - {void} - last() - -
-
- Moves the iterator to the last position of the aggregate. - - -
- - -
-
Returns:
- -
{void}
- -
- - -
- - - -
- - {void} - next() - -
-
- Moves the iterator to the next item. - - -
- - -
-
Returns:
- -
{void}
- -
- - -
- - - -
- - {void} - previous() - -
-
- Moves the iterator to the previous item. - - -
- - -
-
Returns:
- -
{void}
- -
- - - - - -
-
- - - -
- - Documentation generated by JsDoc Toolkit 2.4.0 - on Wed Apr 23 2014 22:40:58 GMT+0200 (CEST) -
- - diff --git a/doc/symbols/HashTable.html b/doc/symbols/HashTable.html deleted file mode 100644 index b225578..0000000 --- a/doc/symbols/HashTable.html +++ /dev/null @@ -1,1120 +0,0 @@ - - - - - - - JsDoc Reference - HashTable - - - - - - - - - - - - - -
- -

- - Class HashTable -

- - -

- - -
Defined in: DataStructures.js. - -

- - - - - - - - - - - - - - - - - -
Class Summary
Constructor AttributesConstructor Name and Description
  -
- HashTable(size) -
-
Class for managing an hash table.
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Field Summary
Field AttributesField Name and Description
  -
- items -
-
The items stored in the hash table.
-
  -
- keyLength -
-
The number of keys stored in the hash table.
-
  -
- size -
-
The size of the table
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Method Summary
Method AttributesMethod Name and Description
  -
clear() -
-
Removes all the keys and the items stored in the hash table.
-
  -
clone() -
-
Clones the hash table into a new hash table.
-
  -
containsKey(key, callback) -
-
Checks if the hash table contains a key that satisfy the condition represented by - the callback function. -
-
  -
deleteAllKey(key) -
-
Deletes all the items relative to the key value.
-
  -
deleteKey(key) -
-
Deletes the first item relatives to the key value.
-
  -
execute(callback) -
-
Executes the callback function for each item of the hash table.
-
  -
filter(callback) -
-
Returns the items that satisfy the condition determined by the callback.
-
  - -
Returns the items stored in the hash table.
-
  -
getKeys() -
-
Returns the keys stored in the hash table.
-
  - -
Returns the number of keys stored in the hash table.
-
  -
getSize() -
-
Returns the size of the hash table.
-
  -
hash(key) -
-
Calculate the hash of the param key.
-
  -
insert(key, item) -
-
Stores the item with its key.
-
  -
isEmpty() -
-
Checks if the hash table is empty.
-
  -
search(key) -
-
Searches the item relative to the key value.
-
  -
searchAll(key) -
-
Searches all the items relative to the key value.
-
- - - - - - - -
- -
- Class Detail -
- -
- HashTable(size) -
- -
- Class for managing an hash table. - -
- - -
-
Parameters:
- -
- size - -
-
{number} The size of the table.
- -
- - -
- - - - -
- Field Detail -
- - - -
- - - items - -
-
- The items stored in the hash table. - - -
- - -
- - - -
- - - keyLength - -
-
- The number of keys stored in the hash table. - - -
- - -
- - - -
- - - size - -
-
- The size of the table - - -
- - - - -
- Method Detail -
- - - -
- - {void} - clear() - -
-
- Removes all the keys and the items stored in the hash table. - - -
- - -
-
Returns:
- -
{void}
- -
- - -
- - - -
- - {HashTable} - clone() - -
-
- Clones the hash table into a new hash table. - - -
- - -
-
Returns:
- -
{HashTable} The hash table cloned - from this hash table. -
- -
- - -
- - - -
- - {boolean} - containsKey(key, callback) - -
-
- Checks if the hash table contains a key that satisfy the condition represented by the callback function. - - -
- - -
-
Parameters:
- -
- key - -
-
{number} The key to find.
- -
- callback - Optional, Default: function(k){return(k===key);} -
-
The condition to satisfy. The callback must accept the current key to check.
- -
- - -
-
Returns:
- -
{boolean} True if the hash table contains the key that satisfy the - condition, false otherwise. -
- -
- - -
- - - -
- - {void} - deleteAllKey(key) - -
-
- Deletes all the items relative to the key value. - - -
- - -
-
Parameters:
- -
- key - -
-
{number} The key to delete.
- -
- - -
-
Returns:
- -
{void}
- -
- - -
- - - -
- - {void} - deleteKey(key) - -
-
- Deletes the first item relatives to the key value. - - -
- - -
-
Parameters:
- -
- key - -
-
{number} The key to delete.
- -
- - -
-
Returns:
- -
{void}
- -
- - -
- - - -
- - {void} - execute(callback) - -
-
- Executes the callback function for each item of the hash table. - This method modifies the hash table so if you don't need to modify it you must return the same item stored. - - -
- - -
-
Parameters:
- -
- callback - -
-
{function} The function to execute for each item. The function must accept the current item on which execute the - function. -
- -
- - -
-
Returns:
- -
{void}
- -
- - -
- - - -
- - {Array<*>} - filter(callback) - -
-
- Returns the items that satisfy the condition determined by the callback. - - -
- - -
-
Parameters:
- -
- callback - -
-
{function} The function that implements the condition.
- -
- - -
-
Returns:
- -
{Array<*>} The array that contains the items that satisfy the condition. -
- -
- - -
- - - -
- - {Array<*>} - getItems() - -
-
- Returns the items stored in the hash table. - - -
- - -
-
Returns:
- -
{Array<*>} The items stored in the table.
- -
- - -
- - - -
- - {Array} - getKeys() - -
-
- Returns the keys stored in the hash table. - - -
- - -
-
Returns:
- -
{Array} The keys stored in the table.
- -
- - -
- - - -
- - {number} - getNumberOfKeys() - -
-
- Returns the number of keys stored in the hash table. - - -
- - -
-
Returns:
- -
{number} The number of keys stored.
- -
- - -
- - - -
- - {number} - getSize() - -
-
- Returns the size of the hash table. - - -
- - -
-
Returns:
- -
{number} The size of the hash table.
- -
- - -
- - - -
- - {number} - hash(key) - -
-
- Calculate the hash of the param key. - - -
- - -
-
Parameters:
- -
- key - -
-
{number} The key to hash.
- -
- - -
-
Returns:
- -
{number} The hash of the key.
- -
- - -
- - - -
- - - insert(key, item) - -
-
- Stores the item with its key. - - -
- - -
-
Parameters:
- -
- key - -
-
{number} The key relatives to the item.
- -
- item - -
-
{*} The item to store.
- -
- - -
- - - -
- - {boolean} - isEmpty() - -
-
- Checks if the hash table is empty. - - -
- - -
-
Returns:
- -
{boolean} True if the hash table is empty, false otherwise.
- -
- - -
- - - -
- - {*|undefined} - search(key) - -
-
- Searches the item relative to the key value. - - -
- - -
-
Parameters:
- -
- key - -
-
{number} The key of the item to search.
- -
- - -
-
Returns:
- -
{*|undefined} The item found or undefined if the key does not exist.
- -
- - -
- - - -
- - {Array.<*>} - searchAll(key) - -
-
- Searches all the items relative to the key value. - - -
- - -
-
Parameters:
- -
- key - -
-
{number} The key of the items to search.
- -
- - -
-
Returns:
- -
{Array.<*>} An array with the items found.
- -
- - - - - -
-
- - - -
- - Documentation generated by JsDoc Toolkit 2.4.0 - on Wed Apr 23 2014 22:40:58 GMT+0200 (CEST) -
- - diff --git a/doc/symbols/Iterator.html b/doc/symbols/Iterator.html deleted file mode 100644 index 782b8f3..0000000 --- a/doc/symbols/Iterator.html +++ /dev/null @@ -1,552 +0,0 @@ - - - - - - - JsDoc Reference - Iterator - - - - - - - - - - - - - -
- -

- - Class Iterator -

- - -

- - -
Defined in: DataStructures.js. - -

- - - - - - - - - - - - - - - - - -
Class Summary
Constructor AttributesConstructor Name and Description
  -
- Iterator() -
-
Interface for managing an iterator for an aggregate.
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Method Summary
Method AttributesMethod Name and Description
  -
first() -
-
Moves the iterator to the first position of the aggregate.
-
  -
getItem() -
-
Returns the item stored at the position pointed by the iterator.
-
  -
isDone() -
-
Checks if the iterator is out of the bounds of the aggregate.
-
  -
last() -
-
Moves the iterator to the last position of the aggregate.
-
  -
next() -
-
Moves the iterator to the next item.
-
  - -
Moves the iterator to the previous item.
-
- - - - - - - -
- -
- Class Detail -
- -
- Iterator() -
- -
- Interface for managing an iterator for an aggregate. - -
- - -
- - - - - - - -
- Method Detail -
- - - -
- - {void} - first() - -
-
- Moves the iterator to the first position of the aggregate. - - -
- - -
-
Returns:
- -
{void}
- -
- - -
- - - -
- - {*} - getItem() - -
-
- Returns the item stored at the position pointed by the iterator. - - -
- - -
-
Returns:
- -
{*} The item stored or undefined if it's out of the bounds.
- -
- - -
- - - -
- - {boolean} - isDone() - -
-
- Checks if the iterator is out of the bounds of the aggregate. - - -
- - -
-
Returns:
- -
{boolean} It return true if the iterator is out of the bounds of the - aggregate, otherwise false. -
- -
- - -
- - - -
- - {void} - last() - -
-
- Moves the iterator to the last position of the aggregate. - - -
- - -
-
Returns:
- -
{void}
- -
- - -
- - - -
- - {void} - next() - -
-
- Moves the iterator to the next item. - - -
- - -
-
Returns:
- -
{void}
- -
- - -
- - - -
- - {void} - previous() - -
-
- Moves the iterator to the previous item. - - -
- - -
-
Returns:
- -
{void}
- -
- - - - - -
-
- - - -
- - Documentation generated by JsDoc Toolkit 2.4.0 - on Wed Apr 23 2014 22:40:58 GMT+0200 (CEST) -
- - diff --git a/doc/symbols/LinkedList.html b/doc/symbols/LinkedList.html deleted file mode 100644 index 9b637e4..0000000 --- a/doc/symbols/LinkedList.html +++ /dev/null @@ -1,1929 +0,0 @@ - - - - - - - JsDoc Reference - LinkedList - - - - - - - - - - - - - -
- -

- - Class LinkedList -

- - -

- - -
Defined in: DataStructures.js. - -

- - - - - - - - - - - - - - - - - -
Class Summary
Constructor AttributesConstructor Name and Description
  -
- LinkedList(args) -
-
Class for managing a linked list.
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Field Summary
Field AttributesField Name and Description
  -
- first -
-
The first node of the list.
-
  -
- last -
-
The last node of the list.
-
  -
- length -
-
The length of the list.
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Method Summary
Method AttributesMethod Name and Description
  -
addAt(item, index) -
-
Adds the item at the index position.
-
  -
allIndexesOf(item, callback) -
-
Returns all the position in which the item has been found in the list.
-
  -
clear() -
-
Removes all the items stored in the list.
-
  -
clone() -
-
Clones the list into a new list.
-
  - -
Clones the list into a new list without cloning duplicated items.
-
  -
contains(item, callback) -
-
Checks if the list contains an item that satisfy the condition represented by the - callback function. -
-
  -
count(callback) -
-
Returns the number of items that satisfy the represented by the callback function. -
-
  -
divide(index) -
-
Divides the list at the index position.
-
  -
execute(callback) -
-
Executes the callback function for each item of the stack.
-
  -
filter(callback) -
-
Returns the items that satisfy the condition determined by the callback.
-
  -
fromArray(array) -
-
Builds the list from the array.
-
  -
getItem(index) -
-
Returns the item at the position index.
-
  - -
Returns the iterator relative to the aggregate.
-
  - -
Returns the length of the list.
-
  -
getNode(index) -
-
Returns the node at the position index.
-
  -
indexOf(item, callback) -
-
Returns the first position of the item in the list.
-
  -
isEmpty() -
-
Checks if the list is empty.
-
  -
join(list) -
-
Joins the list at the end of this list.
-
  -
lastIndexOf(item, callback) -
-
Returns the last position of the item in the list.
-
  -
modifyAt(index, item) -
-
Changes the item stored in the index position.
-
  -
multiPopBack(times) -
-
Removes the last times items of the list.
-
  -
multiPopFront(times) -
-
Removes the first times items of the list.
-
  -
peek() -
-
Returns the first item of the list without remove it.
-
  -
popBack() -
-
Removes the last item of the list.
-
  - -
Removes the first item of the list.
-
  -
pushBack(item) -
-
Adds an item at the tail of the list.
-
  -
pushFront(item) -
-
Adds an item at the head of the list.
-
  -
remove(item, callback) -
-
Removes the item from the list.
-
  -
removeAll(item, callback) -
-
Removes all the item from the list.
-
  -
removeAt(index) -
-
Removes the item at the index position.
-
  -
removeSegment(from, to) -
-
Removes all the items stored from the from position to the to position.
-
  -
split(size) -
-
Splits the list into lists of desired size.
-
  -
toArray() -
-
Transforms the list into an array.
-
- - - - - - - -
- -
- Class Detail -
- -
- LinkedList(args) -
- -
- Class for managing a linked list. - -
- - -
-
Parameters:
- -
- {...*} args - Optional -
-
The items for initializing the list.
- -
- - -
- - - - -
- Field Detail -
- - - -
- - - first - -
-
- The first node of the list. - - -
- - -
- - - -
- - - last - -
-
- The last node of the list. - - -
- - -
- - - -
- - - length - -
-
- The length of the list. - - -
- - - - -
- Method Detail -
- - - -
- - {void} - addAt(item, index) - -
-
- Adds the item at the index position. - - -
- - -
-
Parameters:
- -
- item - -
-
{*} The item to add.
- -
- index - -
-
{number} The position where to add the item. If index is negative, the item won't be added.
- -
- - -
-
Returns:
- -
{void}
- -
- - -
- - - -
- - {Array} - allIndexesOf(item, callback) - -
-
- Returns all the position in which the item has been found in the list. - - -
- - -
-
Parameters:
- -
- item - -
-
{*} The item to search.
- -
- callback - Optional, Default: function(item){return(it===item);} -
-
The condition to satisfy. The callback must accept the current item to check.
- -
- - -
-
Returns:
- -
{Array} The positions in which the item has been found.
- -
- - -
- - - -
- - {void} - clear() - -
-
- Removes all the items stored in the list. - - -
- - -
-
Returns:
- -
{void}
- -
- - -
- - - -
- - {LinkedList} - clone() - -
-
- Clones the list into a new list. - - -
- - -
-
Returns:
- -
{LinkedList} The list cloned from - this list. -
- -
- - -
- - - -
- - {LinkedList} - cloneDistinct() - -
-
- Clones the list into a new list without cloning duplicated items. - - -
- - -
-
Returns:
- -
{LinkedList} The list cloned from - this list. -
- -
- - -
- - - -
- - {boolean} - contains(item, callback) - -
-
- Checks if the list contains an item that satisfy the condition represented by the callback function. - - -
- - -
-
Parameters:
- -
- item - -
-
{*} The item to find.
- -
- callback - Optional, Default: function(item){return(it===item);} -
-
The condition to satisfy. The callback must accept the current item to check.
- -
- - -
-
Returns:
- -
{boolean} True if the list contains the item that satisfy the condition, - false otherwise. -
- -
- - -
- - - -
- - {number} - count(callback) - -
-
- Returns the number of items that satisfy the represented by the callback function. - - -
- - -
-
Parameters:
- -
- callback - -
-
{function} The condition to satisfy.
- -
- - -
-
Returns:
- -
{number} The number of items that satisfy the condition.
- -
- - -
- - - -
- - {LinkedList} - divide(index) - -
-
- Divides the list at the index position. The node at the index position is the first new node of the list. - - -
- - -
-
Parameters:
- -
- index - -
-
{number} The position where to divide the list.
- -
- - -
-
Returns:
- -
{LinkedList} The list formed by - the nodes from the index position then. If the index is out of bound, the list will be empty. -
- -
- - -
- - - -
- - {void} - execute(callback) - -
-
- Executes the callback function for each item of the stack. - This method modifies the list so if you don't need to modify it you must return the same item of the array. - - -
- - -
-
Parameters:
- -
- callback - -
-
{function} The function to execute for each item. The function must accept the current item on which execute the - function. -
- -
- - -
-
Returns:
- -
{void}
- -
- - -
- - - -
- - {Array<*>} - filter(callback) - -
-
- Returns the items that satisfy the condition determined by the callback. - - -
- - -
-
Parameters:
- -
- callback - -
-
{function} The function that implements the condition.
- -
- - -
-
Returns:
- -
{Array<*>} The array that contains the items that satisfy the condition. -
- -
- - -
- - - -
- - {void} - fromArray(array) - -
-
- Builds the list from the array. - - -
- - -
-
Parameters:
- -
- array - -
-
{Array<*>} The array from which build the list.
- -
- - -
-
Returns:
- -
{void}
- -
- - -
- - - -
- - {*} - getItem(index) - -
-
- Returns the item at the position index. - - -
- - -
-
Parameters:
- -
- index - -
-
{number} The position of the item.
- -
- - -
-
Returns:
- -
{*} The item stored at the position index. It's undefined if index isn't in - the list bounds. -
- -
- - -
- - - -
- - {Iterator} - getIterator() - -
-
- Returns the iterator relative to the aggregate. - - -
- - -
-
Returns:
- -
{Iterator} The iterator.
- -
- - -
- - - -
- - {Number} - getLength() - -
-
- Returns the length of the list. - - -
- - -
-
Returns:
- -
{Number} The length of the list.
- -
- - -
- - - -
- - {LLNode} - getNode(index) - -
-
- Returns the node at the position index. - - -
- - -
-
Parameters:
- -
- index - -
-
{number} The position of the node.
- -
- - -
-
Returns:
- -
{LLNode} The node stored at the position index. It's undefined if index - isn't in the list bounds. -
- -
- - -
- - - -
- - {number} - indexOf(item, callback) - -
-
- Returns the first position of the item in the list. - - -
- - -
-
Parameters:
- -
- item - -
-
{*} The item to search.
- -
- callback - Optional, Default: function(item){return(it===item);} -
-
The condition to satisfy. The callback must accept the current item to check.
- -
- - -
-
Returns:
- -
{number} The first position of the item.
- -
- - -
- - - -
- - {boolean} - isEmpty() - -
-
- Checks if the list is empty. - - -
- - -
-
Returns:
- -
{boolean} True if the list is empty, false otherwise.
- -
- - -
- - - -
- - {void} - join(list) - -
-
- Joins the list at the end of this list. - - -
- - -
-
Parameters:
- -
- list - -
-
{LinkedList} The list to join.
- -
- - -
-
Returns:
- -
{void}
- -
- - -
- - - -
- - {number} - lastIndexOf(item, callback) - -
-
- Returns the last position of the item in the list. - - -
- - -
-
Parameters:
- -
- item - -
-
{*} The item to search.
- -
- callback - Optional, Default: function(item){return(it===item);} -
-
The condition to satisfy. The callback must accept the current item to check.
- -
- - -
-
Returns:
- -
{number} The last position of the item.
- -
- - -
- - - -
- - {void} - modifyAt(index, item) - -
-
- Changes the item stored in the index position. If the index is out of bound, the node won't be updated. - - -
- - -
-
Parameters:
- -
- index - -
-
{number} The position of the node to modify.
- -
- item - -
-
{*} The new item stored in the node.
- -
- - -
-
Returns:
- -
{void}
- -
- - -
- - - -
- - {*} - multiPopBack(times) - -
-
- Removes the last times items of the list. - - -
- - -
-
Parameters:
- -
- times - -
-
{number} The number of times to repeat the popBack method.
- -
- - -
-
Returns:
- -
{*} The items removed.
- -
- - -
- - - -
- - {*} - multiPopFront(times) - -
-
- Removes the first times items of the list. - - -
- - -
-
Parameters:
- -
- times - -
-
{number} The number of times to repeat the popFront method.
- -
- - -
-
Returns:
- -
{*} The item removed. It's undefined if the list is empty.
- -
- - -
- - - -
- - {*} - peek() - -
-
- Returns the first item of the list without remove it. - - -
- - -
-
Returns:
- -
{*} The item at the top of the list. It's undefined if the list is empty. -
- -
- - -
- - - -
- - {*} - popBack() - -
-
- Removes the last item of the list. - - -
- - -
-
Returns:
- -
{*} The item removed. It's undefined if the list is empty.
- -
- - -
- - - -
- - {*} - popFront() - -
-
- Removes the first item of the list. - - -
- - -
-
Returns:
- -
{*} The item removed. It's undefined if the list is empty.
- -
- - -
- - - -
- - {void} - pushBack(item) - -
-
- Adds an item at the tail of the list. - - -
- - -
-
Parameters:
- -
- item - -
-
{*} The item to add.
- -
- - -
-
Returns:
- -
{void}
- -
- - -
- - - -
- - {void} - pushFront(item) - -
-
- Adds an item at the head of the list. - - -
- - -
-
Parameters:
- -
- item - -
-
{*} The item to add.
- -
- - -
-
Returns:
- -
{void}
- -
- - -
- - - -
- - {void} - remove(item, callback) - -
-
- Removes the item from the list. - - -
- - -
-
Parameters:
- -
- item - -
-
{*} The item to remove.
- -
- callback - Optional, Default: function(item){return(it===item);} -
-
The condition to satisfy. The callback must accept the current item to check.
- -
- - -
-
Returns:
- -
{void}
- -
- - -
- - - -
- - {void} - removeAll(item, callback) - -
-
- Removes all the item from the list. - - -
- - -
-
Parameters:
- -
- item - -
-
{*} The item to remove.
- -
- callback - Optional, Default: function(item){return(it===item);} -
-
The condition to satisfy. The callback must accept the current item to check.
- -
- - -
-
Returns:
- -
{void}
- -
- - -
- - - -
- - {*} - removeAt(index) - -
-
- Removes the item at the index position. - - -
- - -
-
Parameters:
- -
- index - -
-
{number} The position of the item to remove.
- -
- - -
-
Returns:
- -
{*} The item stored at the position index. It's undefined if the index is - out of bounds. -
- -
- - -
- - - -
- - {Array<*>} - removeSegment(from, to) - -
-
- Removes all the items stored from the from position to the to position. - If from > to, the method will remove all the items up to the end. - - -
- - -
-
Parameters:
- -
- from - -
-
{number} The position where start to remove the items. The from position is included.
- -
- to - -
-
{number} The position where stop to remove the items. The to position is included.
- -
- - -
-
Returns:
- -
{Array<*>} The items removed.
- -
- - -
- - - -
- - {Array} - split(size) - -
-
- Splits the list into lists of desired size. - - -
- - -
-
Parameters:
- -
- size - -
-
{number} The size of the lists.
- -
- - -
-
Returns:
- -
{Array} The lists created by splitting the list.
- -
- - -
- - - -
- - {Array<*>} - toArray() - -
-
- Transforms the list into an array. - - -
- - -
-
Returns:
- -
{Array<*>} The array built.
- -
- - - - - -
-
- - - -
- - Documentation generated by JsDoc Toolkit 2.4.0 - on Wed Apr 23 2014 22:40:59 GMT+0200 (CEST) -
- - diff --git a/doc/symbols/LinkedListIterator.html b/doc/symbols/LinkedListIterator.html deleted file mode 100644 index 42db394..0000000 --- a/doc/symbols/LinkedListIterator.html +++ /dev/null @@ -1,670 +0,0 @@ - - - - - - - JsDoc Reference - LinkedListIterator - - - - - - - - - - - - - -
- -

- - Class LinkedListIterator -

- - -

- - -
Defined in: DataStructures.js. - -

- - - - - - - - - - - - - - - - - -
Class Summary
Constructor AttributesConstructor Name and Description
  -
- LinkedListIterator(aggregate) -
-
Class that implements the iterator for a linked list.
-
- - - - - - - - - - - - - - - - - - - - - - - - - - -
Field Summary
Field AttributesField Name and Description
  -
- aggregate -
-
The aggregate relates to this iterator.
-
  -
- pointer -
-
The pointer to the position.
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Method Summary
Method AttributesMethod Name and Description
  -
first() -
-
Moves the iterator to the first position of the aggregate.
-
  -
getItem() -
-
Returns the item stored at the position pointed by the iterator.
-
  -
getNode() -
-
Returns the node stored at the position pointed by the iterator.
-
  -
isDone() -
-
Checks if the iterator is out of the bounds of the aggregate.
-
  -
last() -
-
Moves the iterator to the last position of the aggregate.
-
  -
next() -
-
Moves the iterator to the next item.
-
  - -
Moves the iterator to the previous item.
-
- - - - - - - -
- -
- Class Detail -
- -
- LinkedListIterator(aggregate) -
- -
- Class that implements the iterator for a linked list. - -
- - -
-
Parameters:
- -
- aggregate - -
-
{LinkedList} The aggregate to scan.
- -
- - -
- - - - -
- Field Detail -
- - - -
- - - aggregate - -
-
- The aggregate relates to this iterator. - - -
- - -
- - - -
- - - pointer - -
-
- The pointer to the position. - - -
- - - - -
- Method Detail -
- - - -
- - {void} - first() - -
-
- Moves the iterator to the first position of the aggregate. - - -
- - -
-
Returns:
- -
{void}
- -
- - -
- - - -
- - {*} - getItem() - -
-
- Returns the item stored at the position pointed by the iterator. - - -
- - -
-
Returns:
- -
{*} The item stored or undefined if it's out of the bounds.
- -
- - -
- - - -
- - {Node|null} - getNode() - -
-
- Returns the node stored at the position pointed by the iterator. - - -
- - -
-
Returns:
- -
{Node|null} The node stored or null if it's out of the bounds.
- -
- - -
- - - -
- - {boolean} - isDone() - -
-
- Checks if the iterator is out of the bounds of the aggregate. - - -
- - -
-
Returns:
- -
{boolean} It return true if the iterator is out of the bounds of the - aggregate, otherwise false. -
- -
- - -
- - - -
- - {void} - last() - -
-
- Moves the iterator to the last position of the aggregate. - - -
- - -
-
Returns:
- -
{void}
- -
- - -
- - - -
- - {void} - next() - -
-
- Moves the iterator to the next item. - - -
- - -
-
Returns:
- -
{void}
- -
- - -
- - - -
- - {void} - previous() - -
-
- Moves the iterator to the previous item. - - -
- - -
-
Returns:
- -
{void}
- -
- - - - - -
-
- - - -
- - Documentation generated by JsDoc Toolkit 2.4.0 - on Wed Apr 23 2014 22:40:59 GMT+0200 (CEST) -
- - diff --git a/doc/symbols/PriorityQueue.html b/doc/symbols/PriorityQueue.html deleted file mode 100644 index 31151d2..0000000 --- a/doc/symbols/PriorityQueue.html +++ /dev/null @@ -1,1232 +0,0 @@ - - - - - - - JsDoc Reference - PriorityQueue - - - - - - - - - - - - - -
- -

- - Class PriorityQueue -

- - -

- - -
Defined in: DataStructures.js. - -

- - - - - - - - - - - - - - - - - -
Class Summary
Constructor AttributesConstructor Name and Description
  - -
Class for managing a priority queue.
-
- - - - - - - - - - - - - - - - - - - - - - - - - - -
Field Summary
Field AttributesField Name and Description
  -
- items -
-
The list of the items in the queue.
-
  -
- length -
-
The length of the queue.
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Method Summary
Method AttributesMethod Name and Description
  -
changePriority(index, - newPriority) -
-
Changes the priority of the item at the position index.
-
  -
clear() -
-
Removes all the items stored in the queue.
-
  -
clone() -
-
Clones the queue into a new queue.
-
  - -
Clones the queue into a new queue without cloning duplicated items.
-
  -
containsPriority(priority, - callback) -
-
Checks if the queue contains a priority that satisfy the condition represented by - the callback function. -
-
  -
dequeue() -
-
Removes the item at the head of the queue.
-
  -
enqueue(priority, item) -
-
Adds the item at the tail of the queue.
-
  -
execute(callback) -
-
Executes the callback function for each item of the queue.
-
  -
filter(callback) -
-
Returns the items that satisfy the condition determined by the callback.
-
  -
getItem(index) -
-
Returns the item at the position index.
-
  -
getItems(priority) -
-
Returns the items relatives to the priority.
-
  - -
Returns the iterator relative to the aggregate.
-
  - -
Returns the length of the queue.
-
  -
isEmpty() -
-
Checks if the queue is empty.
-
  -
multiDequeue(times) -
-
Removes the items at the head of the queue.
-
  -
multiEnqueue(priority, - items) -
-
Adds the items with the same priority at the tail of the queue.
-
  -
peek() -
-
Returns the first item in the queue.
-
  -
remove(index, length) -
-
Removes the first length items from the position index.
-
  -
toQueue() -
-
Returns the queue created by the priority queue with the items in the same order - but without the priority. -
-
- - - - - - - -
- -
- Class Detail -
- -
- PriorityQueue() -
- -
- Class for managing a priority queue. - -
- - -
- - - - -
- Field Detail -
- - - -
- - - items - -
-
- The list of the items in the queue. - - -
- - -
- - - -
- - - length - -
-
- The length of the queue. - - -
- - - - -
- Method Detail -
- - - -
- - {void} - changePriority(index, newPriority) - -
-
- Changes the priority of the item at the position index. - - -
- - -
-
Parameters:
- -
- index - -
-
{number} The position of the item of which increase the priority.
- -
- newPriority - -
-
{number} The new priority.
- -
- - -
-
Returns:
- -
{void}
- -
- - -
- - - -
- - {void} - clear() - -
-
- Removes all the items stored in the queue. - - -
- - -
-
Returns:
- -
{void}
- -
- - -
- - - -
- - {PriorityQueue} - clone() - -
-
- Clones the queue into a new queue. - - -
- - -
-
Returns:
- -
{PriorityQueue} The queue - cloned from this queue. -
- -
- - -
- - - -
- - {PriorityQueue} - cloneDistinct() - -
-
- Clones the queue into a new queue without cloning duplicated items. - - -
- - -
-
Returns:
- -
{PriorityQueue} The queue - cloned from this queue. -
- -
- - -
- - - -
- - {boolean} - containsPriority(priority, callback) - -
-
- Checks if the queue contains a priority that satisfy the condition represented by the callback function. - - -
- - -
-
Parameters:
- -
- priority - -
-
{number} The priority to find.
- -
- callback - Optional, Default: function(p){return(p===priority);} -
-
The condition to satisfy. The callback must accept the current priority to check.
- -
- - -
-
Returns:
- -
{boolean} True if the queue contains the priority that satisfy the - condition, false otherwise. -
- -
- - -
- - - -
- - {*} - dequeue() - -
-
- Removes the item at the head of the queue. - - -
- - -
-
Returns:
- -
{*} The item at the head of the queue. It's undefined if the queue is - empty. -
- -
- - -
- - - -
- - {void} - enqueue(priority, item) - -
-
- Adds the item at the tail of the queue. - - -
- - -
-
Parameters:
- -
- priority - -
-
{number} The priority of the item.
- -
- item - -
-
{*} The item to add.
- -
- - -
-
Returns:
- -
{void}
- -
- - -
- - - -
- - {void} - execute(callback) - -
-
- Executes the callback function for each item of the queue. - This method modifies the queue so if you don't need to modify it you must return the same item of the array. - - -
- - -
-
Parameters:
- -
- callback - -
-
{function} The function to execute for each item. The function must accept the current item on which execute the - function. -
- -
- - -
-
Returns:
- -
{void}
- -
- - -
- - - -
- - {Array<*>} - filter(callback) - -
-
- Returns the items that satisfy the condition determined by the callback. - - -
- - -
-
Parameters:
- -
- callback - -
-
{function} The function that implements the condition.
- -
- - -
-
Returns:
- -
{Array<*>} The array that contains the items that satisfy the condition. -
- -
- - -
- - - -
- - {*} - getItem(index) - -
-
- Returns the item at the position index. - - -
- - -
-
Parameters:
- -
- index - -
-
{number} The index of the item.
- -
- - -
-
Returns:
- -
{*} The item found. It's undefined if the position index is out of bounds. -
- -
- - -
- - - -
- - {Array<*>} - getItems(priority) - -
-
- Returns the items relatives to the priority. - - -
- - -
-
Parameters:
- -
- priority - -
-
{number} The priority of the items.
- -
- - -
-
Returns:
- -
{Array<*>} The items found.
- -
- - -
- - - -
- - {Iterator} - getIterator() - -
-
- Returns the iterator relative to the aggregate. - - -
- - -
-
Returns:
- -
{Iterator} The iterator.
- -
- - -
- - - -
- - {number} - getLength() - -
-
- Returns the length of the queue. - - -
- - -
-
Returns:
- -
{number} The length of the queue.
- -
- - -
- - - -
- - {boolean} - isEmpty() - -
-
- Checks if the queue is empty. - - -
- - -
-
Returns:
- -
{boolean} True if the queue is empty, false otherwise.
- -
- - -
- - - -
- - {Array<*>} - multiDequeue(times) - -
-
- Removes the items at the head of the queue. - - -
- - -
-
Parameters:
- -
- times - -
-
{number} The number of times to repeat the dequeue method.
- -
- - -
-
Returns:
- -
{Array<*>} The items at the head of the queue.
- -
- - -
- - - -
- - {void} - multiEnqueue(priority, items) - -
-
- Adds the items with the same priority at the tail of the queue. - - -
- - -
-
Parameters:
- -
- priority - -
-
{number} The priority of the items.
- -
- items - -
-
{Array<*>} The items to add.
- -
- - -
-
Returns:
- -
{void}
- -
- - -
- - - -
- - {*} - peek() - -
-
- Returns the first item in the queue. The item is not removed. - - -
- - -
-
Returns:
- -
{*} The first item. It's undefined if the queue is empty.
- -
- - -
- - - -
- - {void} - remove(index, length) - -
-
- Removes the first length items from the position index. - - -
- - -
-
Parameters:
- -
- index - -
-
{number} The position where to start to remove the items.
- -
- length - Optional, Default: 1 -
-
{number} The number of items to remove.
- -
- - -
-
Returns:
- -
{void}
- -
- - -
- - - -
- - {Queue} - toQueue() - -
-
- Returns the queue created by the priority queue with the items in the same order but without the priority. - - -
- - -
-
Returns:
- -
{Queue} The queue created.
- -
- - - - - -
-
- - - -
- - Documentation generated by JsDoc Toolkit 2.4.0 - on Wed Apr 23 2014 22:40:59 GMT+0200 (CEST) -
- - diff --git a/doc/symbols/PriorityQueueIterator.html b/doc/symbols/PriorityQueueIterator.html deleted file mode 100644 index a05d2c8..0000000 --- a/doc/symbols/PriorityQueueIterator.html +++ /dev/null @@ -1,663 +0,0 @@ - - - - - - - JsDoc Reference - PriorityQueueIterator - - - - - - - - - - - - - -
- -

- - Class PriorityQueueIterator -

- - -

- - -
Defined in: DataStructures.js. - -

- - - - - - - - - - - - - - - - - -
Class Summary
Constructor AttributesConstructor Name and Description
  -
- PriorityQueueIterator(aggregate) -
-
Class that implements the iterator for a priority queue.
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Field Summary
Field AttributesField Name and Description
  -
- aggregate -
-
The aggregate relates to this iterator.
-
  - -
The pointer to the position of the node.
-
  - -
The pointer to the position in the node.
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Method Summary
Method AttributesMethod Name and Description
  -
first() -
-
Moves the iterator to the first position of the aggregate.
-
  -
getItem() -
-
Returns the item stored at the position pointed by the iterator.
-
  -
isDone() -
-
Checks if the iterator is out of the bounds of the aggregate.
-
  -
last() -
-
Moves the iterator to the last position of the aggregate.
-
  -
next() -
-
Moves the iterator to the next item.
-
  - -
Moves the iterator to the previous item.
-
- - - - - - - -
- -
- Class Detail -
- -
- PriorityQueueIterator(aggregate) -
- -
- Class that implements the iterator for a priority queue. - -
- - -
-
Parameters:
- -
- aggregate - -
-
{PriorityQueue} The aggregate to scan.
- -
- - -
- - - - -
- Field Detail -
- - - -
- - - aggregate - -
-
- The aggregate relates to this iterator. - - -
- - -
- - - -
- - - pointerNode - -
-
- The pointer to the position of the node. - - -
- - -
- - - -
- - - pointerPosition - -
-
- The pointer to the position in the node. - - -
- - - - -
- Method Detail -
- - - -
- - {void} - first() - -
-
- Moves the iterator to the first position of the aggregate. - - -
- - -
-
Returns:
- -
{void}
- -
- - -
- - - -
- - {*} - getItem() - -
-
- Returns the item stored at the position pointed by the iterator. - - -
- - -
-
Returns:
- -
{*} The item stored or undefined if it's out of the bounds.
- -
- - -
- - - -
- - {boolean} - isDone() - -
-
- Checks if the iterator is out of the bounds of the aggregate. - - -
- - -
-
Returns:
- -
{boolean} It return true if the iterator is out of the bounds of the - aggregate, otherwise false. -
- -
- - -
- - - -
- - {void} - last() - -
-
- Moves the iterator to the last position of the aggregate. - - -
- - -
-
Returns:
- -
{void}
- -
- - -
- - - -
- - {void} - next() - -
-
- Moves the iterator to the next item. - - -
- - -
-
Returns:
- -
{void}
- -
- - -
- - - -
- - {void} - previous() - -
-
- Moves the iterator to the previous item. - - -
- - -
-
Returns:
- -
{void}
- -
- - - - - -
-
- - - -
- - Documentation generated by JsDoc Toolkit 2.4.0 - on Wed Apr 23 2014 22:40:59 GMT+0200 (CEST) -
- - diff --git a/doc/symbols/Queue.html b/doc/symbols/Queue.html deleted file mode 100644 index eab245e..0000000 --- a/doc/symbols/Queue.html +++ /dev/null @@ -1,1224 +0,0 @@ - - - - - - - JsDoc Reference - Queue - - - - - - - - - - - - - -
- -

- - Class Queue -

- - -

- - -
Defined in: DataStructures.js. - -

- - - - - - - - - - - - - - - - - -
Class Summary
Constructor AttributesConstructor Name and Description
  -
- Queue(args) -
-
Class for managing a queue.
-
- - - - - - - - - - - - - - - - - - - - - -
Field Summary
Field AttributesField Name and Description
  -
- items -
-
The list of the items in the queue.
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Method Summary
Method AttributesMethod Name and Description
  -
allIndexesOf(item, callback) -
-
Returns all the position in which the item has been found in the queue.
-
  -
clear() -
-
Removes all the items stored in the queue.
-
  -
clone() -
-
Clones the queue into a new queue.
-
  - -
Clones the queue into a new queue without cloning duplicated items.
-
  -
contains(item, callback) -
-
Checks if the queue contains an item that satisfy the condition represented by the - callback function. -
-
  -
dequeue() -
-
Removes the item at the head of the queue.
-
  -
enqueue(item) -
-
Adds the item at the tail of the queue.
-
  -
execute(callback) -
-
Executes the callback function for each item of the queue.
-
  -
filter(callback) -
-
Returns the items that satisfy the condition determined by the callback.
-
  -
getItem(index) -
-
Returns the item at the position index.
-
  - -
Returns the iterator relative to the aggregate.
-
  - -
Returns the length of the queue.
-
  -
indexOf(item, callback) -
-
Returns the first position of the item in the queue.
-
  -
isEmpty() -
-
Checks if the queue is empty.
-
  -
lastIndexOf(item, callback) -
-
Returns the last position of the item in the queue.
-
  -
multiDequeue(times) -
-
Removes the items at the head of the queue.
-
  -
multiEnqueue(items) -
-
Adds the items at the tail of the queue.
-
  -
peek() -
-
Returns the first item in the queue.
-
  -
remove(index, length) -
-
Removes the first length items from the position index.
-
- - - - - - - -
- -
- Class Detail -
- -
- Queue(args) -
- -
- Class for managing a queue. - -
- - -
-
Parameters:
- -
- {...*} args - Optional -
-
The items for initializing the queue.
- -
- - -
- - - - -
- Field Detail -
- - - -
- - - items - -
-
- The list of the items in the queue. - - -
- - - - -
- Method Detail -
- - - -
- - {Array} - allIndexesOf(item, callback) - -
-
- Returns all the position in which the item has been found in the queue. - - -
- - -
-
Parameters:
- -
- item - -
-
{*} The item to search.
- -
- callback - Optional, Default: function(item){return(it===item);} -
-
The condition to satisfy. The callback must accept the current item to check.
- -
- - -
-
Returns:
- -
{Array} The positions in which the item has been found.
- -
- - -
- - - -
- - {void} - clear() - -
-
- Removes all the items stored in the queue. - - -
- - -
-
Returns:
- -
{void}
- -
- - -
- - - -
- - {Queue} - clone() - -
-
- Clones the queue into a new queue. - - -
- - -
-
Returns:
- -
{Queue} The queue cloned from this - queue. -
- -
- - -
- - - -
- - {Queue} - cloneDistinct() - -
-
- Clones the queue into a new queue without cloning duplicated items. - - -
- - -
-
Returns:
- -
{Queue} The queue cloned from this - queue. -
- -
- - -
- - - -
- - {boolean} - contains(item, callback) - -
-
- Checks if the queue contains an item that satisfy the condition represented by the callback function. - - -
- - -
-
Parameters:
- -
- item - -
-
{*} The item to find.
- -
- callback - Optional, Default: function(item){return(it===item);} -
-
The condition to satisfy. The callback must accept the current item to check.
- -
- - -
-
Returns:
- -
{boolean} True if the queue contains the item that satisfy the condition, - false otherwise. -
- -
- - -
- - - -
- - {*} - dequeue() - -
-
- Removes the item at the head of the queue. - - -
- - -
-
Returns:
- -
{*} The item at the head of the queue. It's undefined if the queue is - empty. -
- -
- - -
- - - -
- - {void} - enqueue(item) - -
-
- Adds the item at the tail of the queue. - - -
- - -
-
Parameters:
- -
- item - -
-
{*} The item to add.
- -
- - -
-
Returns:
- -
{void}
- -
- - -
- - - -
- - {void} - execute(callback) - -
-
- Executes the callback function for each item of the queue. - This method modifies the queue so if you don't need to modify it you must return the same item of the array. - - -
- - -
-
Parameters:
- -
- callback - -
-
{function} The function to execute for each item. The function must accept the current item on which execute the - function. -
- -
- - -
-
Returns:
- -
{void}
- -
- - -
- - - -
- - {Array<*>} - filter(callback) - -
-
- Returns the items that satisfy the condition determined by the callback. - - -
- - -
-
Parameters:
- -
- callback - -
-
{function} The function that implements the condition.
- -
- - -
-
Returns:
- -
{Array<*>} The array that contains the items that satisfy the condition. -
- -
- - -
- - - -
- - {*} - getItem(index) - -
-
- Returns the item at the position index. - - -
- - -
-
Parameters:
- -
- index - -
-
{number} The position of the item.
- -
- - -
-
Returns:
- -
{*} The item at the position. It's undefined if index isn't in the queue - bounds. -
- -
- - -
- - - -
- - {Iterator} - getIterator() - -
-
- Returns the iterator relative to the aggregate. - - -
- - -
-
Returns:
- -
{Iterator} The iterator.
- -
- - -
- - - -
- - {number} - getLength() - -
-
- Returns the length of the queue. - - -
- - -
-
Returns:
- -
{number} The length of the queue.
- -
- - -
- - - -
- - {number} - indexOf(item, callback) - -
-
- Returns the first position of the item in the queue. - - -
- - -
-
Parameters:
- -
- item - -
-
{*} The item to search.
- -
- callback - Optional, Default: function(item){return(it===item);} -
-
The condition to satisfy. The callback must accept the current item to check.
- -
- - -
-
Returns:
- -
{number} The first position of the item.
- -
- - -
- - - -
- - {boolean} - isEmpty() - -
-
- Checks if the queue is empty. - - -
- - -
-
Returns:
- -
{boolean} True if the queue is empty, false otherwise.
- -
- - -
- - - -
- - {number} - lastIndexOf(item, callback) - -
-
- Returns the last position of the item in the queue. - - -
- - -
-
Parameters:
- -
- item - -
-
{*} The item to search.
- -
- callback - Optional, Default: function(item){return(it===item);} -
-
The condition to satisfy. The callback must accept the current item to check.
- -
- - -
-
Returns:
- -
{number} The last position of the item.
- -
- - -
- - - -
- - {Array<*>} - multiDequeue(times) - -
-
- Removes the items at the head of the queue. - - -
- - -
-
Parameters:
- -
- times - -
-
{number} The number of times to repeat the dequeue method.
- -
- - -
-
Returns:
- -
{Array<*>} The items at the head of the queue.
- -
- - -
- - - -
- - {void} - multiEnqueue(items) - -
-
- Adds the items at the tail of the queue. - - -
- - -
-
Parameters:
- -
- items - -
-
{Array<*>} The items to add.
- -
- - -
-
Returns:
- -
{void}
- -
- - -
- - - -
- - {*} - peek() - -
-
- Returns the first item in the queue. The item is not removed. - - -
- - -
-
Returns:
- -
{*} The first item. It's undefined if the queue is empty.
- -
- - -
- - - -
- - {void} - remove(index, length) - -
-
- Removes the first length items from the position index. - - -
- - -
-
Parameters:
- -
- index - -
-
{number} The position where to start to remove the items.
- -
- length - Optional, Default: 1 -
-
{number} The number of items to remove.
- -
- - -
-
Returns:
- -
{void}
- -
- - - - - -
-
- - - -
- - Documentation generated by JsDoc Toolkit 2.4.0 - on Wed Apr 23 2014 22:40:59 GMT+0200 (CEST) -
- - diff --git a/doc/symbols/QueueIterator.html b/doc/symbols/QueueIterator.html deleted file mode 100644 index 1c43074..0000000 --- a/doc/symbols/QueueIterator.html +++ /dev/null @@ -1,634 +0,0 @@ - - - - - - - JsDoc Reference - QueueIterator - - - - - - - - - - - - - -
- -

- - Class QueueIterator -

- - -

- - -
Defined in: DataStructures.js. - -

- - - - - - - - - - - - - - - - - -
Class Summary
Constructor AttributesConstructor Name and Description
  -
- QueueIterator(aggregate) -
-
Class that implements the iterator for a linked list.
-
- - - - - - - - - - - - - - - - - - - - - - - - - - -
Field Summary
Field AttributesField Name and Description
  -
- aggregate -
-
The aggregate relates to this iterator.
-
  -
- pointer -
-
The pointer to the position.
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Method Summary
Method AttributesMethod Name and Description
  -
first() -
-
Moves the iterator to the first position of the aggregate.
-
  -
getItem() -
-
Returns the item stored at the position pointed by the iterator.
-
  -
isDone() -
-
Checks if the iterator is out of the bounds of the aggregate.
-
  -
last() -
-
Moves the iterator to the last position of the aggregate.
-
  -
next() -
-
Moves the iterator to the next item.
-
  - -
Moves the iterator to the previous item.
-
- - - - - - - -
- -
- Class Detail -
- -
- QueueIterator(aggregate) -
- -
- Class that implements the iterator for a linked list. - -
- - -
-
Parameters:
- -
- aggregate - -
-
{Queue} The aggregate to scan.
- -
- - -
- - - - -
- Field Detail -
- - - -
- - - aggregate - -
-
- The aggregate relates to this iterator. - - -
- - -
- - - -
- - - pointer - -
-
- The pointer to the position. - - -
- - - - -
- Method Detail -
- - - -
- - {void} - first() - -
-
- Moves the iterator to the first position of the aggregate. - - -
- - -
-
Returns:
- -
{void}
- -
- - -
- - - -
- - {*} - getItem() - -
-
- Returns the item stored at the position pointed by the iterator. - - -
- - -
-
Returns:
- -
{*} The item stored or undefined if it's out of the bounds.
- -
- - -
- - - -
- - {boolean} - isDone() - -
-
- Checks if the iterator is out of the bounds of the aggregate. - - -
- - -
-
Returns:
- -
{boolean} It return true if the iterator is out of the bounds of the - aggregate, otherwise false. -
- -
- - -
- - - -
- - {void} - last() - -
-
- Moves the iterator to the last position of the aggregate. - - -
- - -
-
Returns:
- -
{void}
- -
- - -
- - - -
- - {void} - next() - -
-
- Moves the iterator to the next item. - - -
- - -
-
Returns:
- -
{void}
- -
- - -
- - - -
- - {void} - previous() - -
-
- Moves the iterator to the previous item. - - -
- - -
-
Returns:
- -
{void}
- -
- - - - - -
-
- - - -
- - Documentation generated by JsDoc Toolkit 2.4.0 - on Wed Apr 23 2014 22:40:59 GMT+0200 (CEST) -
- - diff --git a/doc/symbols/RBTree.html b/doc/symbols/RBTree.html deleted file mode 100644 index 0ec8b16..0000000 --- a/doc/symbols/RBTree.html +++ /dev/null @@ -1,1598 +0,0 @@ - - - - - - - JsDoc Reference - RBTree - - - - - - - - - - - - - -
- -

- - Class RBTree -

- - -

- - -
Defined in: DataStructures.js. - -

- - - - - - - - - - - - - - - - - -
Class Summary
Constructor AttributesConstructor Name and Description
  -
- RBTree() -
-
Class for managing a red-black tree.
-
- - - - - - - - - - - - - - - - - - - - - - - - - - -
Field Summary
Field AttributesField Name and Description
  -
- root -
-
The root of the tree.
-
  -
- size -
-
The number of items stored in the tree.
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Method Summary
Method AttributesMethod Name and Description
  -
allIndexesOf(item, callback) -
-
Returns all the position in which the item has been found in the tree.
-
  -
clear() -
-
Removes all the items stored in the tree.
-
  -
clone() -
-
Clones the queue into a new queue.
-
  - -
Clones the tree into a new tree without cloning duplicated items.
-
  -
contains(key, callback) -
-
Checks if the tree contains a key or a node that satisfy the condition represented by - the callback function. -
-
  -
deleteFixUp(node, parent) -
-
Preserves the properties of the tree after a deletion.
-
  -
deleteNode(node) -
-
Deletes the node from the tree.
-
  -
execute(callback) -
-
Executes the callback function for each item of the tree.
-
  -
filter(callback) -
-
Returns the items that satisfy the condition determined by the callback.
-
  -
fullContains(callback) -
-
Checks if the tree contains a node that satisfy the condition represented by the - callback function. -
-
  -
getItem(index) -
-
Returns the item at the position index.
-
  - -
Returns the iterator relative to the aggregate.
-
  -
getSize() -
-
Returns the size of the tree.
-
  -
indexOf(item, callback) -
-
Returns the first position of the item in the tree.
-
  -
insert(key, item) -
-
Inserts the item relatives to the key value in the tree.
-
  -
insertFixUp(node) -
-
Preserves the properties of the tree after an insert.
-
  -
isEmpty() -
-
Checks if the tree is empty.
-
  -
lastIndexOf(item, callback) -
-
Returns the last position of the item in the tree.
-
  -
leftRotate(node) -
-
Rotates the node with its right child.
-
  -
maximum(node) -
-
Gets the item relatives to the maximum key stored in the tree.
-
  -
minimum(node) -
-
Gets the item relatives to the minimum key stored in the tree.
-
  -
predecessor(node) -
-
Gets the node with the key previous to the param node key.
-
  -
rightRotate(node) -
-
Rotates the node with its left child.
-
  -
search(key, node, callback) -
-
Searches the item relatives to the key and to the nodes that satisfy the condition - represented by the callback function. -
-
  -
successor(node) -
-
Gets the node with the key next to the param node key.
-
  -
toArray() -
-
Transforms the tree into an array without preserving keys.
-
- - - - - - - -
- -
- Class Detail -
- -
- RBTree() -
- -
- Class for managing a red-black tree. - -
- - -
- - - - -
- Field Detail -
- - - -
- - - root - -
-
- The root of the tree. - - -
- - -
- - - -
- - - size - -
-
- The number of items stored in the tree. - - -
- - - - -
- Method Detail -
- - - -
- - {Array} - allIndexesOf(item, callback) - -
-
- Returns all the position in which the item has been found in the tree. - - -
- - -
-
Parameters:
- -
- item - -
-
{*} The item to search.
- -
- callback - Optional, Default: function(item){return(it===item);} -
-
The condition to satisfy. The callback must accept the current item to check.
- -
- - -
-
Returns:
- -
{Array} The positions in which the item has been found.
- -
- - -
- - - -
- - {void} - clear() - -
-
- Removes all the items stored in the tree. - - -
- - -
-
Returns:
- -
{void}
- -
- - -
- - - -
- - {RBTree} - clone() - -
-
- Clones the queue into a new queue. - - -
- - -
-
Returns:
- -
{RBTree} The tree cloned from this - queue. -
- -
- - -
- - - -
- - {RBTree} - cloneDistinct() - -
-
- Clones the tree into a new tree without cloning duplicated items. - - -
- - -
-
Returns:
- -
{RBTree} The tree cloned from this - tree. -
- -
- - -
- - - -
- - {boolean} - contains(key, callback) - -
-
- Checks if the tree contains a key or a node that satisfy the condition represented by the callback function. - This method avoid to search in branches where the key won't be found. - - -
- - -
-
Parameters:
- -
- key - -
-
{*} The key to find.
- -
- callback - Optional, Default: function(node){return(node.key===key);} -
-
The condition to satisfy. The callback must accept the current node to check.
- -
- - -
-
Returns:
- -
{boolean} True if the tree contains the key or a node that satisfy the - condition, false otherwise. -
- -
- - -
- - - -
- - {void} - deleteFixUp(node, parent) - -
-
- Preserves the properties of the tree after a deletion. - - -
- - -
-
Parameters:
- -
- node - -
-
{RBNode} The node to delete.
- -
- parent - -
-
{RBNode} The parent of the node.
- -
- - -
-
Returns:
- -
{void}
- -
- - -
- - - -
- - {void} - deleteNode(node) - -
-
- Deletes the node from the tree. - - -
- - -
-
Parameters:
- -
- node - -
-
{RBNode} The node to delete.
- -
- - -
-
Returns:
- -
{void}
- -
- - -
- - - -
- - {void} - execute(callback) - -
-
- Executes the callback function for each item of the tree. - This method modifies the tree so if you don't need to modify it you must return the same item stored. - - -
- - -
-
Parameters:
- -
- callback - -
-
{function} The function to execute for each item. The function must accept the current item on which execute the - function. -
- -
- - -
-
Returns:
- -
{void}
- -
- - -
- - - -
- - {Array<*>} - filter(callback) - -
-
- Returns the items that satisfy the condition determined by the callback. - - -
- - -
-
Parameters:
- -
- callback - -
-
{function} The function that implements the condition.
- -
- - -
-
Returns:
- -
{Array<*>} The array that contains the items that satisfy the condition. -
- -
- - -
- - - -
- - {boolean} - fullContains(callback) - -
-
- Checks if the tree contains a node that satisfy the condition represented by the callback function. - This method check all the tree avoiding the binary search. - - -
- - -
-
Parameters:
- -
- callback - -
-
{function} The condition to satisfy. The callback must accept the current node to check.
- -
- - -
-
Returns:
- -
{boolean} True if the tree contains the node that satisfy the condition, - false otherwise. -
- -
- - -
- - - -
- - {*} - getItem(index) - -
-
- Returns the item at the position index. - - -
- - -
-
Parameters:
- -
- index - -
-
{number} The position of the item.
- -
- - -
-
Returns:
- -
{*} The item at the position. It's undefined if index isn't in the tree - bounds. -
- -
- - -
- - - -
- - {Iterator} - getIterator() - -
-
- Returns the iterator relative to the aggregate. - - -
- - -
-
Returns:
- -
{Iterator} The iterator.
- -
- - -
- - - -
- - {number} - getSize() - -
-
- Returns the size of the tree. - - -
- - -
-
Returns:
- -
{number} The size of the tree.
- -
- - -
- - - -
- - {number} - indexOf(item, callback) - -
-
- Returns the first position of the item in the tree. - - -
- - -
-
Parameters:
- -
- item - -
-
{*} The item to search.
- -
- callback - Optional, Default: function(item){return(it===item);} -
-
The condition to satisfy. The callback must accept the current item to check.
- -
- - -
-
Returns:
- -
{number} The first position of the item.
- -
- - -
- - - -
- - {void} - insert(key, item) - -
-
- Inserts the item relatives to the key value in the tree. - - -
- - -
-
Parameters:
- -
- key - -
-
{number} The key to store.
- -
- item - -
-
{*} The item to store.
- -
- - -
-
Returns:
- -
{void}
- -
- - -
- - - -
- - {void} - insertFixUp(node) - -
-
- Preserves the properties of the tree after an insert. - - -
- - -
-
Parameters:
- -
- node - -
-
{RBNode} The node to insert.
- -
- - -
-
Returns:
- -
{void}
- -
- - -
- - - -
- - {boolean} - isEmpty() - -
-
- Checks if the tree is empty. - - -
- - -
-
Returns:
- -
{boolean} True if the tree is empty, false otherwise.
- -
- - -
- - - -
- - {number} - lastIndexOf(item, callback) - -
-
- Returns the last position of the item in the tree. - - -
- - -
-
Parameters:
- -
- item - -
-
{*} The item to search.
- -
- callback - Optional, Default: function(item){return(it===item);} -
-
The condition to satisfy. The callback must accept the current item to check.
- -
- - -
-
Returns:
- -
{number} The last position of the item.
- -
- - -
- - - -
- - {void} - leftRotate(node) - -
-
- Rotates the node with its right child. - - -
- - -
-
Parameters:
- -
- node - -
-
{RBNode} The node to rotate.
- -
- - -
-
Returns:
- -
{void}
- -
- - -
- - - -
- - {RBNode} - maximum(node) - -
-
- Gets the item relatives to the maximum key stored in the tree. - - -
- - -
-
Parameters:
- -
- node - Optional, Default: root -
-
{Node} The node from which start the search.
- -
- - -
-
Returns:
- -
{RBNode} The node found.
- -
- - -
- - - -
- - {RBNode} - minimum(node) - -
-
- Gets the item relatives to the minimum key stored in the tree. - - -
- - -
-
Parameters:
- -
- node - Optional, Default: root -
-
{Node} The node from which start the search.
- -
- - -
-
Returns:
- -
{RBNode} The node found.
- -
- - -
- - - -
- - {RBNode} - predecessor(node) - -
-
- Gets the node with the key previous to the param node key. - - -
- - -
-
Parameters:
- -
- node - -
-
{RBNode} The node of which search the predecessor.
- -
- - -
-
Returns:
- -
{RBNode} The node found.
- -
- - -
- - - -
- - {void} - rightRotate(node) - -
-
- Rotates the node with its left child. - - -
- - -
-
Parameters:
- -
- node - -
-
{RBNode} The node to rotate.
- -
- - -
-
Returns:
- -
{void}
- -
- - -
- - - -
- - {*} - search(key, node, callback) - -
-
- Searches the item relatives to the key and to the nodes that satisfy the condition represented by the callback - function. - - -
- - -
-
Parameters:
- -
- key - -
-
{number} The key to find.
- -
- node - Optional, Default: root -
-
{RBNode} The node from which start the search.
- -
- callback - Optional, Default: function(node){return(node.key===key);} -
-
The condition to satisfy. The callback must accept the current node to check.
- -
- - -
-
Returns:
- -
{*} The item found or undefined if there isn't the key in the tree.
- -
- - -
- - - -
- - {RBNode} - successor(node) - -
-
- Gets the node with the key next to the param node key. - - -
- - -
-
Parameters:
- -
- node - -
-
{RBNode} The node of which search the successor.
- -
- - -
-
Returns:
- -
{RBNode} The node found.
- -
- - -
- - - -
- - {Array<*>} - toArray() - -
-
- Transforms the tree into an array without preserving keys. - - -
- - -
-
Returns:
- -
{Array<*>} The array that represents the tree.
- -
- - - - - -
-
- - - -
- - Documentation generated by JsDoc Toolkit 2.4.0 - on Wed Apr 23 2014 22:40:59 GMT+0200 (CEST) -
- - diff --git a/doc/symbols/RBTreeIterator.html b/doc/symbols/RBTreeIterator.html deleted file mode 100644 index 7bcbdf1..0000000 --- a/doc/symbols/RBTreeIterator.html +++ /dev/null @@ -1,669 +0,0 @@ - - - - - - - JsDoc Reference - RBTreeIterator - - - - - - - - - - - - - -
- -

- - Class RBTreeIterator -

- - -

- - -
Defined in: DataStructures.js. - -

- - - - - - - - - - - - - - - - - -
Class Summary
Constructor AttributesConstructor Name and Description
  -
- RBTreeIterator(aggregate) -
-
Class that implements the iterator for a red-black tree.
-
- - - - - - - - - - - - - - - - - - - - - - - - - - -
Field Summary
Field AttributesField Name and Description
  -
- aggregate -
-
The aggregate relates to this iterator.
-
  -
- pointer -
-
The pointer to the position.
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Method Summary
Method AttributesMethod Name and Description
  -
first() -
-
Moves the iterator to the first position of the aggregate.
-
  -
getItem() -
-
Returns the item stored at the position pointed by the iterator.
-
  -
getNode() -
-
Returns the node stored at the position pointed by the iterator.
-
  -
isDone() -
-
Checks if the iterator is out of the bounds of the aggregate.
-
  -
last() -
-
Moves the iterator to the last position of the aggregate.
-
  -
next() -
-
Moves the iterator to the next item.
-
  - -
Moves the iterator to the previous item.
-
- - - - - - - -
- -
- Class Detail -
- -
- RBTreeIterator(aggregate) -
- -
- Class that implements the iterator for a red-black tree. - -
- - -
-
Parameters:
- -
- aggregate - -
-
{RBTree} The aggregate to scan.
- -
- - -
- - - - -
- Field Detail -
- - - -
- - - aggregate - -
-
- The aggregate relates to this iterator. - - -
- - -
- - - -
- - - pointer - -
-
- The pointer to the position. - - -
- - - - -
- Method Detail -
- - - -
- - {void} - first() - -
-
- Moves the iterator to the first position of the aggregate. - - -
- - -
-
Returns:
- -
{void}
- -
- - -
- - - -
- - {Object|undefined} - getItem() - -
-
- Returns the item stored at the position pointed by the iterator. - - -
- - -
-
Returns:
- -
{Object|undefined} The item stored or undefined if it's out of the bounds. -
- -
- - -
- - - -
- - {RBNode|null} - getNode() - -
-
- Returns the node stored at the position pointed by the iterator. - - -
- - -
-
Returns:
- -
{RBNode|null} The node stored or null if it's out of the bounds.
- -
- - -
- - - -
- - {boolean} - isDone() - -
-
- Checks if the iterator is out of the bounds of the aggregate. - - -
- - -
-
Returns:
- -
{boolean} It return true if the iterator is out of the bounds of the - aggregate, otherwise false. -
- -
- - -
- - - -
- - {void} - last() - -
-
- Moves the iterator to the last position of the aggregate. - - -
- - -
-
Returns:
- -
{void}
- -
- - -
- - - -
- - {void} - next() - -
-
- Moves the iterator to the next item. - - -
- - -
-
Returns:
- -
{void}
- -
- - -
- - - -
- - {void} - previous() - -
-
- Moves the iterator to the previous item. - - -
- - -
-
Returns:
- -
{void}
- -
- - - - - -
-
- - - -
- - Documentation generated by JsDoc Toolkit 2.4.0 - on Wed Apr 23 2014 22:40:59 GMT+0200 (CEST) -
- - diff --git a/doc/symbols/RBTreeList.html b/doc/symbols/RBTreeList.html deleted file mode 100644 index 2cc5327..0000000 --- a/doc/symbols/RBTreeList.html +++ /dev/null @@ -1,1651 +0,0 @@ - - - - - - - JsDoc Reference - RBTreeList - - - - - - - - - - - - - -
- -

- - Class RBTreeList -

- - -

- - -
Defined in: DataStructures.js. - -

- - - - - - - - - - - - - - - - - -
Class Summary
Constructor AttributesConstructor Name and Description
  -
- RBTreeList() -
-
Class for managing a red-black tree where nodes are also in a list.
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Field Summary
Field AttributesField Name and Description
  -
- first -
-
The first node of the tree.
-
  -
- last -
-
The last node of the tree.
-
  -
- root -
-
The root of the tree.
-
  -
- size -
-
The size of the tree.
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Method Summary
Method AttributesMethod Name and Description
  -
allIndexesOf(item, callback) -
-
Returns all the position in which the item has been found in the tree.
-
  -
clear() -
-
Removes all the items stored in the tree.
-
  -
clone() -
-
Clones the tree into a new tree.
-
  - -
Clones the tree into a new tree without cloning duplicated items.
-
  -
contains(key, callback) -
-
Checks if the tree contains a key or a node that satisfy the condition represented by - the callback function. -
-
  -
deleteFixUp(node, parent) -
-
Preserves the properties of the tree after a deletion.
-
  -
deleteNode(node) -
-
Deletes the node from the tree.
-
  -
execute(callback) -
-
Executes the callback function for each item of the tree.
-
  -
filter(callback) -
-
Returns the items that satisfy the condition determined by the callback.
-
  -
fullContains(callback) -
-
Checks if the tree contains a node that satisfy the condition represented by the - callback function. -
-
  -
getItem(index) -
-
Returns the item at the position index.
-
  - -
Returns the iterator relative to the aggregate.
-
  -
getSize() -
-
Returns the size of the tree.
-
  -
indexOf(item, callback) -
-
Returns the first position of the item in the tree.
-
  -
insert(key, item) -
-
Inserts the item relatives to the key value in the tree.
-
  -
insertFixUp(node) -
-
Preserves the properties of the tree after an insert.
-
  -
isEmpty() -
-
Checks if the tree is empty.
-
  -
lastIndexOf(item, callback) -
-
Returns the last position of the item in the tree.
-
  -
leftRotate(node) -
-
Rotates the node with its right child.
-
  -
maximum(node) -
-
Gets the item relatives to the maximum key stored in the tree.
-
  -
minimum(node) -
-
Gets the item relatives to the minimum key stored in the tree.
-
  -
predecessor(node) -
-
Gets the node with the key previous to the param node key.
-
  -
rightRotate(node) -
-
Rotates the node with its left child.
-
  -
search(key, node, callback) -
-
Searches the item relatives to the key that satisfy the condition represented by the - callback function. -
-
  -
successor(node) -
-
Gets the node with the key next to the param node key.
-
  -
toArray() -
-
Transforms the tree into an array without preserving keys.
-
- - - - - - - -
- -
- Class Detail -
- -
- RBTreeList() -
- -
- Class for managing a red-black tree where nodes are also in a list. - -
- - -
- - - - -
- Field Detail -
- - - -
- - - first - -
-
- The first node of the tree. - - -
- - -
- - - -
- - - last - -
-
- The last node of the tree. - - -
- - -
- - - -
- - - root - -
-
- The root of the tree. - - -
- - -
- - - -
- - - size - -
-
- The size of the tree. - - -
- - - - -
- Method Detail -
- - - -
- - {Array} - allIndexesOf(item, callback) - -
-
- Returns all the position in which the item has been found in the tree. - - -
- - -
-
Parameters:
- -
- item - -
-
{*} The item to search.
- -
- callback - Optional, Default: function(item){return(it===item);} -
-
The condition to satisfy. The callback must accept the current item to check.
- -
- - -
-
Returns:
- -
{Array} The positions in which the item has been found.
- -
- - -
- - - -
- - {void} - clear() - -
-
- Removes all the items stored in the tree. - - -
- - -
-
Returns:
- -
{void}
- -
- - -
- - - -
- - {RBTreeList} - clone() - -
-
- Clones the tree into a new tree. - - -
- - -
-
Returns:
- -
{RBTreeList} The tree cloned from - this tree. -
- -
- - -
- - - -
- - {RBTreeList} - cloneDistinct() - -
-
- Clones the tree into a new tree without cloning duplicated items. - - -
- - -
-
Returns:
- -
{RBTreeList} The tree cloned from - this tree. -
- -
- - -
- - - -
- - {boolean} - contains(key, callback) - -
-
- Checks if the tree contains a key or a node that satisfy the condition represented by the callback function. - This method avoid to search in branches where the key won't be found. - - -
- - -
-
Parameters:
- -
- key - -
-
{*} The key to find.
- -
- callback - Optional, Default: function(node){return(node.key===key);} -
-
The condition to satisfy. The callback must accept the current node to check.
- -
- - -
-
Returns:
- -
{boolean} True if the tree contains the key or a node that satisfy the - condition, false otherwise. -
- -
- - -
- - - -
- - {void} - deleteFixUp(node, parent) - -
-
- Preserves the properties of the tree after a deletion. - - -
- - -
-
Parameters:
- -
- node - -
-
{RBLNode} The node to delete.
- -
- parent - -
-
{RBLNode} The parent of the node.
- -
- - -
-
Returns:
- -
{void}
- -
- - -
- - - -
- - {void} - deleteNode(node) - -
-
- Deletes the node from the tree. - - -
- - -
-
Parameters:
- -
- node - -
-
{RBLNode} The node to delete.
- -
- - -
-
Returns:
- -
{void}
- -
- - -
- - - -
- - {void} - execute(callback) - -
-
- Executes the callback function for each item of the tree. - This method modifies the tree so if you don't need to modify it you must return the same item stored. - - -
- - -
-
Parameters:
- -
- callback - -
-
{function} The function to execute for each item. The function must accept the current item on which execute the - function. -
- -
- - -
-
Returns:
- -
{void}
- -
- - -
- - - -
- - {Array<*>} - filter(callback) - -
-
- Returns the items that satisfy the condition determined by the callback. - - -
- - -
-
Parameters:
- -
- callback - -
-
{function} The function that implements the condition.
- -
- - -
-
Returns:
- -
{Array<*>} The array that contains the items that satisfy the condition. -
- -
- - -
- - - -
- - {boolean} - fullContains(callback) - -
-
- Checks if the tree contains a node that satisfy the condition represented by the callback function. - This method check all the tree avoiding the binary search. - - -
- - -
-
Parameters:
- -
- callback - -
-
{function} The condition to satisfy. The callback must accept the current node to check.
- -
- - -
-
Returns:
- -
{boolean} True if the tree contains the node that satisfy the condition, - false otherwise. -
- -
- - -
- - - -
- - {*} - getItem(index) - -
-
- Returns the item at the position index. - - -
- - -
-
Parameters:
- -
- index - -
-
{number} The position of the item.
- -
- - -
-
Returns:
- -
{*} The item at the position. It's undefined if index isn't in the tree - bounds. -
- -
- - -
- - - -
- - {Iterator} - getIterator() - -
-
- Returns the iterator relative to the aggregate. - - -
- - -
-
Returns:
- -
{Iterator} The iterator.
- -
- - -
- - - -
- - {number} - getSize() - -
-
- Returns the size of the tree. - - -
- - -
-
Returns:
- -
{number} The size of the tree.
- -
- - -
- - - -
- - {number} - indexOf(item, callback) - -
-
- Returns the first position of the item in the tree. - - -
- - -
-
Parameters:
- -
- item - -
-
{*} The item to search.
- -
- callback - Optional, Default: function(item){return(it===item);} -
-
The condition to satisfy. The callback must accept the current item to check.
- -
- - -
-
Returns:
- -
{number} The first position of the item.
- -
- - -
- - - -
- - {void} - insert(key, item) - -
-
- Inserts the item relatives to the key value in the tree. - - -
- - -
-
Parameters:
- -
- key - -
-
{number} The key to store.
- -
- item - -
-
{*} The item to store.
- -
- - -
-
Returns:
- -
{void}
- -
- - -
- - - -
- - {void} - insertFixUp(node) - -
-
- Preserves the properties of the tree after an insert. - - -
- - -
-
Parameters:
- -
- node - -
-
{RBLNode} The node to insert.
- -
- - -
-
Returns:
- -
{void}
- -
- - -
- - - -
- - {boolean} - isEmpty() - -
-
- Checks if the tree is empty. - - -
- - -
-
Returns:
- -
{boolean} True if the tree is empty, false otherwise.
- -
- - -
- - - -
- - {number} - lastIndexOf(item, callback) - -
-
- Returns the last position of the item in the tree. - - -
- - -
-
Parameters:
- -
- item - -
-
{*} The item to search.
- -
- callback - Optional, Default: function(item){return(it===item);} -
-
The condition to satisfy. The callback must accept the current item to check.
- -
- - -
-
Returns:
- -
{number} The last position of the item.
- -
- - -
- - - -
- - {void} - leftRotate(node) - -
-
- Rotates the node with its right child. - - -
- - -
-
Parameters:
- -
- node - -
-
{RBLNode} The node to rotate.
- -
- - -
-
Returns:
- -
{void}
- -
- - -
- - - -
- - {RBLNode} - maximum(node) - -
-
- Gets the item relatives to the maximum key stored in the tree. - - -
- - -
-
Parameters:
- -
- node - Optional, Default: root -
-
{Node} The node from which start the search.
- -
- - -
-
Returns:
- -
{RBLNode} The node found.
- -
- - -
- - - -
- - {RBLNode} - minimum(node) - -
-
- Gets the item relatives to the minimum key stored in the tree. - - -
- - -
-
Parameters:
- -
- node - Optional, Default: root -
-
{Node} The node from which start the search.
- -
- - -
-
Returns:
- -
{RBLNode} The node found.
- -
- - -
- - - -
- - {RBLNode} - predecessor(node) - -
-
- Gets the node with the key previous to the param node key. - - -
- - -
-
Parameters:
- -
- node - -
-
{RBLNode} The node of which search the predecessor.
- -
- - -
-
Returns:
- -
{RBLNode} The node found.
- -
- - -
- - - -
- - {void} - rightRotate(node) - -
-
- Rotates the node with its left child. - - -
- - -
-
Parameters:
- -
- node - -
-
{RBLNode} The node to rotate.
- -
- - -
-
Returns:
- -
{void}
- -
- - -
- - - -
- - {*} - search(key, node, callback) - -
-
- Searches the item relatives to the key that satisfy the condition represented by the callback function. - - -
- - -
-
Parameters:
- -
- key - -
-
{number} The key to find.
- -
- node - Optional, Default: root -
-
{RBNode} The node from which start the search.
- -
- callback - Optional, Default: function(k){return(k===key);} -
-
The condition to satisfy. The callback must accept the current key to check.
- -
- - -
-
Returns:
- -
{*} The item found or undefined if there isn't the key in the tree.
- -
- - -
- - - -
- - {RBLNode} - successor(node) - -
-
- Gets the node with the key next to the param node key. - - -
- - -
-
Parameters:
- -
- node - -
-
{RBLNode} The node of which search the successor.
- -
- - -
-
Returns:
- -
{RBLNode} The node found.
- -
- - -
- - - -
- - {Array<*>} - toArray() - -
-
- Transforms the tree into an array without preserving keys. - - -
- - -
-
Returns:
- -
{Array<*>} The array that represents the tree.
- -
- - - - - -
-
- - - -
- - Documentation generated by JsDoc Toolkit 2.4.0 - on Wed Apr 23 2014 22:40:59 GMT+0200 (CEST) -
- - diff --git a/doc/symbols/RBTreeListIterator.html b/doc/symbols/RBTreeListIterator.html deleted file mode 100644 index c1bc7f5..0000000 --- a/doc/symbols/RBTreeListIterator.html +++ /dev/null @@ -1,670 +0,0 @@ - - - - - - - JsDoc Reference - RBTreeListIterator - - - - - - - - - - - - - -
- -

- - Class RBTreeListIterator -

- - -

- - -
Defined in: DataStructures.js. - -

- - - - - - - - - - - - - - - - - -
Class Summary
Constructor AttributesConstructor Name and Description
  -
- RBTreeListIterator(aggregate) -
-
Class that implements the iterator for a red-black tree.
-
- - - - - - - - - - - - - - - - - - - - - - - - - - -
Field Summary
Field AttributesField Name and Description
  -
- aggregate -
-
The aggregate relates to this iterator.
-
  -
- pointer -
-
The pointer to the position.
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Method Summary
Method AttributesMethod Name and Description
  -
first() -
-
Moves the iterator to the first position of the aggregate.
-
  -
getItem() -
-
Returns the item stored at the position pointed by the iterator.
-
  -
getNode() -
-
Returns the node stored at the position pointed by the iterator.
-
  -
isDone() -
-
Checks if the iterator is out of the bounds of the aggregate.
-
  -
last() -
-
Moves the iterator to the last position of the aggregate.
-
  -
next() -
-
Moves the iterator to the next item.
-
  - -
Moves the iterator to the previous item.
-
- - - - - - - -
- -
- Class Detail -
- -
- RBTreeListIterator(aggregate) -
- -
- Class that implements the iterator for a red-black tree. - -
- - -
-
Parameters:
- -
- aggregate - -
-
{RBTreeList} The aggregate to scan.
- -
- - -
- - - - -
- Field Detail -
- - - -
- - - aggregate - -
-
- The aggregate relates to this iterator. - - -
- - -
- - - -
- - - pointer - -
-
- The pointer to the position. - - -
- - - - -
- Method Detail -
- - - -
- - {void} - first() - -
-
- Moves the iterator to the first position of the aggregate. - - -
- - -
-
Returns:
- -
{void}
- -
- - -
- - - -
- - {*} - getItem() - -
-
- Returns the item stored at the position pointed by the iterator. - - -
- - -
-
Returns:
- -
{*} The item stored or undefined if it's out of the bounds.
- -
- - -
- - - -
- - {RBNode|null} - getNode() - -
-
- Returns the node stored at the position pointed by the iterator. - - -
- - -
-
Returns:
- -
{RBNode|null} The node stored or null if it's out of the bounds.
- -
- - -
- - - -
- - {boolean} - isDone() - -
-
- Checks if the iterator is out of the bounds of the aggregate. - - -
- - -
-
Returns:
- -
{boolean} It return true if the iterator is out of the bounds of the - aggregate, otherwise false. -
- -
- - -
- - - -
- - {void} - last() - -
-
- Moves the iterator to the last position of the aggregate. - - -
- - -
-
Returns:
- -
{void}
- -
- - -
- - - -
- - {void} - next() - -
-
- Moves the iterator to the next item. - - -
- - -
-
Returns:
- -
{void}
- -
- - -
- - - -
- - {void} - previous() - -
-
- Moves the iterator to the previous item. - - -
- - -
-
Returns:
- -
{void}
- -
- - - - - -
-
- - - -
- - Documentation generated by JsDoc Toolkit 2.4.0 - on Wed Apr 23 2014 22:40:59 GMT+0200 (CEST) -
- - diff --git a/doc/symbols/Set.html b/doc/symbols/Set.html deleted file mode 100644 index fc233c5..0000000 --- a/doc/symbols/Set.html +++ /dev/null @@ -1,968 +0,0 @@ - - - - - - - JsDoc Reference - Set - - - - - - - - - - - - - -
- -

- - Class Set -

- - -

- - -
Defined in: DataStructures.js. - -

- - - - - - - - - - - - - - - - - -
Class Summary
Constructor AttributesConstructor Name and Description
  -
- Set() -
-
Class for managing a set.
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Field Summary
Field AttributesField Name and Description
  -
- elements -
-
The elements stored.
-
  -
- parents -
-
The parents of the set.
-
  -
- sets -
-
The subsets of this set.
-
  -
- size -
-
The size of the set.
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Method Summary
Method AttributesMethod Name and Description
  -
addSubset(set) -
-
Adds the subset.
-
  -
addSubsets(sets) -
-
Adds the subsets.
-
  - -
Returns the set that represents the cartesian product of two sets.
-
  -
clone() -
-
Clones the set into a new set.
-
  -
difference(set) -
-
Returns the set that represents the difference of two sets.
-
  - -
Returns the cardinality of the set.
-
  - -
Returns the items that are stored in the set.
-
  -
insert(element) -
-
Adds the element to the set.
-
  -
intersect(set) -
-
Returns the set that represents the intersection of two sets.
-
  -
isEmpty() -
-
Checks if the set is empty.
-
  -
multiInsert(elements) -
-
Adds the elements to the set.
-
  -
union(set) -
-
Returns the set that represents the union of two sets.
-
- - - - - - - -
- -
- Class Detail -
- -
- Set() -
- -
- Class for managing a set. - -
- - -
- - - - -
- Field Detail -
- - - -
- - - elements - -
-
- The elements stored. - - -
- - -
- - - -
- - - parents - -
-
- The parents of the set. - - -
- - -
- - - -
- - - sets - -
-
- The subsets of this set. - - -
- - -
- - - -
- - - size - -
-
- The size of the set. It's equal to his cardinality. - - -
- - - - -
- Method Detail -
- - - -
- - - addSubset(set) - -
-
- Adds the subset. - - -
- - -
-
Parameters:
- -
- set - -
-
{Set} The subset.
- -
- - -
- - - -
- - - addSubsets(sets) - -
-
- Adds the subsets. - - -
- - -
-
Parameters:
- -
- sets - -
-
{Array - } The subsets. -
- -
- - -
- - - -
- - {Set} - cartesianProduct(set) - -
-
- Returns the set that represents the cartesian product of two sets. - - -
- - -
-
Parameters:
- -
- set - -
-
{Set} The set to make the cartesian product with this.
- -
- - -
-
Returns:
- -
{Set} The set that represents the - cartesian product . -
- -
- - -
- - - -
- - {Set} - clone() - -
-
- Clones the set into a new set. - - -
- - -
-
Returns:
- -
{Set} The set cloned from this set.
- -
- - -
- - - -
- - {Set} - difference(set) - -
-
- Returns the set that represents the difference of two sets. - - -
- - -
-
Parameters:
- -
- set - -
-
{Set} The set to difference with this.
- -
- - -
-
Returns:
- -
{Set} The set that represents the - difference. -
- -
- - -
- - - -
- - {number} - getCardinality() - -
-
- Returns the cardinality of the set. - - -
- - -
-
Returns:
- -
{number} The cardinality of the set.
- -
- - -
- - - -
- - {Array} - getItems() - -
-
- Returns the items that are stored in the set. - - -
- - -
-
Returns:
- -
{Array} The items stored.
- -
- - -
- - - -
- - {void} - insert(element) - -
-
- Adds the element to the set. - - -
- - -
-
Parameters:
- -
- element - -
-
{Element} The element to add.
- -
- - -
-
Returns:
- -
{void}
- -
- - -
- - - -
- - {Set} - intersect(set) - -
-
- Returns the set that represents the intersection of two sets. - - -
- - -
-
Parameters:
- -
- set - -
-
{Set} The set to intersect with this.
- -
- - -
-
Returns:
- -
{Set} The set that represents the - intersection. -
- -
- - -
- - - -
- - {boolean} - isEmpty() - -
-
- Checks if the set is empty. - - -
- - -
-
Returns:
- -
{boolean} True if the set is empty, false otherwise.
- -
- - -
- - - -
- - {void} - multiInsert(elements) - -
-
- Adds the elements to the set. - - -
- - -
-
Parameters:
- -
- elements - -
-
{Array - } The elements to add. -
- -
- - -
-
Returns:
- -
{void}
- -
- - -
- - - -
- - {Set} - union(set) - -
-
- Returns the set that represents the union of two sets. - - -
- - -
-
Parameters:
- -
- set - -
-
{Set} The set with make the union.
- -
- - -
-
Returns:
- -
{Set} The set that represents the union. -
- -
- - - - - -
-
- - - -
- - Documentation generated by JsDoc Toolkit 2.4.0 - on Wed Apr 23 2014 22:40:59 GMT+0200 (CEST) -
- - diff --git a/doc/symbols/Stack.html b/doc/symbols/Stack.html deleted file mode 100644 index 9024dc6..0000000 --- a/doc/symbols/Stack.html +++ /dev/null @@ -1,1166 +0,0 @@ - - - - - - - JsDoc Reference - Stack - - - - - - - - - - - - - -
- -

- - Class Stack -

- - -

- - -
Defined in: DataStructures.js. - -

- - - - - - - - - - - - - - - - - -
Class Summary
Constructor AttributesConstructor Name and Description
  -
- Stack(args) -
-
Class for managing a stack.
-
- - - - - - - - - - - - - - - - - - - - - -
Field Summary
Field AttributesField Name and Description
  -
- items -
-
The list of the items in the stack.
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Method Summary
Method AttributesMethod Name and Description
  -
allIndexesOf(item, callback) -
-
Returns all the position in which the item has been found in the stack.
-
  -
clear() -
-
Removes all the items stored in the stack.
-
  -
clone() -
-
Clones the stack into a new stack.
-
  - -
Clones the stack into a new stack without cloning duplicated items.
-
  -
contains(item, callback) -
-
Checks if the stack contains an item that satisfy the condition represented by the - callback function. -
-
  -
execute(callback) -
-
Executes the callback function for each item of the stack.
-
  -
filter(callback) -
-
Returns the items that satisfy the condition determined by the callback.
-
  -
getItem(index) -
-
Returns the item at the position index.
-
  - -
Returns the iterator relative to the aggregate.
-
  - -
Returns the length of the stack.
-
  -
indexOf(item, callback) -
-
Returns the first position of the item in the stack.
-
  -
isEmpty() -
-
Checks if the stack is empty.
-
  -
lastIndexOf(item, callback) -
-
Returns the last position of the item in the stack.
-
  -
multiPop(times) -
-
Removes the more item at the top of the stack.
-
  -
multiPush(items) -
-
Adds the items at the top of the stack.
-
  -
peek() -
-
Returns the item at the top of the stack without remove it.
-
  -
pop() -
-
Removes the item at the top of the stack.
-
  -
push(item) -
-
Adds the item at the top of the stack.
-
- - - - - - - -
- -
- Class Detail -
- -
- Stack(args) -
- -
- Class for managing a stack. - -
- - -
-
Parameters:
- -
- {...*} args - Optional -
-
The items for initializing the stack.
- -
- - -
- - - - -
- Field Detail -
- - - -
- - - items - -
-
- The list of the items in the stack. - - -
- - - - -
- Method Detail -
- - - -
- - {Array} - allIndexesOf(item, callback) - -
-
- Returns all the position in which the item has been found in the stack. - - -
- - -
-
Parameters:
- -
- item - -
-
{*} The item to search.
- -
- callback - Optional, Default: function(item){return(it===item);} -
-
The condition to satisfy. The callback must accept the current item to check.
- -
- - -
-
Returns:
- -
{Array} The positions in which the item has been found.
- -
- - -
- - - -
- - {void} - clear() - -
-
- Removes all the items stored in the stack. - - -
- - -
-
Returns:
- -
{void}
- -
- - -
- - - -
- - {Stack} - clone() - -
-
- Clones the stack into a new stack. - - -
- - -
-
Returns:
- -
{Stack} The stack cloned from this - stack. -
- -
- - -
- - - -
- - {Stack} - cloneDistinct() - -
-
- Clones the stack into a new stack without cloning duplicated items. - - -
- - -
-
Returns:
- -
{Stack} The stack cloned from this - stack. -
- -
- - -
- - - -
- - {boolean} - contains(item, callback) - -
-
- Checks if the stack contains an item that satisfy the condition represented by the callback function. - - -
- - -
-
Parameters:
- -
- item - -
-
{*} The item to find.
- -
- callback - Optional, Default: function(item){return(it===item);} -
-
The condition to satisfy. The callback must accept the current item to check.
- -
- - -
-
Returns:
- -
{boolean} True if the stack contains the item that satisfy the condition, - false otherwise. -
- -
- - -
- - - -
- - {void} - execute(callback) - -
-
- Executes the callback function for each item of the stack. - This method modifies the stack so if you don't need to modify it you must return the same item of the array. - - -
- - -
-
Parameters:
- -
- callback - -
-
{function} The function to execute for each item. The function must accept the current item on which execute the - function. -
- -
- - -
-
Returns:
- -
{void}
- -
- - -
- - - -
- - {Array<*>} - filter(callback) - -
-
- Returns the items that satisfy the condition determined by the callback. - - -
- - -
-
Parameters:
- -
- callback - -
-
{function} The function that implements the condition.
- -
- - -
-
Returns:
- -
{Array<*>} The array that contains the items that satisfy the condition. -
- -
- - -
- - - -
- - {*} - getItem(index) - -
-
- Returns the item at the position index. - - -
- - -
-
Parameters:
- -
- index - -
-
The position of the item.
- -
- - -
-
Returns:
- -
{*} The item at the position. It's undefined if index isn't in the stack - bounds. -
- -
- - -
- - - -
- - {Iterator} - getIterator() - -
-
- Returns the iterator relative to the aggregate. - - -
- - -
-
Returns:
- -
{Iterator} The iterator.
- -
- - -
- - - -
- - {Number} - getLength() - -
-
- Returns the length of the stack. - - -
- - -
-
Returns:
- -
{Number} The length of the stack.
- -
- - -
- - - -
- - {number} - indexOf(item, callback) - -
-
- Returns the first position of the item in the stack. - - -
- - -
-
Parameters:
- -
- item - -
-
{*} The item to search.
- -
- callback - Optional, Default: function(item){return(it===item);} -
-
The condition to satisfy. The callback must accept the current item to check.
- -
- - -
-
Returns:
- -
{number} The first position of the item.
- -
- - -
- - - -
- - {boolean} - isEmpty() - -
-
- Checks if the stack is empty. - - -
- - -
-
Returns:
- -
{boolean} True if the stack is empty, false otherwise.
- -
- - -
- - - -
- - {number} - lastIndexOf(item, callback) - -
-
- Returns the last position of the item in the stack. - - -
- - -
-
Parameters:
- -
- item - -
-
{*} The item to search.
- -
- callback - Optional, Default: function(item){return(it===item);} -
-
The condition to satisfy. The callback must accept the current item to check.
- -
- - -
-
Returns:
- -
{number} The last position of the item.
- -
- - -
- - - -
- - {Array<*>} - multiPop(times) - -
-
- Removes the more item at the top of the stack. - - -
- - -
-
Parameters:
- -
- times - -
-
{number} The number of times to repeat the pop method.
- -
- - -
-
Returns:
- -
{Array<*>} The items at the top of the stack.
- -
- - -
- - - -
- - {void} - multiPush(items) - -
-
- Adds the items at the top of the stack. - - -
- - -
-
Parameters:
- -
- items - -
-
{Array<*>} The items to add.
- -
- - -
-
Returns:
- -
{void}
- -
- - -
- - - -
- - {*} - peek() - -
-
- Returns the item at the top of the stack without remove it. - - -
- - -
-
Returns:
- -
{*} The item at the top of the stack. It's undefined if the stack is empty. -
- -
- - -
- - - -
- - {*} - pop() - -
-
- Removes the item at the top of the stack. - - -
- - -
-
Returns:
- -
{*} The item at the top of the stack. It's undefined if the stack is empty. -
- -
- - -
- - - -
- - - push(item) - -
-
- Adds the item at the top of the stack. - - -
- - -
-
Parameters:
- -
- item - -
-
{*} The item to add. - return {void} -
- -
- - - - - -
-
- - - -
- - Documentation generated by JsDoc Toolkit 2.4.0 - on Wed Apr 23 2014 22:40:59 GMT+0200 (CEST) -
- - diff --git a/doc/symbols/StackIterator.html b/doc/symbols/StackIterator.html deleted file mode 100644 index 89c3e95..0000000 --- a/doc/symbols/StackIterator.html +++ /dev/null @@ -1,634 +0,0 @@ - - - - - - - JsDoc Reference - StackIterator - - - - - - - - - - - - - -
- -

- - Class StackIterator -

- - -

- - -
Defined in: DataStructures.js. - -

- - - - - - - - - - - - - - - - - -
Class Summary
Constructor AttributesConstructor Name and Description
  -
- StackIterator(aggregate) -
-
Class that implements the iterator for a linked list.
-
- - - - - - - - - - - - - - - - - - - - - - - - - - -
Field Summary
Field AttributesField Name and Description
  -
- aggregate -
-
The aggregate relates to this iterator.
-
  -
- pointer -
-
The pointer to the position.
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Method Summary
Method AttributesMethod Name and Description
  -
first() -
-
Moves the iterator to the first position of the aggregate.
-
  -
getItem() -
-
Returns the item stored at the position pointed by the iterator.
-
  -
isDone() -
-
Checks if the iterator is out of the bounds of the aggregate.
-
  -
last() -
-
Moves the iterator to the last position of the aggregate.
-
  -
next() -
-
Moves the iterator to the next item.
-
  - -
Moves the iterator to the previous item.
-
- - - - - - - -
- -
- Class Detail -
- -
- StackIterator(aggregate) -
- -
- Class that implements the iterator for a linked list. - -
- - -
-
Parameters:
- -
- aggregate - -
-
{Stack} The aggregate to scan.
- -
- - -
- - - - -
- Field Detail -
- - - -
- - - aggregate - -
-
- The aggregate relates to this iterator. - - -
- - -
- - - -
- - - pointer - -
-
- The pointer to the position. - - -
- - - - -
- Method Detail -
- - - -
- - {void} - first() - -
-
- Moves the iterator to the first position of the aggregate. - - -
- - -
-
Returns:
- -
{void}
- -
- - -
- - - -
- - {*} - getItem() - -
-
- Returns the item stored at the position pointed by the iterator. - - -
- - -
-
Returns:
- -
{*} The item stored or undefined if it's out of the bounds.
- -
- - -
- - - -
- - {boolean} - isDone() - -
-
- Checks if the iterator is out of the bounds of the aggregate. - - -
- - -
-
Returns:
- -
{boolean} It return true if the iterator is out of the bounds of the - aggregate, otherwise false. -
- -
- - -
- - - -
- - {void} - last() - -
-
- Moves the iterator to the last position of the aggregate. - - -
- - -
-
Returns:
- -
{void}
- -
- - -
- - - -
- - {void} - next() - -
-
- Moves the iterator to the next item. - - -
- - -
-
Returns:
- -
{void}
- -
- - -
- - - -
- - {void} - previous() - -
-
- Moves the iterator to the previous item. - - -
- - -
-
Returns:
- -
{void}
- -
- - - - - -
-
- - - -
- - Documentation generated by JsDoc Toolkit 2.4.0 - on Wed Apr 23 2014 22:40:59 GMT+0200 (CEST) -
- - diff --git a/doc/symbols/_global_.html b/doc/symbols/_global_.html deleted file mode 100644 index 199bbbb..0000000 --- a/doc/symbols/_global_.html +++ /dev/null @@ -1,289 +0,0 @@ - - - - - - - JsDoc Reference - _global_ - - - - - - - - - - - - - -
- -

- - Built-In Namespace _global_ -

- - -

- - -

- - - - - - - - - - - - - - - - - - - - - - - - -
-
- - - -
- - Documentation generated by JsDoc Toolkit 2.4.0 - on Wed Apr 23 2014 22:40:58 GMT+0200 (CEST) -
- - diff --git a/doc/symbols/src/C__DataStructures_DataStructures.js.html b/doc/symbols/src/C__DataStructures_DataStructures.js.html deleted file mode 100644 index c5a6ae0..0000000 --- a/doc/symbols/src/C__DataStructures_DataStructures.js.html +++ /dev/null @@ -1,12882 +0,0 @@ - - - - - - -
  1 /**
-  2  * Interface for managing a generic data structure.
-  3  * @constructor
-  4  * @interface
-  5  */
-  6 function Aggregate() {
-  7 
-  8 }
-  9 
- 10 /**
- 11  * Returns the iterator relative to the aggregate.
- 12  * @abstract
- 13  * @return {Iterator} The iterator.
- 14  */
- 15 Aggregate.prototype.getIterator = function () {
- 16 };
- 17 
- 18 /**
- 19  * Interface for managing an iterator for an aggregate.
- 20  * @constructor
- 21  * @interface
- 22  */
- 23 function Iterator() {
- 24 
- 25 }
- 26 
- 27 /**
- 28  * Moves the iterator to the first position of the aggregate.
- 29  * @abstract
- 30  * @return {void}
- 31  */
- 32 Iterator.prototype.first = function () {
- 33 
- 34 };
- 35 
- 36 /**
- 37  * Moves the iterator to the next item.
- 38  * @abstract
- 39  * @return {void}
- 40  */
- 41 Iterator.prototype.next = function () {
- 42 
- 43 };
- 44 
- 45 /**
- 46  * Moves the iterator to the last position of the aggregate.
- 47  * @abstract
- 48  * @return {void}
- 49  */
- 50 Iterator.prototype.last = function () {
- 51 
- 52 };
- 53 
- 54 /**
- 55  * Moves the iterator to the previous item.
- 56  * @abstract
- 57  * @return {void}
- 58  */
- 59 Iterator.prototype.previous = function () {
- 60 
- 61 };
- 62 
- 63 /**
- 64  * Checks if the iterator is out of the bounds of the aggregate.
- 65  * @abstract
- 66  * @return {boolean} It return true if the iterator is out of the bounds of the aggregate, otherwise false.
- 67  */
- 68 Iterator.prototype.isDone = function () {
- 69 
- 70 };
- 71 
- 72 /**
- 73  * Returns the item stored at the position pointed by the iterator.
- 74  * @abstract
- 75  * @return {*} The item stored or undefined if it's out of the bounds.
- 76  */
- 77 Iterator.prototype.getItem = function () {
- 78 
- 79 };
- 80 
- 81 /**
- 82  * Class for managing a binary search tree.
- 83  * @constructor
- 84  */
- 85 function BSTree() {
- 86 	/**
- 87 	 * The root of the tree.
- 88 	 * @type {BSNode|null}
- 89 	 */
- 90 	this.root = null;
- 91 }
- 92 
- 93 /**
- 94  * Returns the iterator relative to the aggregate.
- 95  * @return {Iterator} The iterator.
- 96  */
- 97 BSTree.prototype.getIterator = function () {
- 98 	return new BSTreeIterator(this);
- 99 };
-100 
-101 /**
-102  * Inserts the item relatives to the key value in the tree.
-103  * @param key {number} The key to store.
-104  * @param item {*} The item to store.
-105  * @return {void}
-106  */
-107 BSTree.prototype.insert = function (key, item) {
-108 	var node = new BSNode(key, item);
-109 	var p = this.root;
-110 	for (var n = this.root; n;) {
-111 		p = n;
-112 		if (key < n.key)
-113 			n = n.left;
-114 		else
-115 			n = n.right;
-116 	}
-117 	node.parent = p;
-118 	if (!p)
-119 		this.root = node;
-120 	else if (key < p.key)
-121 		p.left = node;
-122 	else
-123 		p.right = node;
-124 };
-125 
-126 /**
-127  * Searches the item relatives to the key.
-128  * @param key {Number} The key to find.
-129  * @param [node = root] {BSNode} The node from which start the search.
-130  * @return {*} The item found or undefined if there isn't the key in the tree.
-131  */
-132 BSTree.prototype.search = function (key, node) {
-133 	node = node || this.root;
-134 	while (node && key !== node.key)
-135 		if (key < node.key)
-136 			node = node.left;
-137 		else
-138 			node = node.right;
-139 	if (node)
-140 		return node.item;
-141 	return undefined;
-142 };
-143 
-144 /**
-145  * Gets the item relatives to the minimum key stored in the tree.
-146  * @param [node = root] {Node} The node from which start the search.
-147  * @return {BSNode} The node found.
-148  */
-149 BSTree.prototype.minimum = function (node) {
-150 	node = node || this.root;
-151 	while (node && node.left)
-152 		node = node.left;
-153 	return node;
-154 };
-155 
-156 /**
-157  * Gets the item relatives to the maximum key stored in the tree.
-158  * @param [node = root] {Node} The node from which start the search.
-159  * @return {BSNode} The node found.
-160  */
-161 BSTree.prototype.maximum = function (node) {
-162 	node = node || this.root;
-163 	while (node && node.right)
-164 		node = node.right;
-165 	return node;
-166 };
-167 
-168 /**
-169  * Gets the node with the key next to the param node key.
-170  * @param node {BSNode} The node of which search the successor.
-171  * @return {BSNode} The node found.
-172  */
-173 BSTree.prototype.successor = function (node) {
-174 	if (node.right)
-175 		return this.minimum(node.right);
-176 	var parent = node.parent;
-177 	while (parent && node === parent.right) {
-178 		node = parent;
-179 		parent = parent.parent;
-180 	}
-181 	return parent;
-182 };
-183 
-184 /**
-185  * Gets the node with the key previous to the param node key.
-186  * @param node {BSNode} The node of which search the predecessor.
-187  * @return {BSNode} The node found.
-188  */
-189 BSTree.prototype.predecessor = function (node) {
-190 	if (node.left)
-191 		return this.maximum(node.left);
-192 	var parent = node.parent;
-193 	while (parent && node === parent.left) {
-194 		node = parent;
-195 		parent = parent.parent;
-196 	}
-197 	return parent;
-198 };
-199 
-200 /**
-201  * Deletes the node from the tree.
-202  * @param node {BSNode} The node to delete.
-203  * @return {void}
-204  */
-205 BSTree.prototype.deleteNode = function (node) {
-206 	if (!node.left && !node.right) {
-207 		if (node === this.root)
-208 			this.root = null;
-209 		else if (node.parent.left === node)
-210 			node.parent.left = null;
-211 		else
-212 			node.parent.right = null;
-213 	} else if (node.left && node.right) {
-214 		var next = this.successor(node);
-215 		node.key = next.key;
-216 		node.item = next.item;
-217 		if (next.parent.left === next)
-218 			next.parent.left = null;
-219 		else
-220 			next.parent.right = null;
-221 	} else {
-222 		if (node.right) {
-223 			if (node === this.root) {
-224 				this.root = node.right;
-225 				node.right.parent = null;
-226 			} else {
-227 				node.parent.right = node.right;
-228 				node.right.parent = node.parent;
-229 			}
-230 		} else {
-231 			if (node === this.root) {
-232 				this.root = node.left;
-233 				node.left.parent = null;
-234 			} else {
-235 				node.parent.left = node.left;
-236 				node.left.parent = node.parent;
-237 			}
-238 		}
-239 	}
-240 };
-241 
-242 /**
-243  * Class that implements the iterator for a binary search tree.
-244  * @param aggregate {BSTree} The aggregate to scan.
-245  * @constructor
-246  */
-247 function BSTreeIterator(aggregate) {
-248 	/**
-249 	 * The aggregate relates to this iterator.
-250 	 * @type {BSTree}
-251 	 */
-252 	this.aggregate = aggregate;
-253 
-254 	/**
-255 	 * The pointer to the position.
-256 	 * @type {BSNode|null}
-257 	 */
-258 	this.pointer = null;
-259 }
-260 
-261 /**
-262  * Moves the iterator to the first position of the aggregate.
-263  * @return {void}
-264  */
-265 BSTreeIterator.prototype.first = function () {
-266 	this.pointer = this.aggregate.minimum();
-267 };
-268 
-269 /**
-270  * Moves the iterator to the next item.
-271  * @return {void}
-272  */
-273 BSTreeIterator.prototype.next = function () {
-274 	this.pointer = this.aggregate.successor(this.pointer);
-275 };
-276 
-277 /**
-278  * Moves the iterator to the last position of the aggregate.
-279  * @return {void}
-280  */
-281 BSTreeIterator.prototype.last = function () {
-282 	this.pointer = this.aggregate.maximum();
-283 };
-284 
-285 /**
-286  * Moves the iterator to the previous item.
-287  * @return {void}
-288  */
-289 BSTreeIterator.prototype.previous = function () {
-290 	this.pointer = this.aggregate.predecessor(this.pointer);
-291 };
-292 
-293 /**
-294  * Checks if the iterator is out of the bounds of the aggregate.
-295  * @return {boolean} It return true if the iterator is out of the bounds of the aggregate, otherwise false.
-296  */
-297 BSTreeIterator.prototype.isDone = function () {
-298 	return !this.pointer;
-299 };
-300 
-301 /**
-302  * Returns the item stored at the position pointed by the iterator.
-303  * @return {*} The item stored or undefined if it's out of the bounds.
-304  */
-305 BSTreeIterator.prototype.getItem = function () {
-306 	return this.pointer.item;
-307 };
-308 
-309 /**
-310  * Returns the node stored at the position pointed by the iterator.
-311  * @return {BSNode|null} The node stored or null if it's out of the bounds.
-312  */
-313 BSTreeIterator.prototype.getNode = function () {
-314 	return this.pointer;
-315 };
-316 
-317 /**
-318  * Class for managing a B-Tree.
-319  * @param minimumDegree {number} The minimum number of keys of a node.
-320  * @constructor
-321  */
-322 function BTree(minimumDegree) {
-323 	/**
-324 	 * The root of the tree.
-325 	 * @type {BNode}
-326 	 */
-327 	this.root = new BNode();
-328 
-329 	/**
-330 	 * The minimum number of the keys of a node.
-331 	 * @type {number}
-332 	 */
-333 	this.t = minimumDegree;
-334 
-335 	/**
-336 	 * The number of items stored in the tree.
-337 	 * @type {number}
-338 	 */
-339 	this.size = 0;
-340 }
-341 
-342 /**
-343  * Returns the iterator relative to the aggregate.
-344  * @return {Iterator} The iterator.
-345  */
-346 BTree.prototype.getIterator = function () {
-347 	return new BTreeIterator(this);
-348 };
-349 
-350 /**
-351  * Inserts the item relatives to the key value in the tree.
-352  * @param key {number} The key to store.
-353  * @param item {*} The item to store.
-354  * @return {void}
-355  */
-356 BTree.prototype.insert = function (key, item) {
-357 	var node = this.root;
-358 	if (node.keys.length === 2 * this.t - 1) {
-359 		var newNode = new BNode();
-360 		newNode.childs.push(node);
-361 		this.root = newNode;
-362 		this.splitChild(newNode, 0);
-363 		node = newNode;
-364 	}
-365 	this.size++;
-366 	this.insertNonFull(node, key, item);
-367 };
-368 
-369 /**
-370  * Inserts the new node in the right position if the node is not full.
-371  * @param node {BNode} The node from which start to check the insertion.
-372  * @param key {number} The key to store.
-373  * @param item {*} The item to store.
-374  * @return {void}
-375  */
-376 BTree.prototype.insertNonFull = function (node, key, item) {
-377 	while (node) {
-378 		var i = node.keys.length - 1;
-379 		if (!node.childs.length) {
-380 			for (; i > -1 && key < node.keys[i]; i--) {
-381 				node.keys[i + 1] = node.keys[i];
-382 				node.items[i + 1] = node.items[i];
-383 			}
-384 			node.keys[i + 1] = key;
-385 			node.items[i + 1] = item;
-386 			return;
-387 		} else {
-388 			var j = 0;
-389 			i++;
-390 			while (j < i) {
-391 				var m = Math.floor((j + i) / 2);
-392 				if (key <= node.keys[m])
-393 					i = m;
-394 				else
-395 					j = m + 1;
-396 			}
-397 			if (node.childs[j].keys.length === 2 * this.t - 1) {
-398 				this.splitChild(node, j);
-399 				if (key > node.keys[j])
-400 					j++;
-401 			}
-402 			node = node.childs[j];
-403 		}
-404 	}
-405 };
-406 
-407 /**
-408  * Searches the item relatives to the key that satisfy the condition represented by the callback function.
-409  * @param key {Number} The key to find.
-410  * @param [node = root] {RBNode} The node from which start the search.
-411  * @param [callback = function(node,index){return(node.keys[index]===key);}] The condition to satisfy. The callback must accept the current node to check and optionally the position of the key.
-412  * @return {*} The item found or undefined if there isn't the key in the tree.
-413  */
-414 BTree.prototype.search = function (key, node, callback) {
-415 	node = node || this.root;
-416 	callback = callback || function (node, index) {
-417 		return node.keys[index] === key;
-418 	};
-419 	while (node) {
-420 		var n = node.keys.length;
-421 		var i = 0, j = n;
-422 		while (i < j) {
-423 			var m = Math.floor((i + j) / 2);
-424 			if (key <= node.keys[m])
-425 				j = m;
-426 			else
-427 				i = m + 1;
-428 		}
-429 		if (i < n && callback(node, i))
-430 			return node.items[i];
-431 		else if (!node.childs.length)
-432 			return undefined;
-433 		else
-434 			node = node.childs[i];
-435 	}
-436 };
-437 
-438 /**
-439  * Splits the child of the node at the position index.
-440  * @param node {BNode} The parent of the child to split.
-441  * @param index {number} The position of the child to split.
-442  * @return {void}
-443  */
-444 BTree.prototype.splitChild = function (node, index) {
-445 	var newNode = new BNode();
-446 	var child = node.childs[index];
-447 	//copy of the last t - 1 keys and items in the new node
-448 	for (var i = 0; i < this.t - 1; i++) {
-449 		newNode.keys[i] = child.keys[i + this.t];
-450 		newNode.items[i] = child.items[i + this.t];
-451 	}
-452 	if (child.childs.length)
-453 	//copy of the last t child in the new node
-454 		for (var j = 0; j < this.t; j++)
-455 			newNode.childs[j] = child.childs[j + this.t];
-456 	//shift the children from index + 1 position
-457 	for (var l = node.keys.length; l > index; l--)
-458 		node.childs[l + 1] = node.childs[l];
-459 	//set the index position as the position t of the child
-460 	node.childs[index + 1] = newNode;
-461 	//shift the keys and the items from index position
-462 	for (var k = node.keys.length - 1; k > index - 1; k--) {
-463 		node.keys[k + 1] = node.keys[k];
-464 		node.items[k + 1] = node.items[k];
-465 	}
-466 	node.keys[index] = child.keys[this.t - 1];
-467 	node.items[index] = child.items[this.t - 1];
-468 	//remove keys, items and child in the old node.
-469 	child.keys.splice(child.keys.length - this.t);
-470 	child.items.splice(child.items.length - this.t);
-471 	child.childs.splice(child.childs.length - this.t);
-472 };
-473 
-474 /**
-475  * Deletes the key from the tree.
-476  * @param key {*} The key to delete.
-477  * @return {void}
-478  */
-479 BTree.prototype.deleteKey = function (key) {
-480 	if (this.root.keys.length) {
-481 		this.deleteNonMin(this.root, key);
-482 		if (!this.root.keys.length && this.root.childs.length)
-483 			this.root = this.root.childs[0];
-484 		this.size--;
-485 	}
-486 };
-487 
-488 /**
-489  * Deletes a node that's a number of keys greater than the minimum for a node.
-490  * @param node {BNode} The node to delete.
-491  * @param key {number} The key to delete.
-492  * @return {void}
-493  */
-494 BTree.prototype.deleteNonMin = function (node, key) {
-495 	var i = 0, j = node.keys.length;
-496 	while (i < j) {
-497 		var m = Math.floor((i + j) / 2);
-498 		if (key <= node.keys[m])
-499 			j = m;
-500 		else
-501 			i = m + 1;
-502 	}
-503 	//key is in the node
-504 	if (i < node.keys.length && key === node.keys[i]) {
-505 		//the node is a leaf
-506 		if (!node.childs.length) {
-507 			//remove the key
-508 			for (j = i + 1; j < node.keys.length; j++) {
-509 				node.keys[j - 1] = node.keys[j];
-510 				node.items[j - 1] = node.items[j];
-511 			}
-512 			node.keys.pop();
-513 			node.items.pop();
-514 		} else {
-515 			//the node is not a leaf
-516 			//the node has the minimum number of keys
-517 			if (node.childs[i].length === this.t - 1) {
-518 				//increase the number of the keys of the node
-519 				this.augmentChild(node, i);
-520 				if (i === node.keys.length + 1)
-521 					i--;
-522 			}
-523 			//check if the key is moved in the child
-524 			if (node.keys[i] !== key)
-525 				this.deleteNonMin(node.childs[i], key);
-526 			else
-527 				this.deleteMax(node, i);
-528 		}
-529 		//the key is not in the node
-530 	} else {
-531 		//check if the child i has the minimum number of keys
-532 		if (node.childs[i].keys.length === this.t - 1) {
-533 			this.augmentChild(node, i);
-534 			if (i === node.keys.length + 2)
-535 				i--;
-536 		}
-537 		this.deleteNonMin(node.childs[i], key);
-538 	}
-539 };
-540 
-541 /**
-542  * Deletes a node that have the maximum number of keys for node.
-543  * @param node {BNode} The node to delete.
-544  * @param index {number} The key to delete in the node.
-545  * @return {void}
-546  */
-547 BTree.prototype.deleteMax = function (node, index) {
-548 	var child = node.childs[index];
-549 	var goAhead = true;
-550 	while (goAhead) {
-551 		if (!child.childs.length) {
-552 			node.keys[index] = child.keys[child.keys.length - 1];
-553 			node.items[index] = child.items[child.items.length - 1];
-554 			child.keys.pop();
-555 			child.items.pop();
-556 			goAhead = false;
-557 		} else {
-558 			var last = child.childs[child.keys.length];
-559 			if (last.keys.length === this.t - 1)
-560 				this.augmentChild(child, child.keys.length);
-561 			child = child.childs[child.keys.length];
-562 		}
-563 	}
-564 };
-565 
-566 /**
-567  * Augments the number of keys stored in the node preserving the order.
-568  * @param node {BNode} The node to delete.
-569  * @param index {number} The index of the position to augment.
-570  * @return {void}
-571  */
-572 BTree.prototype.augmentChild = function (node, index) {
-573 	var child = node.childs[index];
-574 	var brother;
-575 	if (index)
-576 		brother = node.childs[index - 1];
-577 	if (index && brother.keys.length > this.t - 1) {
-578 		if (child.childs.length) {
-579 			for (var j = this.keys.length + 1; j > 0; j--)
-580 				child.childs[j] = child.childs[j - 1];
-581 			child.childs[0] = brother.childs[brother.keys.length];
-582 			for (var i = child.keys.length; i > 0; i--) {
-583 				child.keys[i] = child.keys[i - 1];
-584 				child.items[i] = child.items[i - 1];
-585 			}
-586 			child.keys[0] = node.keys[index - 1];
-587 			child.items[0] = node.items[index - 1];
-588 			node.keys[index - 1] = brother.keys[brother.keys.length - 1];
-589 			node.items[index - 1] = brother.items[brother.items.length - 1];
-590 		}
-591 	} else {
-592 		if (index < node.keys.length)
-593 			brother = node.childs[index + 1];
-594 		if (index < node.keys.length && brother.keys.length > this.t - 1) {
-595 			if (brother.childs.length) {
-596 				child.childs[child.keys.length + 1] = brother.childs[0];
-597 				for (var l = 1; l < brother.keys.length + 1; l++)
-598 					brother.childs[l - 1] = brother.childs[l];
-599 				brother.childs.pop();
-600 			}
-601 			child.keys[child.keys.length] = node.keys[index];
-602 			child.items[child.items.length] = node.items[index];
-603 			node.keys[index] = brother.keys[0];
-604 			node.items[index] = brother.items[0];
-605 			for (var k = 1; k < brother.keys.length; k++) {
-606 				brother.keys[k - 1] = brother.keys[k];
-607 				brother.items[k - 1] = brother.items[k];
-608 			}
-609 			brother.keys.pop();
-610 			brother.items.pop();
-611 		} else {
-612 			if (index < node.keys.length) {
-613 				child.keys[this.t - 1] = node.keys[index];
-614 				child.items[this.t - 1] = node.items[index];
-615 				for (var m = index + 2; m < node.keys.length + 1; m++)
-616 					node.childs[m - 1] = node.childs[m];
-617 				node.childs.pop();
-618 				for (var n = index + 1; n < node.keys.length; n++) {
-619 					node.keys[n - 1] = node.keys[n];
-620 					node.items[n - 1] = node.items[n];
-621 				}
-622 				node.keys.pop();
-623 				node.items.pop();
-624 				if (brother.childs.length)
-625 					for (var y = 0; y < brother.keys.length + 1; y++)
-626 						child.childs[this.t + y] = brother.childs[y];
-627 				for (var x = 0; x < brother.keys.length; x++) {
-628 					child.keys[x + this.t] = brother.keys[x];
-629 					child.items[x + this.t] = brother.items[x];
-630 				}
-631 			} else {
-632 				if (brother.childs.length)
-633 					for (var w = 0; w < child.keys.length + 1; w++)
-634 						brother.childs[this.t + w] = child.childs[w];
-635 				brother.keys[this.t - 1] = node.keys[node.keys.length - 1];
-636 				brother.items[this.t - 1] = node.items[node.keys.length - 1];
-637 				for (var z = 0; z < child.keys.length; z++) {
-638 					brother.keys[z + this.t] = child.keys[z];
-639 					brother.items[z + this.t] = child.items[z];
-640 				}
-641 			}
-642 		}
-643 	}
-644 };
-645 
-646 /**
-647  * Checks if the tree contains the key.
-648  * @param key {number} The key to find.
-649  * @param [callback = function(node,index){return(node.keys[index]===key);}] The condition to satisfy. The callback must accept the current node to check and optionally the position of the key.
-650  * @return {boolean} True if the tree contains the key.
-651  */
-652 BTree.prototype.contains = function (key, callback) {
-653 	return this.search(key, null, callback) !== undefined;
-654 };
-655 
-656 /**
-657  * Checks if the tree contains a node that satisfy the condition represented by the callback function.
-658  * This method check all the tree avoiding the binary search.
-659  * @param callback {function} The condition to satisfy. The callback must accept the current node to check.
-660  * @return {boolean} True if the tree contains the node that satisfy the condition, false otherwise.
-661  */
-662 BTree.prototype.fullContains = function (callback) {
-663 	var key = this.minimumKey();
-664 	while (key !== null && !callback(this.search(key)))
-665 		key = this.successor(key);
-666 	return key !== null;
-667 };
-668 
-669 /**
-670  * Gets the key next to the param node key.
-671  * @param key {number} The key of which search the successor.
-672  * @param [node = root] The node from start the search of the successor.
-673  * @return {number} The key found.
-674  */
-675 BTree.prototype.successor = function (key, node) {
-676 	node = node || this.root;
-677 	var i = 0, j = node.keys.length;
-678 	//search the key in the node
-679 	while (i < j) {
-680 		var m = Math.floor((i + j) / 2);
-681 		if (key <= node.keys[m])
-682 			j = m;
-683 		else
-684 			i = m + 1;
-685 	}
-686 	//check if the key has been found
-687 	if (node.keys[i] === key)
-688 	//in this case the successor is the next key
-689 		i++;
-690 	//if it's a leaf
-691 	if (!node.childs.length) {
-692 		//check if the key hasn't been found
-693 		if (i > node.keys.length - 1)
-694 			return null;
-695 		else
-696 			return node.keys[i];
-697 	}
-698 	//if it's not a leaf check if the successor is in the i-child
-699 	var successor = this.successor(key, node.childs[i]);
-700 	//if it's not in the child and has been found a key then return it
-701 	if (successor === null && i < node.keys.length)
-702 		return node.keys[i];
-703 	//return the value of the successor even if it's null
-704 	return successor;
-705 };
-706 
-707 /**
-708  * Gets the key previous to the param key.
-709  * @param key {number} The key of which search the predecessor.
-710  * @param [node = root] The node from start the search of the predecessor.
-711  * @return {number} The key found.
-712  */
-713 BTree.prototype.predecessor = function (key, node) {
-714 	node = node || this.root;
-715 	var i = 0, j = node.keys.length;
-716 	//search the key in the node
-717 	while (i < j) {
-718 		var m = Math.floor((i + j) / 2);
-719 		if (key <= node.keys[m])
-720 			j = m;
-721 		else
-722 			i = m + 1;
-723 	}
-724 	i--;
-725 	//check if the node is a leaf
-726 	if (!node.childs.length) {
-727 		//check if a predecessor has been found
-728 		if (i < 0)
-729 			return null;
-730 		else
-731 			return node.keys[i];
-732 	}
-733 	var predecessor = this.predecessor(key, node.childs[i + 1]);
-734 	if (predecessor === null && key > node.keys[0]) {
-735 		return node.keys[i];
-736 	}
-737 	return predecessor;
-738 };
-739 
-740 /**
-741  * Gets the minimum key stored in the tree.
-742  * @return {number} The key found.
-743  */
-744 BTree.prototype.minimumKey = function () {
-745 	var node = this.root;
-746 	while (node.childs.length)
-747 		node = node.childs[0];
-748 	if (node)
-749 		return node.keys[0];
-750 	return null;
-751 };
-752 
-753 /**
-754  * Gets the maximum key stored in the tree.
-755  * @return {number} The key found.
-756  */
-757 BTree.prototype.maximumKey = function () {
-758 	var node = this.root;
-759 	while (node.childs.length)
-760 		node = node.childs[node.childs.length - 1];
-761 	if (node)
-762 		return node.keys[node.keys.length - 1];
-763 	return null;
-764 };
-765 
-766 /**
-767  * Gets the item relatives to the minimum key stored in the tree.
-768  * @return {number} The item found.
-769  */
-770 BTree.prototype.minimum = function () {
-771 	var node = this.root;
-772 	while (node.childs.length)
-773 		node = node.childs[0];
-774 	return node.items[0];
-775 };
-776 
-777 /**
-778  * Gets the item relatives to the maximum key stored in the tree.
-779  * @return {node} The item found.
-780  */
-781 BTree.prototype.maximum = function () {
-782 	var node = this.root;
-783 	while (node.childs.length)
-784 		node = node.childs[node.childs.length - 1];
-785 	return node.items[node.items.length - 1];
-786 };
-787 
-788 /**
-789  * Returns the size of the tree.
-790  * @return {number} The size of the tree.
-791  */
-792 BTree.prototype.getSize = function () {
-793 	return this.size;
-794 };
-795 
-796 /**
-797  * Checks if the tree is empty.
-798  * @return {boolean} True if the tree is empty, false otherwise.
-799  */
-800 BTree.prototype.isEmpty = function () {
-801 	return !this.size;
-802 };
-803 
-804 /**
-805  * Executes the callback function for each item of the tree.
-806  * This method modifies the tree so if you don't need to modify it you must return the same item of the array.
-807  * @param callback {function} The function to execute for each item. The function must accept the current item on which execute the function.
-808  * @return {void}
-809  */
-810 BTree.prototype.execute = function (callback) {
-811 	var node = arguments[1] || this.root;
-812 	for (var i = 0; i < node.items.length; i++)
-813 		node.items[i] = callback(node.items[i]);
-814 	for (var j = 0; j < node.childs.length; j++)
-815 		this.execute(callback, node.childs[j]);
-816 };
-817 
-818 /**
-819  * Removes all the items stored in the tree.
-820  * @return {void}
-821  */
-822 BTree.prototype.clear = function () {
-823 	this.root = null;
-824 	this.size = 0;
-825 };
-826 
-827 /**
-828  * Returns the items that satisfy the condition determined by the callback.
-829  * @param callback {function} The function that implements the condition.
-830  * @return {Array<*>} The array that contains the items that satisfy the condition.
-831  */
-832 BTree.prototype.filter = function (callback) {
-833 	var result = [];
-834 	var node = arguments[1] || this.root;
-835 	for (var i = 0; i < node.items.length; i++) {
-836 		if (node.childs.length)
-837 			result = result.concat(this.filter(callback, node.childs[i]));
-838 		if (callback(node.items[i]))
-839 			result.push(node.items[i]);
-840 	}
-841 	if (node.childs.length)
-842 		result = result.concat(this.filter(callback, node.childs[node.childs.length - 1]));
-843 	return result;
-844 };
-845 
-846 /**
-847  * Clones the tree into a new tree.
-848  * @return {BTree} The tree cloned from this tree.
-849  */
-850 BTree.prototype.clone = function () {
-851 	var tree = new BTree(this.t);
-852 	var it = this.getIterator();
-853 	for (it.first(); !it.isDone(); it.next()) {
-854 		var item = it.getItem();
-855 		if (item.clone)
-856 			item = item.clone();
-857 		tree.insert(it.getKey(), item);
-858 	}
-859 	return tree;
-860 };
-861 
-862 /**
-863  * Clones the tree into a new tree without cloning duplicated items.
-864  * @return {BTree} The tree cloned from this tree.
-865  */
-866 BTree.prototype.cloneDistinct = function () {
-867 	var tree = new BTree(this.t);
-868 	var it = this.getIterator();
-869 	for (it.first(); !it.isDone(); it.next()) {
-870 		var callback = function (item) {
-871 			return item === it.getItem();
-872 		};
-873 		if (!tree.fullContains(callback)) {
-874 			if (it.getItem().cloneDistinct)
-875 				tree.insert(it.getKey(), it.getItem().cloneDistinct());
-876 			else if (it.getItem().clone)
-877 				tree.insert(it.getKey(), it.getItem().clone());
-878 			else
-879 				tree.insert(it.getKey(), it.getItem());
-880 		}
-881 	}
-882 	return tree;
-883 };
-884 
-885 /**
-886  * Transforms the tree into an array without preserving keys.
-887  * @return {Array<*>} The array that represents the tree.
-888  */
-889 BTree.prototype.toArray = function () {
-890 	var result = [];
-891 	var it = this.getIterator();
-892 	for (it.first(); !it.isDone(); it.next())
-893 		result.push(it.getItem());
-894 	return result;
-895 };
-896 
-897 /**
-898  * Returns the first position of the item in the tree.
-899  * @param item {*} The item to search.
-900  * @param [callback = function(item){return(it===item);}] The condition to satisfy. The callback must accept the current item to check.
-901  * @return {number} The first position of the item.
-902  */
-903 BTree.prototype.indexOf = function (item, callback) {
-904 	callback = callback || function (it) {
-905 		return it === item;
-906 	};
-907 	var i = 0, key = this.minimumKey();
-908 	while (key !== null) {
-909 		if (callback(this.search(key)))
-910 			return i;
-911 		key = this.successor(key);
-912 		i++;
-913 	}
-914 	return -1;
-915 };
-916 
-917 /**
-918  * Returns the last position of the item in the tree.
-919  * @param item {*} The item to search.
-920  * @param [callback = function(item){return(it===item);}] The condition to satisfy. The callback must accept the current item to check.
-921  * @return {number} The last position of the item.
-922  */
-923 BTree.prototype.lastIndexOf = function (item, callback) {
-924 	callback = callback || function (it) {
-925 		return it === item;
-926 	};
-927 	var i = this.size - 1, key = this.maximumKey();
-928 	while (key !== null) {
-929 		if (callback(this.search(key)))
-930 			return i;
-931 		i--;
-932 		key = this.predecessor(key);
-933 	}
-934 	return -1;
-935 };
-936 
-937 /**
-938  * Returns all the position in which the item has been found in the tree.
-939  * @param item {*} The item to search.
-940  * @param [callback = function(item){return(it===item);}] The condition to satisfy. The callback must accept the current item to check.
-941  * @return {Array<number>} The positions in which the item has been found.
-942  */
-943 BTree.prototype.allIndexesOf = function (item, callback) {
-944 	callback = callback || function (it) {
-945 		return it === item;
-946 	};
-947 	var i = 0, key = this.minimumKey();
-948 	var indexes = [];
-949 	while (key !== null) {
-950 		if (callback(this.search(key)))
-951 			indexes.push(i);
-952 		i++;
-953 		key = this.successor(key);
-954 	}
-955 	return indexes;
-956 };
-957 
-958 /**
-959  * Returns the item at the position index.
-960  * @param index {number} The position of the item.
-961  * @return {*} The item at the position. It's undefined if index isn't in the tree bounds.
-962  */
-963 BTree.prototype.getItem = function (index) {
-964 	if (index < 0 || index > this.size - 1)
-965 		return undefined;
-966 	var key = this.minimum();
-967 	for (var i = 0; i < index; i++)
-968 		key = this.successor(key);
-969 	return this.search(key);
-970 };
-971 
-972 /**
-973  * Class that implements the iterator for a binary search tree.
-974  * @param aggregate {BTree} The aggregate to scan.
-975  * @constructor
-976  */
-977 function BTreeIterator(aggregate) {
-978 	/**
-979 	 * The aggregate relates to this iterator.
-980 	 * @type {BTree}
-981 	 */
-982 	this.aggregate = aggregate;
-983 
-984 	/**
-985 	 * The pointer to the position.
-986 	 * @type {number}
-987 	 */
-988 	this.pointer = null;
-989 }
-990 
-991 /**
-992  * Moves the iterator to the first position of the aggregate.
-993  * @return {void}
-994  */
-995 BTreeIterator.prototype.first = function () {
-996 	this.pointer = this.aggregate.minimumKey();
-997 };
-998 
-999 /**
-1000  * Moves the iterator to the next item.
-1001  * @return {void}
-1002  */
-1003 BTreeIterator.prototype.next = function () {
-1004 	this.pointer = this.aggregate.successor(this.pointer);
-1005 };
-1006 
-1007 /**
-1008  * Moves the iterator to the last position of the aggregate.
-1009  * @return {void}
-1010  */
-1011 BTreeIterator.prototype.last = function () {
-1012 	this.pointer = this.aggregate.maximumKey();
-1013 };
-1014 
-1015 /**
-1016  * Moves the iterator to the previous item.
-1017  * @return {void}
-1018  */
-1019 BTreeIterator.prototype.previous = function () {
-1020 	this.pointer = this.aggregate.predecessor(this.pointer);
-1021 };
-1022 
-1023 /**
-1024  * Checks if the iterator is out of the bounds of the aggregate.
-1025  * @return {boolean} It return true if the iterator is out of the bounds of the aggregate, otherwise false.
-1026  */
-1027 BTreeIterator.prototype.isDone = function () {
-1028 	return this.pointer === null;
-1029 };
-1030 
-1031 /**
-1032  * Returns the item stored at the position pointed by the iterator.
-1033  * @return {*} The item stored or undefined if it's out of the bounds.
-1034  */
-1035 BTreeIterator.prototype.getItem = function () {
-1036 	return this.aggregate.search(this.pointer);
-1037 };
-1038 
-1039 /**
-1040  * Returns the key stored at the position pointed by the iterator.
-1041  * @return {number} The key stored or null if it's out of the bounds.
-1042  */
-1043 BTreeIterator.prototype.getKey = function () {
-1044 	return this.pointer;
-1045 };
-1046 
-1047 /**
-1048  * Class for managing a circular buffer.
-1049  * @param size {Number} The size of the buffer.
-1050  * @constructor
-1051  */
-1052 function CircularBuffer(size) {
-1053 	/**
-1054 	 * The index of the position of the head of the buffer.
-1055 	 * @type {number}
-1056 	 */
-1057 	this.head = 0;
-1058 	/**
-1059 	 * The index of the position of the tail of the buffer.
-1060 	 * @type {number}
-1061 	 */
-1062 	this.tail = 0;
-1063 	/**
-1064 	 * The items stored in the buffer.
-1065 	 * @type {Array<*>}
-1066 	 */
-1067 	this.items = new Array(size);
-1068 	/**
-1069 	 * Is true if buffer is empty, false otherwise.
-1070 	 * @type {boolean}
-1071 	 */
-1072 	this.empty = true;
-1073 	/**
-1074 	 * Is false if buffer is full, false otherwise.
-1075 	 * @type {boolean}
-1076 	 */
-1077 	this.full = false;
-1078 	/**
-1079 	 * The size of the buffer.
-1080 	 * @type {Number}
-1081 	 */
-1082 	this.size = size;
-1083 }
-1084 
-1085 /**
-1086  * Returns the iterator relative to the aggregate.
-1087  * @return {Iterator} The iterator.
-1088  */
-1089 CircularBuffer.prototype.getIterator = function () {
-1090 	return new CircularBufferIterator(this);
-1091 };
-1092 
-1093 /**
-1094  * Writes the item at the head of the buffer.
-1095  * @param item {*} The item to write.
-1096  * @return {void}
-1097  */
-1098 CircularBuffer.prototype.write = function (item) {
-1099 	this.empty = false;
-1100 	if (this.full)
-1101 	//if buffer is full tail must be set forward
-1102 		this.tail = (this.tail + 1) % this.size;
-1103 	this.items[this.head] = item;
-1104 	//head is set forward
-1105 	this.head = (this.head + 1) % this.size;
-1106 	if (this.tail === this.head)
-1107 		this.full = true;
-1108 };
-1109 
-1110 /**
-1111  * Frees the buffer between indexes from and to.
-1112  * If from > to, positions between from and the end of the buffer and between the start and to will be free.
-1113  * @param from {Number} The index from which start to free (inclusive index)
-1114  * @param to {Number} The index where stop to free (exclusive index)
-1115  * @return {void}
-1116  */
-1117 CircularBuffer.prototype.free = function (from, to) {
-1118 	if (from < 0)
-1119 		from = 0;
-1120 	if (from > this.size - 1)
-1121 		from = this.size - 1;
-1122 	if (to < 0)
-1123 		to = 0;
-1124 	if (to > this.size - 1)
-1125 		to = this.size - 1;
-1126 	//if from < to then will be free allocation between from and to
-1127 	//otherwise will be free allocations between from and the end and between the start and to
-1128 	for (var i = from; i < to; i = (i + 1) % this.size)
-1129 		delete this.items[i];
-1130 
-1131 	//adjust the position of the tail and of the head
-1132 	if (this.tail > from - 1 || this.tail < to)
-1133 		if (this.tail < this.head) {
-1134 			this.tail = (from - 1) % this.size;
-1135 		} else {
-1136 			this.tail = to;
-1137 		}
-1138 	if (this.head > from || this.head < to)
-1139 		if (this.tail < this.head) {
-1140 			this.head = to;
-1141 		} else {
-1142 			this.head = from;
-1143 		}
-1144 	//check if something is free
-1145 	if (from !== to)
-1146 		this.full = false;
-1147 	//free could make buffer empty
-1148 	for (var j = 0; j < this.size; j++)
-1149 		if (this.items[j] !== undefined) {
-1150 			this.empty = false;
-1151 			return;
-1152 		}
-1153 	this.empty = true;
-1154 };
-1155 
-1156 /**
-1157  * Frees all the buffer.
-1158  * @return {void}
-1159  */
-1160 CircularBuffer.prototype.freeAll = function () {
-1161 	for (var i = 0; i < this.size; i++)
-1162 		delete this.items[i];
-1163 	this.empty = true;
-1164 	this.head = 0;
-1165 	this.tail = 0;
-1166 };
-1167 
-1168 /**
-1169  * Reads the item stored at the position index.
-1170  * @param index {Number} The position of the item to read.
-1171  * @return {*} The item read.
-1172  */
-1173 CircularBuffer.prototype.read = function (index) {
-1174 	return this.items[index % this.size];
-1175 };
-1176 
-1177 /**
-1178  * Returns true if the buffer is empty, false otherwise.
-1179  * @return {boolean}
-1180  */
-1181 CircularBuffer.prototype.isEmpty = function () {
-1182 	return this.empty;
-1183 };
-1184 
-1185 /**
-1186  * Returns true if the buffer is full, false otherwise.
-1187  * @return {boolean}
-1188  */
-1189 CircularBuffer.prototype.isFull = function () {
-1190 	return this.full;
-1191 };
-1192 
-1193 /**
-1194  * Clones the circular buffer into a new circular buffer.
-1195  * @return {CircularBuffer} The circular buffer cloned from this circular buffer.
-1196  */
-1197 CircularBuffer.prototype.clone = function () {
-1198 	var buffer = new CircularBuffer(this.size);
-1199 	buffer.head = this.head;
-1200 	buffer.tail = this.tail;
-1201 	for (var i = 0; i < this.items.length; i++)
-1202 		buffer.items[i] = this.items[i];
-1203 	buffer.empty = this.empty;
-1204 	buffer.full = this.full;
-1205 	return buffer;
-1206 };
-1207 
-1208 /**
-1209  * Resize the buffer.
-1210  * @param size {number} The new size of the buffer.
-1211  * @return {void}
-1212  */
-1213 CircularBuffer.prototype.resize = function (size) {
-1214 	if (this.size < size) {
-1215 		if (this.head < this.tail + 1) {
-1216 			for (var i = 0; i < this.head; i++) {
-1217 				this.items[(i + this.size) % size] = this.items[i];
-1218 				delete this.items[i];
-1219 			}
-1220 			this.head = (this.head + this.size) % size;
-1221 		}
-1222 	} else if (this.size > size) {
-1223 		if (this.head < this.tail + 1) {
-1224 			//check if the tail is after the size
-1225 			var start = size;
-1226 			if (this.tail > size - 1) {
-1227 				start = this.tail;
-1228 				this.tail = 0;
-1229 			}
-1230 			//the items stored must be shift to a valid position
-1231 			var step = this.size - start;
-1232 			for (var j = this.head - step - 1; j > start - 1 || j < this.head - step; j--) {
-1233 				this.items[(j + step) % this.size] = this.items[j];
-1234 				if (!j)
-1235 					j = this.size;
-1236 			}
-1237 			this.head = (this.head + step) % this.size;
-1238 		}
-1239 	}
-1240 	this.size = size;
-1241 };
-1242 
-1243 /**
-1244  * Class that implements the iterator for a circular buffer.
-1245  * @param aggregate {CircularBuffer} The aggregate to scan.
-1246  * @constructor
-1247  */
-1248 function CircularBufferIterator(aggregate) {
-1249 	/**
-1250 	 * The aggregate relates to this iterator.
-1251 	 * @type {CircularBuffer}
-1252 	 */
-1253 	this.aggregate = aggregate;
-1254 
-1255 	/**
-1256 	 * The pointer to the position.
-1257 	 * @type {number|null}
-1258 	 */
-1259 	this.pointer = null;
-1260 	/**
-1261 	 * Discriminator for full buffer
-1262 	 * @type {bool}
-1263 	 */
-1264 	this.start = true;
-1265 }
-1266 
-1267 /**
-1268  * Moves the iterator to the first position of the aggregate.
-1269  * @return {void}
-1270  */
-1271 CircularBufferIterator.prototype.first = function () {
-1272 	this.pointer = this.aggregate.tail;
-1273 	this.start = true;
-1274 };
-1275 
-1276 /**
-1277  * Moves the iterator to the next item.
-1278  * @return {void}
-1279  */
-1280 CircularBufferIterator.prototype.next = function () {
-1281 	this.pointer = (this.pointer + 1) % this.aggregate.size;
-1282 	this.start = false;
-1283 };
-1284 
-1285 /**
-1286  * Moves the iterator to the last position of the aggregate.
-1287  * @return {void}
-1288  */
-1289 CircularBufferIterator.prototype.last = function () {
-1290 	this.pointer = (this.aggregate.head - 1) % this.aggregate.size;
-1291 	this.start = true;
-1292 };
-1293 
-1294 /**
-1295  * Moves the iterator to the previous item.
-1296  * @return {void}
-1297  */
-1298 CircularBufferIterator.prototype.previous = function () {
-1299 	this.pointer = (this.pointer - 1) % this.aggregate.size;
-1300 	this.start = false;
-1301 };
-1302 
-1303 /**
-1304  * Checks if the iterator is out of the bounds of the aggregate.
-1305  * @return {boolean} It return true if the iterator is out of the bounds of the aggregate, otherwise false.
-1306  */
-1307 CircularBufferIterator.prototype.isDone = function () {
-1308 	return (this.pointer === this.aggregate.head && !this.start) || (this.pointer === this.aggregate.tail - 1) % this.aggregate.size || this.aggregate.isEmpty();
-1309 };
-1310 
-1311 /**
-1312  * Returns the item stored at the position pointed by the iterator.
-1313  * @return {*} The item stored or undefined if it's out of the bounds.
-1314  */
-1315 CircularBufferIterator.prototype.getItem = function () {
-1316 	return this.aggregate.read(this.pointer);
-1317 };
-1318 
-1319 /**
-1320  * Class for managing a double linked list.
-1321  * @param {...*} [args] The items for initializing the list.
-1322  * @constructor
-1323  */
-1324 function DoubleLinkedList(args) {
-1325 	/**
-1326 	 * The first node of the list.
-1327 	 * @type {DLLNode|null}
-1328 	 */
-1329 	this.first = null;
-1330 	/**
-1331 	 * The last node of the list.
-1332 	 * @type {DLLNode|null}
-1333 	 */
-1334 	this.last = null;
-1335 	/**
-1336 	 * The length of the list.
-1337 	 * @type {number}
-1338 	 */
-1339 	this.length = 0;
-1340 	//builds the list from the parameters of the constructor
-1341 	this.fromArray(arguments);
-1342 }
-1343 
-1344 /**
-1345  * Returns the iterator relative to the aggregate.
-1346  * @return {Iterator} The iterator.
-1347  */
-1348 DoubleLinkedList.prototype.getIterator = function () {
-1349 	return new DoubleLinkedListIterator(this);
-1350 };
-1351 
-1352 /**
-1353  * Adds an item at the head of the list.
-1354  * @param item {*} The item to add.
-1355  * @return {void}
-1356  */
-1357 DoubleLinkedList.prototype.pushFront = function (item) {
-1358 	var node = new DLLNode(item);
-1359 	node.next = this.first;
-1360 	this.first = node;
-1361 	//link the next node to the new node
-1362 	if (node.next)
-1363 		node.next.previous = node;
-1364 	else
-1365 		this.last = node;
-1366 	this.length++;
-1367 };
-1368 
-1369 /**
-1370  * Adds an item at the tail of the list.
-1371  * @param item {*} The item to add.
-1372  * @return {void}
-1373  */
-1374 DoubleLinkedList.prototype.pushBack = function (item) {
-1375 	var node = new DLLNode(item);
-1376 	node.previous = this.last;
-1377 	this.last = node;
-1378 	//link the previous node to the new node
-1379 	if (node.previous)
-1380 		node.previous.next = node;
-1381 	else
-1382 		this.first = node;
-1383 	this.length++;
-1384 };
-1385 
-1386 /**
-1387  * Removes the first item of the list.
-1388  * @return {*} The item removed. It's undefined if the list is empty.
-1389  */
-1390 DoubleLinkedList.prototype.popFront = function () {
-1391 	if (this.length) {
-1392 		var node = this.first;
-1393 		this.first = node.next;
-1394 		if (node.next)
-1395 			node.next.previous = null;
-1396 		this.length--;
-1397 		node.next = null;
-1398 		return node.item;
-1399 	}
-1400 	return undefined;
-1401 };
-1402 
-1403 /**
-1404  * Removes the last item of the list.
-1405  * @return {*} The item removed. It's undefined if the list is empty.
-1406  */
-1407 DoubleLinkedList.prototype.popBack = function () {
-1408 	if (this.length) {
-1409 		var node = this.last;
-1410 		this.last = node.previous;
-1411 		if (node.previous)
-1412 			node.previous.next = null;
-1413 		this.length--;
-1414 		node.previous = null;
-1415 		return node.item;
-1416 	}
-1417 	return undefined;
-1418 };
-1419 
-1420 /**
-1421  * Removes the first times items of the list.
-1422  * @param times {number} The number of times to repeat the popFront method.
-1423  * @return {*} The item removed. It's undefined if the list is empty.
-1424  */
-1425 DoubleLinkedList.prototype.multiPopFront = function (times) {
-1426 	var result = [];
-1427 	for (var i = 0; i < times && this.length; i++)
-1428 		result.push(this.popFront());
-1429 	return result;
-1430 };
-1431 
-1432 /**
-1433  * Removes the last times items of the list.
-1434  * @param times {number} The number of times to repeat the popBack method.
-1435  * @return {*} The items removed.
-1436  */
-1437 DoubleLinkedList.prototype.multiPopBack = function (times) {
-1438 	var result = [];
-1439 	for (var i = 0; i < times && this.length; i++)
-1440 		result.push(this.popBack());
-1441 	return result;
-1442 };
-1443 
-1444 /**
-1445  * Returns the first item of the list without remove it.
-1446  * @return {*} The item at the top of the list. It's undefined if the list is empty.
-1447  */
-1448 DoubleLinkedList.prototype.peek = function () {
-1449 	if (!this.length)
-1450 		return undefined;
-1451 	return this.first.item;
-1452 };
-1453 
-1454 /**
-1455  * Adds the item at the index position.
-1456  * @param item {*} The item to add.
-1457  * @param index {number} The position where to add the item. If index is negative, the item won't be added.
-1458  * @return {void}
-1459  */
-1460 DoubleLinkedList.prototype.addAt = function (item, index) {
-1461 	if (index < -1)
-1462 		return;
-1463 	if (!index) {
-1464 		this.pushFront(item);
-1465 		return;
-1466 	}
-1467 	if (index === this.length) {
-1468 		this.pushBack(item);
-1469 		return;
-1470 	}
-1471 	var node = this.first;
-1472 	if (!node && index > 0)
-1473 		this.pushBack(undefined);
-1474 	for (var i = 0; i < index - 1; i++, node = node.next) {
-1475 		if (node === this.last)
-1476 			this.pushBack(undefined);
-1477 	}
-1478 	if (node === this.last)
-1479 		this.pushBack(item);
-1480 	else if (node === this.first)
-1481 		this.pushFront(item);
-1482 	else {
-1483 		var newNode = new DLLNode(item);
-1484 		newNode.next = node.next;
-1485 		newNode.previous = node;
-1486 		node.next = newNode;
-1487 		if (newNode.next)
-1488 			newNode.next.previous = newNode;
-1489 		this.length++;
-1490 	}
-1491 };
-1492 
-1493 /**
-1494  * Removes the item at the position index.
-1495  * @param index {Number} The position of the item to remove.
-1496  * @return {*} The item stored at the position index. It's undefined if the index is out of bounds.
-1497  */
-1498 DoubleLinkedList.prototype.removeAt = function (index) {
-1499 	if (index < 0 || index > this.length - 1)
-1500 		return undefined;
-1501 	if (index === 0)
-1502 		return this.popFront();
-1503 	if (index === this.length - 1)
-1504 		return this.popBack();
-1505 	var node = this.first;
-1506 	for (; index > 0; index--)
-1507 		node = node.next;
-1508 	//now node is the node to remove
-1509 	node.previous.next = node.next;
-1510 	node.next.previous = node.previous;
-1511 	node.next = null;
-1512 	node.previous = null;
-1513 	this.length--;
-1514 	return node.item;
-1515 };
-1516 
-1517 /**
-1518  * Removes the item from the list.
-1519  * @param item {*} The item to remove.
-1520  * @param [callback = function(item){return(it===item);}] The condition to satisfy. The callback must accept the current item to check.
-1521  * @return {void}
-1522  */
-1523 DoubleLinkedList.prototype.remove = function (item, callback) {
-1524 	callback = callback || function (it) {
-1525 		return it === item;
-1526 	};
-1527 	var node = this.first;
-1528 	var previous = null;
-1529 	while (node) {
-1530 		if (callback(node.item)) {
-1531 			if (node === this.first)
-1532 				this.first = node.next;
-1533 			if (node === this.last)
-1534 				this.last = previous;
-1535 			if (previous) {
-1536 				previous.next = node.next;
-1537 				if (node.next)
-1538 					node.next.previous = previous;
-1539 			}
-1540 			return;
-1541 		}
-1542 		previous = node;
-1543 		node = node.next;
-1544 	}
-1545 };
-1546 
-1547 /**
-1548  * Removes all the item from the list.
-1549  * @param item {*} The item to remove.
-1550  * @param [callback = function(item){return(it===item);}] The condition to satisfy. The callback must accept the current item to check.
-1551  * @return {void}
-1552  */
-1553 DoubleLinkedList.prototype.removeAll = function (item, callback) {
-1554 	callback = callback || function (it) {
-1555 		return it === item;
-1556 	};
-1557 	var node = this.first;
-1558 	var previous = null;
-1559 	while (node) {
-1560 		if (callback(node.item)) {
-1561 			if (node === this.first)
-1562 				this.first = node.next;
-1563 			if (node === this.last)
-1564 				this.last = previous;
-1565 			if (previous) {
-1566 				previous.next = node.next;
-1567 				if (node.next)
-1568 					node.next.previous = previous;
-1569 			}
-1570 		} else
-1571 			previous = node;
-1572 		node = node.next;
-1573 	}
-1574 };
-1575 
-1576 /**
-1577  * Removes all the items stored from the from position to the to position.
-1578  * If from > to, the method will remove all the items up to the end.
-1579  * @param from {number} The position where start to remove the items. The from position is included.
-1580  * @param to {number} The position where stop to remove the items. The to position is included.
-1581  * @return {Array<*>} The items removed.
-1582  */
-1583 DoubleLinkedList.prototype.removeSegment = function (from, to) {
-1584 	var result = [];
-1585 	if (to > -1 && from < this.length) {
-1586 		if (from === 0)
-1587 			return this.multiPopFront(to + 1);
-1588 		if (to === this.length - 1 || from > to)
-1589 			return this.multiPopBack(Math.max(to - from, this.length - from)).reverse();
-1590 		var node = this.first;
-1591 		for (var i = 0; i < from - 1; i++)
-1592 			node = node.next;
-1593 		//now node is the node before the node to remove
-1594 		//node to remove
-1595 		var next = node.next;
-1596 		for (var j = from; j < to + 1 && j < this.length; j++) {
-1597 			result.push(next.item);
-1598 			next = next.next;
-1599 		}
-1600 		this.length -= Math.min(to - from + 1, this.length - from);
-1601 		node.next = next;
-1602 		next.previous = node;
-1603 	}
-1604 	return result;
-1605 };
-1606 
-1607 /**
-1608  * Changes the item stored in the index position. If the index is out of bound, the node won't be updated.
-1609  * @param index {number} The position of the node to modify.
-1610  * @param item {*} The new item stored in the node.
-1611  * @return {void}
-1612  */
-1613 DoubleLinkedList.prototype.modifyAt = function (index, item) {
-1614 	var node = this.getNode(index);
-1615 	if (node)
-1616 		node.item = item;
-1617 };
-1618 
-1619 /**
-1620  * Removes all the items stored in the list.
-1621  * @return {void}
-1622  */
-1623 DoubleLinkedList.prototype.clear = function () {
-1624 	this.first = null;
-1625 	this.last = null;
-1626 	this.length = 0;
-1627 };
-1628 
-1629 /**
-1630  * Checks if the list contains an item that satisfy the condition represented by the callback function.
-1631  * @param item {*} The item to find.
-1632  * @param [callback = function(item){return(it===item);}] The condition to satisfy. The callback must accept the current item to check.
-1633  * @return {boolean} True if the list contains the item that satisfy the condition, false otherwise.
-1634  */
-1635 DoubleLinkedList.prototype.contains = function (item, callback) {
-1636 	callback = callback || function (it) {
-1637 		return it === item;
-1638 	};
-1639 	var i = 0;
-1640 	var node = this.first;
-1641 	while (i < this.length && !callback(node.item)) {
-1642 		i++;
-1643 		node = node.next;
-1644 	}
-1645 	return i < this.length;
-1646 };
-1647 
-1648 /**
-1649  * Executes the callback function for each item of the stack.
-1650  * This method modifies the list so if you don't need to modify it you must return the same item of the array.
-1651  * @param callback {function} The function to execute for each item. The function must accept the current item on which execute the function.
-1652  * @return {void}
-1653  */
-1654 DoubleLinkedList.prototype.execute = function (callback) {
-1655 	var node = this.first;
-1656 	while (node) {
-1657 		node.item = callback(node.item);
-1658 		node = node.next;
-1659 	}
-1660 };
-1661 
-1662 /**
-1663  * Deletes the node from the list.
-1664  * @param node {DLLNode} The node to delete.
-1665  * @return {void}
-1666  */
-1667 DoubleLinkedList.prototype.deleteNode = function (node) {
-1668 	if (node === this.first) {
-1669 		this.popFront();
-1670 		return;
-1671 	}
-1672 	if (node === this.last) {
-1673 		this.popBack();
-1674 		return;
-1675 	}
-1676 	node.previous.next = node.next;
-1677 	node.next.previous = node.previous;
-1678 	this.length--;
-1679 };
-1680 
-1681 /**
-1682  * Gets the node at the position index relative from the node.
-1683  * @param index {Number} The index, relative to the node, of the node to return.
-1684  * @param [node = first] {DLLNode} The node from which start the search.
-1685  * @return {DLLNode} The node at the position index.
-1686  */
-1687 DoubleLinkedList.prototype.getNode = function (index, node) {
-1688 	if (index < 0 || index > this.length - 1)
-1689 		return undefined;
-1690 	var m = Math.floor(this.length / 2);
-1691 	//if the index is less than the middle, the search start from the head of the list, otherwise from the tail of the list
-1692 	if (index < m || node) {
-1693 		node = node || this.first;
-1694 		for (; index > 0; index--)
-1695 			node = node.next;
-1696 	} else
-1697 		for (index = this.length - index - 1, node = this.last; index > 0; index--)
-1698 			node = node.previous;
-1699 	return node;
-1700 };
-1701 
-1702 /**
-1703  * Gets the item at the position index.
-1704  * @param index {Number} The position of the item.
-1705  * @return {*}. It's undefined if index isn't in the queue bounds.
-1706  */
-1707 DoubleLinkedList.prototype.getItem = function (index) {
-1708 	if (index < 0 || index > this.length - 1)
-1709 		return undefined;
-1710 	var node;
-1711 	var m = Math.floor(this.length / 2);
-1712 	if (index < m) //if the index is less than the middle, the search start from the head of the list, otherwise from the tail of the list
-1713 		for (node = this.first; index > 0; index--)
-1714 			node = node.next;
-1715 	else
-1716 		for (index = this.length - index - 1, node = this.last; index > 0; index--)
-1717 			node = node.previous;
-1718 	return node.item;
-1719 };
-1720 
-1721 /**
-1722  * Sorts the list using web workers.
-1723  * Using this method is discouraged. Many web browser set a limit to the maximum number of workers instantiated.
-1724  * The items of the list, due to web workers implementation, will be serialized so they will lost own methods.
-1725  * @return {void}
-1726  */
-1727 DoubleLinkedList.prototype.parallelSort = function () {
-1728 
-1729 	var workers = [];
-1730 	var _array = this.toArray();
-1731 	console.log(_array);
-1732 
-1733 	function partialSort(_from, _to, _id) {
-1734 		if (_from < _to) {
-1735 			var m = Math.floor((_from + _to) / 2);
-1736 			var workerLeft = new Worker("DoubleLinkedList/WorkerSort.js");
-1737 			var workerRight = new Worker("DoubleLinkedList/WorkerSort.js");
-1738 			workers.push(workerLeft);
-1739 			workers.push(workerRight);
-1740 			var length = workers.length;
-1741 			workerLeft.postMessage({cmd: 'start', from: _from, to: m, worker: _id});
-1742 			workerRight.postMessage({cmd: 'start', from: m + 1, to: _to, worker: _id});
-1743 			partialSort(_from, m, length - 2);
-1744 			partialSort(m + 1, _to, length - 1);
-1745 			workerLeft.onmessage = function (event) {
-1746 				var data = event.data;
-1747 				switch (data.cmd) {
-1748 					case 'finished':
-1749 						workers[data.worker].postMessage({cmd: 'finished', array: _array});
-1750 						break;
-1751 					case 'replace':
-1752 						_array[data.index] = data.value;
-1753 						break;
-1754 				}
-1755 			};
-1756 			workerRight.onmessage = function (event) {
-1757 				var data = event.data;
-1758 				switch (data.cmd) {
-1759 					case 'finished':
-1760 						workers[data.worker].postMessage({cmd: 'finished', array: _array});
-1761 						break;
-1762 					case 'replace':
-1763 						_array[data.index] = data.value;
-1764 						break;
-1765 				}
-1766 			}
-1767 		}
-1768 	}
-1769 
-1770 	var outerThis = this;
-1771 
-1772 	var mainWorker = new Worker("DoubleLinkedList/WorkerSort.js");
-1773 	workers.push(mainWorker);
-1774 	mainWorker.postMessage({cmd: 'start', from: 0, to: this.length - 1, worker: -1, array: _array});
-1775 	mainWorker.onmessage = function (event) {
-1776 		var data = event.data;
-1777 		switch (data.cmd) {
-1778 			case 'finished':
-1779 				outerThis.fromArray(_array);
-1780 				console.log(outerThis);
-1781 				break;
-1782 			case 'replace':
-1783 				_array[data.index] = data.value;
-1784 		}
-1785 	};
-1786 	partialSort(0, this.length - 1, 0);
-1787 };
-1788 
-1789 /**
-1790  * Sorts the list.
-1791  * @param [callback = function(item){return(item);}] {function} The function invoked in order to get the value for the evaluation of the sort criteria.
-1792  * @example
-1793  * callback = function(item) {return -item.key;}
-1794  * This function callback will return the opposite of the attribute key of the item. In this case the list will be sorted in descending order.
-1795  * @return {void}
-1796  */
-1797 DoubleLinkedList.prototype.sort = function (callback) {
-1798 
-1799 	if (!callback)
-1800 		callback = function (item) {
-1801 			return item;
-1802 		};
-1803 
-1804 	var outerThis = this;
-1805 
-1806 	function partialSort(from, to, fromNode, toNode) {
-1807 		if (from < to) {
-1808 			var m = Math.floor((from + to) / 2);
-1809 			var mNode = outerThis.getNode(m - from, fromNode);
-1810 			partialSort(from, m, fromNode, mNode);
-1811 			partialSort(m + 1, to, mNode.next, toNode);
-1812 			merge(from, m, to, fromNode);
-1813 		}
-1814 	}
-1815 
-1816 	function merge(from, m, to, fromNode) {
-1817 		var left = [];
-1818 		var right = [];
-1819 		var node = fromNode;
-1820 		for (var i = 0; i < m - from + 1; i++, node = node.next)
-1821 			left[i] = node.item;
-1822 		for (var j = 0; j < to - m; j++, node = node.next)
-1823 			right[j] = node.item;
-1824 		var x = 0, y = 0;
-1825 		for (var k = from; k < to + 1; k++, fromNode = fromNode.next) {
-1826 			if (y > to - m - 1 || (callback(left[x]) <= callback(right[y]) && x < m - from + 1)) {
-1827 				fromNode.item = left[x];
-1828 				x++;
-1829 			} else {
-1830 				fromNode.item = right[y];
-1831 				y++;
-1832 			}
-1833 		}
-1834 	}
-1835 
-1836 	partialSort(0, this.length - 1, this.first, this.last);
-1837 };
-1838 
-1839 /**
-1840  * Transforms the list into an array.
-1841  * @return {Array<*>} The array built.
-1842  */
-1843 DoubleLinkedList.prototype.toArray = function () {
-1844 	var array = [];
-1845 	for (var node = this.first, i = 0; node; node = node.next, i++)
-1846 		array[i] = node.item;
-1847 	return array;
-1848 };
-1849 
-1850 /**
-1851  * Returns the length of the list.
-1852  * @return {Number} The length of the list.
-1853  */
-1854 DoubleLinkedList.prototype.getLength = function () {
-1855 	return this.length;
-1856 };
-1857 
-1858 /**
-1859  * Builds the list from the array.
-1860  * @param array {Array<*>} The array from which build the list.
-1861  * @return {void}
-1862  */
-1863 DoubleLinkedList.prototype.fromArray = function (array) {
-1864 	var node = this.first;
-1865 	for (var i = 0; i < Math.min(this.length, array.length); i++, node = node.next)
-1866 		node.item = array[i];
-1867 	if (this.length < array.length)
-1868 		for (var j = this.length; j < array.length; j++)
-1869 			this.pushBack(array[j]);
-1870 	else
-1871 		for (var k = array.length; k < this.length;)
-1872 			this.popBack();
-1873 };
-1874 
-1875 /**
-1876  * Returns the items that satisfy the condition determined by the callback.
-1877  * @param callback {function} The function that implements the condition.
-1878  * @return {Array<Object>} The array that contains the items that satisfy the condition.
-1879  */
-1880 DoubleLinkedList.prototype.filter = function (callback) {
-1881 	var result = [];
-1882 	for (var node = this.first; node; node = node.next) {
-1883 		if (callback(node.item))
-1884 			result.push(node.item);
-1885 	}
-1886 	return result;
-1887 };
-1888 
-1889 /**
-1890  * Reverses the list. This method reverses only the items, not the nodes.
-1891  * @return {void}
-1892  */
-1893 DoubleLinkedList.prototype.reverse = function () {
-1894 	for (var start = this.first, end = this.last; start !== end && start.previous !== end; start = start.next, end = end.previous) {
-1895 		var item = start.item;
-1896 		start.item = end.item;
-1897 		end.item = item;
-1898 	}
-1899 };
-1900 
-1901 /**
-1902  * Checks if the list is empty.
-1903  * @return {boolean} True if the list is empty, false otherwise.
-1904  */
-1905 DoubleLinkedList.prototype.isEmpty = function () {
-1906 	return !this.length;
-1907 };
-1908 
-1909 /**
-1910  * Returns the first position of the item in the list.
-1911  * @param item {*} The item to search.
-1912  * @param [callback = function(item){return(it===item);}] The condition to satisfy. The callback must accept the current item to check.
-1913  * @return {number} The first position of the item.
-1914  */
-1915 DoubleLinkedList.prototype.indexOf = function (item, callback) {
-1916 	callback = callback || function (it) {
-1917 		return it === item;
-1918 	};
-1919 	var i = 0;
-1920 	var node = this.first;
-1921 	while (node) {
-1922 		if (callback(node.item))
-1923 			return i;
-1924 		i++;
-1925 		node = node.next;
-1926 	}
-1927 	return -1;
-1928 };
-1929 
-1930 /**
-1931  * Returns the last position of the item in the list.
-1932  * @param item {*} The item to search.
-1933  * @param [callback = function(item){return(it===item);}] The condition to satisfy. The callback must accept the current item to check.
-1934  * @return {number} The last position of the item.
-1935  */
-1936 DoubleLinkedList.prototype.lastIndexOf = function (item, callback) {
-1937 	callback = callback || function (it) {
-1938 		return it === item;
-1939 	};
-1940 	var i = this.length - 1;
-1941 	var node = this.last;
-1942 	while (node) {
-1943 		if (callback(node.item))
-1944 			return i;
-1945 		i--;
-1946 		node = node.previous;
-1947 	}
-1948 	return -1;
-1949 };
-1950 
-1951 /**
-1952  * Returns all the position in which the item has been found in the list.
-1953  * @param item {*} The item to search.
-1954  * @param [callback = function(item){return(it===item);}] The condition to satisfy. The callback must accept the current item to check.
-1955  * @return {Array<number>} The positions in which the item has been found.
-1956  */
-1957 DoubleLinkedList.prototype.allIndexesOf = function (item, callback) {
-1958 	callback = callback || function (it) {
-1959 		return it === item;
-1960 	};
-1961 	var i = 0;
-1962 	var node = this.first;
-1963 	var indexes = [];
-1964 	while (node) {
-1965 		if (callback(node.item))
-1966 			indexes.push(i);
-1967 		i++;
-1968 		node = node.next;
-1969 	}
-1970 	return indexes;
-1971 };
-1972 
-1973 /**
-1974  * Adds the list at the end of this list.
-1975  * @param list {DoubleLinkedList} The list to join.
-1976  * @return {void}
-1977  */
-1978 DoubleLinkedList.prototype.join = function (list) {
-1979 	if (this.last)
-1980 		this.last.next = list.first;
-1981 	else
-1982 		this.first = list.first;
-1983 	if (list.first)
-1984 		list.first.previous = this.last;
-1985 	this.last = list.last;
-1986 	this.length += list.length;
-1987 };
-1988 
-1989 /**
-1990  * Divides the list at the index position. The node at the index position is the first new node of the list.
-1991  * @param index {number} The position where to divide the list.
-1992  * @return {DoubleLinkedList} The list formed by the nodes from the index position then. If the index is out of bound, the list will be empty.
-1993  */
-1994 DoubleLinkedList.prototype.divide = function (index) {
-1995 	var list = new DoubleLinkedList();
-1996 	if (index > -1 && index < this.length) {
-1997 		var node = this.first;
-1998 		var previous = null;
-1999 		for (var i = 0; i < index; i++) {
-2000 			previous = node;
-2001 			node = node.next;
-2002 		}
-2003 		if (node === this.first) {
-2004 			list.first = this.first;
-2005 			list.last = this.last;
-2006 			this.first = null;
-2007 			this.last = null;
-2008 		} else {
-2009 			list.first = node;
-2010 			list.last = this.last;
-2011 			this.last = previous;
-2012 			previous.next = null;
-2013 			node.previous = null;
-2014 		}
-2015 		list.length = this.length - index;
-2016 		this.length = index;
-2017 	}
-2018 	return list;
-2019 };
-2020 
-2021 /**
-2022  * Clones the list into a new list.
-2023  * @return {DoubleLinkedList} The list cloned from this list.
-2024  */
-2025 DoubleLinkedList.prototype.clone = function () {
-2026 	var list = new DoubleLinkedList();
-2027 	var node = this.first;
-2028 	for (var i = 0; i < this.length; i++, node = node.next)
-2029 		if (node.item.clone)
-2030 			list.pushBack(node.item.clone());
-2031 		else
-2032 			list.pushBack(node.item);
-2033 	return list;
-2034 };
-2035 
-2036 /**
-2037  * Clones the list into a new list without cloning duplicated items.
-2038  * @return {DoubleLinkedList} The list cloned from this list.
-2039  */
-2040 DoubleLinkedList.prototype.cloneDistinct = function () {
-2041 	var list = new DoubleLinkedList();
-2042 	var node = this.first;
-2043 	for (var i = 0; i < this.length; i++, node = node.next)
-2044 		if (!list.contains(node.item))
-2045 			if (node.item.cloneDistinct)
-2046 				list.pushBack(node.item.cloneDistinct());
-2047 			else if (node.item.clone)
-2048 				list.pushBack(node.item.clone());
-2049 			else
-2050 				list.pushBack(node.item);
-2051 	return list;
-2052 };
-2053 
-2054 /**
-2055  * Splits the list into lists of desired size.
-2056  * @param size {number} The size of the lists.
-2057  * @return {Array<DoubleLinkedList>} The lists created by splitting the list.
-2058  */
-2059 DoubleLinkedList.prototype.split = function (size) {
-2060 	var length = this.length;
-2061 	var lists = [this];
-2062 	for (var i = size; i < length; i += size)
-2063 		lists.push(lists[lists.length - 1].divide(size));
-2064 	return lists;
-2065 };
-2066 
-2067 /**
-2068  * Returns the number of items that satisfy the represented by the callback function.
-2069  * @param callback {function} The condition to satisfy.
-2070  * @return {number} The number of items that satisfy the condition.
-2071  */
-2072 DoubleLinkedList.prototype.count = function (callback) {
-2073 	var count = 0;
-2074 	var node = this.first;
-2075 	while (node) {
-2076 		if (callback(node.item))
-2077 			count++;
-2078 		node = node.next;
-2079 	}
-2080 	return count;
-2081 };
-2082 
-2083 /**
-2084  * Class that implements the iterator for a double linked list.
-2085  * @param aggregate {DoubleLinkedList} The aggregate to scan.
-2086  * @constructor
-2087  */
-2088 function DoubleLinkedListIterator(aggregate) {
-2089 	/**
-2090 	 * The aggregate relates to this iterator.
-2091 	 * @type {DoubleLinkedList}
-2092 	 */
-2093 	this.aggregate = aggregate;
-2094 
-2095 	/**
-2096 	 * The pointer to the position.
-2097 	 * @type {Node|null}
-2098 	 */
-2099 	this.pointer = null;
-2100 }
-2101 
-2102 /**
-2103  * Moves the iterator to the first position of the aggregate.
-2104  * @return {void}
-2105  */
-2106 DoubleLinkedListIterator.prototype.first = function () {
-2107 	this.pointer = this.aggregate.first;
-2108 };
-2109 
-2110 /**
-2111  * Moves the iterator to the next item.
-2112  * @return {void}
-2113  */
-2114 DoubleLinkedListIterator.prototype.next = function () {
-2115 	this.pointer = this.pointer.next;
-2116 };
-2117 
-2118 /**
-2119  * Moves the iterator to the last position of the aggregate.
-2120  * @return {void}
-2121  */
-2122 DoubleLinkedListIterator.prototype.last = function () {
-2123 	this.pointer = this.aggregate.last;
-2124 };
-2125 
-2126 /**
-2127  * Moves the iterator to the previous item.
-2128  * @return {void}
-2129  */
-2130 DoubleLinkedListIterator.prototype.previous = function () {
-2131 	this.pointer = this.pointer.previous;
-2132 };
-2133 
-2134 /**
-2135  * Checks if the iterator is out of the bounds of the aggregate.
-2136  * @return {boolean} It return true if the iterator is out of the bounds of the aggregate, otherwise false.
-2137  */
-2138 DoubleLinkedListIterator.prototype.isDone = function () {
-2139 	return !this.pointer;
-2140 };
-2141 
-2142 /**
-2143  * Returns the item stored at the position pointed by the iterator.
-2144  * @abstract
-2145  * @return {*} The item stored or undefined if it's out of the bounds.
-2146  */
-2147 DoubleLinkedListIterator.prototype.getItem = function () {
-2148 	return this.pointer.item;
-2149 };
-2150 
-2151 /**
-2152  * Returns the node stored at the position pointed by the iterator.
-2153  * @abstract
-2154  * @return {DLLNode|null} The node stored or null if it's out of the bounds.
-2155  */
-2156 DoubleLinkedListIterator.prototype.getNode = function () {
-2157 	return this.pointer;
-2158 };
-2159 
-2160 /**
-2161  * Class for managing an hash table.
-2162  * @param size {number} The size of the table.
-2163  * @constructor
-2164  */
-2165 function HashTable(size) {
-2166 	/**
-2167 	 * The size of the table
-2168 	 * @type {number}
-2169 	 */
-2170 	this.size = size;
-2171 
-2172 	this.p = 1000;
-2173 
-2174 	this.a = Math.floor(Math.random() * this.p);
-2175 
-2176 	this.b = Math.floor(Math.random() * this.p);
-2177 
-2178 	/**
-2179 	 * Calculate the hash of the param key.
-2180 	 * @param key {number} The key to hash.
-2181 	 * @return {number} The hash of the key.
-2182 	 */
-2183 	this.hash = function (key) {
-2184 		return ((this.a * key + this.b) % this.p) % this.size;
-2185 	};
-2186 
-2187 	/**
-2188 	 * The items stored in the hash table.
-2189 	 * @type {Array<DoubleLinkedList>}
-2190 	 */
-2191 	this.items = [];
-2192 
-2193 	/**
-2194 	 * The number of keys stored in the hash table.
-2195 	 * @type {number}
-2196 	 */
-2197 	this.keyLength = 0;
-2198 
-2199 	this.clear();
-2200 }
-2201 
-2202 /**
-2203  * Stores the item with its key.
-2204  * @param key {number} The key relatives to the item.
-2205  * @param item {*} The item to store.
-2206  */
-2207 HashTable.prototype.insert = function (key, item) {
-2208 	this.keyLength++;
-2209 	this.items[this.hash(key)].pushBack({key: key, item: item});
-2210 };
-2211 
-2212 /**
-2213  * Deletes the first item relatives to the key value.
-2214  * @param key {number} The key to delete.
-2215  * @return {void}
-2216  */
-2217 HashTable.prototype.deleteKey = function (key) {
-2218 	var list = this.items[this.hash(key)];
-2219 	var it = list.getIterator();
-2220 	for (it.first(); !it.isDone() && it.getItem().key !== key;)
-2221 		it.next();
-2222 	if (!it.isDone()) {
-2223 		list.deleteNode(it.getNode());
-2224 		this.keyLength--;
-2225 	}
-2226 };
-2227 
-2228 /**
-2229  * Deletes all the items relative to the key value.
-2230  * @param key {number} The key to delete.
-2231  * @return {void}
-2232  */
-2233 HashTable.prototype.deleteAllKey = function (key) {
-2234 	var list = this.items[this.hash(key)];
-2235 	var it = list.getIterator();
-2236 	var keysRemoved = 0;
-2237 	for (it.first(); !it.isDone(); it.next())
-2238 		if (it.getItem().key === key) {
-2239 			list.deleteNode(it.getNode());
-2240 			keysRemoved++;
-2241 		}
-2242 	this.keyLength -= keysRemoved;
-2243 };
-2244 
-2245 /**
-2246  * Searches the item relative to the key value.
-2247  * @param key {number} The key of the item to search.
-2248  * @return {*|undefined} The item found or undefined if the key does not exist.
-2249  */
-2250 HashTable.prototype.search = function (key) {
-2251 	var list = this.items[this.hash(key)];
-2252 	var it = list.getIterator();
-2253 	for (it.first(); !it.isDone(); it.next())
-2254 		if (it.getItem().key === key)
-2255 			return it.getItem().item;
-2256 	return undefined;
-2257 };
-2258 
-2259 /**
-2260  * Checks if the hash table contains a key that satisfy the condition represented by the callback function.
-2261  * @param key {number} The key to find.
-2262  * @param [callback = function(k){return(k===key);}] The condition to satisfy. The callback must accept the current key to check.
-2263  * @return {boolean} True if the hash table contains the key that satisfy the condition, false otherwise.
-2264  */
-2265 HashTable.prototype.containsKey = function (key, callback) {
-2266 	callback = callback || function (k) {
-2267 		return k === key;
-2268 	};
-2269 	var list = this.items[this.hash(key)];
-2270 	var it = list.getIterator();
-2271 	for (it.first(); !it.isDone(); it.next())
-2272 		if (callback(it.getItem().key))
-2273 			return true;
-2274 	return false;
-2275 };
-2276 
-2277 /**
-2278  * Searches all the items relative to the key value.
-2279  * @param key {number} The key of the items to search.
-2280  * @return {Array.<*>} An array with the items found.
-2281  */
-2282 HashTable.prototype.searchAll = function (key) {
-2283 	var list = this.items[this.hash(key)];
-2284 	var it = list.getIterator();
-2285 	var array = [];
-2286 	for (it.first(); !it.isDone(); it.next())
-2287 		if (it.getItem().key === key)
-2288 			array.push(it.getItem().item);
-2289 	return array;
-2290 };
-2291 
-2292 /**
-2293  * Returns the keys stored in the hash table.
-2294  * @return {Array<number>} The keys stored in the table.
-2295  */
-2296 HashTable.prototype.getKeys = function () {
-2297 	var keys = [];
-2298 	for (var i = 0; i < this.size; i++) {
-2299 		var it = this.items[i].getIterator();
-2300 		for (it.first(); !it.isDone(); it.next())
-2301 			keys.push(it.getItem().key);
-2302 	}
-2303 	return keys;
-2304 };
-2305 
-2306 /**
-2307  * Returns the items stored in the hash table.
-2308  * @return {Array<*>} The items stored in the table.
-2309  */
-2310 HashTable.prototype.getItems = function () {
-2311 	var items = [];
-2312 	for (var i = 0; i < this.size; i++) {
-2313 		var it = this.items[i].getIterator();
-2314 		for (it.first(); !it.isDone(); it.next())
-2315 			items.push(it.getItem().item);
-2316 	}
-2317 	return items;
-2318 };
-2319 
-2320 /**
-2321  * Removes all the keys and the items stored in the hash table.
-2322  * @return {void}
-2323  */
-2324 HashTable.prototype.clear = function () {
-2325 	this.items = [];
-2326 	for (var i = 0; i < this.size; i++)
-2327 		this.items[i] = new DoubleLinkedList();
-2328 	this.keyLength = 0;
-2329 };
-2330 
-2331 /**
-2332  * Returns the number of keys stored in the hash table.
-2333  * @return {number} The number of keys stored.
-2334  */
-2335 HashTable.prototype.getNumberOfKeys = function () {
-2336 	return this.keyLength;
-2337 };
-2338 
-2339 /**
-2340  * Checks if the hash table is empty.
-2341  * @return {boolean} True if the hash table is empty, false otherwise.
-2342  */
-2343 HashTable.prototype.isEmpty = function () {
-2344 	return !this.keyLength;
-2345 };
-2346 
-2347 /**
-2348  * Executes the callback function for each item of the hash table.
-2349  * This method modifies the hash table so if you don't need to modify it you must return the same item stored.
-2350  * @param callback {function} The function to execute for each item. The function must accept the current item on which execute the function.
-2351  * @return {void}
-2352  */
-2353 HashTable.prototype.execute = function (callback) {
-2354 	for (var i = 0; i < this.size; i++)
-2355 		this.items[i].execute(callback);
-2356 };
-2357 
-2358 /**
-2359  * Returns the items that satisfy the condition determined by the callback.
-2360  * @param callback {function} The function that implements the condition.
-2361  * @return {Array<*>} The array that contains the items that satisfy the condition.
-2362  */
-2363 HashTable.prototype.filter = function (callback) {
-2364 	var result = [];
-2365 	for (var i = 0; i < this.size; i++)
-2366 		result.concat(this.items[i].filter(callback));
-2367 	return result;
-2368 };
-2369 
-2370 /**
-2371  * Returns the size of the hash table.
-2372  * @return {number} The size of the hash table.
-2373  */
-2374 HashTable.prototype.getSize = function () {
-2375 	return this.size;
-2376 };
-2377 
-2378 /**
-2379  * Clones the hash table into a new hash table.
-2380  * @return {HashTable} The hash table cloned from this hash table.
-2381  */
-2382 HashTable.prototype.clone = function () {
-2383 	var table = new HashTable(this.size);
-2384 	for (var i = 0; i < this.size; i++)
-2385 		for (var node = this.items[i].first; node; node = node.next)
-2386 			table.insert(node.key, node.item);
-2387 	return table;
-2388 };
-2389 
-2390 /**
-2391  * Class for managing a linked list.
-2392  * @param {...*} [args] The items for initializing the list.
-2393  * @constructor
-2394  */
-2395 function LinkedList(args) {
-2396 	/**
-2397 	 * The first node of the list.
-2398 	 * @type {LLNode|null}
-2399 	 */
-2400 	this.first = null;
-2401 	/**
-2402 	 * The last node of the list.
-2403 	 * @type {LLNode|null}
-2404 	 */
-2405 	this.last = null;
-2406 	/**
-2407 	 * The length of the list.
-2408 	 * @type {number}
-2409 	 */
-2410 	this.length = 0;
-2411 	//builds the list from the parameters of the constructor
-2412 	this.fromArray(arguments);
-2413 }
-2414 
-2415 /**
-2416  * Returns the iterator relative to the aggregate.
-2417  * @return {Iterator} The iterator.
-2418  */
-2419 LinkedList.prototype.getIterator = function () {
-2420 	return new LinkedListIterator(this);
-2421 };
-2422 
-2423 /**
-2424  * Adds an item at the head of the list.
-2425  * @param item {*} The item to add.
-2426  * @return {void}
-2427  */
-2428 LinkedList.prototype.pushFront = function (item) {
-2429 	var node = new LLNode(item);
-2430 	node.next = this.first;
-2431 	this.first = node;
-2432 	if (!this.last)
-2433 		this.last = node;
-2434 	this.length++;
-2435 };
-2436 
-2437 /**
-2438  * Adds an item at the tail of the list.
-2439  * @param item {*} The item to add.
-2440  * @return {void}
-2441  */
-2442 LinkedList.prototype.pushBack = function (item) {
-2443 	var node = new LLNode(item);
-2444 	if (this.last)
-2445 		this.last.next = node;
-2446 	else
-2447 		this.first = node;
-2448 	this.last = node;
-2449 	this.length++;
-2450 };
-2451 
-2452 /**
-2453  * Removes the first item of the list.
-2454  * @return {*} The item removed. It's undefined if the list is empty.
-2455  */
-2456 LinkedList.prototype.popFront = function () {
-2457 	if (this.length) {
-2458 		var node = this.first;
-2459 		this.first = this.first.next;
-2460 		this.length--;
-2461 		node.next = null;
-2462 		return node.item;
-2463 	}
-2464 	return undefined;
-2465 };
-2466 
-2467 /**
-2468  * Removes the last item of the list.
-2469  * @return {*} The item removed. It's undefined if the list is empty.
-2470  */
-2471 LinkedList.prototype.popBack = function () {
-2472 	if (this.length) {
-2473 		var node = this.last;
-2474 		var next = this.first;
-2475 		while (next.next && next.next.next) {
-2476 			next = next.next;
-2477 		}
-2478 		if (node === next)
-2479 			this.last = null;
-2480 		else
-2481 			this.last = next;
-2482 		next.next = null;
-2483 		this.length--;
-2484 		return node.item;
-2485 	}
-2486 	return undefined;
-2487 };
-2488 
-2489 /**
-2490  * Removes the first times items of the list.
-2491  * @param times {number} The number of times to repeat the popFront method.
-2492  * @return {*} The item removed. It's undefined if the list is empty.
-2493  */
-2494 LinkedList.prototype.multiPopFront = function (times) {
-2495 	var result = [];
-2496 	for (var i = 0; i < times && this.length; i++)
-2497 		result.push(this.popFront());
-2498 	return result;
-2499 };
-2500 
-2501 /**
-2502  * Removes the last times items of the list.
-2503  * @param times {number} The number of times to repeat the popBack method.
-2504  * @return {*} The items removed.
-2505  */
-2506 LinkedList.prototype.multiPopBack = function (times) {
-2507 	var result = [];
-2508 	for (var i = 0; i < times && this.length; i++)
-2509 		result.push(this.popBack());
-2510 	return result;
-2511 };
-2512 
-2513 /**
-2514  * Returns the first item of the list without remove it.
-2515  * @return {*} The item at the top of the list. It's undefined if the list is empty.
-2516  */
-2517 LinkedList.prototype.peek = function () {
-2518 	if (!this.length)
-2519 		return undefined;
-2520 	return this.first.item;
-2521 };
-2522 
-2523 /**
-2524  * Adds the item at the index position.
-2525  * @param item {*} The item to add.
-2526  * @param index {number} The position where to add the item. If index is negative, the item won't be added.
-2527  * @return {void}
-2528  */
-2529 LinkedList.prototype.addAt = function (item, index) {
-2530 	if (index < -1)
-2531 		return;
-2532 	if (!index) {
-2533 		this.pushFront(item);
-2534 		return;
-2535 	}
-2536 	if (index === this.length) {
-2537 		this.pushBack(item);
-2538 		return;
-2539 	}
-2540 	var node = this.first;
-2541 	if (!node && index > 0)
-2542 		this.pushBack(undefined);
-2543 	for (var i = 0; i < index - 1; i++, node = node.next) {
-2544 		if (node === this.last)
-2545 			this.pushBack(undefined);
-2546 	}
-2547 	if (node === this.last)
-2548 		this.pushBack(item);
-2549 	else if (node === this.first)
-2550 		this.pushFront(item);
-2551 	else {
-2552 		var newNode = new LLNode(item);
-2553 		newNode.next = node.next;
-2554 		node.next = newNode;
-2555 		this.length++;
-2556 	}
-2557 };
-2558 
-2559 /**
-2560  * Removes the item at the index position.
-2561  * @param index {number} The position of the item to remove.
-2562  * @return {*} The item stored at the position index. It's undefined if the index is out of bounds.
-2563  */
-2564 LinkedList.prototype.removeAt = function (index) {
-2565 	if (index < 0 || index > this.length - 1)
-2566 		return undefined;
-2567 	if (index === 0)
-2568 		return this.popFront();
-2569 	if (index === this.length - 1)
-2570 		return this.popBack();
-2571 	var node = this.first;
-2572 	for (; index > 1; index--)
-2573 		node = node.next;
-2574 	//now node is the node before the node to remove
-2575 	//node to remove
-2576 	var next = node.next;
-2577 	node.next = next.next;
-2578 	this.length--;
-2579 	return next.item;
-2580 };
-2581 
-2582 /**
-2583  * Removes the item from the list.
-2584  * @param item {*} The item to remove.
-2585  * @param [callback = function(item){return(it===item);}] The condition to satisfy. The callback must accept the current item to check.
-2586  * @return {void}
-2587  */
-2588 LinkedList.prototype.remove = function (item, callback) {
-2589 	callback = callback || function (it) {
-2590 		return it === item;
-2591 	};
-2592 	var node = this.first;
-2593 	var previous = null;
-2594 	while (node) {
-2595 		if (callback(node.item)) {
-2596 			if (node === this.first)
-2597 				this.first = node.next;
-2598 			if (node === this.last)
-2599 				this.last = previous;
-2600 			if (previous)
-2601 				previous.next = node.next;
-2602 			return;
-2603 		}
-2604 		previous = node;
-2605 		node = node.next;
-2606 	}
-2607 };
-2608 
-2609 /**
-2610  * Removes all the item from the list.
-2611  * @param item {*} The item to remove.
-2612  * @param [callback = function(item){return(it===item);}] The condition to satisfy. The callback must accept the current item to check.
-2613  * @return {void}
-2614  */
-2615 LinkedList.prototype.removeAll = function (item, callback) {
-2616 	callback = callback || function (it) {
-2617 		return it === item;
-2618 	};
-2619 	var node = this.first;
-2620 	var previous = null;
-2621 	while (node) {
-2622 		if (callback(node.item)) {
-2623 			if (node === this.first)
-2624 				this.first = node.next;
-2625 			if (node === this.last)
-2626 				this.last = previous;
-2627 			if (previous)
-2628 				previous.next = node.next;
-2629 		} else
-2630 			previous = node;
-2631 		node = node.next;
-2632 	}
-2633 };
-2634 
-2635 /**
-2636  * Removes all the items stored from the from position to the to position.
-2637  * If from > to, the method will remove all the items up to the end.
-2638  * @param from {number} The position where start to remove the items. The from position is included.
-2639  * @param to {number} The position where stop to remove the items. The to position is included.
-2640  * @return {Array<*>} The items removed.
-2641  */
-2642 LinkedList.prototype.removeSegment = function (from, to) {
-2643 	var result = [];
-2644 	if (to > -1 && from < this.length) {
-2645 		if (from === 0)
-2646 			return this.multiPopFront(to + 1);
-2647 		if (to === this.length - 1 || from > to)
-2648 			return this.multiPopBack(Math.max(to - from, this.length - from)).reverse();
-2649 		var node = this.first;
-2650 		for (var i = 0; i < from - 1; i++)
-2651 			node = node.next;
-2652 		//now node is the node before the node to remove
-2653 		//node to remove
-2654 		var next = node.next;
-2655 		for (var j = from; j < to + 1 && j < this.length; j++) {
-2656 			result.push(next.item);
-2657 			next = next.next;
-2658 		}
-2659 		this.length -= Math.min(to - from + 1, this.length - from);
-2660 		node.next = next;
-2661 	}
-2662 	return result;
-2663 };
-2664 
-2665 /**
-2666  * Changes the item stored in the index position. If the index is out of bound, the node won't be updated.
-2667  * @param index {number} The position of the node to modify.
-2668  * @param item {*} The new item stored in the node.
-2669  * @return {void}
-2670  */
-2671 LinkedList.prototype.modifyAt = function (index, item) {
-2672 	var node = this.getNode(index);
-2673 	if (node)
-2674 		node.item = item;
-2675 };
-2676 
-2677 /**
-2678  * Removes all the items stored in the list.
-2679  * @return {void}
-2680  */
-2681 LinkedList.prototype.clear = function () {
-2682 	this.first = null;
-2683 	this.last = null;
-2684 	this.length = 0;
-2685 };
-2686 
-2687 /**
-2688  * Checks if the list contains an item that satisfy the condition represented by the callback function.
-2689  * @param item {*} The item to find.
-2690  * @param [callback = function(item){return(it===item);}] The condition to satisfy. The callback must accept the current item to check.
-2691  * @return {boolean} True if the list contains the item that satisfy the condition, false otherwise.
-2692  */
-2693 LinkedList.prototype.contains = function (item, callback) {
-2694 	callback = callback || function (it) {
-2695 		return it === item;
-2696 	};
-2697 	var i = 0;
-2698 	var node = this.first;
-2699 	while (i < this.length && !callback(node.item)) {
-2700 		i++;
-2701 		node = node.next;
-2702 	}
-2703 	return i < this.length;
-2704 };
-2705 
-2706 /**
-2707  * Executes the callback function for each item of the stack.
-2708  * This method modifies the list so if you don't need to modify it you must return the same item of the array.
-2709  * @param callback {function} The function to execute for each item. The function must accept the current item on which execute the function.
-2710  * @return {void}
-2711  */
-2712 LinkedList.prototype.execute = function (callback) {
-2713 	var node = this.first;
-2714 	while (node) {
-2715 		node.item = callback(node.item);
-2716 		node = node.next;
-2717 	}
-2718 };
-2719 
-2720 /**
-2721  * Returns the node at the position index.
-2722  * @param index {number} The position of the node.
-2723  * @return {LLNode} The node stored at the position index. It's undefined if index isn't in the list bounds.
-2724  */
-2725 LinkedList.prototype.getNode = function (index) {
-2726 	if (index < 0 || index > this.length - 1)
-2727 		return undefined;
-2728 	var node = this.first;
-2729 	for (; index > 0; index--)
-2730 		node = node.next;
-2731 	return node;
-2732 };
-2733 
-2734 /**
-2735  * Returns the item at the position index.
-2736  * @param index {number} The position of the item.
-2737  * @return {*} The item stored at the position index. It's undefined if index isn't in the list bounds.
-2738  */
-2739 LinkedList.prototype.getItem = function (index) {
-2740 	if (index < 0 || index > this.length - 1)
-2741 		return undefined;
-2742 	var node = this.first;
-2743 	for (; index > 0; index--)
-2744 		node = node.next;
-2745 	return node.item;
-2746 };
-2747 
-2748 /**
-2749  * Transforms the list into an array.
-2750  * @return {Array<*>} The array built.
-2751  */
-2752 LinkedList.prototype.toArray = function () {
-2753 	var array = [];
-2754 	for (var node = this.first, i = 0; node; node = node.next, i++)
-2755 		array[i] = node.item;
-2756 	return array;
-2757 };
-2758 
-2759 /**
-2760  * Returns the length of the list.
-2761  * @return {Number} The length of the list.
-2762  */
-2763 LinkedList.prototype.getLength = function () {
-2764 	return this.length;
-2765 };
-2766 
-2767 /**
-2768  * Builds the list from the array.
-2769  * @param array {Array<*>} The array from which build the list.
-2770  * @return {void}
-2771  */
-2772 LinkedList.prototype.fromArray = function (array) {
-2773 	var node = this.first;
-2774 	for (var i = 0; i < Math.min(this.length, array.length); i++, node = node.next)
-2775 		node.item = array[i];
-2776 	if (this.length < array.length)
-2777 		for (var j = this.length; j < array.length; j++)
-2778 			this.pushBack(array[j]);
-2779 	else
-2780 		for (var k = array.length; k < this.length;)
-2781 			this.popBack();
-2782 };
-2783 
-2784 /**
-2785  * Returns the items that satisfy the condition determined by the callback.
-2786  * @param callback {function} The function that implements the condition.
-2787  * @return {Array<*>} The array that contains the items that satisfy the condition.
-2788  */
-2789 LinkedList.prototype.filter = function (callback) {
-2790 	var result = [];
-2791 	for (var node = this.first; node; node = node.next) {
-2792 		if (callback(node.item))
-2793 			result.push(node.item);
-2794 	}
-2795 	return result;
-2796 };
-2797 
-2798 /**
-2799  * Checks if the list is empty.
-2800  * @return {boolean} True if the list is empty, false otherwise.
-2801  */
-2802 LinkedList.prototype.isEmpty = function () {
-2803 	return !this.length;
-2804 };
-2805 
-2806 /**
-2807  * Returns the first position of the item in the list.
-2808  * @param item {*} The item to search.
-2809  * @param [callback = function(item){return(it===item);}] The condition to satisfy. The callback must accept the current item to check.
-2810  * @return {number} The first position of the item.
-2811  */
-2812 LinkedList.prototype.indexOf = function (item, callback) {
-2813 	callback = callback || function (it) {
-2814 		return it === item;
-2815 	};
-2816 	var i = 0;
-2817 	var node = this.first;
-2818 	while (node) {
-2819 		if (callback(node.item))
-2820 			return i;
-2821 		i++;
-2822 		node = node.next;
-2823 	}
-2824 	return -1;
-2825 };
-2826 
-2827 /**
-2828  * Returns the last position of the item in the list.
-2829  * @param item {*} The item to search.
-2830  * @param [callback = function(item){return(it===item);}] The condition to satisfy. The callback must accept the current item to check.
-2831  * @return {number} The last position of the item.
-2832  */
-2833 LinkedList.prototype.lastIndexOf = function (item, callback) {
-2834 	callback = callback || function (it) {
-2835 		return it === item;
-2836 	};
-2837 	var i = 0;
-2838 	var node = this.first;
-2839 	var index = -1;
-2840 	while (node) {
-2841 		if (callback(node.item))
-2842 			index = i;
-2843 		i++;
-2844 		node = node.next;
-2845 	}
-2846 	return index;
-2847 };
-2848 
-2849 /**
-2850  * Returns all the position in which the item has been found in the list.
-2851  * @param item {*} The item to search.
-2852  * @param [callback = function(item){return(it===item);}] The condition to satisfy. The callback must accept the current item to check.
-2853  * @return {Array<number>} The positions in which the item has been found.
-2854  */
-2855 LinkedList.prototype.allIndexesOf = function (item, callback) {
-2856 	callback = callback || function (it) {
-2857 		return it === item;
-2858 	};
-2859 	var i = 0;
-2860 	var node = this.first;
-2861 	var indexes = [];
-2862 	while (node) {
-2863 		if (callback(node.item))
-2864 			indexes.push(i);
-2865 		i++;
-2866 		node = node.next;
-2867 	}
-2868 	return indexes;
-2869 };
-2870 
-2871 /**
-2872  * Joins the list at the end of this list.
-2873  * @param list {LinkedList} The list to join.
-2874  * @return {void}
-2875  */
-2876 LinkedList.prototype.join = function (list) {
-2877 	if (this.last)
-2878 		this.last.next = list.first;
-2879 	else
-2880 		this.first = list.first;
-2881 	this.last = list.last;
-2882 	this.length += list.length;
-2883 };
-2884 
-2885 /**
-2886  * Divides the list at the index position. The node at the index position is the first new node of the list.
-2887  * @param index {number} The position where to divide the list.
-2888  * @return {LinkedList} The list formed by the nodes from the index position then. If the index is out of bound, the list will be empty.
-2889  */
-2890 LinkedList.prototype.divide = function (index) {
-2891 	var list = new LinkedList();
-2892 	if (index > -1 && index < this.length) {
-2893 		var node = this.first;
-2894 		var previous = null;
-2895 		for (var i = 0; i < index; i++) {
-2896 			previous = node;
-2897 			node = node.next;
-2898 		}
-2899 		if (node === this.first) {
-2900 			list.first = this.first;
-2901 			list.last = this.last;
-2902 			this.first = null;
-2903 			this.last = null;
-2904 		} else {
-2905 			list.first = node;
-2906 			list.last = this.last;
-2907 			this.last = previous;
-2908 			previous.next = null;
-2909 		}
-2910 		list.length = this.length - index;
-2911 		this.length = index;
-2912 	}
-2913 	return list;
-2914 };
-2915 
-2916 /**
-2917  * Clones the list into a new list.
-2918  * @return {LinkedList} The list cloned from this list.
-2919  */
-2920 LinkedList.prototype.clone = function () {
-2921 	var list = new LinkedList();
-2922 	var node = this.first;
-2923 	for (var i = 0; i < this.length; i++, node = node.next)
-2924 		if (node.item.clone)
-2925 			list.pushBack(node.item.clone());
-2926 		else
-2927 			list.pushBack(node.item);
-2928 	return list;
-2929 };
-2930 
-2931 /**
-2932  * Clones the list into a new list without cloning duplicated items.
-2933  * @return {LinkedList} The list cloned from this list.
-2934  */
-2935 LinkedList.prototype.cloneDistinct = function () {
-2936 	var list = new LinkedList();
-2937 	var node = this.first;
-2938 	for (var i = 0; i < this.length; i++, node = node.next)
-2939 		if (!list.contains(node.item))
-2940 			if (node.item.cloneDistinct)
-2941 				list.pushBack(node.item.cloneDistinct());
-2942 			else if (node.item.clone)
-2943 				list.pushBack(node.item.clone());
-2944 			else
-2945 				list.pushBack(node.item);
-2946 	return list;
-2947 };
-2948 
-2949 /**
-2950  * Splits the list into lists of desired size.
-2951  * @param size {number} The size of the lists.
-2952  * @return {Array<LinkedList>} The lists created by splitting the list.
-2953  */
-2954 LinkedList.prototype.split = function (size) {
-2955 	var length = this.length;
-2956 	var lists = [this];
-2957 	for (var i = size; i < length; i += size)
-2958 		lists.push(lists[lists.length - 1].divide(size));
-2959 	return lists;
-2960 };
-2961 
-2962 /**
-2963  * Returns the number of items that satisfy the represented by the callback function.
-2964  * @param callback {function} The condition to satisfy.
-2965  * @return {number} The number of items that satisfy the condition.
-2966  */
-2967 LinkedList.prototype.count = function (callback) {
-2968 	var count = 0;
-2969 	var node = this.first;
-2970 	while (node) {
-2971 		if (callback(node.item))
-2972 			count++;
-2973 		node = node.next;
-2974 	}
-2975 	return count;
-2976 };
-2977 
-2978 /**
-2979  * Class that implements the iterator for a linked list.
-2980  * @param aggregate {LinkedList} The aggregate to scan.
-2981  * @constructor
-2982  */
-2983 function LinkedListIterator(aggregate) {
-2984 	/**
-2985 	 * The aggregate relates to this iterator.
-2986 	 * @type {LinkedList}
-2987 	 */
-2988 	this.aggregate = aggregate;
-2989 
-2990 	/**
-2991 	 * The pointer to the position.
-2992 	 * @type {Node|null}
-2993 	 */
-2994 	this.pointer = null;
-2995 }
-2996 
-2997 /**
-2998  * Moves the iterator to the first position of the aggregate.
-2999  * @return {void}
-3000  */
-3001 LinkedListIterator.prototype.first = function () {
-3002 	this.pointer = this.aggregate.first;
-3003 };
-3004 
-3005 /**
-3006  * Moves the iterator to the next item.
-3007  * @return {void}
-3008  */
-3009 LinkedListIterator.prototype.next = function () {
-3010 	this.pointer = this.pointer.next;
-3011 };
-3012 
-3013 /**
-3014  * Moves the iterator to the last position of the aggregate.
-3015  * @return {void}
-3016  */
-3017 LinkedListIterator.prototype.last = function () {
-3018 	this.pointer = this.aggregate.last;
-3019 };
-3020 
-3021 /**
-3022  * Moves the iterator to the previous item.
-3023  * @return {void}
-3024  */
-3025 LinkedListIterator.prototype.previous = function () {
-3026 	var node = this.pointer;
-3027 	for (this.pointer = this.first(); this.pointer.next !== node;)
-3028 		this.next();
-3029 };
-3030 
-3031 /**
-3032  * Checks if the iterator is out of the bounds of the aggregate.
-3033  * @return {boolean} It return true if the iterator is out of the bounds of the aggregate, otherwise false.
-3034  */
-3035 LinkedListIterator.prototype.isDone = function () {
-3036 	return !this.pointer;
-3037 };
-3038 
-3039 /**
-3040  * Returns the item stored at the position pointed by the iterator.
-3041  * @return {*} The item stored or undefined if it's out of the bounds.
-3042  */
-3043 LinkedListIterator.prototype.getItem = function () {
-3044 	return this.pointer.item;
-3045 };
-3046 
-3047 /**
-3048  * Returns the node stored at the position pointed by the iterator.
-3049  * @abstract
-3050  * @return {Node|null} The node stored or null if it's out of the bounds.
-3051  */
-3052 LinkedListIterator.prototype.getNode = function () {
-3053 	return this.pointer;
-3054 };
-3055 
-3056 /**
-3057  * Class for managing a priority queue.
-3058  * @constructor
-3059  */
-3060 function PriorityQueue() {
-3061 	/**
-3062 	 * The list of the items in the queue.
-3063 	 * @type {RBTreeList}
-3064 	 */
-3065 	this.items = new RBTreeList();
-3066 	/**
-3067 	 * The length of the queue.
-3068 	 * @type {number}
-3069 	 */
-3070 	this.length = 0;
-3071 }
-3072 
-3073 /**
-3074  * Returns the iterator relative to the aggregate.
-3075  * @return {Iterator} The iterator.
-3076  */
-3077 PriorityQueue.prototype.getIterator = function () {
-3078 	return new PriorityQueueIterator(this);
-3079 };
-3080 
-3081 /**
-3082  * Adds the item at the tail of the queue.
-3083  * @param priority {number} The priority of the item.
-3084  * @param item {*} The item to add.
-3085  * @return {void}
-3086  */
-3087 PriorityQueue.prototype.enqueue = function (priority, item) {
-3088 	var queue = this.items.search(priority);
-3089 	if (!queue) {
-3090 		queue = new Queue();
-3091 		this.items.insert(priority, queue);
-3092 	}
-3093 	queue.enqueue(item);
-3094 	this.length++;
-3095 };
-3096 
-3097 /**
-3098  * Adds the items with the same priority at the tail of the queue.
-3099  * @param priority {number} The priority of the items.
-3100  * @param items {Array<*>} The items to add.
-3101  * @return {void}
-3102  */
-3103 PriorityQueue.prototype.multiEnqueue = function (priority, items) {
-3104 	for (var i = 0; i < items.length; i++)
-3105 		this.enqueue(priority, items[i]);
-3106 };
-3107 
-3108 /**
-3109  * Removes the item at the head of the queue.
-3110  * @return {*} The item at the head of the queue. It's undefined if the queue is empty.
-3111  */
-3112 PriorityQueue.prototype.dequeue = function () {
-3113 	var node = this.items.maximum();
-3114 	var item = undefined;
-3115 	if (node) {
-3116 		var queue = node.item;
-3117 		item = queue.dequeue();
-3118 		if (queue.isEmpty())
-3119 			this.items.deleteNode(node);
-3120 		this.length--;
-3121 	}
-3122 	return item;
-3123 };
-3124 
-3125 /**
-3126  * Removes the items at the head of the queue.
-3127  * @param times {number} The number of times to repeat the dequeue method.
-3128  * @return {Array<*>} The items at the head of the queue.
-3129  */
-3130 PriorityQueue.prototype.multiDequeue = function (times) {
-3131 	var items = [];
-3132 	for (var i = 0; i < times && this.length; i++)
-3133 		items.push(this.dequeue());
-3134 	return items;
-3135 };
-3136 
-3137 /**
-3138  * Removes the first length items from the position index.
-3139  * @param index {number} The position where to start to remove the items.
-3140  * @param [length = 1] {number} The number of items to remove.
-3141  * @return {void}
-3142  */
-3143 PriorityQueue.prototype.remove = function (index, length) {
-3144 	length = length || 1;
-3145 	var it = this.items.getIterator();
-3146 	for (it.last(); !it.isDone() && length > 0; it.previous()) {
-3147 		var queue = it.getItem();
-3148 		if (index > -1 && index < queue.getLength()) {
-3149 			var oldLength = queue.getLength();
-3150 			queue.remove(index, length);
-3151 			length -= oldLength - index;
-3152 			index = 0;
-3153 			if (!queue.getLength())
-3154 				this.items.deleteNode(it.getNode());
-3155 		} else
-3156 			index = index - queue.getLength();
-3157 	}
-3158 };
-3159 
-3160 /**
-3161  * Returns the item at the position index.
-3162  * @param index {number} The index of the item.
-3163  * @return {*} The item found. It's undefined if the position index is out of bounds.
-3164  */
-3165 PriorityQueue.prototype.getItem = function (index) {
-3166 	var it = this.items.getIterator();
-3167 	for (it.last(); !it.isDone(); it.previous()) {
-3168 		var queue = it.getItem();
-3169 		if (index > -1 && index < queue.getLength())
-3170 			return queue.getItem(index);
-3171 		index = index - queue.getLength();
-3172 	}
-3173 	return undefined;
-3174 };
-3175 
-3176 /**
-3177  * Returns the items relatives to the priority.
-3178  * @param priority {number} The priority of the items.
-3179  * @return {Array<*>} The items found.
-3180  */
-3181 PriorityQueue.prototype.getItems = function (priority) {
-3182 	var items = this.items.search(priority);
-3183 	if (items)
-3184 		return items.items;
-3185 	return [];
-3186 };
-3187 
-3188 /**
-3189  * Returns the first item in the queue. The item is not removed.
-3190  * @return {*} The first item. It's undefined if the queue is empty.
-3191  */
-3192 PriorityQueue.prototype.peek = function () {
-3193 	return this.items.maximum().item.peek();
-3194 };
-3195 
-3196 /**
-3197  * Returns the length of the queue.
-3198  * @return {number} The length of the queue.
-3199  */
-3200 PriorityQueue.prototype.getLength = function () {
-3201 	return this.length;
-3202 };
-3203 
-3204 /**
-3205  * Checks if the queue is empty.
-3206  * @return {boolean} True if the queue is empty, false otherwise.
-3207  */
-3208 PriorityQueue.prototype.isEmpty = function () {
-3209 	return !this.length;
-3210 };
-3211 
-3212 /**
-3213  * Removes all the items stored in the queue.
-3214  * @return {void}
-3215  */
-3216 PriorityQueue.prototype.clear = function () {
-3217 	this.items = new RBTreeList();
-3218 	this.length = 0;
-3219 };
-3220 
-3221 /**
-3222  * Checks if the queue contains a priority that satisfy the condition represented by the callback function.
-3223  * @param priority {number} The priority to find.
-3224  * @param [callback = function(p){return(p===priority);}] The condition to satisfy. The callback must accept the current priority to check.
-3225  * @return {boolean} True if the queue contains the priority that satisfy the condition, false otherwise.
-3226  */
-3227 PriorityQueue.prototype.containsPriority = function (priority, callback) {
-3228 	if (callback)
-3229 		return this.items.fullContains(callback);
-3230 	else
-3231 		return this.items.contains(priority);
-3232 };
-3233 
-3234 /**
-3235  * Returns the queue created by the priority queue with the items in the same order but without the priority.
-3236  * @return {Queue} The queue created.
-3237  */
-3238 PriorityQueue.prototype.toQueue = function () {
-3239 	var queue = new Queue();
-3240 	var it = this.items.getIterator();
-3241 	for (it.last(); !it.isDone(); it.previous()) {
-3242 		var item = it.getItem();
-3243 		var itQ = item.getIterator();
-3244 		for (itQ.first(); !itQ.isDone(); itQ.next())
-3245 			queue.enqueue(itQ.getItem());
-3246 	}
-3247 	return queue;
-3248 };
-3249 
-3250 /**
-3251  * Executes the callback function for each item of the queue.
-3252  * This method modifies the queue so if you don't need to modify it you must return the same item of the array.
-3253  * @param callback {function} The function to execute for each item. The function must accept the current item on which execute the function.
-3254  * @return {void}
-3255  */
-3256 PriorityQueue.prototype.execute = function (callback) {
-3257 	var it = this.items.getIterator();
-3258 	for (it.last(); !it.isDone(); it.previous())
-3259 		it.getItem().execute(callback);
-3260 };
-3261 
-3262 /**
-3263  * Changes the priority of the item at the position index.
-3264  * @param index {number} The position of the item of which increase the priority.
-3265  * @param newPriority {number} The new priority.
-3266  * @return {void}
-3267  */
-3268 PriorityQueue.prototype.changePriority = function (index, newPriority) {
-3269 	var item = this.getItem(index);
-3270 	this.remove(index);
-3271 	this.enqueue(newPriority, item);
-3272 };
-3273 
-3274 /**
-3275  * Returns the items that satisfy the condition determined by the callback.
-3276  * @param callback {function} The function that implements the condition.
-3277  * @return {Array<*>} The array that contains the items that satisfy the condition.
-3278  */
-3279 PriorityQueue.prototype.filter = function (callback) {
-3280 	var result = [];
-3281 	var it = this.items.getIterator();
-3282 	for (it.last(); !it.isDone(); it.previous()) {
-3283 		var itQ = it.getItem().getIterator();
-3284 		for (itQ.first(); !itQ.isDone(); itQ.next()) {
-3285 			if (callback(itQ.getItem()))
-3286 				result.push(itQ.getItem());
-3287 		}
-3288 	}
-3289 	return result;
-3290 };
-3291 
-3292 /**
-3293  * Clones the queue into a new queue.
-3294  * @return {PriorityQueue} The queue cloned from this queue.
-3295  */
-3296 PriorityQueue.prototype.clone = function () {
-3297 	var queue = new PriorityQueue();
-3298 	queue.items = this.items.clone();
-3299 	queue.length = this.length;
-3300 	return queue;
-3301 };
-3302 
-3303 /**
-3304  * Clones the queue into a new queue without cloning duplicated items.
-3305  * @return {PriorityQueue} The queue cloned from this queue.
-3306  */
-3307 PriorityQueue.prototype.cloneDistinct = function () {
-3308 	var queue = new PriorityQueue();
-3309 	queue.items = this.items.cloneDistinct();
-3310 	queue.length = queue.items.getSize();
-3311 	return queue;
-3312 };
-3313 
-3314 /**
-3315  * Class that implements the iterator for a priority queue.
-3316  * @param aggregate {PriorityQueue} The aggregate to scan.
-3317  * @constructor
-3318  */
-3319 function PriorityQueueIterator(aggregate) {
-3320 	/**
-3321 	 * The aggregate relates to this iterator.
-3322 	 * @type {PriorityQueue}
-3323 	 */
-3324 	this.aggregate = aggregate;
-3325 
-3326 	/**
-3327 	 * The pointer to the position of the node.
-3328 	 * @type {RBLNode|null}
-3329 	 */
-3330 	this.pointerNode = null;
-3331 	/**
-3332 	 * The pointer to the position in the node.
-3333 	 * @type {number}
-3334 	 */
-3335 	this.pointerPosition = -1;
-3336 }
-3337 
-3338 /**
-3339  * Moves the iterator to the first position of the aggregate.
-3340  * @return {void}
-3341  */
-3342 PriorityQueueIterator.prototype.first = function () {
-3343 	this.pointerNode = this.aggregate.items.maximum();
-3344 	this.pointerPosition = 0;
-3345 };
-3346 
-3347 /**
-3348  * Moves the iterator to the next item.
-3349  * @return {void}
-3350  */
-3351 PriorityQueueIterator.prototype.next = function () {
-3352 	this.pointerPosition++;
-3353 	if (this.pointerPosition > this.pointerNode.item.getLength() - 1) {
-3354 		this.pointerNode = this.pointerNode.previous;
-3355 		this.pointerPosition = 0;
-3356 	}
-3357 };
-3358 
-3359 /**
-3360  * Moves the iterator to the last position of the aggregate.
-3361  * @return {void}
-3362  */
-3363 PriorityQueueIterator.prototype.last = function () {
-3364 	this.pointerNode = this.aggregate.items.minimum();
-3365 	this.pointerPosition = this.pointerNode.item.getLength() - 1;
-3366 };
-3367 
-3368 /**
-3369  * Moves the iterator to the previous item.
-3370  * @return {void}
-3371  */
-3372 PriorityQueueIterator.prototype.previous = function () {
-3373 	this.pointerPosition--;
-3374 	if (this.pointerPosition < 0) {
-3375 		this.pointerNode = this.pointerNode.next;
-3376 		if (this.pointerNode)
-3377 			this.pointerPosition = this.pointerNode.item.getLength() - 1;
-3378 	}
-3379 };
-3380 
-3381 /**
-3382  * Checks if the iterator is out of the bounds of the aggregate.
-3383  * @return {boolean} It return true if the iterator is out of the bounds of the aggregate, otherwise false.
-3384  */
-3385 PriorityQueueIterator.prototype.isDone = function () {
-3386 	return !this.pointerNode;
-3387 };
-3388 
-3389 /**
-3390  * Returns the item stored at the position pointed by the iterator.
-3391  * @return {*} The item stored or undefined if it's out of the bounds.
-3392  */
-3393 PriorityQueueIterator.prototype.getItem = function () {
-3394 	return this.pointerNode.item.items[this.pointerPosition];
-3395 };
-3396 
-3397 /**
-3398  * Class for managing a queue.
-3399  * @param {...*} [args] The items for initializing the queue.
-3400  * @constructor
-3401  */
-3402 function Queue(args) {
-3403 	/**
-3404 	 * The list of the items in the queue.
-3405 	 * @type {Array<*>}
-3406 	 */
-3407 	this.items = [];
-3408 
-3409 	//builds the queue from the parameters of the constructor
-3410 	this.multiEnqueue(arguments);
-3411 }
-3412 
-3413 /**
-3414  * Returns the iterator relative to the aggregate.
-3415  * @return {Iterator} The iterator.
-3416  */
-3417 Queue.prototype.getIterator = function () {
-3418 	return new QueueIterator(this);
-3419 };
-3420 
-3421 /**
-3422  * Adds the item at the tail of the queue.
-3423  * @param item {*} The item to add.
-3424  * @return {void}
-3425  */
-3426 Queue.prototype.enqueue = function (item) {
-3427 	this.items.push(item);
-3428 };
-3429 
-3430 /**
-3431  * Adds the items at the tail of the queue.
-3432  * @param items {Array<*>} The items to add.
-3433  * @return {void}
-3434  */
-3435 Queue.prototype.multiEnqueue = function (items) {
-3436 	for (var i = 0; i < items.length; i++)
-3437 		this.items.push(items[i]);
-3438 };
-3439 
-3440 /**
-3441  * Removes the item at the head of the queue.
-3442  * @return {*} The item at the head of the queue. It's undefined if the queue is empty.
-3443  */
-3444 Queue.prototype.dequeue = function () {
-3445 	if (!this.items.length)
-3446 		return undefined;
-3447 	return this.items.splice(0, 1)[0]; //remove the first item and return it
-3448 };
-3449 
-3450 /**
-3451  * Removes the items at the head of the queue.
-3452  * @param times {number} The number of times to repeat the dequeue method.
-3453  * @return {Array<*>} The items at the head of the queue.
-3454  */
-3455 Queue.prototype.multiDequeue = function (times) {
-3456 	return this.items.splice(0, times); //removes the last times item and returns the array
-3457 };
-3458 
-3459 /**
-3460  * Removes the first length items from the position index.
-3461  * @param index {number} The position where to start to remove the items.
-3462  * @param [length = 1] {number} The number of items to remove.
-3463  * @return {void}
-3464  */
-3465 Queue.prototype.remove = function (index, length) {
-3466 	length = length || 1;
-3467 	this.items.splice(index, length);
-3468 };
-3469 
-3470 /**
-3471  * Returns the item at the position index.
-3472  * @param index {number} The position of the item.
-3473  * @return {*} The item at the position. It's undefined if index isn't in the queue bounds.
-3474  */
-3475 Queue.prototype.getItem = function (index) {
-3476 	if (index < 0 || index > this.items.length - 1)
-3477 		return undefined;
-3478 	return this.items[index];
-3479 };
-3480 
-3481 /**
-3482  * Returns the first item in the queue. The item is not removed.
-3483  * @return {*} The first item. It's undefined if the queue is empty.
-3484  */
-3485 Queue.prototype.peek = function () {
-3486 	if (this.items.length)
-3487 		return this.items[0];
-3488 	return undefined
-3489 };
-3490 
-3491 /**
-3492  * Removes all the items stored in the queue.
-3493  * @return {void}
-3494  */
-3495 Queue.prototype.clear = function () {
-3496 	this.items = [];
-3497 };
-3498 
-3499 /**
-3500  * Checks if the queue contains an item that satisfy the condition represented by the callback function.
-3501  * @param item {*} The item to find.
-3502  * @param [callback = function(item){return(it===item);}] The condition to satisfy. The callback must accept the current item to check.
-3503  * @return {boolean} True if the queue contains the item that satisfy the condition, false otherwise.
-3504  */
-3505 Queue.prototype.contains = function (item, callback) {
-3506 	callback = callback || function (it) {
-3507 		return it === item;
-3508 	};
-3509 	var i = 0;
-3510 	while (i < this.items.length && !callback(this.items[i]))
-3511 		i++;
-3512 	return i < this.items.length;
-3513 };
-3514 
-3515 /**
-3516  * Executes the callback function for each item of the queue.
-3517  * This method modifies the queue so if you don't need to modify it you must return the same item of the array.
-3518  * @param callback {function} The function to execute for each item. The function must accept the current item on which execute the function.
-3519  * @return {void}
-3520  */
-3521 Queue.prototype.execute = function (callback) {
-3522 	for (var i = 0; i < this.items.length; i++)
-3523 		this.items[i] = callback(this.items[i]);
-3524 };
-3525 
-3526 /**
-3527  * Returns the length of the queue.
-3528  * @return {number} The length of the queue.
-3529  */
-3530 Queue.prototype.getLength = function () {
-3531 	return this.items.length;
-3532 };
-3533 
-3534 /**
-3535  * Checks if the queue is empty.
-3536  * @return {boolean} True if the queue is empty, false otherwise.
-3537  */
-3538 Queue.prototype.isEmpty = function () {
-3539 	return !this.items.length;
-3540 };
-3541 
-3542 /**
-3543  * Returns the items that satisfy the condition determined by the callback.
-3544  * @param callback {function} The function that implements the condition.
-3545  * @return {Array<*>} The array that contains the items that satisfy the condition.
-3546  */
-3547 Queue.prototype.filter = function (callback) {
-3548 	var result = [];
-3549 	for (var i = 0; i < this.items.length; i++)
-3550 		if (callback(this.items[i]))
-3551 			result.push(this.items[i]);
-3552 	return result;
-3553 };
-3554 
-3555 /**
-3556  * Returns the first position of the item in the queue.
-3557  * @param item {*} The item to search.
-3558  * @param [callback = function(item){return(it===item);}] The condition to satisfy. The callback must accept the current item to check.
-3559  * @return {number} The first position of the item.
-3560  */
-3561 Queue.prototype.indexOf = function (item, callback) {
-3562 	callback = callback || function (it) {
-3563 		return it === item;
-3564 	};
-3565 	var i = 0;
-3566 	while (i < this.items.length) {
-3567 		if (callback(this.items[i]))
-3568 			return i;
-3569 		i++;
-3570 	}
-3571 	return -1;
-3572 };
-3573 
-3574 /**
-3575  * Returns the last position of the item in the queue.
-3576  * @param item {*} The item to search.
-3577  * @param [callback = function(item){return(it===item);}] The condition to satisfy. The callback must accept the current item to check.
-3578  * @return {number} The last position of the item.
-3579  */
-3580 Queue.prototype.lastIndexOf = function (item, callback) {
-3581 	callback = callback || function (it) {
-3582 		return it === item;
-3583 	};
-3584 	var i = this.items.length - 1;
-3585 	while (i > -1) {
-3586 		if (callback(this.items[i]))
-3587 			return i;
-3588 		i--;
-3589 	}
-3590 	return -1;
-3591 };
-3592 
-3593 /**
-3594  * Returns all the position in which the item has been found in the queue.
-3595  * @param item {*} The item to search.
-3596  * @param [callback = function(item){return(it===item);}] The condition to satisfy. The callback must accept the current item to check.
-3597  * @return {Array<number>} The positions in which the item has been found.
-3598  */
-3599 Queue.prototype.allIndexesOf = function (item, callback) {
-3600 	callback = callback || function (it) {
-3601 		return it === item;
-3602 	};
-3603 	var i = 0;
-3604 	var indexes = [];
-3605 	while (i < this.items.length) {
-3606 		if (callback(this.items[i]))
-3607 			indexes.push(i);
-3608 		i++;
-3609 	}
-3610 	return indexes;
-3611 };
-3612 
-3613 /**
-3614  * Clones the queue into a new queue.
-3615  * @return {Queue} The queue cloned from this queue.
-3616  */
-3617 Queue.prototype.clone = function () {
-3618 	var queue = new Queue();
-3619 	for (var i = 0; i < this.items.length; i++)
-3620 		if (this.items[i].clone)
-3621 			queue.enqueue(this.items[i].clone());
-3622 		else
-3623 			queue.enqueue(this.items[i]);
-3624 
-3625 	return queue;
-3626 };
-3627 
-3628 /**
-3629  * Clones the queue into a new queue without cloning duplicated items.
-3630  * @return {Queue} The queue cloned from this queue.
-3631  */
-3632 Queue.prototype.cloneDistinct = function () {
-3633 	var queue = new Queue();
-3634 	for (var i = 0; i < this.items.length; i++)
-3635 		if (!queue.contains(this.items[i]))
-3636 			if (this.items[i].cloneDistinct)
-3637 				queue.enqueue(this.items[i].cloneDistinct());
-3638 			else if (this.items[i].clone)
-3639 				queue.enqueue(this.items[i].clone());
-3640 			else
-3641 				queue.enqueue(this.items[i]);
-3642 	return queue;
-3643 };
-3644 
-3645 /**
-3646  * Class that implements the iterator for a linked list.
-3647  * @param aggregate {Queue} The aggregate to scan.
-3648  * @constructor
-3649  */
-3650 function QueueIterator(aggregate) {
-3651 	/**
-3652 	 * The aggregate relates to this iterator.
-3653 	 * @type {Queue}
-3654 	 */
-3655 	this.aggregate = aggregate;
-3656 
-3657 	/**
-3658 	 * The pointer to the position.
-3659 	 * @type {number}
-3660 	 */
-3661 	this.pointer = -1;
-3662 }
-3663 
-3664 /**
-3665  * Moves the iterator to the first position of the aggregate.
-3666  * @return {void}
-3667  */
-3668 QueueIterator.prototype.first = function () {
-3669 	this.pointer = 0;
-3670 };
-3671 
-3672 /**
-3673  * Moves the iterator to the next item.
-3674  * @return {void}
-3675  */
-3676 QueueIterator.prototype.next = function () {
-3677 	this.pointer++;
-3678 };
-3679 
-3680 /**
-3681  * Moves the iterator to the last position of the aggregate.
-3682  * @return {void}
-3683  */
-3684 QueueIterator.prototype.last = function () {
-3685 	this.pointer = this.aggregate.items.length - 1;
-3686 };
-3687 
-3688 /**
-3689  * Moves the iterator to the previous item.
-3690  * @return {void}
-3691  */
-3692 QueueIterator.prototype.previous = function () {
-3693 	this.pointer--;
-3694 };
-3695 
-3696 /**
-3697  * Checks if the iterator is out of the bounds of the aggregate.
-3698  * @return {boolean} It return true if the iterator is out of the bounds of the aggregate, otherwise false.
-3699  */
-3700 QueueIterator.prototype.isDone = function () {
-3701 	return this.pointer < 0 || this.pointer > this.aggregate.items.length - 1;
-3702 };
-3703 
-3704 /**
-3705  * Returns the item stored at the position pointed by the iterator.
-3706  * @return {*} The item stored or undefined if it's out of the bounds.
-3707  */
-3708 QueueIterator.prototype.getItem = function () {
-3709 	return this.aggregate.getItem(this.pointer);
-3710 };
-3711 
-3712 /**
-3713  * Class for managing a red-black tree.
-3714  * @constructor
-3715  */
-3716 function RBTree() {
-3717 	/**
-3718 	 * The root of the tree.
-3719 	 * @type {RBNode|null}
-3720 	 */
-3721 	this.root = null;
-3722 	/**
-3723 	 * The number of items stored in the tree.
-3724 	 * @type {number}
-3725 	 */
-3726 	this.size = 0;
-3727 }
-3728 
-3729 /**
-3730  * Returns the iterator relative to the aggregate.
-3731  * @return {Iterator} The iterator.
-3732  */
-3733 RBTree.prototype.getIterator = function () {
-3734 	return new RBTreeIterator(this);
-3735 };
-3736 
-3737 /**
-3738  * Inserts the item relatives to the key value in the tree.
-3739  * @param key {number} The key to store.
-3740  * @param item {*} The item to store.
-3741  * @return {void}
-3742  */
-3743 RBTree.prototype.insert = function (key, item) {
-3744 	var node = new RBNode(key, item);
-3745 	this.size++;
-3746 	if (!this.root) {
-3747 		this.root = node;
-3748 		node.type = 'b';
-3749 		return;
-3750 	}
-3751 	var p = this.root;
-3752 	for (var n = this.root; n;) {
-3753 		p = n;
-3754 		if (key < n.key)
-3755 			n = n.left;
-3756 		else
-3757 			n = n.right;
-3758 	}
-3759 	node.parent = p;
-3760 	if (!p)
-3761 		this.root = node;
-3762 	else if (key < p.key)
-3763 		p.left = node;
-3764 	else
-3765 		p.right = node;
-3766 
-3767 	this.insertFixUp(node);
-3768 };
-3769 
-3770 /**
-3771  * Preserves the properties of the tree after an insert.
-3772  * @param node {RBNode} The node to insert.
-3773  * @return {void}
-3774  */
-3775 RBTree.prototype.insertFixUp = function (node) {
-3776 	for (var parent = node.parent; parent && parent.type === 'r'; parent = node.parent) {
-3777 		if (parent === parent.parent.left) {
-3778 			var uncle = parent.parent.right;
-3779 			if (uncle && uncle.type === 'r') {
-3780 				parent.type = 'b';
-3781 				uncle.type = 'b';
-3782 				parent.parent.type = 'r';
-3783 				node = parent.parent;
-3784 			} else if (node === parent.right) {
-3785 				node = parent;
-3786 				this.leftRotate(node);
-3787 			} else {
-3788 				parent.type = 'b';
-3789 				parent.parent.type = 'r';
-3790 				this.rightRotate(parent.parent);
-3791 			}
-3792 		} else {
-3793 			var uncle = parent.parent.left;
-3794 			if (uncle && uncle.type === 'r') {
-3795 				parent.type = 'b';
-3796 				uncle.type = 'b';
-3797 				parent.parent.type = 'r';
-3798 				node = parent.parent;
-3799 			} else if (node === parent.left) {
-3800 				node = parent;
-3801 				this.rightRotate(node);
-3802 			} else {
-3803 				parent.type = 'b';
-3804 				parent.parent.type = 'r';
-3805 				this.leftRotate(parent.parent);
-3806 			}
-3807 		}
-3808 	}
-3809 	this.root.type = 'b';
-3810 };
-3811 
-3812 /**
-3813  * Deletes the node from the tree.
-3814  * @param node {RBNode} The node to delete.
-3815  * @return {void}
-3816  */
-3817 RBTree.prototype.deleteNode = function (node) {
-3818 	var successor;
-3819 	this.size--;
-3820 	if (!node.left || !node.right)
-3821 		successor = node;
-3822 	else {
-3823 		successor = this.successor(node);
-3824 		node.key = successor.key;
-3825 		node.item = successor.item;
-3826 	}
-3827 	var child;
-3828 	if (!successor.left)
-3829 		child = successor.right;
-3830 	else
-3831 		child = successor.left;
-3832 	if (child)
-3833 		child.parent = successor.parent;
-3834 	if (!successor.parent)
-3835 		this.root = child;
-3836 	else if (successor === successor.parent.left)
-3837 		successor.parent.left = child;
-3838 	else
-3839 		successor.parent.right = child;
-3840 
-3841 	if (successor.type === 'b')
-3842 		this.deleteFixUp(child, successor.parent);
-3843 };
-3844 
-3845 /**
-3846  * Preserves the properties of the tree after a deletion.
-3847  * @param node {RBNode} The node to delete.
-3848  * @param parent {RBNode} The parent of the node.
-3849  * @return {void}
-3850  */
-3851 RBTree.prototype.deleteFixUp = function (node, parent) {
-3852 	while (node !== this.root && (!node || node.type === 'b')) {
-3853 		if (node === parent.left) {
-3854 			var brother = parent.right;
-3855 			if (brother && brother.type === 'r') {
-3856 				brother.type = 'b';
-3857 				parent.type = 'r';
-3858 				this.leftRotate(parent);
-3859 				brother = parent.right;
-3860 			}
-3861 			if (brother && (!brother.left || brother.left.type === 'b') && (!brother.right || brother.right.type === 'b')) {
-3862 				brother.type = 'r';
-3863 				node = parent;
-3864 			} else {
-3865 				if (!brother.right || brother.right.type === 'b') {
-3866 					brother.left.type = 'b';
-3867 					brother.type = 'r';
-3868 					this.rightRotate(brother);
-3869 					brother = parent.right;
-3870 				}
-3871 				brother.type = parent.type;
-3872 				parent.type = 'b';
-3873 				brother.right.type = 'b';
-3874 				this.leftRotate(parent);
-3875 				node = this.root;
-3876 			}
-3877 		} else {
-3878 			var brother = parent.left;
-3879 			if (brother && brother.type === 'r') {
-3880 				brother.type = 'b';
-3881 				parent.type = 'r';
-3882 				this.rightRotate(parent);
-3883 				brother = parent.left;
-3884 			}
-3885 			if (brother && (!brother.left || brother.left.type === 'b') && (!brother.right || brother.right.type === 'b')) {
-3886 				brother.type = 'r';
-3887 				node = parent;
-3888 			} else {
-3889 				if (!brother.left || brother.left.type === 'b') {
-3890 					brother.right.type = 'b';
-3891 					brother.type = 'r';
-3892 					this.leftRotate(brother);
-3893 					brother = parent.left;
-3894 				}
-3895 				brother.type = parent.type;
-3896 				parent.type = 'b';
-3897 				brother.left.type = 'b';
-3898 				this.rightRotate(parent);
-3899 				node = this.root;
-3900 			}
-3901 		}
-3902 		parent = node.parent;
-3903 	}
-3904 	if (node)
-3905 		node.type = 'b';
-3906 };
-3907 
-3908 /**
-3909  * Gets the node with the key next to the param node key.
-3910  * @param node {RBNode} The node of which search the successor.
-3911  * @return {RBNode} The node found.
-3912  */
-3913 RBTree.prototype.successor = function (node) {
-3914 	if (node.right)
-3915 		return this.minimum(node.right);
-3916 	var parent = node.parent;
-3917 	while (parent && node === parent.right) {
-3918 		node = parent;
-3919 		parent = parent.parent;
-3920 	}
-3921 	return parent;
-3922 };
-3923 
-3924 /**
-3925  * Gets the node with the key previous to the param node key.
-3926  * @param node {RBNode} The node of which search the predecessor.
-3927  * @return {RBNode} The node found.
-3928  */
-3929 RBTree.prototype.predecessor = function (node) {
-3930 	if (node.left)
-3931 		return this.maximum(node.left);
-3932 	var parent = node.parent;
-3933 	while (parent && node === parent.left) {
-3934 		node = parent;
-3935 		parent = parent.parent;
-3936 	}
-3937 	return parent;
-3938 };
-3939 
-3940 /**
-3941  * Searches the item relatives to the key and to the nodes that satisfy the condition represented by the callback function.
-3942  * @param key {number} The key to find.
-3943  * @param [node = root] {RBNode} The node from which start the search.
-3944  * @param [callback = function(node){return(node.key===key);}] The condition to satisfy. The callback must accept the current node to check.
-3945  * @return {*} The item found or undefined if there isn't the key in the tree.
-3946  */
-3947 RBTree.prototype.search = function (key, node, callback) {
-3948 	node = node || this.root;
-3949 	callback = callback || function (node) {
-3950 		return node.key === key;
-3951 	};
-3952 	while (node && !callback(node))
-3953 		if (key < node.key)
-3954 			node = node.left;
-3955 		else
-3956 			node = node.right;
-3957 	if (node)
-3958 		return node.item;
-3959 	return undefined;
-3960 };
-3961 
-3962 /**
-3963  * Checks if the tree contains a key or a node that satisfy the condition represented by the callback function.
-3964  * This method avoid to search in branches where the key won't be found.
-3965  * @param key {*} The key to find.
-3966  * @param [callback = function(node){return(node.key===key);}] The condition to satisfy. The callback must accept the current node to check.
-3967  * @return {boolean} True if the tree contains the key or a node that satisfy the condition, false otherwise.
-3968  */
-3969 RBTree.prototype.contains = function (key, callback) {
-3970 	return this.search(key, null, callback) !== undefined;
-3971 };
-3972 
-3973 /**
-3974  * Checks if the tree contains a node that satisfy the condition represented by the callback function.
-3975  * This method check all the tree avoiding the binary search.
-3976  * @param callback {function} The condition to satisfy. The callback must accept the current node to check.
-3977  * @return {boolean} True if the tree contains the node that satisfy the condition, false otherwise.
-3978  */
-3979 RBTree.prototype.fullContains = function (callback) {
-3980 	var node = this.minimum();
-3981 	while (node && !callback(node.key))
-3982 		node = this.successor(node);
-3983 	return node !== null;
-3984 };
-3985 
-3986 /**
-3987  * Gets the item relatives to the minimum key stored in the tree.
-3988  * @param [node = root] {Node} The node from which start the search.
-3989  * @return {RBNode} The node found.
-3990  */
-3991 RBTree.prototype.minimum = function (node) {
-3992 	node = node || this.root;
-3993 	while (node && node.left)
-3994 		node = node.left;
-3995 	return node;
-3996 };
-3997 
-3998 /**
-3999  * Gets the item relatives to the maximum key stored in the tree.
-4000  * @param [node = root] {Node} The node from which start the search.
-4001  * @return {RBNode} The node found.
-4002  */
-4003 RBTree.prototype.maximum = function (node) {
-4004 	node = node || this.root;
-4005 	while (node && node.right)
-4006 		node = node.right;
-4007 	return node;
-4008 };
-4009 
-4010 /**
-4011  * Rotates the node with its right child.
-4012  * @param node {RBNode} The node to rotate.
-4013  * @return {void}
-4014  */
-4015 RBTree.prototype.leftRotate = function (node) {
-4016 	var child = node.right;
-4017 	node.right = child.left;
-4018 	if (child.left !== null)
-4019 		child.left.parent = node;
-4020 	child.parent = node.parent;
-4021 	if (node.parent === null)
-4022 		this.root = child;
-4023 	else if (node === node.parent.left)
-4024 		node.parent.left = child;
-4025 	else
-4026 		node.parent.right = child;
-4027 	node.parent = child;
-4028 	child.left = node;
-4029 };
-4030 
-4031 /**
-4032  * Rotates the node with its left child.
-4033  * @param node {RBNode} The node to rotate.
-4034  * @return {void}
-4035  */
-4036 RBTree.prototype.rightRotate = function (node) {
-4037 	var child = node.left;
-4038 	node.left = child.right;
-4039 	if (child.right !== null)
-4040 		child.right.parent = node;
-4041 	child.parent = node.parent;
-4042 	if (node.parent === null)
-4043 		this.root = child;
-4044 	else if (node === node.parent.left)
-4045 		node.parent.left = child;
-4046 	else
-4047 		node.parent.right = child;
-4048 	node.parent = child;
-4049 	child.right = node;
-4050 };
-4051 
-4052 /**
-4053  * Returns the size of the tree.
-4054  * @return {number} The size of the tree.
-4055  */
-4056 RBTree.prototype.getSize = function () {
-4057 	return this.size;
-4058 };
-4059 
-4060 /**
-4061  * Clones the queue into a new queue.
-4062  * @return {RBTree} The tree cloned from this queue.
-4063  */
-4064 RBTree.prototype.clone = function () {
-4065 	var tree = new RBTree();
-4066 	var it = this.getIterator();
-4067 	for (it.first(); !it.isDone(); it.next())
-4068 		if (it.getNode().item.clone)
-4069 			tree.insert(it.getNode().key, it.getNode().item.clone());
-4070 		else
-4071 			tree.insert(it.getNode().key, it.getNode().item);
-4072 
-4073 	return tree;
-4074 };
-4075 
-4076 /**
-4077  * Clones the tree into a new tree without cloning duplicated items.
-4078  * @return {RBTree} The tree cloned from this tree.
-4079  */
-4080 RBTree.prototype.cloneDistinct = function () {
-4081 	var tree = new RBTree();
-4082 	var it = this.getIterator();
-4083 	for (it.first(); !it.isDone(); it.next()) {
-4084 		var callback = function (node) {
-4085 			return node.key === it.getNode().key && node.item === it.getNode().item;
-4086 		};
-4087 		if (!tree.contains(it.getNode().key, callback)) {
-4088 			if (it.getNode().item.cloneDistinct)
-4089 				tree.insert(it.getNode().key, it.getNode().item.cloneDistinct());
-4090 			else if (it.getNode().item.clone)
-4091 				tree.insert(it.getNode().key, it.getNode().item.clone());
-4092 			else
-4093 				tree.insert(it.getNode().key, it.getNode().item);
-4094 		}
-4095 	}
-4096 	return tree;
-4097 };
-4098 
-4099 /**
-4100  * Transforms the tree into an array without preserving keys.
-4101  * @return {Array<*>} The array that represents the tree.
-4102  */
-4103 RBTree.prototype.toArray = function () {
-4104 	var result = [];
-4105 	for (var node = this.minimum(); node; node = this.successor(node))
-4106 		result.push(node.item);
-4107 	return result;
-4108 };
-4109 
-4110 /**
-4111  * Removes all the items stored in the tree.
-4112  * @return {void}
-4113  */
-4114 RBTree.prototype.clear = function () {
-4115 	this.root = null;
-4116 	this.size = 0;
-4117 };
-4118 
-4119 /**
-4120  * Checks if the tree is empty.
-4121  * @return {boolean} True if the tree is empty, false otherwise.
-4122  */
-4123 RBTree.prototype.isEmpty = function () {
-4124 	return !this.size;
-4125 };
-4126 
-4127 /**
-4128  * Executes the callback function for each item of the tree.
-4129  * This method modifies the tree so if you don't need to modify it you must return the same item stored.
-4130  * @param callback {function} The function to execute for each item. The function must accept the current item on which execute the function.
-4131  * @return {void}
-4132  */
-4133 RBTree.prototype.execute = function (callback) {
-4134 	for (var node = this.minimum(); node; node = this.successor(node))
-4135 		node.item = callback(node.item);
-4136 };
-4137 
-4138 /**
-4139  * Returns the items that satisfy the condition determined by the callback.
-4140  * @param callback {function} The function that implements the condition.
-4141  * @return {Array<*>} The array that contains the items that satisfy the condition.
-4142  */
-4143 RBTree.prototype.filter = function (callback) {
-4144 	var result = [];
-4145 	for (var node = this.minimum(); node; node = this.successor(node))
-4146 		if (callback(node.item))
-4147 			result.push(node.item);
-4148 	return result;
-4149 };
-4150 
-4151 /**
-4152  * Returns the first position of the item in the tree.
-4153  * @param item {*} The item to search.
-4154  * @param [callback = function(item){return(it===item);}] The condition to satisfy. The callback must accept the current item to check.
-4155  * @return {number} The first position of the item.
-4156  */
-4157 RBTree.prototype.indexOf = function (item, callback) {
-4158 	callback = callback || function (it) {
-4159 		return it === item;
-4160 	};
-4161 	var i = 0, node = this.minimum();
-4162 	while (node) {
-4163 		if (callback(node.item))
-4164 			return i;
-4165 		node = this.successor(node);
-4166 		i++;
-4167 	}
-4168 	return -1;
-4169 };
-4170 
-4171 /**
-4172  * Returns the last position of the item in the tree.
-4173  * @param item {*} The item to search.
-4174  * @param [callback = function(item){return(it===item);}] The condition to satisfy. The callback must accept the current item to check.
-4175  * @return {number} The last position of the item.
-4176  */
-4177 RBTree.prototype.lastIndexOf = function (item, callback) {
-4178 	callback = callback || function (it) {
-4179 		return it === item;
-4180 	};
-4181 	var i = this.size - 1, node = this.maximum();
-4182 	while (node) {
-4183 		if (callback(node.item))
-4184 			return i;
-4185 		i--;
-4186 		node = this.predecessor(node);
-4187 	}
-4188 	return -1;
-4189 };
-4190 
-4191 /**
-4192  * Returns all the position in which the item has been found in the tree.
-4193  * @param item {*} The item to search.
-4194  * @param [callback = function(item){return(it===item);}] The condition to satisfy. The callback must accept the current item to check.
-4195  * @return {Array<number>} The positions in which the item has been found.
-4196  */
-4197 RBTree.prototype.allIndexesOf = function (item, callback) {
-4198 	callback = callback || function (it) {
-4199 		return it === item;
-4200 	};
-4201 	var i = 0, node = this.minimum();
-4202 	var indexes = [];
-4203 	while (node) {
-4204 		if (callback(node.item))
-4205 			indexes.push(i);
-4206 		i++;
-4207 		node = this.successor(node);
-4208 	}
-4209 	return indexes;
-4210 };
-4211 
-4212 /**
-4213  * Returns the item at the position index.
-4214  * @param index {number} The position of the item.
-4215  * @return {*} The item at the position. It's undefined if index isn't in the tree bounds.
-4216  */
-4217 RBTree.prototype.getItem = function (index) {
-4218 	if (index < 0 || index > this.size - 1)
-4219 		return undefined;
-4220 	for (var node = this.minimum(), i = 0; i < index; node = this.successor(node))
-4221 		i++;
-4222 	return node.item;
-4223 };
-4224 
-4225 /**
-4226  * Class that implements the iterator for a red-black tree.
-4227  * @param aggregate {RBTree} The aggregate to scan.
-4228  * @constructor
-4229  */
-4230 function RBTreeIterator(aggregate) {
-4231 	/**
-4232 	 * The aggregate relates to this iterator.
-4233 	 * @type {RBTree}
-4234 	 */
-4235 	this.aggregate = aggregate;
-4236 
-4237 	/**
-4238 	 * The pointer to the position.
-4239 	 * @type {RBNode|null}
-4240 	 */
-4241 	this.pointer = null;
-4242 }
-4243 
-4244 /**
-4245  * Moves the iterator to the first position of the aggregate.
-4246  * @return {void}
-4247  */
-4248 RBTreeIterator.prototype.first = function () {
-4249 	this.pointer = this.aggregate.minimum();
-4250 };
-4251 
-4252 /**
-4253  * Moves the iterator to the next item.
-4254  * @return {void}
-4255  */
-4256 RBTreeIterator.prototype.next = function () {
-4257 	this.pointer = this.aggregate.successor(this.pointer);
-4258 };
-4259 
-4260 /**
-4261  * Moves the iterator to the last position of the aggregate.
-4262  * @return {void}
-4263  */
-4264 RBTreeIterator.prototype.last = function () {
-4265 	this.pointer = this.aggregate.maximum();
-4266 };
-4267 
-4268 /**
-4269  * Moves the iterator to the previous item.
-4270  * @return {void}
-4271  */
-4272 RBTreeIterator.prototype.previous = function () {
-4273 	this.pointer = this.aggregate.predecessor(this.pointer);
-4274 };
-4275 
-4276 /**
-4277  * Checks if the iterator is out of the bounds of the aggregate.
-4278  * @return {boolean} It return true if the iterator is out of the bounds of the aggregate, otherwise false.
-4279  */
-4280 RBTreeIterator.prototype.isDone = function () {
-4281 	return !this.pointer;
-4282 };
-4283 
-4284 /**
-4285  * Returns the item stored at the position pointed by the iterator.
-4286  * @return {Object|undefined} The item stored or undefined if it's out of the bounds.
-4287  */
-4288 RBTreeIterator.prototype.getItem = function () {
-4289 	return this.pointer.item;
-4290 };
-4291 
-4292 /**
-4293  * Returns the node stored at the position pointed by the iterator.
-4294  * @return {RBNode|null} The node stored or null if it's out of the bounds.
-4295  */
-4296 RBTreeIterator.prototype.getNode = function () {
-4297 	return this.pointer;
-4298 };
-4299 
-4300 /**
-4301  * Class for managing a red-black tree where nodes are also in a list.
-4302  * @constructor
-4303  */
-4304 function RBTreeList() {
-4305 	/**
-4306 	 * The root of the tree.
-4307 	 * @type {RBLNode|null}
-4308 	 */
-4309 	this.root = null;
-4310 	/**
-4311 	 * The first node of the tree.
-4312 	 * @type {RBLNode|null}
-4313 	 */
-4314 	this.first = null;
-4315 	/**
-4316 	 * The last node of the tree.
-4317 	 * @type {RBLNode|null}
-4318 	 */
-4319 	this.last = null;
-4320 	/**
-4321 	 * The size of the tree.
-4322 	 * @type {number}
-4323 	 */
-4324 	this.size = 0;
-4325 }
-4326 
-4327 /**
-4328  * Returns the iterator relative to the aggregate.
-4329  * @return {Iterator} The iterator.
-4330  */
-4331 RBTreeList.prototype.getIterator = function () {
-4332 	return new RBTreeListIterator(this);
-4333 };
-4334 
-4335 /**
-4336  * Inserts the item relatives to the key value in the tree.
-4337  * @param key {number} The key to store.
-4338  * @param item {*} The item to store.
-4339  * @return {void}
-4340  */
-4341 RBTreeList.prototype.insert = function (key, item) {
-4342 	var node = new RBLNode(key, item);
-4343 	this.size++;
-4344 	if (!this.root) {
-4345 		this.root = node;
-4346 		this.first = node;
-4347 		this.last = node;
-4348 		node.type = 'b';
-4349 		return;
-4350 	}
-4351 	var p = this.root;
-4352 	for (var n = this.root; n;) {
-4353 		p = n;
-4354 		if (key < n.key)
-4355 			n = n.left;
-4356 		else
-4357 			n = n.right;
-4358 	}
-4359 	node.parent = p;
-4360 	if (!p)
-4361 		this.root = node;
-4362 	else if (key < p.key)
-4363 		p.left = node;
-4364 	else
-4365 		p.right = node;
-4366 
-4367 	node.next = this.successor(node);
-4368 	if (node.next) {
-4369 		if (node.next.previous)
-4370 			node.next.previous.next = node;
-4371 		else
-4372 			this.first = node;
-4373 		node.previous = node.next.previous;
-4374 		node.next.previous = node;
-4375 	} else {
-4376 		this.last = node;
-4377 		node.previous = this.predecessor(node);
-4378 		if (node.previous)
-4379 			node.previous.next = node;
-4380 		else
-4381 			this.first = node;
-4382 	}
-4383 
-4384 	this.insertFixUp(node);
-4385 };
-4386 
-4387 /**
-4388  * Preserves the properties of the tree after an insert.
-4389  * @param node {RBLNode} The node to insert.
-4390  * @return {void}
-4391  */
-4392 RBTreeList.prototype.insertFixUp = function (node) {
-4393 	for (var parent = node.parent; parent && parent.type === 'r'; parent = node.parent) {
-4394 		if (parent === parent.parent.left) {
-4395 			var uncle = parent.parent.right;
-4396 			if (uncle && uncle.type === 'r') {
-4397 				parent.type = 'b';
-4398 				uncle.type = 'b';
-4399 				parent.parent.type = 'r';
-4400 				node = parent.parent;
-4401 			} else if (node === parent.right) {
-4402 				node = parent;
-4403 				this.leftRotate(node);
-4404 			} else {
-4405 				parent.type = 'b';
-4406 				parent.parent.type = 'r';
-4407 				this.rightRotate(parent.parent);
-4408 			}
-4409 		} else {
-4410 			var uncle = parent.parent.left;
-4411 			if (uncle && uncle.type === 'r') {
-4412 				parent.type = 'b';
-4413 				uncle.type = 'b';
-4414 				parent.parent.type = 'r';
-4415 				node = parent.parent;
-4416 			} else if (node === parent.left) {
-4417 				node = parent;
-4418 				this.rightRotate(node);
-4419 			} else {
-4420 				parent.type = 'b';
-4421 				parent.parent.type = 'r';
-4422 				this.leftRotate(parent.parent);
-4423 			}
-4424 		}
-4425 	}
-4426 	this.root.type = 'b';
-4427 };
-4428 
-4429 /**
-4430  * Deletes the node from the tree.
-4431  * @param node {RBLNode} The node to delete.
-4432  * @return {void}
-4433  */
-4434 RBTreeList.prototype.deleteNode = function (node) {
-4435 	this.size--;
-4436 	var successor;
-4437 	if (!node.left || !node.right)
-4438 		successor = node;
-4439 	else {
-4440 		successor = this.successor(node);
-4441 		node.key = successor.key;
-4442 		node.item = successor.item;
-4443 	}
-4444 	var child;
-4445 	if (!successor.left)
-4446 		child = successor.right;
-4447 	else
-4448 		child = successor.left;
-4449 	if (child)
-4450 		child.parent = successor.parent;
-4451 	if (!successor.parent)
-4452 		this.root = child;
-4453 	else if (successor === successor.parent.left)
-4454 		successor.parent.left = child;
-4455 	else
-4456 		successor.parent.right = child;
-4457 
-4458 	if (successor.next)
-4459 		successor.next.previous = successor.previous;
-4460 	else
-4461 		this.last = successor.previous;
-4462 	if (successor.previous)
-4463 		successor.previous.next = successor.next;
-4464 	else
-4465 		this.first = successor.next;
-4466 
-4467 	if (successor.type === 'b')
-4468 		this.deleteFixUp(child, successor.parent);
-4469 };
-4470 
-4471 /**
-4472  * Preserves the properties of the tree after a deletion.
-4473  * @param node {RBLNode} The node to delete.
-4474  * @param parent {RBLNode} The parent of the node.
-4475  * @return {void}
-4476  */
-4477 RBTreeList.prototype.deleteFixUp = function (node, parent) {
-4478 	while (node !== this.root && (!node || node.type === 'b')) {
-4479 		if (node === parent.left) {
-4480 			var brother = parent.right;
-4481 			if (brother && brother.type === 'r') {
-4482 				brother.type = 'b';
-4483 				parent.type = 'r';
-4484 				this.leftRotate(parent);
-4485 				brother = parent.right;
-4486 			}
-4487 			if (brother && (!brother.left || brother.left.type === 'b') && (!brother.right || brother.right.type === 'b')) {
-4488 				brother.type = 'r';
-4489 				node = parent;
-4490 			} else {
-4491 				if (!brother.right || brother.right.type === 'b') {
-4492 					brother.left.type = 'b';
-4493 					brother.type = 'r';
-4494 					this.rightRotate(brother);
-4495 					brother = parent.right;
-4496 				}
-4497 				brother.type = parent.type;
-4498 				parent.type = 'b';
-4499 				brother.right.type = 'b';
-4500 				this.leftRotate(parent);
-4501 				node = this.root;
-4502 			}
-4503 		} else {
-4504 			var brother = parent.left;
-4505 			if (brother && brother.type === 'r') {
-4506 				brother.type = 'b';
-4507 				parent.type = 'r';
-4508 				this.rightRotate(parent);
-4509 				brother = parent.left;
-4510 			}
-4511 			if (brother && (!brother.left || brother.left.type === 'b') && (!brother.right || brother.right.type === 'b')) {
-4512 				brother.type = 'r';
-4513 				node = parent;
-4514 			} else {
-4515 				if (!brother.left || brother.left.type === 'b') {
-4516 					brother.right.type = 'b';
-4517 					brother.type = 'r';
-4518 					this.leftRotate(brother);
-4519 					brother = parent.left;
-4520 				}
-4521 				brother.type = parent.type;
-4522 				parent.type = 'b';
-4523 				brother.left.type = 'b';
-4524 				this.rightRotate(parent);
-4525 				node = this.root;
-4526 			}
-4527 		}
-4528 		parent = node.parent;
-4529 	}
-4530 	if (node)
-4531 		node.type = 'b';
-4532 };
-4533 
-4534 /**
-4535  * Gets the node with the key next to the param node key.
-4536  * @param node {RBLNode} The node of which search the successor.
-4537  * @return {RBLNode} The node found.
-4538  */
-4539 RBTreeList.prototype.successor = function (node) {
-4540 	if (node.next || node === this.last)
-4541 		return node.next;
-4542 	if (node.right)
-4543 		return this.minimum(node.right);
-4544 	var parent = node.parent;
-4545 	while (parent && node === parent.right) {
-4546 		node = parent;
-4547 		parent = parent.parent;
-4548 	}
-4549 	return parent;
-4550 };
-4551 
-4552 /**
-4553  * Gets the node with the key previous to the param node key.
-4554  * @param node {RBLNode} The node of which search the predecessor.
-4555  * @return {RBLNode} The node found.
-4556  */
-4557 RBTreeList.prototype.predecessor = function (node) {
-4558 	if (node.previous || node === this.first)
-4559 		return node.previous;
-4560 	if (node.left)
-4561 		return this.maximum(node.left);
-4562 	var parent = node.parent;
-4563 	while (parent && node === parent.left) {
-4564 		node = parent;
-4565 		parent = parent.parent;
-4566 	}
-4567 	return parent;
-4568 };
-4569 
-4570 /**
-4571  * Searches the item relatives to the key that satisfy the condition represented by the callback function.
-4572  * @param key {number} The key to find.
-4573  * @param [node = root] {RBNode} The node from which start the search.
-4574  * @param [callback = function(k){return(k===key);}] The condition to satisfy. The callback must accept the current key to check.
-4575  * @return {*} The item found or undefined if there isn't the key in the tree.
-4576  */
-4577 RBTreeList.prototype.search = function (key, node, callback) {
-4578 	node = node || this.root;
-4579 	callback = callback || function (node) {
-4580 		return node.key === key;
-4581 	};
-4582 	while (node && !callback(node))
-4583 		if (key < node.key)
-4584 			node = node.left;
-4585 		else
-4586 			node = node.right;
-4587 	if (node)
-4588 		return node.item;
-4589 	return undefined;
-4590 };
-4591 
-4592 /**
-4593  * Checks if the tree contains a key or a node that satisfy the condition represented by the callback function.
-4594  * This method avoid to search in branches where the key won't be found.
-4595  * @param key {*} The key to find.
-4596  * @param [callback = function(node){return(node.key===key);}] The condition to satisfy. The callback must accept the current node to check.
-4597  * @return {boolean} True if the tree contains the key or a node that satisfy the condition, false otherwise.
-4598  */
-4599 RBTreeList.prototype.contains = function (key, callback) {
-4600 	return this.search(key, null, callback) !== undefined;
-4601 };
-4602 
-4603 /**
-4604  * Checks if the tree contains a node that satisfy the condition represented by the callback function.
-4605  * This method check all the tree avoiding the binary search.
-4606  * @param callback {function} The condition to satisfy. The callback must accept the current node to check.
-4607  * @return {boolean} True if the tree contains the node that satisfy the condition, false otherwise.
-4608  */
-4609 RBTreeList.prototype.fullContains = function (callback) {
-4610 	var node = this.first;
-4611 	while (node && !callback(node.key))
-4612 		node = node.next;
-4613 	return node !== null;
-4614 };
-4615 
-4616 /**
-4617  * Gets the item relatives to the minimum key stored in the tree.
-4618  * @param [node = root] {Node} The node from which start the search.
-4619  * @return {RBLNode} The node found.
-4620  */
-4621 RBTreeList.prototype.minimum = function (node) {
-4622 	if (node)
-4623 		while (node && node.left)
-4624 			node = node.left;
-4625 	else
-4626 		return this.first;
-4627 	return node;
-4628 };
-4629 
-4630 /**
-4631  * Gets the item relatives to the maximum key stored in the tree.
-4632  * @param [node = root] {Node} The node from which start the search.
-4633  * @return {RBLNode} The node found.
-4634  */
-4635 RBTreeList.prototype.maximum = function (node) {
-4636 	if (node)
-4637 		while (node && node.right)
-4638 			node = node.right;
-4639 	else
-4640 		return this.last;
-4641 	return node;
-4642 };
-4643 
-4644 /**
-4645  * Rotates the node with its right child.
-4646  * @param node {RBLNode} The node to rotate.
-4647  * @return {void}
-4648  */
-4649 RBTreeList.prototype.leftRotate = function (node) {
-4650 	var child = node.right;
-4651 	node.right = child.left;
-4652 	if (child.left !== null)
-4653 		child.left.parent = node;
-4654 	child.parent = node.parent;
-4655 	if (node.parent === null)
-4656 		this.root = child;
-4657 	else if (node === node.parent.left)
-4658 		node.parent.left = child;
-4659 	else
-4660 		node.parent.right = child;
-4661 	node.parent = child;
-4662 	child.left = node;
-4663 };
-4664 
-4665 /**
-4666  * Rotates the node with its left child.
-4667  * @param node {RBLNode} The node to rotate.
-4668  * @return {void}
-4669  */
-4670 RBTreeList.prototype.rightRotate = function (node) {
-4671 	var child = node.left;
-4672 	node.left = child.right;
-4673 	if (child.right !== null)
-4674 		child.right.parent = node;
-4675 	child.parent = node.parent;
-4676 	if (node.parent === null)
-4677 		this.root = child;
-4678 	else if (node === node.parent.left)
-4679 		node.parent.left = child;
-4680 	else
-4681 		node.parent.right = child;
-4682 	node.parent = child;
-4683 	child.right = node;
-4684 };
-4685 
-4686 /**
-4687  * Returns the size of the tree.
-4688  * @return {number} The size of the tree.
-4689  */
-4690 RBTreeList.prototype.getSize = function () {
-4691 	return this.size;
-4692 };
-4693 
-4694 /**
-4695  * Clones the tree into a new tree.
-4696  * @return {RBTreeList} The tree cloned from this tree.
-4697  */
-4698 RBTreeList.prototype.clone = function () {
-4699 	var tree = new RBTreeList();
-4700 	var it = this.getIterator();
-4701 	for (it.first(); !it.isDone(); it.next())
-4702 		tree.insert(it.getNode().key, it.getNode().item);
-4703 	return tree;
-4704 };
-4705 
-4706 /**
-4707  * Clones the tree into a new tree without cloning duplicated items.
-4708  * @return {RBTreeList} The tree cloned from this tree.
-4709  */
-4710 RBTreeList.prototype.cloneDistinct = function () {
-4711 	var tree = new RBTreeList();
-4712 	var it = this.getIterator();
-4713 	for (it.first(); !it.isDone(); it.next()) {
-4714 		var callback = function (node) {
-4715 			return node.key === it.getNode().key && node.item === it.getNode().item;
-4716 		};
-4717 		if (!tree.contains(it.getNode().key, callback)) {
-4718 			if (it.getNode().item.cloneDistinct)
-4719 				tree.insert(it.getNode().key, it.getNode().item.cloneDistinct());
-4720 			else if (it.getNode().item.clone)
-4721 				tree.insert(it.getNode().key, it.getNode().item.clone());
-4722 			else
-4723 				tree.insert(it.getNode().key, it.getNode().item);
-4724 		}
-4725 	}
-4726 	return tree;
-4727 };
-4728 
-4729 /**
-4730  * Transforms the tree into an array without preserving keys.
-4731  * @return {Array<*>} The array that represents the tree.
-4732  */
-4733 RBTreeList.prototype.toArray = function () {
-4734 	var result = [];
-4735 	for (var node = this.first; node; node = node.next)
-4736 		result.push(node.item);
-4737 	return result;
-4738 };
-4739 
-4740 /**
-4741  * Removes all the items stored in the tree.
-4742  * @return {void}
-4743  */
-4744 RBTreeList.prototype.clear = function () {
-4745 	this.root = null;
-4746 	this.first = null;
-4747 	this.last = null;
-4748 	this.size = 0;
-4749 };
-4750 
-4751 /**
-4752  * Checks if the tree is empty.
-4753  * @return {boolean} True if the tree is empty, false otherwise.
-4754  */
-4755 RBTreeList.prototype.isEmpty = function () {
-4756 	return !this.size;
-4757 };
-4758 
-4759 /**
-4760  * Executes the callback function for each item of the tree.
-4761  * This method modifies the tree so if you don't need to modify it you must return the same item stored.
-4762  * @param callback {function} The function to execute for each item. The function must accept the current item on which execute the function.
-4763  * @return {void}
-4764  */
-4765 RBTreeList.prototype.execute = function (callback) {
-4766 	for (var node = this.first; node; node = node.next)
-4767 		node.item = callback(node.item);
-4768 };
-4769 
-4770 /**
-4771  * Returns the items that satisfy the condition determined by the callback.
-4772  * @param callback {function} The function that implements the condition.
-4773  * @return {Array<*>} The array that contains the items that satisfy the condition.
-4774  */
-4775 RBTreeList.prototype.filter = function (callback) {
-4776 	var result = [];
-4777 	for (var node = this.first; node; node = node.next)
-4778 		if (callback(node.item))
-4779 			result.push(node.item);
-4780 	return result;
-4781 };
-4782 
-4783 /**
-4784  * Returns the first position of the item in the tree.
-4785  * @param item {*} The item to search.
-4786  * @param [callback = function(item){return(it===item);}] The condition to satisfy. The callback must accept the current item to check.
-4787  * @return {number} The first position of the item.
-4788  */
-4789 RBTreeList.prototype.indexOf = function (item, callback) {
-4790 	callback = callback || function (it) {
-4791 		return it === item;
-4792 	};
-4793 	var i = 0, node = this.first;
-4794 	while (node) {
-4795 		if (callback(node.item))
-4796 			return i;
-4797 		node = node.next;
-4798 		i++;
-4799 	}
-4800 	return -1;
-4801 };
-4802 
-4803 /**
-4804  * Returns the last position of the item in the tree.
-4805  * @param item {*} The item to search.
-4806  * @param [callback = function(item){return(it===item);}] The condition to satisfy. The callback must accept the current item to check.
-4807  * @return {number} The last position of the item.
-4808  */
-4809 RBTreeList.prototype.lastIndexOf = function (item, callback) {
-4810 	callback = callback || function (it) {
-4811 		return it === item;
-4812 	};
-4813 	var i = this.size - 1, node = this.last;
-4814 	while (node) {
-4815 		if (callback(node.item))
-4816 			return i;
-4817 		i--;
-4818 		node = node.previous;
-4819 	}
-4820 	return -1;
-4821 };
-4822 
-4823 /**
-4824  * Returns all the position in which the item has been found in the tree.
-4825  * @param item {*} The item to search.
-4826  * @param [callback = function(item){return(it===item);}] The condition to satisfy. The callback must accept the current item to check.
-4827  * @return {Array<number>} The positions in which the item has been found.
-4828  */
-4829 RBTreeList.prototype.allIndexesOf = function (item, callback) {
-4830 	callback = callback || function (it) {
-4831 		return it === item;
-4832 	};
-4833 	var i = 0, node = this.first;
-4834 	var indexes = [];
-4835 	while (node) {
-4836 		if (callback(node.item))
-4837 			indexes.push(i);
-4838 		i++;
-4839 		node = node.next;
-4840 	}
-4841 	return indexes;
-4842 };
-4843 
-4844 /**
-4845  * Returns the item at the position index.
-4846  * @param index {number} The position of the item.
-4847  * @return {*} The item at the position. It's undefined if index isn't in the tree bounds.
-4848  */
-4849 RBTreeList.prototype.getItem = function (index) {
-4850 	if (index < 0 || index > this.size - 1)
-4851 		return undefined;
-4852 	for (var node = this.first, i = 0; i < index; node = node.next)
-4853 		i++;
-4854 	return node.item;
-4855 };
-4856 
-4857 /**
-4858  * Class that implements the iterator for a red-black tree.
-4859  * @param aggregate {RBTreeList} The aggregate to scan.
-4860  * @constructor
-4861  */
-4862 function RBTreeListIterator(aggregate) {
-4863 	/**
-4864 	 * The aggregate relates to this iterator.
-4865 	 * @type {RBTreeList}
-4866 	 */
-4867 	this.aggregate = aggregate;
-4868 	/**
-4869 	 * The pointer to the position.
-4870 	 * @type {RBLNode|null}
-4871 	 */
-4872 	this.pointer = null;
-4873 }
-4874 
-4875 /**
-4876  * Moves the iterator to the first position of the aggregate.
-4877  * @return {void}
-4878  */
-4879 RBTreeListIterator.prototype.first = function () {
-4880 	this.pointer = this.aggregate.first;
-4881 };
-4882 
-4883 /**
-4884  * Moves the iterator to the next item.
-4885  * @return {void}
-4886  */
-4887 RBTreeListIterator.prototype.next = function () {
-4888 	this.pointer = this.pointer.next;
-4889 };
-4890 
-4891 /**
-4892  * Moves the iterator to the last position of the aggregate.
-4893  * @return {void}
-4894  */
-4895 RBTreeListIterator.prototype.last = function () {
-4896 	this.pointer = this.aggregate.last;
-4897 };
-4898 
-4899 /**
-4900  * Moves the iterator to the previous item.
-4901  * @return {void}
-4902  */
-4903 RBTreeListIterator.prototype.previous = function () {
-4904 	this.pointer = this.pointer.previous;
-4905 };
-4906 
-4907 /**
-4908  * Checks if the iterator is out of the bounds of the aggregate.
-4909  * @return {boolean} It return true if the iterator is out of the bounds of the aggregate, otherwise false.
-4910  */
-4911 RBTreeListIterator.prototype.isDone = function () {
-4912 	return !this.pointer;
-4913 };
-4914 
-4915 /**
-4916  * Returns the item stored at the position pointed by the iterator.
-4917  * @return {*} The item stored or undefined if it's out of the bounds.
-4918  */
-4919 RBTreeListIterator.prototype.getItem = function () {
-4920 	return this.pointer.item;
-4921 };
-4922 
-4923 /**
-4924  * Returns the node stored at the position pointed by the iterator.
-4925  * @abstract
-4926  * @return {RBNode|null} The node stored or null if it's out of the bounds.
-4927  */
-4928 RBTreeListIterator.prototype.getNode = function () {
-4929 	return this.pointer;
-4930 };
-4931 
-4932 /**
-4933  * Class for managing a set.
-4934  * @constructor
-4935  */
-4936 function Set() {
-4937 	/**
-4938 	 * The parents of the set.
-4939 	 * @type {DoubleLinkedList}
-4940 	 */
-4941 	this.parents = new DoubleLinkedList();
-4942 	/**
-4943 	 * The elements stored.
-4944 	 * @type {DoubleLinkedList}
-4945 	 */
-4946 	this.elements = new DoubleLinkedList();
-4947 	/**
-4948 	 * The subsets of this set.
-4949 	 * @type {DoubleLinkedList}
-4950 	 */
-4951 	this.sets = new DoubleLinkedList();
-4952 	/**
-4953 	 * The size of the set. It's equal to his cardinality.
-4954 	 * @type {number}
-4955 	 */
-4956 	this.size = 0;
-4957 }
-4958 
-4959 /**
-4960  * Adds the element to the set.
-4961  * @param element {Element} The element to add.
-4962  * @return {void}
-4963  */
-4964 Set.prototype.insert = function (element) {
-4965 	this.elements.pushBack(element);
-4966 	element.parents.pushBack(this);
-4967 	this.size++;
-4968 };
-4969 
-4970 /**
-4971  * Adds the elements to the set.
-4972  * @param elements {Array<Element>} The elements to add.
-4973  * @return {void}
-4974  */
-4975 Set.prototype.multiInsert = function (elements) {
-4976 	for (var i = 0; i < elements.length; i++) {
-4977 		this.elements.pushBack(elements[i]);
-4978 		elements[i].parents.pushBack(this);
-4979 	}
-4980 	this.size += elements.length;
-4981 };
-4982 
-4983 /**
-4984  * Returns the set that represents the union of two sets.
-4985  * @param set {Set} The set with make the union.
-4986  * @return {Set} The set that represents the union.
-4987  */
-4988 Set.prototype.union = function (set) {
-4989 	var parent = new Set();
-4990 	parent.addSubsets([this, set]);
-4991 	this.parents.pushBack(parent);
-4992 	set.parents.pushBack(parent);
-4993 	//change the parent of the subset
-4994 	var that = this;
-4995 	var f = function (item) {
-4996 		if (item === that)
-4997 			return parent;
-4998 	};
-4999 	var it = this.sets.getIterator();
-5000 	for (it.first(); !it.isDone(); it.next())
-5001 		it.getItem().parents.execute(f);
-5002 	f = function (item) {
-5003 		if (item === set)
-5004 			return parent;
-5005 	};
-5006 	it = set.sets.getIterator();
-5007 	for (it.first(); !it.isDone(); it.next())
-5008 		it.getItem().parents.execute(f);
-5009 	return parent;
-5010 };
-5011 
-5012 /**
-5013  * Returns the set that represents the intersection of two sets.
-5014  * @param set {Set} The set to intersect with this.
-5015  * @return {Set} The set that represents the intersection.
-5016  */
-5017 Set.prototype.intersect = function (set) {
-5018 	var intersection = new Set();
-5019 	//intersect this set with the set
-5020 	var el = this.elements.getIterator();
-5021 	for (el.first(); !el.isDone(); el.next())
-5022 		if (el.getItem().parents.contains(set))
-5023 			intersection.insert(el.getItem());
-5024 
-5025 	//intersect the subsets with the set
-5026 	var it = this.sets.getIterator();
-5027 	for (it.first(); !it.isDone(); it.next()) {
-5028 		el = it.getItem().getIterator();
-5029 		for (el.first(); !el.isDone(); el.next())
-5030 			if (el.getItem().parents.contains(set))
-5031 				intersection.insert(el.getItem());
-5032 	}
-5033 	return intersection;
-5034 };
-5035 
-5036 /**
-5037  * Returns the set that represents the difference of two sets.
-5038  * @param set {Set} The set to difference with this.
-5039  * @return {Set} The set that represents the difference.
-5040  */
-5041 Set.prototype.difference = function (set) {
-5042 	var diff = new Set();
-5043 	//intersect this set with the set
-5044 	var el = this.elements.getIterator();
-5045 	for (el.first(); !el.isDone(); el.next())
-5046 		if (!el.getItem().parents.contains(set))
-5047 			diff.insert(el.getItem());
-5048 
-5049 	//intersect the subsets with the set
-5050 	var it = this.sets.getIterator();
-5051 	for (it.first(); !it.isDone(); it.next()) {
-5052 		el = it.getItem().getIterator();
-5053 		for (el.first(); !el.isDone(); el.next())
-5054 			if (!el.getItem().parents.contains(set))
-5055 				diff.insert(el.getItem());
-5056 	}
-5057 	return diff;
-5058 };
-5059 
-5060 /**
-5061  * Returns the set that represents the cartesian product of two sets.
-5062  * @param set {Set} The set to make the cartesian product with this.
-5063  * @return {Set} The set that represents the cartesian product .
-5064  */
-5065 Set.prototype.cartesianProduct = function (set) {
-5066 	var el1 = this.getItems();
-5067 	var el2 = set.getItems();
-5068 	var product = new Set();
-5069 	for (var i = 0; i < el1.length; i++)
-5070 		for (var j = 0; j < el2.length; j++)
-5071 			product.insert(new Element([el1[i], el2[j]]));
-5072 	return product;
-5073 };
-5074 
-5075 /**
-5076  * Adds the subset.
-5077  * @param set {Set} The subset.
-5078  */
-5079 Set.prototype.addSubset = function (set) {
-5080 	this.sets.pushBack(set);
-5081 	this.size += set.size;
-5082 };
-5083 
-5084 /**
-5085  * Adds the subsets.
-5086  * @param sets {Array<Set>} The subsets.
-5087  */
-5088 Set.prototype.addSubsets = function (sets) {
-5089 	for (var i = 0; i < sets.length; i++)
-5090 		this.addSubset(sets[i]);
-5091 };
-5092 
-5093 /**
-5094  * Returns the items that are stored in the set.
-5095  * @return {Array} The items stored.
-5096  */
-5097 Set.prototype.getItems = function () {
-5098 	var array = [];
-5099 	//get the items stored in the set
-5100 	var el = this.elements.getIterator();
-5101 	for (el.first(); !el.isDone(); el.next())
-5102 		array.push(el.getItem().item);
-5103 
-5104 	//get the items stored in the subsets
-5105 	var it = this.sets.getIterator();
-5106 	for (it.first(); !it.isDone(); it.next()) {
-5107 		el = it.getItem().getIterator();
-5108 		for (el.first(); !el.isDone(); el.next())
-5109 			array.push(el.getItem().item);
-5110 	}
-5111 	return array;
-5112 };
-5113 
-5114 /**
-5115  * Returns the cardinality of the set.
-5116  * @return {number} The cardinality of the set.
-5117  */
-5118 Set.prototype.getCardinality = function () {
-5119 	return this.size;
-5120 };
-5121 
-5122 /**
-5123  * Checks if the set is empty.
-5124  * @return {boolean} True if the set is empty, false otherwise.
-5125  */
-5126 Set.prototype.isEmpty = function () {
-5127 	return !this.size;
-5128 };
-5129 
-5130 /**
-5131  * Clones the set into a new set.
-5132  * @return {Set} The set cloned from this set.
-5133  */
-5134 Set.prototype.clone = function () {
-5135 	var s = new Set();
-5136 	s.parents = this.parents.clone();
-5137 	s.elements = this.elements.clone();
-5138 	s.sets = this.sets.clone();
-5139 	s.size = this.size;
-5140 	return s;
-5141 };
-5142 
-5143 /**
-5144  * Class for managing a stack.
-5145  * @param {...*} [args] The items for initializing the stack.
-5146  * @constructor
-5147  */
-5148 function Stack(args) {
-5149 	/**
-5150 	 * The list of the items in the stack.
-5151 	 * @type {Array<*>}
-5152 	 */
-5153 	this.items = [];
-5154 
-5155 	//builds the stack from the parameters of the constructor
-5156 	this.multiPush(arguments);
-5157 }
-5158 
-5159 /**
-5160  * Returns the iterator relative to the aggregate.
-5161  * @return {Iterator} The iterator.
-5162  */
-5163 Stack.prototype.getIterator = function () {
-5164 	return new StackIterator(this);
-5165 };
-5166 
-5167 /**
-5168  * Adds the item at the top of the stack.
-5169  * @param item {*} The item to add.
-5170  * return {void}
-5171  */
-5172 Stack.prototype.push = function (item) {
-5173 	this.items.push(item);
-5174 };
-5175 
-5176 /**
-5177  * Adds the items at the top of the stack.
-5178  * @param items {Array<*>} The items to add.
-5179  * @return {void}
-5180  */
-5181 Stack.prototype.multiPush = function (items) {
-5182 	for (var i = 0; i < items.length; i++)
-5183 		this.push(items[i]);
-5184 };
-5185 
-5186 /**
-5187  * Removes the item at the top of the stack.
-5188  * @return {*} The item at the top of the stack. It's undefined if the stack is empty.
-5189  */
-5190 Stack.prototype.pop = function () {
-5191 	if (!this.items.length)
-5192 		return undefined;
-5193 	return this.items.pop();
-5194 };
-5195 
-5196 /**
-5197  * Removes the more item at the top of the stack.
-5198  * @param times {number} The number of times to repeat the pop method.
-5199  * @return {Array<*>} The items at the top of the stack.
-5200  */
-5201 Stack.prototype.multiPop = function (times) {
-5202 	var result = [];
-5203 	for (var i = 0; i < times && this.items.length; i++)
-5204 		result.push(this.pop());
-5205 	return result;
-5206 };
-5207 
-5208 /**
-5209  * Returns the item at the top of the stack without remove it.
-5210  * @return {*} The item at the top of the stack. It's undefined if the stack is empty.
-5211  */
-5212 Stack.prototype.peek = function () {
-5213 	if (!this.items.length)
-5214 		return undefined;
-5215 	return this.items[this.items.length - 1];
-5216 };
-5217 
-5218 /**
-5219  * Removes all the items stored in the stack.
-5220  * @return {void}
-5221  */
-5222 Stack.prototype.clear = function () {
-5223 	this.items = [];
-5224 };
-5225 
-5226 /**
-5227  * Checks if the stack contains an item that satisfy the condition represented by the callback function.
-5228  * @param item {*} The item to find.
-5229  * @param [callback = function(item){return(it===item);}] The condition to satisfy. The callback must accept the current item to check.
-5230  * @return {boolean} True if the stack contains the item that satisfy the condition, false otherwise.
-5231  */
-5232 Stack.prototype.contains = function (item, callback) {
-5233 	callback = callback || function (it) {
-5234 		return it === item;
-5235 	};
-5236 	var i = 0;
-5237 	while (i < this.items.length && !callback(this.items[i]))
-5238 		i++;
-5239 	return i < this.items.length;
-5240 };
-5241 
-5242 /**
-5243  * Executes the callback function for each item of the stack.
-5244  * This method modifies the stack so if you don't need to modify it you must return the same item of the array.
-5245  * @param callback {function} The function to execute for each item. The function must accept the current item on which execute the function.
-5246  * @return {void}
-5247  */
-5248 Stack.prototype.execute = function (callback) {
-5249 	for (var i = this.items.length - 1; i > -1; i--)
-5250 		this.items[i] = callback(this.items[i]);
-5251 };
-5252 
-5253 /**
-5254  * Returns the item at the position index.
-5255  * @param index The position of the item.
-5256  * @return {*} The item at the position. It's undefined if index isn't in the stack bounds.
-5257  */
-5258 Stack.prototype.getItem = function (index) {
-5259 	if (index < 0 || index > this.items.length - 1)
-5260 		return undefined;
-5261 	return this.items[index];
-5262 };
-5263 
-5264 /**
-5265  * Returns the length of the stack.
-5266  * @return {Number} The length of the stack.
-5267  */
-5268 Stack.prototype.getLength = function () {
-5269 	return this.items.length;
-5270 };
-5271 
-5272 /**
-5273  * Checks if the stack is empty.
-5274  * @return {boolean} True if the stack is empty, false otherwise.
-5275  */
-5276 Stack.prototype.isEmpty = function () {
-5277 	return !this.items.length;
-5278 };
-5279 
-5280 /**
-5281  * Returns the items that satisfy the condition determined by the callback.
-5282  * @param callback {function} The function that implements the condition.
-5283  * @return {Array<*>} The array that contains the items that satisfy the condition.
-5284  */
-5285 Stack.prototype.filter = function (callback) {
-5286 	var result = [];
-5287 	for (var i = this.items.length - 1; i > -1; i--) {
-5288 		if (callback(this.items[i]))
-5289 			result.push(this.items[i]);
-5290 	}
-5291 	return result;
-5292 };
-5293 
-5294 /**
-5295  * Returns the first position of the item in the stack.
-5296  * @param item {*} The item to search.
-5297  * @param [callback = function(item){return(it===item);}] The condition to satisfy. The callback must accept the current item to check.
-5298  * @return {number} The first position of the item.
-5299  */
-5300 Stack.prototype.indexOf = function (item, callback) {
-5301 	callback = callback || function (it) {
-5302 		return it === item;
-5303 	};
-5304 	var i = this.items.length - 1;
-5305 	while (i > -1) {
-5306 		if (callback(this.items[i]))
-5307 			return i;
-5308 		i--;
-5309 	}
-5310 	return -1;
-5311 };
-5312 
-5313 /**
-5314  * Returns the last position of the item in the stack.
-5315  * @param item {*} The item to search.
-5316  * @param [callback = function(item){return(it===item);}] The condition to satisfy. The callback must accept the current item to check.
-5317  * @return {number} The last position of the item.
-5318  */
-5319 Stack.prototype.lastIndexOf = function (item, callback) {
-5320 	callback = callback || function (it) {
-5321 		return it === item;
-5322 	};
-5323 	var i = 0;
-5324 	while (i < this.items.length) {
-5325 		if (callback(this.items[i]))
-5326 			return i;
-5327 		i++;
-5328 	}
-5329 	return -1;
-5330 };
-5331 
-5332 /**
-5333  * Returns all the position in which the item has been found in the stack.
-5334  * @param item {*} The item to search.
-5335  * @param [callback = function(item){return(it===item);}] The condition to satisfy. The callback must accept the current item to check.
-5336  * @return {Array<number>} The positions in which the item has been found.
-5337  */
-5338 Stack.prototype.allIndexesOf = function (item, callback) {
-5339 	callback = callback || function (it) {
-5340 		return it === item;
-5341 	};
-5342 	var i = this.items.length - 1;
-5343 	var indexes = [];
-5344 	while (i > -1) {
-5345 		if (callback(this.items[i]))
-5346 			indexes.push(i);
-5347 		i--;
-5348 	}
-5349 	return indexes;
-5350 };
-5351 
-5352 /**
-5353  * Clones the stack into a new stack.
-5354  * @return {Stack} The stack cloned from this stack.
-5355  */
-5356 Stack.prototype.clone = function () {
-5357 	var stack = new Stack();
-5358 	for (var i = 0; i < this.items.length; i++)
-5359 		if (this.items[i].clone)
-5360 			stack.push(this.items[i].clone());
-5361 		else
-5362 			stack.push(this.items[i]);
-5363 	return stack;
-5364 };
-5365 
-5366 /**
-5367  * Clones the stack into a new stack without cloning duplicated items.
-5368  * @return {Stack} The stack cloned from this stack.
-5369  */
-5370 Stack.prototype.cloneDistinct = function () {
-5371 	var stack = new Stack();
-5372 	for (var i = 0; i < this.items.length; i++)
-5373 		if (!stack.contains(this.items[i])) {
-5374 			if (this.items[i].cloneDistinct)
-5375 				stack.push(this.items[i].cloneDistinct());
-5376 			else if (this.items[i].clone)
-5377 				stack.push(this.items[i].clone());
-5378 			else
-5379 				stack.push(this.items[i]);
-5380 		}
-5381 	return stack;
-5382 };
-5383 
-5384 /**
-5385  * Class that implements the iterator for a linked list.
-5386  * @param aggregate {Stack} The aggregate to scan.
-5387  * @constructor
-5388  */
-5389 function StackIterator(aggregate) {
-5390 	/**
-5391 	 * The aggregate relates to this iterator.
-5392 	 * @type {Stack}
-5393 	 */
-5394 	this.aggregate = aggregate;
-5395 
-5396 	/**
-5397 	 * The pointer to the position.
-5398 	 * @type {number}
-5399 	 */
-5400 	this.pointer = -1;
-5401 }
-5402 
-5403 /**
-5404  * Moves the iterator to the first position of the aggregate.
-5405  * @return {void}
-5406  */
-5407 StackIterator.prototype.first = function () {
-5408 	this.pointer = this.aggregate.items.length - 1;
-5409 };
-5410 
-5411 /**
-5412  * Moves the iterator to the next item.
-5413  * @return {void}
-5414  */
-5415 StackIterator.prototype.next = function () {
-5416 	this.pointer--;
-5417 };
-5418 
-5419 /**
-5420  * Moves the iterator to the last position of the aggregate.
-5421  * @return {void}
-5422  */
-5423 StackIterator.prototype.last = function () {
-5424 	this.pointer = 0;
-5425 };
-5426 
-5427 /**
-5428  * Moves the iterator to the previous item.
-5429  * @return {void}
-5430  */
-5431 StackIterator.prototype.previous = function () {
-5432 	this.pointer++;
-5433 };
-5434 
-5435 /**
-5436  * Checks if the iterator is out of the bounds of the aggregate.
-5437  * @return {boolean} It return true if the iterator is out of the bounds of the aggregate, otherwise false.
-5438  */
-5439 StackIterator.prototype.isDone = function () {
-5440 	return this.pointer < 0 || this.pointer > this.aggregate.items.length - 1;
-5441 };
-5442 
-5443 /**
-5444  * Returns the item stored at the position pointed by the iterator.
-5445  * @return {*} The item stored or undefined if it's out of the bounds.
-5446  */
-5447 StackIterator.prototype.getItem = function () {
-5448 	return this.aggregate.getItem(this.pointer);
-5449 };
- - \ No newline at end of file diff --git a/fonts/OpenSans-Bold-webfont.eot b/fonts/OpenSans-Bold-webfont.eot new file mode 100644 index 0000000..e1c7674 Binary files /dev/null and b/fonts/OpenSans-Bold-webfont.eot differ diff --git a/fonts/OpenSans-Bold-webfont.svg b/fonts/OpenSans-Bold-webfont.svg new file mode 100644 index 0000000..364b368 --- /dev/null +++ b/fonts/OpenSans-Bold-webfont.svg @@ -0,0 +1,146 @@ + + + + +This is a custom SVG webfont generated by Font Squirrel. +Copyright : Digitized data copyright 20102011 Google Corporation +Foundry : Ascender Corporation +Foundry URL : httpwwwascendercorpcom + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/fonts/OpenSans-Bold-webfont.ttf b/fonts/OpenSans-Bold-webfont.ttf new file mode 100644 index 0000000..2d94f06 Binary files /dev/null and b/fonts/OpenSans-Bold-webfont.ttf differ diff --git a/fonts/OpenSans-Bold-webfont.woff b/fonts/OpenSans-Bold-webfont.woff new file mode 100644 index 0000000..cd86852 Binary files /dev/null and b/fonts/OpenSans-Bold-webfont.woff differ diff --git a/fonts/OpenSans-BoldItalic-webfont.eot b/fonts/OpenSans-BoldItalic-webfont.eot new file mode 100644 index 0000000..f44ac9a Binary files /dev/null and b/fonts/OpenSans-BoldItalic-webfont.eot differ diff --git a/fonts/OpenSans-BoldItalic-webfont.svg b/fonts/OpenSans-BoldItalic-webfont.svg new file mode 100644 index 0000000..8392240 --- /dev/null +++ b/fonts/OpenSans-BoldItalic-webfont.svg @@ -0,0 +1,146 @@ + + + + +This is a custom SVG webfont generated by Font Squirrel. +Copyright : Digitized data copyright 20102011 Google Corporation +Foundry : Ascender Corporation +Foundry URL : httpwwwascendercorpcom + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/fonts/OpenSans-BoldItalic-webfont.ttf b/fonts/OpenSans-BoldItalic-webfont.ttf new file mode 100644 index 0000000..f74e0e3 Binary files /dev/null and b/fonts/OpenSans-BoldItalic-webfont.ttf differ diff --git a/fonts/OpenSans-BoldItalic-webfont.woff b/fonts/OpenSans-BoldItalic-webfont.woff new file mode 100644 index 0000000..f3248c1 Binary files /dev/null and b/fonts/OpenSans-BoldItalic-webfont.woff differ diff --git a/fonts/OpenSans-Italic-webfont.eot b/fonts/OpenSans-Italic-webfont.eot new file mode 100644 index 0000000..277c189 Binary files /dev/null and b/fonts/OpenSans-Italic-webfont.eot differ diff --git a/fonts/OpenSans-Italic-webfont.svg b/fonts/OpenSans-Italic-webfont.svg new file mode 100644 index 0000000..29c7497 --- /dev/null +++ b/fonts/OpenSans-Italic-webfont.svg @@ -0,0 +1,146 @@ + + + + +This is a custom SVG webfont generated by Font Squirrel. +Copyright : Digitized data copyright 20102011 Google Corporation +Foundry : Ascender Corporation +Foundry URL : httpwwwascendercorpcom + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/fonts/OpenSans-Italic-webfont.ttf b/fonts/OpenSans-Italic-webfont.ttf new file mode 100644 index 0000000..63f187e Binary files /dev/null and b/fonts/OpenSans-Italic-webfont.ttf differ diff --git a/fonts/OpenSans-Italic-webfont.woff b/fonts/OpenSans-Italic-webfont.woff new file mode 100644 index 0000000..469a29b Binary files /dev/null and b/fonts/OpenSans-Italic-webfont.woff differ diff --git a/fonts/OpenSans-Light-webfont.eot b/fonts/OpenSans-Light-webfont.eot new file mode 100644 index 0000000..837daab Binary files /dev/null and b/fonts/OpenSans-Light-webfont.eot differ diff --git a/fonts/OpenSans-Light-webfont.svg b/fonts/OpenSans-Light-webfont.svg new file mode 100644 index 0000000..bdb6726 --- /dev/null +++ b/fonts/OpenSans-Light-webfont.svg @@ -0,0 +1,146 @@ + + + + +This is a custom SVG webfont generated by Font Squirrel. +Copyright : Digitized data copyright 20102011 Google Corporation +Foundry : Ascender Corporation +Foundry URL : httpwwwascendercorpcom + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/fonts/OpenSans-Light-webfont.ttf b/fonts/OpenSans-Light-webfont.ttf new file mode 100644 index 0000000..b50ef9d Binary files /dev/null and b/fonts/OpenSans-Light-webfont.ttf differ diff --git a/fonts/OpenSans-Light-webfont.woff b/fonts/OpenSans-Light-webfont.woff new file mode 100644 index 0000000..99514d1 Binary files /dev/null and b/fonts/OpenSans-Light-webfont.woff differ diff --git a/fonts/OpenSans-LightItalic-webfont.eot b/fonts/OpenSans-LightItalic-webfont.eot new file mode 100644 index 0000000..f0ebf2c Binary files /dev/null and b/fonts/OpenSans-LightItalic-webfont.eot differ diff --git a/fonts/OpenSans-LightItalic-webfont.svg b/fonts/OpenSans-LightItalic-webfont.svg new file mode 100644 index 0000000..60765da --- /dev/null +++ b/fonts/OpenSans-LightItalic-webfont.svg @@ -0,0 +1,146 @@ + + + + +This is a custom SVG webfont generated by Font Squirrel. +Copyright : Digitized data copyright 20102011 Google Corporation +Foundry : Ascender Corporation +Foundry URL : httpwwwascendercorpcom + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/fonts/OpenSans-LightItalic-webfont.ttf b/fonts/OpenSans-LightItalic-webfont.ttf new file mode 100644 index 0000000..5898c8c Binary files /dev/null and b/fonts/OpenSans-LightItalic-webfont.ttf differ diff --git a/fonts/OpenSans-LightItalic-webfont.woff b/fonts/OpenSans-LightItalic-webfont.woff new file mode 100644 index 0000000..9c978dc Binary files /dev/null and b/fonts/OpenSans-LightItalic-webfont.woff differ diff --git a/fonts/OpenSans-Regular-webfont.eot b/fonts/OpenSans-Regular-webfont.eot new file mode 100644 index 0000000..dd6fd2c Binary files /dev/null and b/fonts/OpenSans-Regular-webfont.eot differ diff --git a/fonts/OpenSans-Regular-webfont.svg b/fonts/OpenSans-Regular-webfont.svg new file mode 100644 index 0000000..01038bb --- /dev/null +++ b/fonts/OpenSans-Regular-webfont.svg @@ -0,0 +1,146 @@ + + + + +This is a custom SVG webfont generated by Font Squirrel. +Copyright : Digitized data copyright 20102011 Google Corporation +Foundry : Ascender Corporation +Foundry URL : httpwwwascendercorpcom + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/fonts/OpenSans-Regular-webfont.ttf b/fonts/OpenSans-Regular-webfont.ttf new file mode 100644 index 0000000..05951e7 Binary files /dev/null and b/fonts/OpenSans-Regular-webfont.ttf differ diff --git a/fonts/OpenSans-Regular-webfont.woff b/fonts/OpenSans-Regular-webfont.woff new file mode 100644 index 0000000..274664b Binary files /dev/null and b/fonts/OpenSans-Regular-webfont.woff differ diff --git a/fonts/OpenSans-Semibold-webfont.eot b/fonts/OpenSans-Semibold-webfont.eot new file mode 100644 index 0000000..289aade Binary files /dev/null and b/fonts/OpenSans-Semibold-webfont.eot differ diff --git a/fonts/OpenSans-Semibold-webfont.svg b/fonts/OpenSans-Semibold-webfont.svg new file mode 100644 index 0000000..cc2ca42 --- /dev/null +++ b/fonts/OpenSans-Semibold-webfont.svg @@ -0,0 +1,146 @@ + + + + +This is a custom SVG webfont generated by Font Squirrel. +Copyright : Digitized data copyright 2011 Google Corporation +Foundry : Ascender Corporation +Foundry URL : httpwwwascendercorpcom + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/fonts/OpenSans-Semibold-webfont.ttf b/fonts/OpenSans-Semibold-webfont.ttf new file mode 100644 index 0000000..6f15073 Binary files /dev/null and b/fonts/OpenSans-Semibold-webfont.ttf differ diff --git a/fonts/OpenSans-Semibold-webfont.woff b/fonts/OpenSans-Semibold-webfont.woff new file mode 100644 index 0000000..4e47cb1 Binary files /dev/null and b/fonts/OpenSans-Semibold-webfont.woff differ diff --git a/fonts/OpenSans-SemiboldItalic-webfont.eot b/fonts/OpenSans-SemiboldItalic-webfont.eot new file mode 100644 index 0000000..50a8a6f Binary files /dev/null and b/fonts/OpenSans-SemiboldItalic-webfont.eot differ diff --git a/fonts/OpenSans-SemiboldItalic-webfont.svg b/fonts/OpenSans-SemiboldItalic-webfont.svg new file mode 100644 index 0000000..65b50e2 --- /dev/null +++ b/fonts/OpenSans-SemiboldItalic-webfont.svg @@ -0,0 +1,146 @@ + + + + +This is a custom SVG webfont generated by Font Squirrel. +Copyright : Digitized data copyright 20102011 Google Corporation +Foundry : Ascender Corporation +Foundry URL : httpwwwascendercorpcom + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/fonts/OpenSans-SemiboldItalic-webfont.ttf b/fonts/OpenSans-SemiboldItalic-webfont.ttf new file mode 100644 index 0000000..55ba312 Binary files /dev/null and b/fonts/OpenSans-SemiboldItalic-webfont.ttf differ diff --git a/fonts/OpenSans-SemiboldItalic-webfont.woff b/fonts/OpenSans-SemiboldItalic-webfont.woff new file mode 100644 index 0000000..0adc6df Binary files /dev/null and b/fonts/OpenSans-SemiboldItalic-webfont.woff differ diff --git a/images/bullet.png b/images/bullet.png new file mode 100644 index 0000000..22ea543 Binary files /dev/null and b/images/bullet.png differ diff --git a/images/hr.gif b/images/hr.gif new file mode 100644 index 0000000..bdb4168 Binary files /dev/null and b/images/hr.gif differ diff --git a/images/nav-bg.gif b/images/nav-bg.gif new file mode 100644 index 0000000..4743965 Binary files /dev/null and b/images/nav-bg.gif differ diff --git a/index.html b/index.html new file mode 100644 index 0000000..b9f545f --- /dev/null +++ b/index.html @@ -0,0 +1,115 @@ + + + + + + Javascript-data-structures by Bishop92 + + + + + + + + + + + + +
+ +
+
+

Javascript-data-structures

+

A library for data structure in JavaScript

+
+ Project maintained by Bishop92 + Hosted on GitHub Pages — Theme by mattgraham +
+ +

+Data Structures +

+ +

A library for data structures in JavaScript

+ +

DataStructures is a JavaScript library where you can find the most common data structures and also other data +structures more advanced. Various method are also provided in order to manipulate data structures.

+ +

This library implements the iterator pattern in order to hide +the data structure that work for storing your data.

+ +

+Supported data structures

+ +

+How to use

+ +
    +
  1. Download the minimized library here (right click and save as...);

  2. +
  3. Include the file in your project;

  4. +
  5. Start to use it as any other class.

  6. +

Example

+ +
var listA = new DoubleLinkedList();
+var listB = new DoubleLinkedList();
+listA.fromArray([0, 1]);
+listB.fromArray([2, 3]);
+listA.join(listB);
+listA.toArray(); // [0, 1, 2, 3]
+
+ +

+Documentation

+ +

Follow this link to read the full documentation. +Follow this link to read the JSDoc.

+ +

+History

+ +

+Future implementations

+ +
    +
  • Persistence for data structures like array and lists.
  • +

+Current state of the art

+ +
    +
  • v 1.0.0 First release of the library.
  • +

+Support

+ +

Battistella Stefano, stefano.battistella.92@gmail.com

+
+ +
+ + + + \ No newline at end of file diff --git a/javascripts/respond.js b/javascripts/respond.js new file mode 100644 index 0000000..76bc260 --- /dev/null +++ b/javascripts/respond.js @@ -0,0 +1,779 @@ +if(typeof Object.create!=="function"){ +Object.create=function(o){ +function F(){ +}; +F.prototype=o; +return new F(); +}; +} +var ua={toString:function(){ +return navigator.userAgent; +},test:function(s){ +return this.toString().toLowerCase().indexOf(s.toLowerCase())>-1; +}}; +ua.version=(ua.toString().toLowerCase().match(/[\s\S]+(?:rv|it|ra|ie)[\/: ]([\d.]+)/)||[])[1]; +ua.webkit=ua.test("webkit"); +ua.gecko=ua.test("gecko")&&!ua.webkit; +ua.opera=ua.test("opera"); +ua.ie=ua.test("msie")&&!ua.opera; +ua.ie6=ua.ie&&document.compatMode&&typeof document.documentElement.style.maxHeight==="undefined"; +ua.ie7=ua.ie&&document.documentElement&&typeof document.documentElement.style.maxHeight!=="undefined"&&typeof XDomainRequest==="undefined"; +ua.ie8=ua.ie&&typeof XDomainRequest!=="undefined"; +var domReady=function(){ +var _1=[]; +var _2=function(){ +if(!arguments.callee.done){ +arguments.callee.done=true; +for(var i=0;i<_1.length;i++){ +_1[i](); +} +} +}; +if(document.addEventListener){ +document.addEventListener("DOMContentLoaded",_2,false); +} +if(ua.ie){ +(function(){ +try{ +document.documentElement.doScroll("left"); +} +catch(e){ +setTimeout(arguments.callee,50); +return; +} +_2(); +})(); +document.onreadystatechange=function(){ +if(document.readyState==="complete"){ +document.onreadystatechange=null; +_2(); +} +}; +} +if(ua.webkit&&document.readyState){ +(function(){ +if(document.readyState!=="loading"){ +_2(); +}else{ +setTimeout(arguments.callee,10); +} +})(); +} +window.onload=_2; +return function(fn){ +if(typeof fn==="function"){ +_1[_1.length]=fn; +} +return fn; +}; +}(); +var cssHelper=function(){ +var _3={BLOCKS:/[^\s{][^{]*\{(?:[^{}]*\{[^{}]*\}[^{}]*|[^{}]*)*\}/g,BLOCKS_INSIDE:/[^\s{][^{]*\{[^{}]*\}/g,DECLARATIONS:/[a-zA-Z\-]+[^;]*:[^;]+;/g,RELATIVE_URLS:/url\(['"]?([^\/\)'"][^:\)'"]+)['"]?\)/g,REDUNDANT_COMPONENTS:/(?:\/\*([^*\\\\]|\*(?!\/))+\*\/|@import[^;]+;)/g,REDUNDANT_WHITESPACE:/\s*(,|:|;|\{|\})\s*/g,MORE_WHITESPACE:/\s{2,}/g,FINAL_SEMICOLONS:/;\}/g,NOT_WHITESPACE:/\S+/g}; +var _4,_5=false; +var _6=[]; +var _7=function(fn){ +if(typeof fn==="function"){ +_6[_6.length]=fn; +} +}; +var _8=function(){ +for(var i=0;i<_6.length;i++){ +_6[i](_4); +} +}; +var _9={}; +var _a=function(n,v){ +if(_9[n]){ +var _b=_9[n].listeners; +if(_b){ +for(var i=0;i<_b.length;i++){ +_b[i](v); +} +} +} +}; +var _c=function(_d,_e,_f){ +if(ua.ie&&!window.XMLHttpRequest){ +window.XMLHttpRequest=function(){ +return new ActiveXObject("Microsoft.XMLHTTP"); +}; +} +if(!XMLHttpRequest){ +return ""; +} +var r=new XMLHttpRequest(); +try{ +r.open("get",_d,true); +r.setRequestHeader("X_REQUESTED_WITH","XMLHttpRequest"); +} +catch(e){ +_f(); +return; +} +var _10=false; +setTimeout(function(){ +_10=true; +},5000); +document.documentElement.style.cursor="progress"; +r.onreadystatechange=function(){ +if(r.readyState===4&&!_10){ +if(!r.status&&location.protocol==="file:"||(r.status>=200&&r.status<300)||r.status===304||navigator.userAgent.indexOf("Safari")>-1&&typeof r.status==="undefined"){ +_e(r.responseText); +}else{ +_f(); +} +document.documentElement.style.cursor=""; +r=null; +} +}; +r.send(""); +}; +var _11=function(_12){ +_12=_12.replace(_3.REDUNDANT_COMPONENTS,""); +_12=_12.replace(_3.REDUNDANT_WHITESPACE,"$1"); +_12=_12.replace(_3.MORE_WHITESPACE," "); +_12=_12.replace(_3.FINAL_SEMICOLONS,"}"); +return _12; +}; +var _13={mediaQueryList:function(s){ +var o={}; +var idx=s.indexOf("{"); +var lt=s.substring(0,idx); +s=s.substring(idx+1,s.length-1); +var mqs=[],rs=[]; +var qts=lt.toLowerCase().substring(7).split(","); +for(var i=0;i-1&&_23.href&&_23.href.length!==0&&!_23.disabled){ +_1f[_1f.length]=_23; +} +} +if(_1f.length>0){ +var c=0; +var _24=function(){ +c++; +if(c===_1f.length){ +_20(); +} +}; +var _25=function(_26){ +var _27=_26.href; +_c(_27,function(_28){ +_28=_11(_28).replace(_3.RELATIVE_URLS,"url("+_27.substring(0,_27.lastIndexOf("/"))+"/$1)"); +_26.cssHelperText=_28; +_24(); +},_24); +}; +for(i=0;i<_1f.length;i++){ +_25(_1f[i]); +} +}else{ +_20(); +} +}; +var _29={mediaQueryLists:"array",rules:"array",selectors:"object",declarations:"array",properties:"object"}; +var _2a={mediaQueryLists:null,rules:null,selectors:null,declarations:null,properties:null}; +var _2b=function(_2c,v){ +if(_2a[_2c]!==null){ +if(_29[_2c]==="array"){ +return (_2a[_2c]=_2a[_2c].concat(v)); +}else{ +var c=_2a[_2c]; +for(var n in v){ +if(v.hasOwnProperty(n)){ +if(!c[n]){ +c[n]=v[n]; +}else{ +c[n]=c[n].concat(v[n]); +} +} +} +return c; +} +} +}; +var _2d=function(_2e){ +_2a[_2e]=(_29[_2e]==="array")?[]:{}; +for(var i=0;i<_4.length;i++){ +_2b(_2e,_4[i].cssHelperParsed[_2e]); +} +return _2a[_2e]; +}; +domReady(function(){ +var els=document.body.getElementsByTagName("*"); +for(var i=0;i=_44)||(max&&_46<_44)||(!min&&!max&&_46===_44)); +}else{ +return false; +} +}else{ +return _46>0; +} +}else{ +if("device-height"===_41.substring(l-13,l)){ +_47=screen.height; +if(_42!==null){ +if(_43==="length"){ +return ((min&&_47>=_44)||(max&&_47<_44)||(!min&&!max&&_47===_44)); +}else{ +return false; +} +}else{ +return _47>0; +} +}else{ +if("width"===_41.substring(l-5,l)){ +_46=document.documentElement.clientWidth||document.body.clientWidth; +if(_42!==null){ +if(_43==="length"){ +return ((min&&_46>=_44)||(max&&_46<_44)||(!min&&!max&&_46===_44)); +}else{ +return false; +} +}else{ +return _46>0; +} +}else{ +if("height"===_41.substring(l-6,l)){ +_47=document.documentElement.clientHeight||document.body.clientHeight; +if(_42!==null){ +if(_43==="length"){ +return ((min&&_47>=_44)||(max&&_47<_44)||(!min&&!max&&_47===_44)); +}else{ +return false; +} +}else{ +return _47>0; +} +}else{ +if("device-aspect-ratio"===_41.substring(l-19,l)){ +return _43==="aspect-ratio"&&screen.width*_44[1]===screen.height*_44[0]; +}else{ +if("color-index"===_41.substring(l-11,l)){ +var _48=Math.pow(2,screen.colorDepth); +if(_42!==null){ +if(_43==="absolute"){ +return ((min&&_48>=_44)||(max&&_48<_44)||(!min&&!max&&_48===_44)); +}else{ +return false; +} +}else{ +return _48>0; +} +}else{ +if("color"===_41.substring(l-5,l)){ +var _49=screen.colorDepth; +if(_42!==null){ +if(_43==="absolute"){ +return ((min&&_49>=_44)||(max&&_49<_44)||(!min&&!max&&_49===_44)); +}else{ +return false; +} +}else{ +return _49>0; +} +}else{ +if("resolution"===_41.substring(l-10,l)){ +var res; +if(_45==="dpcm"){ +res=_3d("1cm"); +}else{ +res=_3d("1in"); +} +if(_42!==null){ +if(_43==="resolution"){ +return ((min&&res>=_44)||(max&&res<_44)||(!min&&!max&&res===_44)); +}else{ +return false; +} +}else{ +return res>0; +} +}else{ +return false; +} +} +} +} +} +} +} +} +}; +var _4a=function(mq){ +var _4b=mq.getValid(); +var _4c=mq.getExpressions(); +var l=_4c.length; +if(l>0){ +for(var i=0;i0){ +s[c++]=","; +} +s[c++]=n; +} +} +if(s.length>0){ +_39[_39.length]=cssHelper.addStyle("@media "+s.join("")+"{"+mql.getCssText()+"}",false); +} +}; +var _4e=function(_4f){ +for(var i=0;i<_4f.length;i++){ +_4d(_4f[i]); +} +if(ua.ie){ +document.documentElement.style.display="block"; +setTimeout(function(){ +document.documentElement.style.display=""; +},0); +setTimeout(function(){ +cssHelper.broadcast("cssMediaQueriesTested"); +},100); +}else{ +cssHelper.broadcast("cssMediaQueriesTested"); +} +}; +var _50=function(){ +for(var i=0;i<_39.length;i++){ +cssHelper.removeStyle(_39[i]); +} +_39=[]; +cssHelper.mediaQueryLists(_4e); +}; +var _51=0; +var _52=function(){ +var _53=cssHelper.getViewportWidth(); +var _54=cssHelper.getViewportHeight(); +if(ua.ie){ +var el=document.createElement("div"); +el.style.position="absolute"; +el.style.top="-9999em"; +el.style.overflow="scroll"; +document.body.appendChild(el); +_51=el.offsetWidth-el.clientWidth; +document.body.removeChild(el); +} +var _55; +var _56=function(){ +var vpw=cssHelper.getViewportWidth(); +var vph=cssHelper.getViewportHeight(); +if(Math.abs(vpw-_53)>_51||Math.abs(vph-_54)>_51){ +_53=vpw; +_54=vph; +clearTimeout(_55); +_55=setTimeout(function(){ +if(!_3a()){ +_50(); +}else{ +cssHelper.broadcast("cssMediaQueriesTested"); +} +},500); +} +}; +window.onresize=function(){ +var x=window.onresize||function(){ +}; +return function(){ +x(); +_56(); +}; +}(); +}; +var _57=document.documentElement; +_57.style.marginLeft="-32767px"; +setTimeout(function(){ +_57.style.marginTop=""; +},20000); +return function(){ +if(!_3a()){ +cssHelper.addListener("newStyleParsed",function(el){ +_4e(el.cssHelperParsed.mediaQueryLists); +}); +cssHelper.addListener("cssMediaQueriesTested",function(){ +if(ua.ie){ +_57.style.width="1px"; +} +setTimeout(function(){ +_57.style.width=""; +_57.style.marginLeft=""; +},0); +cssHelper.removeListener("cssMediaQueriesTested",arguments.callee); +}); +_3c(); +_50(); +}else{ +_57.style.marginLeft=""; +} +_52(); +}; +}()); +try{ +document.execCommand("BackgroundImageCache",false,true); +} +catch(e){ +} + diff --git a/lib/Aggregate/Aggregate.js b/lib/Aggregate/Aggregate.js deleted file mode 100644 index 7b0c5ba..0000000 --- a/lib/Aggregate/Aggregate.js +++ /dev/null @@ -1,15 +0,0 @@ -/** - * Created by Stefano on 04/04/2014. - */ - -function Aggregate() { - -} - -/** - * Returns the iterator relative to the aggregate. - * @abstract - * @return {Iterator} The iterator. - */ -Aggregate.prototype.getIterator = function () { -}; \ No newline at end of file diff --git a/lib/Aggregate/Iterator.js b/lib/Aggregate/Iterator.js deleted file mode 100644 index 971f0e3..0000000 --- a/lib/Aggregate/Iterator.js +++ /dev/null @@ -1,66 +0,0 @@ -/** - * Created by Stefano on 04/04/2014. - */ - -/** - * Interface for managing an iterator for an aggregate. - * @constructor - * @interface - */ -function Iterator() { - -} - -/** - * Moves the iterator to the first position of the aggregate. - * @abstract - * @return {void} - */ -Iterator.prototype.first = function () { - -}; - -/** - * Moves the iterator to the next item. - * @abstract - * @return {void} - */ -Iterator.prototype.next = function () { - -}; - -/** - * Moves the iterator to the last position of the aggregate. - * @abstract - * @return {void} - */ -Iterator.prototype.last = function () { - -}; - -/** - * Moves the iterator to the previous item. - * @abstract - * @return {void} - */ -Iterator.prototype.previous = function () { - -}; - -/** - * Checks if the iterator is out of the bounds of the aggregate. - * @abstract - * @return {boolean} It return true if the iterator is out of the bounds of the aggregate, otherwise false. - */ -Iterator.prototype.isDone = function () { - -}; - -/** - * Returns the item stored at the position pointed by the iterator. - * @abstract - * @return {*} The item stored or undefined if it's out of the bounds. - */ -Iterator.prototype.getItem = function () { - -}; \ No newline at end of file diff --git a/lib/BSTree/BSTree.js b/lib/BSTree/BSTree.js deleted file mode 100644 index 2421e19..0000000 --- a/lib/BSTree/BSTree.js +++ /dev/null @@ -1,200 +0,0 @@ -/** - * Created by Stefano on 05/04/2014. - */ - -/** - * The single node of the tree. - * @param key {number} The key of the node. - * @param item {*} The item to store in the node. - * @constructor - */ -function BSNode(key, item) { - /** - * The item stored. - * @type {*} - */ - this.item = item; - /** - * The key of the node. - * @type {number} - */ - this.key = key; - /** - * The parent node. It's null if there's no a parent node. - * @type {BSNode|null} - */ - this.parent = null; - /** - * The left node. It's null if there's no a left node. - * @type {BSNode|null} - */ - this.left = null; - /** - * The right node. It's null if there's no a right node. - * @type {BSNode|null} - */ - this.right = null; -} - -BSTree.prototype = new Aggregate(); -BSTree.prototype.constructor = BSTree; - -/** - * Class for managing a binary search tree. - * @constructor - */ -function BSTree() { - /** - * The root of the tree. - * @type {BSNode|null} - */ - this.root = null; -} - -/** - * @inheritDoc - */ -BSTree.prototype.getIterator = function () { - return new BSTreeIterator(this); -}; - -/** - * Insert the item relatives to the key value in the tree. - * @param key {number} The key to store. - * @param item {*} The item to store. - * @return {void} - */ -BSTree.prototype.insert = function (key, item) { - var node = new BSNode(key, item); - var p = this.root; - for (var n = this.root; n;) { - p = n; - if (key < n.key) - n = n.left; - else - n = n.right; - } - node.parent = p; - if (!p) - this.root = node; - else if (key < p.key) - p.left = node; - else - p.right = node; -}; - -/** - * Search the item relatives to the key. - * @param key {Number} The key to find. - * @param [node = root] {BSNode} The node from which start the search. - * @return {*} The item found or undefined if there isn't the key in the tree. - */ -BSTree.prototype.search = function (key, node) { - node = node || this.root; - while (node && key !== node.key) - if (key < node.key) - node = node.left; - else - node = node.right; - if (node) - return node.item; - return undefined; -}; - -/** - * Get the item relatives to the minimum key stored in the tree. - * @param [node = root] {Node} The node from which start the search. - * @return {BSNode} The node found. - */ -BSTree.prototype.minimum = function (node) { - node = node || this.root; - while (node && node.left) - node = node.left; - return node; -}; - -/** - * Get the item relatives to the maximum key stored in the tree. - * @param [node = root] {Node} The node from which start the search. - * @return {BSNode} The node found. - */ -BSTree.prototype.maximum = function (node) { - node = node || this.root; - while (node && node.right) - node = node.right; - return node; -}; - -/** - * Get the node with the key next to the param node key. - * @param node {BSNode} The node of which search the successor. - * @return {BSNode} The node found. - */ -BSTree.prototype.successor = function (node) { - if (node.right) - return this.minimum(node.right); - var parent = node.parent; - while (parent && node === parent.right) { - node = parent; - parent = parent.parent; - } - return parent; -}; - -/** - * Get the node with the key previous to the param node key. - * @param node {BSNode} The node of which search the predecessor. - * @return {BSNode} The node found. - */ -BSTree.prototype.predecessor = function (node) { - if (node.left) - return this.maximum(node.left); - var parent = node.parent; - while (parent && node === parent.left) { - node = parent; - parent = parent.parent; - } - return parent; -}; - -/** - * Delete the node from the tree. - * @param node {BSNode} The node to delete. - * @return {void} - */ -BSTree.prototype.deleteNode = function (node) { - if (!node.left && !node.right) { - if (node === this.root) - this.root = null; - else if (node.parent.left === node) - node.parent.left = null; - else - node.parent.right = null; - } else if (node.left && node.right) { - var next = this.successor(node); - node.key = next.key; - node.item = next.item; - if (next.parent.left === next) - next.parent.left = null; - else - next.parent.right = null; - } else { - if (node.right) { - if (node === this.root) { - this.root = node.right; - node.right.parent = null; - } else { - node.parent.right = node.right; - node.right.parent = node.parent; - } - } else { - if (node === this.root) { - this.root = node.left; - node.left.parent = null; - } else { - node.parent.left = node.left; - node.left.parent = node.parent; - } - } - } -}; \ No newline at end of file diff --git a/lib/BSTree/BSTreeIterator.js b/lib/BSTree/BSTreeIterator.js deleted file mode 100644 index 49c2dfc..0000000 --- a/lib/BSTree/BSTreeIterator.js +++ /dev/null @@ -1,76 +0,0 @@ -/** - * Created by Stefano on 06/04/2014. - */ - -BSTreeIterator.prototype = new Iterator(); -BSTreeIterator.prototype.constructor = BSTreeIterator; - -/** - * Class that implements the iterator for a binary search tree. - * @param aggregate {BSTree} The aggregate to scan. - * @constructor - */ -function BSTreeIterator(aggregate) { - /** - * The aggregate relates to this iterator. - * @type {BSTree} - */ - this.aggregate = aggregate; - - /** - * The pointer to the position. - * @type {BSNode|null} - */ - this.pointer = null; -} - -/** - * @inheritDoc - */ -BSTreeIterator.prototype.first = function () { - this.pointer = this.aggregate.minimum(); -}; - -/** - * @inheritDoc - */ -BSTreeIterator.prototype.next = function () { - this.pointer = this.aggregate.successor(this.pointer); -}; - -/** - * @inheritDoc - */ -BSTreeIterator.prototype.last = function () { - this.pointer = this.aggregate.maximum(); -}; - -/** - * @inheritDoc - */ -BSTreeIterator.prototype.previous = function () { - this.pointer = this.aggregate.predecessor(this.pointer); -}; - -/** - * @inheritDoc - */ -BSTreeIterator.prototype.isDone = function () { - return !this.pointer; -}; - -/** - * @inheritDoc - */ -BSTreeIterator.prototype.getItem = function () { - return this.pointer.item; -}; - -/** - * Return the node stored at the position pointed by the iterator. - * @abstract - * @return {BSNode|null} The node stored or null if it's out of the bounds. - */ -BSTreeIterator.prototype.getNode = function () { - return this.pointer; -}; \ No newline at end of file diff --git a/lib/BTree/BTree.js b/lib/BTree/BTree.js deleted file mode 100644 index afbd5a7..0000000 --- a/lib/BTree/BTree.js +++ /dev/null @@ -1,682 +0,0 @@ -/** - * Created by Stefano on 08/04/2014. - */ - -/** - * The single node of the tree. - * @constructor - */ -function BNode() { - /** - * The keys stored it the node. - * @type {Array<*>} - */ - this.keys = []; - /** - * The items stored in the node. - * @type {Array<*>} - */ - this.items = []; - /** - * The nodes child of the node. - * @type {Array} - */ - this.childs = []; -} - -BTree.prototype = new Aggregate(); -BTree.prototype.constructor = BTree; - -/** - * Class for managing a B-Tree. - * @param minimumDegree {number} The minimum number of keys of a node. - * @constructor - */ -function BTree(minimumDegree) { - /** - * The root of the tree. - * @type {BNode} - */ - this.root = new BNode(); - - /** - * The minimum number of the keys of a node. - * @type {number} - */ - this.t = minimumDegree; - - /** - * The number of items stored in the tree. - * @type {number} - */ - this.size = 0; -} - -/** - * @inheritDoc - */ -BTree.prototype.getIterator = function () { - return new BTreeIterator(this); -}; - -/** - * Insert the item relatives to the key value in the tree. - * @param key {number} The key to store. - * @param item {*} The item to store. - * @return {void} - */ -BTree.prototype.insert = function (key, item) { - var node = this.root; - if (node.keys.length === 2 * this.t - 1) { - var newNode = new BNode(); - newNode.childs.push(node); - this.root = newNode; - this.splitChild(newNode, 0); - node = newNode; - } - this.size++; - this.insertNonFull(node, key, item); -}; - -/** - * Insert the new node in the right position if the node is not full. - * @param node {BNode} The node from which start to check the insertion. - * @param key {number} The key to store. - * @param item {*} The item to store. - * @return {void} - */ -BTree.prototype.insertNonFull = function (node, key, item) { - while (node) { - var i = node.keys.length - 1; - if (!node.childs.length) { - for (; i > -1 && key < node.keys[i]; i--) { - node.keys[i + 1] = node.keys[i]; - node.items[i + 1] = node.items[i]; - } - node.keys[i + 1] = key; - node.items[i + 1] = item; - return; - } else { - var j = 0; - i++; - while (j < i) { - var m = Math.floor((j + i) / 2); - if (key <= node.keys[m]) - i = m; - else - j = m + 1; - } - if (node.childs[j].keys.length === 2 * this.t - 1) { - this.splitChild(node, j); - if (key > node.keys[j]) - j++; - } - node = node.childs[j]; - } - } -}; - -/** - * Search the item relatives to the key that satisfy the condition represented by the callback function. - * @param key {Number} The key to find. - * @param [node = root] {RBNode} The node from which start the search. - * @param [callback = function(node,index){return(node.keys[index]===key);}] The condition to satisfy. The callback must accept the current node to check and optionally the position of the key. - * @return {*} The item found or undefined if there isn't the key in the tree. - */ -BTree.prototype.search = function (key, node, callback) { - node = node || this.root; - callback = callback || function (node, index) { - return node.keys[index] === key; - }; - while (node) { - var n = node.keys.length; - var i = 0, j = n; - while (i < j) { - var m = Math.floor((i + j) / 2); - if (key <= node.keys[m]) - j = m; - else - i = m + 1; - } - if (i < n && callback(node, i)) - return node.items[i]; - else if (!node.childs.length) - return undefined; - else - node = node.childs[i]; - } -}; - -/** - * Split the child of the node at the position index. - * @param node {BNode} The parent of the child to split. - * @param index {number} The position of the child to split. - * @return {void} - */ -BTree.prototype.splitChild = function (node, index) { - var newNode = new BNode(); - var child = node.childs[index]; - //copy of the last t - 1 keys and items in the new node - for (var i = 0; i < this.t - 1; i++) { - newNode.keys[i] = child.keys[i + this.t]; - newNode.items[i] = child.items[i + this.t]; - } - if (child.childs.length) - //copy of the last t child in the new node - for (var j = 0; j < this.t; j++) - newNode.childs[j] = child.childs[j + this.t]; - //shift the children from index + 1 position - for (var l = node.keys.length; l > index; l--) - node.childs[l + 1] = node.childs[l]; - //set the index position as the position t of the child - node.childs[index + 1] = newNode; - //shift the keys and the items from index position - for (var k = node.keys.length - 1; k > index - 1; k--) { - node.keys[k + 1] = node.keys[k]; - node.items[k + 1] = node.items[k]; - } - node.keys[index] = child.keys[this.t - 1]; - node.items[index] = child.items[this.t - 1]; - //remove keys, items and child in the old node. - child.keys.splice(child.keys.length - this.t); - child.items.splice(child.items.length - this.t); - child.childs.splice(child.childs.length - this.t); -}; - -/** - * Delete the key from the tree. - * @param key {*} The key to delete. - * @return {void} - */ -BTree.prototype.deleteKey = function (key) { - if (this.root.keys.length) { - this.deleteNonMin(this.root, key); - if (!this.root.keys.length && this.root.childs.length) - this.root = this.root.childs[0]; - this.size--; - } -}; - -/** - * Deletes a node that's a number of keys greater than the minimum for a node. - * @param node {BNode} The node to delete. - * @param key {number} The key to delete. - * @return {void} - */ -BTree.prototype.deleteNonMin = function (node, key) { - var i = 0, j = node.keys.length; - while (i < j) { - var m = Math.floor((i + j) / 2); - if (key <= node.keys[m]) - j = m; - else - i = m + 1; - } - //key is in the node - if (i < node.keys.length && key === node.keys[i]) { - //the node is a leaf - if (!node.childs.length) { - //remove the key - for (j = i + 1; j < node.keys.length; j++) { - node.keys[j - 1] = node.keys[j]; - node.items[j - 1] = node.items[j]; - } - node.keys.pop(); - node.items.pop(); - } else { - //the node is not a leaf - //the node has the minimum number of keys - if (node.childs[i].length === this.t - 1) { - //increase the number of the keys of the node - this.augmentChild(node, i); - if (i === node.keys.length + 1) - i--; - } - //check if the key is moved in the child - if (node.keys[i] !== key) - this.deleteNonMin(node.childs[i], key); - else - this.deleteMax(node, i); - } - //the key is not in the node - } else { - //check if the child i has the minimum number of keys - if (node.childs[i].keys.length === this.t - 1) { - this.augmentChild(node, i); - if (i === node.keys.length + 2) - i--; - } - this.deleteNonMin(node.childs[i], key); - } -}; - -/** - * Deletes a node that have the maximum number of keys for node. - * @param node {BNode} The node to delete. - * @param index {number} The key to delete in the node. - * @return {void} - */ -BTree.prototype.deleteMax = function (node, index) { - var child = node.childs[index]; - var goAhead = true; - while (goAhead) { - if (!child.childs.length) { - node.keys[index] = child.keys[child.keys.length - 1]; - node.items[index] = child.items[child.items.length - 1]; - child.keys.pop(); - child.items.pop(); - goAhead = false; - } else { - var last = child.childs[child.keys.length]; - if (last.keys.length === this.t - 1) - this.augmentChild(child, child.keys.length); - child = child.childs[child.keys.length]; - } - } -}; - -/** - * Augments the number of keys stored in the node preserving the order. - * @param node {BNode} The node to delete. - * @param index {number} The index of the position to augment. - * @return {void} - */ -BTree.prototype.augmentChild = function (node, index) { - var child = node.childs[index]; - var brother; - if (index) - brother = node.childs[index - 1]; - if (index && brother.keys.length > this.t - 1) { - if (child.childs.length) { - for (var j = this.keys.length + 1; j > 0; j--) - child.childs[j] = child.childs[j - 1]; - child.childs[0] = brother.childs[brother.keys.length]; - for (var i = child.keys.length; i > 0; i--) { - child.keys[i] = child.keys[i - 1]; - child.items[i] = child.items[i - 1]; - } - child.keys[0] = node.keys[index - 1]; - child.items[0] = node.items[index - 1]; - node.keys[index - 1] = brother.keys[brother.keys.length - 1]; - node.items[index - 1] = brother.items[brother.items.length - 1]; - } - } else { - if (index < node.keys.length) - brother = node.childs[index + 1]; - if (index < node.keys.length && brother.keys.length > this.t - 1) { - if (brother.childs.length) { - child.childs[child.keys.length + 1] = brother.childs[0]; - for (var l = 1; l < brother.keys.length + 1; l++) - brother.childs[l - 1] = brother.childs[l]; - brother.childs.pop(); - } - child.keys[child.keys.length] = node.keys[index]; - child.items[child.items.length] = node.items[index]; - node.keys[index] = brother.keys[0]; - node.items[index] = brother.items[0]; - for (var k = 1; k < brother.keys.length; k++) { - brother.keys[k - 1] = brother.keys[k]; - brother.items[k - 1] = brother.items[k]; - } - brother.keys.pop(); - brother.items.pop(); - } else { - if (index < node.keys.length) { - child.keys[this.t - 1] = node.keys[index]; - child.items[this.t - 1] = node.items[index]; - for (var m = index + 2; m < node.keys.length + 1; m++) - node.childs[m - 1] = node.childs[m]; - node.childs.pop(); - for (var n = index + 1; n < node.keys.length; n++) { - node.keys[n - 1] = node.keys[n]; - node.items[n - 1] = node.items[n]; - } - node.keys.pop(); - node.items.pop(); - if (brother.childs.length) - for (var y = 0; y < brother.keys.length + 1; y++) - child.childs[this.t + y] = brother.childs[y]; - for (var x = 0; x < brother.keys.length; x++) { - child.keys[x + this.t] = brother.keys[x]; - child.items[x + this.t] = brother.items[x]; - } - } else { - if (brother.childs.length) - for (var w = 0; w < child.keys.length + 1; w++) - brother.childs[this.t + w] = child.childs[w]; - brother.keys[this.t - 1] = node.keys[node.keys.length - 1]; - brother.items[this.t - 1] = node.items[node.keys.length - 1]; - for (var z = 0; z < child.keys.length; z++) { - brother.keys[z + this.t] = child.keys[z]; - brother.items[z + this.t] = child.items[z]; - } - } - } - } -}; - -/** - * Checks if the tree contains the key. - * @param key {number} The key to find. - * @param [callback = function(node,index){return(node.keys[index]===key);}] The condition to satisfy. The callback must accept the current node to check and optionally the position of the key. - * @return {boolean} True if the tree contains the key. - */ -BTree.prototype.contains = function (key, callback) { - return this.search(key, null, callback) !== undefined; -}; - -/** - * Checks if the tree contains a node that satisfy the condition represented by the callback function. - * This method check all the tree avoiding the binary search. - * @param callback {function} The condition to satisfy. The callback must accept the current node to check. - * @return {boolean} True if the tree contains the node that satisfy the condition, false otherwise. - */ -BTree.prototype.fullContains = function (callback) { - var key = this.minimumKey(); - while (key !== null && !callback(this.search(key))) - key = this.successor(key); - return key !== null; -}; - -/** - * Get the key next to the param node key. - * @param key {number} The key of which search the successor. - * @param [node = root] The node from start the search of the successor. - * @return {number} The key found. - */ -BTree.prototype.successor = function (key, node) { - node = node || this.root; - var i = 0, j = node.keys.length; - //search the key in the node - while (i < j) { - var m = Math.floor((i + j) / 2); - if (key <= node.keys[m]) - j = m; - else - i = m + 1; - } - //check if the key has been found - if (node.keys[i] === key) - //in this case the successor is the next key - i++; - //if it's a leaf - if (!node.childs.length) { - //check if the key hasn't been found - if (i > node.keys.length - 1) - return null; - else - return node.keys[i]; - } - //if it's not a leaf check if the successor is in the i-child - var successor = this.successor(key, node.childs[i]); - //if it's not in the child and has been found a key then return it - if (successor === null && i < node.keys.length) - return node.keys[i]; - //return the value of the successor even if it's null - return successor; -}; - -/** - * Get the key previous to the param key. - * @param key {number} The key of which search the predecessor. - * @param [node = root] The node from start the search of the predecessor. - * @return {number} The key found. - */ -BTree.prototype.predecessor = function (key, node) { - node = node || this.root; - var i = 0, j = node.keys.length; - //search the key in the node - while (i < j) { - var m = Math.floor((i + j) / 2); - if (key <= node.keys[m]) - j = m; - else - i = m + 1; - } - i--; - //check if the node is a leaf - if (!node.childs.length) { - //check if a predecessor has been found - if (i < 0) - return null; - else - return node.keys[i]; - } - var predecessor = this.predecessor(key, node.childs[i + 1]); - if (predecessor === null && key > node.keys[0]) { - return node.keys[i]; - } - return predecessor; -}; - -/** - * Gets the minimum key stored in the tree. - * @return {number} The key found. - */ -BTree.prototype.minimumKey = function () { - var node = this.root; - while (node.childs.length) - node = node.childs[0]; - if (node) - return node.keys[0]; - return null; -}; - -/** - * Gets the maximum key stored in the tree. - * @return {number} The key found. - */ -BTree.prototype.maximumKey = function () { - var node = this.root; - while (node.childs.length) - node = node.childs[node.childs.length - 1]; - if (node) - return node.keys[node.keys.length - 1]; - return null; -}; - -/** - * Gets the item relatives to the minimum key stored in the tree. - * @return {number} The item found. - */ -BTree.prototype.minimum = function () { - var node = this.root; - while (node.childs.length) - node = node.childs[0]; - return node.items[0]; -}; - -/** - * Gets the item relatives to the maximum key stored in the tree. - * @return {node} The item found. - */ -BTree.prototype.maximum = function () { - var node = this.root; - while (node.childs.length) - node = node.childs[node.childs.length - 1]; - return node.items[node.items.length - 1]; -}; - -/** - * Returns the size of the tree. - * @return {number} The size of the tree. - */ -BTree.prototype.getSize = function () { - return this.size; -}; - -/** - * Checks if the tree is empty. - * @return {boolean} True if the tree is empty, false otherwise. - */ -BTree.prototype.isEmpty = function () { - return !this.size; -}; - -/** - * Executes the callback function for each item of the tree. - * This method modifies the tree so if you don't need to modify it you must return the same item of the array. - * @param callback {function} The function to execute for each item. The function must accept the current item on which execute the function. - * @return {void} - */ -BTree.prototype.execute = function (callback) { - var node = arguments[1] || this.root; - for (var i = 0; i < node.items.length; i++) - node.items[i] = callback(node.items[i]); - for (var j = 0; j < node.childs.length; j++) - this.execute(callback, node.childs[j]); -}; - -/** - * Removes all the items stored in the tree. - * @return {void} - */ -BTree.prototype.clear = function () { - this.root = null; - this.size = 0; -}; - -/** - * Returns the items that satisfy the condition determined by the callback. - * @param callback {function} The function that implements the condition. - * @return {Array<*>} The array that contains the items that satisfy the condition. - */ -BTree.prototype.filter = function (callback) { - var result = []; - var node = arguments[1] || this.root; - for (var i = 0; i < node.items.length; i++) { - if (node.childs.length) - result = result.concat(this.filter(callback, node.childs[i])); - if (callback(node.items[i])) - result.push(node.items[i]); - } - if (node.childs.length) - result = result.concat(this.filter(callback, node.childs[node.childs.length - 1])); - return result; -}; - -/** - * Clones the tree into a new tree. - * @return {BTree} The tree cloned from this tree. - */ -BTree.prototype.clone = function () { - var tree = new BTree(this.t); - var it = this.getIterator(); - for (it.first(); !it.isDone(); it.next()) { - var item = it.getItem(); - if (item.clone) - item = item.clone(); - tree.insert(it.getKey(), item); - } - return tree; -}; - -/** - * Clones the tree into a new tree without cloning duplicated items. - * @return {BTree} The tree cloned from this tree. - */ -BTree.prototype.cloneDistinct = function () { - var tree = new BTree(this.t); - var it = this.getIterator(); - for (it.first(); !it.isDone(); it.next()) { - var callback = function (item) { - return item === it.getItem(); - }; - if (!tree.fullContains(callback)) { - if (it.getItem().cloneDistinct) - tree.insert(it.getKey(), it.getItem().cloneDistinct()); - else if (it.getItem().clone) - tree.insert(it.getKey(), it.getItem().clone()); - else - tree.insert(it.getKey(), it.getItem()); - } - } - return tree; -}; - -/** - * Transform the tree into an array without preserving keys. - * @return {Array<*>} The array that represents the tree. - */ -BTree.prototype.toArray = function () { - var result = []; - var it = this.getIterator(); - for (it.first(); !it.isDone(); it.next()) - result.push(it.getItem()); - return result; -}; - -/** - * Returns the first position of the item in the tree. - * @param item {*} The item to search. - * @param [callback = function(item){return(it===item);}] The condition to satisfy. The callback must accept the current item to check. - * @return {number} The first position of the item. - */ -BTree.prototype.indexOf = function (item, callback) { - callback = callback || function (it) { - return it === item; - }; - var i = 0, key = this.minimumKey(); - while (key !== null) { - if (callback(this.search(key))) - return i; - key = this.successor(key); - i++; - } - return -1; -}; - -/** - * Returns the last position of the item in the tree. - * @param item {*} The item to search. - * @param [callback = function(item){return(it===item);}] The condition to satisfy. The callback must accept the current item to check. - * @return {number} The last position of the item. - */ -BTree.prototype.lastIndexOf = function (item, callback) { - callback = callback || function (it) { - return it === item; - }; - var i = this.size - 1, key = this.maximumKey(); - while (key !== null) { - if (callback(this.search(key))) - return i; - i--; - key = this.predecessor(key); - } - return -1; -}; - -/** - * Returns all the position in which the item has been found in the tree. - * @param item {*} The item to search. - * @param [callback = function(item){return(it===item);}] The condition to satisfy. The callback must accept the current item to check. - * @return {Array} The positions in which the item has been found. - */ -BTree.prototype.allIndexesOf = function (item, callback) { - callback = callback || function (it) { - return it === item; - }; - var i = 0, key = this.minimumKey(); - var indexes = []; - while (key !== null) { - if (callback(this.search(key))) - indexes.push(i); - i++; - key = this.successor(key); - } - return indexes; -}; - -/** - * Returns the item at the position index. - * @param index {number} The position of the item. - * @return {*} The item at the position. It's undefined if index isn't in the tree bounds. - */ -BTree.prototype.getItem = function (index) { - if (index < 0 || index > this.size - 1) - return undefined; - var key = this.minimum(); - for (var i = 0; i < index; i++) - key = this.successor(key); - return this.search(key); -}; \ No newline at end of file diff --git a/lib/BTree/BTreeIterator.js b/lib/BTree/BTreeIterator.js deleted file mode 100644 index d357113..0000000 --- a/lib/BTree/BTreeIterator.js +++ /dev/null @@ -1,76 +0,0 @@ -/** - * Created by Stefano on 06/04/2014. - */ - -BTreeIterator.prototype = new Iterator(); -BTreeIterator.prototype.constructor = BTreeIterator; - -/** - * Class that implements the iterator for a binary search tree. - * @param aggregate {BTree} The aggregate to scan. - * @constructor - */ -function BTreeIterator(aggregate) { - /** - * The aggregate relates to this iterator. - * @type {BTree} - */ - this.aggregate = aggregate; - - /** - * The pointer to the position. - * @type {number} - */ - this.pointer = null; -} - -/** - * @inheritDoc - */ -BTreeIterator.prototype.first = function () { - this.pointer = this.aggregate.minimumKey(); -}; - -/** - * @inheritDoc - */ -BTreeIterator.prototype.next = function () { - this.pointer = this.aggregate.successor(this.pointer); -}; - -/** - * @inheritDoc - */ -BTreeIterator.prototype.last = function () { - this.pointer = this.aggregate.maximumKey(); -}; - -/** - * @inheritDoc - */ -BTreeIterator.prototype.previous = function () { - this.pointer = this.aggregate.predecessor(this.pointer); -}; - -/** - * @inheritDoc - */ -BTreeIterator.prototype.isDone = function () { - return this.pointer === null; -}; - -/** - * @inheritDoc - */ -BTreeIterator.prototype.getItem = function () { - return this.aggregate.search(this.pointer); -}; - -/** - * Return the key stored at the position pointed by the iterator. - * @abstract - * @return {number} The key stored or null if it's out of the bounds. - */ -BTreeIterator.prototype.getKey = function () { - return this.pointer; -}; \ No newline at end of file diff --git a/lib/CircularBuffer/CircularBuffer.js b/lib/CircularBuffer/CircularBuffer.js deleted file mode 100644 index 5719cab..0000000 --- a/lib/CircularBuffer/CircularBuffer.js +++ /dev/null @@ -1,201 +0,0 @@ -/** - * Created by Stefano on 31/03/14. - */ - -CircularBuffer.prototype = new Aggregate(); -CircularBuffer.prototype.constructor = CircularBuffer; - -/** - * Class for managing a circular buffer. - * @param size {Number} The size of the buffer. - * @constructor - */ -function CircularBuffer(size) { - /** - * The index of the position of the head of the buffer. - * @type {number} - */ - this.head = 0; - /** - * The index of the position of the tail of the buffer. - * @type {number} - */ - this.tail = 0; - /** - * The items stored in the buffer. - * @type {Array<*>} - */ - this.items = new Array(size); - /** - * Is true if buffer is empty, false otherwise. - * @type {boolean} - */ - this.empty = true; - /** - * Is false if buffer is full, false otherwise. - * @type {boolean} - */ - this.full = false; - /** - * The size of the buffer. - * @type {Number} - */ - this.size = size; -} - -/** - * @inheritDoc - */ -CircularBuffer.prototype.getIterator = function () { - return new CircularBufferIterator(this); -}; - -/** - * Write the item at the head of the buffer. - * @param item {*} The item to write. - * @return {void} - */ -CircularBuffer.prototype.write = function (item) { - this.empty = false; - if (this.full) - //if buffer is full tail must be set forward - this.tail = (this.tail + 1) % this.size; - this.items[this.head] = item; - //head is set forward - this.head = (this.head + 1) % this.size; - if (this.tail === this.head) - this.full = true; -}; - -/** - * Free the buffer between indexes from and to. - * If from > to, positions between from and the end of the buffer and between the start and to will be free. - * @param from {Number} The index from which start to free (inclusive index) - * @param to {Number} The index where stop to free (exclusive index) - * @return {void} - */ -CircularBuffer.prototype.free = function (from, to) { - if (from < 0) - from = 0; - if (from > this.size - 1) - from = this.size - 1; - if (to < 0) - to = 0; - if (to > this.size - 1) - to = this.size - 1; - //if from < to then will be free allocation between from and to - //otherwise will be free allocations between from and the end and between the start and to - for (var i = from; i < to; i = (i + 1) % this.size) - delete this.items[i]; - - //adjust the position of the tail and of the head - if (this.tail > from - 1 || this.tail < to) - if (this.tail < this.head) { - this.tail = (from - 1) % this.size; - } else { - this.tail = to; - } - if (this.head > from || this.head < to) - if (this.tail < this.head) { - this.head = to; - } else { - this.head = from; - } - //check if something is free - if (from !== to) - this.full = false; - //free could make buffer empty - for (var j = 0; j < this.size; j++) - if (this.items[j] !== undefined) { - this.empty = false; - return; - } - this.empty = true; -}; - -/** - * Free all the buffer. - * @return {void} - */ -CircularBuffer.prototype.freeAll = function () { - for (var i = 0; i < this.size; i++) - delete this.items[i]; - this.empty = true; - this.head = 0; - this.tail = 0; -}; - -/** - * Read the item stored at the position index. - * @param index {Number} The position of the item to read. - * @return {*} The item read. - */ -CircularBuffer.prototype.read = function (index) { - return this.items[index % this.size]; -}; - -/** - * Return true if the buffer is empty, false otherwise. - * @return {boolean} - */ -CircularBuffer.prototype.isEmpty = function () { - return this.empty; -}; - -/** - * Return true if the buffer is full, false otherwise. - * @return {boolean} - */ -CircularBuffer.prototype.isFull = function () { - return this.full; -}; - -/** - * Clones the circular buffer into a new circular buffer. - * @return {CircularBuffer} The circular buffer cloned from this circular buffer. - */ -CircularBuffer.prototype.clone = function () { - var buffer = new CircularBuffer(this.size); - buffer.head = this.head; - buffer.tail = this.tail; - for (var i = 0; i < this.items.length; i++) - buffer.items[i] = this.items[i]; - buffer.empty = this.empty; - buffer.full = this.full; - return buffer; -}; - -/** - * Resize the buffer. - * @param size {number} The new size of the buffer. - * @return {void} - */ -CircularBuffer.prototype.resize = function (size) { - if (this.size < size) { - if (this.head < this.tail + 1) { - for (var i = 0; i < this.head; i++) { - this.items[(i + this.size) % size] = this.items[i]; - delete this.items[i]; - } - this.head = (this.head + this.size) % size; - } - } else if (this.size > size) { - if (this.head < this.tail + 1) { - //check if the tail is after the size - var start = size; - if (this.tail > size - 1) { - start = this.tail; - this.tail = 0; - } - //the items stored must be shift to a valid position - var step = this.size - start; - for (var j = this.head - step - 1; j > start - 1 || j < this.head - step; j--) { - this.items[(j + step) % this.size] = this.items[j]; - if (!j) - j = this.size; - } - this.head = (this.head + step) % this.size; - } - } - this.size = size; -}; \ No newline at end of file diff --git a/lib/CircularBuffer/CircularBufferIterator.js b/lib/CircularBuffer/CircularBufferIterator.js deleted file mode 100644 index b58f656..0000000 --- a/lib/CircularBuffer/CircularBufferIterator.js +++ /dev/null @@ -1,76 +0,0 @@ -/** - * Created by Stefano on 06/04/2014. - */ - -CircularBufferIterator.prototype = new Iterator(); -CircularBufferIterator.prototype.constructor = CircularBufferIterator; - -/** - * Class that implements the iterator for a circular buffer. - * @param aggregate {CircularBuffer} The aggregate to scan. - * @constructor - */ -function CircularBufferIterator(aggregate) { - /** - * The aggregate relates to this iterator. - * @type {CircularBuffer} - */ - this.aggregate = aggregate; - - /** - * The pointer to the position. - * @type {number|null} - */ - this.pointer = null; - /** - * Discriminator for full buffer - * @type {bool} - */ - this.start = true; -} - -/** - * @inheritDoc - */ -CircularBufferIterator.prototype.first = function () { - this.pointer = this.aggregate.tail; - this.start = true; -}; - -/** - * @inheritDoc - */ -CircularBufferIterator.prototype.next = function () { - this.pointer = (this.pointer + 1) % this.aggregate.size; - this.start = false; -}; - -/** - * @inheritDoc - */ -CircularBufferIterator.prototype.last = function () { - this.pointer = (this.aggregate.head - 1) % this.aggregate.size; - this.start = true; -}; - -/** - * @inheritDoc - */ -CircularBufferIterator.prototype.previous = function () { - this.pointer = (this.pointer - 1) % this.aggregate.size; - this.start = false; -}; - -/** - * @inheritDoc - */ -CircularBufferIterator.prototype.isDone = function () { - return (this.pointer === this.aggregate.head && !this.start) || (this.pointer === this.aggregate.tail - 1) % this.aggregate.size || this.aggregate.isEmpty(); -}; - -/** - * @inheritDoc - */ -CircularBufferIterator.prototype.getItem = function () { - return this.aggregate.read(this.pointer); -}; \ No newline at end of file diff --git a/lib/DoubleLinkedList/DoubleLinkedList.js b/lib/DoubleLinkedList/DoubleLinkedList.js deleted file mode 100644 index 9e6e2f7..0000000 --- a/lib/DoubleLinkedList/DoubleLinkedList.js +++ /dev/null @@ -1,798 +0,0 @@ -/** - * Created by Stefano on 31/03/14. - */ - -/** - * The single node of the list. - * @param item {*} The item to store in the node. - * @constructor - */ -function DLLNode(item) { - /** - * The item stored. - * @type {*} - */ - this.item = item; - /** - * The next node. It's null if there's no a next node. - * @type {DLLNode|null} - */ - this.next = null; - /** - * The previous node. It's null if there's no a previous node. - * @type {DLLNode|null} - */ - this.previous = null; -} - -DoubleLinkedList.prototype = new Aggregate(); -DoubleLinkedList.prototype.constructor = DoubleLinkedList; - -/** - * Class for managing a double linked list. - * @param {...*} [args] The items for initializing the list. - * @constructor - */ -function DoubleLinkedList(args) { - /** - * The first node of the list. - * @type {DLLNode|null} - */ - this.first = null; - /** - * The last node of the list. - * @type {DLLNode|null} - */ - this.last = null; - /** - * The length of the list. - * @type {number} - */ - this.length = 0; - - if(args && args.length) { - //builds the list from the range passed from the constructor - this.fromArray(args); - } else { - //builds the list from the parameters of the constructor - this.fromArray(arguments); - } -} - -/** - * @inheritDoc - */ -DoubleLinkedList.prototype.getIterator = function () { - return new DoubleLinkedListIterator(this); -}; - -/** - * Add an item at the head of the list. - * @param item {*} The item to add. - * @return {void} - */ -DoubleLinkedList.prototype.pushFront = function (item) { - var node = new DLLNode(item); - node.next = this.first; - this.first = node; - //link the next node to the new node - if (node.next) - node.next.previous = node; - else - this.last = node; - this.length++; -}; - -/** - * Add an item at the tail of the list. - * @param item {*} The item to add. - * @return {void} - */ -DoubleLinkedList.prototype.pushBack = function (item) { - var node = new DLLNode(item); - node.previous = this.last; - this.last = node; - //link the previous node to the new node - if (node.previous) - node.previous.next = node; - else - this.first = node; - this.length++; -}; - -/** - * Remove the first item of the list. - * @return {*} The item removed. It's undefined if the list is empty. - */ -DoubleLinkedList.prototype.popFront = function () { - if (this.length) { - var node = this.first; - this.first = node.next; - if (node.next) - node.next.previous = null; - this.length--; - node.next = null; - return node.item; - } - return undefined; -}; - -/** - * Remove the last item of the list. - * @return {*} The item removed. It's undefined if the list is empty. - */ -DoubleLinkedList.prototype.popBack = function () { - if (this.length) { - var node = this.last; - this.last = node.previous; - if (node.previous) - node.previous.next = null; - this.length--; - node.previous = null; - return node.item; - } - return undefined; -}; - -/** - * Removes the first times items of the list. - * @param times {number} The number of times to repeat the popFront method. - * @return {*} The item removed. It's undefined if the list is empty. - */ -DoubleLinkedList.prototype.multiPopFront = function (times) { - var result = []; - for (var i = 0; i < times && this.length; i++) - result.push(this.popFront()); - return result; -}; - -/** - * Removes the last times items of the list. - * @param times {number} The number of times to repeat the popBack method. - * @return {*} The items removed. - */ -DoubleLinkedList.prototype.multiPopBack = function (times) { - var result = []; - for (var i = 0; i < times && this.length; i++) - result.push(this.popBack()); - return result; -}; - -/** - * Returns the first item of the list without remove it. - * @return {*} The item at the top of the list. It's undefined if the list is empty. - */ -DoubleLinkedList.prototype.peek = function () { - if (!this.length) - return undefined; - return this.first.item; -}; - -/** - * Add the item at the index position. - * @param item {*} The item to add. - * @param index {number} The position where to add the item. If index is negative, the item won't be added. - * @return {void} - */ -DoubleLinkedList.prototype.addAt = function (item, index) { - if (index < 0) - return; - if (!index) { - this.pushFront(item); - return; - } - if (index === this.length) { - this.pushBack(item); - return; - } - var node = this.first; - if (!node && index > 0) - this.pushBack(undefined); - for (var i = 0; i < index - 1; i++, node = node.next) { - if (node === this.last) - this.pushBack(undefined); - } - if (node === this.last) - this.pushBack(item); - else if (node === this.first) - this.pushFront(item); - else { - var newNode = new DLLNode(item); - newNode.next = node.next; - newNode.previous = node; - node.next = newNode; - if (newNode.next) - newNode.next.previous = newNode; - this.length++; - } -}; - -/** - * Remove the item at the position index. - * @param index {Number} The position of the item to remove. - * @return {*} The item stored at the position index. It's undefined if the index is out of bounds. - */ -DoubleLinkedList.prototype.removeAt = function (index) { - if (index < 0 || index > this.length - 1) - return undefined; - if (index === 0) - return this.popFront(); - if (index === this.length - 1) - return this.popBack(); - var node = this.first; - for (; index > 0; index--) - node = node.next; - //now node is the node to remove - node.previous.next = node.next; - node.next.previous = node.previous; - node.next = null; - node.previous = null; - this.length--; - return node.item; -}; - -/** - * Removes the item from the list. - * @param item {*} The item to remove. - * @param [callback = function(item){return(it===item);}] The condition to satisfy. The callback must accept the current item to check. - * @return {void} - */ -DoubleLinkedList.prototype.remove = function (item, callback) { - callback = callback || function (it) { - return it === item; - }; - var node = this.first; - var previous = null; - while (node) { - if (callback(node.item)) { - if (node === this.first) - this.first = node.next; - if (node === this.last) - this.last = previous; - if (previous) { - previous.next = node.next; - if (node.next) - node.next.previous = previous; - } - return; - } - previous = node; - node = node.next; - } -}; - -/** - * Removes all the item from the list. - * @param item {*} The item to remove. - * @param [callback = function(item){return(it===item);}] The condition to satisfy. The callback must accept the current item to check. - * @return {void} - */ -DoubleLinkedList.prototype.removeAll = function (item, callback) { - callback = callback || function (it) { - return it === item; - }; - var node = this.first; - var previous = null; - while (node) { - if (callback(node.item)) { - if (node === this.first) - this.first = node.next; - if (node === this.last) - this.last = previous; - if (previous) { - previous.next = node.next; - if (node.next) - node.next.previous = previous; - } - } else - previous = node; - node = node.next; - } -}; - -/** - * Removes all the items stored from the from position to the to position. - * If from > to, the method will remove all the items up to the end. - * @param from {number} The position where start to remove the items. The from position is included. - * @param to {number} The position where stop to remove the items. The to position is included. - * @return {Array<*>} The items removed. - */ -DoubleLinkedList.prototype.removeSegment = function (from, to) { - var result = []; - if (to > -1 && from < this.length) { - if (from === 0) - return this.multiPopFront(to + 1); - if (to === this.length - 1 || from > to) - return this.multiPopBack(Math.max(to - from, this.length - from)).reverse(); - var node = this.first; - for (var i = 0; i < from - 1; i++) - node = node.next; - //now node is the node before the node to remove - //node to remove - var next = node.next; - for (var j = from; j < to + 1 && j < this.length; j++) { - result.push(next.item); - next = next.next; - } - this.length -= Math.min(to - from + 1, this.length - from); - node.next = next; - next.previous = node; - } - return result; -}; - -/** - * Change the item stored in the index position. If the index is out of bound, the node won't be updated. - * @param index {number} The position of the node to modify. - * @param item {*} The new item stored in the node. - * @return {void} - */ -DoubleLinkedList.prototype.modifyAt = function (index, item) { - var node = this.getNode(index); - if (node) - node.item = item; -}; - -/** - * Removes all the items stored in the list. - * @return {void} - */ -DoubleLinkedList.prototype.clear = function () { - this.first = null; - this.last = null; - this.length = 0; -}; - -/** - * Checks if the list contains an item that satisfy the condition represented by the callback function. - * @param item {*} The item to find. - * @param [callback = function(item){return(it===item);}] The condition to satisfy. The callback must accept the current item to check. - * @return {boolean} True if the list contains the item that satisfy the condition, false otherwise. - */ -DoubleLinkedList.prototype.contains = function (item, callback) { - callback = callback || function (it) { - return it === item; - }; - var i = 0; - var node = this.first; - while (i < this.length && !callback(node.item)) { - i++; - node = node.next; - } - return i < this.length; -}; - -/** - * Executes the callback function for each item of the stack. - * This method modifies the list so if you don't need to modify it you must return the same item of the array. - * @param callback {function} The function to execute for each item. The function must accept the current item on which execute the function. - * @return {void} - */ -DoubleLinkedList.prototype.execute = function (callback) { - var node = this.first; - while (node) { - node.item = callback(node.item); - node = node.next; - } -}; - -/** - * Delete the node from the list. - * @param node {DLLNode} The node to delete. - * @return {void} - */ -DoubleLinkedList.prototype.deleteNode = function (node) { - if (node === this.first) { - this.popFront(); - return; - } - if (node === this.last) { - this.popBack(); - return; - } - node.previous.next = node.next; - node.next.previous = node.previous; - this.length--; -}; - -/** - * Get the node at the position index relative from the node. - * @param index {Number} The index, relative to the node, of the node to return. - * @param [node = first] {DLLNode} The node from which start the search. - * @return {DLLNode} The node at the position index. - */ -DoubleLinkedList.prototype.getNode = function (index, node) { - if (index < 0 || index > this.length - 1) - return undefined; - var m = Math.floor(this.length / 2); - //if the index is less than the middle, the search start from the head of the list, otherwise from the tail of the list - if (index < m || node) { - node = node || this.first; - for (; index > 0; index--) - node = node.next; - } else - for (index = this.length - index - 1, node = this.last; index > 0; index--) - node = node.previous; - return node; -}; - -/** - * Get the item at the position index. - * @param index {Number} The position of the item. - * @return {*}. It's undefined if index isn't in the queue bounds. - */ -DoubleLinkedList.prototype.getItem = function (index) { - if (index < 0 || index > this.length - 1) - return undefined; - var node; - var m = Math.floor(this.length / 2); - if (index < m) //if the index is less than the middle, the search start from the head of the list, otherwise from the tail of the list - for (node = this.first; index > 0; index--) - node = node.next; - else - for (index = this.length - index - 1, node = this.last; index > 0; index--) - node = node.previous; - return node.item; -}; - -/** - * Sort the list using web workers. - * Using this method is discouraged. Many web browser set a limit to the maximum number of workers instantiated. - * The items of the list, due to web workers implementation, will be serialized so they will lost own methods. - * @return {void} - */ -DoubleLinkedList.prototype.parallelSort = function () { - - var workers = []; - var _array = this.toArray(); - console.log(_array); - - function partialSort(_from, _to, _id) { - if (_from < _to) { - var m = Math.floor((_from + _to) / 2); - var workerLeft = new Worker("DoubleLinkedList/WorkerSort.js"); - var workerRight = new Worker("DoubleLinkedList/WorkerSort.js"); - workers.push(workerLeft); - workers.push(workerRight); - var length = workers.length; - workerLeft.postMessage({cmd: 'start', from: _from, to: m, worker: _id}); - workerRight.postMessage({cmd: 'start', from: m + 1, to: _to, worker: _id}); - partialSort(_from, m, length - 2); - partialSort(m + 1, _to, length - 1); - workerLeft.onmessage = function (event) { - var data = event.data; - switch (data.cmd) { - case 'finished': - workers[data.worker].postMessage({cmd: 'finished', array: _array}); - break; - case 'replace': - _array[data.index] = data.value; - break; - } - }; - workerRight.onmessage = function (event) { - var data = event.data; - switch (data.cmd) { - case 'finished': - workers[data.worker].postMessage({cmd: 'finished', array: _array}); - break; - case 'replace': - _array[data.index] = data.value; - break; - } - } - } - } - - var outerThis = this; - - var mainWorker = new Worker("DoubleLinkedList/WorkerSort.js"); - workers.push(mainWorker); - mainWorker.postMessage({cmd: 'start', from: 0, to: this.length - 1, worker: -1, array: _array}); - mainWorker.onmessage = function (event) { - var data = event.data; - switch (data.cmd) { - case 'finished': - outerThis.fromArray(_array); - console.log(outerThis); - break; - case 'replace': - _array[data.index] = data.value; - } - }; - partialSort(0, this.length - 1, 0); -}; - -/** - * Sort the list. - * @param [callback = function(item){return(item);}] {function} The function invoked in order to get the value for the evaluation of the sort criteria. - * @example - * callback = function(item) {return -item.key;} - * This function callback will return the opposite of the attribute key of the item. In this case the list will be sorted in descending order. - * @return {void} - */ -DoubleLinkedList.prototype.sort = function (callback) { - - if (!callback) - callback = function (item) { - return item; - }; - - var outerThis = this; - - function partialSort(from, to, fromNode, toNode) { - if (from < to) { - var m = Math.floor((from + to) / 2); - var mNode = outerThis.getNode(m - from, fromNode); - partialSort(from, m, fromNode, mNode); - partialSort(m + 1, to, mNode.next, toNode); - merge(from, m, to, fromNode); - } - } - - function merge(from, m, to, fromNode) { - var left = []; - var right = []; - var node = fromNode; - for (var i = 0; i < m - from + 1; i++, node = node.next) - left[i] = node.item; - for (var j = 0; j < to - m; j++, node = node.next) - right[j] = node.item; - var x = 0, y = 0; - for (var k = from; k < to + 1; k++, fromNode = fromNode.next) { - if (y > to - m - 1 || (callback(left[x]) <= callback(right[y]) && x < m - from + 1)) { - fromNode.item = left[x]; - x++; - } else { - fromNode.item = right[y]; - y++; - } - } - } - - partialSort(0, this.length - 1, this.first, this.last); -}; - -/** - * Transform the list into an array. - * @return {Array<*>} The array built. - */ -DoubleLinkedList.prototype.toArray = function () { - var array = []; - for (var node = this.first, i = 0; node; node = node.next, i++) - array[i] = node.item; - return array; -}; - -/** - * Returns the length of the list. - * @return {Number} The length of the list. - */ -DoubleLinkedList.prototype.getLength = function () { - return this.length; -}; - -/** - * Build the list from the array. - * @param array {Array<*>} The array from which build the list. - * @return {void} - */ -DoubleLinkedList.prototype.fromArray = function (array) { - var node = this.first; - for (var i = 0; i < Math.min(this.length, array.length); i++, node = node.next) - node.item = array[i]; - if (this.length < array.length) - for (var j = this.length; j < array.length; j++) - this.pushBack(array[j]); - else - for (var k = array.length; k < this.length;) - this.popBack(); -}; - -/** - * Return the items that satisfy the condition determined by the callback. - * @param callback {function} The function that implements the condition. - * @return {Array} The array that contains the items that satisfy the condition. - */ -DoubleLinkedList.prototype.filter = function (callback) { - var result = []; - for (var node = this.first; node; node = node.next) { - if (callback(node.item)) - result.push(node.item); - } - return result; -}; - -/** - * Reverse the list. This method reverses only the items, not the nodes. - * @return {void} - */ -DoubleLinkedList.prototype.reverse = function () { - for (var start = this.first, end = this.last; start !== end && start.previous !== end; start = start.next, end = end.previous) { - var item = start.item; - start.item = end.item; - end.item = item; - } -}; - -/** - * Checks if the list is empty. - * @return {boolean} True if the list is empty, false otherwise. - */ -DoubleLinkedList.prototype.isEmpty = function () { - return !this.length; -}; - -/** - * Returns the first position of the item in the list. - * @param item {*} The item to search. - * @param [callback = function(item){return(it===item);}] The condition to satisfy. The callback must accept the current item to check. - * @return {number} The first position of the item. - */ -DoubleLinkedList.prototype.indexOf = function (item, callback) { - callback = callback || function (it) { - return it === item; - }; - var i = 0; - var node = this.first; - while (node) { - if (callback(node.item)) - return i; - i++; - node = node.next; - } - return -1; -}; - -/** - * Returns the last position of the item in the list. - * @param item {*} The item to search. - * @param [callback = function(item){return(it===item);}] The condition to satisfy. The callback must accept the current item to check. - * @return {number} The last position of the item. - */ -DoubleLinkedList.prototype.lastIndexOf = function (item, callback) { - callback = callback || function (it) { - return it === item; - }; - var i = this.length - 1; - var node = this.last; - while (node) { - if (callback(node.item)) - return i; - i--; - node = node.previous; - } - return -1; -}; - -/** - * Returns all the position in which the item has been found in the list. - * @param item {*} The item to search. - * @param [callback = function(item){return(it===item);}] The condition to satisfy. The callback must accept the current item to check. - * @return {Array} The positions in which the item has been found. - */ -DoubleLinkedList.prototype.allIndexesOf = function (item, callback) { - callback = callback || function (it) { - return it === item; - }; - var i = 0; - var node = this.first; - var indexes = []; - while (node) { - if (callback(node.item)) - indexes.push(i); - i++; - node = node.next; - } - return indexes; -}; - -/** - * Add the list at the end of this list. - * @param list {DoubleLinkedList} The list to join. - * @return {void} - */ -DoubleLinkedList.prototype.join = function (list) { - if (this.last) - this.last.next = list.first; - else - this.first = list.first; - if (list.first) - list.first.previous = this.last; - this.last = list.last; - this.length += list.length; -}; - -/** - * Divides the list at the index position. The node at the index position is the first new node of the list. - * @param index {number} The position where to divide the list. - * @return {DoubleLinkedList} The list formed by the nodes from the index position then. If the index is out of bound, the list will be empty. - */ -DoubleLinkedList.prototype.divide = function (index) { - var list = new DoubleLinkedList(); - if (index > -1 && index < this.length) { - var node = this.first; - var previous = null; - for (var i = 0; i < index; i++) { - previous = node; - node = node.next; - } - if (node === this.first) { - list.first = this.first; - list.last = this.last; - this.first = null; - this.last = null; - } else { - list.first = node; - list.last = this.last; - this.last = previous; - previous.next = null; - node.previous = null; - } - list.length = this.length - index; - this.length = index; - } - return list; -}; - -/** - * Clones the list into a new list. - * @return {DoubleLinkedList} The list cloned from this list. - */ -DoubleLinkedList.prototype.clone = function () { - var list = new DoubleLinkedList(); - var node = this.first; - for (var i = 0; i < this.length; i++, node = node.next) - if (node.item.clone) - list.pushBack(node.item.clone()); - else - list.pushBack(node.item); - return list; -}; - -/** - * Clones the list into a new list without cloning duplicated items. - * @return {DoubleLinkedList} The list cloned from this list. - */ -DoubleLinkedList.prototype.cloneDistinct = function () { - var list = new DoubleLinkedList(); - var node = this.first; - for (var i = 0; i < this.length; i++, node = node.next) - if (!list.contains(node.item)) - if (node.item.cloneDistinct) - list.pushBack(node.item.cloneDistinct()); - else if (node.item.clone) - list.pushBack(node.item.clone()); - else - list.pushBack(node.item); - return list; -}; - -/** - * Splits the list into lists of desired size. - * @param size {number} The size of the lists. - * @return {Array} The lists created by splitting the list. - */ -DoubleLinkedList.prototype.split = function (size) { - var length = this.length; - var lists = [this]; - for (var i = size; i < length; i += size) - lists.push(lists[lists.length - 1].divide(size)); - return lists; -}; - -/** - * Returns the number of items that satisfy the represented by the callback function. - * @param callback {function} The condition to satisfy. - * @return {number} The number of items that satisfy the condition. - */ -DoubleLinkedList.prototype.count = function (callback) { - var count = 0; - var node = this.first; - while (node) { - if (callback(node.item)) - count++; - node = node.next; - } - return count; -}; diff --git a/lib/DoubleLinkedList/DoubleLinkedListIterator.js b/lib/DoubleLinkedList/DoubleLinkedListIterator.js deleted file mode 100644 index 38de29b..0000000 --- a/lib/DoubleLinkedList/DoubleLinkedListIterator.js +++ /dev/null @@ -1,76 +0,0 @@ -/** - * Created by Stefano on 04/04/2014. - */ - -DoubleLinkedListIterator.prototype = new Iterator(); -DoubleLinkedListIterator.prototype.constructor = DoubleLinkedListIterator; - -/** - * Class that implements the iterator for a double linked list. - * @param aggregate {DoubleLinkedList} The aggregate to scan. - * @constructor - */ -function DoubleLinkedListIterator(aggregate) { - /** - * The aggregate relates to this iterator. - * @type {DoubleLinkedList} - */ - this.aggregate = aggregate; - - /** - * The pointer to the position. - * @type {Node|null} - */ - this.pointer = null; -} - -/** - * @inheritDoc - */ -DoubleLinkedListIterator.prototype.first = function () { - this.pointer = this.aggregate.first; -}; - -/** - * @inheritDoc - */ -DoubleLinkedListIterator.prototype.next = function () { - this.pointer = this.pointer.next; -}; - -/** - * @inheritDoc - */ -DoubleLinkedListIterator.prototype.last = function () { - this.pointer = this.aggregate.last; -}; - -/** - * @inheritDoc - */ -DoubleLinkedListIterator.prototype.previous = function () { - this.pointer = this.pointer.previous; -}; - -/** - * @inheritDoc - */ -DoubleLinkedListIterator.prototype.isDone = function () { - return !this.pointer; -}; - -/** - * @inheritDoc - */ -DoubleLinkedListIterator.prototype.getItem = function () { - return this.pointer.item; -}; - -/** - * Return the node stored at the position pointed by the iterator. - * @abstract - * @return {Node|null} The node stored or null if it's out of the bounds. - */ -DoubleLinkedListIterator.prototype.getNode = function () { - return this.pointer; -}; \ No newline at end of file diff --git a/lib/DoubleLinkedList/WorkerSort.js b/lib/DoubleLinkedList/WorkerSort.js deleted file mode 100644 index 871b250..0000000 --- a/lib/DoubleLinkedList/WorkerSort.js +++ /dev/null @@ -1,50 +0,0 @@ -/** - * Created by Stefano on 01/04/14. - */ -onmessage = function (event) { - var data = event.data; - switch (data.cmd) { - case 'start': - this.finished = 0; - this.from = data.from; - this.to = data.to; - this.worker = data.worker; - if (this.from === this.to) { - this.postMessage({cmd: 'finished', worker: this.worker}); - close(); - } - break; - case 'finished': - this.finished++; - if (this.finished > 1) { - this.array = data.array; - merge(this.from, this.to, this.array); - this.postMessage({cmd: 'finished', worker: this.worker}); - close(); - } - break; - default : - this.postMessage('Something went wrong'); - } -}; - -//noinspection FunctionWithMultipleLoopsJS -function merge(from, to, array) { - var m = Math.floor((from + to) / 2); - var left = []; - var right = []; - for (var i = 0; i < m - from + 1; i++) - left[i] = array[from + i]; - for (var j = 0; j < to - m; j++) - right[j] = array[m + j + 1]; - var x = 0, y = 0; - for (var k = from; k < to + 1; k++) { - if (y > to - m - 1 || (left[x] <= right[y] && x < m - from + 1)) { - this.postMessage({cmd: 'replace', index: k, value: left[x]}); - x++; - } else { - this.postMessage({cmd: 'replace', index: k, value: right[y]}); - y++; - } - } -} \ No newline at end of file diff --git a/lib/HashTable/HashTable.js b/lib/HashTable/HashTable.js deleted file mode 100644 index 1e15fe3..0000000 --- a/lib/HashTable/HashTable.js +++ /dev/null @@ -1,233 +0,0 @@ -/** - * Created by Stefano on 05/04/2014. - */ - -/** - * Class for managing an hash table. - * @param size {number} The size of the table. - * @constructor - */ -function HashTable(size) { - /** - * The size of the table - * @type {number} - */ - this.size = size; - - this.p = 1000; - - this.a = Math.floor(Math.random() * this.p); - - this.b = Math.floor(Math.random() * this.p); - - /** - * Calculate the hash of the param key. - * @param key {number} The key to hash. - * @return {number} The hash of the key. - */ - this.hash = function (key) { - return ((this.a * key + this.b) % this.p) % this.size; - }; - - /** - * The items stored in the hash table. - * @type {Array} - */ - this.items = []; - - /** - * The number of keys stored in the hash table. - * @type {number} - */ - this.keyLength = 0; - - this.clear(); -} - -/** - * Stores the item with its key. - * @param key {number} The key relatives to the item. - * @param item {*} The item to store. - */ -HashTable.prototype.insert = function (key, item) { - this.keyLength++; - this.items[this.hash(key)].pushBack({key: key, item: item}); -}; - -/** - * Deletes the first item relatives to the key value. - * @param key {number} The key to delete. - * @return {void} - */ -HashTable.prototype.deleteKey = function (key) { - var list = this.items[this.hash(key)]; - var it = list.getIterator(); - for (it.first(); !it.isDone() && it.getItem().key !== key;) - it.next(); - if (!it.isDone()) { - list.deleteNode(it.getNode()); - this.keyLength--; - } -}; - -/** - * Deletes all the items relative to the key value. - * @param key {number} The key to delete. - * @return {void} - */ -HashTable.prototype.deleteAllKey = function (key) { - var list = this.items[this.hash(key)]; - var it = list.getIterator(); - var keysRemoved = 0; - for (it.first(); !it.isDone(); it.next()) - if (it.getItem().key === key) { - list.deleteNode(it.getNode()); - keysRemoved++; - } - this.keyLength -= keysRemoved; -}; - -/** - * Searches the item relative to the key value. - * @param key {number} The key of the item to search. - * @return {*|undefined} The item found or undefined if the key does not exist. - */ -HashTable.prototype.search = function (key) { - var list = this.items[this.hash(key)]; - var it = list.getIterator(); - for (it.first(); !it.isDone(); it.next()) - if (it.getItem().key === key) - return it.getItem().item; - return undefined; -}; - -/** - * Checks if the hash table contains a key that satisfy the condition represented by the callback function. - * @param key {number} The key to find. - * @param [callback = function(k){return(k===key);}] The condition to satisfy. The callback must accept the current key to check. - * @return {boolean} True if the hash table contains the key that satisfy the condition, false otherwise. - */ -HashTable.prototype.containsKey = function (key, callback) { - callback = callback || function (k) { - return k === key; - }; - var list = this.items[this.hash(key)]; - var it = list.getIterator(); - for (it.first(); !it.isDone(); it.next()) - if (callback(it.getItem().key)) - return true; - return false; -}; - -/** - * Searches all the items relative to the key value. - * @param key {number} The key of the items to search. - * @return {Array.<*>} An array with the items found. - */ -HashTable.prototype.searchAll = function (key) { - var list = this.items[this.hash(key)]; - var it = list.getIterator(); - var array = []; - for (it.first(); !it.isDone(); it.next()) - if (it.getItem().key === key) - array.push(it.getItem().item); - return array; -}; - -/** - * Returns the keys stored in the hash table. - * @return {Array} The keys stored in the table. - */ -HashTable.prototype.getKeys = function () { - var keys = []; - for (var i = 0; i < this.size; i++) { - var it = this.items[i].getIterator(); - for (it.first(); !it.isDone(); it.next()) - keys.push(it.getItem().key); - } - return keys; -}; - -/** - * Returns the items stored in the hash table. - * @return {Array<*>} The items stored in the table. - */ -HashTable.prototype.getItems = function () { - var items = []; - for (var i = 0; i < this.size; i++) { - var it = this.items[i].getIterator(); - for (it.first(); !it.isDone(); it.next()) - items.push(it.getItem().item); - } - return items; -}; - -/** - * Removes all the keys and the items stored in the hash table. - * @return {void} - */ -HashTable.prototype.clear = function () { - this.items = []; - for (var i = 0; i < this.size; i++) - this.items[i] = new DoubleLinkedList(); - this.keyLength = 0; -}; - -/** - * Returns the number of keys stored in the hash table. - * @return {number} The number of keys stored. - */ -HashTable.prototype.getNumberOfKeys = function () { - return this.keyLength; -}; - -/** - * Checks if the hash table is empty. - * @return {boolean} True if the hash table is empty, false otherwise. - */ -HashTable.prototype.isEmpty = function () { - return !this.keyLength; -}; - -/** - * Executes the callback function for each item of the hash table. - * This method modifies the hash table so if you don't need to modify it you must return the same item stored. - * @param callback {function} The function to execute for each item. The function must accept the current item on which execute the function. - * @return {void} - */ -HashTable.prototype.execute = function (callback) { - for (var i = 0; i < this.size; i++) - this.items[i].execute(callback); -}; - -/** - * Returns the items that satisfy the condition determined by the callback. - * @param callback {function} The function that implements the condition. - * @return {Array<*>} The array that contains the items that satisfy the condition. - */ -HashTable.prototype.filter = function (callback) { - var result = []; - for (var i = 0; i < this.size; i++) - result.concat(this.items[i].filter(callback)); - return result; -}; - -/** - * Returns the size of the hash table. - * @return {number} The size of the hash table. - */ -HashTable.prototype.getSize = function () { - return this.size; -}; - -/** - * Clones the hash table into a new hash table. - * @return {HashTable} The hash table cloned from this hash table. - */ -HashTable.prototype.clone = function () { - var table = new HashTable(this.size); - for (var i = 0; i < this.size; i++) - for (var node = this.items[i].first; node; node = node.next) - table.insert(node.key, node.item); - return table; -}; \ No newline at end of file diff --git a/lib/LinkedList/LinkedList.js b/lib/LinkedList/LinkedList.js deleted file mode 100644 index ab41043..0000000 --- a/lib/LinkedList/LinkedList.js +++ /dev/null @@ -1,617 +0,0 @@ -/** - * Created by Stefano on 31/03/14. - */ - -/** - * The single node of the list. - * @param item {*} The item to store in the node. - * @constructor - */ -function LLNode(item) { - /** - * The item stored. - * @type {*} - */ - this.item = item; - /** - * The next node. It's null if there's no a next node. - * @type {LLNode|null} - */ - this.next = null; -} - -LinkedList.prototype = new Aggregate(); -LinkedList.prototype.constructor = LinkedList; - -/** - * Class for managing a linked list. - * @param {...*} [args] The items for initializing the list. - * @constructor - */ -function LinkedList(args) { - /** - * The first node of the list. - * @type {LLNode|null} - */ - this.first = null; - /** - * The last node of the list. - * @type {LLNode|null} - */ - this.last = null; - /** - * The length of the list. - * @type {number} - */ - this.length = 0; - - if(args && args.length) { - //builds the list from the range passed from the constructor - this.fromArray(args); - } else { - //builds the list from the parameters of the constructor - this.fromArray(arguments); - } -} - -/** - * @inheritDoc - */ -LinkedList.prototype.getIterator = function () { - return new LinkedListIterator(this); -}; - -/** - * Adds an item at the head of the list. - * @param item {*} The item to add. - * @return {void} - */ -LinkedList.prototype.pushFront = function (item) { - var node = new LLNode(item); - node.next = this.first; - this.first = node; - if (!this.last) - this.last = node; - this.length++; -}; - -/** - * Adds an item at the tail of the list. - * @param item {*} The item to add. - * @return {void} - */ -LinkedList.prototype.pushBack = function (item) { - var node = new LLNode(item); - if (this.last) - this.last.next = node; - else - this.first = node; - this.last = node; - this.length++; -}; - -/** - * Removes the first item of the list. - * @return {*} The item removed. It's undefined if the list is empty. - */ -LinkedList.prototype.popFront = function () { - if (this.length) { - var node = this.first; - this.first = this.first.next; - this.length--; - node.next = null; - return node.item; - } - return undefined; -}; - -/** - * Removes the last item of the list. - * @return {*} The item removed. It's undefined if the list is empty. - */ -LinkedList.prototype.popBack = function () { - if (this.length) { - var node = this.last; - var next = this.first; - while (next.next && next.next.next) { - next = next.next; - } - if (node === next) - this.last = null; - else - this.last = next; - next.next = null; - this.length--; - return node.item; - } - return undefined; -}; - -/** - * Removes the first times items of the list. - * @param times {number} The number of times to repeat the popFront method. - * @return {*} The item removed. It's undefined if the list is empty. - */ -LinkedList.prototype.multiPopFront = function (times) { - var result = []; - for (var i = 0; i < times && this.length; i++) - result.push(this.popFront()); - return result; -}; - -/** - * Removes the last times items of the list. - * @param times {number} The number of times to repeat the popBack method. - * @return {*} The items removed. - */ -LinkedList.prototype.multiPopBack = function (times) { - var result = []; - for (var i = 0; i < times && this.length; i++) - result.push(this.popBack()); - return result; -}; - -/** - * Returns the first item of the list without remove it. - * @return {*} The item at the top of the list. It's undefined if the list is empty. - */ -LinkedList.prototype.peek = function () { - if (!this.length) - return undefined; - return this.first.item; -}; - -/** - * Add the item at the index position. - * @param item {*} The item to add. - * @param index {number} The position where to add the item. If index is negative, the item won't be added. - * @return {void} - */ -LinkedList.prototype.addAt = function (item, index) { - if (index < 0) - return; - if (!index) { - this.pushFront(item); - return; - } - if (index === this.length) { - this.pushBack(item); - return; - } - var node = this.first; - if (!node && index > 0) - this.pushBack(undefined); - for (var i = 0; i < index - 1; i++, node = node.next) { - if (node === this.last) - this.pushBack(undefined); - } - if (node === this.last) - this.pushBack(item); - else if (node === this.first) - this.pushFront(item); - else { - var newNode = new LLNode(item); - newNode.next = node.next; - node.next = newNode; - this.length++; - } -}; - -/** - * Removes the item at the index position. - * @param index {number} The position of the item to remove. - * @return {*} The item stored at the position index. It's undefined if the index is out of bounds. - */ -LinkedList.prototype.removeAt = function (index) { - if (index < 0 || index > this.length - 1) - return undefined; - if (index === 0) - return this.popFront(); - if (index === this.length - 1) - return this.popBack(); - var node = this.first; - for (; index > 1; index--) - node = node.next; - //now node is the node before the node to remove - //node to remove - var next = node.next; - node.next = next.next; - this.length--; - return next.item; -}; - -/** - * Removes the item from the list. - * @param item {*} The item to remove. - * @param [callback = function(item){return(it===item);}] The condition to satisfy. The callback must accept the current item to check. - * @return {void} - */ -LinkedList.prototype.remove = function (item, callback) { - callback = callback || function (it) { - return it === item; - }; - var node = this.first; - var previous = null; - while (node) { - if (callback(node.item)) { - if (node === this.first) - this.first = node.next; - if (node === this.last) - this.last = previous; - if (previous) - previous.next = node.next; - return; - } - previous = node; - node = node.next; - } -}; - -/** - * Removes all the item from the list. - * @param item {*} The item to remove. - * @param [callback = function(item){return(it===item);}] The condition to satisfy. The callback must accept the current item to check. - * @return {void} - */ -LinkedList.prototype.removeAll = function (item, callback) { - callback = callback || function (it) { - return it === item; - }; - var node = this.first; - var previous = null; - while (node) { - if (callback(node.item)) { - if (node === this.first) - this.first = node.next; - if (node === this.last) - this.last = previous; - if (previous) - previous.next = node.next; - } else - previous = node; - node = node.next; - } -}; - -/** - * Removes all the items stored from the from position to the to position. - * If from > to, the method will remove all the items up to the end. - * @param from {number} The position where start to remove the items. The from position is included. - * @param to {number} The position where stop to remove the items. The to position is included. - * @return {Array<*>} The items removed. - */ -LinkedList.prototype.removeSegment = function (from, to) { - var result = []; - if (to > -1 && from < this.length) { - if (from === 0) - return this.multiPopFront(to + 1); - if (to === this.length - 1 || from > to) - return this.multiPopBack(Math.max(to - from, this.length - from)).reverse(); - var node = this.first; - for (var i = 0; i < from - 1; i++) - node = node.next; - //now node is the node before the node to remove - //node to remove - var next = node.next; - for (var j = from; j < to + 1 && j < this.length; j++) { - result.push(next.item); - next = next.next; - } - this.length -= Math.min(to - from + 1, this.length - from); - node.next = next; - } - return result; -}; - -/** - * Change the item stored in the index position. If the index is out of bound, the node won't be updated. - * @param index {number} The position of the node to modify. - * @param item {*} The new item stored in the node. - * @return {void} - */ -LinkedList.prototype.modifyAt = function (index, item) { - var node = this.getNode(index); - if (node) - node.item = item; -}; - -/** - * Removes all the items stored in the list. - * @return {void} - */ -LinkedList.prototype.clear = function () { - this.first = null; - this.last = null; - this.length = 0; -}; - -/** - * Checks if the list contains an item that satisfy the condition represented by the callback function. - * @param item {*} The item to find. - * @param [callback = function(item){return(it===item);}] The condition to satisfy. The callback must accept the current item to check. - * @return {boolean} True if the list contains the item that satisfy the condition, false otherwise. - */ -LinkedList.prototype.contains = function (item, callback) { - callback = callback || function (it) { - return it === item; - }; - var i = 0; - var node = this.first; - while (i < this.length && !callback(node.item)) { - i++; - node = node.next; - } - return i < this.length; -}; - -/** - * Executes the callback function for each item of the stack. - * This method modifies the list so if you don't need to modify it you must return the same item of the array. - * @param callback {function} The function to execute for each item. The function must accept the current item on which execute the function. - * @return {void} - */ -LinkedList.prototype.execute = function (callback) { - var node = this.first; - while (node) { - node.item = callback(node.item); - node = node.next; - } -}; - -/** - * Returns the node at the position index. - * @param index {number} The position of the node. - * @return {LLNode} The node stored at the position index. It's undefined if index isn't in the list bounds. - */ -LinkedList.prototype.getNode = function (index) { - if (index < 0 || index > this.length - 1) - return undefined; - var node = this.first; - for (; index > 0; index--) - node = node.next; - return node; -}; - -/** - * Returns the item at the position index. - * @param index {number} The position of the item. - * @return {*} The item stored at the position index. It's undefined if index isn't in the list bounds. - */ -LinkedList.prototype.getItem = function (index) { - if (index < 0 || index > this.length - 1) - return undefined; - var node = this.first; - for (; index > 0; index--) - node = node.next; - return node.item; -}; - -/** - * Transforms the list into an array. - * @return {Array<*>} The array built. - */ -LinkedList.prototype.toArray = function () { - var array = []; - for (var node = this.first, i = 0; node; node = node.next, i++) - array[i] = node.item; - return array; -}; - -/** - * Returns the length of the list. - * @return {Number} The length of the list. - */ -LinkedList.prototype.getLength = function () { - return this.length; -}; - -/** - * Builds the list from the array. - * @param array {Array<*>} The array from which build the list. - * @return {void} - */ -LinkedList.prototype.fromArray = function (array) { - var node = this.first; - for (var i = 0; i < Math.min(this.length, array.length); i++, node = node.next) - node.item = array[i]; - if (this.length < array.length) - for (var j = this.length; j < array.length; j++) - this.pushBack(array[j]); - else - for (var k = array.length; k < this.length;) - this.popBack(); -}; - -/** - * Returns the items that satisfy the condition determined by the callback. - * @param callback {function} The function that implements the condition. - * @return {Array<*>} The array that contains the items that satisfy the condition. - */ -LinkedList.prototype.filter = function (callback) { - var result = []; - for (var node = this.first; node; node = node.next) { - if (callback(node.item)) - result.push(node.item); - } - return result; -}; - -/** - * Checks if the list is empty. - * @return {boolean} True if the list is empty, false otherwise. - */ -LinkedList.prototype.isEmpty = function () { - return !this.length; -}; - -/** - * Returns the first position of the item in the list. - * @param item {*} The item to search. - * @param [callback = function(item){return(it===item);}] The condition to satisfy. The callback must accept the current item to check. - * @return {number} The first position of the item. - */ -LinkedList.prototype.indexOf = function (item, callback) { - callback = callback || function (it) { - return it === item; - }; - var i = 0; - var node = this.first; - while (node) { - if (callback(node.item)) - return i; - i++; - node = node.next; - } - return -1; -}; - -/** - * Returns the last position of the item in the list. - * @param item {*} The item to search. - * @param [callback = function(item){return(it===item);}] The condition to satisfy. The callback must accept the current item to check. - * @return {number} The last position of the item. - */ -LinkedList.prototype.lastIndexOf = function (item, callback) { - callback = callback || function (it) { - return it === item; - }; - var i = 0; - var node = this.first; - var index = -1; - while (node) { - if (callback(node.item)) - index = i; - i++; - node = node.next; - } - return index; -}; - -/** - * Returns all the position in which the item has been found in the list. - * @param item {*} The item to search. - * @param [callback = function(item){return(it===item);}] The condition to satisfy. The callback must accept the current item to check. - * @return {Array} The positions in which the item has been found. - */ -LinkedList.prototype.allIndexesOf = function (item, callback) { - callback = callback || function (it) { - return it === item; - }; - var i = 0; - var node = this.first; - var indexes = []; - while (node) { - if (callback(node.item)) - indexes.push(i); - i++; - node = node.next; - } - return indexes; -}; - -/** - * Add the list at the end of this list. - * @param list {LinkedList} The list to join. - * @return {void} - */ -LinkedList.prototype.join = function (list) { - if (this.last) - this.last.next = list.first; - else - this.first = list.first; - this.last = list.last; - this.length += list.length; -}; - -/** - * Divides the list at the index position. The node at the index position is the first new node of the list. - * @param index {number} The position where to divide the list. - * @return {LinkedList} The list formed by the nodes from the index position then. If the index is out of bound, the list will be empty. - */ -LinkedList.prototype.divide = function (index) { - var list = new LinkedList(); - if (index > -1 && index < this.length) { - var node = this.first; - var previous = null; - for (var i = 0; i < index; i++) { - previous = node; - node = node.next; - } - if (node === this.first) { - list.first = this.first; - list.last = this.last; - this.first = null; - this.last = null; - } else { - list.first = node; - list.last = this.last; - this.last = previous; - previous.next = null; - } - list.length = this.length - index; - this.length = index; - } - return list; -}; - -/** - * Clones the list into a new list. - * @return {LinkedList} The list cloned from this list. - */ -LinkedList.prototype.clone = function () { - var list = new LinkedList(); - var node = this.first; - for (var i = 0; i < this.length; i++, node = node.next) - if (node.item.clone) - list.pushBack(node.item.clone()); - else - list.pushBack(node.item); - return list; -}; - -/** - * Clones the list into a new list without cloning duplicated items. - * @return {LinkedList} The list cloned from this list. - */ -LinkedList.prototype.cloneDistinct = function () { - var list = new LinkedList(); - var node = this.first; - for (var i = 0; i < this.length; i++, node = node.next) - if (!list.contains(node.item)) - if (node.item.cloneDistinct) - list.pushBack(node.item.cloneDistinct()); - else if (node.item.clone) - list.pushBack(node.item.clone()); - else - list.pushBack(node.item); - return list; -}; - -/** - * Splits the list into lists of desired size. - * @param size {number} The size of the lists. - * @return {Array} The lists created by splitting the list. - */ -LinkedList.prototype.split = function (size) { - var length = this.length; - var lists = [this]; - for (var i = size; i < length; i += size) - lists.push(lists[lists.length - 1].divide(size)); - return lists; -}; - -/** - * Returns the number of items that satisfy the represented by the callback function. - * @param callback {function} The condition to satisfy. - * @return {number} The number of items that satisfy the condition. - */ -LinkedList.prototype.count = function (callback) { - var count = 0; - var node = this.first; - while (node) { - if (callback(node.item)) - count++; - node = node.next; - } - return count; -}; diff --git a/lib/LinkedList/LinkedListIterator.js b/lib/LinkedList/LinkedListIterator.js deleted file mode 100644 index 90237dd..0000000 --- a/lib/LinkedList/LinkedListIterator.js +++ /dev/null @@ -1,78 +0,0 @@ -/** - * Created by Stefano on 04/04/2014. - */ - -LinkedListIterator.prototype = new Iterator(); -LinkedListIterator.prototype.constructor = LinkedListIterator; - -/** - * Class that implements the iterator for a linked list. - * @param aggregate {LinkedList} The aggregate to scan. - * @constructor - */ -function LinkedListIterator(aggregate) { - /** - * The aggregate relates to this iterator. - * @type {LinkedList} - */ - this.aggregate = aggregate; - - /** - * The pointer to the position. - * @type {Node|null} - */ - this.pointer = null; -} - -/** - * @inheritDoc - */ -LinkedListIterator.prototype.first = function () { - this.pointer = this.aggregate.first; -}; - -/** - * @inheritDoc - */ -LinkedListIterator.prototype.next = function () { - this.pointer = this.pointer.next; -}; - -/** - * @inheritDoc - */ -LinkedListIterator.prototype.last = function () { - this.pointer = this.aggregate.last; -}; - -/** - * @inheritDoc - */ -LinkedListIterator.prototype.previous = function () { - var node = this.pointer; - for (this.pointer = this.first(); this.pointer.next !== node;) - this.next(); -}; - -/** - * @inheritDoc - */ -LinkedListIterator.prototype.isDone = function () { - return !this.pointer; -}; - -/** - * @inheritDoc - */ -LinkedListIterator.prototype.getItem = function () { - return this.pointer.item; -}; - -/** - * Return the node stored at the position pointed by the iterator. - * @abstract - * @return {Node|null} The node stored or null if it's out of the bounds. - */ -LinkedListIterator.prototype.getNode = function () { - return this.pointer; -}; \ No newline at end of file diff --git a/lib/PriorityQueue/PriorityQueue.js b/lib/PriorityQueue/PriorityQueue.js deleted file mode 100644 index 373c9b4..0000000 --- a/lib/PriorityQueue/PriorityQueue.js +++ /dev/null @@ -1,264 +0,0 @@ -/** - * Created by Stefano on 31/03/14. - */ - -PriorityQueue.prototype = new Aggregate(); -PriorityQueue.prototype.constructor = PriorityQueue; - -/** - * Class for managing a priority queue. - * @constructor - */ -function PriorityQueue() { - /** - * The list of the items in the queue. - * @type {RBTreeList} - */ - this.items = new RBTreeList(); - /** - * The length of the queue. - * @type {number} - */ - this.length = 0; -} - -/** - * @inheritDoc - */ -PriorityQueue.prototype.getIterator = function () { - return new PriorityQueueIterator(this); -}; - -/** - * Add the item at the tail of the queue. - * @param priority {number} The priority of the item. - * @param item {*} The item to add. - * @return {void} - */ -PriorityQueue.prototype.enqueue = function (priority, item) { - var queue = this.items.search(priority); - if (!queue) { - queue = new Queue(); - this.items.insert(priority, queue); - } - queue.enqueue(item); - this.length++; -}; - -/** - * Adds the items with the same priority at the tail of the queue. - * @param priority {number} The priority of the items. - * @param items {Array<*>} The items to add. - * @return {void} - */ -PriorityQueue.prototype.multiEnqueue = function (priority, items) { - for (var i = 0; i < items.length; i++) - this.enqueue(priority, items[i]); -}; - -/** - * Remove the item at the head of the queue. - * @return {*} The item at the head of the queue. It's undefined if the queue is empty. - */ -PriorityQueue.prototype.dequeue = function () { - var node = this.items.maximum(); - var item = undefined; - if (node) { - var queue = node.item; - item = queue.dequeue(); - if (queue.isEmpty()) - this.items.deleteNode(node); - this.length--; - } - return item; -}; - -/** - * Removes the items at the head of the queue. - * @param times {number} The number of times to repeat the dequeue method. - * @return {Array<*>} The items at the head of the queue. - */ -PriorityQueue.prototype.multiDequeue = function (times) { - var items = []; - for (var i = 0; i < times && this.length; i++) - items.push(this.dequeue()); - return items; -}; - -/** - * Removes the first length items from the position index. - * @param index {number} The position where to start to remove the items. - * @param [length = 1] {number} The number of items to remove. - * @return {void} - */ -PriorityQueue.prototype.remove = function (index, length) { - length = length || 1; - var it = this.items.getIterator(); - for (it.last(); !it.isDone() && length > 0; it.previous()) { - var queue = it.getItem(); - if (index > -1 && index < queue.getLength()) { - var oldLength = queue.getLength(); - queue.remove(index, length); - length -= oldLength - index; - index = 0; - if (!queue.getLength()) - this.items.deleteNode(it.getNode()); - } else - index = index - queue.getLength(); - } -}; - -/** - * Return the item at the position index. - * @param index {number} The index of the item. - * @return {*} The item found. It's undefined if the position index is out of bounds. - */ -PriorityQueue.prototype.getItem = function (index) { - var it = this.items.getIterator(); - for (it.last(); !it.isDone(); it.previous()) { - var queue = it.getItem(); - if (index > -1 && index < queue.getLength()) - return queue.getItem(index); - index = index - queue.getLength(); - } - return undefined; -}; - -/** - * Return the items relatives to the priority. - * @param priority {number} The priority of the items. - * @return {Array<*>} The items found. - */ -PriorityQueue.prototype.getItems = function (priority) { - var items = this.items.search(priority); - if (items) - return items.items; - return []; -}; - -/** - * Return the first item in the queue. The item is not removed. - * @return {*} The first item. It's undefined if the queue is empty. - */ -PriorityQueue.prototype.peek = function () { - return this.items.maximum().item.peek(); -}; - -/** - * Return the length of the queue. - * @return {number} The length of the queue. - */ -PriorityQueue.prototype.getLength = function () { - return this.length; -}; - -/** - * Checks if the queue is empty. - * @return {boolean} True if the queue is empty, false otherwise. - */ -PriorityQueue.prototype.isEmpty = function () { - return !this.length; -}; - -/** - * Removes all the items stored in the queue. - * @return {void} - */ -PriorityQueue.prototype.clear = function () { - this.items = new RBTreeList(); - this.length = 0; -}; - -/** - * Checks if the queue contains a priority that satisfy the condition represented by the callback function. - * @param priority {number} The priority to find. - * @param [callback = function(p){return(p===priority);}] The condition to satisfy. The callback must accept the current priority to check. - * @return {boolean} True if the queue contains the priority that satisfy the condition, false otherwise. - */ -PriorityQueue.prototype.containsPriority = function (priority, callback) { - if (callback) - return this.items.fullContains(callback); - else - return this.items.contains(priority); -}; - -/** - * Return the queue created by the priority queue with the items in the same order but without the priority. - * @return {Queue} The queue created. - */ -PriorityQueue.prototype.toQueue = function () { - var queue = new Queue(); - var it = this.items.getIterator(); - for (it.last(); !it.isDone(); it.previous()) { - var item = it.getItem(); - var itQ = item.getIterator(); - for (itQ.first(); !itQ.isDone(); itQ.next()) - queue.enqueue(itQ.getItem()); - } - return queue; -}; - -/** - * Executes the callback function for each item of the queue. - * This method modifies the queue so if you don't need to modify it you must return the same item of the array. - * @param callback {function} The function to execute for each item. The function must accept the current item on which execute the function. - * @return {void} - */ -PriorityQueue.prototype.execute = function (callback) { - var it = this.items.getIterator(); - for (it.last(); !it.isDone(); it.previous()) - it.getItem().execute(callback); -}; - -/** - * Change the priority of the item at the position index. - * @param index {number} The position of the item of which increase the priority. - * @param newPriority {number} The new priority. - * @return {void} - */ -PriorityQueue.prototype.changePriority = function (index, newPriority) { - var item = this.getItem(index); - this.remove(index); - this.enqueue(newPriority, item); -}; - -/** - * Returns the items that satisfy the condition determined by the callback. - * @param callback {function} The function that implements the condition. - * @return {Array<*>} The array that contains the items that satisfy the condition. - */ -PriorityQueue.prototype.filter = function (callback) { - var result = []; - var it = this.items.getIterator(); - for (it.last(); !it.isDone(); it.previous()) { - var itQ = it.getItem().getIterator(); - for (itQ.first(); !itQ.isDone(); itQ.next()) { - if (callback(itQ.getItem())) - result.push(itQ.getItem()); - } - } - return result; -}; - -/** - * Clones the queue into a new queue. - * @return {PriorityQueue} The queue cloned from this queue. - */ -PriorityQueue.prototype.clone = function () { - var queue = new PriorityQueue(); - queue.items = this.items.clone(); - queue.length = this.length; - return queue; -}; - -/** - * Clones the queue into a new queue without cloning duplicated items. - * @return {PriorityQueue} The queue cloned from this queue. - */ -PriorityQueue.prototype.cloneDistinct = function () { - var queue = new PriorityQueue(); - queue.items = this.items.cloneDistinct(); - queue.length = queue.items.getSize(); - return queue; -}; - diff --git a/lib/PriorityQueue/PriorityQueueIterator.js b/lib/PriorityQueue/PriorityQueueIterator.js deleted file mode 100644 index deceffa..0000000 --- a/lib/PriorityQueue/PriorityQueueIterator.js +++ /dev/null @@ -1,83 +0,0 @@ -/** - * Created by Stefano on 04/04/2014. - */ - -PriorityQueueIterator.prototype = new Iterator(); -PriorityQueueIterator.prototype.constructor = PriorityQueueIterator; - -/** - * Class that implements the iterator for a priority queue. - * @param aggregate {PriorityQueue} The aggregate to scan. - * @constructor - */ -function PriorityQueueIterator(aggregate) { - /** - * The aggregate relates to this iterator. - * @type {PriorityQueue} - */ - this.aggregate = aggregate; - - /** - * The pointer to the position of the node. - * @type {RBLNode|null} - */ - this.pointerNode = null; - /** - * The pointer to the position in the node. - * @type {number} - */ - this.pointerPosition = -1; -} - -/** - * @inheritDoc - */ -PriorityQueueIterator.prototype.first = function () { - this.pointerNode = this.aggregate.items.maximum(); - this.pointerPosition = 0; -}; - -/** - * @inheritDoc - */ -PriorityQueueIterator.prototype.next = function () { - this.pointerPosition++; - if (this.pointerPosition > this.pointerNode.item.getLength() - 1) { - this.pointerNode = this.pointerNode.previous; - this.pointerPosition = 0; - } -}; - -/** - * @inheritDoc - */ -PriorityQueueIterator.prototype.last = function () { - this.pointerNode = this.aggregate.items.minimum(); - this.pointerPosition = this.pointerNode.item.getLength() - 1; -}; - -/** - * @inheritDoc - */ -PriorityQueueIterator.prototype.previous = function () { - this.pointerPosition--; - if (this.pointerPosition < 0) { - this.pointerNode = this.pointerNode.next; - if (this.pointerNode) - this.pointerPosition = this.pointerNode.item.getLength() - 1; - } -}; - -/** - * @inheritDoc - */ -PriorityQueueIterator.prototype.isDone = function () { - return !this.pointerNode; -}; - -/** - * @inheritDoc - */ -PriorityQueueIterator.prototype.getItem = function () { - return this.pointerNode.item.items[this.pointerPosition]; -}; \ No newline at end of file diff --git a/lib/Queue/Queue.js b/lib/Queue/Queue.js deleted file mode 100644 index 15486ba..0000000 --- a/lib/Queue/Queue.js +++ /dev/null @@ -1,297 +0,0 @@ -/** - * Created by Stefano on 31/03/14. - */ - -Queue.prototype = new Aggregate(); -Queue.prototype.constructor = Queue; - -/** - * Class for managing a queue. - * @param {...*} [args] The items for initializing the queue. - * @constructor - */ -function Queue(args) { - /** - * The list of the items in the queue. - * @type {Array<*>} - */ - this.items = []; - - /** - * Decreases dequeue big O complexity by shifting starting indexs - * for each dequeue, instead of splicing. - * @type {int} - */ - this.offsetIndex = 0; - - if(args && args.length) { - //builds the list from the range passed from the constructor - this.multiEnqueue(args); - } else { - //builds the list from the parameters of the constructor - this.multiEnqueue(arguments); - } -} - -/** - * @inheritDoc - */ -Queue.prototype.getIterator = function () { - return new QueueIterator(this); -}; - -/** - * Adds the item at the tail of the queue. - * @param item {*} The item to add. - * @return {void} - */ -Queue.prototype.enqueue = function (item) { - this.items.push(item); -}; - -/** - * Adds the items at the tail of the queue. - * @param items {Array<*>} The items to add. - * @return {void} - */ -Queue.prototype.multiEnqueue = function (items) { - for (var i = 0; i < items.length; i++) - this.items.push(items[i]); -}; - -/** - * Removes the item at the head of the queue. - * @return {*} The item at the head of the queue. It's undefined if the queue is empty. - */ -Queue.prototype.dequeue = function () { - if (!(this.items.length - this.offsetIndex)) - return undefined; - - var dequeued = this.items[this.offsetIndex]; // holds the value, for cases that purge occurs - this.offsetIndex++; - /** - * Automatically purge unneeded (already dequeued) - * indexs from the array when they take up - * more than one half the array - */ - if (this.offsetIndex >= this.items.length/2){ - this.purge(); - } - - return dequeued; //return dequeued item -}; - -/** - * Removes the items at the head of the queue. - * @param times {number} The number of times to repeat the dequeue method. - * @return {Array<*>} The items at the head of the queue. - */ -Queue.prototype.multiDequeue = function (times) { - var dequeued = []; // Holds variables that have been removed from the array - // Dequeue the desired number of items - console.log('items', this.items); - for(var i = 0; (i < times && this.items.length -this.offsetIndex > 0); i++){ - console.log('calleds'); - dequeued.push(this.dequeue()); - } - - return dequeued; //removes the last times item and returns the array -}; - -/** - * Clears array indexs hidden by offset. To free up memory - * @return {void} - */ -Queue.prototype.purge = function(){ - this.items.splice(0, this.offsetIndex); - this.offsetIndex = 0; -} - -/** - * Removes the first length items from the position index. - * @param index {number} The position where to start to remove the items. - * @param [length = 1] {number} The number of items to remove. - * @return {void} - */ -Queue.prototype.remove = function (index, length) { - length = length || 1; - this.items.splice(index, length); -}; - -/** - * Returns the item at the position index. - * @param index {number} The position of the item. - * @return {*} The item at the position. It's undefined if index isn't in the queue bounds. - */ -Queue.prototype.getItem = function (index) { - // take offsetIndex into account - var index = index + this.offsetIndex; - if (index < 0 || index > this.items.length - 1 - this.offsetIndex) - return undefined; - return this.items[index]; -}; - -/** - * Returns the first item in the queue. The item is not removed. - * @return {*} The first item. It's undefined if the queue is empty. - */ -Queue.prototype.peek = function () { - if (this.items.length - this.offsetIndex) - return this.items[this.offsetIndex]; - return undefined -}; - -/** - * Removes all the items stored in the queue. - * @return {void} - */ -Queue.prototype.clear = function () { - this.items = []; -}; - -/** - * Checks if the queue contains an item that satisfy the condition represented by the callback function. - * @param item {*} The item to find. - * @param [callback = function(item){return(it===item);}] The condition to satisfy. The callback must accept the current item to check. - * @return {boolean} True if the queue contains the item that satisfy the condition, false otherwise. - */ -Queue.prototype.contains = function (item, callback) { - callback = callback || function (it) { - return it === item; - }; - var i = this.offsetIndex; - while (i < this.items.length && !callback(this.items[i])) - i++; - return i < this.items.length; -}; - -/** - * Executes the callback function for each item of the queue. - * This method modifies the queue so if you don't need to modify it you must return the same item of the array. - * @param callback {function} The function to execute for each item. The function must accept the current item on which execute the function. - * @return {void} - */ -Queue.prototype.execute = function (callback) { - for (var i = this.offsetIndex; i < this.items.length; i++) - this.items[i] = callback(this.items[i]); -}; - -/** - * Returns the length of the queue. - * @return {number} The length of the queue. - */ -Queue.prototype.getLength = function () { - return this.items.length - this.offsetIndex; -}; - -/** - * Checks if the queue is empty. - * @return {boolean} True if the queue is empty, false otherwise. - */ -Queue.prototype.isEmpty = function () { - return !(this.items.length - this.offsetIndex); -}; - -/** - * Returns the items that satisfy the condition determined by the callback. - * @param callback {function} The function that implements the condition. - * @return {Array<*>} The array that contains the items that satisfy the condition. - */ -Queue.prototype.filter = function (callback) { - var result = []; - for (var i = this.offsetIndex; i < this.items.length; i++) - if (callback(this.items[i])) - result.push(this.items[i]); - return result; -}; - -/** - * Returns the first position of the item in the queue. - * @param item {*} The item to search. - * @param [callback = function(item){return(it===item);}] The condition to satisfy. The callback must accept the current item to check. - * @return {number} The first position of the item. - */ -Queue.prototype.indexOf = function (item, callback) { - callback = callback || function (it) { - return it === item; - }; - var i = this.offsetIndex; - while (i < this.items.length) { - if (callback(this.items[i])) - return i - this.offsetIndex; - i++; - } - return -1; -}; - -/** - * Returns the last position of the item in the queue. - * @param item {*} The item to search. - * @param [callback = function(item){return(it===item);}] The condition to satisfy. The callback must accept the current item to check. - * @return {number} The last position of the item. - */ -Queue.prototype.lastIndexOf = function (item, callback) { - callback = callback || function (it) { - return it === item; - }; - var i = this.items.length - 1; - while (i > this.offsetIndex - 1) { - console.log('l', this.offsetIndex); - if (callback(this.items[i])) - return i - this.offsetIndex; - i--; - } - return -1; -}; - -/** - * Returns all the position in which the item has been found in the queue. - * @param item {*} The item to search. - * @param [callback = function(item){return(it===item);}] The condition to satisfy. The callback must accept the current item to check. - * @return {Array} The positions in which the item has been found. - */ -Queue.prototype.allIndexesOf = function (item, callback) { - callback = callback || function (it) { - return it === item; - }; - var i = this.offsetIndex; - var indexes = []; - while (i < this.items.length) { - if (callback(this.items[i])) - indexes.push(i - this.offsetIndex); - i++; - } - return indexes; -}; - -/** - * Clones the queue into a new queue. - * @return {Queue} The queue cloned from this queue. - */ -Queue.prototype.clone = function () { - var queue = new Queue(); - for (var i = this.offsetIndex; i < this.items.length; i++) - if (this.items[i].clone) - queue.enqueue(this.items[i].clone()); - else - queue.enqueue(this.items[i]); - - return queue; -}; - -/** - * Clones the queue into a new queue without cloning duplicated items. - * @return {Queue} The queue cloned from this queue. - */ -Queue.prototype.cloneDistinct = function () { - var queue = new Queue(); - for (var i = this.offsetIndex; i < this.items.length; i++) - if (!queue.contains(this.items[i])) - if (this.items[i].cloneDistinct) - queue.enqueue(this.items[i].cloneDistinct()); - else if (this.items[i].clone) - queue.enqueue(this.items[i].clone()); - else - queue.enqueue(this.items[i]); - return queue; -}; \ No newline at end of file diff --git a/lib/Queue/QueueIterator.js b/lib/Queue/QueueIterator.js deleted file mode 100644 index e0b6db7..0000000 --- a/lib/Queue/QueueIterator.js +++ /dev/null @@ -1,67 +0,0 @@ -/** - * Created by Stefano on 04/04/2014. - */ - -QueueIterator.prototype = new Iterator(); -QueueIterator.prototype.constructor = QueueIterator; - -/** - * Class that implements the iterator for a linked list. - * @param aggregate {Queue} The aggregate to scan. - * @constructor - */ -function QueueIterator(aggregate) { - /** - * The aggregate relates to this iterator. - * @type {Queue} - */ - this.aggregate = aggregate; - - /** - * The pointer to the position. - * @type {number} - */ - this.pointer = -1; -} - -/** - * @inheritDoc - */ -QueueIterator.prototype.first = function () { - this.pointer = 0; -}; - -/** - * @inheritDoc - */ -QueueIterator.prototype.next = function () { - this.pointer++; -}; - -/** - * @inheritDoc - */ -QueueIterator.prototype.last = function () { - this.pointer = this.aggregate.items.length - 1; -}; - -/** - * @inheritDoc - */ -QueueIterator.prototype.previous = function () { - this.pointer--; -}; - -/** - * @inheritDoc - */ -QueueIterator.prototype.isDone = function () { - return this.pointer < 0 || this.pointer > this.aggregate.items.length - 1; -}; - -/** - * @inheritDoc - */ -QueueIterator.prototype.getItem = function () { - return this.aggregate.getItem(this.pointer); -}; \ No newline at end of file diff --git a/lib/RBTree/RBTree.js b/lib/RBTree/RBTree.js deleted file mode 100644 index dd4edf4..0000000 --- a/lib/RBTree/RBTree.js +++ /dev/null @@ -1,553 +0,0 @@ -/** - * The single node of the tree. - * @param key {number} The key of the node. - * @param item {*} The item to store in the node. - * @constructor - */ -function RBNode(key, item) { - /** - * The item stored. - * @type {*} - */ - this.item = item; - /** - * The key of the node. - * @type {number} - */ - this.key = key; - /** - * The parent node. It's null if there's no a parent node. - * @type {RBNode|null} - */ - this.parent = null; - /** - * The left node. It's null if there's no a left node. - * @type {RBNode|null} - */ - this.left = null; - /** - * The right node. It's null if there's no a right node. - * @type {RBNode|null} - */ - this.right = null; - /** - * The type of the node. It's or red or black. - * @type {string} - */ - this.type = 'r'; -} - -RBTree.prototype = new Aggregate(); -RBTree.prototype.constructor = RBTree; - -/** - * Class for managing a red-black tree. - * @constructor - */ -function RBTree() { - /** - * The root of the tree. - * @type {RBNode|null} - */ - this.root = null; - /** - * The number of items stored in the tree. - * @type {number} - */ - this.size = 0; -} - -/** - * @inheritDoc - */ -RBTree.prototype.getIterator = function () { - return new RBTreeIterator(this); -}; - -/** - * Insert the item relatives to the key value in the tree. - * @param key {number} The key to store. - * @param item {*} The item to store. - * @return {void} - */ -RBTree.prototype.insert = function (key, item) { - var node = new RBNode(key, item); - this.size++; - if (!this.root) { - this.root = node; - node.type = 'b'; - return; - } - var p = this.root; - for (var n = this.root; n;) { - p = n; - if (key < n.key) - n = n.left; - else - n = n.right; - } - node.parent = p; - if (!p) - this.root = node; - else if (key < p.key) - p.left = node; - else - p.right = node; - - this.insertFixUp(node); -}; - -/** - * Preserve the properties of the tree after an insert. - * @param node {RBNode} The node to insert. - * @return {void} - */ -RBTree.prototype.insertFixUp = function (node) { - for (var parent = node.parent; parent && parent.type === 'r'; parent = node.parent) { - if (parent === parent.parent.left) { - var uncle = parent.parent.right; - if (uncle && uncle.type === 'r') { - parent.type = 'b'; - uncle.type = 'b'; - parent.parent.type = 'r'; - node = parent.parent; - } else if (node === parent.right) { - node = parent; - this.leftRotate(node); - } else { - parent.type = 'b'; - parent.parent.type = 'r'; - this.rightRotate(parent.parent); - } - } else { - var uncle = parent.parent.left; - if (uncle && uncle.type === 'r') { - parent.type = 'b'; - uncle.type = 'b'; - parent.parent.type = 'r'; - node = parent.parent; - } else if (node === parent.left) { - node = parent; - this.rightRotate(node); - } else { - parent.type = 'b'; - parent.parent.type = 'r'; - this.leftRotate(parent.parent); - } - } - } - this.root.type = 'b'; -}; - -/** - * Delete the node from the tree. - * @param node {RBNode} The node to delete. - * @return {void} - */ -RBTree.prototype.deleteNode = function (node) { - var successor; - this.size--; - if (!node.left || !node.right) - successor = node; - else { - successor = this.successor(node); - node.key = successor.key; - node.item = successor.item; - } - var child; - if (!successor.left) - child = successor.right; - else - child = successor.left; - if (child) - child.parent = successor.parent; - if (!successor.parent) - this.root = child; - else if (successor === successor.parent.left) - successor.parent.left = child; - else - successor.parent.right = child; - - if (successor.type === 'b') - this.deleteFixUp(child, successor.parent); -}; - -/** - * Preserve the properties of the tree after a deletion. - * @param node {RBNode} The node to delete. - * @param parent {RBNode} The parent of the node. - * @return {void} - */ -RBTree.prototype.deleteFixUp = function (node, parent) { - while (node !== this.root && (!node || node.type === 'b')) { - if (node === parent.left) { - var brother = parent.right; - if (brother && brother.type === 'r') { - brother.type = 'b'; - parent.type = 'r'; - this.leftRotate(parent); - brother = parent.right; - } - if (brother && (!brother.left || brother.left.type === 'b') && (!brother.right || brother.right.type === 'b')) { - brother.type = 'r'; - node = parent; - } else { - if (!brother.right || brother.right.type === 'b') { - brother.left.type = 'b'; - brother.type = 'r'; - this.rightRotate(brother); - brother = parent.right; - } - brother.type = parent.type; - parent.type = 'b'; - brother.right.type = 'b'; - this.leftRotate(parent); - node = this.root; - } - } else { - var brother = parent.left; - if (brother && brother.type === 'r') { - brother.type = 'b'; - parent.type = 'r'; - this.rightRotate(parent); - brother = parent.left; - } - if (brother && (!brother.left || brother.left.type === 'b') && (!brother.right || brother.right.type === 'b')) { - brother.type = 'r'; - node = parent; - } else { - if (!brother.left || brother.left.type === 'b') { - brother.right.type = 'b'; - brother.type = 'r'; - this.leftRotate(brother); - brother = parent.left; - } - brother.type = parent.type; - parent.type = 'b'; - brother.left.type = 'b'; - this.rightRotate(parent); - node = this.root; - } - } - parent = node.parent; - } - if (node) - node.type = 'b'; -}; - -/** - * Get the node with the key next to the param node key. - * @param node {RBNode} The node of which search the successor. - * @return {RBNode} The node found. - */ -RBTree.prototype.successor = function (node) { - if (node.right) - return this.minimum(node.right); - var parent = node.parent; - while (parent && node === parent.right) { - node = parent; - parent = parent.parent; - } - return parent; -}; - -/** - * Get the node with the key previous to the param node key. - * @param node {RBNode} The node of which search the predecessor. - * @return {RBNode} The node found. - */ -RBTree.prototype.predecessor = function (node) { - if (node.left) - return this.maximum(node.left); - var parent = node.parent; - while (parent && node === parent.left) { - node = parent; - parent = parent.parent; - } - return parent; -}; - -/** - * Search the item relatives to the key and to the nodes that satisfy the condition represented by the callback function. - * @param key {number} The key to find. - * @param [node = root] {RBNode} The node from which start the search. - * @param [callback = function(node){return(node.key===key);}] The condition to satisfy. The callback must accept the current node to check. - * @return {*} The item found or undefined if there isn't the key in the tree. - */ -RBTree.prototype.search = function (key, node, callback) { - node = node || this.root; - callback = callback || function (node) { - return node.key === key; - }; - while (node && !callback(node)) - if (key < node.key) - node = node.left; - else - node = node.right; - if (node) - return node.item; - return undefined; -}; - -/** - * Checks if the tree contains a key or a node that satisfy the condition represented by the callback function. - * This method avoid to search in branches where the key won't be found. - * @param key {*} The key to find. - * @param [callback = function(node){return(node.key===key);}] The condition to satisfy. The callback must accept the current node to check. - * @return {boolean} True if the tree contains the key or a node that satisfy the condition, false otherwise. - */ -RBTree.prototype.contains = function (key, callback) { - return this.search(key, null, callback) !== undefined; -}; - -/** - * Checks if the tree contains a node that satisfy the condition represented by the callback function. - * This method check all the tree avoiding the binary search. - * @param callback {function} The condition to satisfy. The callback must accept the current node to check. - * @return {boolean} True if the tree contains the node that satisfy the condition, false otherwise. - */ -RBTree.prototype.fullContains = function (callback) { - var node = this.minimum(); - while (node && !callback(node.key)) - node = this.successor(node); - return node !== null; -}; - -/** - * Get the item relatives to the minimum key stored in the tree. - * @param [node = root] {Node} The node from which start the search. - * @return {RBNode} The node found. - */ -RBTree.prototype.minimum = function (node) { - node = node || this.root; - while (node && node.left) - node = node.left; - return node; -}; - -/** - * Get the item relatives to the maximum key stored in the tree. - * @param [node = root] {Node} The node from which start the search. - * @return {RBNode} The node found. - */ -RBTree.prototype.maximum = function (node) { - node = node || this.root; - while (node && node.right) - node = node.right; - return node; -}; - -/** - * Rotate the node with its right child. - * @param node {RBNode} The node to rotate. - * @return {void} - */ -RBTree.prototype.leftRotate = function (node) { - var child = node.right; - node.right = child.left; - if (child.left !== null) - child.left.parent = node; - child.parent = node.parent; - if (node.parent === null) - this.root = child; - else if (node === node.parent.left) - node.parent.left = child; - else - node.parent.right = child; - node.parent = child; - child.left = node; -}; - -/** - * Rotate the node with its left child. - * @param node {RBNode} The node to rotate. - * @return {void} - */ -RBTree.prototype.rightRotate = function (node) { - var child = node.left; - node.left = child.right; - if (child.right !== null) - child.right.parent = node; - child.parent = node.parent; - if (node.parent === null) - this.root = child; - else if (node === node.parent.left) - node.parent.left = child; - else - node.parent.right = child; - node.parent = child; - child.right = node; -}; - -/** - * Returns the size of the tree. - * @return {number} The size of the tree. - */ -RBTree.prototype.getSize = function () { - return this.size; -}; - -/** - * Clones the queue into a new queue. - * @return {RBTree} The tree cloned from this queue. - */ -RBTree.prototype.clone = function () { - var tree = new RBTree(); - var it = this.getIterator(); - for (it.first(); !it.isDone(); it.next()) - if (it.getNode().item.clone) - tree.insert(it.getNode().key, it.getNode().item.clone()); - else - tree.insert(it.getNode().key, it.getNode().item); - - return tree; -}; - -/** - * Clones the tree into a new tree without cloning duplicated items. - * @return {RBTree} The tree cloned from this tree. - */ -RBTree.prototype.cloneDistinct = function () { - var tree = new RBTree(); - var it = this.getIterator(); - for (it.first(); !it.isDone(); it.next()) { - var callback = function (node) { - return node.key === it.getNode().key && node.item === it.getNode().item; - }; - if (!tree.contains(it.getNode().key, callback)) { - if (it.getNode().item.cloneDistinct) - tree.insert(it.getNode().key, it.getNode().item.cloneDistinct()); - else if (it.getNode().item.clone) - tree.insert(it.getNode().key, it.getNode().item.clone()); - else - tree.insert(it.getNode().key, it.getNode().item); - } - } - return tree; -}; - -/** - * Transform the tree into an array without preserving keys. - * @return {Array<*>} The array that represents the tree. - */ -RBTree.prototype.toArray = function () { - var result = []; - for (var node = this.minimum(); node; node = this.successor(node)) - result.push(node.item); - return result; -}; - -/** - * Removes all the items stored in the tree. - * @return {void} - */ -RBTree.prototype.clear = function () { - this.root = null; - this.size = 0; -}; - -/** - * Checks if the tree is empty. - * @return {boolean} True if the tree is empty, false otherwise. - */ -RBTree.prototype.isEmpty = function () { - return !this.size; -}; - -/** - * Executes the callback function for each item of the tree. - * This method modifies the tree so if you don't need to modify it you must return the same item stored. - * @param callback {function} The function to execute for each item. The function must accept the current item on which execute the function. - * @return {void} - */ -RBTree.prototype.execute = function (callback) { - for (var node = this.minimum(); node; node = this.successor(node)) - node.item = callback(node.item); -}; - -/** - * Returns the items that satisfy the condition determined by the callback. - * @param callback {function} The function that implements the condition. - * @return {Array<*>} The array that contains the items that satisfy the condition. - */ -RBTree.prototype.filter = function (callback) { - var result = []; - for (var node = this.minimum(); node; node = this.successor(node)) - if (callback(node.item)) - result.push(node.item); - return result; -}; - -/** - * Returns the first position of the item in the tree. - * @param item {*} The item to search. - * @param [callback = function(item){return(it===item);}] The condition to satisfy. The callback must accept the current item to check. - * @return {number} The first position of the item. - */ -RBTree.prototype.indexOf = function (item, callback) { - callback = callback || function (it) { - return it === item; - }; - var i = 0, node = this.minimum(); - while (node) { - if (callback(node.item)) - return i; - node = this.successor(node); - i++; - } - return -1; -}; - -/** - * Returns the last position of the item in the tree. - * @param item {*} The item to search. - * @param [callback = function(item){return(it===item);}] The condition to satisfy. The callback must accept the current item to check. - * @return {number} The last position of the item. - */ -RBTree.prototype.lastIndexOf = function (item, callback) { - callback = callback || function (it) { - return it === item; - }; - var i = this.size - 1, node = this.maximum(); - while (node) { - if (callback(node.item)) - return i; - i--; - node = this.predecessor(node); - } - return -1; -}; - -/** - * Returns all the position in which the item has been found in the tree. - * @param item {*} The item to search. - * @param [callback = function(item){return(it===item);}] The condition to satisfy. The callback must accept the current item to check. - * @return {Array} The positions in which the item has been found. - */ -RBTree.prototype.allIndexesOf = function (item, callback) { - callback = callback || function (it) { - return it === item; - }; - var i = 0, node = this.minimum(); - var indexes = []; - while (node) { - if (callback(node.item)) - indexes.push(i); - i++; - node = this.successor(node); - } - return indexes; -}; - -/** - * Returns the item at the position index. - * @param index {number} The position of the item. - * @return {*} The item at the position. It's undefined if index isn't in the tree bounds. - */ -RBTree.prototype.getItem = function (index) { - if (index < 0 || index > this.size - 1) - return undefined; - for (var node = this.minimum(), i = 0; i < index; node = this.successor(node)) - i++; - return node.item; -}; \ No newline at end of file diff --git a/lib/RBTree/RBTreeIterator.js b/lib/RBTree/RBTreeIterator.js deleted file mode 100644 index accb87b..0000000 --- a/lib/RBTree/RBTreeIterator.js +++ /dev/null @@ -1,76 +0,0 @@ -/** - * Created by Stefano on 06/04/2014. - */ - -RBTreeIterator.prototype = new Iterator(); -RBTreeIterator.prototype.constructor = RBTreeIterator; - -/** - * Class that implements the iterator for a red-black tree. - * @param aggregate {RBTree} The aggregate to scan. - * @constructor - */ -function RBTreeIterator(aggregate) { - /** - * The aggregate relates to this iterator. - * @type {RBTree} - */ - this.aggregate = aggregate; - - /** - * The pointer to the position. - * @type {RBNode|null} - */ - this.pointer = null; -} - -/** - * @inheritDoc - */ -RBTreeIterator.prototype.first = function () { - this.pointer = this.aggregate.minimum(); -}; - -/** - * @inheritDoc - */ -RBTreeIterator.prototype.next = function () { - this.pointer = this.aggregate.successor(this.pointer); -}; - -/** - * @inheritDoc - */ -RBTreeIterator.prototype.last = function () { - this.pointer = this.aggregate.maximum(); -}; - -/** - * @inheritDoc - */ -RBTreeIterator.prototype.previous = function () { - this.pointer = this.aggregate.predecessor(this.pointer); -}; - -/** - * @inheritDoc - */ -RBTreeIterator.prototype.isDone = function () { - return !this.pointer; -}; - -/** - * @inheritDoc - */ -RBTreeIterator.prototype.getItem = function () { - return this.pointer.item; -}; - -/** - * Return the node stored at the position pointed by the iterator. - * @abstract - * @return {RBNode|null} The node stored or null if it's out of the bounds. - */ -RBTreeIterator.prototype.getNode = function () { - return this.pointer; -}; \ No newline at end of file diff --git a/lib/RBTreeList/RBTreeList.js b/lib/RBTreeList/RBTreeList.js deleted file mode 100644 index c5f1d85..0000000 --- a/lib/RBTreeList/RBTreeList.js +++ /dev/null @@ -1,603 +0,0 @@ -/** - * The single node of the tree. - * @param key {number} The key of the node. - * @param item {*} The item to store in the node. - * @constructor - */ -function RBLNode(key, item) { - /** - * The item stored. - * @type {*} - */ - this.item = item; - /** - * The key of the node. - * @type {number} - */ - this.key = key; - /** - * The parent node. It's null if there's no a parent node. - * @type {RBLNode|null} - */ - this.parent = null; - /** - * The left node. It's null if there's no a left node. - * @type {RBLNode|null} - */ - this.left = null; - /** - * The right node. It's null if there's no a right node. - * @type {RBLNode|null} - */ - this.right = null; - /** - * The next node. It's null if there's no a next node. - * @type {RBLNode|null} - */ - this.next = null; - /** - * The previous node. It's null if there's no a previous node. - * @type {RBLNode|null} - */ - this.previous = null; - /** - * The type of the node. It's or red or black. - * @type {string} - */ - this.type = 'r'; -} - -RBTreeList.prototype = new Aggregate(); -RBTreeList.prototype.constructor = RBTreeList; - -function RBTreeList() { - /** - * The root of the tree. - * @type {RBLNode|null} - */ - this.root = null; - /** - * The first node of the tree. - * @type {RBLNode|null} - */ - this.first = null; - /** - * The last node of the tree. - * @type {RBLNode|null} - */ - this.last = null; - /** - * The size of the tree. - * @type {number} - */ - this.size = 0; -} - -/** - * @inheritDoc - */ -RBTreeList.prototype.getIterator = function () { - return new RBTreeListIterator(this); -}; - -/** - * Insert the item relatives to the key value in the tree. - * @param key {number} The key to store. - * @param item {*} The item to store. - * @return {void} - */ -RBTreeList.prototype.insert = function (key, item) { - var node = new RBLNode(key, item); - this.size++; - if (!this.root) { - this.root = node; - this.first = node; - this.last = node; - node.type = 'b'; - return; - } - var p = this.root; - for (var n = this.root; n;) { - p = n; - if (key < n.key) - n = n.left; - else - n = n.right; - } - node.parent = p; - if (!p) - this.root = node; - else if (key < p.key) - p.left = node; - else - p.right = node; - - node.next = this.successor(node); - if (node.next) { - if (node.next.previous) - node.next.previous.next = node; - else - this.first = node; - node.previous = node.next.previous; - node.next.previous = node; - } else { - this.last = node; - node.previous = this.predecessor(node); - if (node.previous) - node.previous.next = node; - else - this.first = node; - } - - this.insertFixUp(node); -}; - -/** - * Preserve the properties of the tree after an insert. - * @param node {RBLNode} The node to insert. - * @return {void} - */ -RBTreeList.prototype.insertFixUp = function (node) { - for (var parent = node.parent; parent && parent.type === 'r'; parent = node.parent) { - if (parent === parent.parent.left) { - var uncle = parent.parent.right; - if (uncle && uncle.type === 'r') { - parent.type = 'b'; - uncle.type = 'b'; - parent.parent.type = 'r'; - node = parent.parent; - } else if (node === parent.right) { - node = parent; - this.leftRotate(node); - } else { - parent.type = 'b'; - parent.parent.type = 'r'; - this.rightRotate(parent.parent); - } - } else { - var uncle = parent.parent.left; - if (uncle && uncle.type === 'r') { - parent.type = 'b'; - uncle.type = 'b'; - parent.parent.type = 'r'; - node = parent.parent; - } else if (node === parent.left) { - node = parent; - this.rightRotate(node); - } else { - parent.type = 'b'; - parent.parent.type = 'r'; - this.leftRotate(parent.parent); - } - } - } - this.root.type = 'b'; -}; - -/** - * Delete the node from the tree. - * @param node {RBLNode} The node to delete. - * @return {void} - */ -RBTreeList.prototype.deleteNode = function (node) { - this.size--; - var successor; - if (!node.left || !node.right) - successor = node; - else { - successor = this.successor(node); - node.key = successor.key; - node.item = successor.item; - } - var child; - if (!successor.left) - child = successor.right; - else - child = successor.left; - if (child) - child.parent = successor.parent; - if (!successor.parent) - this.root = child; - else if (successor === successor.parent.left) - successor.parent.left = child; - else - successor.parent.right = child; - - if (successor.next) - successor.next.previous = successor.previous; - else - this.last = successor.previous; - if (successor.previous) - successor.previous.next = successor.next; - else - this.first = successor.next; - - if (successor.type === 'b') - this.deleteFixUp(child, successor.parent); -}; - -/** - * Preserve the properties of the tree after a deletion. - * @param node {RBLNode} The node to delete. - * @param parent {RBLNode} The parent of the node. - * @return {void} - */ -RBTreeList.prototype.deleteFixUp = function (node, parent) { - while (node !== this.root && (!node || node.type === 'b')) { - if (node === parent.left) { - var brother = parent.right; - if (brother && brother.type === 'r') { - brother.type = 'b'; - parent.type = 'r'; - this.leftRotate(parent); - brother = parent.right; - } - if (brother && (!brother.left || brother.left.type === 'b') && (!brother.right || brother.right.type === 'b')) { - brother.type = 'r'; - node = parent; - } else { - if (!brother.right || brother.right.type === 'b') { - brother.left.type = 'b'; - brother.type = 'r'; - this.rightRotate(brother); - brother = parent.right; - } - brother.type = parent.type; - parent.type = 'b'; - brother.right.type = 'b'; - this.leftRotate(parent); - node = this.root; - } - } else { - var brother = parent.left; - if (brother && brother.type === 'r') { - brother.type = 'b'; - parent.type = 'r'; - this.rightRotate(parent); - brother = parent.left; - } - if (brother && (!brother.left || brother.left.type === 'b') && (!brother.right || brother.right.type === 'b')) { - brother.type = 'r'; - node = parent; - } else { - if (!brother.left || brother.left.type === 'b') { - brother.right.type = 'b'; - brother.type = 'r'; - this.leftRotate(brother); - brother = parent.left; - } - brother.type = parent.type; - parent.type = 'b'; - brother.left.type = 'b'; - this.rightRotate(parent); - node = this.root; - } - } - parent = node.parent; - } - if (node) - node.type = 'b'; -}; - -/** - * Get the node with the key next to the param node key. - * @param node {RBLNode} The node of which search the successor. - * @return {RBLNode} The node found. - */ -RBTreeList.prototype.successor = function (node) { - if (node.next || node === this.last) - return node.next; - if (node.right) - return this.minimum(node.right); - var parent = node.parent; - while (parent && node === parent.right) { - node = parent; - parent = parent.parent; - } - return parent; -}; - -/** - * Get the node with the key previous to the param node key. - * @param node {RBLNode} The node of which search the predecessor. - * @return {RBLNode} The node found. - */ -RBTreeList.prototype.predecessor = function (node) { - if (node.previous || node === this.first) - return node.previous; - if (node.left) - return this.maximum(node.left); - var parent = node.parent; - while (parent && node === parent.left) { - node = parent; - parent = parent.parent; - } - return parent; -}; - -/** - * Search the item relatives to the key that satisfy the condition represented by the callback function. - * @param key {number} The key to find. - * @param [node = root] {RBNode} The node from which start the search. - * @param [callback = function(k){return(k===key);}] The condition to satisfy. The callback must accept the current key to check. - * @return {*} The item found or undefined if there isn't the key in the tree. - */ -RBTreeList.prototype.search = function (key, node, callback) { - node = node || this.root; - callback = callback || function (node) { - return node.key === key; - }; - while (node && !callback(node)) - if (key < node.key) - node = node.left; - else - node = node.right; - if (node) - return node.item; - return undefined; -}; - -/** - * Checks if the tree contains a key or a node that satisfy the condition represented by the callback function. - * This method avoid to search in branches where the key won't be found. - * @param key {*} The key to find. - * @param [callback = function(node){return(node.key===key);}] The condition to satisfy. The callback must accept the current node to check. - * @return {boolean} True if the tree contains the key or a node that satisfy the condition, false otherwise. - */ -RBTreeList.prototype.contains = function (key, callback) { - return this.search(key, null, callback) !== undefined; -}; - -/** - * Checks if the tree contains a node that satisfy the condition represented by the callback function. - * This method check all the tree avoiding the binary search. - * @param callback {function} The condition to satisfy. The callback must accept the current node to check. - * @return {boolean} True if the tree contains the node that satisfy the condition, false otherwise. - */ -RBTreeList.prototype.fullContains = function (callback) { - var node = this.first; - while (node && !callback(node.key)) - node = node.next; - return node !== null; -}; - -/** - * Get the item relatives to the minimum key stored in the tree. - * @param [node = root] {Node} The node from which start the search. - * @return {RBLNode} The node found. - */ -RBTreeList.prototype.minimum = function (node) { - if (node) - while (node && node.left) - node = node.left; - else - return this.first; - return node; -}; - -/** - * Get the item relatives to the maximum key stored in the tree. - * @param [node = root] {Node} The node from which start the search. - * @return {RBLNode} The node found. - */ -RBTreeList.prototype.maximum = function (node) { - if (node) - while (node && node.right) - node = node.right; - else - return this.last; - return node; -}; - -/** - * Rotate the node with its right child. - * @param node {RBLNode} The node to rotate. - * @return {void} - */ -RBTreeList.prototype.leftRotate = function (node) { - var child = node.right; - node.right = child.left; - if (child.left !== null) - child.left.parent = node; - child.parent = node.parent; - if (node.parent === null) - this.root = child; - else if (node === node.parent.left) - node.parent.left = child; - else - node.parent.right = child; - node.parent = child; - child.left = node; -}; - -/** - * Rotate the node with its left child. - * @param node {RBLNode} The node to rotate. - * @return {void} - */ -RBTreeList.prototype.rightRotate = function (node) { - var child = node.left; - node.left = child.right; - if (child.right !== null) - child.right.parent = node; - child.parent = node.parent; - if (node.parent === null) - this.root = child; - else if (node === node.parent.left) - node.parent.left = child; - else - node.parent.right = child; - node.parent = child; - child.right = node; -}; - -/** - * Returns the size of the tree. - * @return {number} The size of the tree. - */ -RBTreeList.prototype.getSize = function () { - return this.size; -}; - -/** - * Clones the tree into a new tree. - * @return {RBTreeList} The tree cloned from this tree. - */ -RBTreeList.prototype.clone = function () { - var tree = new RBTreeList(); - var it = this.getIterator(); - for (it.first(); !it.isDone(); it.next()) - tree.insert(it.getNode().key, it.getNode().item); - return tree; -}; - -/** - * Clones the tree into a new tree without cloning duplicated items. - * @return {RBTreeList} The tree cloned from this tree. - */ -RBTreeList.prototype.cloneDistinct = function () { - var tree = new RBTreeList(); - var it = this.getIterator(); - for (it.first(); !it.isDone(); it.next()) { - var callback = function (node) { - return node.key === it.getNode().key && node.item === it.getNode().item; - }; - if (!tree.contains(it.getNode().key, callback)) { - if (it.getNode().item.cloneDistinct) - tree.insert(it.getNode().key, it.getNode().item.cloneDistinct()); - else if (it.getNode().item.clone) - tree.insert(it.getNode().key, it.getNode().item.clone()); - else - tree.insert(it.getNode().key, it.getNode().item); - } - } - return tree; -}; - -/** - * Transform the tree into an array without preserving keys. - * @return {Array<*>} The array that represents the tree. - */ -RBTreeList.prototype.toArray = function () { - var result = []; - for (var node = this.first; node; node = node.next) - result.push(node.item); - return result; -}; - -/** - * Removes all the items stored in the tree. - * @return {void} - */ -RBTreeList.prototype.clear = function () { - this.root = null; - this.first = null; - this.last = null; - this.size = 0; -}; - -/** - * Checks if the tree is empty. - * @return {boolean} True if the tree is empty, false otherwise. - */ -RBTreeList.prototype.isEmpty = function () { - return !this.size; -}; - -/** - * Executes the callback function for each item of the tree. - * This method modifies the tree so if you don't need to modify it you must return the same item stored. - * @param callback {function} The function to execute for each item. The function must accept the current item on which execute the function. - * @return {void} - */ -RBTreeList.prototype.execute = function (callback) { - for (var node = this.first; node; node = node.next) - node.item = callback(node.item); -}; - -/** - * Returns the items that satisfy the condition determined by the callback. - * @param callback {function} The function that implements the condition. - * @return {Array<*>} The array that contains the items that satisfy the condition. - */ -RBTreeList.prototype.filter = function (callback) { - var result = []; - for (var node = this.first; node; node = node.next) - if (callback(node.item)) - result.push(node.item); - return result; -}; - -/** - * Returns the first position of the item in the tree. - * @param item {*} The item to search. - * @param [callback = function(item){return(it===item);}] The condition to satisfy. The callback must accept the current item to check. - * @return {number} The first position of the item. - */ -RBTreeList.prototype.indexOf = function (item, callback) { - callback = callback || function (it) { - return it === item; - }; - var i = 0, node = this.first; - while (node) { - if (callback(node.item)) - return i; - node = node.next; - i++; - } - return -1; -}; - -/** - * Returns the last position of the item in the tree. - * @param item {*} The item to search. - * @param [callback = function(item){return(it===item);}] The condition to satisfy. The callback must accept the current item to check. - * @return {number} The last position of the item. - */ -RBTreeList.prototype.lastIndexOf = function (item, callback) { - callback = callback || function (it) { - return it === item; - }; - var i = this.size - 1, node = this.last; - while (node) { - if (callback(node.item)) - return i; - i--; - node = node.previous; - } - return -1; -}; - -/** - * Returns all the position in which the item has been found in the tree. - * @param item {*} The item to search. - * @param [callback = function(item){return(it===item);}] The condition to satisfy. The callback must accept the current item to check. - * @return {Array} The positions in which the item has been found. - */ -RBTreeList.prototype.allIndexesOf = function (item, callback) { - callback = callback || function (it) { - return it === item; - }; - var i = 0, node = this.first; - var indexes = []; - while (node) { - if (callback(node.item)) - indexes.push(i); - i++; - node = node.next; - } - return indexes; -}; - -/** - * Returns the item at the position index. - * @param index {number} The position of the item. - * @return {*} The item at the position. It's undefined if index isn't in the tree bounds. - */ -RBTreeList.prototype.getItem = function (index) { - if (index < 0 || index > this.size - 1) - return undefined; - for (var node = this.first, i = 0; i < index; node = node.next) - i++; - return node.item; -}; \ No newline at end of file diff --git a/lib/RBTreeList/RBTreeListIterator.js b/lib/RBTreeList/RBTreeListIterator.js deleted file mode 100644 index c4cd51c..0000000 --- a/lib/RBTreeList/RBTreeListIterator.js +++ /dev/null @@ -1,75 +0,0 @@ -/** - * Created by Stefano on 06/04/2014. - */ - -RBTreeListIterator.prototype = new Iterator(); -RBTreeListIterator.prototype.constructor = RBTreeListIterator; - -/** - * Class that implements the iterator for a red-black tree. - * @param aggregate {RBTreeList} The aggregate to scan. - * @constructor - */ -function RBTreeListIterator(aggregate) { - /** - * The aggregate relates to this iterator. - * @type {RBTreeList} - */ - this.aggregate = aggregate; - /** - * The pointer to the position. - * @type {RBLNode|null} - */ - this.pointer = null; -} - -/** - * @inheritDoc - */ -RBTreeListIterator.prototype.first = function () { - this.pointer = this.aggregate.first; -}; - -/** - * @inheritDoc - */ -RBTreeListIterator.prototype.next = function () { - this.pointer = this.pointer.next; -}; - -/** - * @inheritDoc - */ -RBTreeListIterator.prototype.last = function () { - this.pointer = this.aggregate.last; -}; - -/** - * @inheritDoc - */ -RBTreeListIterator.prototype.previous = function () { - this.pointer = this.pointer.previous; -}; - -/** - * @inheritDoc - */ -RBTreeListIterator.prototype.isDone = function () { - return !this.pointer; -}; - -/** - * @inheritDoc - */ -RBTreeListIterator.prototype.getItem = function () { - return this.pointer.item; -}; - -/** - * Return the node stored at the position pointed by the iterator. - * @abstract - * @return {RBNode|null} The node stored or null if it's out of the bounds. - */ -RBTreeListIterator.prototype.getNode = function () { - return this.pointer; -}; \ No newline at end of file diff --git a/lib/Range/Range.js b/lib/Range/Range.js deleted file mode 100644 index 80a0892..0000000 --- a/lib/Range/Range.js +++ /dev/null @@ -1,21 +0,0 @@ -/** - * Created by Stefano on 01/02/2015. - */ - -/** - * Create an array containing the value of the range - * @param from {number} The inclusive start value of the range. - * @param to {number} The inclusive end value of the range. - * @param [step=1] The step to sample the values - * @return {Array} The array containing the value of the range. - */ -function Range(from, to, step) { - var range = []; - step = step || 1; - var sign = (step > 0 ? 1 : -1); - - for (var i = 0; from * sign <= to * sign; from += step, ++i) - range[i] = from; - - return range; -} \ No newline at end of file diff --git a/lib/Set/Set.js b/lib/Set/Set.js deleted file mode 100644 index 5a7be32..0000000 --- a/lib/Set/Set.js +++ /dev/null @@ -1,224 +0,0 @@ -/** - * Created by Stefano on 12/04/2014. - */ - -/** - * Class for representing an element of a set. - * @param item {*} The item to store in the element. - * @constructor - */ -function Element(item) { - this.parents = new DoubleLinkedList(); - this.item = item; -} - -/** - * Class for managing a set. - * @constructor - */ -function Set() { - /** - * The parents of the set. - * @type {DoubleLinkedList} - */ - this.parents = new DoubleLinkedList(); - /** - * The elements stored. - * @type {DoubleLinkedList} - */ - this.elements = new DoubleLinkedList(); - /** - * The subsets of this set. - * @type {DoubleLinkedList} - */ - this.sets = new DoubleLinkedList(); - /** - * The size of the set. It's equal to his cardinality. - * @type {number} - */ - this.size = 0; -} - -/** - * Add the element to the set. - * @param element {Element} The element to add. - * @return {void} - */ -Set.prototype.insert = function (element) { - this.elements.pushBack(element); - element.parents.pushBack(this); - this.size++; -}; - -/** - * Add the elements to the set. - * @param elements {Array} The elements to add. - * @return {void} - */ -Set.prototype.multiInsert = function (elements) { - for (var i = 0; i < elements.length; i++) { - this.elements.pushBack(elements[i]); - elements[i].parents.pushBack(this); - } - this.size += elements.length; -}; - -/** - * Returns the set that represents the union of two sets. - * @param set {Set} The set with make the union. - * @return {Set} The set that represents the union. - */ -Set.prototype.union = function (set) { - var parent = new Set(); - parent.addSubsets([this, set]); - this.parents.pushBack(parent); - set.parents.pushBack(parent); - //change the parent of the subset - var that = this; - var f = function (item) { - if (item === that) - return parent; - }; - var it = this.sets.getIterator(); - for (it.first(); !it.isDone(); it.next()) - it.getItem().parents.execute(f); - f = function (item) { - if (item === set) - return parent; - }; - it = set.sets.getIterator(); - for (it.first(); !it.isDone(); it.next()) - it.getItem().parents.execute(f); - return parent; -}; - -/** - * Returns the set that represents the intersection of two sets. - * @param set {Set} The set to intersect with this. - * @return {Set} The set that represents the intersection. - */ -Set.prototype.intersect = function (set) { - var intersection = new Set(); - //intersect this set with the set - var el = this.elements.getIterator(); - for (el.first(); !el.isDone(); el.next()) - if (el.getItem().parents.contains(set)) - intersection.insert(el.getItem()); - - //intersect the subsets with the set - var it = this.sets.getIterator(); - for (it.first(); !it.isDone(); it.next()) { - el = it.getItem().getIterator(); - for (el.first(); !el.isDone(); el.next()) - if (el.getItem().parents.contains(set)) - intersection.insert(el.getItem()); - } - return intersection; -}; - -/** - * Returns the set that represents the difference of two sets. - * @param set {Set} The set to difference with this. - * @return {Set} The set that represents the difference. - */ -Set.prototype.difference = function (set) { - var diff = new Set(); - //intersect this set with the set - var el = this.elements.getIterator(); - for (el.first(); !el.isDone(); el.next()) - if (!el.getItem().parents.contains(set)) - diff.insert(el.getItem()); - - //intersect the subsets with the set - var it = this.sets.getIterator(); - for (it.first(); !it.isDone(); it.next()) { - el = it.getItem().getIterator(); - for (el.first(); !el.isDone(); el.next()) - if (!el.getItem().parents.contains(set)) - diff.insert(el.getItem()); - } - return diff; -}; - -/** - * Returns the set that represents the cartesian product of two sets. - * @param set {Set} The set to make the cartesian product with this. - * @return {Set} The set that represents the cartesian product . - */ -Set.prototype.cartesianProduct = function (set) { - var el1 = this.getItems(); - var el2 = set.getItems(); - var product = new Set(); - for (var i = 0; i < el1.length; i++) - for (var j = 0; j < el2.length; j++) - product.insert(new Element([el1[i], el2[j]])); - return product; -}; - -/** - * Add the subset. - * @param set {Set} The subset. - */ -Set.prototype.addSubset = function (set) { - this.sets.pushBack(set); - this.size += set.size; -}; - -/** - * Add the subsets. - * @param sets {Array} The subsets. - */ -Set.prototype.addSubsets = function (sets) { - for (var i = 0; i < sets.length; i++) - this.addSubset(sets[i]); -}; - -/** - * Returns the items that are stored in the set. - * @return {Array} The items stored. - */ -Set.prototype.getItems = function () { - var array = []; - //get the items stored in the set - var el = this.elements.getIterator(); - for (el.first(); !el.isDone(); el.next()) - array.push(el.getItem().item); - - //get the items stored in the subsets - var it = this.sets.getIterator(); - for (it.first(); !it.isDone(); it.next()) { - el = it.getItem().getIterator(); - for (el.first(); !el.isDone(); el.next()) - array.push(el.getItem().item); - } - return array; -}; - -/** - * Returns the cardinality of the set. - * @return {number} The cardinality of the set. - */ -Set.prototype.getCardinality = function () { - return this.size; -}; - -/** - * Checks if the set is empty. - * @return {boolean} True if the set is empty, false otherwise. - */ -Set.prototype.isEmpty = function () { - return !this.size; -}; - -/** - * Clones the set into a new set. - * @return {Set} The set cloned from this set. - */ -Set.prototype.clone = function () { - var s = new Set(); - s.parents = this.parents.clone(); - s.elements = this.elements.clone(); - s.sets = this.sets.clone(); - s.size = this.size; - return s; -}; \ No newline at end of file diff --git a/lib/Stack/Stack.js b/lib/Stack/Stack.js deleted file mode 100644 index 6798b14..0000000 --- a/lib/Stack/Stack.js +++ /dev/null @@ -1,251 +0,0 @@ -/** - * Created by Battistella Stefano on 31/03/14. - */ - -Stack.prototype = new Aggregate(); -Stack.prototype.constructor = Stack; - -/** - * Class for managing a stack. - * @param {...*} [args] The items for initializing the stack. - * @constructor - */ -function Stack(args) { - /** - * The list of the items in the stack. - * @type {Array<*>} - */ - this.items = []; - - if(args && args.length) { - //builds the stack from the range passed from the constructor - this.multiPush(args); - } else { - //builds the stack from the parameters of the constructor - this.multiPush(arguments); - } -} - -/** - * @inheritDoc - */ -Stack.prototype.getIterator = function () { - return new StackIterator(this); -}; - -/** - * Adds the item at the top of the stack. - * @param item {*} The item to add. - * return {void} - */ -Stack.prototype.push = function (item) { - this.items.push(item); -}; - -/** - * Adds the items at the top of the stack. - * @param items {Array<*>} The items to add. - * @return {void} - */ -Stack.prototype.multiPush = function (items) { - for (var i = 0; i < items.length; i++) - this.push(items[i]); -}; - -/** - * Removes the item at the top of the stack. - * @return {*} The item at the top of the stack. It's undefined if the stack is empty. - */ -Stack.prototype.pop = function () { - if (!this.items.length) - return undefined; - return this.items.pop(); -}; - -/** - * Removes the more item at the top of the stack. - * @param times {number} The number of times to repeat the pop method. - * @return {Array<*>} The items at the top of the stack. - */ -Stack.prototype.multiPop = function (times) { - var result = []; - for (var i = 0; i < times && this.items.length; i++) - result.push(this.pop()); - return result; -}; - -/** - * Returns the item at the top of the stack without remove it. - * @return {*} The item at the top of the stack. It's undefined if the stack is empty. - */ -Stack.prototype.peek = function () { - if (!this.items.length) - return undefined; - return this.items[this.items.length - 1]; -}; - -/** - * Removes all the items stored in the stack. - * @return {void} - */ -Stack.prototype.clear = function () { - this.items = []; -}; - -/** - * Checks if the stack contains an item that satisfy the condition represented by the callback function. - * @param item {*} The item to find. - * @param [callback = function(item){return(it===item);}] The condition to satisfy. The callback must accept the current item to check. - * @return {boolean} True if the stack contains the item that satisfy the condition, false otherwise. - */ -Stack.prototype.contains = function (item, callback) { - callback = callback || function (it) { - return it === item; - }; - var i = 0; - while (i < this.items.length && !callback(this.items[i])) - i++; - return i < this.items.length; -}; - -/** - * Executes the callback function for each item of the stack. - * This method modifies the stack so if you don't need to modify it you must return the same item of the array. - * @param callback {function} The function to execute for each item. The function must accept the current item on which execute the function. - * @return {void} - */ -Stack.prototype.execute = function (callback) { - for (var i = this.items.length - 1; i > -1; i--) - this.items[i] = callback(this.items[i]); -}; - -/** - * Returns the item at the position index. - * @param index The position of the item. - * @return {*} The item at the position. It's undefined if index isn't in the stack bounds. - */ -Stack.prototype.getItem = function (index) { - if (index < 0 || index > this.items.length - 1) - return undefined; - return this.items[this.items.length - index - 1]; -}; - -/** - * Returns the length of the stack. - * @return {Number} The length of the stack. - */ -Stack.prototype.getLength = function () { - return this.items.length; -}; - -/** - * Checks if the stack is empty. - * @return {boolean} True if the stack is empty, false otherwise. - */ -Stack.prototype.isEmpty = function () { - return !this.items.length; -}; - -/** - * Returns the items that satisfy the condition determined by the callback. - * @param callback {function} The function that implements the condition. - * @return {Array<*>} The array that contains the items that satisfy the condition. - */ -Stack.prototype.filter = function (callback) { - var result = []; - for (var i = this.items.length - 1; i > -1; i--) { - if (callback(this.items[i])) - result.push(this.items[i]); - } - return result; -}; - -/** - * Returns the first position of the item in the stack. - * @param item {*} The item to search. - * @param [callback = function(item){return(it===item);}] The condition to satisfy. The callback must accept the current item to check. - * @return {number} The first position of the item. - */ -Stack.prototype.indexOf = function (item, callback) { - callback = callback || function (it) { - return it === item; - }; - var i = this.items.length - 1; - while (i > -1) { - if (callback(this.items[i])) - return i; - i--; - } - return -1; -}; - -/** - * Returns the last position of the item in the stack. - * @param item {*} The item to search. - * @param [callback = function(item){return(it===item);}] The condition to satisfy. The callback must accept the current item to check. - * @return {number} The last position of the item. - */ -Stack.prototype.lastIndexOf = function (item, callback) { - callback = callback || function (it) { - return it === item; - }; - var i = 0; - while (i < this.items.length) { - if (callback(this.items[i])) - return i; - i++; - } - return -1; -}; - -/** - * Returns all the position in which the item has been found in the stack. - * @param item {*} The item to search. - * @param [callback = function(item){return(it===item);}] The condition to satisfy. The callback must accept the current item to check. - * @return {Array} The positions in which the item has been found. - */ -Stack.prototype.allIndexesOf = function (item, callback) { - callback = callback || function (it) { - return it === item; - }; - var i = this.items.length - 1; - var indexes = []; - while (i > -1) { - if (callback(this.items[i])) - indexes.push(i); - i--; - } - return indexes; -}; - -/** - * Clones the stack into a new stack. - * @return {Stack} The stack cloned from this stack. - */ -Stack.prototype.clone = function () { - var stack = new Stack(); - for (var i = 0; i < this.items.length; i++) - if (this.items[i].clone) - stack.push(this.items[i].clone()); - else - stack.push(this.items[i]); - return stack; -}; - -/** - * Clones the stack into a new stack without cloning duplicated items. - * @return {Stack} The stack cloned from this stack. - */ -Stack.prototype.cloneDistinct = function () { - var stack = new Stack(); - for (var i = 0; i < this.items.length; i++) - if (!stack.contains(this.items[i])) { - if (this.items[i].cloneDistinct) - stack.push(this.items[i].cloneDistinct()); - else if (this.items[i].clone) - stack.push(this.items[i].clone()); - else - stack.push(this.items[i]); - } - return stack; -}; \ No newline at end of file diff --git a/lib/Stack/StackIterator.js b/lib/Stack/StackIterator.js deleted file mode 100644 index c59d146..0000000 --- a/lib/Stack/StackIterator.js +++ /dev/null @@ -1,67 +0,0 @@ -/** - * Created by Stefano on 04/04/2014. - */ - -StackIterator.prototype = new Iterator(); -StackIterator.prototype.constructor = StackIterator; - -/** - * Class that implements the iterator for a linked list. - * @param aggregate {Stack} The aggregate to scan. - * @constructor - */ -function StackIterator(aggregate) { - /** - * The aggregate relates to this iterator. - * @type {Stack} - */ - this.aggregate = aggregate; - - /** - * The pointer to the position. - * @type {number} - */ - this.pointer = -1; -} - -/** - * @inheritDoc - */ -StackIterator.prototype.first = function () { - this.pointer = this.aggregate.items.length - 1; -}; - -/** - * @inheritDoc - */ -StackIterator.prototype.next = function () { - this.pointer--; -}; - -/** - * @inheritDoc - */ -StackIterator.prototype.last = function () { - this.pointer = 0; -}; - -/** - * @inheritDoc - */ -StackIterator.prototype.previous = function () { - this.pointer++; -}; - -/** - * @inheritDoc - */ -StackIterator.prototype.isDone = function () { - return this.pointer < 0 || this.pointer > this.aggregate.items.length - 1; -}; - -/** - * @inheritDoc - */ -StackIterator.prototype.getItem = function () { - return this.aggregate.items[this.pointer]; -}; \ No newline at end of file diff --git a/lib/Trie/Trie.js b/lib/Trie/Trie.js deleted file mode 100644 index 730fee2..0000000 --- a/lib/Trie/Trie.js +++ /dev/null @@ -1,202 +0,0 @@ -/** - * Created by Stefano on 02/02/2015. - */ - -/** - * The single node of the tree. - * @param [string = null] The string of the node. - * @param [item = null] The item to store in the node. - * @constructor - */ -function TNode(string, item) { - /** - * The item stored. - * @type {*|null} - */ - this.item = item || null; - /** - * The key of the node. - * @type {string|null} - */ - this.string = string || null; - /** - * The parent node. It's null if there's no a parent node. - * @type {TNode|null} - */ - this.parent = null; - /** - * The children of the node. - * @type {Array} - */ - this.childs = []; -} - -Trie.prototype = new Aggregate(); -Trie.prototype.constructor = Trie; - -/** - * Class for managing a trie - * @constructor - */ -function Trie() { - /** - * The root of the trie. - * @type {TNode} - */ - this.root = new TNode(''); - - /** - * The size of the trie - * @type {number} - */ - this.size = 0; -} - -/** - * @inheritDoc - */ -Trie.prototype.getIterator = function () { - return new TrieIterator(this); -}; - -/** - * Insert the string in the tree creating the relative path to it. - * If the string already exists then the values are updated - * @param string {string} The string to store. - * @param [item = null] The item to store. - * @return {void} - */ -Trie.prototype.insert = function (string, item) { - var node = this.root; - - var i = 0; - while (i < string.length && node.childs[string.charCodeAt(i)]) { - node = node.childs[string.charCodeAt(i)]; - ++i; - } - - while (i < string.length) { - node.childs[string.charCodeAt(i)] = new TNode(); - node = node.childs[string.charCodeAt(i)]; - ++i; - } - - if (node.string != string) - ++this.size; - - node.string = string; - node.item = item; -}; - -/** - * Suggest the possible conclusion for the string. - * @param string {string} The start of the string. - * @return {Array} The array of possible string conclusion to fill. - */ -Trie.prototype.suggest = function (string) { - var node = this.root; - - for (var i = 0; i < string.length && node; ++i) { - node = node.childs[string.charCodeAt(i)]; - } - - var results = []; - if (node) { - this.stringsToArray(results, node); - } - return results; -}; - -/** - * Return all the string saved under the node in the array. - * @param result {Array} The array to fill. - * @param [node {TNode|null} = null] The node from which start searching the strings. - * @return {void} - */ -Trie.prototype.stringsToArray = function (result, node) { - node = node || this.root; - - - if (node.string) { - result.push(node.string); - } - - for (var key in node.childs) { - if (key !== 'length' && node.childs.hasOwnProperty(key)) { - this.stringsToArray(result, node.childs[key]); - } - } -}; - -/** - * Update the item related to the string searched. - * @param string {string} The string for finding the item. - * @param callback {function} The function to execute to update the item. It should accept the item the iteration is working on. - * @return {void} - */ -Trie.prototype.updateItem = function (string, callback) { - var node = this.root; - - var i = 0; - while (i < string.length && node.childs[string.charCodeAt(i)]) { - node = node.childs[string.charCodeAt(i)]; - ++i; - } - - // Update the value only if the node reached correspond to the string - if (node && node.string == string) { - node.item = callback(node.item); - } -}; - -/** - * Return the item related to the string searched. - * @param string {string} The string for finding the item. - * @returns {*} The item found. Undefined if the string is not in the trie - */ -Trie.prototype.getItem = function (string) { - var node = this.root; - - var i = 0; - while (i < string.length && node.childs[string.charCodeAt(i)]) { - node = node.childs[string.charCodeAt(i)]; - ++i; - } - - // Return the value only if the node reached correspond to the string - if (node && node.string == string) { - return node.item; - } - - return undefined; -}; - -/** - * Return the size of the trie. - * @returns {number} The size of the tree. - */ -Trie.prototype.getSize = function() { - return this.size; -}; - -/** - * Get the minimum string stored in the tree. - * @param [node = root] {Node} The node from which start the search. - * @return {string} The string found. - */ -Trie.prototype.minimum = function (node) { - node = node || this.root; - return node.string; -}; - -/** - * Get the maximum string stored in the tree. - * @param [node = root] {Node} The node from which start the search. - * @return {string} The string found. - */ -Trie.prototype.maximum = function (node) { - node = node || this.root; - while (node && node.childs[node.childs.length - 1]) - node = node.childs[node.childs.length - 1]; - return node.string; -}; \ No newline at end of file diff --git a/lib/Trie/TrieIterator.js b/lib/Trie/TrieIterator.js deleted file mode 100644 index bb30449..0000000 --- a/lib/Trie/TrieIterator.js +++ /dev/null @@ -1,67 +0,0 @@ -/** - * Created by Stefano on 06/04/2014. - */ - -TrieIterator.prototype = new Iterator(); -TrieIterator.prototype.constructor = TrieIterator; - -/** - * Class that implements the iterator for a trie. - * @param aggregate {Trie} The aggregate to scan. - * @constructor - */ -function TrieIterator(aggregate) { - /** - * The aggregate relates to this iterator. - * @type {Trie} - */ - this.aggregate = aggregate; - - /** - * The pointer to the position. - * @type {TNode|null} - */ - this.pointer = null; -} - -/** - * @inheritDoc - */ -TrieIterator.prototype.first = function () { - this.pointer = this.aggregate.minimum(); -}; - -/** - * @inheritDoc - */ -TrieIterator.prototype.next = function () { - this.pointer = this.aggregate.successor(this.pointer); -}; - -/** - * @inheritDoc - */ -TrieIterator.prototype.last = function () { - this.pointer = this.aggregate.maximum(); -}; - -/** - * @inheritDoc - */ -TrieIterator.prototype.previous = function () { - this.pointer = this.aggregate.predecessor(this.pointer); -}; - -/** - * @inheritDoc - */ -TrieIterator.prototype.isDone = function () { - return !this.pointer; -}; - -/** - * @inheritDoc - */ -TrieIterator.prototype.getItem = function () { - return this.pointer.item; -}; \ No newline at end of file diff --git a/params.json b/params.json new file mode 100644 index 0000000..1c6b374 --- /dev/null +++ b/params.json @@ -0,0 +1 @@ +{"name":"Javascript-data-structures","tagline":"A library for data structure in JavaScript","body":"[Data Structures](https://github.com/Bishop92/JavaScript-Data-Structures)\r\n=================\r\n**A library for data structures in JavaScript**\r\n\r\nDataStructures is a JavaScript library where you can find the most common data structures and also other data\r\nstructures more advanced. Various method are also provided in order to manipulate data structures.\r\n\r\nThis library implements the [iterator] (http://en.wikipedia.org/wiki/Iterator_pattern) pattern in order to hide\r\nthe data structure that work for storing your data.\r\n\r\nSupported data structures\r\n-------------------------\r\n- [Stack](https://rawgit.com/Bishop92/JavaScript-Data-Structures/master/doc/symbols/Stack.html)\r\n- [Queue](https://rawgit.com/Bishop92/JavaScript-Data-Structures/master/doc/symbols/Queue.html)\r\n- [Priority Queue](https://rawgit.com/Bishop92/JavaScript-Data-Structures/master/doc/symbols/PriorityQueue.html)\r\n- [Circular Buffer](https://rawgit.com/Bishop92/JavaScript-Data-Structures/master/doc/symbols/CircularBuffer.html)\r\n- [Hash Table](https://rawgit.com/Bishop92/JavaScript-Data-Structures/master/doc/symbols/HashTable.html)\r\n- [Linked List](https://rawgit.com/Bishop92/JavaScript-Data-Structures/master/doc/symbols/LinkedList.html)\r\n- [Double Linked List](https://rawgit.com/Bishop92/JavaScript-Data-Structures/master/doc/symbols/DoubleLinkedList.html)\r\n- [Binary Search Tree](https://rawgit.com/Bishop92/JavaScript-Data-Structures/master/doc/symbols/BSTree.html)\r\n- [Red-Black Tree](https://rawgit.com/Bishop92/JavaScript-Data-Structures/master/doc/symbols/RBTree.html)\r\n- [Red-Black Tree List](https://rawgit.com/Bishop92/JavaScript-Data-Structures/master/doc/symbols/RBTreeList.html)\r\n- [B-Tree](https://rawgit.com/Bishop92/JavaScript-Data-Structures/master/doc/symbols/BTree.html)\r\n- [Set](https://rawgit.com/Bishop92/JavaScript-Data-Structures/master/doc/symbols/Set.html)\r\n\r\nHow to use\r\n----------\r\n1. Download the minimized library [here](https://raw.githubusercontent.com/Bishop92/JavaScript-Data-Structures/master/DataStructuresMinimized.js) (right click and save as...);\r\n\r\n2. Include the file in your project;\r\n\r\n3. Start to use it as any other class.\r\n\r\nExample\r\n\r\n```JavaScript\r\nvar listA = new DoubleLinkedList();\r\nvar listB = new DoubleLinkedList();\r\nlistA.fromArray([0, 1]);\r\nlistB.fromArray([2, 3]);\r\nlistA.join(listB);\r\nlistA.toArray(); // [0, 1, 2, 3]\r\n```\r\n\r\nDocumentation\r\n-------------\r\nFollow this [link](https://github.com/Bishop92/JavaScript-Data-Structures/wiki) to read the full documentation.\r\nFollow this [link](https://rawgit.com/Bishop92/JavaScript-Data-Structures/master/doc/index.html) to read the JSDoc.\r\n\r\nHistory\r\n-------\r\n\r\n### Future implementations\r\n\r\n- Persistence for data structures like array and lists.\r\n\r\n### Current state of the art\r\n- v 1.0.0 First release of the library.\r\n\r\nSupport\r\n-------\r\nBattistella Stefano, [stefano.battistella.92@gmail.com](mailto:stefano.battistella.92@gmail.com)","google":"","note":"Don't delete this file! It's used internally to help with page regeneration."} \ No newline at end of file diff --git a/stylesheets/ie.css b/stylesheets/ie.css new file mode 100644 index 0000000..43882f2 --- /dev/null +++ b/stylesheets/ie.css @@ -0,0 +1,3 @@ +nav { + display: none; +} diff --git a/stylesheets/normalize.css b/stylesheets/normalize.css new file mode 100644 index 0000000..bc2ba93 --- /dev/null +++ b/stylesheets/normalize.css @@ -0,0 +1,459 @@ +/* normalize.css 2012-02-07T12:37 UTC - http://github.com/necolas/normalize.css */ +/* ============================================================================= + HTML5 display definitions + ========================================================================== */ +/* + * Corrects block display not defined in IE6/7/8/9 & FF3 + */ +article, +aside, +details, +figcaption, +figure, +footer, +header, +hgroup, +nav, +section, +summary { + display: block; +} + +/* + * Corrects inline-block display not defined in IE6/7/8/9 & FF3 + */ +audio, +canvas, +video { + display: inline-block; + *display: inline; + *zoom: 1; +} + +/* + * Prevents modern browsers from displaying 'audio' without controls + */ +audio:not([controls]) { + display: none; +} + +/* + * Addresses styling for 'hidden' attribute not present in IE7/8/9, FF3, S4 + * Known issue: no IE6 support + */ +[hidden] { + display: none; +} + +/* ============================================================================= + Base + ========================================================================== */ +/* + * 1. Corrects text resizing oddly in IE6/7 when body font-size is set using em units + * http://clagnut.com/blog/348/#c790 + * 2. Prevents iOS text size adjust after orientation change, without disabling user zoom + * www.456bereastreet.com/archive/201012/controlling_text_size_in_safari_for_ios_without_disabling_user_zoom/ + */ +html { + font-size: 100%; + /* 1 */ + -webkit-text-size-adjust: 100%; + /* 2 */ + -ms-text-size-adjust: 100%; + /* 2 */ +} + +/* + * Addresses font-family inconsistency between 'textarea' and other form elements. + */ +html, +button, +input, +select, +textarea { + font-family: sans-serif; +} + +/* + * Addresses margins handled incorrectly in IE6/7 + */ +body { + margin: 0; +} + +/* ============================================================================= + Links + ========================================================================== */ +/* + * Addresses outline displayed oddly in Chrome + */ +a:focus { + outline: thin dotted; +} + +/* + * Improves readability when focused and also mouse hovered in all browsers + * people.opera.com/patrickl/experiments/keyboard/test + */ +a:hover, +a:active { + outline: 0; +} + +/* ============================================================================= + Typography + ========================================================================== */ +/* + * Addresses font sizes and margins set differently in IE6/7 + * Addresses font sizes within 'section' and 'article' in FF4+, Chrome, S5 + */ +h1 { + font-size: 2em; + margin: 0.67em 0; +} + +h2 { + font-size: 1.5em; + margin: 0.83em 0; +} + +h3 { + font-size: 1.17em; + margin: 1em 0; +} + +h4 { + font-size: 1em; + margin: 1.33em 0; +} + +h5 { + font-size: 0.83em; + margin: 1.67em 0; +} + +h6 { + font-size: 0.75em; + margin: 2.33em 0; +} + +/* + * Addresses styling not present in IE7/8/9, S5, Chrome + */ +abbr[title] { + border-bottom: 1px dotted; +} + +/* + * Addresses style set to 'bolder' in FF3+, S4/5, Chrome +*/ +b, +strong { + font-weight: bold; +} + +blockquote { + margin: 1em 40px; +} + +/* + * Addresses styling not present in S5, Chrome + */ +dfn { + font-style: italic; +} + +/* + * Addresses styling not present in IE6/7/8/9 + */ +mark { + background: #ff0; + color: #000; +} + +/* + * Addresses margins set differently in IE6/7 + */ +p, +pre { + margin: 1em 0; +} + +/* + * Corrects font family set oddly in IE6, S4/5, Chrome + * en.wikipedia.org/wiki/User:Davidgothberg/Test59 + */ +pre, +code, +kbd, +samp { + font-family: monospace, serif; + _font-family: 'courier new', monospace; + font-size: 1em; +} + +/* + * 1. Addresses CSS quotes not supported in IE6/7 + * 2. Addresses quote property not supported in S4 + */ +/* 1 */ +q { + quotes: none; +} + +/* 2 */ +q:before, +q:after { + content: ''; + content: none; +} + +small { + font-size: 75%; +} + +/* + * Prevents sub and sup affecting line-height in all browsers + * gist.github.com/413930 + */ +sub, +sup { + font-size: 75%; + line-height: 0; + position: relative; + vertical-align: baseline; +} + +sup { + top: -0.5em; +} + +sub { + bottom: -0.25em; +} + +/* ============================================================================= + Lists + ========================================================================== */ +/* + * Addresses margins set differently in IE6/7 + */ +dl, +menu, +ol, +ul { + margin: 1em 0; +} + +dd { + margin: 0 0 0 40px; +} + +/* + * Addresses paddings set differently in IE6/7 + */ +menu, +ol, +ul { + padding: 0 0 0 40px; +} + +/* + * Corrects list images handled incorrectly in IE7 + */ +nav ul, +nav ol { + list-style: none; + list-style-image: none; +} + +/* ============================================================================= + Embedded content + ========================================================================== */ +/* + * 1. Removes border when inside 'a' element in IE6/7/8/9, FF3 + * 2. Improves image quality when scaled in IE7 + * code.flickr.com/blog/2008/11/12/on-ui-quality-the-little-things-client-side-image-resizing/ + */ +img { + border: 0; + /* 1 */ + -ms-interpolation-mode: bicubic; + /* 2 */ +} + +/* + * Corrects overflow displayed oddly in IE9 + */ +svg:not(:root) { + overflow: hidden; +} + +/* ============================================================================= + Figures + ========================================================================== */ +/* + * Addresses margin not present in IE6/7/8/9, S5, O11 + */ +figure { + margin: 0; +} + +/* ============================================================================= + Forms + ========================================================================== */ +/* + * Corrects margin displayed oddly in IE6/7 + */ +form { + margin: 0; +} + +/* + * Define consistent border, margin, and padding + */ +fieldset { + border: 1px solid #c0c0c0; + margin: 0 2px; + padding: 0.35em 0.625em 0.75em; +} + +/* + * 1. Corrects color not being inherited in IE6/7/8/9 + * 2. Corrects text not wrapping in FF3 + * 3. Corrects alignment displayed oddly in IE6/7 + */ +legend { + border: 0; + /* 1 */ + padding: 0; + white-space: normal; + /* 2 */ + *margin-left: -7px; + /* 3 */ +} + +/* + * 1. Corrects font size not being inherited in all browsers + * 2. Addresses margins set differently in IE6/7, FF3+, S5, Chrome + * 3. Improves appearance and consistency in all browsers + */ +button, +input, +select, +textarea { + font-size: 100%; + /* 1 */ + margin: 0; + /* 2 */ + vertical-align: baseline; + /* 3 */ + *vertical-align: middle; + /* 3 */ +} + +/* + * Addresses FF3/4 setting line-height on 'input' using !important in the UA stylesheet + */ +button, +input { + line-height: normal; + /* 1 */ +} + +/* + * 1. Improves usability and consistency of cursor style between image-type 'input' and others + * 2. Corrects inability to style clickable 'input' types in iOS + * 3. Removes inner spacing in IE7 without affecting normal text inputs + * Known issue: inner spacing remains in IE6 + */ +button, +input[type="button"], +input[type="reset"], +input[type="submit"] { + cursor: pointer; + /* 1 */ + -webkit-appearance: button; + /* 2 */ + *overflow: visible; + /* 3 */ +} + +/* + * Re-set default cursor for disabled elements + */ +button[disabled], +input[disabled] { + cursor: default; +} + +/* + * 1. Addresses box sizing set to content-box in IE8/9 + * 2. Removes excess padding in IE8/9 + * 3. Removes excess padding in IE7 + Known issue: excess padding remains in IE6 + */ +input[type="checkbox"], +input[type="radio"] { + box-sizing: border-box; + /* 1 */ + padding: 0; + /* 2 */ + *height: 13px; + /* 3 */ + *width: 13px; + /* 3 */ +} + +/* + * 1. Addresses appearance set to searchfield in S5, Chrome + * 2. Addresses box-sizing set to border-box in S5, Chrome (include -moz to future-proof) + */ +input[type="search"] { + -webkit-appearance: textfield; + /* 1 */ + -moz-box-sizing: content-box; + -webkit-box-sizing: content-box; + /* 2 */ + box-sizing: content-box; +} + +/* + * Removes inner padding and search cancel button in S5, Chrome on OS X + */ +input[type="search"]::-webkit-search-decoration, +input[type="search"]::-webkit-search-cancel-button { + -webkit-appearance: none; +} + +/* + * Removes inner padding and border in FF3+ + * www.sitepen.com/blog/2008/05/14/the-devils-in-the-details-fixing-dojos-toolbar-buttons/ + */ +button::-moz-focus-inner, +input::-moz-focus-inner { + border: 0; + padding: 0; +} + +/* + * 1. Removes default vertical scrollbar in IE6/7/8/9 + * 2. Improves readability and alignment in all browsers + */ +textarea { + overflow: auto; + /* 1 */ + vertical-align: top; + /* 2 */ +} + +/* ============================================================================= + Tables + ========================================================================== */ +/* + * Remove most spacing between table cells + */ +table { + border-collapse: collapse; + border-spacing: 0; +} diff --git a/stylesheets/pygment_trac.css b/stylesheets/pygment_trac.css new file mode 100644 index 0000000..c79bef4 --- /dev/null +++ b/stylesheets/pygment_trac.css @@ -0,0 +1,70 @@ +.highlight .hll { background-color: #404040 } +.highlight { color: #d0d0d0 } +.highlight .c { color: #999999; font-style: italic } /* Comment */ +.highlight .err { color: #a61717; background-color: #e3d2d2 } /* Error */ +.highlight .g { color: #d0d0d0 } /* Generic */ +.highlight .k { color: #6ab825; font-weight: normal } /* Keyword */ +.highlight .l { color: #d0d0d0 } /* Literal */ +.highlight .n { color: #d0d0d0 } /* Name */ +.highlight .o { color: #d0d0d0 } /* Operator */ +.highlight .x { color: #d0d0d0 } /* Other */ +.highlight .p { color: #d0d0d0 } /* Punctuation */ +.highlight .cm { color: #999999; font-style: italic } /* Comment.Multiline */ +.highlight .cp { color: #cd2828; font-weight: normal } /* Comment.Preproc */ +.highlight .c1 { color: #999999; font-style: italic } /* Comment.Single */ +.highlight .cs { color: #e50808; font-weight: normal; background-color: #520000 } /* Comment.Special */ +.highlight .gd { color: #d22323 } /* Generic.Deleted */ +.highlight .ge { color: #d0d0d0; font-style: italic } /* Generic.Emph */ +.highlight .gr { color: #d22323 } /* Generic.Error */ +.highlight .gh { color: #ffffff; font-weight: normal } /* Generic.Heading */ +.highlight .gi { color: #589819 } /* Generic.Inserted */ +.highlight .go { color: #cccccc } /* Generic.Output */ +.highlight .gp { color: #aaaaaa } /* Generic.Prompt */ +.highlight .gs { color: #d0d0d0; font-weight: normal } /* Generic.Strong */ +.highlight .gu { color: #ffffff; text-decoration: underline } /* Generic.Subheading */ +.highlight .gt { color: #d22323 } /* Generic.Traceback */ +.highlight .kc { color: #6ab825; font-weight: normal } /* Keyword.Constant */ +.highlight .kd { color: #6ab825; font-weight: normal } /* Keyword.Declaration */ +.highlight .kn { color: #6ab825; font-weight: normal } /* Keyword.Namespace */ +.highlight .kp { color: #6ab825 } /* Keyword.Pseudo */ +.highlight .kr { color: #6ab825; font-weight: normal } /* Keyword.Reserved */ +.highlight .kt { color: #6ab825; font-weight: normal } /* Keyword.Type */ +.highlight .ld { color: #d0d0d0 } /* Literal.Date */ +.highlight .m { color: #3677a9 } /* Literal.Number */ +.highlight .s { color: #9dd5f1 } /* Literal.String */ +.highlight .na { color: #bbbbbb } /* Name.Attribute */ +.highlight .nb { color: #24909d } /* Name.Builtin */ +.highlight .nc { color: #447fcf; text-decoration: underline } /* Name.Class */ +.highlight .no { color: #40ffff } /* Name.Constant */ +.highlight .nd { color: #ffa500 } /* Name.Decorator */ +.highlight .ni { color: #d0d0d0 } /* Name.Entity */ +.highlight .ne { color: #bbbbbb } /* Name.Exception */ +.highlight .nf { color: #447fcf } /* Name.Function */ +.highlight .nl { color: #d0d0d0 } /* Name.Label */ +.highlight .nn { color: #447fcf; text-decoration: underline } /* Name.Namespace */ +.highlight .nx { color: #d0d0d0 } /* Name.Other */ +.highlight .py { color: #d0d0d0 } /* Name.Property */ +.highlight .nt { color: #6ab825;} /* Name.Tag */ +.highlight .nv { color: #40ffff } /* Name.Variable */ +.highlight .ow { color: #6ab825; font-weight: normal } /* Operator.Word */ +.highlight .w { color: #666666 } /* Text.Whitespace */ +.highlight .mf { color: #3677a9 } /* Literal.Number.Float */ +.highlight .mh { color: #3677a9 } /* Literal.Number.Hex */ +.highlight .mi { color: #3677a9 } /* Literal.Number.Integer */ +.highlight .mo { color: #3677a9 } /* Literal.Number.Oct */ +.highlight .sb { color: #9dd5f1 } /* Literal.String.Backtick */ +.highlight .sc { color: #9dd5f1 } /* Literal.String.Char */ +.highlight .sd { color: #9dd5f1 } /* Literal.String.Doc */ +.highlight .s2 { color: #9dd5f1 } /* Literal.String.Double */ +.highlight .se { color: #9dd5f1 } /* Literal.String.Escape */ +.highlight .sh { color: #9dd5f1 } /* Literal.String.Heredoc */ +.highlight .si { color: #9dd5f1 } /* Literal.String.Interpol */ +.highlight .sx { color: #ffa500 } /* Literal.String.Other */ +.highlight .sr { color: #9dd5f1 } /* Literal.String.Regex */ +.highlight .s1 { color: #9dd5f1 } /* Literal.String.Single */ +.highlight .ss { color: #9dd5f1 } /* Literal.String.Symbol */ +.highlight .bp { color: #24909d } /* Name.Builtin.Pseudo */ +.highlight .vc { color: #40ffff } /* Name.Variable.Class */ +.highlight .vg { color: #40ffff } /* Name.Variable.Global */ +.highlight .vi { color: #40ffff } /* Name.Variable.Instance */ +.highlight .il { color: #3677a9 } /* Literal.Number.Integer.Long */ \ No newline at end of file diff --git a/stylesheets/styles.css b/stylesheets/styles.css new file mode 100644 index 0000000..e7b4ffc --- /dev/null +++ b/stylesheets/styles.css @@ -0,0 +1,851 @@ +@font-face { + font-family: 'OpenSansLight'; + src: url("../fonts/OpenSans-Light-webfont.eot"); + src: url("../fonts/OpenSans-Light-webfont.eot?#iefix") format("embedded-opentype"), url("../fonts/OpenSans-Light-webfont.woff") format("woff"), url("../fonts/OpenSans-Light-webfont.ttf") format("truetype"), url("../fonts/OpenSans-Light-webfont.svg#OpenSansLight") format("svg"); + font-weight: normal; + font-style: normal; +} + +@font-face { + font-family: 'OpenSansLightItalic'; + src: url("../fonts/OpenSans-LightItalic-webfont.eot"); + src: url("../fonts/OpenSans-LightItalic-webfont.eot?#iefix") format("embedded-opentype"), url("../fonts/OpenSans-LightItalic-webfont.woff") format("woff"), url("../fonts/OpenSans-LightItalic-webfont.ttf") format("truetype"), url("../fonts/OpenSans-LightItalic-webfont.svg#OpenSansLightItalic") format("svg"); + font-weight: normal; + font-style: normal; +} + +@font-face { + font-family: 'OpenSansRegular'; + src: url("../fonts/OpenSans-Regular-webfont.eot"); + src: url("../fonts/OpenSans-Regular-webfont.eot?#iefix") format("embedded-opentype"), url("../fonts/OpenSans-Regular-webfont.woff") format("woff"), url("../fonts/OpenSans-Regular-webfont.ttf") format("truetype"), url("../fonts/OpenSans-Regular-webfont.svg#OpenSansRegular") format("svg"); + font-weight: normal; + font-style: normal; + -webkit-font-smoothing: antialiased; +} + +@font-face { + font-family: 'OpenSansItalic'; + src: url("../fonts/OpenSans-Italic-webfont.eot"); + src: url("../fonts/OpenSans-Italic-webfont.eot?#iefix") format("embedded-opentype"), url("../fonts/OpenSans-Italic-webfont.woff") format("woff"), url("../fonts/OpenSans-Italic-webfont.ttf") format("truetype"), url("../fonts/OpenSans-Italic-webfont.svg#OpenSansItalic") format("svg"); + font-weight: normal; + font-style: normal; + -webkit-font-smoothing: antialiased; +} + +@font-face { + font-family: 'OpenSansSemibold'; + src: url("../fonts/OpenSans-Semibold-webfont.eot"); + src: url("../fonts/OpenSans-Semibold-webfont.eot?#iefix") format("embedded-opentype"), url("../fonts/OpenSans-Semibold-webfont.woff") format("woff"), url("../fonts/OpenSans-Semibold-webfont.ttf") format("truetype"), url("../fonts/OpenSans-Semibold-webfont.svg#OpenSansSemibold") format("svg"); + font-weight: normal; + font-style: normal; + -webkit-font-smoothing: antialiased; +} + +@font-face { + font-family: 'OpenSansSemiboldItalic'; + src: url("../fonts/OpenSans-SemiboldItalic-webfont.eot"); + src: url("../fonts/OpenSans-SemiboldItalic-webfont.eot?#iefix") format("embedded-opentype"), url("../fonts/OpenSans-SemiboldItalic-webfont.woff") format("woff"), url("../fonts/OpenSans-SemiboldItalic-webfont.ttf") format("truetype"), url("../fonts/OpenSans-SemiboldItalic-webfont.svg#OpenSansSemiboldItalic") format("svg"); + font-weight: normal; + font-style: normal; + -webkit-font-smoothing: antialiased; +} + +@font-face { + font-family: 'OpenSansBold'; + src: url("../fonts/OpenSans-Bold-webfont.eot"); + src: url("../fonts/OpenSans-Bold-webfont.eot?#iefix") format("embedded-opentype"), url("../fonts/OpenSans-Bold-webfont.woff") format("woff"), url("../fonts/OpenSans-Bold-webfont.ttf") format("truetype"), url("../fonts/OpenSans-Bold-webfont.svg#OpenSansBold") format("svg"); + font-weight: normal; + font-style: normal; + -webkit-font-smoothing: antialiased; +} + +@font-face { + font-family: 'OpenSansBoldItalic'; + src: url("../fonts/OpenSans-BoldItalic-webfont.eot"); + src: url("../fonts/OpenSans-BoldItalic-webfont.eot?#iefix") format("embedded-opentype"), url("../fonts/OpenSans-BoldItalic-webfont.woff") format("woff"), url("../fonts/OpenSans-BoldItalic-webfont.ttf") format("truetype"), url("../fonts/OpenSans-BoldItalic-webfont.svg#OpenSansBoldItalic") format("svg"); + font-weight: normal; + font-style: normal; + -webkit-font-smoothing: antialiased; +} + +/* normalize.css 2012-02-07T12:37 UTC - http://github.com/necolas/normalize.css */ +/* ============================================================================= + HTML5 display definitions + ========================================================================== */ +/* + * Corrects block display not defined in IE6/7/8/9 & FF3 + */ +article, +aside, +details, +figcaption, +figure, +footer, +header, +hgroup, +nav, +section, +summary { + display: block; +} + +/* + * Corrects inline-block display not defined in IE6/7/8/9 & FF3 + */ +audio, +canvas, +video { + display: inline-block; + *display: inline; + *zoom: 1; +} + +/* + * Prevents modern browsers from displaying 'audio' without controls + */ +audio:not([controls]) { + display: none; +} + +/* + * Addresses styling for 'hidden' attribute not present in IE7/8/9, FF3, S4 + * Known issue: no IE6 support + */ +[hidden] { + display: none; +} + +/* ============================================================================= + Base + ========================================================================== */ +/* + * 1. Corrects text resizing oddly in IE6/7 when body font-size is set using em units + * http://clagnut.com/blog/348/#c790 + * 2. Prevents iOS text size adjust after orientation change, without disabling user zoom + * www.456bereastreet.com/archive/201012/controlling_text_size_in_safari_for_ios_without_disabling_user_zoom/ + */ +html { + font-size: 100%; + /* 1 */ + -webkit-text-size-adjust: 100%; + /* 2 */ + -ms-text-size-adjust: 100%; + /* 2 */ +} + +/* + * Addresses font-family inconsistency between 'textarea' and other form elements. + */ +html, +button, +input, +select, +textarea { + font-family: sans-serif; +} + +/* + * Addresses margins handled incorrectly in IE6/7 + */ +body { + margin: 0; +} + +/* ============================================================================= + Links + ========================================================================== */ +/* + * Addresses outline displayed oddly in Chrome + */ +a:focus { + outline: thin dotted; +} + +/* + * Improves readability when focused and also mouse hovered in all browsers + * people.opera.com/patrickl/experiments/keyboard/test + */ +a:hover, +a:active { + outline: 0; +} + +/* ============================================================================= + Typography + ========================================================================== */ +/* + * Addresses font sizes and margins set differently in IE6/7 + * Addresses font sizes within 'section' and 'article' in FF4+, Chrome, S5 + */ +h1 { + font-size: 2em; + margin: 0.67em 0; +} + +h2 { + font-size: 1.5em; + margin: 0.83em 0; +} + +h3 { + font-size: 1.17em; + margin: 1em 0; +} + +h4 { + font-size: 1em; + margin: 1.33em 0; +} + +h5 { + font-size: 0.83em; + margin: 1.67em 0; +} + +h6 { + font-size: 0.75em; + margin: 2.33em 0; +} + +/* + * Addresses styling not present in IE7/8/9, S5, Chrome + */ +abbr[title] { + border-bottom: 1px dotted; +} + +/* + * Addresses style set to 'bolder' in FF3+, S4/5, Chrome +*/ +b, +strong { + font-weight: bold; +} + +blockquote { + margin: 1em 40px; +} + +/* + * Addresses styling not present in S5, Chrome + */ +dfn { + font-style: italic; +} + +/* + * Addresses styling not present in IE6/7/8/9 + */ +mark { + background: #ff0; + color: #000; +} + +/* + * Addresses margins set differently in IE6/7 + */ +p, +pre { + margin: 1em 0; +} + +/* + * Corrects font family set oddly in IE6, S4/5, Chrome + * en.wikipedia.org/wiki/User:Davidgothberg/Test59 + */ +pre, +code, +kbd, +samp { + font-family: monospace, serif; + _font-family: 'courier new', monospace; + font-size: 1em; +} + +/* + * 1. Addresses CSS quotes not supported in IE6/7 + * 2. Addresses quote property not supported in S4 + */ +/* 1 */ +q { + quotes: none; +} + +/* 2 */ +q:before, +q:after { + content: ''; + content: none; +} + +small { + font-size: 75%; +} + +/* + * Prevents sub and sup affecting line-height in all browsers + * gist.github.com/413930 + */ +sub, +sup { + font-size: 75%; + line-height: 0; + position: relative; + vertical-align: baseline; +} + +sup { + top: -0.5em; +} + +sub { + bottom: -0.25em; +} + +/* ============================================================================= + Lists + ========================================================================== */ +/* + * Addresses margins set differently in IE6/7 + */ +dl, +menu, +ol, +ul { + margin: 1em 0; +} + +dd { + margin: 0 0 0 40px; +} + +/* + * Addresses paddings set differently in IE6/7 + */ +menu, +ol, +ul { + padding: 0 0 0 40px; +} + +/* + * Corrects list images handled incorrectly in IE7 + */ +nav ul, +nav ol { + list-style: none; + list-style-image: none; +} + +/* ============================================================================= + Embedded content + ========================================================================== */ +/* + * 1. Removes border when inside 'a' element in IE6/7/8/9, FF3 + * 2. Improves image quality when scaled in IE7 + * code.flickr.com/blog/2008/11/12/on-ui-quality-the-little-things-client-side-image-resizing/ + */ +img { + border: 0; + /* 1 */ + -ms-interpolation-mode: bicubic; + /* 2 */ +} + +/* + * Corrects overflow displayed oddly in IE9 + */ +svg:not(:root) { + overflow: hidden; +} + +/* ============================================================================= + Figures + ========================================================================== */ +/* + * Addresses margin not present in IE6/7/8/9, S5, O11 + */ +figure { + margin: 0; +} + +/* ============================================================================= + Forms + ========================================================================== */ +/* + * Corrects margin displayed oddly in IE6/7 + */ +form { + margin: 0; +} + +/* + * Define consistent border, margin, and padding + */ +fieldset { + border: 1px solid #c0c0c0; + margin: 0 2px; + padding: 0.35em 0.625em 0.75em; +} + +/* + * 1. Corrects color not being inherited in IE6/7/8/9 + * 2. Corrects text not wrapping in FF3 + * 3. Corrects alignment displayed oddly in IE6/7 + */ +legend { + border: 0; + /* 1 */ + padding: 0; + white-space: normal; + /* 2 */ + *margin-left: -7px; + /* 3 */ +} + +/* + * 1. Corrects font size not being inherited in all browsers + * 2. Addresses margins set differently in IE6/7, FF3+, S5, Chrome + * 3. Improves appearance and consistency in all browsers + */ +button, +input, +select, +textarea { + font-size: 100%; + /* 1 */ + margin: 0; + /* 2 */ + vertical-align: baseline; + /* 3 */ + *vertical-align: middle; + /* 3 */ +} + +/* + * Addresses FF3/4 setting line-height on 'input' using !important in the UA stylesheet + */ +button, +input { + line-height: normal; + /* 1 */ +} + +/* + * 1. Improves usability and consistency of cursor style between image-type 'input' and others + * 2. Corrects inability to style clickable 'input' types in iOS + * 3. Removes inner spacing in IE7 without affecting normal text inputs + * Known issue: inner spacing remains in IE6 + */ +button, +input[type="button"], +input[type="reset"], +input[type="submit"] { + cursor: pointer; + /* 1 */ + -webkit-appearance: button; + /* 2 */ + *overflow: visible; + /* 3 */ +} + +/* + * Re-set default cursor for disabled elements + */ +button[disabled], +input[disabled] { + cursor: default; +} + +/* + * 1. Addresses box sizing set to content-box in IE8/9 + * 2. Removes excess padding in IE8/9 + * 3. Removes excess padding in IE7 + Known issue: excess padding remains in IE6 + */ +input[type="checkbox"], +input[type="radio"] { + box-sizing: border-box; + /* 1 */ + padding: 0; + /* 2 */ + *height: 13px; + /* 3 */ + *width: 13px; + /* 3 */ +} + +/* + * 1. Addresses appearance set to searchfield in S5, Chrome + * 2. Addresses box-sizing set to border-box in S5, Chrome (include -moz to future-proof) + */ +input[type="search"] { + -webkit-appearance: textfield; + /* 1 */ + -moz-box-sizing: content-box; + -webkit-box-sizing: content-box; + /* 2 */ + box-sizing: content-box; +} + +/* + * Removes inner padding and search cancel button in S5, Chrome on OS X + */ +input[type="search"]::-webkit-search-decoration, +input[type="search"]::-webkit-search-cancel-button { + -webkit-appearance: none; +} + +/* + * Removes inner padding and border in FF3+ + * www.sitepen.com/blog/2008/05/14/the-devils-in-the-details-fixing-dojos-toolbar-buttons/ + */ +button::-moz-focus-inner, +input::-moz-focus-inner { + border: 0; + padding: 0; +} + +/* + * 1. Removes default vertical scrollbar in IE6/7/8/9 + * 2. Improves readability and alignment in all browsers + */ +textarea { + overflow: auto; + /* 1 */ + vertical-align: top; + /* 2 */ +} + +/* ============================================================================= + Tables + ========================================================================== */ +/* + * Remove most spacing between table cells + */ +table { + border-collapse: collapse; + border-spacing: 0; +} + +body { + padding: 0px 0 20px 0px; + margin: 0px; + font: 14px/1.5 "OpenSansRegular", "Helvetica Neue", Helvetica, Arial, sans-serif; + color: #f0e7d5; + font-weight: normal; + background: #252525; + background-attachment: fixed !important; + background: -webkit-gradient(linear, 50% 0%, 50% 100%, color-stop(0%, #2a2a29), color-stop(100%, #1c1c1c)); + background: -webkit-linear-gradient(#2a2a29, #1c1c1c); + background: -moz-linear-gradient(#2a2a29, #1c1c1c); + background: -o-linear-gradient(#2a2a29, #1c1c1c); + background: -ms-linear-gradient(#2a2a29, #1c1c1c); + background: linear-gradient(#2a2a29, #1c1c1c); +} + +h1, h2, h3, h4, h5, h6 { + color: #e8e8e8; + margin: 0 0 10px; + font-family: 'OpenSansRegular', "Helvetica Neue", Helvetica, Arial, sans-serif; + font-weight: normal; +} + +p, ul, ol, table, pre, dl { + margin: 0 0 20px; +} + +h1, h2, h3 { + line-height: 1.1; +} + +h1 { + font-size: 28px; +} + +h2 { + font-size: 24px; +} + +h4, h5, h6 { + color: #e8e8e8; +} + +h3 { + font-size: 18px; + line-height: 24px; + font-family: 'OpenSansRegular', "Helvetica Neue", Helvetica, Arial, sans-serif !important; + font-weight: normal; + color: #b6b6b6; +} + +a { + color: #ffcc00; + font-weight: 400; + text-decoration: none; +} +a:hover { + color: #ffeb9b; +} + +a small { + font-size: 11px; + color: #666; + margin-top: -0.6em; + display: block; +} + +ul { + list-style-image: url("../images/bullet.png"); +} + +strong { + font-family: 'OpenSansBold', "Helvetica Neue", Helvetica, Arial, sans-serif !important; + font-weight: normal; +} + +.wrapper { + max-width: 650px; + margin: 0 auto; + position: relative; + padding: 0 20px; +} + +section img { + max-width: 100%; +} + +blockquote { + border-left: 3px solid #ffcc00; + margin: 0; + padding: 0 0 0 20px; + font-style: italic; +} + +code { + font-family: "Lucida Sans", Monaco, Bitstream Vera Sans Mono, Lucida Console, Terminal; + color: #efefef; + font-size: 13px; + margin: 0 4px; + padding: 4px 6px; + -moz-border-radius: 2px; + -webkit-border-radius: 2px; + -o-border-radius: 2px; + -ms-border-radius: 2px; + -khtml-border-radius: 2px; + border-radius: 2px; +} + +pre { + padding: 8px 15px; + background: #191919; + -moz-border-radius: 2px; + -webkit-border-radius: 2px; + -o-border-radius: 2px; + -ms-border-radius: 2px; + -khtml-border-radius: 2px; + border-radius: 2px; + border: 1px solid #121212; + -moz-box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.3); + -webkit-box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.3); + -o-box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.3); + box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.3); + overflow: auto; + overflow-y: hidden; +} +pre code { + color: #efefef; + text-shadow: 0px 1px 0px #000; + margin: 0; + padding: 0; +} + +table { + width: 100%; + border-collapse: collapse; +} + +th { + text-align: left; + padding: 5px 10px; + border-bottom: 1px solid #434343; + color: #b6b6b6; + font-family: 'OpenSansSemibold', "Helvetica Neue", Helvetica, Arial, sans-serif !important; + font-weight: normal; +} + +td { + text-align: left; + padding: 5px 10px; + border-bottom: 1px solid #434343; +} + +hr { + border: 0; + outline: none; + height: 3px; + background: transparent url("../images/hr.gif") center center repeat-x; + margin: 0 0 20px; +} + +dt { + color: #F0E7D5; + font-family: 'OpenSansSemibold', "Helvetica Neue", Helvetica, Arial, sans-serif !important; + font-weight: normal; +} + +#header { + z-index: 100; + left: 0; + top: 0px; + height: 60px; + width: 100%; + position: fixed; + background: url(../images/nav-bg.gif) #353535; + border-bottom: 4px solid #434343; + -moz-box-shadow: 0px 1px 3px rgba(0, 0, 0, 0.25); + -webkit-box-shadow: 0px 1px 3px rgba(0, 0, 0, 0.25); + -o-box-shadow: 0px 1px 3px rgba(0, 0, 0, 0.25); + box-shadow: 0px 1px 3px rgba(0, 0, 0, 0.25); +} +#header nav { + max-width: 650px; + margin: 0 auto; + padding: 0 10px; + background: blue; + margin: 6px auto; +} +#header nav li { + font-family: 'OpenSansLight', "Helvetica Neue", Helvetica, Arial, sans-serif; + font-weight: normal; + list-style: none; + display: inline; + color: white; + line-height: 50px; + text-shadow: 0px 1px 0px rgba(0, 0, 0, 0.2); + font-size: 14px; +} +#header nav li a { + color: white; + border: 1px solid #5d910b; + background: -webkit-gradient(linear, 50% 0%, 50% 100%, color-stop(0%, #93bd20), color-stop(100%, #659e10)); + background: -webkit-linear-gradient(#93bd20, #659e10); + background: -moz-linear-gradient(#93bd20, #659e10); + background: -o-linear-gradient(#93bd20, #659e10); + background: -ms-linear-gradient(#93bd20, #659e10); + background: linear-gradient(#93bd20, #659e10); + -moz-border-radius: 2px; + -webkit-border-radius: 2px; + -o-border-radius: 2px; + -ms-border-radius: 2px; + -khtml-border-radius: 2px; + border-radius: 2px; + -moz-box-shadow: inset 0px 1px 0px rgba(255, 255, 255, 0.3), 0px 3px 7px rgba(0, 0, 0, 0.7); + -webkit-box-shadow: inset 0px 1px 0px rgba(255, 255, 255, 0.3), 0px 3px 7px rgba(0, 0, 0, 0.7); + -o-box-shadow: inset 0px 1px 0px rgba(255, 255, 255, 0.3), 0px 3px 7px rgba(0, 0, 0, 0.7); + box-shadow: inset 0px 1px 0px rgba(255, 255, 255, 0.3), 0px 3px 7px rgba(0, 0, 0, 0.7); + background-color: #93bd20; + padding: 10px 12px; + margin-top: 6px; + line-height: 14px; + font-size: 14px; + display: inline-block; + text-align: center; +} +#header nav li a:hover { + background: -webkit-gradient(linear, 50% 0%, 50% 100%, color-stop(0%, #749619), color-stop(100%, #527f0e)); + background: -webkit-linear-gradient(#749619, #527f0e); + background: -moz-linear-gradient(#749619, #527f0e); + background: -o-linear-gradient(#749619, #527f0e); + background: -ms-linear-gradient(#749619, #527f0e); + background: linear-gradient(#749619, #527f0e); + background-color: #659e10; + border: 1px solid #527f0e; + -moz-box-shadow: inset 0px 1px 1px rgba(0, 0, 0, 0.2), 0px 1px 0px rgba(0, 0, 0, 0); + -webkit-box-shadow: inset 0px 1px 1px rgba(0, 0, 0, 0.2), 0px 1px 0px rgba(0, 0, 0, 0); + -o-box-shadow: inset 0px 1px 1px rgba(0, 0, 0, 0.2), 0px 1px 0px rgba(0, 0, 0, 0); + box-shadow: inset 0px 1px 1px rgba(0, 0, 0, 0.2), 0px 1px 0px rgba(0, 0, 0, 0); +} +#header nav li.fork { + float: left; + margin-left: 0px; +} +#header nav li.downloads { + float: right; + margin-left: 6px; +} +#header nav li.title { + float: right; + margin-right: 10px; + font-size: 11px; +} + +section { + max-width: 650px; + padding: 30px 0px 50px 0px; + margin: 20px 0; + margin-top: 70px; +} +section #title { + border: 0; + outline: none; + margin: 0 0 50px 0; + padding: 0 0 5px 0; +} +section #title h1 { + font-family: 'OpenSansLight', "Helvetica Neue", Helvetica, Arial, sans-serif; + font-weight: normal; + font-size: 40px; + text-align: center; + line-height: 36px; +} +section #title p { + color: #d7cfbe; + font-family: 'OpenSansLight', "Helvetica Neue", Helvetica, Arial, sans-serif; + font-weight: normal; + font-size: 18px; + text-align: center; +} +section #title .credits { + font-size: 11px; + font-family: 'OpenSansRegular', "Helvetica Neue", Helvetica, Arial, sans-serif; + font-weight: normal; + color: #696969; + margin-top: -10px; +} +section #title .credits.left { + float: left; +} +section #title .credits.right { + float: right; +} + +@media print, screen and (max-width: 720px) { + #title .credits { + display: block; + width: 100%; + line-height: 30px; + text-align: center; + } + #title .credits .left { + float: none; + display: block; + } + #title .credits .right { + float: none; + display: block; + } +} +@media print, screen and (max-width: 480px) { + #header { + margin-top: -20px; + } + + section { + margin-top: 40px; + } + + nav { + display: none; + } +}