diff --git a/bin/needle.min.js b/bin/needle.min.js index b26e905..2072473 100644 --- a/bin/needle.min.js +++ b/bin/needle.min.js @@ -2,4 +2,4 @@ // node-needle v0.1.9 | MIT // Copyright (c) 2016 Nick Zuber */ -!function t(e,i,n){function r(s,h){if(!i[s]){if(!e[s]){var a="function"==typeof require&&require;if(!h&&a)return a(s,!0);if(o)return o(s,!0);throw new Error("Cannot find module '"+s+"'")}var u=i[s]={exports:{}};e[s][0].call(u.exports,function(t){var i=e[s][1][t];return r(i?i:t)},u,u.exports,t,e,i,n)}return i[s].exports}for(var o="function"==typeof require&&require,s=0;s1;)r(this.heap[e],this.heap[Math.floor(e/2)],this.compare)&&this.heap.swap(e,Math.floor(e/2)),e=Math.floor(e/2)},o.prototype["delete"]=function(t){if("number"==typeof t?++t:t=1,"number"!=typeof t)throw new TypeError("Expected a number as argument in BinaryHeap.delete");if(t<0||t>=this.heap.length)throw new Error("Index out of bounds in BinaryHeap.delete");if(this.heap.length<=1)throw new Error("Attempted to remove min element from an empty heap in BinaryHeap.delete");if(2===this.heap.length)return void this.heap.pop();if(this.heap[t]=this.heap.pop(),2===this.heap.length);else if(3===this.heap.length){var t=1;r(this.heap[2*t],this.heap[t],this.compare)&&this.heap.swap(t,2*t)}else for(var e=0,t=1;r(this.heap[2*t],this.heap[t],this.compare)||r(this.heap[2*t+1],this.heap[t],this.compare);){var i;if(i=r(this.heap[2*t],this.heap[2*t+1],this.compare)||"undefined"==typeof this.heap[2*t+1]?2*t:2*t+1,this.heap.swap(t,i),t=i,++e,e>1e3)throw new Error("Timeout error in BinaryHeap.delete. Please report this to https://github.com/nickzuber/needle/issues")}},o.prototype._heapify=function(t){var e=2*t,i=e+1,n=t;this.heap.length;e=1;--e)this._heapify(e);console.log(this.heap)},e.exports=o},{}],2:[function(t,e,i){"use strict";const n=t("./binaryHeap");e.exports=n},{"./binaryHeap":1}],3:[function(t,e,i){"use strict";function n(t,e){return t=this.data.length*r)throw new Error("Index out of bounds in BitArray.set");var i=Math.floor(t++/r);e?this.data[i]|=1<=this.data.length*r)throw new Error("Index out of bounds in BitArray.get");var e=Math.floor(t++/r),i=this.data[e];return i>>r-t&1},o.prototype.size=function(){return this.data.length*r},o.prototype.resize=function(t){if("number"!=typeof bitarray)throw new TypeError("");return this.data.length*r},o.prototype.complement=function(t){"undefined"==typeof t?t=this:t instanceof o||(t=new o(t));var e=new o;return t.data.map(function(t){e.data.push(~t)}),e},o.prototype.union=function(t){if("undefined"==typeof t)throw new Error("Undefined bitarray argument in BitArray.union");if(!(t instanceof o))throw new TypeError("Invalid argument: expected BitArray as an argument in BitArray.union");if(t.size()!==this.size())throw new Error("BitArrays must be of same size to resolve a union in BitArray.union");for(var e=new o,i=0;i>>31),e<<=1;t.split("").reverse().join("")}),t},e.exports=o},{}],6:[function(t,e,i){"use strict";const n=t("./bitArray");e.exports=n},{"./bitArray":5}],7:[function(t,e,i){"use strict";const n=t("../__Nodes__/bidirectional_node.js"),r=function(t){this.head,this.tail,this.size,"undefined"!=typeof t?(this.head=new n(t),this.tail=this.head,this.size=1):(this.head=null,this.tail=null,this.size=0)};r.prototype.insertFront=function(t){if("undefined"==typeof t)throw new Error("Too few arguments for DoublyLinkedList.insertFront");var e=new n(t);if(null===this.head&&null===this.tail)this.head=e,this.tail=this.head;else{if(null===this.head||null===this.tail)throw new Error("Unsynced head and tail in an Doubly Linked List. Please report this to https://github.com/nickzuber/needle/issues");var i=this.head;i.prev=e,this.head=e,this.head.next=i,this.head.prev=null}++this.size},r.prototype.insertNth=function(t,e){if("undefined"==typeof e||"undefined"==typeof t)throw new Error("Too few arguments for DoublyLinkedList.insertNth");if("number"!=typeof t)throw new TypeError("Invalid argument for DoublyLinkedList.insertNth");if(t<0||t>=this.size&&0!==t)throw new Error("Index out of bounds on DoublyLinkedList.insertNth");if(0===t)return void this.insertFront(e);if(null===this.head)return!1;if(t===this.size-1)return void this.insertBack(e);for(var i=new n(e),r=this.head,o=1;o0)throw new Error("Null head in an unemptied list. Please report this to https://github.com/nickzuber/needle/issues");var e,i,n=this.head,r=!1;if(i="object"==typeof t?JSON.stringify(t):t,e="object"==typeof n.data?JSON.stringify(n.data):n.data,JSON.stringify(this.head.data)===JSON.stringify(t))return this.head=n.next,this.head.prev=null,n=null,--this.size,!0;if(JSON.stringify(this.tail.data)===JSON.stringify(t))return n=this.tail,this.tail=n.prev,this.tail.next=null,n=null,--this.size,!0;for(n=n.next;null!==n;){if(e="object"==typeof n.data?JSON.stringify(n.data):n.data,e===i){r=!0;var o=n.prev;o.next=n.next,n.next.prev=o,n=null,--this.size;break}n=n.next}return r},r.prototype.removeNth=function(t){if("undefined"==typeof t)throw new Error("Too few arguments for DoublyLinkedList.removeNth");if("number"!=typeof t)throw new TypeError("Invalid argument for DoublyLinkedList.removeNth");if(t<0||t>=this.size)throw new Error("Index out of bounds on DoublyLinkedList.removeNth: "+t);if(1===this.size)return this.head=null,this.tail=null,void(this.size=0);var e=this.head;if(0===t)return this.head=e.next,this.head.prev=null,e=null,void--this.size;if(t===this.size-1)return e=this.tail,this.tail=e.prev,this.tail.next=null,e=null,--this.size,!0;e=e.next;for(var i=1;i0)throw new Error("Null head in an unemptied list. Please report this to https://github.com/nickzuber/needle/issues");for(var e=this.head,i=!1;null!==e;){if(JSON.stringify(e.data)===JSON.stringify(t)){i=!0;break}e=e.next}return!!i&&e},r.prototype.findNth=function(t){if("undefined"==typeof t)throw new TypeError("Too few arguments for DoublyLinkedList.findNth");if("number"!=typeof t)throw new TypeError("Invalid argument for DoublyLinkedList.findNth");if(t<0||t>=this.size)throw new Error("Index out of bounds; attempted to find a node from a SinglyLinkedList that does not exist");if(null===this.head&&this.size>0)throw new Error("Null head in an unemptied list. Please report this to https://github.com/nickzuber/needle/issues");for(var e=this.head,i=0;i0)for(var e=0;e0?parseInt(t):void 0};const s=2147483647,h=function(t){if("undefined"==typeof t)throw new Error("Too few arguments in RollingHash constructor");if("number"!=typeof t)throw new TypeError("Invalid argument; expected a number in RollingHash constructor");this.BASE=t,this.state=0,this.CACHE=1,this.BUFFER_SIZE=Math.log(t)*Math.LOG10E+1|0,this.INVERSE_BASE=n(this.BASE,s)%s,this.OFFSET_IF_NEGATIVE=s*this.BASE};h.prototype.hash=function(t){if("undefined"==typeof t)throw new Error("Too few arguments in RollingHash.hash");if(!parseInt(Math.pow(this.BASE,t.length-1)))throw new Error('Integer overflow while trying to hash "'+t+'" in RollingHash.hash\nThis hashing window is too large\nIf this issue is breaking to your program, please report this to https://github.com/nickzuber/needle/issues');var e=0;if("string"==typeof t)for(var i=0;i=this.size&&0!==t)throw new Error("Index out of bounds on SinglyLinkedList.insertNth");if(0===t)return void this.insertFront(e);if(null===this.head)return!1;for(var i=new n(e),r=this.head,o=1;o0)throw new Error("Null head in an unemptied list. Please report this to https://github.com/nickzuber/needle/issues");var e,i,n=null,r=this.head,o=!1;if(i="object"==typeof t?JSON.stringify(t):t,e="object"==typeof r.data?JSON.stringify(r.data):r.data,e===i)return this.head=r.next,r=null,--this.size,!0;for(n=r,r=n.next;null!==r;){if(e="object"==typeof r.data?JSON.stringify(r.data):r.data,e===i){o=!0,n.next=r.next,r=null,--this.size;break}n=r,r=r.next}return o},r.prototype.removeNth=function(t){if("undefined"==typeof t)throw new Error("Too few arguments for SinglyLinkedList.removeNth");if("number"!=typeof t)throw new TypeError("Invalid argument for SinglyLinkedList.removeNth");if(t<0||t>=this.size)throw new Error("Index out of bounds on SinglyLinkedList.removeNth: "+t);if(1===this.size)return this.head=null,void(this.size=0);var e=null,i=this.head;if(0===t)return this.head=i.next,i=null,void--this.size;e=i,i=i.next;for(var n=1;n0)throw new Error("Null head in an unemptied list. Please report this to https://github.com/nickzuber/needle/issues");for(var e=this.head,i=!1;null!==e;){if(JSON.stringify(e.data)===JSON.stringify(t)){i=!0;break}e=e.next}return!!i&&e},r.prototype.findNth=function(t){if("undefined"==typeof t)throw new TypeError("Too few arguments for SinglyLinkedList.findNth");if("number"!=typeof t)throw new TypeError("Invalid argument for SinglyLinkedList.findNth");if(t<0||t>=this.size)throw new Error("Index out of bounds; attempted to find a node from a SinglyLinkedList that does not exist");if(null===this.head&&this.size>0)throw new Error("Null head in an unemptied list. Please report this to https://github.com/nickzuber/needle/issues");for(var e=this.head,i=0;i1&&!r(t,this.elements[n]);)n=Math.floor(e+(i-e)/2),o(this.elements[n],t,this.compare)?e=n:i=n;o(t,this.elements[n],this.compare)?this.elements.splice(n,0,t):this.elements.splice(n+1,0,t)},s.prototype["delete"]=function(t){if("undefined"==typeof t)throw new Error("Too few arguments in SortedArray.delete");if(0===this.elements.length)return!1;for(var e=0,i=this.elements.length,n=Math.floor(e+(i-e)/2);i>=e;){if(n=Math.floor(e+(i-e)/2),r(t,this.elements[n]))return this.elements.splice(n,1),!0;o(this.elements[n],t,this.compare)?e=n+1:i=n-1}return!1},s.prototype.get=function(t){if("undefined"==typeof t)throw new Error("Too few arguments in SortedArray.get");if(0==typeof t)throw new Error("Invalid argument; expected a number in SortedArray.get");return this.elements[t]},s.prototype.size=function(){return this.elements.length},s.prototype.toString=function(){var t,e="";for(t=0;t0?e.slice(0,-1):e},e.exports=s},{}],21:[function(t,e,i){"use strict";const n=t("./stack");e.exports=n},{"./stack":22}],22:[function(t,e,i){"use strict";const n=t("../__Nodes__/unidirectional_node.js"),r=function(t){this.top,this.size,"undefined"!=typeof t?(this.top=new n(t),this.size=1):(this.top=null,this.size=0)};r.prototype.peek=function(){return this.top},r.prototype.push=function(t){if("undefined"==typeof t)throw new Error("Too few arguments in Stack.push");var e=new n(t),i=this.top;this.top=e,this.top.next=i,++this.size},r.prototype.pop=function(){if(0===this.size)throw new Error("Attempted to remove from empty stack in Stack.pop");var t=this.top.next,e=this.top;return this.top=t,--this.size,e},e.exports=r},{"../__Nodes__/unidirectional_node.js":26}],23:[function(t,e,i){"use strict";const n=function(t){this.data=t||void 0,this.next=null,this.prev=null};e.exports=n},{}],24:[function(t,e,i){"use strict";const n=function(t){this.data=t||void 0,this.right=null,this.left=null};e.exports=n},{}],25:[function(t,e,i){"use strict";const n=function(t){this.data=t||void 0,this.children=[]};n.prototype.appendChild=function(t){this.children.push(new n(t))},e.exports=n},{}],26:[function(t,e,i){"use strict";const n=function(t){this.data=t||void 0,this.next=null};e.exports=n},{}],27:[function(t,e,i){"use strict";const n=t("./SinglyLinkedList"),r=t("./Queue"),o=t("./Stack"),s=t("./DoublyLinkedList"),h=t("./BinaryHeap"),a=t("./BinarySearchTree"),u=t("./Hashmap"),f=t("./SortedArray"),p=t("./RollingHash"),d=t("./BitArray"),l=t("./KaryTree"),y={};y.SinglyLinkedList=n,y.Queue=r,y.Stack=o,y.DoublyLinkedList=s,y.BinaryHeap=h,y.BinarySearchTree=a,y.Hashmap=u,y.SortedArray=f,y.RollingHash=p,y.BitArray=d,y.KaryTree=l,i=e.exports=y,"undefined"!=typeof window&&(window.Needle=y)},{"./BinaryHeap":2,"./BinarySearchTree":4,"./BitArray":6,"./DoublyLinkedList":8,"./Hashmap":10,"./KaryTree":12,"./Queue":13,"./RollingHash":15,"./SinglyLinkedList":17,"./SortedArray":19,"./Stack":21}]},{},[27]); \ No newline at end of file +!function t(e,i,n){function r(s,h){if(!i[s]){if(!e[s]){var a="function"==typeof require&&require;if(!h&&a)return a(s,!0);if(o)return o(s,!0);throw new Error("Cannot find module '"+s+"'")}var u=i[s]={exports:{}};e[s][0].call(u.exports,function(t){var i=e[s][1][t];return r(i?i:t)},u,u.exports,t,e,i,n)}return i[s].exports}for(var o="function"==typeof require&&require,s=0;s1;)r(this.heap[e],this.heap[Math.floor(e/2)],this.compare)&&this.heap.swap(e,Math.floor(e/2)),e=Math.floor(e/2)},o.prototype["delete"]=function(t){if("number"==typeof t?++t:t=1,"number"!=typeof t)throw new TypeError("Expected a number as argument in BinaryHeap.delete");if(t<0||t>=this.heap.length)throw new Error("Index out of bounds in BinaryHeap.delete");if(this.heap.length<=1)throw new Error("Attempted to remove min element from an empty heap in BinaryHeap.delete");if(2===this.heap.length)return void this.heap.pop();if(this.heap[t]=this.heap.pop(),2===this.heap.length);else if(3===this.heap.length){var t=1;r(this.heap[2*t],this.heap[t],this.compare)&&this.heap.swap(t,2*t)}else for(var e=0,t=1;r(this.heap[2*t],this.heap[t],this.compare)||r(this.heap[2*t+1],this.heap[t],this.compare);){var i;if(i=r(this.heap[2*t],this.heap[2*t+1],this.compare)||"undefined"==typeof this.heap[2*t+1]?2*t:2*t+1,this.heap.swap(t,i),t=i,++e,e>1e3)throw new Error("Timeout error in BinaryHeap.delete. Please report this to https://github.com/nickzuber/needle/issues")}},o.prototype._heapify=function(t){var e=2*t,i=e+1,n=t;this.heap.length;e=1;--e)this._heapify(e);console.log(this.heap)},e.exports=o},{}],2:[function(t,e,i){"use strict";const n=t("./binaryHeap");e.exports=n},{"./binaryHeap":1}],3:[function(t,e,i){"use strict";function n(t,e){return t=this.data.length*r)throw new Error("Index out of bounds in BitArray.set");var i=Math.floor(t++/r);e?this.data[i]|=1<=this.data.length*r)throw new Error("Index out of bounds in BitArray.get");var e=Math.floor(t++/r),i=this.data[e];return i>>r-t&1},o.prototype.size=function(){return this.data.length*r},o.prototype.resize=function(t){if("number"!=typeof bitarray)throw new TypeError("");return this.data.length*r},o.prototype.complement=function(t){"undefined"==typeof t?t=this:t instanceof o||(t=new o(t));var e=new o;return t.data.map(function(t){e.data.push(~t)}),e},o.prototype.union=function(t){if("undefined"==typeof t)throw new Error("Undefined bitarray argument in BitArray.union");if(!(t instanceof o))throw new TypeError("Invalid argument: expected BitArray as an argument in BitArray.union");if(t.size()!==this.size())throw new Error("BitArrays must be of same size to resolve a union in BitArray.union");for(var e=new o,i=0;i>>31),e<<=1;t.split("").reverse().join("")}),t},e.exports=o},{}],6:[function(t,e,i){"use strict";const n=t("./bitArray");e.exports=n},{"./bitArray":5}],7:[function(t,e,i){"use strict";const n=t("../Nodes/bidirectional_node.js"),r=function(t){this.head,this.tail,this.size,"undefined"!=typeof t?(this.head=new n(t),this.tail=this.head,this.size=1):(this.head=null,this.tail=null,this.size=0)};r.prototype.insertFront=function(t){if("undefined"==typeof t)throw new Error("Too few arguments for DoublyLinkedList.insertFront");var e=new n(t);if(null===this.head&&null===this.tail)this.head=e,this.tail=this.head;else{if(null===this.head||null===this.tail)throw new Error("Unsynced head and tail in an Doubly Linked List. Please report this to https://github.com/nickzuber/needle/issues");var i=this.head;i.prev=e,this.head=e,this.head.next=i,this.head.prev=null}++this.size},r.prototype.insertNth=function(t,e){if("undefined"==typeof e||"undefined"==typeof t)throw new Error("Too few arguments for DoublyLinkedList.insertNth");if("number"!=typeof t)throw new TypeError("Invalid argument for DoublyLinkedList.insertNth");if(t<0||t>=this.size&&0!==t)throw new Error("Index out of bounds on DoublyLinkedList.insertNth");if(0===t)return void this.insertFront(e);if(null===this.head)return!1;if(t===this.size-1)return void this.insertBack(e);for(var i=new n(e),r=this.head,o=1;o0)throw new Error("Null head in an unemptied list. Please report this to https://github.com/nickzuber/needle/issues");var e,i,n=this.head,r=!1;if(i="object"==typeof t?JSON.stringify(t):t,e="object"==typeof n.data?JSON.stringify(n.data):n.data,JSON.stringify(this.head.data)===JSON.stringify(t))return this.head=n.next,this.head.prev=null,n=null,--this.size,!0;if(JSON.stringify(this.tail.data)===JSON.stringify(t))return n=this.tail,this.tail=n.prev,this.tail.next=null,n=null,--this.size,!0;for(n=n.next;null!==n;){if(e="object"==typeof n.data?JSON.stringify(n.data):n.data,e===i){r=!0;var o=n.prev;o.next=n.next,n.next.prev=o,n=null,--this.size;break}n=n.next}return r},r.prototype.removeNth=function(t){if("undefined"==typeof t)throw new Error("Too few arguments for DoublyLinkedList.removeNth");if("number"!=typeof t)throw new TypeError("Invalid argument for DoublyLinkedList.removeNth");if(t<0||t>=this.size)throw new Error("Index out of bounds on DoublyLinkedList.removeNth: "+t);if(1===this.size)return this.head=null,this.tail=null,void(this.size=0);var e=this.head;if(0===t)return this.head=e.next,this.head.prev=null,e=null,void--this.size;if(t===this.size-1)return e=this.tail,this.tail=e.prev,this.tail.next=null,e=null,--this.size,!0;e=e.next;for(var i=1;i0)throw new Error("Null head in an unemptied list. Please report this to https://github.com/nickzuber/needle/issues");for(var e=this.head,i=!1;null!==e;){if(JSON.stringify(e.data)===JSON.stringify(t)){i=!0;break}e=e.next}return!!i&&e},r.prototype.findNth=function(t){if("undefined"==typeof t)throw new TypeError("Too few arguments for DoublyLinkedList.findNth");if("number"!=typeof t)throw new TypeError("Invalid argument for DoublyLinkedList.findNth");if(t<0||t>=this.size)throw new Error("Index out of bounds; attempted to find a node from a SinglyLinkedList that does not exist");if(null===this.head&&this.size>0)throw new Error("Null head in an unemptied list. Please report this to https://github.com/nickzuber/needle/issues");for(var e=this.head,i=0;i0)for(var e=0;e0?parseInt(t):void 0};const s=2147483647,h=function(t){if("undefined"==typeof t)throw new Error("Too few arguments in RollingHash constructor");if("number"!=typeof t)throw new TypeError("Invalid argument; expected a number in RollingHash constructor");this.BASE=t,this.state=0,this.CACHE=1,this.BUFFER_SIZE=Math.log(t)*Math.LOG10E+1|0,this.INVERSE_BASE=n(this.BASE,s)%s,this.OFFSET_IF_NEGATIVE=s*this.BASE};h.prototype.hash=function(t){if("undefined"==typeof t)throw new Error("Too few arguments in RollingHash.hash");if(!parseInt(Math.pow(this.BASE,t.length-1)))throw new Error('Integer overflow while trying to hash "'+t+'" in RollingHash.hash\nThis hashing window is too large\nIf this issue is breaking to your program, please report this to https://github.com/nickzuber/needle/issues');var e=0;if("string"==typeof t)for(var i=0;i=this.size&&0!==t)throw new Error("Index out of bounds on SinglyLinkedList.insertNth");if(0===t)return void this.insertFront(e);if(null===this.head)return!1;for(var i=new n(e),r=this.head,o=1;o0)throw new Error("Null head in an unemptied list. Please report this to https://github.com/nickzuber/needle/issues");var e,i,n=null,r=this.head,o=!1;if(i="object"==typeof t?JSON.stringify(t):t,e="object"==typeof r.data?JSON.stringify(r.data):r.data,e===i)return this.head=r.next,r=null,--this.size,!0;for(n=r,r=n.next;null!==r;){if(e="object"==typeof r.data?JSON.stringify(r.data):r.data,e===i){o=!0,n.next=r.next,r=null,--this.size;break}n=r,r=r.next}return o},r.prototype.removeNth=function(t){if("undefined"==typeof t)throw new Error("Too few arguments for SinglyLinkedList.removeNth");if("number"!=typeof t)throw new TypeError("Invalid argument for SinglyLinkedList.removeNth");if(t<0||t>=this.size)throw new Error("Index out of bounds on SinglyLinkedList.removeNth: "+t);if(1===this.size)return this.head=null,void(this.size=0);var e=null,i=this.head;if(0===t)return this.head=i.next,i=null,void--this.size;e=i,i=i.next;for(var n=1;n0)throw new Error("Null head in an unemptied list. Please report this to https://github.com/nickzuber/needle/issues");for(var e=this.head,i=!1;null!==e;){if(JSON.stringify(e.data)===JSON.stringify(t)){i=!0;break}e=e.next}return!!i&&e},r.prototype.findNth=function(t){if("undefined"==typeof t)throw new TypeError("Too few arguments for SinglyLinkedList.findNth");if("number"!=typeof t)throw new TypeError("Invalid argument for SinglyLinkedList.findNth");if(t<0||t>=this.size)throw new Error("Index out of bounds; attempted to find a node from a SinglyLinkedList that does not exist");if(null===this.head&&this.size>0)throw new Error("Null head in an unemptied list. Please report this to https://github.com/nickzuber/needle/issues");for(var e=this.head,i=0;i1&&!r(t,this.elements[n]);)n=Math.floor(e+(i-e)/2),o(this.elements[n],t,this.compare)?e=n:i=n;o(t,this.elements[n],this.compare)?this.elements.splice(n,0,t):this.elements.splice(n+1,0,t)},s.prototype["delete"]=function(t){if("undefined"==typeof t)throw new Error("Too few arguments in SortedArray.delete");if(0===this.elements.length)return!1;for(var e=0,i=this.elements.length,n=Math.floor(e+(i-e)/2);i>=e;){if(n=Math.floor(e+(i-e)/2),r(t,this.elements[n]))return this.elements.splice(n,1),!0;o(this.elements[n],t,this.compare)?e=n+1:i=n-1}return!1},s.prototype.get=function(t){if("undefined"==typeof t)throw new Error("Too few arguments in SortedArray.get");if(0==typeof t)throw new Error("Invalid argument; expected a number in SortedArray.get");return this.elements[t]},s.prototype.size=function(){return this.elements.length},s.prototype.toString=function(){var t,e="";for(t=0;t0?e.slice(0,-1):e},e.exports=s},{}],25:[function(t,e,i){"use strict";const n=t("./stack");e.exports=n},{"./stack":26}],26:[function(t,e,i){"use strict";const n=t("../Nodes/unidirectional_node.js"),r=function(t){this.top,this.size,"undefined"!=typeof t?(this.top=new n(t),this.size=1):(this.top=null,this.size=0)};r.prototype.peek=function(){return this.top},r.prototype.push=function(t){if("undefined"==typeof t)throw new Error("Too few arguments in Stack.push");var e=new n(t),i=this.top;this.top=e,this.top.next=i,++this.size},r.prototype.pop=function(){if(0===this.size)throw new Error("Attempted to remove from empty stack in Stack.pop");var t=this.top.next,e=this.top;return this.top=t,--this.size,e},e.exports=r},{"../Nodes/unidirectional_node.js":16}],27:[function(t,e,i){"use strict";const n=t("./SinglyLinkedList"),r=t("./Queue"),o=t("./Stack"),s=t("./DoublyLinkedList"),h=t("./BinaryHeap"),a=t("./BinarySearchTree"),u=t("./Hashmap"),f=t("./SortedArray"),p=t("./RollingHash"),d=t("./BitArray"),l=t("./KaryTree"),y={};y.SinglyLinkedList=n,y.Queue=r,y.Stack=o,y.DoublyLinkedList=s,y.BinaryHeap=h,y.BinarySearchTree=a,y.Hashmap=u,y.SortedArray=f,y.RollingHash=p,y.BitArray=d,y.KaryTree=l,i=e.exports=y,"undefined"!=typeof window&&(window.Needle=y)},{"./BinaryHeap":2,"./BinarySearchTree":4,"./BitArray":6,"./DoublyLinkedList":8,"./Hashmap":10,"./KaryTree":12,"./Queue":17,"./RollingHash":19,"./SinglyLinkedList":21,"./SortedArray":23,"./Stack":25}]},{},[27]); \ No newline at end of file diff --git a/docs/doxide_output.md b/docs/doxide_output.md new file mode 100644 index 0000000..7d8efc8 --- /dev/null +++ b/docs/doxide_output.md @@ -0,0 +1,210 @@ + - **swap**(< _number_ >second, < _number_ >first) - *void* - + + - **defaultCompare**(< _number_ >second, < _number_ >first) - *boolean* - + + - **safeCompare**(< _function_ >the, < _number_ >second, < _number_ >first) - *boolean* - + + - **BinaryHeap**(< _function_ >[compare]) - *void* - Single argument constructor. + + - **peek**(< _void_ >) - *any* - Returns the min node of the heap. + + - **getParent**(< _number_ >index) - *any* - Returns the parent element of a given index in the heap. + + - **getLeftChild**(< _number_ >index) - *any* - Returns the left child element of a given index in the heap. + + - **getRightChild**(< _number_ >index) - *any* - Returns the right child element of a given index in the heap. + + - **size**(< _void_ >) - *number* - Returns the size of the heap. + + - **insert**(< _any_ >the) - *void* - Inserts a Node into the heap. + + - **delete**(< _number_ >if) - *void* - Removes the min in the heap and reorders heap with new min. + + - **_heapify**(< _number_ >the) - *void* - Actually does the heapify-ing. + + - **heapify**(< _number_ >the) - *array* - Reorganizes the input array into a legal binary heap. + + - **defaultCompare**(< _number_ >second, < _number_ >first) - *boolean* - + + - **safeCompare**(< _function_ >the, < _number_ >second, < _number_ >first) - *boolean* - + + - **BinarySearchTree**(< _function_ >[compare]) - *void* - Single argument constructor. + + - **hasRight**(< _Node_ >the) - *boolean* - Checks if the given node has a right branch. + + - **hasLeft**(< _Node_ >the) - *boolean* - Checks if the given node has a left branch. + + - **isLeaf**(< _Node_ >the) - *boolean* - Checks if the given node is a leaf. + + - **emptySubtree**(< _Node_ >the) - *void* - Empties the subtree of the given node. + + - **emptyTree**(< _void_ >) - *void* - Empties the entire tree. + + - **heightSubtree**(< _Node_ >the) - *number* - Find the height of a subtree. + + - **numNodesSubtree**(< _Node_ >the) - *number* - Find the number of nodes in a subtree. + + - **numLeavesSubtree**(< _Node_ >the) - *number* - Find the number of leaves in a subtree. + + - **insert**(< _Node_ >[node], < _any_ >the) - *void* - Insert a node into the tree. + + - **search**(< _Node_ >[node], < _any_ >the) - *Node || false* - Search for a node in the tree. + + - **shred**(< _any_ >input) - *number* - Transforms input into a number. + + - **BitArray**(< _number_ >[size) - *void* - Instantiates a bit array with given size. + + - **set**(< _boolean_ >the, < _number_ >the) - *void* - _no description provided_ + + - **get**(< _number_ >the) - *number* - Returns the bit from the bit array at desired location. + + - **size**(< _void_ >) - *number* - Returns the size of the bit array. + + - **resize**(< _number_ >the) - *void* - Adjusts the size of the bit array. + + - **complement**(< _BitArray_ >[bitarray) - *BitArray* - Resolve the complement bit array. + + - **union**(< _BitArray_ >[bitarray) - *BitArray* - Resolve the union bit array. + + - **intersection**(< _BitArray_ >[bitarray) - *BitArray* - Resolve the intersection bit array. + + - **difference**(< _BitArray_ >[bitarray) - *BitArray* - Resolve the difference bit array. + + - **toString**(< _void_ >) - *string* - Converts the bit array into a string of bits. + + - **DoublyLinkedList**(< _any_ >[data]) - *void* - Single argument constructor. + + - **insertFront**(< _any_ >data) - *void* - Create a node from given data and insert to front of linked list. + + - **insertNth**(< _any_ >data, < _number_ >position) - *void* - Create a node from given data and insert in given location of linked list. + + - **insertAfter**(< _any_ >data, < _any_ >the) - *boolean* - Create a node from given data and inserts after a given node. of linked list. + + - **insertBack**(< _any_ >data) - *void* - Create a node from given data and insert to end of linked list. + + - **remove**(< _any_ >data) - *boolean* - Remove a node based on its given data + + - **removeNth**(< _number_ >index) - *void* - Remove a node based on the given position in the linked list + + - **find**(< _any_ >data) - *boolean || Node* - Find a node by a given value + + - **hash**(< _any_ >the) - *number* - + + - **removeCustom**(< _DoublyLinkedList_ >the, < _any_ >the) - *void* - + + - **Hashmap**(< _void_ >) - *void* - No argument constructor. + + - **put**(< _any_ >the, < _any_ >the) - *void* - Inserts an entry into the hashmap. + + - **get**(< _any_ >the) - * || false* - Returns an entry based on a given key. + + - **delete**(< _any_ >the) - *boolean* - Deletes an entry based on a given key. + + - **next**(< _void_ >) - *key* - Updates the current node to the next node after returning the current node. + + - **iterator**(< _void_ >) - *key* - Resets the internal iterator to the first entry and returns it. + + - **size**(< _void_ >) - *number* - Returns the amount of unique entries within the hashmap. + + - **KaryTree**(< _Node_ >the) - *void* - Creates an empty k-ary tree. + + - **isLeaf**(< _Node_ >the) - *boolean* - Checks if the given node is a leaf. + + - **emptySubtree**(< _Node_ >the) - *void* - Empties the subtree of the given node. + + - **emptyTree**(< _void_ >) - *void* - Empties the entire tree. + + - **search**(< _Node_ >[node], < _any_ >the) - *Node || false* - Search for a node in the tree. + + - **Queue**(< _any_ >[data]) - *void* - Single argument constructor. + + - **enqueue**(< _any_ >data) - *void* - Creates a node with the given data and adds that node to the back of the queue + + - **dequeue**(< _void_ >) - *void* - Removes the node at the front of the queue + + - **modInverse**(< _number_ >the, < _number_ >the) - *number* - + + - **gcd**(< _number_ >second, < _number_ >first) - *number* - + + - **safePOW**(< _number_ >the, < _number_ >the, < _number_ >the) - *number* - + + - **ascii**(< _string_ >the) - *number* - + + - **RollingHash**(< _number_ >the) - *void* - Single argument constructor which defines the base of the working + + - **hash**(< _number || string || Array_ >the) - *number* - Computes a hash on the input assuming it is of the same base of the instance of the rolling hash. + + - **append**(< _string || number_ >the) - *void* - Appends a new segment onto the rolling hash window. + + - **skip**(< _string || number_ >the) - *void* - Disjoins the trailing segment of rolling hash window. + + - **slide**(< _string || number_ >the, < _string || number_ >the) - *number* - Shifts the window over by one iteration and returns the new internal hash value. + + - **set**(< _string || Array_ >either) - *number* - Sets the internal window of the rolling hash. Usually set with the beginning elements that fit within the window of the item to find. + + - **SinglyLinkedList**(< _any_ >[data]) - *void* - Single argument constructor. + + - **insertFront**(< _any_ >data) - *void* - Create a node from given data and insert to front of linked list. + + - **insertNth**(< _any_ >data, < _number_ >position) - *void* - Create a node from given data and insert in given location of linked list. + + - **insertAfter**(< _any_ >data, < _any_ >the) - *boolean* - Create a node from given data and inserts after a given node. + + - **insertBack**(< _any_ >data) - *void* - Create a node from given data and insert to end of linked list. + + - **remove**(< _any_ >data) - *boolean* - Remove a node based on its given data + + - **removeNth**(< _number_ >index) - *void* - Remove a node based on the given position in the linked list + + - **find**(< _any_ >data) - *boolean || Node* - Find a node by a given value + + - **defaultCompare**(< _number_ >second, < _number_ >first) - *boolean* - + + - **equal**(< _any_ >second, < _any_ >first) - *boolean* - + + - **safeCompare**(< _function_ >the, < _number_ >second, < _number_ >first) - *boolean* - + + - **SortedArray**(< _function_ >[compare]) - *void* - Single argument constructor. + + - **insert**(< _any_ >the) - *void* - Adds an element into the array in its sorted position. + + - **delete**(< _any_ >the) - *boolean* - Deletes the first occurance of an element from the array. + + - **get**(< _number_ >index) - *element* - Returns the element at the given index. + + - **size**(< _void_ >) - *number* - Returns the amount of elements in the sorted array. + + - **toString**(< _void_ >) - *string* - + + - **Stack**(< _any_ >[data]) - *void* - Single argument constructor. + + - **peek**(< _void_ >) - *Node* - Returns the top of the stack. + + - **push**(< _any_ >data) - *void* - Creates a node with the given data and adds that node to the top of the stack + + - **pop**(< _void_ >) - *Node* - Removes the node at the top of the stack. + +### Needle.Multidirectional_Tree_Node() +**data** - *any* - Any data for the node to hold.
+**children** - *Array* - The set of Multidirectional_Tree_Node which are direct children to this node.
+ + - **Multidirectional_Tree_Node**(< _any_ >data) - *void* - Creates a multidirectional tree node. + + - **appendChild**(< _any_ >data) - *void* - Appends data as a node as a direct child to the tree. + +### Needle.Bidirectional_Tree_Node() +**data** - *any* - Any data for the node to hold.
+**right** - *Bidirectional_Tree_Node* - Points to the right child node.
+**left** - *Bidirectional_Tree_Node* - Points to the left child node.
+ + - **Bidirectional_Tree_Node**(< _any_ >data) - *void* - Constructs a bidirectional tree node. + +### Needle.Bidirectional_Node() +**data** - *any* - Any data for the node to hold.
+**next** - *Bidirectional_node* - Points to the next node.
+**prev** - *Bidirectional_node* - Points to the previous node.
+ + - **Bidirectional_Node**(< _any_ >data) - *void* - Constructs a bidirectional node. + + - **Unidirectional_Node**(< _any_ >data) - *void* - Constructs a unidirectional node. + diff --git a/doxyfile.json b/doxyfile.json new file mode 100644 index 0000000..9fd0a1d --- /dev/null +++ b/doxyfile.json @@ -0,0 +1,6 @@ +{ + "targets" : [ + "./src" + ], + "output" : "./docs/doxide_output.md" +} diff --git a/examples/scripts/needle.min.js b/examples/scripts/needle.min.js index b26e905..2072473 100644 --- a/examples/scripts/needle.min.js +++ b/examples/scripts/needle.min.js @@ -2,4 +2,4 @@ // node-needle v0.1.9 | MIT // Copyright (c) 2016 Nick Zuber */ -!function t(e,i,n){function r(s,h){if(!i[s]){if(!e[s]){var a="function"==typeof require&&require;if(!h&&a)return a(s,!0);if(o)return o(s,!0);throw new Error("Cannot find module '"+s+"'")}var u=i[s]={exports:{}};e[s][0].call(u.exports,function(t){var i=e[s][1][t];return r(i?i:t)},u,u.exports,t,e,i,n)}return i[s].exports}for(var o="function"==typeof require&&require,s=0;s1;)r(this.heap[e],this.heap[Math.floor(e/2)],this.compare)&&this.heap.swap(e,Math.floor(e/2)),e=Math.floor(e/2)},o.prototype["delete"]=function(t){if("number"==typeof t?++t:t=1,"number"!=typeof t)throw new TypeError("Expected a number as argument in BinaryHeap.delete");if(t<0||t>=this.heap.length)throw new Error("Index out of bounds in BinaryHeap.delete");if(this.heap.length<=1)throw new Error("Attempted to remove min element from an empty heap in BinaryHeap.delete");if(2===this.heap.length)return void this.heap.pop();if(this.heap[t]=this.heap.pop(),2===this.heap.length);else if(3===this.heap.length){var t=1;r(this.heap[2*t],this.heap[t],this.compare)&&this.heap.swap(t,2*t)}else for(var e=0,t=1;r(this.heap[2*t],this.heap[t],this.compare)||r(this.heap[2*t+1],this.heap[t],this.compare);){var i;if(i=r(this.heap[2*t],this.heap[2*t+1],this.compare)||"undefined"==typeof this.heap[2*t+1]?2*t:2*t+1,this.heap.swap(t,i),t=i,++e,e>1e3)throw new Error("Timeout error in BinaryHeap.delete. Please report this to https://github.com/nickzuber/needle/issues")}},o.prototype._heapify=function(t){var e=2*t,i=e+1,n=t;this.heap.length;e=1;--e)this._heapify(e);console.log(this.heap)},e.exports=o},{}],2:[function(t,e,i){"use strict";const n=t("./binaryHeap");e.exports=n},{"./binaryHeap":1}],3:[function(t,e,i){"use strict";function n(t,e){return t=this.data.length*r)throw new Error("Index out of bounds in BitArray.set");var i=Math.floor(t++/r);e?this.data[i]|=1<=this.data.length*r)throw new Error("Index out of bounds in BitArray.get");var e=Math.floor(t++/r),i=this.data[e];return i>>r-t&1},o.prototype.size=function(){return this.data.length*r},o.prototype.resize=function(t){if("number"!=typeof bitarray)throw new TypeError("");return this.data.length*r},o.prototype.complement=function(t){"undefined"==typeof t?t=this:t instanceof o||(t=new o(t));var e=new o;return t.data.map(function(t){e.data.push(~t)}),e},o.prototype.union=function(t){if("undefined"==typeof t)throw new Error("Undefined bitarray argument in BitArray.union");if(!(t instanceof o))throw new TypeError("Invalid argument: expected BitArray as an argument in BitArray.union");if(t.size()!==this.size())throw new Error("BitArrays must be of same size to resolve a union in BitArray.union");for(var e=new o,i=0;i>>31),e<<=1;t.split("").reverse().join("")}),t},e.exports=o},{}],6:[function(t,e,i){"use strict";const n=t("./bitArray");e.exports=n},{"./bitArray":5}],7:[function(t,e,i){"use strict";const n=t("../__Nodes__/bidirectional_node.js"),r=function(t){this.head,this.tail,this.size,"undefined"!=typeof t?(this.head=new n(t),this.tail=this.head,this.size=1):(this.head=null,this.tail=null,this.size=0)};r.prototype.insertFront=function(t){if("undefined"==typeof t)throw new Error("Too few arguments for DoublyLinkedList.insertFront");var e=new n(t);if(null===this.head&&null===this.tail)this.head=e,this.tail=this.head;else{if(null===this.head||null===this.tail)throw new Error("Unsynced head and tail in an Doubly Linked List. Please report this to https://github.com/nickzuber/needle/issues");var i=this.head;i.prev=e,this.head=e,this.head.next=i,this.head.prev=null}++this.size},r.prototype.insertNth=function(t,e){if("undefined"==typeof e||"undefined"==typeof t)throw new Error("Too few arguments for DoublyLinkedList.insertNth");if("number"!=typeof t)throw new TypeError("Invalid argument for DoublyLinkedList.insertNth");if(t<0||t>=this.size&&0!==t)throw new Error("Index out of bounds on DoublyLinkedList.insertNth");if(0===t)return void this.insertFront(e);if(null===this.head)return!1;if(t===this.size-1)return void this.insertBack(e);for(var i=new n(e),r=this.head,o=1;o0)throw new Error("Null head in an unemptied list. Please report this to https://github.com/nickzuber/needle/issues");var e,i,n=this.head,r=!1;if(i="object"==typeof t?JSON.stringify(t):t,e="object"==typeof n.data?JSON.stringify(n.data):n.data,JSON.stringify(this.head.data)===JSON.stringify(t))return this.head=n.next,this.head.prev=null,n=null,--this.size,!0;if(JSON.stringify(this.tail.data)===JSON.stringify(t))return n=this.tail,this.tail=n.prev,this.tail.next=null,n=null,--this.size,!0;for(n=n.next;null!==n;){if(e="object"==typeof n.data?JSON.stringify(n.data):n.data,e===i){r=!0;var o=n.prev;o.next=n.next,n.next.prev=o,n=null,--this.size;break}n=n.next}return r},r.prototype.removeNth=function(t){if("undefined"==typeof t)throw new Error("Too few arguments for DoublyLinkedList.removeNth");if("number"!=typeof t)throw new TypeError("Invalid argument for DoublyLinkedList.removeNth");if(t<0||t>=this.size)throw new Error("Index out of bounds on DoublyLinkedList.removeNth: "+t);if(1===this.size)return this.head=null,this.tail=null,void(this.size=0);var e=this.head;if(0===t)return this.head=e.next,this.head.prev=null,e=null,void--this.size;if(t===this.size-1)return e=this.tail,this.tail=e.prev,this.tail.next=null,e=null,--this.size,!0;e=e.next;for(var i=1;i0)throw new Error("Null head in an unemptied list. Please report this to https://github.com/nickzuber/needle/issues");for(var e=this.head,i=!1;null!==e;){if(JSON.stringify(e.data)===JSON.stringify(t)){i=!0;break}e=e.next}return!!i&&e},r.prototype.findNth=function(t){if("undefined"==typeof t)throw new TypeError("Too few arguments for DoublyLinkedList.findNth");if("number"!=typeof t)throw new TypeError("Invalid argument for DoublyLinkedList.findNth");if(t<0||t>=this.size)throw new Error("Index out of bounds; attempted to find a node from a SinglyLinkedList that does not exist");if(null===this.head&&this.size>0)throw new Error("Null head in an unemptied list. Please report this to https://github.com/nickzuber/needle/issues");for(var e=this.head,i=0;i0)for(var e=0;e0?parseInt(t):void 0};const s=2147483647,h=function(t){if("undefined"==typeof t)throw new Error("Too few arguments in RollingHash constructor");if("number"!=typeof t)throw new TypeError("Invalid argument; expected a number in RollingHash constructor");this.BASE=t,this.state=0,this.CACHE=1,this.BUFFER_SIZE=Math.log(t)*Math.LOG10E+1|0,this.INVERSE_BASE=n(this.BASE,s)%s,this.OFFSET_IF_NEGATIVE=s*this.BASE};h.prototype.hash=function(t){if("undefined"==typeof t)throw new Error("Too few arguments in RollingHash.hash");if(!parseInt(Math.pow(this.BASE,t.length-1)))throw new Error('Integer overflow while trying to hash "'+t+'" in RollingHash.hash\nThis hashing window is too large\nIf this issue is breaking to your program, please report this to https://github.com/nickzuber/needle/issues');var e=0;if("string"==typeof t)for(var i=0;i=this.size&&0!==t)throw new Error("Index out of bounds on SinglyLinkedList.insertNth");if(0===t)return void this.insertFront(e);if(null===this.head)return!1;for(var i=new n(e),r=this.head,o=1;o0)throw new Error("Null head in an unemptied list. Please report this to https://github.com/nickzuber/needle/issues");var e,i,n=null,r=this.head,o=!1;if(i="object"==typeof t?JSON.stringify(t):t,e="object"==typeof r.data?JSON.stringify(r.data):r.data,e===i)return this.head=r.next,r=null,--this.size,!0;for(n=r,r=n.next;null!==r;){if(e="object"==typeof r.data?JSON.stringify(r.data):r.data,e===i){o=!0,n.next=r.next,r=null,--this.size;break}n=r,r=r.next}return o},r.prototype.removeNth=function(t){if("undefined"==typeof t)throw new Error("Too few arguments for SinglyLinkedList.removeNth");if("number"!=typeof t)throw new TypeError("Invalid argument for SinglyLinkedList.removeNth");if(t<0||t>=this.size)throw new Error("Index out of bounds on SinglyLinkedList.removeNth: "+t);if(1===this.size)return this.head=null,void(this.size=0);var e=null,i=this.head;if(0===t)return this.head=i.next,i=null,void--this.size;e=i,i=i.next;for(var n=1;n0)throw new Error("Null head in an unemptied list. Please report this to https://github.com/nickzuber/needle/issues");for(var e=this.head,i=!1;null!==e;){if(JSON.stringify(e.data)===JSON.stringify(t)){i=!0;break}e=e.next}return!!i&&e},r.prototype.findNth=function(t){if("undefined"==typeof t)throw new TypeError("Too few arguments for SinglyLinkedList.findNth");if("number"!=typeof t)throw new TypeError("Invalid argument for SinglyLinkedList.findNth");if(t<0||t>=this.size)throw new Error("Index out of bounds; attempted to find a node from a SinglyLinkedList that does not exist");if(null===this.head&&this.size>0)throw new Error("Null head in an unemptied list. Please report this to https://github.com/nickzuber/needle/issues");for(var e=this.head,i=0;i1&&!r(t,this.elements[n]);)n=Math.floor(e+(i-e)/2),o(this.elements[n],t,this.compare)?e=n:i=n;o(t,this.elements[n],this.compare)?this.elements.splice(n,0,t):this.elements.splice(n+1,0,t)},s.prototype["delete"]=function(t){if("undefined"==typeof t)throw new Error("Too few arguments in SortedArray.delete");if(0===this.elements.length)return!1;for(var e=0,i=this.elements.length,n=Math.floor(e+(i-e)/2);i>=e;){if(n=Math.floor(e+(i-e)/2),r(t,this.elements[n]))return this.elements.splice(n,1),!0;o(this.elements[n],t,this.compare)?e=n+1:i=n-1}return!1},s.prototype.get=function(t){if("undefined"==typeof t)throw new Error("Too few arguments in SortedArray.get");if(0==typeof t)throw new Error("Invalid argument; expected a number in SortedArray.get");return this.elements[t]},s.prototype.size=function(){return this.elements.length},s.prototype.toString=function(){var t,e="";for(t=0;t0?e.slice(0,-1):e},e.exports=s},{}],21:[function(t,e,i){"use strict";const n=t("./stack");e.exports=n},{"./stack":22}],22:[function(t,e,i){"use strict";const n=t("../__Nodes__/unidirectional_node.js"),r=function(t){this.top,this.size,"undefined"!=typeof t?(this.top=new n(t),this.size=1):(this.top=null,this.size=0)};r.prototype.peek=function(){return this.top},r.prototype.push=function(t){if("undefined"==typeof t)throw new Error("Too few arguments in Stack.push");var e=new n(t),i=this.top;this.top=e,this.top.next=i,++this.size},r.prototype.pop=function(){if(0===this.size)throw new Error("Attempted to remove from empty stack in Stack.pop");var t=this.top.next,e=this.top;return this.top=t,--this.size,e},e.exports=r},{"../__Nodes__/unidirectional_node.js":26}],23:[function(t,e,i){"use strict";const n=function(t){this.data=t||void 0,this.next=null,this.prev=null};e.exports=n},{}],24:[function(t,e,i){"use strict";const n=function(t){this.data=t||void 0,this.right=null,this.left=null};e.exports=n},{}],25:[function(t,e,i){"use strict";const n=function(t){this.data=t||void 0,this.children=[]};n.prototype.appendChild=function(t){this.children.push(new n(t))},e.exports=n},{}],26:[function(t,e,i){"use strict";const n=function(t){this.data=t||void 0,this.next=null};e.exports=n},{}],27:[function(t,e,i){"use strict";const n=t("./SinglyLinkedList"),r=t("./Queue"),o=t("./Stack"),s=t("./DoublyLinkedList"),h=t("./BinaryHeap"),a=t("./BinarySearchTree"),u=t("./Hashmap"),f=t("./SortedArray"),p=t("./RollingHash"),d=t("./BitArray"),l=t("./KaryTree"),y={};y.SinglyLinkedList=n,y.Queue=r,y.Stack=o,y.DoublyLinkedList=s,y.BinaryHeap=h,y.BinarySearchTree=a,y.Hashmap=u,y.SortedArray=f,y.RollingHash=p,y.BitArray=d,y.KaryTree=l,i=e.exports=y,"undefined"!=typeof window&&(window.Needle=y)},{"./BinaryHeap":2,"./BinarySearchTree":4,"./BitArray":6,"./DoublyLinkedList":8,"./Hashmap":10,"./KaryTree":12,"./Queue":13,"./RollingHash":15,"./SinglyLinkedList":17,"./SortedArray":19,"./Stack":21}]},{},[27]); \ No newline at end of file +!function t(e,i,n){function r(s,h){if(!i[s]){if(!e[s]){var a="function"==typeof require&&require;if(!h&&a)return a(s,!0);if(o)return o(s,!0);throw new Error("Cannot find module '"+s+"'")}var u=i[s]={exports:{}};e[s][0].call(u.exports,function(t){var i=e[s][1][t];return r(i?i:t)},u,u.exports,t,e,i,n)}return i[s].exports}for(var o="function"==typeof require&&require,s=0;s1;)r(this.heap[e],this.heap[Math.floor(e/2)],this.compare)&&this.heap.swap(e,Math.floor(e/2)),e=Math.floor(e/2)},o.prototype["delete"]=function(t){if("number"==typeof t?++t:t=1,"number"!=typeof t)throw new TypeError("Expected a number as argument in BinaryHeap.delete");if(t<0||t>=this.heap.length)throw new Error("Index out of bounds in BinaryHeap.delete");if(this.heap.length<=1)throw new Error("Attempted to remove min element from an empty heap in BinaryHeap.delete");if(2===this.heap.length)return void this.heap.pop();if(this.heap[t]=this.heap.pop(),2===this.heap.length);else if(3===this.heap.length){var t=1;r(this.heap[2*t],this.heap[t],this.compare)&&this.heap.swap(t,2*t)}else for(var e=0,t=1;r(this.heap[2*t],this.heap[t],this.compare)||r(this.heap[2*t+1],this.heap[t],this.compare);){var i;if(i=r(this.heap[2*t],this.heap[2*t+1],this.compare)||"undefined"==typeof this.heap[2*t+1]?2*t:2*t+1,this.heap.swap(t,i),t=i,++e,e>1e3)throw new Error("Timeout error in BinaryHeap.delete. Please report this to https://github.com/nickzuber/needle/issues")}},o.prototype._heapify=function(t){var e=2*t,i=e+1,n=t;this.heap.length;e=1;--e)this._heapify(e);console.log(this.heap)},e.exports=o},{}],2:[function(t,e,i){"use strict";const n=t("./binaryHeap");e.exports=n},{"./binaryHeap":1}],3:[function(t,e,i){"use strict";function n(t,e){return t=this.data.length*r)throw new Error("Index out of bounds in BitArray.set");var i=Math.floor(t++/r);e?this.data[i]|=1<=this.data.length*r)throw new Error("Index out of bounds in BitArray.get");var e=Math.floor(t++/r),i=this.data[e];return i>>r-t&1},o.prototype.size=function(){return this.data.length*r},o.prototype.resize=function(t){if("number"!=typeof bitarray)throw new TypeError("");return this.data.length*r},o.prototype.complement=function(t){"undefined"==typeof t?t=this:t instanceof o||(t=new o(t));var e=new o;return t.data.map(function(t){e.data.push(~t)}),e},o.prototype.union=function(t){if("undefined"==typeof t)throw new Error("Undefined bitarray argument in BitArray.union");if(!(t instanceof o))throw new TypeError("Invalid argument: expected BitArray as an argument in BitArray.union");if(t.size()!==this.size())throw new Error("BitArrays must be of same size to resolve a union in BitArray.union");for(var e=new o,i=0;i>>31),e<<=1;t.split("").reverse().join("")}),t},e.exports=o},{}],6:[function(t,e,i){"use strict";const n=t("./bitArray");e.exports=n},{"./bitArray":5}],7:[function(t,e,i){"use strict";const n=t("../Nodes/bidirectional_node.js"),r=function(t){this.head,this.tail,this.size,"undefined"!=typeof t?(this.head=new n(t),this.tail=this.head,this.size=1):(this.head=null,this.tail=null,this.size=0)};r.prototype.insertFront=function(t){if("undefined"==typeof t)throw new Error("Too few arguments for DoublyLinkedList.insertFront");var e=new n(t);if(null===this.head&&null===this.tail)this.head=e,this.tail=this.head;else{if(null===this.head||null===this.tail)throw new Error("Unsynced head and tail in an Doubly Linked List. Please report this to https://github.com/nickzuber/needle/issues");var i=this.head;i.prev=e,this.head=e,this.head.next=i,this.head.prev=null}++this.size},r.prototype.insertNth=function(t,e){if("undefined"==typeof e||"undefined"==typeof t)throw new Error("Too few arguments for DoublyLinkedList.insertNth");if("number"!=typeof t)throw new TypeError("Invalid argument for DoublyLinkedList.insertNth");if(t<0||t>=this.size&&0!==t)throw new Error("Index out of bounds on DoublyLinkedList.insertNth");if(0===t)return void this.insertFront(e);if(null===this.head)return!1;if(t===this.size-1)return void this.insertBack(e);for(var i=new n(e),r=this.head,o=1;o0)throw new Error("Null head in an unemptied list. Please report this to https://github.com/nickzuber/needle/issues");var e,i,n=this.head,r=!1;if(i="object"==typeof t?JSON.stringify(t):t,e="object"==typeof n.data?JSON.stringify(n.data):n.data,JSON.stringify(this.head.data)===JSON.stringify(t))return this.head=n.next,this.head.prev=null,n=null,--this.size,!0;if(JSON.stringify(this.tail.data)===JSON.stringify(t))return n=this.tail,this.tail=n.prev,this.tail.next=null,n=null,--this.size,!0;for(n=n.next;null!==n;){if(e="object"==typeof n.data?JSON.stringify(n.data):n.data,e===i){r=!0;var o=n.prev;o.next=n.next,n.next.prev=o,n=null,--this.size;break}n=n.next}return r},r.prototype.removeNth=function(t){if("undefined"==typeof t)throw new Error("Too few arguments for DoublyLinkedList.removeNth");if("number"!=typeof t)throw new TypeError("Invalid argument for DoublyLinkedList.removeNth");if(t<0||t>=this.size)throw new Error("Index out of bounds on DoublyLinkedList.removeNth: "+t);if(1===this.size)return this.head=null,this.tail=null,void(this.size=0);var e=this.head;if(0===t)return this.head=e.next,this.head.prev=null,e=null,void--this.size;if(t===this.size-1)return e=this.tail,this.tail=e.prev,this.tail.next=null,e=null,--this.size,!0;e=e.next;for(var i=1;i0)throw new Error("Null head in an unemptied list. Please report this to https://github.com/nickzuber/needle/issues");for(var e=this.head,i=!1;null!==e;){if(JSON.stringify(e.data)===JSON.stringify(t)){i=!0;break}e=e.next}return!!i&&e},r.prototype.findNth=function(t){if("undefined"==typeof t)throw new TypeError("Too few arguments for DoublyLinkedList.findNth");if("number"!=typeof t)throw new TypeError("Invalid argument for DoublyLinkedList.findNth");if(t<0||t>=this.size)throw new Error("Index out of bounds; attempted to find a node from a SinglyLinkedList that does not exist");if(null===this.head&&this.size>0)throw new Error("Null head in an unemptied list. Please report this to https://github.com/nickzuber/needle/issues");for(var e=this.head,i=0;i0)for(var e=0;e0?parseInt(t):void 0};const s=2147483647,h=function(t){if("undefined"==typeof t)throw new Error("Too few arguments in RollingHash constructor");if("number"!=typeof t)throw new TypeError("Invalid argument; expected a number in RollingHash constructor");this.BASE=t,this.state=0,this.CACHE=1,this.BUFFER_SIZE=Math.log(t)*Math.LOG10E+1|0,this.INVERSE_BASE=n(this.BASE,s)%s,this.OFFSET_IF_NEGATIVE=s*this.BASE};h.prototype.hash=function(t){if("undefined"==typeof t)throw new Error("Too few arguments in RollingHash.hash");if(!parseInt(Math.pow(this.BASE,t.length-1)))throw new Error('Integer overflow while trying to hash "'+t+'" in RollingHash.hash\nThis hashing window is too large\nIf this issue is breaking to your program, please report this to https://github.com/nickzuber/needle/issues');var e=0;if("string"==typeof t)for(var i=0;i=this.size&&0!==t)throw new Error("Index out of bounds on SinglyLinkedList.insertNth");if(0===t)return void this.insertFront(e);if(null===this.head)return!1;for(var i=new n(e),r=this.head,o=1;o0)throw new Error("Null head in an unemptied list. Please report this to https://github.com/nickzuber/needle/issues");var e,i,n=null,r=this.head,o=!1;if(i="object"==typeof t?JSON.stringify(t):t,e="object"==typeof r.data?JSON.stringify(r.data):r.data,e===i)return this.head=r.next,r=null,--this.size,!0;for(n=r,r=n.next;null!==r;){if(e="object"==typeof r.data?JSON.stringify(r.data):r.data,e===i){o=!0,n.next=r.next,r=null,--this.size;break}n=r,r=r.next}return o},r.prototype.removeNth=function(t){if("undefined"==typeof t)throw new Error("Too few arguments for SinglyLinkedList.removeNth");if("number"!=typeof t)throw new TypeError("Invalid argument for SinglyLinkedList.removeNth");if(t<0||t>=this.size)throw new Error("Index out of bounds on SinglyLinkedList.removeNth: "+t);if(1===this.size)return this.head=null,void(this.size=0);var e=null,i=this.head;if(0===t)return this.head=i.next,i=null,void--this.size;e=i,i=i.next;for(var n=1;n0)throw new Error("Null head in an unemptied list. Please report this to https://github.com/nickzuber/needle/issues");for(var e=this.head,i=!1;null!==e;){if(JSON.stringify(e.data)===JSON.stringify(t)){i=!0;break}e=e.next}return!!i&&e},r.prototype.findNth=function(t){if("undefined"==typeof t)throw new TypeError("Too few arguments for SinglyLinkedList.findNth");if("number"!=typeof t)throw new TypeError("Invalid argument for SinglyLinkedList.findNth");if(t<0||t>=this.size)throw new Error("Index out of bounds; attempted to find a node from a SinglyLinkedList that does not exist");if(null===this.head&&this.size>0)throw new Error("Null head in an unemptied list. Please report this to https://github.com/nickzuber/needle/issues");for(var e=this.head,i=0;i1&&!r(t,this.elements[n]);)n=Math.floor(e+(i-e)/2),o(this.elements[n],t,this.compare)?e=n:i=n;o(t,this.elements[n],this.compare)?this.elements.splice(n,0,t):this.elements.splice(n+1,0,t)},s.prototype["delete"]=function(t){if("undefined"==typeof t)throw new Error("Too few arguments in SortedArray.delete");if(0===this.elements.length)return!1;for(var e=0,i=this.elements.length,n=Math.floor(e+(i-e)/2);i>=e;){if(n=Math.floor(e+(i-e)/2),r(t,this.elements[n]))return this.elements.splice(n,1),!0;o(this.elements[n],t,this.compare)?e=n+1:i=n-1}return!1},s.prototype.get=function(t){if("undefined"==typeof t)throw new Error("Too few arguments in SortedArray.get");if(0==typeof t)throw new Error("Invalid argument; expected a number in SortedArray.get");return this.elements[t]},s.prototype.size=function(){return this.elements.length},s.prototype.toString=function(){var t,e="";for(t=0;t0?e.slice(0,-1):e},e.exports=s},{}],25:[function(t,e,i){"use strict";const n=t("./stack");e.exports=n},{"./stack":26}],26:[function(t,e,i){"use strict";const n=t("../Nodes/unidirectional_node.js"),r=function(t){this.top,this.size,"undefined"!=typeof t?(this.top=new n(t),this.size=1):(this.top=null,this.size=0)};r.prototype.peek=function(){return this.top},r.prototype.push=function(t){if("undefined"==typeof t)throw new Error("Too few arguments in Stack.push");var e=new n(t),i=this.top;this.top=e,this.top.next=i,++this.size},r.prototype.pop=function(){if(0===this.size)throw new Error("Attempted to remove from empty stack in Stack.pop");var t=this.top.next,e=this.top;return this.top=t,--this.size,e},e.exports=r},{"../Nodes/unidirectional_node.js":16}],27:[function(t,e,i){"use strict";const n=t("./SinglyLinkedList"),r=t("./Queue"),o=t("./Stack"),s=t("./DoublyLinkedList"),h=t("./BinaryHeap"),a=t("./BinarySearchTree"),u=t("./Hashmap"),f=t("./SortedArray"),p=t("./RollingHash"),d=t("./BitArray"),l=t("./KaryTree"),y={};y.SinglyLinkedList=n,y.Queue=r,y.Stack=o,y.DoublyLinkedList=s,y.BinaryHeap=h,y.BinarySearchTree=a,y.Hashmap=u,y.SortedArray=f,y.RollingHash=p,y.BitArray=d,y.KaryTree=l,i=e.exports=y,"undefined"!=typeof window&&(window.Needle=y)},{"./BinaryHeap":2,"./BinarySearchTree":4,"./BitArray":6,"./DoublyLinkedList":8,"./Hashmap":10,"./KaryTree":12,"./Queue":17,"./RollingHash":19,"./SinglyLinkedList":21,"./SortedArray":23,"./Stack":25}]},{},[27]); \ No newline at end of file diff --git a/examples/views/index.html b/examples/views/index.html index 7e40cfd..6706abb 100644 --- a/examples/views/index.html +++ b/examples/views/index.html @@ -9,14 +9,22 @@ - \ No newline at end of file + diff --git a/gulpfile.js b/gulpfile.js index ebe7aee..070a9d9 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -16,8 +16,10 @@ var banner = ['/*!', // Contacat & compress javascript files gulp.task('dispatch', function(){ - gulp.src(['src/*.js']) - .pipe(browserify({})) + gulp.src(['src/index.js']) + .pipe(browserify({ + entries: ['./index.js'] + })) .pipe(uglify()) .pipe(rename({ basename: 'needle', diff --git a/package.json b/package.json index 19ac427..5af7ef8 100644 --- a/package.json +++ b/package.json @@ -5,12 +5,9 @@ "main": "src/needle.js", "scripts": { "build": "gulp", -<<<<<<< Updated upstream - "dev": "gulp watch", -======= "dev": "gulp && gulp watch || true", "examples": "node ./examples/app.js || true", ->>>>>>> Stashed changes + "dev": "gulp && gulp watch || true", "bench": "node --harmony benchmarks/runTests.js || true", "unit": "node --harmony unit/runTests.js || true", "lint": "./node_modules/.bin/eslint src/*.js || true", diff --git a/src/BinarySearchTree/binarySearchTree.js b/src/BinarySearchTree/binarySearchTree.js index 489c640..54d9947 100644 --- a/src/BinarySearchTree/binarySearchTree.js +++ b/src/BinarySearchTree/binarySearchTree.js @@ -18,14 +18,18 @@ * | search | O(n) | * +------------------------------+ * - * TODO: let user set a custom `equal` function - * */ - 'use strict'; +'use strict'; + +const Node = require('../Nodes/bidirectional_tree_node.js'); -const Node = require('../__Nodes__/bidirectional_tree_node.js'); +const Types = { + LEFT: 'left', + RIGHT: 'right' +} +// @TODO: let user set a custom `compare` function /** @private @default * Compares two elements and returns. * @param {number} first index to compare @@ -206,6 +210,57 @@ BinarySearchTree.prototype.insert = function(data, node){ } } +/** + * Deletes a node from the tree with the value of `data`. + * @param {any} data The data of the node to delete. + * @return {boolean} Returns the success of the deletion success. + */ +BinarySearchTree.prototype.delete = function (data) { + deleteHelper = deleteHelper.bind(this); + return deleteHelper(data, this.root, null, null); +} + +/** + * Deletes a node from the tree with the value of `data`. + * @param {any} data The data of the node to delete. + * @param {Node} node The current node being analyzed. + * @param {Node} nodeType The type of child of the current node being analyzed. + * @param {Node} parentNode The last node that was analyzed. + * @return {boolean} Returns the success of the deletion success. + */ +function deleteHelper (data, node, nodeType, parentNode) { + if (node === null) { + return false; + } + + // @TODO handle object comparisons -- doing a stringify is horrible dont do that + if (data === node.data) { + if (nodeType === Types.RIGHT) { + parentNode.right = null; + } else { + parentNode.left = null; + } + + // Fix tree + if (node.left) { + var nodeRightSubtree = node.right; + parentNode[nodeType] = node.left; + parentNode[nodeType].right = nodeRightSubtree; + } else if (node.right) { + var nodeLeftSubtree = node.left; + parentNode[nodeType] = node.right; + parentNode[nodeType].left = nodeLeftSubtree; + } + return true; + } + + if (safeCompare(data, node.data, this.compare)) { + return deleteHelper(data, node.left, Types.LEFT, node); + } else { + return deleteHelper(data, node.right, Types.RIGHT, node); + } +} + /** * Search for a node in the tree. * @param {*} the data of the node being searched for diff --git a/src/DoublyLinkedList/doublyLinkedList.js b/src/DoublyLinkedList/doublyLinkedList.js index 7a308c9..73814e3 100644 --- a/src/DoublyLinkedList/doublyLinkedList.js +++ b/src/DoublyLinkedList/doublyLinkedList.js @@ -20,7 +20,7 @@ 'use strict'; -const Node = require('../__Nodes__/bidirectional_node.js'); +const Node = require('../Nodes/bidirectional_node.js'); /** * Single argument constructor. diff --git a/src/KaryTree/karyTree.js b/src/KaryTree/karyTree.js index 2b3865b..4bb5315 100644 --- a/src/KaryTree/karyTree.js +++ b/src/KaryTree/karyTree.js @@ -16,7 +16,7 @@ 'use strict'; -const Node = require('../__Nodes__/multidirectional_tree_node.js'); +const Node = require('../Nodes/multidirectional_tree_node.js'); /** * Creates an empty k-ary tree. diff --git a/src/Nodes/bidirectional_node.js b/src/Nodes/bidirectional_node.js new file mode 100644 index 0000000..b65fa0d --- /dev/null +++ b/src/Nodes/bidirectional_node.js @@ -0,0 +1,21 @@ +/** @header + * Bidirectional_Node + * @property {any} data Any data for the node to hold + * @property {Bidirectional_node} next Points to the next node + * @property {Bidirectional_node} prev Points to the previous node + */ + +'use strict'; + +/** @constructor + * Constructs a bidirectional node. + * @param {*} data Any data for the node to hold + * @return {void} + */ +const Bidirectional_Node = function(data){ + this.data = data || undefined; + this.next = null; + this.prev = null; +}; + +module.exports = Bidirectional_Node; diff --git a/src/Nodes/bidirectional_tree_node.js b/src/Nodes/bidirectional_tree_node.js new file mode 100644 index 0000000..c170c3f --- /dev/null +++ b/src/Nodes/bidirectional_tree_node.js @@ -0,0 +1,21 @@ +/** @header + * Bidirectional_Tree_Node + * @property {any} data Any data for the node to hold + * @property {Bidirectional_Tree_Node} right Points to the right child node + * @property {Bidirectional_Tree_Node} left Points to the left child node + */ + +'use strict'; + +/** @constructor + * Constructs a bidirectional tree node. + * @param {*} data Any data for the node to hold + * @return {void} + */ +const Bidirectional_Tree_Node = function(data){ + this.data = data || undefined; + this.right = null; + this.left = null; +}; + +module.exports = Bidirectional_Tree_Node; diff --git a/src/Nodes/multidirectional_tree_node.js b/src/Nodes/multidirectional_tree_node.js new file mode 100644 index 0000000..1f402d6 --- /dev/null +++ b/src/Nodes/multidirectional_tree_node.js @@ -0,0 +1,28 @@ +/** @header + * Multidirectional_Tree_Node + * @property {any} data Any data for the node to hold + * @property {Array} children The set of Multidirectional_Tree_Node which are direct children to this node + */ + +'use strict'; + +/** @constructor + * Creates a multidirectional tree node. + * @param {*} data Any data for the node to hold + * @return {void} + */ +const Multidirectional_Tree_Node = function(data){ + this.data = data || undefined; + this.children = []; +}; + +/** + * Appends data as a node as a direct child to the tree. + * @param {*} data Any data for the node to hold + * @return {void} + */ +Multidirectional_Tree_Node.prototype.appendChild = function(data){ + this.children.push(new Multidirectional_Tree_Node(data)); +}; + +module.exports = Multidirectional_Tree_Node; diff --git a/src/Nodes/unidirectional_node.js b/src/Nodes/unidirectional_node.js new file mode 100644 index 0000000..40683f8 --- /dev/null +++ b/src/Nodes/unidirectional_node.js @@ -0,0 +1,19 @@ +/** + * Unidirectional_Node + * @property {any} data Any data for the node to hold + * @property {Unidirectional_node} next Points to the next node + */ + +'use strict'; + +/** @constructor + * Constructs a unidirectional node. + * @param {*} data Any data for the node to hold + * @return {void} + */ +const Unidirectional_Node = function(data){ + this.data = data || undefined; + this.next = null; +}; + +module.exports = Unidirectional_Node; diff --git a/src/Queue/queue.js b/src/Queue/queue.js index fbe05f6..01c826a 100644 --- a/src/Queue/queue.js +++ b/src/Queue/queue.js @@ -12,7 +12,7 @@ * */ -const Node = require('../__Nodes__/unidirectional_node.js'); +const Node = require('../Nodes/unidirectional_node.js'); /** * Single argument constructor. diff --git a/src/SinglyLinkedList/singlyLinkedList.js b/src/SinglyLinkedList/singlyLinkedList.js index 723940b..c96b35e 100644 --- a/src/SinglyLinkedList/singlyLinkedList.js +++ b/src/SinglyLinkedList/singlyLinkedList.js @@ -19,7 +19,7 @@ 'use strict'; -const Node = require('../__Nodes__/unidirectional_node.js'); +const Node = require('../Nodes/unidirectional_node.js'); /** * Single argument constructor. diff --git a/src/Stack/stack.js b/src/Stack/stack.js index 0066365..57003a1 100644 --- a/src/Stack/stack.js +++ b/src/Stack/stack.js @@ -14,7 +14,7 @@ 'use strict'; -const Node = require('../__Nodes__/unidirectional_node.js'); +const Node = require('../Nodes/unidirectional_node.js'); /** * Single argument constructor. diff --git a/src/__Nodes__/bidirectional_node.js b/src/__Nodes__/bidirectional_node.js deleted file mode 100644 index 558225d..0000000 --- a/src/__Nodes__/bidirectional_node.js +++ /dev/null @@ -1,21 +0,0 @@ -/** - * Basic bidirectional node - * {data} *, any data for the node to hold - * {next} Bidirectional_node, points to the next node - * {prev} Bidirectional_node, points to the previous node - */ - -'use strict'; - -/** - * Single argument constructor. - * @param {*} any data for the node to hold - * @return {void} - */ -const Bidirectional_Node = function(data){ - this.data = data || undefined; - this.next = null; - this.prev = null; -}; - -module.exports = Bidirectional_Node; \ No newline at end of file diff --git a/src/__Nodes__/bidirectional_tree_node.js b/src/__Nodes__/bidirectional_tree_node.js deleted file mode 100644 index 4df2229..0000000 --- a/src/__Nodes__/bidirectional_tree_node.js +++ /dev/null @@ -1,21 +0,0 @@ -/** - * Basic bidirectional tree node - * {data} *, any data for the node to hold - * {right} Bidirectional_Tree_Node, points to the right child node - * {left} Bidirectional_Tree_Node, points to the left child node - */ - -'use strict'; - -/** - * Single argument constructor. - * @param {*} any data for the node to hold - * @return {void} - */ -const Bidirectional_Tree_Node = function(data){ - this.data = data || undefined; - this.right = null; - this.left = null; -}; - -module.exports = Bidirectional_Tree_Node; \ No newline at end of file diff --git a/src/__Nodes__/multidirectional_tree_node.js b/src/__Nodes__/multidirectional_tree_node.js deleted file mode 100644 index 1e64a9a..0000000 --- a/src/__Nodes__/multidirectional_tree_node.js +++ /dev/null @@ -1,23 +0,0 @@ -/** - * Basic multidirectional tree node - * {data} *, any data for the node to hold - * {children} Array, the set of Multidirectional_Tree_Node which are direct children to this node - */ - -'use strict'; - -/** - * Single argument constructor. - * @param {*} any data for the node to hold - * @return {void} - */ -const Multidirectional_Tree_Node = function(data){ - this.data = data || undefined; - this.children = []; -}; - -Multidirectional_Tree_Node.prototype.appendChild = function(data){ - this.children.push(new Multidirectional_Tree_Node(data)); -}; - -module.exports = Multidirectional_Tree_Node; \ No newline at end of file diff --git a/src/__Nodes__/unidirectional_node.js b/src/__Nodes__/unidirectional_node.js deleted file mode 100644 index dee64ff..0000000 --- a/src/__Nodes__/unidirectional_node.js +++ /dev/null @@ -1,19 +0,0 @@ -/** - * Basic unidirectional node - * {data} *, any data for the node to hold - * {next} Unidirectional_node, points to the next node - */ - -'use strict'; - -/** - * Single argument constructor. - * @param {*} any data for the node to hold - * @return {void} - */ -const Unidirectional_Node = function(data){ - this.data = data || undefined; - this.next = null; -}; - -module.exports = Unidirectional_Node; \ No newline at end of file