diff --git a/.nycrc.json b/.nycrc.json index 76620cd..0cbfa5f 100644 --- a/.nycrc.json +++ b/.nycrc.json @@ -2,9 +2,6 @@ "extends": "@istanbuljs/nyc-config-typescript", "all": true, "check-coverage": true, - "exclude": [ - "src/TODO/**/*" - ], "extension": [".ts", ".tsx"], "include": [ "src/**/*" diff --git a/README.md b/README.md index 0454869..83af152 100644 --- a/README.md +++ b/README.md @@ -39,6 +39,12 @@ See [docs/](./docs/README.md) or the [wiki](https://github.com/havelessbemore/da - [LinkedStack](docs/classes/linkedstack.md) - [SkewHeap](docs/classes/skewheap.md) +### Utilities +- [ArrayUtils](docs/modules/arrayutils.md) +- [IteratorUtils](docs/modules/iteratorutils.md) +- [NumberUtils](docs/modules/numberutils.md) +- [u32](docs/modules/u32.md) + ## Contribute There are many ways to contribute: diff --git a/src/TODO/array/bigArray.ts b/TODO/array/bigArray.ts similarity index 100% rename from src/TODO/array/bigArray.ts rename to TODO/array/bigArray.ts diff --git a/src/TODO/segmentTree/operation.ts b/TODO/segmentTree/operation.ts similarity index 100% rename from src/TODO/segmentTree/operation.ts rename to TODO/segmentTree/operation.ts diff --git a/src/TODO/trie/genericTrie.ts b/TODO/trie/genericTrie.ts similarity index 100% rename from src/TODO/trie/genericTrie.ts rename to TODO/trie/genericTrie.ts diff --git a/src/TODO/trie/index.ts b/TODO/trie/index.ts similarity index 100% rename from src/TODO/trie/index.ts rename to TODO/trie/index.ts diff --git a/src/TODO/trie/prefixTrie.ts b/TODO/trie/prefixTrie.ts similarity index 100% rename from src/TODO/trie/prefixTrie.ts rename to TODO/trie/prefixTrie.ts diff --git a/src/TODO/trie/suffixTrie.ts b/TODO/trie/suffixTrie.ts similarity index 100% rename from src/TODO/trie/suffixTrie.ts rename to TODO/trie/suffixTrie.ts diff --git a/src/TODO/trie/trie.ts b/TODO/trie/trie.ts similarity index 100% rename from src/TODO/trie/trie.ts rename to TODO/trie/trie.ts diff --git a/dist/dastal.min.js b/dist/dastal.min.js index be94993..875a36f 100644 --- a/dist/dastal.min.js +++ b/dist/dastal.min.js @@ -1,2 +1,2 @@ -!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define("Dastal",[],e):"object"==typeof exports?exports.Dastal=e():t.Dastal=e()}(self,(function(){return(()=>{"use strict";var t={d:(e,r)=>{for(var n in r)t.o(r,n)&&!t.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:r[n]})},o:(t,e)=>Object.prototype.hasOwnProperty.call(t,e),r:t=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})}},e={};t.r(e),t.d(e,{AATree:()=>ie,AVLTree:()=>ce,ArrayList:()=>rt,ArrayQueue:()=>_t,ArrayStack:()=>Vt,BinaryHeap:()=>b,DoublyLinkedList:()=>ut,InOrderSegmentTree:()=>Ut,LevelOrderSegmentTree:()=>Ht,LinkedList:()=>yt,LinkedQueue:()=>Pt,LinkedStack:()=>Nt,SkewHeap:()=>U,math:()=>n});var r={};t.r(r),t.d(r,{bitsSet:()=>gt,invert:()=>pt,isPow2:()=>dt,lsb:()=>bt,lsp:()=>mt,lsps:()=>kt,mlsp:()=>xt,msb:()=>wt,msp:()=>At,msps:()=>St,reverse:()=>zt,u32:()=>jt});var n={};t.r(n),t.d(n,{clamp:()=>$,u32:()=>r});var i=4294967295;function a(t){return t instanceof Array||u(t)}var o,l,u=(o=Object.getPrototypeOf(Uint8Array),function(t){return t instanceof o});function s(t,e,r){for(var n=r[t];t>0;){var i=Math.floor((t+1)/2)-1,a=r[i];if(e(a,n)<=0)break;r[i]=n,r[t]=a,t=i}}function h(t,e){for(var r=e.length+1>>>1;r>0;f(--r,t,e));}function f(t,e,r){for(var n=r.length,i=r[t];;){var a=2*t+1;if(a>=n)break;var o=r[a];if(a+11;i=i.next){var a;e[0]=null!==(a=e[0].next)&&void 0!==a?a:e.pop(),f(0,r,e),i.next=e[0]}return n}((function(e,r){return t(r.value,e.value)}),n),s=u.value;u=u.next;){var c=u.value;c.right=c.left,c.left=s,s=c}return s}function v(t,e){var r="undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(!r){if(Array.isArray(t)||(r=function(t,e){if(t){if("string"==typeof t)return y(t,e);var r=Object.prototype.toString.call(t).slice(8,-1);return"Object"===r&&t.constructor&&(r=t.constructor.name),"Map"===r||"Set"===r?Array.from(t):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?y(t,e):void 0}}(t))||e&&t&&"number"==typeof t.length){r&&(t=r);var n=0,i=function(){};return{s:i,n:function(){return n>=t.length?{done:!0}:{done:!1,value:t[n++]}},e:function(t){throw t},f:i}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var a,o=!0,l=!1;return{s:function(){r=r.call(t)},n:function(){var t=r.next();return o=t.done,t},e:function(t){l=!0,a=t},f:function(){try{o||null==r.return||r.return()}finally{if(l)throw a}}}}function y(t,e){(null==e||e>t.length)&&(e=t.length);for(var r=0,n=new Array(e);ri)throw new RangeError("Invalid heap length");for(var n=0;n=i)throw new RangeError("Invalid heap length");e.push(u)}}catch(t){l.e(t)}finally{l.f()}}return r=0}},{key:"delete",value:function(t){var e=this.array.indexOf(t);if(e<0)return!1;var r=this.array.pop();return e>=this.array.length||(this.array[e]=r,f(e,this.compare,this.array),s(e,this.compare,this.array)),!0}},{key:"merge",value:function(t){var e=this.array;if(t.size<1)return this;if(e.length+t.size>i)throw new RangeError("Invalid heap length");var r,n=v(t);try{for(n.s();!(r=n.n()).done;){var a=r.value;e.push(a)}}catch(t){n.e(t)}finally{n.f()}return h(this.compare,e),this}},{key:"peek",value:function(){return this.array.length>0?this.array[0]:void 0}},{key:"pop",value:function(){if(!(this.array.length<1)){var t=this.array[0],e=this.array.pop();return this.array.length>0&&(this.array[0]=e,f(0,this.compare,this.array)),t}}},{key:"push",value:function(t){return this.array.push(t),s(this.array.length-1,this.compare,this.array),this.size}},{key:"pushPop",value:function(t){if(this.array.length<1||this.compare(t,this.array[0])<=0)return t;var e=this.array[0];return this.array[0]=t,f(0,this.compare,this.array),e}},{key:"replace",value:function(t){if(!(this.array.length<1)){var e=this.array[0];return this.array[0]=t,t=e,f(0,this.compare,this.array),t}this.array.push(t)}},{key:"size",get:function(){return this.array.length}},{key:"sorted",value:regeneratorRuntime.mark((function e(){var r,n,i,a=this;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(!(this.array.length<1)){e.next=2;break}return e.abrupt("return");case 2:r=this.array,n=new t((function(t,e){return a.compare(r[t],r[e])}),[0]);case 4:if(!((i=n.pop())0){e.next=4;break}case 12:case"end":return e.stop()}}),e,this)}))},{key:l,value:function(){return this.array[Symbol.iterator]()}},{key:"update",value:function(t,e){var r=this.array.indexOf(t);return!(r<0||(this.array[r]=e,f(r,this.compare,this.array),s(r,this.compare,this.array),0))}}])&&g(e.prototype,r),t}(),m=regeneratorRuntime.mark(z),k=regeneratorRuntime.mark(O);function x(t){var e=!(arguments.length>1&&void 0!==arguments[1])||arguments[1],r=t.value,n=r.to;if(null==n)return t;if(null==n.right)n=n.left;else if(null==n.left)n=n.right;else if(e){var i=(r=(t=P(t)).value).to;n.value=i.value,n=i.right}else{var a=(r=(t=j(t)).value).to;n.value=a.value,n=a.left}return r.to=n,r.from&&(r.from[r.label]=r.to=n),t}function w(t){if(null!=t){var e=Object.assign({},t),r={value:e};do{t=r.value,r=r.next,t.left&&(r={next:r,value:t.left=Object.assign({},t.left)}),t.right&&(r={next:r,value:t.right=Object.assign({},t.right)})}while(r);return e}}function A(t){if(null!=t){for(;t.left;)t=t.left;return t}}function S(t){var e=t.value.to;if(null==e)return t;for(;e.left;)t={next:t,value:{label:"left",from:e,to:e.left}},e=e.left;return t}function z(t){var e;return regeneratorRuntime.wrap((function(r){for(;;)switch(r.prev=r.next){case 0:for(e=void 0;t;)e={next:e,value:t},t=t.left;case 2:if(!e){r.next=11;break}return t=e.value,e=e.next,r.next=7,t;case 7:for(t=t.right;t;)e={next:e,value:t},t=t.left;r.next=2;break;case 11:case"end":return r.stop()}}),m)}function j(t){var e=t.value.to;return null==e?t:_(t={next:t,value:{label:"left",from:e,to:e.left}})}function O(t){var e;return regeneratorRuntime.wrap((function(r){for(;;)switch(r.prev=r.next){case 0:e={value:t};case 1:if(t=e.value,e=e.next,!t){r.next=8;break}return r.next=6,t;case 6:e={next:e={next:e,value:t.right},value:t.left};case 8:if(e){r.next=1;break}case 9:case"end":return r.stop()}}),k)}function R(t){if(null!=t){for(;t.right;)t=t.right;return t}}function _(t){var e=t.value.to;if(null==e)return t;for(;e.right;)t={next:t,value:{label:"right",from:e,to:e.right}},e=e.right;return t}function I(t,e,r){for(;e;){var n=r(t,e.value);if(0==n)break;e=n<0?e.left:e.right}return e}function E(t,e,r){for(var n=arguments.length>3&&void 0!==arguments[3]?arguments[3]:0,i=["left","right"],a=e.value.to;a;){var o=r(t,a.value)||n;if(0===o)break;var l=i[+(o>0)];e={next:e,value:{label:l,from:a,to:a[l]}},a=a[l]}return e}function P(t){var e=t.value.to;return null==e?t:S(t={next:t,value:{label:"right",from:e,to:e.right}})}function T(t){if(!(null==t||t.length<1||null==t[0])){var e=t.length,r=new Array(e);r[0]={value:t[0]};for(var n=1;n>>1],a={value:t[n]};r[n]=a,1&n?i.left=a:i.right=a}return r[0]}}function M(t,e){var r="undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(!r){if(Array.isArray(t)||(r=function(t,e){if(t){if("string"==typeof t)return C(t,e);var r=Object.prototype.toString.call(t).slice(8,-1);return"Object"===r&&t.constructor&&(r=t.constructor.name),"Map"===r||"Set"===r?Array.from(t):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?C(t,e):void 0}}(t))||e&&t&&"number"==typeof t.length){r&&(t=r);var n=0,i=function(){};return{s:i,n:function(){return n>=t.length?{done:!0}:{done:!1,value:t[n++]}},e:function(t){throw t},f:i}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var a,o=!0,l=!1;return{s:function(){r=r.call(t)},n:function(){var t=r.next();return o=t.done,t},e:function(t){l=!0,a=t},f:function(){try{o||null==r.return||r.return()}finally{if(l)throw a}}}}function C(t,e){(null==e||e>t.length)&&(e=t.length);for(var r=0,n=new Array(e);r0){e.next=3;break}case 9:case"end":return e.stop()}}),e,this)}))},{key:d,value:regeneratorRuntime.mark((function t(){var e,r,n;return regeneratorRuntime.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:e=M(O(this.root)),t.prev=1,e.s();case 3:if((r=e.n()).done){t.next=9;break}return n=r.value,t.next=7,n.value;case 7:t.next=3;break;case 9:t.next=14;break;case 11:t.prev=11,t.t0=t.catch(1),e.e(t.t0);case 14:return t.prev=14,e.f(),t.finish(14);case 17:case"end":return t.stop()}}),t,this,[[1,11,14,17]])}))},{key:"update",value:function(t,e){if(null==this.root)return!1;if(this.root.value===t)return this.root=c(this.compare,[this.root.left,this.root.right,{value:e}]),!0;var r,n=void 0,i=M(O(this.root));try{for(i.s();!(r=i.n()).done;){var a=r.value;if(a.left&&a.left.value===t){n=a.left,a.left=void 0;break}if(a.right&&a.right.value===t){n=a.right,a.right=void 0;break}}}catch(t){i.e(t)}finally{i.f()}return null!=n&&(this.root=c(this.compare,[this.root,n.left,n.right,{value:e}]),!0)}}])&&F(e.prototype,r),t}();function $(t,e,r){return Math.min(r,Math.max(e,t))}function L(t,e){var r="undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(!r){if(Array.isArray(t)||(r=function(t,e){if(t){if("string"==typeof t)return q(t,e);var r=Object.prototype.toString.call(t).slice(8,-1);return"Object"===r&&t.constructor&&(r=t.constructor.name),"Map"===r||"Set"===r?Array.from(t):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?q(t,e):void 0}}(t))||e&&t&&"number"==typeof t.length){r&&(t=r);var n=0,i=function(){};return{s:i,n:function(){return n>=t.length?{done:!0}:{done:!1,value:t[n++]}},e:function(t){throw t},f:i}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var a,o=!0,l=!1;return{s:function(){r=r.call(t)},n:function(){var t=r.next();return o=t.done,t},e:function(t){l=!0,a=t},f:function(){try{o||null==r.return||r.return()}finally{if(l)throw a}}}}function q(t,e){(null==e||e>t.length)&&(e=t.length);for(var r=0,n=new Array(e);r=t)){l.next=20;break}return l.next=9,r;case 9:if(l.t1=o=l.sent,l.t0=null!==l.t1,!l.t0){l.next=13;break}l.t0=void 0!==o;case 13:if(!l.t0){l.next=17;break}l.t2=o,l.next=18;break;case 17:l.t2=t;case 18:t=l.t2,r=[];case 20:l.next=4;break;case 22:l.next=27;break;case 24:l.prev=24,l.t3=l.catch(2),n.e(l.t3);case 27:return l.prev=27,n.f(),l.finish(27);case 30:if(!(r.length>0)){l.next=33;break}return l.next=33,r;case 33:case"end":return l.stop()}}),D,null,[[2,24,27,30]])}function V(t,e,r){return $(function(t,e){return t<0?e+t:t}(t,r),e,r)}function G(t,e,r,n){if(e<2)return[t,t];e/=2;var i=[Math.ceil(e),Math.floor(e)],a=G(t,i[0],r,n),o=G(a[1].next,i[1],r,n);t=a[1],a[1]=o[0],o[0]=t,o[0].next=o[1].next;var l=a[0].prev;return t=function(t,e,r,n){var i={},a=i;do{var o=+(n(t[0].value,t[1].value)>0);a.next=t[o],r&&(a.next.prev=a),a=a.next,t[o]=a.next,--e[o]}while(e[0]>0&&e[1]>0);return a.next=t[+(e[0]<1)],r&&a.next&&(a.next.prev=a),i.next}(a,i,r,n),r&&(t.prev=l),[t,o[+(i[0]<1)]]}function J(t){return function(t){if(Array.isArray(t))return Y(t)}(t)||function(t){if("undefined"!=typeof Symbol&&null!=t[Symbol.iterator]||null!=t["@@iterator"])return Array.from(t)}(t)||N(t)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function K(t,e){var r="undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(!r){if(Array.isArray(t)||(r=N(t))||e&&t&&"number"==typeof t.length){r&&(t=r);var n=0,i=function(){};return{s:i,n:function(){return n>=t.length?{done:!0}:{done:!1,value:t[n++]}},e:function(t){throw t},f:i}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var a,o=!0,l=!1;return{s:function(){r=r.call(t)},n:function(){var t=r.next();return o=t.done,t},e:function(t){l=!0,a=t},f:function(){try{o||null==r.return||r.return()}finally{if(l)throw a}}}}function N(t,e){if(t){if("string"==typeof t)return Y(t,e);var r=Object.prototype.toString.call(t).slice(8,-1);return"Object"===r&&t.constructor&&(r=t.constructor.name),"Map"===r||"Set"===r?Array.from(t):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?Y(t,e):void 0}}function Y(t,e){(null==e||e>t.length)&&(e=t.length);for(var r=0,n=new Array(e);r=0&&t<=this.size&&this.array.splice(t,0,e),this.size}},{key:"addAll",value:function(t,e){if(t>=0&&t<=this.size){var r,n=K(H(1e4,e));try{for(n.s();!(r=n.n()).done;){var i,a=r.value;(i=this.array).splice.apply(i,[t,0].concat(J(a))),t+=a.length}}catch(t){n.e(t)}finally{n.f()}}return this.size}},{key:"clear",value:function(){this.array.length=0}},{key:"concat",value:function(){for(var e=new t(this),r=arguments.length,n=new Array(r),i=0;i=this.size?void 0:this.array[t]}},{key:"getSet",value:function(t,e){var r=void 0;return t>=0&&t=this.size?void 0:this.array.splice(t,1)[0]}},{key:"reverse",value:function(t,e){var r,n;for(t=V(null!==(r=t)&&void 0!==r?r:0,0,this.size),e=V(null!==(n=e)&&void 0!==n?n:this.size,0,this.size)-1;t=0&&t=0?function(){return Math.min(r,a.size)}:function(){return a.size+r};case 2:if(!(et.length)&&(e=t.length);for(var r=0,n=new Array(e);rthis.length)return this.length;var r=this._get(t-1),n={next:r.next,prev:r,value:e};return r.next=n,n.next.prev=n,++this.length}},{key:"addAll",value:function(t,e){return t>=0&&t<=this.length&&this._addAll(this._get(t),e),this.length}},{key:"clear",value:function(){this.length=0,this.root.prev=this.root.next=this.root}},{key:"concat",value:function(){for(var e=new t(this),r=arguments.length,n=new Array(r),i=0;i=(r=e+Math.min(r-e,this.length-t)))return this;if(e=this.length?void 0:this._get(t).value}},{key:"getSet",value:function(t,e){if(!(t<0||t>=this.length)){var r=this._get(t),n=r.value;return r.value=e(r.value),n}}},{key:"pop",value:function(){if(!(this.length<1)){var t=this.root.prev;return t.prev.next=this.root,this.root.prev=t.prev,--this.length,t.value}}},{key:"push",value:function(t){var e=this.root.prev,r={next:this.root,prev:e,value:t};return e.next=this.root.prev=r,++this.length}},{key:"remove",value:function(t){if(!(t<0||t>=this.length)){var e=this._get(t);return e.prev.next=e.next,e.next.prev=e.prev,--this.length,e.value}}},{key:"reverse",value:function(t,e){var r,n;if(t=V(null!==(r=t)&&void 0!==r?r:0,0,this.length),(e=V(null!==(n=e)&&void 0!==n?n:this.length,0,this.length))-t<2)return this;var i=this._get(t-1),a=i.next,o=a;do{var l=o.next;o.next=o.prev,o.prev=l,i.next=o,o=l}while(++t=this.length)){var r=this._get(t),n=r.value;return r.value=e,n}}},{key:"shift",value:function(){if(!(this.length<1)){var t=this.root.next;return t.next.prev=this.root,this.root.next=t.next,--this.length,t.value}}},{key:"size",get:function(){return this.length}},{key:"slice",value:function(e,r){return new t(this.view(e,r))}},{key:"splice",value:function(e,r,n){var i,a;e=V(null!==(i=e)&&void 0!==i?i:0,0,this.size),r=$(null!==(a=r)&&void 0!==a?a:this.size,0,this.size-e);var o=new t;if(null==n&&r<1)return o;for(var l=this._get(e);r-- >0;)o.push(l.value),l.prev.next=l.next,l.next.prev=l.prev,l=l.next,--this.length;return this._addAll(l,null!=n?n:[]),o}},{key:"sort",value:function(t){if(this.length>1){var e=(i=G(this.root.next,this.length,!0,t),a=2,function(t){if(Array.isArray(t))return t}(i)||function(t,e){var r=null==t?null:"undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(null!=r){var n,i,a=[],o=!0,l=!1;try{for(r=r.call(t);!(o=(n=r.next()).done)&&(a.push(n.value),!e||a.length!==e);o=!0);}catch(t){l=!0,i=t}finally{try{o||null==r.return||r.return()}finally{if(l)throw i}}return a}}(i,a)||nt(i,a)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()),r=e[0],n=e[1];this.root.next=r,n.next.prev=n}var i,a;return this}},{key:et,value:regeneratorRuntime.mark((function t(){var e;return regeneratorRuntime.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:e=this.root.next;case 1:if(e===this.root){t.next=7;break}return t.next=4,e.value;case 4:e=e.next,t.next=1;break;case 7:case"end":return t.stop()}}),t,this)}))},{key:"unshift",value:function(t){var e=this.root.next,r={next:e,prev:this.root,value:t};return this.root.next=e.prev=r,++this.length}},{key:"update",value:function(t,e,r){var n,i;if(null==r&&(arguments.length<2?(r=t,t=void 0):(r=e,e=void 0)),(t=V(null!==(n=t)&&void 0!==n?n:0,0,this.length))<(e=V(null!==(i=e)&&void 0!==i?i:this.length,0,this.length))){var a=this._get(t);do{a.value=r(a.value,t),a=a.next}while(++t=0?function(){return r}:function(){return o.length+r})())){t.next=8;break}a=this._get(e);case 4:return t.next=6,a.value;case 6:a=a.next;case 7:if(++e=t.length?{done:!0}:{done:!1,value:t[n++]}},e:function(t){throw t},f:i}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var a,o=!0,l=!1;return{s:function(){r=r.call(t)},n:function(){var t=r.next();return o=t.done,t},e:function(t){l=!0,a=t},f:function(){try{o||null==r.return||r.return()}finally{if(l)throw a}}}}(e);try{for(i.s();!(r=i.n()).done;){var a={prev:n,value:r.value};n.next=a,n=a,++this.length}}catch(t){i.e(t)}finally{i.f()}n.next=t,t.prev=n}},{key:"_get",value:function(t){var e=this.root;if(t=0;)e=e.next;else for(t=this.length-t;t>0;--t)e=e.prev;return e}}])&&at(e.prototype,r),t}();function st(t,e){if(t){if("string"==typeof t)return ht(t,e);var r=Object.prototype.toString.call(t).slice(8,-1);return"Object"===r&&t.constructor&&(r=t.constructor.name),"Map"===r||"Set"===r?Array.from(t):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?ht(t,e):void 0}}function ht(t,e){(null==e||e>t.length)&&(e=t.length);for(var r=0,n=new Array(e);r=0&&t=0&&t=(r=e+Math.min(r-e,this.length-t)))return this;if(tr){var o=this._get(e-1);return this._copyWithin(o,this._get(t-e-1,o),r-e),this}var l=this._get(e-1),u=this._get(r-e-1,l),s=this._copyWithin(l,u,t-e);t+(r-e)>=this.length&&(this.tail=u);var h=l.next;return l.next=u.next,u.next=s.next,s.next=h,this}},{key:"fill",value:function(t,e,r){var n,i;if((e=V(null!==(n=e)&&void 0!==n?n:0,0,this.length))<(r=V(null!==(i=r)&&void 0!==i?i:this.length,0,this.length))){var a=this._get(e);do{a.value=t,a=a.next}while(++e=this.length))return t=this.length)){var r=t=this.length)){var e=this._get(t-1),r=e.next;return e.next=r.next,t===--this.length&&(this.tail=e),r.value}}},{key:"reverse",value:function(t,e){var r,n;if(t=V(null!==(r=t)&&void 0!==r?r:0,0,this.length),(e=V(null!==(n=e)&&void 0!==n?n:this.length,0,this.length))-t<2)return this;var i=this._get(t-1);this.tail=e>=this.length?i.next:this.tail;for(var a=i.next,o=a,l=a.next;++t=this.length)){var r=this._get(t),n=r.value;return r.value=e,n}}},{key:"shift",value:function(){return this.remove(0)}},{key:"size",get:function(){return this.length}},{key:"slice",value:function(e,r){return new t(this.view(e,r))}},{key:"splice",value:function(e,r,n){var i,a;e=V(null!==(i=e)&&void 0!==i?i:0,0,this.size),r=$(null!==(a=r)&&void 0!==a?a:this.size,0,this.size-e);var o=new t;if(null==n&&r<1)return o;for(var l=this._get(e-1),u=e+r>=this.size;r-- >0;){var s=l.next;o.push(s.value),l.next=s.next,--this.length}return l=this._addAll(l,null!=n?n:[]),this.tail=u?l:this.tail,o}},{key:"sort",value:function(t){if(this.length>1){var e=(i=G(this.root.next,this.length,!1,t),a=2,function(t){if(Array.isArray(t))return t}(i)||function(t,e){var r=null==t?null:"undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(null!=r){var n,i,a=[],o=!0,l=!1;try{for(r=r.call(t);!(o=(n=r.next()).done)&&(a.push(n.value),!e||a.length!==e);o=!0);}catch(t){l=!0,i=t}finally{try{o||null==r.return||r.return()}finally{if(l)throw i}}return a}}(i,a)||st(i,a)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()),r=e[0],n=e[1];this.root.next=r,this.tail=n}var i,a;return this}},{key:lt,value:regeneratorRuntime.mark((function t(){var e;return regeneratorRuntime.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:e=this.root.next;case 1:if(e===this.root){t.next=7;break}return t.next=4,e.value;case 4:e=e.next,t.next=1;break;case 7:case"end":return t.stop()}}),t,this)}))},{key:"unshift",value:function(t){return this.add(0,t)}},{key:"update",value:function(t,e,r){var n,i;if(null==r&&(arguments.length<2?(r=t,t=void 0):(r=e,e=void 0)),(t=V(null!==(n=t)&&void 0!==n?n:0,0,this.length))<(e=V(null!==(i=e)&&void 0!==i?i:this.length,0,this.length))){var a=this._get(t);do{a.value=r(a.value,t),a=a.next}while(++t=0?function(){return r}:function(){return o.length+r})())){t.next=8;break}a=this._get(e);case 4:return t.next=6,a.value;case 6:a=a.next;case 7:if(++e=t.length?{done:!0}:{done:!1,value:t[n++]}},e:function(t){throw t},f:i}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var a,o=!0,l=!1;return{s:function(){r=r.call(t)},n:function(){var t=r.next();return o=t.done,t},e:function(t){l=!0,a=t},f:function(){try{o||null==r.return||r.return()}finally{if(l)throw a}}}}(e);try{for(i.s();!(r=i.n()).done;){var a={value:r.value};t.next=a,t=a,++this.length}}catch(t){i.e(t)}finally{i.f()}return t.next=n,t}},{key:"_copyWithin",value:function(t,e,r){for(;r-- >0;)t=t.next,(e=e.next).value=t.value;return e}},{key:"_get",value:function(t){for(var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:this.root,r=e;t-- >=0;)r=r.next;return r}}])&&ft(e.prototype,r),t}();function gt(t){for(var e=0;t;)++e,t&=t-1;return e}function pt(t){var e=At(t);return jt(t^(e|e-1))}function dt(t){return 0==(t&t-1)}function bt(t){var e=-1;for(t=mt(t);t;t>>>=1)++e;return e}function mt(t){return jt(t&-t)}function kt(t){return jt(t&mt(t+mt(t))-1)}function xt(t){return mt(t+mt(t))>>>1||jt(2147483648&t)}function wt(t){for(var e=-1;0!==t;)++e,t>>>=1;return e}function At(t){for(var e=t&-t;t!=e;)e=(t^=e)&-t;return jt(e)}function St(t){for(var e=t&-t;t&t+e;)e=(t^=e)&-t;return jt(t)}function zt(t){return jt((t=(4278255360&(t=(4042322160&(t=(3435973836&(t=(2863311530&t)>>>1|(1431655765&t)<<1))>>>2|(858993459&t)<<2))>>>4|(252645135&t)<<4))>>>8|(16711935&t)<<8)>>>16|t<<16)}function jt(t){return t>>>0}function Ot(t,e){for(var r=0;rt.length)&&(e=t.length);for(var r=0,n=new Array(e);r1&&void 0!==arguments[1]?arguments[1]:[];Mt(this,t),Ft(this,"array",void 0),Ft(this,"combine",void 0),this.array=[],this.combine=e,this.build(r)}var e,r;return e=t,(r=[{key:"clear",value:function(){this.array.length=0}},{key:"pop",value:function(){if(!(this.size<1)){for(var t=this.array.length-1,e=2;t&e;e*=2)this.array[t-e]=this.array[t-e-(e>>>1)];var r=this.array[t-1];return this.array.length-=2,r}}},{key:"push",value:function(e){if(this.size>=t.MAX_SIZE)throw new RangeError("Invalid length");var r=this.array.length;return this.array[r+1]=this.set(r,e),this.size}},{key:"query",value:function(t,e){if(t>=e)throw new RangeError("Range [".concat(t,"..").concat(e,") is empty"));if(t<0||e>this.size)throw new RangeError("Range [".concat(t,"..").concat(e,") not in [0..").concat(this.size,")"));var r=mt((t*=2)|At((e*=2)-t)),n=this.array[t-1+(r>>>1)];for(t+=r;t>>1)]);return n}},{key:"size",get:function(){return this.array.length>>>1}},{key:Et,value:regeneratorRuntime.mark((function t(){var e;return regeneratorRuntime.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:e=0;case 1:if(!(e=e)){if(t<0||e>this.size)throw new RangeError("Range [".concat(t,"..").concat(e,") not in [0..").concat(this.size,")"));var n;t*=2,e*=2;do{n=this.set(t,r(this.array[t],t>>>1)),t+=2}while(t0;--e)n=this.combine(n,this.array[t+(a>>>1)-i]),this.array[t]=n,t+=a-(i=(t&2*a)>>>0),a*=2;this.array[t]=n}}},{key:"build",value:function(t){var e,r=function(t,e){var r="undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(!r){if(Array.isArray(t)||(r=function(t,e){if(t){if("string"==typeof t)return Tt(t,e);var r=Object.prototype.toString.call(t).slice(8,-1);return"Object"===r&&t.constructor&&(r=t.constructor.name),"Map"===r||"Set"===r?Array.from(t):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?Tt(t,e):void 0}}(t))||e&&t&&"number"==typeof t.length){r&&(t=r);var n=0,i=function(){};return{s:i,n:function(){return n>=t.length?{done:!0}:{done:!1,value:t[n++]}},e:function(t){throw t},f:i}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var a,o=!0,l=!1;return{s:function(){r=r.call(t)},n:function(){var t=r.next();return o=t.done,t},e:function(t){l=!0,a=t},f:function(){try{o||null==r.return||r.return()}finally{if(l)throw a}}}}(t);try{for(r.s();!(e=r.n()).done;){var n=e.value;this.push(n)}}catch(t){r.e(t)}finally{r.f()}}},{key:"set",value:function(t,e){this.array[t++]=e;for(var r=2;t&r;r*=2)e=this.combine(this.array[t-r-(r>>>1)],e),this.array[t-r]=e;return e}}])&&Ct(e.prototype,r),t}();function $t(t,e){var r="undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(!r){if(Array.isArray(t)||(r=function(t,e){if(t){if("string"==typeof t)return Lt(t,e);var r=Object.prototype.toString.call(t).slice(8,-1);return"Object"===r&&t.constructor&&(r=t.constructor.name),"Map"===r||"Set"===r?Array.from(t):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?Lt(t,e):void 0}}(t))||e&&t&&"number"==typeof t.length){r&&(t=r);var n=0,i=function(){};return{s:i,n:function(){return n>=t.length?{done:!0}:{done:!1,value:t[n++]}},e:function(t){throw t},f:i}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var a,o=!0,l=!1;return{s:function(){r=r.call(t)},n:function(){var t=r.next();return o=t.done,t},e:function(t){l=!0,a=t},f:function(){try{o||null==r.return||r.return()}finally{if(l)throw a}}}}function Lt(t,e){(null==e||e>t.length)&&(e=t.length);for(var r=0,n=new Array(e);r1&&void 0!==arguments[1]?arguments[1]:[];qt(this,t),Zt(this,"array",void 0),Zt(this,"combine",void 0),Zt(this,"length",void 0),Zt(this,"level",void 0),this.array=[],this.combine=e,this.length=0,this.level=0,this.build(r)}var e,r;return e=t,(r=[{key:"clear",value:function(){this.length=0,this.level=0,this.array.length=0}},{key:"pop",value:function(){if(!(this.length<=this.level)){var t=this.array[--this.length];return this.length<=this.array.length+1>>>2&&this.shrink(),t}}},{key:"push",value:function(t){this.length>=this.array.length&&this.grow(),this.array[this.length++]=t;for(var e=this.length;1&e;this.array[e-1]=t)t=this.combine(this.array[e-2],t),e>>>=1;return this.size}},{key:"query",value:function(t,e){if(t>=e)throw new RangeError("Range [".concat(t,"..").concat(e,") is empty"));if(t<0||e>this.size)throw new RangeError("Range [".concat(t,"..").concat(e,") not in [0..").concat(this.size,")"));var r=mt((t+=this.level+1)|At((e+=this.level+1)-t)),n=this.array[t/r-1];for(t+=r;t=e)){if(t<0||e>this.size)throw new RangeError("Range [".concat(t,"..").concat(e,") not in [0..").concat(this.size,")"));t+=this.level,e+=this.level;for(var n=t;n>>=1){e+=e&e-r>>>31;for(var n=(1|t)>>>0;n>>1)-1]=this.combine(this.array[n-2],this.array[n-1]);t>>>=1,e>>>=1}}},{key:"build",value:function(e){var r,n=void 0;if(a(e))n="length";else{if(!("size"in(r=e))||"number"!=typeof r.size){var i,o=$t(e);try{for(o.s();!(i=o.n()).done;){var l=i.value;this.push(l)}}catch(t){o.e(t)}finally{o.f()}return}n="size"}var u=e[n];if(u<1)return this.array.length=0,this.length=0,void(this.level=0);if(u>=t.MAX_SIZE)throw new RangeError("Invalid length");this.level=2*At(u-1)-1,this.length=this.level,this.array.length=2*this.level+1;var s,h=$t(e);try{for(h.s();!(s=h.n()).done;){var f=s.value;this.array[this.length++]=f}}catch(t){h.e(t)}finally{h.f()}this.aggregate(this.level,this.length)}},{key:"grow",value:function(){if(this.size<1)this.array.length=1;else{if(this.size>=t.MAX_SIZE)throw new RangeError("Invalid length");this.array.length+=this.array.length+1;for(var e=this.level+1,r=this.length+1;e>>=1)this.array.copyWithin(2*e-1,e-1,r-1),e>>>=1;this.length+=this.level+1,this.level+=this.level+1}}},{key:"shrink",value:function(){var t=this.length-this.level;if(t<2)return this.array.copyWithin(0,this.level,this.length),this.level=0,this.length=t,void(this.array.length=t);var e=this.level+1,r=At(t);e=e/mt(e|r)-1,this.level=+!dt(t);for(var n=e+1;r;this.level+=this.level+1)this.array.copyWithin(this.level,e,n),e+=e+1,n+=n+2+ +((t&(r>>>=1))>0);this.length=this.level+t,this.array.length=2*this.level+1}}])&&Xt(e.prototype,r),t}();function Qt(t,e){for(var r=0;r0)){t.next=7;break}case 3:return t.next=5,e[--r];case 5:t.next=2;break;case 7:case"end":return t.stop()}}),t,this)}))}])&&Qt(e.prototype,r),t}();function Gt(t,e){(null==e||e>t.length)&&(e=t.length);for(var r=0,n=new Array(e);r=t.length?{done:!0}:{done:!1,value:t[n++]}},e:function(t){throw t},f:i}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var a,o=!0,l=!1;return{s:function(){r=r.call(t)},n:function(){var t=r.next();return o=t.done,t},e:function(t){l=!0,a=t},f:function(){try{o||null==r.return||r.return()}finally{if(l)throw a}}}}(e||[]);try{for(a.s();!(i=a.n()).done;){var o=i.value;this.push(o)}}catch(t){a.e(t)}finally{a.f()}}var e,r;return e=t,(r=[{key:"clear",value:function(){this.list.clear()}},{key:"peek",value:function(){return this.list.get(0)}},{key:"pop",value:function(){return this.list.shift()}},{key:"push",value:function(t){return this.list.unshift(t)}},{key:"size",get:function(){return this.list.size}},{key:Bt,value:function(){return this.list[Symbol.iterator]()}}])&&Jt(e.prototype,r),t}();function Yt(t,e){var r="undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(!r){if(Array.isArray(t)||(r=function(t,e){if(t){if("string"==typeof t)return te(t,e);var r=Object.prototype.toString.call(t).slice(8,-1);return"Object"===r&&t.constructor&&(r=t.constructor.name),"Map"===r||"Set"===r?Array.from(t):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?te(t,e):void 0}}(t))||e&&t&&"number"==typeof t.length){r&&(t=r);var n=0,i=function(){};return{s:i,n:function(){return n>=t.length?{done:!0}:{done:!1,value:t[n++]}},e:function(t){throw t},f:i}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var a,o=!0,l=!1;return{s:function(){r=r.call(t)},n:function(){var t=r.next();return o=t.done,t},e:function(t){l=!0,a=t},f:function(){try{o||null==r.return||r.return()}finally{if(l)throw a}}}}function te(t,e){(null==e||e>t.length)&&(e=t.length);for(var r=0,n=new Array(e);r=t.length?{done:!0}:{done:!1,value:t[n++]}},e:function(t){throw t},f:i}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var a,o=!0,l=!1;return{s:function(){r=r.call(t)},n:function(){var t=r.next();return o=t.done,t},e:function(t){l=!0,a=t},f:function(){try{o||null==r.return||r.return()}finally{if(l)throw a}}}}function se(t,e){(null==e||e>t.length)&&(e=t.length);for(var r=0,n=new Array(e);r1?(t.right.balanceFactor<0&&(t.right=pe(t.right)),t=ge(t)):t.balanceFactor<-1&&(t.left.balanceFactor>0&&(t.left=ge(t.left)),t=pe(t)),t}function ye(t){var e=t.value;if(null==e.to)return!1;for(var r=(t=x(t)).value.label;t.next&&((e=(t=t.next).value).to.balanceFactor-="left"===r?-1:1,e.to=ve(e.to),e.from[r=e.label]=e.to,0===e.to.balanceFactor););return!0}function ge(t){var e=t.right;return t.right=e.left,e.left=t,t.balanceFactor-=1+Math.max(0,e.balanceFactor),e.balanceFactor-=1-Math.min(0,t.balanceFactor),e}function pe(t){var e=t.left;return t.left=e.right,e.right=t,t.balanceFactor+=1-Math.min(0,e.balanceFactor),e.balanceFactor+=1+Math.max(0,t.balanceFactor),e}return e})()})); +!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define("Dastal",[],e):"object"==typeof exports?exports.Dastal=e():t.Dastal=e()}(self,(function(){return(()=>{"use strict";var t={d:(e,r)=>{for(var n in r)t.o(r,n)&&!t.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:r[n]})},o:(t,e)=>Object.prototype.hasOwnProperty.call(t,e),r:t=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})}},e={};t.r(e),t.d(e,{AATree:()=>he,AVLTree:()=>be,ArrayList:()=>ut,ArrayQueue:()=>Ct,ArrayStack:()=>te,ArrayUtils:()=>i,BinaryHeap:()=>U,DoublyLinkedList:()=>gt,InOrderSegmentTree:()=>Dt,IteratorUtils:()=>r,LevelOrderSegmentTree:()=>Yt,LinkedList:()=>xt,LinkedQueue:()=>Ut,LinkedStack:()=>ie,NumberUtils:()=>n,SkewHeap:()=>at,isCollection:()=>_,u32:()=>a});var r={};t.r(r),t.d(r,{always:()=>o,fill:()=>l,first:()=>u,join:()=>s,never:()=>h,once:()=>f,skip:()=>c,split:()=>v});var n={};t.r(n),t.d(n,{clamp:()=>y,wrap:()=>d,wrapLeft:()=>g,wrapRight:()=>p});var i={};t.r(i),t.d(i,{MAX_ARRAY_LENGTH:()=>x,MAX_SAFE_ARGUMENT_LENGTH:()=>w,isArray:()=>A,isTypedArray:()=>j,splice:()=>O});var a={};function o(t){return{next:function(){return{done:!1,value:t()}}}}function l(t,e){return{next:function(){return t<1?{done:!0,value:void 0}:(--t,{done:!1,value:e()})}}}function u(t,e){return{next:function(){if(t<1)return{done:!0,value:void 0};var r=e.next();return t=r.done?0:t-1,r}}}function s(t){var e={next:function(){return{done:!0,value:void 0}}};return{next:function(){if(null==e)return{done:!0,value:void 0};for(var r=e.next();r.done;){var n=t.next();if(n.done)return e=void 0,{done:!0,value:void 0};r=(e=n.value).next()}return r}}}function h(){return{next:function(){return{done:!0,value:void 0}}}}function f(t){var e=!1;return{next:function(){var r={done:e,value:t()};return e=!0,t=function(){},r}}}function c(t,e){var r=function(){for(var n={done:!1,value:void 0};t-- >0&&!n.done;)n=e.next();return r=e.next.bind(e),n};return{next:function(){return r()}}}function v(t,e){if(t<1)return{next:function(){return{done:!0,value:void 0}}};var r=!1;return{next:function(){if(r)return{done:r,value:void 0};var n=u(t,e),i=n.next();return i.done?{done:r=!0,value:void 0}:{done:r,value:s([f((function(){return i.value})),n][Symbol.iterator]())}}}}function y(t,e,r){return Math.min(r,Math.max(e,t))}function g(t,e,r){return tr?e+(t-r):t}function d(t,e,r){return tt.length)&&(e=t.length);for(var r=0,n=new Array(e);rwt,invert:()=>At,isPow2:()=>St,lsb:()=>zt,lsp:()=>jt,lsps:()=>Ot,msb:()=>_t,msp:()=>Rt,msps:()=>It,reverse:()=>Et,u32:()=>Pt});var x=4294967295,w=32767;function A(t){return t instanceof Array||j(t)}var S,z,j=(S=Object.getPrototypeOf(Uint8Array),function(t){return t instanceof S});function O(t,e,r,n){var i,a;if(e=y(g(null!==(i=e)&&void 0!==i?i:0,0,t.length),0,t.length),r=y(null!==(a=r)&&void 0!==a?a:t.length,0,t.length-e),null==n)return t.splice(e,r);var o=w-2,l=n[Symbol.iterator](),s=t.length-r,h=x-s,f=Math.min(o,h),c=t.splice.apply(t,[e,r].concat(m(b({},Symbol.iterator,(function(){return u(f,l)})))));for(e+=s=t.length-s,f=h-s;f>=o&&s>=o;f-=s)s=t.length,t.splice.apply(t,[e,0].concat(m(b({},Symbol.iterator,(function(){return u(o,l)}))))),e+=s=t.length-s;if(f>0&&s>=o&&t.splice.apply(t,[e,0].concat(m(b({},Symbol.iterator,(function(){return u(f,l)}))))),1!=l.next().done)throw new RangeError("Invalid array length");return c}function _(t){return null!=t&&"number"==typeof t.size&&"function"==typeof t[Symbol.iterator]}function R(t,e,r){for(var n=r[t];t>0;){var i=Math.floor((t+1)/2)-1,a=r[i];if(e(a,n)<=0)break;r[i]=n,r[t]=a,t=i}}function I(t,e){for(var r=e.length+1>>>1;r>0;E(--r,t,e));}function E(t,e,r){for(var n=r.length,i=r[t];;){var a=2*t+1;if(a>=n)break;var o=r[a];if(a+11;i=i.next){var a;e[0]=null!==(a=e[0].next)&&void 0!==a?a:e.pop(),E(0,r,e),i.next=e[0]}return n}((function(e,r){return t(r.value,e.value)}),n),s=u.value;u=u.next;){var h=u.value;h.right=h.left,h.left=s,s=h}return s}function T(t,e){var r="undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(!r){if(Array.isArray(t)||(r=function(t,e){if(t){if("string"==typeof t)return M(t,e);var r=Object.prototype.toString.call(t).slice(8,-1);return"Object"===r&&t.constructor&&(r=t.constructor.name),"Map"===r||"Set"===r?Array.from(t):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?M(t,e):void 0}}(t))||e&&t&&"number"==typeof t.length){r&&(t=r);var n=0,i=function(){};return{s:i,n:function(){return n>=t.length?{done:!0}:{done:!1,value:t[n++]}},e:function(t){throw t},f:i}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var a,o=!0,l=!1;return{s:function(){r=r.call(t)},n:function(){var t=r.next();return o=t.done,t},e:function(t){l=!0,a=t},f:function(){try{o||null==r.return||r.return()}finally{if(l)throw a}}}}function M(t,e){(null==e||e>t.length)&&(e=t.length);for(var r=0,n=new Array(e);rx)throw new RangeError("Invalid heap length");for(var n=0;n=x)throw new RangeError("Invalid heap length");e.push(o)}}catch(t){a.e(t)}finally{a.f()}}return r=0}},{key:"delete",value:function(t){var e=this.array.indexOf(t);if(e<0)return!1;var r=this.array.pop();return e>=this.array.length||(this.array[e]=r,E(e,this.compare,this.array),R(e,this.compare,this.array)),!0}},{key:"merge",value:function(t){var e=this.array;if(t.size<1)return this;if(e.length+t.size>x)throw new RangeError("Invalid heap length");var r,n=T(t);try{for(n.s();!(r=n.n()).done;){var i=r.value;e.push(i)}}catch(t){n.e(t)}finally{n.f()}return I(this.compare,e),this}},{key:"peek",value:function(){return this.array.length>0?this.array[0]:void 0}},{key:"pop",value:function(){if(!(this.array.length<1)){var t=this.array[0],e=this.array.pop();return this.array.length>0&&(this.array[0]=e,E(0,this.compare,this.array)),t}}},{key:"push",value:function(t){return this.array.push(t),R(this.array.length-1,this.compare,this.array),this.size}},{key:"pushPop",value:function(t){if(this.array.length<1||this.compare(t,this.array[0])<=0)return t;var e=this.array[0];return this.array[0]=t,E(0,this.compare,this.array),e}},{key:"replace",value:function(t){if(!(this.array.length<1)){var e=this.array[0];return this.array[0]=t,t=e,E(0,this.compare,this.array),t}this.array.push(t)}},{key:"size",get:function(){return this.array.length}},{key:"sorted",value:regeneratorRuntime.mark((function e(){var r,n,i,a=this;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(!(this.array.length<1)){e.next=2;break}return e.abrupt("return");case 2:r=this.array,n=new t((function(t,e){return a.compare(r[t],r[e])}),[0]);case 4:if(!((i=n.pop())0){e.next=4;break}case 12:case"end":return e.stop()}}),e,this)}))},{key:z,value:function(){return this.array[Symbol.iterator]()}},{key:"update",value:function(t,e){var r=this.array.indexOf(t);return!(r<0||(this.array[r]=e,E(r,this.compare,this.array),R(r,this.compare,this.array),0))}}])&&C(e.prototype,r),t}(),L=regeneratorRuntime.mark(H),$=regeneratorRuntime.mark(G);function X(t){var e=!(arguments.length>1&&void 0!==arguments[1])||arguments[1],r=t.value,n=r.to;if(null==n)return t;if(null==n.right)n=n.left;else if(null==n.left)n=n.right;else if(e){var i=(r=(t=J(t)).value).to;n.value=i.value,n=i.right}else{var a=(r=(t=N(t)).value).to;n.value=a.value,n=a.left}return r.to=n,r.from&&(r.from[r.label]=r.to=n),t}function q(t){if(null!=t){var e=Object.assign({},t),r={value:e};do{t=r.value,r=r.next,t.left&&(r={next:r,value:t.left=Object.assign({},t.left)}),t.right&&(r={next:r,value:t.right=Object.assign({},t.right)})}while(r);return e}}function Z(t){if(null!=t){for(;t.left;)t=t.left;return t}}function D(t){var e=t.value.to;if(null==e)return t;for(;e.left;)t={next:t,value:{label:"left",from:e,to:e.left}},e=e.left;return t}function H(t){var e;return regeneratorRuntime.wrap((function(r){for(;;)switch(r.prev=r.next){case 0:for(e=void 0;t;)e={next:e,value:t},t=t.left;case 2:if(!e){r.next=11;break}return t=e.value,e=e.next,r.next=7,t;case 7:for(t=t.right;t;)e={next:e,value:t},t=t.left;r.next=2;break;case 11:case"end":return r.stop()}}),L)}function N(t){var e=t.value.to;return null==e?t:B(t={next:t,value:{label:"left",from:e,to:e.left}})}function G(t){var e;return regeneratorRuntime.wrap((function(r){for(;;)switch(r.prev=r.next){case 0:e={value:t};case 1:if(t=e.value,e=e.next,!t){r.next=8;break}return r.next=6,t;case 6:e={next:e={next:e,value:t.right},value:t.left};case 8:if(e){r.next=1;break}case 9:case"end":return r.stop()}}),$)}function Q(t){if(null!=t){for(;t.right;)t=t.right;return t}}function B(t){var e=t.value.to;if(null==e)return t;for(;e.right;)t={next:t,value:{label:"right",from:e,to:e.right}},e=e.right;return t}function V(t,e,r){for(;e;){var n=r(t,e.value);if(0==n)break;e=n<0?e.left:e.right}return e}function Y(t,e,r){for(var n=arguments.length>3&&void 0!==arguments[3]?arguments[3]:0,i=["left","right"],a=e.value.to;a;){var o=r(t,a.value)||n;if(0===o)break;var l=i[+(o>0)];e={next:e,value:{label:l,from:a,to:a[l]}},a=a[l]}return e}function J(t){var e=t.value.to;return null==e?t:D(t={next:t,value:{label:"right",from:e,to:e.right}})}function K(t){if(!(null==t||t.length<1||null==t[0])){var e=t.length,r=new Array(e);r[0]={value:t[0]};for(var n=1;n>>1],a={value:t[n]};r[n]=a,1&n?i.left=a:i.right=a}return r[0]}}function tt(t,e){var r="undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(!r){if(Array.isArray(t)||(r=function(t,e){if(t){if("string"==typeof t)return et(t,e);var r=Object.prototype.toString.call(t).slice(8,-1);return"Object"===r&&t.constructor&&(r=t.constructor.name),"Map"===r||"Set"===r?Array.from(t):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?et(t,e):void 0}}(t))||e&&t&&"number"==typeof t.length){r&&(t=r);var n=0,i=function(){};return{s:i,n:function(){return n>=t.length?{done:!0}:{done:!1,value:t[n++]}},e:function(t){throw t},f:i}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var a,o=!0,l=!1;return{s:function(){r=r.call(t)},n:function(){var t=r.next();return o=t.done,t},e:function(t){l=!0,a=t},f:function(){try{o||null==r.return||r.return()}finally{if(l)throw a}}}}function et(t,e){(null==e||e>t.length)&&(e=t.length);for(var r=0,n=new Array(e);r0){e.next=3;break}case 9:case"end":return e.stop()}}),e,this)}))},{key:W,value:regeneratorRuntime.mark((function t(){var e,r,n;return regeneratorRuntime.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:e=tt(G(this.root)),t.prev=1,e.s();case 3:if((r=e.n()).done){t.next=9;break}return n=r.value,t.next=7,n.value;case 7:t.next=3;break;case 9:t.next=14;break;case 11:t.prev=11,t.t0=t.catch(1),e.e(t.t0);case 14:return t.prev=14,e.f(),t.finish(14);case 17:case"end":return t.stop()}}),t,this,[[1,11,14,17]])}))},{key:"update",value:function(t,e){if(null==this.root)return!1;if(this.root.value===t)return this.root=P(this.compare,[this.root.left,this.root.right,{value:e}]),!0;var r,n=void 0,i=tt(G(this.root));try{for(i.s();!(r=i.n()).done;){var a=r.value;if(a.left&&a.left.value===t){n=a.left,a.left=void 0;break}if(a.right&&a.right.value===t){n=a.right,a.right=void 0;break}}}catch(t){i.e(t)}finally{i.f()}return null!=n&&(this.root=P(this.compare,[this.root,n.left,n.right,{value:e}]),!0)}}])&&rt(e.prototype,r),t}();function ot(t,e){for(var r=0;r=0&&t<=this.size&&this.array.splice(t,0,e),this.size}},{key:"addAll",value:function(t,e){return t>=0&&t<=this.size&&O(this.array,t,0,e),this.size}},{key:"clear",value:function(){this.array.length=0}},{key:"concat",value:function(){for(var e=new t(this),r=arguments.length,n=new Array(r),i=0;i=this.size?void 0:this.array[t]}},{key:"getSet",value:function(t,e){var r=void 0;return t>=0&&t=this.size?void 0:this.array.splice(t,1)[0]}},{key:"reverse",value:function(t,e){var r,n;for(t=y(g(null!==(r=t)&&void 0!==r?r:0,0,this.size),0,this.size),e=y(g(null!==(n=e)&&void 0!==n?n:this.size,0,this.size),0,this.size)-1;t=0&&t=0?function(){return Math.min(r,a.size)}:function(){return a.size+r};case 2:if(!(e0);a.next=t[o],r&&(a.next.prev=a),a=a.next,t[o]=a.next,--e[o]}while(e[0]>0&&e[1]>0);return a.next=t[+(e[0]<1)],r&&a.next&&(a.next.prev=a),i.next}(a,i,r,n),r&&(t.prev=l),[t,o[+(i[0]<1)]]}function ht(t,e){if(t){if("string"==typeof t)return ft(t,e);var r=Object.prototype.toString.call(t).slice(8,-1);return"Object"===r&&t.constructor&&(r=t.constructor.name),"Map"===r||"Set"===r?Array.from(t):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?ft(t,e):void 0}}function ft(t,e){(null==e||e>t.length)&&(e=t.length);for(var r=0,n=new Array(e);rthis.length)return this.length;var r=this._get(t-1),n={next:r.next,prev:r,value:e};return r.next=n,n.next.prev=n,++this.length}},{key:"addAll",value:function(t,e){return t>=0&&t<=this.length&&this._addAll(this._get(t),e),this.length}},{key:"clear",value:function(){this.length=0,this.root.prev=this.root.next=this.root}},{key:"concat",value:function(){for(var e=new t(this),r=arguments.length,n=new Array(r),i=0;i=(r=e+Math.min(r-e,this.length-t)))return this;if(e=this.length?void 0:this._get(t).value}},{key:"getSet",value:function(t,e){if(!(t<0||t>=this.length)){var r=this._get(t),n=r.value;return r.value=e(r.value),n}}},{key:"pop",value:function(){if(!(this.length<1)){var t=this.root.prev;return t.prev.next=this.root,this.root.prev=t.prev,--this.length,t.value}}},{key:"push",value:function(t){var e=this.root.prev,r={next:this.root,prev:e,value:t};return e.next=this.root.prev=r,++this.length}},{key:"remove",value:function(t){if(!(t<0||t>=this.length)){var e=this._get(t);return e.prev.next=e.next,e.next.prev=e.prev,--this.length,e.value}}},{key:"reverse",value:function(t,e){var r,n;if(t=y(g(null!==(r=t)&&void 0!==r?r:0,0,this.length),0,this.length),(e=y(g(null!==(n=e)&&void 0!==n?n:this.length,0,this.length),0,this.length))-t<2)return this;var i=this._get(t-1),a=i.next,o=a;do{var l=o.next;o.next=o.prev,o.prev=l,i.next=o,o=l}while(++t=this.length)){var r=this._get(t),n=r.value;return r.value=e,n}}},{key:"shift",value:function(){if(!(this.length<1)){var t=this.root.next;return t.next.prev=this.root,this.root.next=t.next,--this.length,t.value}}},{key:"size",get:function(){return this.length}},{key:"slice",value:function(e,r){return new t(this.view(e,r))}},{key:"splice",value:function(e,r,n){var i,a;e=y(g(null!==(i=e)&&void 0!==i?i:0,0,this.length),0,this.length),r=y(null!==(a=r)&&void 0!==a?a:this.size,0,this.size-e);var o=new t;if(null==n&&r<1)return o;for(var l=this._get(e);r-- >0;)o.push(l.value),l.prev.next=l.next,l.next.prev=l.prev,l=l.next,--this.length;return this._addAll(l,null!=n?n:[]),o}},{key:"sort",value:function(t){if(this.length>1){var e=(i=st(this.root.next,this.length,!0,t),a=2,function(t){if(Array.isArray(t))return t}(i)||function(t,e){var r=null==t?null:"undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(null!=r){var n,i,a=[],o=!0,l=!1;try{for(r=r.call(t);!(o=(n=r.next()).done)&&(a.push(n.value),!e||a.length!==e);o=!0);}catch(t){l=!0,i=t}finally{try{o||null==r.return||r.return()}finally{if(l)throw i}}return a}}(i,a)||ht(i,a)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()),r=e[0],n=e[1];this.root.next=r,n.next.prev=n}var i,a;return this}},{key:lt,value:regeneratorRuntime.mark((function t(){var e;return regeneratorRuntime.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:e=this.root.next;case 1:if(e===this.root){t.next=7;break}return t.next=4,e.value;case 4:e=e.next,t.next=1;break;case 7:case"end":return t.stop()}}),t,this)}))},{key:"unshift",value:function(t){var e=this.root.next,r={next:e,prev:this.root,value:t};return this.root.next=e.prev=r,++this.length}},{key:"update",value:function(t,e,r){var n,i;if(null==r&&(arguments.length<2?(r=t,t=void 0):(r=e,e=void 0)),(t=y(g(null!==(n=t)&&void 0!==n?n:0,0,this.length),0,this.length))<(e=y(g(null!==(i=e)&&void 0!==i?i:this.length,0,this.length),0,this.length))){var a=this._get(t);do{a.value=r(a.value,t),a=a.next}while(++t=0?function(){return r}:function(){return o.length+r})())){t.next=8;break}a=this._get(e);case 4:return t.next=6,a.value;case 6:a=a.next;case 7:if(++e=t.length?{done:!0}:{done:!1,value:t[n++]}},e:function(t){throw t},f:i}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var a,o=!0,l=!1;return{s:function(){r=r.call(t)},n:function(){var t=r.next();return o=t.done,t},e:function(t){l=!0,a=t},f:function(){try{o||null==r.return||r.return()}finally{if(l)throw a}}}}(e);try{for(i.s();!(r=i.n()).done;){var a={prev:n,value:r.value};n.next=a,n=a,++this.length}}catch(t){i.e(t)}finally{i.f()}n.next=t,t.prev=n}},{key:"_get",value:function(t){var e=this.root;if(t=0;)e=e.next;else for(t=this.length-t;t>0;--t)e=e.prev;return e}}])&&ct(e.prototype,r),t}();function pt(t,e){if(t){if("string"==typeof t)return dt(t,e);var r=Object.prototype.toString.call(t).slice(8,-1);return"Object"===r&&t.constructor&&(r=t.constructor.name),"Map"===r||"Set"===r?Array.from(t):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?dt(t,e):void 0}}function dt(t,e){(null==e||e>t.length)&&(e=t.length);for(var r=0,n=new Array(e);r=0&&t=0&&t=(r=e+Math.min(r-e,this.length-t)))return this;if(tr){var o=this._get(e-1);return this._copyWithin(o,this._get(t-e-1,o),r-e),this}var l=this._get(e-1),u=this._get(r-e-1,l),s=this._copyWithin(l,u,t-e);t+(r-e)>=this.length&&(this.tail=u);var h=l.next;return l.next=u.next,u.next=s.next,s.next=h,this}},{key:"fill",value:function(t,e,r){var n,i;if((e=y(g(null!==(n=e)&&void 0!==n?n:0,0,this.length),0,this.length))<(r=y(g(null!==(i=r)&&void 0!==i?i:this.length,0,this.length),0,this.length))){var a=this._get(e);do{a.value=t,a=a.next}while(++e=this.length))return t=this.length)){var r=t=this.length)){var e=this._get(t-1),r=e.next;return e.next=r.next,t===--this.length&&(this.tail=e),r.value}}},{key:"reverse",value:function(t,e){var r,n;if(t=y(g(null!==(r=t)&&void 0!==r?r:0,0,this.length),0,this.length),(e=y(g(null!==(n=e)&&void 0!==n?n:this.length,0,this.length),0,this.length))-t<2)return this;var i=this._get(t-1);this.tail=e>=this.length?i.next:this.tail;for(var a=i.next,o=a,l=a.next;++t=this.length)){var r=this._get(t),n=r.value;return r.value=e,n}}},{key:"shift",value:function(){return this.remove(0)}},{key:"size",get:function(){return this.length}},{key:"slice",value:function(e,r){return new t(this.view(e,r))}},{key:"splice",value:function(e,r,n){var i,a;e=y(g(null!==(i=e)&&void 0!==i?i:0,0,this.length),0,this.length),r=y(null!==(a=r)&&void 0!==a?a:this.size,0,this.size-e);var o=new t;if(null==n&&r<1)return o;for(var l=this._get(e-1),u=e+r>=this.size;r-- >0;){var s=l.next;o.push(s.value),l.next=s.next,--this.length}return l=this._addAll(l,null!=n?n:[]),this.tail=u?l:this.tail,o}},{key:"sort",value:function(t){if(this.length>1){var e=(i=st(this.root.next,this.length,!1,t),a=2,function(t){if(Array.isArray(t))return t}(i)||function(t,e){var r=null==t?null:"undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(null!=r){var n,i,a=[],o=!0,l=!1;try{for(r=r.call(t);!(o=(n=r.next()).done)&&(a.push(n.value),!e||a.length!==e);o=!0);}catch(t){l=!0,i=t}finally{try{o||null==r.return||r.return()}finally{if(l)throw i}}return a}}(i,a)||pt(i,a)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()),r=e[0],n=e[1];this.root.next=r,this.tail=n}var i,a;return this}},{key:yt,value:regeneratorRuntime.mark((function t(){var e;return regeneratorRuntime.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:e=this.root.next;case 1:if(e===this.root){t.next=7;break}return t.next=4,e.value;case 4:e=e.next,t.next=1;break;case 7:case"end":return t.stop()}}),t,this)}))},{key:"unshift",value:function(t){return this.add(0,t)}},{key:"update",value:function(t,e,r){var n,i;if(null==r&&(arguments.length<2?(r=t,t=void 0):(r=e,e=void 0)),(t=y(g(null!==(n=t)&&void 0!==n?n:0,0,this.length),0,this.length))<(e=y(g(null!==(i=e)&&void 0!==i?i:this.length,0,this.length),0,this.length))){var a=this._get(t);do{a.value=r(a.value,t),a=a.next}while(++t=0?function(){return r}:function(){return o.length+r})())){t.next=8;break}a=this._get(e);case 4:return t.next=6,a.value;case 6:a=a.next;case 7:if(++e=t.length?{done:!0}:{done:!1,value:t[n++]}},e:function(t){throw t},f:i}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var a,o=!0,l=!1;return{s:function(){r=r.call(t)},n:function(){var t=r.next();return o=t.done,t},e:function(t){l=!0,a=t},f:function(){try{o||null==r.return||r.return()}finally{if(l)throw a}}}}(e);try{for(i.s();!(r=i.n()).done;){var a={value:r.value};t.next=a,t=a,++this.length}}catch(t){i.e(t)}finally{i.f()}return t.next=n,t}},{key:"_copyWithin",value:function(t,e,r){for(;r-- >0;)t=t.next,(e=e.next).value=t.value;return e}},{key:"_get",value:function(t){for(var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:this.root,r=e;t-- >=0;)r=r.next;return r}}])&&bt(e.prototype,r),t}();function wt(t){for(var e=0;t;)++e,t&=t-1;return e}function At(t){var e=Rt(t);return Pt(t^(e|e-1))}function St(t){return 0==(t&t-1)}function zt(t){var e=-1;for(t=jt(t);t;t>>>=1)++e;return e}function jt(t){return Pt(t&-t)}function Ot(t){return Pt(t&jt(t+jt(t))-1)}function _t(t){for(var e=-1;0!==t;)++e,t>>>=1;return e}function Rt(t){for(var e=t&-t;t!=e;)e=(t^=e)&-t;return Pt(e)}function It(t){for(var e=t&-t;t&t+e;)e=(t^=e)&-t;return Pt(t)}function Et(t){return Pt((t=(4278255360&(t=(4042322160&(t=(3435973836&(t=(2863311530&t)>>>1|(1431655765&t)<<1))>>>2|(858993459&t)<<2))>>>4|(252645135&t)<<4))>>>8|(16711935&t)<<8)>>>16|t<<16)}function Pt(t){return t>>>0}function Tt(t,e){for(var r=0;rt.length)&&(e=t.length);for(var r=0,n=new Array(e);r1&&void 0!==arguments[1]?arguments[1]:[];$t(this,t),qt(this,"array",void 0),qt(this,"combine",void 0),this.array=[],this.combine=e,this.build(r)}var e,r;return e=t,(r=[{key:"clear",value:function(){this.array.length=0}},{key:"pop",value:function(){if(!(this.size<1)){for(var t=this.array.length-1,e=2;t&e;e*=2)this.array[t-e]=this.array[t-e-(e>>>1)];var r=this.array[t-1];return this.array.length-=2,r}}},{key:"push",value:function(e){if(this.size>=t.MAX_SIZE)throw new RangeError("Invalid length");var r=this.array.length;return this.array[r+1]=this.set(r,e),this.size}},{key:"query",value:function(t,e){if(t>=e)throw new RangeError("Range [".concat(t,"..").concat(e,") is empty"));if(t<0||e>this.size)throw new RangeError("Range [".concat(t,"..").concat(e,") not in [0..").concat(this.size,")"));var r=jt((t*=2)|Rt((e*=2)-t)),n=this.array[t-1+(r>>>1)];for(t+=r;t>>1)]);return n}},{key:"size",get:function(){return this.array.length>>>1}},{key:Wt,value:regeneratorRuntime.mark((function t(){var e;return regeneratorRuntime.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:e=0;case 1:if(!(e=e)){if(t<0||e>this.size)throw new RangeError("Range [".concat(t,"..").concat(e,") not in [0..").concat(this.size,")"));var n;t*=2,e*=2;do{n=this.set(t,r(this.array[t],t>>>1)),t+=2}while(t0;--e)n=this.combine(n,this.array[t+(a>>>1)-i]),this.array[t]=n,t+=a-(i=(t&2*a)>>>0),a*=2;this.array[t]=n}}},{key:"build",value:function(t){var e,r=function(t,e){var r="undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(!r){if(Array.isArray(t)||(r=function(t,e){if(t){if("string"==typeof t)return Lt(t,e);var r=Object.prototype.toString.call(t).slice(8,-1);return"Object"===r&&t.constructor&&(r=t.constructor.name),"Map"===r||"Set"===r?Array.from(t):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?Lt(t,e):void 0}}(t))||e&&t&&"number"==typeof t.length){r&&(t=r);var n=0,i=function(){};return{s:i,n:function(){return n>=t.length?{done:!0}:{done:!1,value:t[n++]}},e:function(t){throw t},f:i}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var a,o=!0,l=!1;return{s:function(){r=r.call(t)},n:function(){var t=r.next();return o=t.done,t},e:function(t){l=!0,a=t},f:function(){try{o||null==r.return||r.return()}finally{if(l)throw a}}}}(t);try{for(r.s();!(e=r.n()).done;){var n=e.value;this.push(n)}}catch(t){r.e(t)}finally{r.f()}}},{key:"set",value:function(t,e){this.array[t++]=e;for(var r=2;t&r;r*=2)e=this.combine(this.array[t-r-(r>>>1)],e),this.array[t-r]=e;return e}}])&&Xt(e.prototype,r),t}();function Ht(t,e){var r="undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(!r){if(Array.isArray(t)||(r=function(t,e){if(t){if("string"==typeof t)return Nt(t,e);var r=Object.prototype.toString.call(t).slice(8,-1);return"Object"===r&&t.constructor&&(r=t.constructor.name),"Map"===r||"Set"===r?Array.from(t):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?Nt(t,e):void 0}}(t))||e&&t&&"number"==typeof t.length){r&&(t=r);var n=0,i=function(){};return{s:i,n:function(){return n>=t.length?{done:!0}:{done:!1,value:t[n++]}},e:function(t){throw t},f:i}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var a,o=!0,l=!1;return{s:function(){r=r.call(t)},n:function(){var t=r.next();return o=t.done,t},e:function(t){l=!0,a=t},f:function(){try{o||null==r.return||r.return()}finally{if(l)throw a}}}}function Nt(t,e){(null==e||e>t.length)&&(e=t.length);for(var r=0,n=new Array(e);r>>1),Zt=Symbol.iterator;var Vt,Yt=function(){function t(e){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:[];Gt(this,t),Bt(this,"array",void 0),Bt(this,"combine",void 0),Bt(this,"length",void 0),Bt(this,"level",void 0),this.array=[],this.combine=e,this.length=0,this.level=0,this.build(r)}var e,r;return e=t,(r=[{key:"clear",value:function(){this.length=0,this.level=0,this.array.length=0}},{key:"pop",value:function(){if(!(this.length<=this.level)){var t=this.array[--this.length];return this.length<=this.array.length+1>>>2&&this.shrink(),t}}},{key:"push",value:function(t){this.length>=this.array.length&&this.grow(),this.array[this.length++]=t;for(var e=this.length;1&e;this.array[e-1]=t)t=this.combine(this.array[e-2],t),e>>>=1;return this.size}},{key:"query",value:function(t,e){if(t>=e)throw new RangeError("Range [".concat(t,"..").concat(e,") is empty"));if(t<0||e>this.size)throw new RangeError("Range [".concat(t,"..").concat(e,") not in [0..").concat(this.size,")"));var r=jt((t+=this.level+1)|Rt((e+=this.level+1)-t)),n=this.array[t/r-1];for(t+=r;t=e)){if(t<0||e>this.size)throw new RangeError("Range [".concat(t,"..").concat(e,") not in [0..").concat(this.size,")"));t+=this.level,e+=this.level;for(var n=t;n>>=1){e+=e&e-r>>>31;for(var n=(1|t)>>>0;n>>1)-1]=this.combine(this.array[n-2],this.array[n-1]);t>>>=1,e>>>=1}}},{key:"build",value:function(e){var r=void 0;if(A(e))r="length";else{if(!_(e)){var n,i=Ht(e);try{for(i.s();!(n=i.n()).done;){var a=n.value;this.push(a)}}catch(t){i.e(t)}finally{i.f()}return}r="size"}var o=e[r];if(o<1)return this.array.length=0,this.length=0,void(this.level=0);if(o>=t.MAX_SIZE)throw new RangeError("Invalid length");this.level=2*Rt(o-1)-1,this.length=this.level,this.array.length=2*this.level+1;var l,u=Ht(e);try{for(u.s();!(l=u.n()).done;){var s=l.value;this.array[this.length++]=s}}catch(t){u.e(t)}finally{u.f()}this.aggregate(this.level,this.length)}},{key:"grow",value:function(){if(this.size<1)this.array.length=1;else{if(this.size>=t.MAX_SIZE)throw new RangeError("Invalid length");this.array.length+=this.array.length+1;for(var e=this.level+1,r=this.length+1;e>>=1)this.array.copyWithin(2*e-1,e-1,r-1),e>>>=1;this.length+=this.level+1,this.level+=this.level+1}}},{key:"shrink",value:function(){var t=this.length-this.level;if(t<2)return this.array.copyWithin(0,this.level,this.length),this.level=0,this.length=t,void(this.array.length=t);var e=this.level+1,r=Rt(t);e=e/jt(e|r)-1,this.level=+!St(t);for(var n=e+1;r;this.level+=this.level+1)this.array.copyWithin(this.level,e,n),e+=e+1,n+=n+2+ +((t&(r>>>=1))>0);this.length=this.level+t,this.array.length=2*this.level+1}}])&&Qt(e.prototype,r),t}();function Jt(t,e){for(var r=0;r0)){t.next=7;break}case 3:return t.next=5,e[--r];case 5:t.next=2;break;case 7:case"end":return t.stop()}}),t,this)}))}])&&Jt(e.prototype,r),t}();function ee(t,e){(null==e||e>t.length)&&(e=t.length);for(var r=0,n=new Array(e);r=t.length?{done:!0}:{done:!1,value:t[n++]}},e:function(t){throw t},f:i}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var a,o=!0,l=!1;return{s:function(){r=r.call(t)},n:function(){var t=r.next();return o=t.done,t},e:function(t){l=!0,a=t},f:function(){try{o||null==r.return||r.return()}finally{if(l)throw a}}}}(e||[]);try{for(a.s();!(i=a.n()).done;){var o=i.value;this.push(o)}}catch(t){a.e(t)}finally{a.f()}}var e,r;return e=t,(r=[{key:"clear",value:function(){this.list.clear()}},{key:"peek",value:function(){return this.list.get(0)}},{key:"pop",value:function(){return this.list.shift()}},{key:"push",value:function(t){return this.list.unshift(t)}},{key:"size",get:function(){return this.list.size}},{key:Kt,value:function(){return this.list[Symbol.iterator]()}}])&&re(e.prototype,r),t}();function ae(t,e){var r="undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(!r){if(Array.isArray(t)||(r=function(t,e){if(t){if("string"==typeof t)return oe(t,e);var r=Object.prototype.toString.call(t).slice(8,-1);return"Object"===r&&t.constructor&&(r=t.constructor.name),"Map"===r||"Set"===r?Array.from(t):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?oe(t,e):void 0}}(t))||e&&t&&"number"==typeof t.length){r&&(t=r);var n=0,i=function(){};return{s:i,n:function(){return n>=t.length?{done:!0}:{done:!1,value:t[n++]}},e:function(t){throw t},f:i}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var a,o=!0,l=!1;return{s:function(){r=r.call(t)},n:function(){var t=r.next();return o=t.done,t},e:function(t){l=!0,a=t},f:function(){try{o||null==r.return||r.return()}finally{if(l)throw a}}}}function oe(t,e){(null==e||e>t.length)&&(e=t.length);for(var r=0,n=new Array(e);r=t.length?{done:!0}:{done:!1,value:t[n++]}},e:function(t){throw t},f:i}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var a,o=!0,l=!1;return{s:function(){r=r.call(t)},n:function(){var t=r.next();return o=t.done,t},e:function(t){l=!0,a=t},f:function(){try{o||null==r.return||r.return()}finally{if(l)throw a}}}}function ge(t,e){(null==e||e>t.length)&&(e=t.length);for(var r=0,n=new Array(e);r1?(t.right.balanceFactor<0&&(t.right=we(t.right)),t=xe(t)):t.balanceFactor<-1&&(t.left.balanceFactor>0&&(t.left=xe(t.left)),t=we(t)),t}function ke(t){var e=t.value;if(null==e.to)return!1;for(var r=(t=X(t)).value.label;t.next&&((e=(t=t.next).value).to.balanceFactor-="left"===r?-1:1,e.to=me(e.to),e.from[r=e.label]=e.to,0===e.to.balanceFactor););return!0}function xe(t){var e=t.right;return t.right=e.left,e.left=t,t.balanceFactor-=1+Math.max(0,e.balanceFactor),e.balanceFactor-=1-Math.min(0,t.balanceFactor),e}function we(t){var e=t.left;return t.left=e.right,e.right=t,t.balanceFactor+=1-Math.min(0,e.balanceFactor),e.balanceFactor+=1+Math.max(0,t.balanceFactor),e}return e})()})); //# sourceMappingURL=dastal.min.js.map \ No newline at end of file diff --git a/dist/dastal.min.js.map b/dist/dastal.min.js.map index 1638147..ede780b 100644 --- a/dist/dastal.min.js.map +++ b/dist/dastal.min.js.map @@ -1 +1 @@ -{"version":3,"sources":["webpack://Dastal/webpack/universalModuleDefinition","webpack://Dastal/webpack/bootstrap","webpack://Dastal/webpack/runtime/define property getters","webpack://Dastal/webpack/runtime/hasOwnProperty shorthand","webpack://Dastal/webpack/runtime/make namespace object","webpack://Dastal/./src/array/utils.ts","webpack://Dastal/./src/heap/utils.ts","webpack://Dastal/./src/heap/binaryHeap.ts","webpack://Dastal/./src/tree/binaryTreeUtils.ts","webpack://Dastal/./src/heap/skewHeap.ts","webpack://Dastal/./src/math/num.ts","webpack://Dastal/./src/list/utils.ts","webpack://Dastal/./src/list/arrayList.ts","webpack://Dastal/./src/list/doublyLinkedList.ts","webpack://Dastal/./src/list/linkedList.ts","webpack://Dastal/./src/math/u32.ts","webpack://Dastal/./src/queue/arrayQueue.ts","webpack://Dastal/./src/queue/linkedQueue.ts","webpack://Dastal/./src/segmentTree/inOrderSegmentTree.ts","webpack://Dastal/./src/segmentTree/levelOrderSegmentTree.ts","webpack://Dastal/./src/collection/index.ts","webpack://Dastal/./src/stack/arrayStack.ts","webpack://Dastal/./src/stack/linkedStack.ts","webpack://Dastal/./src/tree/aaTree.ts","webpack://Dastal/./src/tree/avlTree.ts"],"names":["root","factory","exports","module","define","amd","self","__webpack_require__","definition","key","o","Object","defineProperty","enumerable","get","obj","prop","prototype","hasOwnProperty","call","Symbol","toStringTag","value","MAX_ARRAY_LENGTH","isArray","Array","isTypedArray","TypedArray","getPrototypeOf","Uint8Array","bubbleUp","index","compareFn","array","parentIndex","Math","floor","parent","heapify","i","length","sinkDown","n","childIndex","child","skewMerge","heaps","lists","push","list","tree","right","next","compare","a","b","tail","pop","mergeKSorted","heap","node","left","iterator","BinaryHeap","elements","this","addAll","RangeError","element","indexOf","last","size","undefined","curElement","newElement","inOrderTraverse","preOrderTraverse","removeStack","stack","dir","edge","to","temp","successorStack","predecessorStack","from","label","clone","out","assign","leftmost","leftmostStack","rightmostStack","rightmost","search","comp","searchStack","dupeWeight","paths","toBinaryTree","nodes","par","SkewHeap","merge","comparator","clamp","num","min","max","batchArray","batchIterable","batch","iterable","slice","f","cwrap","pivot","nwrap","linkedMergeSort","len","isDoubly","lens","ceil","heads","tails","prev","linkedMergeSorted","ArrayList","splice","items","copyWithin","fill","callback","shift","start","count","sort","unshift","arguments","DoublyLinkedList","_addAll","_get","nodeA","nodeB","head","view","LinkedList","_copyWithin","nodeC","nodeD","remove","deleted","newTail","add","bitsSet","invert","msp","u32","isPow2","lsb","lsp","lsps","mlsp","msb","msps","reverse","ArrayQueue","LinkedQueue","clear","InOrderSegmentTree","combine","build","mask","MAX_SIZE","set","offset","operation","dc","dp","LevelOrderSegmentTree","level","shrink","grow","aggregate","cap","ArrayStack","LinkedStack","AATree","allowDuplicates","sentinel","split","skew","removed","delete","AVLTree","balanceFactor","balance","rotateR","rotateL","P","R","L"],"mappings":"CAAA,SAA2CA,EAAMC,GAC1B,iBAAZC,SAA0C,iBAAXC,OACxCA,OAAOD,QAAUD,IACQ,mBAAXG,QAAyBA,OAAOC,IAC9CD,OAAO,SAAU,GAAIH,GACK,iBAAZC,QACdA,QAAgB,OAAID,IAEpBD,EAAa,OAAIC,IARnB,CASGK,MAAM,WACT,M,mBCTA,IAAIC,EAAsB,CCA1B,EAAwB,CAACL,EAASM,KACjC,IAAI,IAAIC,KAAOD,EACXD,EAAoBG,EAAEF,EAAYC,KAASF,EAAoBG,EAAER,EAASO,IAC5EE,OAAOC,eAAeV,EAASO,EAAK,CAAEI,YAAY,EAAMC,IA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ZA,EAKJ,SAAS0F,GAAUxE,GACtB,IAAIE,EAAOF,EAAMxD,MAIjB,GAAY,MAHC0D,EAAKC,GAId,OAAO,EAQX,IADA,IAAIK,GAHJR,EAAQD,EAAYC,IAGFxD,MAAMgE,MACjBR,EAAM1B,QAET4B,GADAF,EAAQA,EAAM1B,MACD9B,OACR2D,GAAIkH,eAA2B,SAAV7G,GAAoB,EAAI,EAClDN,EAAKC,GAAKmH,GAAQpH,EAAKC,IACvBD,EAAKK,KAAOC,EAAQN,EAAKM,OAAWN,EAAKC,GACV,IAA3BD,EAAKC,GAAIkH,iBAKjB,OAAO,EAKJ,SAASG,GAAWC,GACvB,IAAMC,EAAID,EAAEpJ,MAKZ,OAJAoJ,EAAEpJ,MAAQqJ,EAAE3I,KACZ2I,EAAE3I,KAAO0I,EACTA,EAAEJ,eAAiB,EAAIhK,KAAKyE,IAAI,EAAG4F,EAAEL,eACrCK,EAAEL,eAAiB,EAAIhK,KAAKwE,IAAI,EAAG4F,EAAEJ,eAC9BK,EAKJ,SAASH,GAAWE,GACvB,IAAME,EAAIF,EAAE1I,KAKZ,OAJA0I,EAAE1I,KAAO4I,EAAEtJ,MACXsJ,EAAEtJ,MAAQoJ,EACVA,EAAEJ,eAAiB,EAAIhK,KAAKwE,IAAI,EAAG8F,EAAEN,eACrCM,EAAEN,eAAiB,EAAIhK,KAAKyE,IAAI,EAAG2F,EAAEJ,eAC9BM,E","file":"dastal.min.js","sourcesContent":["(function webpackUniversalModuleDefinition(root, factory) {\n\tif(typeof exports === 'object' && typeof module === 'object')\n\t\tmodule.exports = factory();\n\telse if(typeof define === 'function' && define.amd)\n\t\tdefine(\"Dastal\", [], factory);\n\telse if(typeof exports === 'object')\n\t\texports[\"Dastal\"] = factory();\n\telse\n\t\troot[\"Dastal\"] = factory();\n})(self, function() {\nreturn ","// The require scope\nvar __webpack_require__ = {};\n\n","// define getter functions for harmony exports\n__webpack_require__.d = (exports, definition) => {\n\tfor(var key in definition) {\n\t\tif(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {\n\t\t\tObject.defineProperty(exports, key, { enumerable: true, get: definition[key] });\n\t\t}\n\t}\n};","__webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))","// define __esModule on exports\n__webpack_require__.r = (exports) => {\n\tif(typeof Symbol !== 'undefined' && Symbol.toStringTag) {\n\t\tObject.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });\n\t}\n\tObject.defineProperty(exports, '__esModule', { value: true });\n};","/**\n * The maximum length of an array.\n *\n * According to [ECMA-262](https://tc39.es/ecma262/#array-index):\n * 0 <= array.length <= 2^32 - 1\n */\nexport const MAX_ARRAY_LENGTH = 4294967295;\n/**\n * Check if a value is an Array or TypedArray.\n *\n * @param obj - The value to check.\n *\n * @returns `true` if an Array or TypedArray, otherwise `false`.\n */\nexport function isArray(obj: unknown): obj is T[] {\n return obj instanceof Array || isTypedArray(obj);\n}\n/**\n * Check if a value is a TypedArray.\n *\n * See [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray)\n * for more details.\n *\n * @param obj - The value to check.\n *\n * @returns `true` if a TypedArray, otherwise `false`.\n */\nexport const isTypedArray = (() => {\n const TypedArray = Object.getPrototypeOf(Uint8Array);\n return function isTypedArray(obj: unknown): obj is T[] {\n return obj instanceof TypedArray;\n };\n})();\n","import { LinkedNode } from 'src/list';\nimport { BinaryTreeNode } from 'src/tree/binaryTreeNode';\nimport { CompareFn } from '..';\n\n/**\n * @internal\n */\nexport function bubbleUp(index: number, compareFn: CompareFn, array: Array): void {\n const value = array[index];\n\n // Until we reach the top of the heap\n while (index > 0) {\n // Get the parent\n const parentIndex = Math.floor((index + 1) / 2) - 1;\n const parent = array[parentIndex]!;\n\n // If the parent is above or equal to value, the heap is in order\n if (compareFn(parent, value) <= 0) {\n break;\n }\n\n // Swap the parent with value and continue\n array[parentIndex] = value;\n array[index] = parent;\n index = parentIndex;\n }\n}\n/**\n * @internal\n */\nexport function heapify(compareFn: CompareFn, array: T[]): void {\n for (let i = (array.length + 1) >>> 1; i > 0; sinkDown(--i, compareFn, array)) {}\n}\n/**\n * @internal\n */\nexport function mergeKSorted(compareFn: CompareFn, lists: LinkedNode[]): LinkedNode {\n // Heapify the list of lists based on\n // the value at the head of each list.\n const compare: CompareFn> = (a, b) => compareFn(a.value, b.value);\n heapify(compare, lists);\n\n // Combine the lists into a single list.\n const list: LinkedNode = lists[0];\n for (let tail = list; lists.length > 1; tail = tail.next) {\n lists[0] = lists[0].next ?? lists.pop()!;\n sinkDown(0, compare, lists);\n tail.next = lists[0];\n }\n\n return list;\n}\n/**\n * @internal\n */\nexport function sinkDown(index: number, compareFn: CompareFn, array: Array): void {\n const n = array.length;\n const value = array[index];\n do {\n // Compute the left child's index\n let childIndex = 2 * index + 1;\n\n // If no children exist\n if (childIndex >= n) {\n break;\n }\n\n // Decide which child to compare with\n let child = array[childIndex];\n if (childIndex + 1 < n && compareFn(array[childIndex + 1], child) <= 0) {\n child = array[++childIndex]!;\n }\n\n // If value <= child\n if (compareFn(value, child) <= 0) {\n break;\n }\n\n // Swap value and child\n array[index] = child;\n array[childIndex] = value;\n index = childIndex;\n } while (true);\n}\n/**\n * See: https://en.wikipedia.org/wiki/Skew_heap#Merging_two_heaps\n *\n * @param compareFn - A function used to determine the order of the heap.\n *\n * It is expected to return:\n * - A negative value if first argument < second argument\n * - Zero if first argument == second argument\n * - A positive value if first argument > second argument\n * @param heaps - An iterable of heaps to merge\n *\n * @returns The new heap\n */\nexport function skewMerge(\n compareFn: CompareFn,\n heaps: (BinaryTreeNode | undefined)[],\n): BinaryTreeNode | undefined {\n // Remove undefineds and initialize a list for each heap\n const lists: LinkedNode>[] = [];\n for (let i = 0; i < heaps.length; ++i) {\n if (heaps[i] != null) {\n lists.push({ value: heaps[i]! });\n }\n }\n\n // Check if nothing to merge with\n if (lists.length < 2) {\n return lists[0]?.value;\n }\n\n // Split each heap into subheaps by cutting every right path; From the root\n // node, sever the right node to make the right child its own heap. Repeat\n // until you can't go right. This will turn each heap into a list of heaps\n // where the root either only has a left child or no children at all. The\n // lists of heaps will be in desc order (from bottom to top).\n for (let i = 0; i < lists.length; ++i) {\n let list = lists[i];\n let tree: BinaryTreeNode | undefined = list.value;\n while ((tree = tree.right)) {\n list = { next: list, value: tree };\n }\n lists[i] = list;\n }\n\n // Combine the lists into a single list in desc order\n let list: LinkedNode> | undefined = mergeKSorted(\n (a, b) => compareFn(b.value, a.value),\n lists,\n );\n\n // While there are still multiple heaps, iteratively combine\n // the first two (from left to right). If the root of the second-to-first\n // subtree has a left child, swap it to be the right child. Link the root\n // of the last subtree as the left child of the second-to-first subtree.\n let heap = list.value;\n while ((list = list.next)) {\n const node = list.value;\n node.right = node.left;\n node.left = heap;\n heap = node;\n }\n\n return heap;\n}\n","import { isArray, MAX_ARRAY_LENGTH } from 'src/array/utils';\nimport { CompareFn } from '..';\nimport { Heap } from './heap';\nimport { bubbleUp, heapify, sinkDown } from './utils';\n\n/**\n * A binary heap is a heap implemented as a binary tree with an additional shape property\n * ([source](https://en.wikipedia.org/wiki/Binary_heap)).\n *\n * **Shape property**: Must be a complete binary tree. This means all levels of the tree\n * (except possibly the last one) are fully filled. If the last level of the tree is incomplete,\n * the nodes of that level are filled from left to right.\n *\n * #### Complexity\n *\n * | Property | Average | Worst |\n * | :------- | :------ | :---- |\n * | Space | O(n) | O(n)\n * | Push | O(1) | O(log n)\n * | Peek | O(1)\t| O(1)\n * | Pop | O(log n)| O(log n)\n * | Search | O(n) | O(n)\n */\nexport class BinaryHeap implements Heap {\n /**\n * The array containing every element.\n */\n protected array: T[];\n /**\n * The function to determine the order of elements.\n */\n protected compare: CompareFn;\n /**\n * Instantiate a heap.\n *\n * @param compareFn - The function to determine the order of elements.\n * @param elements - A set of elements to initialize the list with.\n */\n constructor(compareFn: CompareFn, elements?: Iterable) {\n this.compare = compareFn;\n this.array = [];\n this.addAll(elements ?? []);\n }\n\n addAll(elements: Iterable): number {\n const array = this.array;\n const length = array.length;\n\n if (isArray(elements)) {\n if (array.length + elements.length > MAX_ARRAY_LENGTH) {\n throw new RangeError('Invalid heap length');\n }\n for (let i = 0; i < elements.length; ++i) {\n array.push(elements[i]);\n }\n } else {\n for (const element of elements) {\n if (array.length >= MAX_ARRAY_LENGTH) {\n throw new RangeError('Invalid heap length');\n }\n array.push(element);\n }\n }\n\n // Update the heap\n if (length < array.length) {\n heapify(this.compare, array);\n }\n\n return array.length;\n }\n\n clear(): void {\n this.array.length = 0;\n }\n\n comparator(): CompareFn {\n return this.compare;\n }\n\n contains(element: T): boolean {\n return this.array.indexOf(element) >= 0;\n }\n\n delete(element: T): boolean {\n const index = this.array.indexOf(element);\n if (index < 0) {\n return false;\n }\n\n // If deleting the last value\n const last = this.array.pop()!;\n if (index >= this.array.length) {\n return true;\n }\n\n // Add the last value to the\n // deleted index and update the heap\n this.array[index] = last;\n sinkDown(index, this.compare, this.array);\n bubbleUp(index, this.compare, this.array);\n return true;\n }\n\n merge(heap: Heap): this {\n const array = this.array;\n\n if (heap.size < 1) {\n return this;\n }\n\n if (array.length + heap.size > MAX_ARRAY_LENGTH) {\n throw new RangeError('Invalid heap length');\n }\n\n for (const element of heap) {\n array.push(element);\n }\n\n heapify(this.compare, array);\n return this;\n }\n\n peek(): T | undefined {\n return this.array.length > 0 ? this.array[0] : undefined;\n }\n\n pop(): T | undefined {\n if (this.array.length < 1) {\n return undefined;\n }\n\n // Get the root and the last value\n const value = this.array[0];\n const last = this.array.pop();\n\n // If value != last\n if (this.array.length > 0) {\n // Move the last value to the root and update the heap\n this.array[0] = last!;\n sinkDown(0, this.compare, this.array);\n }\n\n return value;\n }\n\n push(value: T): number {\n // Add new value to the end of the heap\n this.array.push(value);\n\n // Update the heap\n bubbleUp(this.array.length - 1, this.compare, this.array);\n return this.size;\n }\n\n pushPop(value: T): T {\n // If empty or value is <= to root\n if (this.array.length < 1 || this.compare(value, this.array[0]) <= 0) {\n return value;\n }\n\n // Swap the root and value\n const root = this.array[0];\n this.array[0] = value;\n sinkDown(0, this.compare, this.array);\n return root;\n }\n\n replace(value: T): T | undefined {\n // If empty\n if (this.array.length < 1) {\n this.array.push(value);\n return undefined;\n }\n\n // Swap the root with value\n const root = this.array[0];\n this.array[0] = value;\n value = root;\n\n // Update the heap\n sinkDown(0, this.compare, this.array);\n return value;\n }\n\n get size(): number {\n return this.array.length;\n }\n\n *sorted(): Iterable {\n if (this.array.length < 1) {\n return;\n }\n const array = this.array;\n const heap = new BinaryHeap((a, b) => this.compare(array[a], array[b]), [0]);\n do {\n let index = heap.pop()!;\n if (index < array.length) {\n yield array[index];\n index = 2 * index + 1;\n index < array.length && heap.push(index);\n ++index < array.length && heap.push(index);\n }\n } while (heap.size > 0);\n }\n /**\n * Receive an iterator through the list.\n *\n * **Note:** Unexpected behavior can occur if the collection is modified during iteration.\n *\n * @returns An iterator through the list\n */\n [Symbol.iterator](): Iterator {\n return this.array[Symbol.iterator]();\n }\n\n update(curElement: T, newElement: T): boolean {\n const index = this.array.indexOf(curElement);\n if (index < 0) {\n return false;\n }\n this.array[index] = newElement;\n sinkDown(index, this.compare, this.array);\n bubbleUp(index, this.compare, this.array);\n return true;\n }\n}\n","import { LinkedNode } from 'src/list';\nimport { CompareFn } from '..';\nimport { BinaryTreeNode } from './binaryTreeNode';\n\n/**\n * @internal\n */\nexport interface Edge> {\n label?: 'left' | 'right';\n from?: Node;\n to?: Node;\n}\n/**\n * [source](https://stackoverflow.com/questions/51419176/how-to-get-a-subset-of-keyof-t-whose-value-tk-are-callable-functions-in-typ)\n * \n * @internal\n *\nexport type KeyOfType = {[K in keyof T]: T[K] extends U ? K: never}[keyof T];\n*/\n/**\n * @internal\n */\nexport function debug, T = any>(\n root: N | undefined,\n mapFn?: (node: N) => any,\n): void {\n mapFn = mapFn == null ? (n) => n.value : mapFn;\n\n // Turn the tree into an array in level-order\n const array: string[] = [];\n for (const node of levelOrderTraverse(root, true)) {\n array.push(node ? `${mapFn(node)}` : '?');\n }\n\n // If empty\n if (array.length < 1) {\n console.log('\\n');\n return;\n }\n\n // Find the longest value string\n const lenV = array.reduce((p, c) => Math.max(p, c.length), 0);\n\n // Pad each value\n for (let i = 0; i < array.length; ++i) {\n array[i] = pad(array[i], lenV, ' ');\n }\n\n // Split values into levels\n const levels = [];\n for (let n = 1; array.length > 0; n *= 2) {\n levels.push(array.splice(0, n));\n }\n\n // Initialize formatting variables\n let branch = '_'.repeat(1 + lenV / 2);\n let offset = '';\n const offsetOffset = ' '.repeat(branch.length);\n let separator = ' '.repeat(1 + ((lenV - 1) & 1));\n const separatorOffset = ' '.repeat(lenV);\n\n // Build the last level\n array.length = levels.length;\n array[array.length - 1] = levels.pop()!.join(separator);\n\n // Build remaining levels in reverse\n for (let n = levels.length - 1; n >= 0; --n) {\n const level = levels.pop()!;\n for (let j = 0; j < level.length; ++j) {\n level[j] = branch + level[j] + branch;\n }\n array[n] = offset + level.join(separator);\n branch += branch;\n offset += offset + offsetOffset;\n separator += separator + separatorOffset;\n }\n\n // Output\n console.log(array.join('\\n'), '\\n');\n}\n/**\n * @internal\n */\nexport function removeStack>(\n stack: LinkedNode>,\n dir = true,\n): LinkedNode> {\n let edge = stack.value;\n let node = edge.to;\n\n // Input check\n if (node == null) {\n return stack;\n }\n\n // Find the replacement\n if (node.right == null) {\n // If no right child, replace with left\n node = node.left;\n } else if (node.left == null) {\n // If no left child, replace with right\n node = node.right;\n } else if (dir) {\n // Replace with the successor\n stack = successorStack(stack);\n edge = stack.value;\n const temp = edge.to!;\n node.value = temp.value;\n node = temp.right;\n } else {\n // Replace with the predecessor\n stack = predecessorStack(stack);\n edge = stack.value;\n const temp = edge.to!;\n node.value = temp.value;\n node = temp.left;\n }\n\n // Make the replacement / update the tree\n edge.to = node;\n if (edge.from) {\n edge.from[edge.label!] = edge.to = node;\n }\n\n return stack;\n}\n/**\n * @internal\n */\nexport function clone>(node: undefined): undefined;\nexport function clone>(node: Node): Node;\nexport function clone>(node: Node | undefined): Node | undefined;\nexport function clone>(node: Node | undefined): Node | undefined {\n if (node == null) {\n return undefined;\n }\n const out: Node = Object.assign({}, node);\n let stack: LinkedNode | undefined = { value: out };\n do {\n node = stack.value;\n stack = stack.next;\n if (node.left) {\n stack = { next: stack, value: (node.left = Object.assign({}, node.left)) };\n }\n if (node.right) {\n stack = { next: stack, value: (node.right = Object.assign({}, node.right)) };\n }\n } while (stack);\n return out;\n}\n/**\n * @internal\n */\nexport function leftmost>(node: undefined): undefined;\nexport function leftmost>(node: Node): Node;\nexport function leftmost>(\n node: Node | undefined,\n): Node | undefined;\nexport function leftmost>(\n node: Node | undefined,\n): Node | undefined {\n if (node == null) {\n return undefined;\n }\n while (node.left) {\n node = node.left;\n }\n return node;\n}\n/**\n * @internal\n */\nexport function leftmostStack>(\n stack: LinkedNode>,\n): LinkedNode> {\n let node = stack.value.to;\n if (node == null) {\n return stack;\n }\n while (node.left) {\n stack = { next: stack, value: { label: 'left', from: node, to: node.left } };\n node = node.left;\n }\n return stack;\n}\n/**\n * @internal\n */\nexport function* inOrderTraverse>(\n node: Node | undefined,\n): Generator {\n let stack: LinkedNode | undefined = undefined;\n\n while (node) {\n stack = { next: stack, value: node };\n node = node.left;\n }\n\n while (stack) {\n node = stack.value;\n stack = stack.next;\n yield node;\n node = node.right;\n while (node) {\n stack = { next: stack, value: node };\n node = node.left;\n }\n }\n}\n/**\n * @internal\n */\nexport function levelOrderTraverse>(\n node: Node | undefined,\n padded?: false,\n): Generator;\nexport function levelOrderTraverse>(\n node: Node | undefined,\n padded: true,\n): Generator;\nexport function* levelOrderTraverse>(\n node: Node | undefined,\n padded = false,\n): Generator {\n const nil = {} as LinkedNode;\n let head: LinkedNode = { value: node };\n let tail = head;\n for (let cont = node != null; cont; head = head.next!) {\n tail = tail.next = nil;\n for (cont = false; head !== nil; head = head.next!) {\n node = head.value;\n if (node) {\n yield node;\n cont ||= node.left != null || node.right != null;\n tail = tail.next = { value: node.left };\n tail = tail.next = { value: node.right };\n } else if (padded) {\n yield undefined;\n tail = tail.next = { value: undefined };\n tail = tail.next = { value: undefined };\n }\n }\n }\n}\n/**\n * @internal\n */\nfunction pad(str: string, maxLen: number, fillString: string): string {\n const len = str.length;\n if (len >= maxLen) {\n return str;\n }\n const diff = maxLen - len;\n return str.padStart(len + diff / 2, fillString).padEnd(len + diff, fillString);\n}\n/**\n * @internal\n */\nexport function* postOrderTraverse>(\n node: Node | undefined,\n): Generator {\n interface Meta {\n seen: boolean;\n node?: Node;\n }\n let stack: LinkedNode | undefined = { value: { seen: false, node } };\n do {\n const meta = stack.value;\n stack = stack.next;\n if (meta.node) {\n if (meta.seen) {\n yield meta.node;\n } else {\n meta.seen = true;\n stack = { next: stack, value: meta };\n stack = { next: stack, value: { seen: false, node: meta.node.right } };\n stack = { next: stack, value: { seen: false, node: meta.node.left } };\n }\n }\n } while (stack);\n}\n/**\n * @internal\n */\nexport function predecessor>(\n node: Node | undefined,\n): Node | undefined {\n return node == null ? undefined : rightmost(node.left);\n}\n/**\n * @internal\n */\nexport function predecessorStack>(\n stack: LinkedNode>,\n): LinkedNode> {\n const node = stack.value.to;\n if (node == null) {\n return stack;\n }\n stack = { next: stack, value: { label: 'left', from: node, to: node.left } };\n return rightmostStack(stack);\n}\n/**\n * @internal\n */\nexport function* preOrderTraverse>(\n node: Node | undefined,\n): Generator {\n let stack: LinkedNode | undefined = { value: node };\n do {\n node = stack.value;\n stack = stack.next;\n if (node) {\n yield node;\n stack = { next: stack, value: node.right };\n stack = { next: stack, value: node.left };\n }\n } while (stack);\n}\n/**\n * @internal\n */\nexport function reverse>(root?: Node): void {\n if (root == null) {\n return;\n }\n for (const node of preOrderTraverse(root)) {\n const left = node.left;\n node.left = node.right;\n node.right = left;\n }\n}\n/**\n * @internal\n */\nexport function rightmost>(node: undefined): undefined;\nexport function rightmost>(node: Node): Node;\nexport function rightmost>(\n node: Node | undefined,\n): Node | undefined;\nexport function rightmost>(\n node: Node | undefined,\n): Node | undefined {\n if (node == null) {\n return undefined;\n }\n while (node.right) {\n node = node.right;\n }\n return node;\n}\n/**\n * @internal\n */\nexport function rightmostStack>(\n stack: LinkedNode>,\n): LinkedNode> {\n let node = stack.value.to;\n if (node == null) {\n return stack;\n }\n while (node.right) {\n stack = { next: stack, value: { label: 'right', from: node, to: node.right } };\n node = node.right;\n }\n return stack;\n}\n/**\n * Assumes sorted by compareFn\n * @internal\n */\nexport function search>(\n element: T,\n node: Node | undefined,\n compareFn: CompareFn,\n): Node | undefined {\n while (node) {\n const comp: number = compareFn(element, node.value);\n if (comp == 0) {\n break;\n }\n node = comp < 0 ? node.left : node.right;\n }\n return node;\n}\n/**\n * Assumes sorted by compareFn\n * @internal\n */\nexport function searchStack>(\n element: T,\n stack: LinkedNode>,\n compareFn: CompareFn,\n dupeWeight = 0,\n): LinkedNode> {\n const paths: ['left', 'right'] = ['left', 'right'];\n let node = stack.value.to;\n while (node) {\n const comp: number = compareFn(element, node.value) || dupeWeight;\n if (comp === 0) {\n break;\n }\n const label = paths[+(comp > 0)];\n stack = { next: stack, value: { label, from: node, to: node[label] } };\n node = node[label]!;\n }\n return stack;\n}\n/**\n * @internal\n */\nexport function successor>(\n node: Node | undefined,\n): Node | undefined {\n return node == null ? undefined : leftmost(node.right);\n}\n/**\n * @internal\n */\nexport function successorStack>(\n stack: LinkedNode>,\n): LinkedNode> {\n const node = stack.value.to;\n if (node == null) {\n return stack;\n }\n stack = { next: stack, value: { label: 'right', from: node, to: node.right } };\n return leftmostStack(stack);\n}\n/**\n * @internal\n */\nexport function toBinaryTree(\n elements: (T | undefined)[] | undefined,\n): BinaryTreeNode | undefined {\n if (elements == null || elements.length < 1 || elements[0] == null) {\n return undefined;\n }\n const n = elements.length;\n const nodes: BinaryTreeNode[] = new Array(n);\n nodes[0] = { value: elements[0] };\n for (let i = 1; i < n; ++i) {\n if (elements[i] == null) {\n continue;\n }\n const par = nodes[(i - 1) >>> 1];\n const node = { value: elements[i]! };\n nodes[i] = node;\n if (i & 1) {\n par.left = node;\n } else {\n par.right = node;\n }\n }\n return nodes[0];\n}\n","import { isArray } from 'src/array/utils';\nimport { BinaryTreeNode } from 'src/tree/binaryTreeNode';\nimport { clone, preOrderTraverse, toBinaryTree } from 'src/tree/binaryTreeUtils';\nimport { CompareFn } from '..';\nimport { BinaryHeap } from './binaryHeap';\nimport { Heap } from './heap';\nimport { skewMerge } from './utils';\n\n/**\n * A skew heap is a heap implemented as a binary tree\n * ([source](https://en.wikipedia.org/wiki/Skew_heap)).\n *\n * A skew heap is a self-adjusting heap which attempts to maintain balance\n * by unconditionally swapping all nodes in the merge path when merging two heaps. Every\n * operation that modifies the heap (e.g. push, pop, merge) is considered a merge and is done\n * by using a skew heap merge.\n *\n * Skew heaps can merge more quickly than binary heaps. This can seem contradictory, since\n * skew heaps have no structural constraints and no guarantee that the height of the tree is\n * logarithmic (i.e. balanced). However, amortized complexity analysis can demonstrate that\n * all operations on a skew heap can be done in O(log(n). More specifically, the\n * amortized complexity is known to be logφ(n) where φ is the golden ratio. This is\n * approximately 1.44*log2(n).\n *\n * #### Complexity\n *\n * | Property | Average | Worst |\n * | :------- | :------ | :---- |\n * | Space | O(n) | O(n)\n * | Push | O(log n) | O(log n)\n * | Peek | O(1)\t | O(1)\n * | Pop | O(log n) | O(log n)\n * | Search | O(n) | O(n)\n */\nexport class SkewHeap implements Heap {\n /**\n * The function to determine the order of elements.\n */\n protected compare: CompareFn;\n /**\n * The number of elements in the list.\n */\n protected length: number;\n /**\n * The node at the \"top\" of the heap.\n */\n protected root: BinaryTreeNode | undefined;\n /**\n * Instantiate a heap.\n *\n * @param compareFn - The function to determine the order of elements.\n * @param elements - A set of elements to initialize the heap with.\n */\n constructor(compareFn: CompareFn, elements?: Iterable) {\n this.compare = compareFn;\n this.length = 0;\n this.addAll(elements ?? []);\n }\n\n addAll(elements: Iterable): number {\n if (isArray(elements)) {\n for (let i = 0; i < elements.length; ++i) {\n this.push(elements[i]);\n }\n } else if (elements instanceof SkewHeap || elements instanceof BinaryHeap) {\n this.merge(elements);\n } else {\n for (const element of elements) {\n this.push(element);\n }\n }\n return this.length;\n }\n\n clear(): void {\n this.length = 0;\n this.root = undefined;\n }\n\n comparator(): CompareFn {\n return this.compare;\n }\n\n contains(element: T): boolean {\n for (const node of preOrderTraverse(this.root)) {\n if (element === node.value) {\n return true;\n }\n }\n return false;\n }\n\n delete(element: T): boolean {\n if (this.root == null) {\n return false;\n }\n if (this.root.value === element) {\n this.pop()!;\n return true;\n }\n for (const par of preOrderTraverse(this.root)) {\n const key: keyof BinaryTreeNode | undefined =\n par.left && par.left.value === element\n ? 'left'\n : par.right && par.right.value === element\n ? 'right'\n : undefined;\n if (key != null) {\n const node = par[key]!;\n par[key] = skewMerge(this.compare, [node.left, node.right]);\n --this.length;\n return true;\n }\n }\n return false;\n }\n\n merge(heap: Heap): this {\n if (this.compare !== heap.comparator()) {\n this.addAll(heap);\n } else if (heap instanceof SkewHeap) {\n this.root = skewMerge(this.compare, [this.root, clone(heap.root)]);\n this.length += heap.size;\n } else if (heap instanceof BinaryHeap) {\n this.root = skewMerge(this.compare, [this.root, toBinaryTree(heap['array'])!]);\n this.length += heap.size;\n } else {\n this.addAll(heap);\n }\n return this;\n }\n\n peek(): T | undefined {\n return this.root?.value;\n }\n\n pop(): T | undefined {\n if (this.root == null) {\n return undefined;\n }\n const value = this.root.value;\n this.root = skewMerge(this.compare, [this.root.left, this.root.right]);\n --this.length;\n return value;\n }\n\n push(value: T): number {\n this.root = skewMerge(this.compare, [this.root, { value }]);\n return ++this.length;\n }\n\n pushPop(value: T): T {\n this.push(value);\n return this.pop()!;\n }\n\n replace(value: T): T | undefined {\n if (this.root == null) {\n this.root = { value };\n this.length = 1;\n return undefined;\n }\n const out = this.root.value;\n this.root = skewMerge(this.compare, [this.root.left, this.root.right, { value }]);\n return out;\n }\n\n get size(): number {\n return this.length;\n }\n\n *sorted(): Iterable {\n if (this.root == null) {\n return;\n }\n const heap = new SkewHeap>(\n (a, b) => this.compare(a.value, b.value),\n [this.root],\n );\n do {\n const node = heap.pop()!;\n yield node.value;\n node.left && heap.push(node.left);\n node.right && heap.push(node.right);\n } while (heap.size > 0);\n }\n /**\n * Receive an iterator through the list.\n *\n * **Note:** Unexpected behavior can occur if the collection is modified during iteration.\n *\n * @returns An iterator through the list\n */\n *[Symbol.iterator](): Iterator {\n for (const node of preOrderTraverse(this.root)) {\n yield node.value;\n }\n }\n\n update(curElement: T, newElement: T): boolean {\n if (this.root == null) {\n return false;\n }\n\n if (this.root.value === curElement) {\n this.root = skewMerge(this.compare, [\n this.root.left,\n this.root.right,\n { value: newElement },\n ]);\n return true;\n }\n\n let node: BinaryTreeNode | undefined = undefined;\n for (const par of preOrderTraverse(this.root)) {\n if (par.left && par.left.value === curElement) {\n node = par.left;\n par.left = undefined;\n break;\n }\n if (par.right && par.right.value === curElement) {\n node = par.right;\n par.right = undefined;\n break;\n }\n }\n\n if (node == null) {\n return false;\n }\n\n this.root = skewMerge(this.compare, [\n this.root,\n node.left,\n node.right,\n { value: newElement },\n ]);\n return true;\n }\n}\n","/**\n * Limits a number to be within a given range.\n *\n * f(x, min, max) = y, where min <= y <= max\n *\n * @param num - The number to clamp\n * @param min - The minimum result value, inclusive\n * @param max - The maximum result value, inclusive\n *\n * @returns The clamped number\n */\nexport function clamp(num: number, min: number, max: number): number {\n return Math.min(max, Math.max(min, num));\n}\n","import { isArray } from '../array/utils';\nimport { CompareFn } from '..';\nimport { DoublyLinkedNode } from './doublyLinkedNode';\nimport { LinkedNode } from './linkedNode';\nimport { clamp } from 'src/math';\n\n/**\n * Groups an iterable into batches of a given size.\n *\n * @param size - The maximum batch size\n * @param iterable - The iterable to batch\n *\n * @returns An iterable of batches\n *\n * @internal\n */\nexport function batch(\n size: number,\n iterable: Iterable,\n): Generator {\n if (isArray(iterable)) {\n return batchArray(size, iterable);\n }\n return batchIterable(size, iterable);\n}\n/**\n * Groups an iterable into batches of a given size.\n *\n * @param size - The maximum batch size\n * @param iterable - The iterable to batch\n *\n * @returns An iterable of batches\n *\n * @internal\n */\nexport function* batchArray(size: number, array: T[]): Generator {\n let min = 0;\n while (min < array.length) {\n const max = min + size;\n size = (yield array.slice(min, max)) ?? size;\n min = max;\n }\n}\n/**\n * Groups an iterable into batches of a given size.\n *\n * @param size - The maximum batch size\n * @param iterable - The iterable to batch\n *\n * @returns An iterable of batches\n *\n * @internal\n */\nexport function* batchIterable(\n size: number,\n iterable: Iterable,\n): Generator {\n let array: T[] = [];\n for (const value of iterable) {\n if (array.push(value) >= size) {\n size = (yield array) ?? size;\n array = [];\n }\n }\n if (array.length > 0) {\n yield array;\n }\n}\n/**\n * Wraps and then clamps a number within a given range.\n *\n * @param num - The number to wrap and then clamp\n * @param min - The minimum result value, inclusive\n * @param max - The wrap pivot and maximum result value, inclusive\n *\n * @returns The crwapped number\n *\n * @internal\n */\nexport function cwrap(num: number, min: number, max: number): number {\n return clamp(nwrap(num, max), min, max);\n}\n/**\n * Sorts a list in place.\n *\n * Works on complete lists as well as sublists and circular lists:\n * - Linked lists will keep the link to the next node beyond the sorted section\n * - Doubly linked lists will keep links to the prev and next nodes outside the sorted section\n *\n * @param node - The head of the list\n * @param len - The length of the list beginning from node\n * @param isDoubly - Whether node is a doubly linked node\n * @param compareFn - A function used to determine the order of elements.\n *\n * It is expected to return:\n * - A negative value if first argument < second argument\n * - Zero if first argument == second argument\n * - A positive value if first argument > second argument\n *\n * @returns The new head and tail of the sorted list\n *\n * @internal\n */\nexport function linkedMergeSort>(\n node: Node,\n len: number,\n isDoubly: boolean,\n compareFn: CompareFn,\n): [Node, Node] {\n // Base case\n if (len < 2) {\n return [node, node];\n }\n\n // Split the list into two halves and sort them\n len = len / 2;\n const lens: [number, number] = [Math.ceil(len), Math.floor(len)];\n const heads = linkedMergeSort(node, lens[0], isDoubly, compareFn);\n const tails = linkedMergeSort(heads[1].next as Node, lens[1], isDoubly, compareFn);\n\n // Group the heads and tails together\n node = heads[1];\n heads[1] = tails[0];\n tails[0] = node;\n tails[0].next = tails[1].next;\n\n // Merge the sorted halves\n const prev = (heads[0] as DoublyLinkedNode).prev;\n node = linkedMergeSorted(heads, lens, isDoubly, compareFn);\n if (isDoubly) {\n (node as DoublyLinkedNode).prev = prev;\n }\n\n // Return the head and tail\n return [node, tails[+(lens[0] < 1)]];\n}\n/**\n * Merges two sorted lists.\n *\n * @param nodes - The heads of the lists\n * @param lens - The lengths of the lists\n * @param isDoubly - Whether the lists are a doubly linked\n * @param compareFn - A function used to determine the order of elements.\n *\n * It is expected to return:\n * - A negative value if first argument < second argument\n * - Zero if first argument == second argument\n * - A positive value if first argument > second argument\n *\n * @returns The new head of the sorted list\n *\n * @internal\n */\nexport function linkedMergeSorted>(\n heads: [Node, Node],\n lens: [number, number],\n isDoubly: boolean,\n compareFn: CompareFn,\n): Node {\n const root = {} as Node;\n\n let node = root;\n do {\n const index = +(compareFn(heads[0].value, heads[1].value) > 0);\n node.next = heads[index];\n if (isDoubly) {\n (node.next as DoublyLinkedNode).prev = node;\n }\n node = node.next as Node;\n heads[index] = node.next as Node;\n --lens[index];\n } while (lens[0] > 0 && lens[1] > 0);\n\n // Add any remaining nodes\n node.next = heads[+(lens[0] < 1)];\n if (isDoubly && node.next) {\n (node.next as DoublyLinkedNode).prev = node;\n }\n return root.next as Node;\n}\n/**\n * Wraps negative numbers around a pivot\n *\n * f(x, min, pivot) = {\n * x, where x >= 0\n * pivot + x, where x < 0\n * }\n *\n * @param num - The number to wrap\n * @param pivot - The number to pivot on\n *\n * @returns - The wrapped number\n *\n * @internal\n */\nexport function nwrap(num: number, pivot: number): number {\n return num < 0 ? pivot + num : num;\n}\n","import { clamp } from 'src/math';\nimport { CompareFn } from '..';\nimport { List } from './list';\nimport { batch, cwrap } from './utils';\n\n/**\n * An implementation of the {@link List} interface using an array\n */\nexport class ArrayList implements List {\n /**\n * The array containing every element.\n */\n protected array: Array;\n /**\n * Instantiate the list.\n *\n * @param elements - A set of elements to initialize the list with.\n */\n constructor(elements?: Iterable) {\n this.array = elements ? Array.from(elements) : [];\n }\n\n add(index: number, element: T): number {\n if (index >= 0 && index <= this.size) {\n this.array.splice(index, 0, element);\n }\n return this.size;\n }\n\n addAll(index: number, elements: Iterable): number {\n if (index >= 0 && index <= this.size) {\n for (const items of batch(10000, elements)) {\n this.array.splice(index, 0, ...items);\n index += items.length;\n }\n }\n return this.size;\n }\n\n clear(): void {\n this.array.length = 0;\n }\n\n concat(...lists: Iterable[]): ArrayList {\n const out = new ArrayList(this);\n for (const list of lists) {\n out.addAll(out.size, list);\n }\n return out;\n }\n\n copyWithin(index: number, min?: number, max?: number): this {\n index = cwrap(index ?? 0, 0, this.size);\n min = cwrap(min ?? 0, 0, this.size);\n max = cwrap(max ?? this.size, 0, this.size);\n this.array.copyWithin(index, min, max);\n return this;\n }\n\n fill(element: T, min?: number, max?: number): this {\n min = cwrap(min ?? 0, 0, this.size);\n max = cwrap(max ?? this.size, 0, this.size);\n this.array.fill(element, min, max);\n return this;\n }\n\n get(index: number): T | undefined {\n return index < 0 || index >= this.size ? undefined : this.array[index];\n }\n\n getSet(index: number, callback: (element: T) => T): T | undefined {\n let value: T | undefined = undefined;\n if (index >= 0 && index < this.size) {\n value = this.array[index];\n this.array[index] = callback(value);\n }\n return value;\n }\n\n pop(): T | undefined {\n return this.array.pop();\n }\n\n push(element: T): number {\n return this.array.push(element);\n }\n\n remove(index: number): T | undefined {\n return index < 0 || index >= this.size ? undefined : this.array.splice(index, 1)[0];\n }\n\n reverse(min?: number, max?: number): this {\n min = cwrap(min ?? 0, 0, this.size);\n max = cwrap(max ?? this.size, 0, this.size) - 1;\n while (min < max) {\n const temp = this.array[min];\n this.array[min++] = this.array[max];\n this.array[max--] = temp;\n }\n return this;\n }\n\n set(index: number, element: T): T | undefined {\n let prev: T | undefined = undefined;\n if (index >= 0 && index < this.size) {\n prev = this.array[index];\n this.array[index] = element;\n }\n return prev;\n }\n\n shift(): T | undefined {\n return this.array.shift();\n }\n\n get size(): number {\n return this.array.length;\n }\n\n slice(min?: number, max?: number): ArrayList {\n return new ArrayList(this.array.slice(min, max));\n }\n\n splice(start?: number, count?: number, elements?: Iterable): List {\n start = cwrap(start ?? 0, 0, this.size);\n count = clamp(count ?? this.size, 0, this.size - start);\n const list = new ArrayList(this.array.splice(start, count));\n for (const items of batch(10000, elements ?? [])) {\n this.array.splice(start, 0, ...items);\n start += items.length;\n }\n return list;\n }\n\n sort(compareFn: CompareFn): this {\n this.array.sort(compareFn);\n return this;\n }\n /**\n * Receive an iterator through the list.\n *\n * **Note:** Unexpected behavior can occur if the collection is modified during iteration.\n *\n * @returns An iterator through the list\n */\n [Symbol.iterator](): Iterator {\n return this.array[Symbol.iterator]();\n }\n\n unshift(element: T): number {\n return this.array.unshift(element);\n }\n\n update(callback: (element: T, index: number) => T): this;\n update(min: number | undefined, callback: (element: T, index: number) => T): this;\n update(\n min: number | undefined,\n max: number | undefined,\n callback: (element: T, index: number) => T,\n ): this;\n update(\n min: number | undefined | ((element: T, index: number) => T),\n max?: number | ((element: T, index: number) => T),\n callback?: (element: T, index: number) => T,\n ): this {\n if (callback == null) {\n if (arguments.length < 2) {\n callback = min as (element: T, index: number) => T;\n min = undefined;\n } else {\n callback = max as (element: T, index: number) => T;\n max = undefined;\n }\n }\n min = cwrap((min as number) ?? 0, 0, this.size);\n max = cwrap((max as number) ?? this.size, 0, this.size);\n while (min < max) {\n this.array[min] = callback(this.array[min], min);\n ++min;\n }\n return this;\n }\n\n *view(min?: number, max?: number): Iterable {\n min = cwrap(min ?? 0, 0, this.size);\n\n let len: () => number;\n if (max == null) {\n len = () => this.size;\n } else if (max >= 0) {\n len = () => Math.min(max, this.size);\n } else {\n len = () => this.size + max;\n }\n\n while (min < len()) {\n yield this.array[min++];\n }\n }\n}\n","import { clamp } from 'src/math';\nimport { CompareFn } from '..';\nimport { DoublyLinkedNode } from './doublyLinkedNode';\nimport { List } from './list';\nimport { linkedMergeSort, cwrap } from './utils';\n\n/**\n * A (circular) doubly-linked list implementation of the {@link List} interface.\n *\n * Operations that index into the list will traverse the list from the beginning or the end, whichever is closer to the specified index.\n */\nexport class DoublyLinkedList implements List {\n /**\n * The number of elements in the list\n */\n protected length: number;\n /**\n * The sentinel node at the fron of the list\n */\n protected root: DoublyLinkedNode;\n /**\n * Instantiate the list.\n *\n * @param elements - A set of elements to initialize the list with.\n */\n constructor(elements?: Iterable) {\n this.length = 0;\n this.root = {} as DoublyLinkedNode;\n this.root.prev = this.root.next = this.root;\n this._addAll(this.root, elements ?? []);\n }\n\n add(index: number, value: T): number {\n if (index < 0 || index > this.length) {\n return this.length;\n }\n const prev = this._get(index - 1);\n const node = { next: prev.next, prev, value };\n prev.next = node;\n node.next!.prev = node;\n return ++this.length;\n }\n\n addAll(index: number, elements: Iterable): number {\n if (index >= 0 && index <= this.length) {\n this._addAll(this._get(index), elements);\n }\n return this.length;\n }\n\n clear(): void {\n this.length = 0;\n this.root.prev = this.root.next = this.root;\n }\n\n concat(...lists: Iterable[]): DoublyLinkedList {\n const out = new DoublyLinkedList(this);\n for (const list of lists) {\n out.addAll(out.size, list);\n }\n return out;\n }\n\n copyWithin(index: number, min?: number, max?: number): this {\n // Check if copying to the same section\n index = cwrap(index, 0, this.length);\n min = cwrap(min ?? 0, 0, this.length);\n if (min === index) {\n return this;\n }\n\n // Check if the section to copy has no length\n max = cwrap(max ?? this.length, 0, this.length);\n max = min + Math.min(max - min, this.length - index);\n if (min >= max) {\n return this;\n }\n\n // Check for overlap edge case\n if (min < index && index < max) {\n let nodeA = this._get(max);\n let nodeB = this._get(index + (max - min));\n do {\n nodeA = nodeA.prev!;\n nodeB = nodeB.prev!;\n nodeB.value = nodeA.value;\n } while (++min < max);\n return this;\n }\n\n // Copy the section to the destination\n let nodeA = this._get(min);\n let nodeB = this._get(index);\n do {\n nodeB.value = nodeA.value;\n nodeA = nodeA.next!;\n nodeB = nodeB.next!;\n } while (++min < max);\n return this;\n }\n\n fill(element: T, min?: number, max?: number): this {\n min = cwrap(min ?? 0, 0, this.length);\n max = cwrap(max ?? this.length, 0, this.length);\n if (min < max) {\n let node = this._get(min);\n do {\n node.value = element;\n node = node.next!;\n } while (++min < max);\n }\n return this;\n }\n\n get(index: number): T | undefined {\n return index < 0 || index >= this.length ? undefined : this._get(index).value;\n }\n\n getSet(index: number, callback: (element: T) => T): T | undefined {\n if (index < 0 || index >= this.length) {\n return undefined;\n }\n const node = this._get(index);\n const value = node.value;\n node.value = callback(node.value);\n return value;\n }\n\n pop(): T | undefined {\n if (this.length < 1) {\n return undefined;\n }\n const tail = this.root.prev!;\n tail.prev!.next = this.root;\n this.root.prev = tail.prev;\n --this.length;\n return tail.value;\n }\n\n push(value: T): number {\n const prev = this.root.prev!;\n const node = { next: this.root, prev, value };\n prev.next = this.root.prev = node;\n return ++this.length;\n }\n\n remove(index: number): T | undefined {\n if (index < 0 || index >= this.length) {\n return undefined;\n }\n const node = this._get(index);\n node.prev!.next = node.next;\n node.next!.prev = node.prev;\n --this.length;\n return node.value;\n }\n\n reverse(min?: number, max?: number): this {\n min = cwrap(min ?? 0, 0, this.length);\n max = cwrap(max ?? this.length, 0, this.length);\n if (max - min < 2) {\n return this;\n }\n const root = this._get(min - 1);\n const tail = root.next!;\n let node = tail;\n do {\n const temp = node.next!;\n node.next = node.prev;\n node.prev = temp;\n root.next = node;\n node = temp;\n } while (++min < max);\n tail.next = node;\n node.prev = tail;\n root.next!.prev = root;\n return this;\n }\n\n set(index: number, element: T): T | undefined {\n if (index < 0 || index >= this.length) {\n return undefined;\n }\n const node = this._get(index);\n const value = node.value;\n node.value = element;\n return value;\n }\n\n shift(): T | undefined {\n if (this.length < 1) {\n return undefined;\n }\n const head = this.root.next!;\n head.next!.prev = this.root;\n this.root.next = head.next;\n --this.length;\n return head.value;\n }\n\n get size(): number {\n return this.length;\n }\n\n slice(min?: number, max?: number): DoublyLinkedList {\n return new DoublyLinkedList(this.view(min, max));\n }\n\n splice(start?: number, count?: number, elements?: Iterable): List {\n start = cwrap(start ?? 0, 0, this.size);\n count = clamp(count ?? this.size, 0, this.size - start);\n\n // If not modifying the list\n const list = new DoublyLinkedList();\n if (elements == null && count < 1) {\n return list;\n }\n\n // Delete elements\n let node = this._get(start);\n while (count-- > 0) {\n list.push(node.value);\n node.prev!.next = node.next!;\n node.next!.prev = node.prev!;\n node = node.next!;\n --this.length;\n }\n\n // Add elements\n this._addAll(node, elements ?? []);\n\n return list;\n }\n\n sort(compareFn: CompareFn): this {\n if (this.length > 1) {\n const [head, tail] = linkedMergeSort(this.root.next!, this.length, true, compareFn);\n this.root.next = head;\n tail.next!.prev = tail;\n }\n return this;\n }\n /**\n * Receive an iterator through the list.\n *\n * **Note:** Unexpected behavior can occur if the collection is modified during iteration.\n *\n * @returns An iterator through the list\n */\n *[Symbol.iterator](): Iterator {\n for (let node = this.root.next!; node !== this.root; node = node.next!) {\n yield node.value;\n }\n }\n\n unshift(value: T): number {\n const head = this.root.next!;\n const node = { next: head, prev: this.root, value };\n this.root.next = head.prev = node;\n return ++this.length;\n }\n\n update(callback: (element: T, index: number) => T): this;\n update(min: number | undefined, callback: (element: T, index: number) => T): this;\n update(\n min: number | undefined,\n max: number | undefined,\n callback: (element: T, index: number) => T,\n ): this;\n update(\n min: number | undefined | ((element: T, index: number) => T),\n max?: number | ((element: T, index: number) => T),\n callback?: (element: T, index: number) => T,\n ): this {\n if (callback == null) {\n if (arguments.length < 2) {\n callback = min as (element: T, index: number) => T;\n min = undefined;\n } else {\n callback = max as (element: T, index: number) => T;\n max = undefined;\n }\n }\n min = cwrap((min as number) ?? 0, 0, this.length);\n max = cwrap((max as number) ?? this.length, 0, this.length);\n if (min < max) {\n let node = this._get(min);\n do {\n node.value = callback(node.value, min);\n node = node.next!;\n } while (++min < max);\n }\n return this;\n }\n\n *view(min?: number, max?: number): Iterable {\n min = cwrap(min ?? 0, 0, this.length);\n\n let len: () => number;\n if (max == null) {\n len = () => this.length;\n } else if (max >= 0) {\n len = () => max;\n } else {\n len = () => this.length + max;\n }\n\n if (min < len()) {\n let node = this._get(min);\n do {\n yield node.value;\n node = node.next!;\n } while (++min < len() && node !== this.root);\n }\n }\n /**\n *\n */\n protected _addAll(next: DoublyLinkedNode, elements: Iterable): void {\n let prev = next.prev!;\n for (const value of elements) {\n const node = { prev, value };\n prev.next = node;\n prev = node;\n ++this.length;\n }\n prev.next = next;\n next.prev = prev;\n }\n /**\n * A helper method to iterate and return the node at the given index.\n *\n * Depending on the index, the list will be traversed from beginning or end; whichever is closest to the specified index.\n *\n * @param index - The index to retrieve\n *\n * @returns The node at the given index\n */\n protected _get(index: number): DoublyLinkedNode {\n let node = this.root;\n if (index < this.length / 2) {\n while (index-- >= 0) {\n node = node.next!;\n }\n } else {\n for (index = this.length - index; index > 0; --index) {\n node = node.prev!;\n }\n }\n return node;\n }\n}\n","import { clamp } from 'src/math';\nimport { CompareFn } from '..';\nimport { LinkedNode } from './linkedNode';\nimport { List } from './list';\nimport { linkedMergeSort, cwrap } from './utils';\n\n/**\n * A (circular) linked list implementation of the {@link List} interface.\n */\nexport class LinkedList implements List {\n /**\n * The number of elements in the list.\n */\n protected length: number;\n /**\n * The sentinel node at the front of the list.\n */\n protected root: LinkedNode;\n /**\n * The last node of the list.\n */\n protected tail: LinkedNode;\n /**\n * Instantiate the list.\n *\n * @param elements - A set of elements to initialize the list with.\n */\n constructor(elements?: Iterable) {\n this.length = 0;\n this.root = {} as LinkedNode;\n this.root.next = this.root;\n this.tail = this._addAll(this.root, elements ?? []);\n }\n\n add(index: number, value: T): number {\n if (index >= 0 && index < this.length) {\n const prev = this._get(index - 1);\n prev.next = { value, next: prev.next };\n ++this.length;\n } else if (index === this.length) {\n this.push(value);\n }\n return this.length;\n }\n\n addAll(index: number, elements: Iterable): number {\n if (index >= 0 && index < this.length) {\n this._addAll(this._get(index - 1), elements);\n } else if (index === this.length) {\n this.tail = this._addAll(this.tail, elements);\n }\n return this.length;\n }\n\n clear(): void {\n this.length = 0;\n this.tail = this.root.next = this.root;\n }\n\n concat(...lists: Iterable[]): LinkedList {\n const out = new LinkedList(this);\n for (const list of lists) {\n out.addAll(out.size, list);\n }\n return out;\n }\n\n copyWithin(index: number, min?: number, max?: number): this {\n // Check if copying to itself\n index = cwrap(index, 0, this.length);\n min = cwrap(min ?? 0, 0, this.length);\n if (min === index) {\n return this;\n }\n\n // Check if the section to copy has no length\n max = cwrap(max ?? this.length, 0, this.length);\n max = min + Math.min(max - min, this.length - index);\n if (min >= max) {\n return this;\n }\n\n // Copy to earlier in the list\n if (index < min) {\n const node = this._get(index - 1);\n this._copyWithin(this._get(min - index - 1, node), node, max - min);\n return this;\n }\n\n // Copy to later in the list\n if (index > max) {\n const node = this._get(min - 1);\n this._copyWithin(node, this._get(index - min - 1, node), max - min);\n return this;\n }\n\n // Copy to overlapping destination\n const nodeA = this._get(min - 1);\n const nodeC = this._get(max - min - 1, nodeA);\n const nodeD = this._copyWithin(nodeA, nodeC, index - min);\n if (index + (max - min) >= this.length) {\n this.tail = nodeC;\n }\n const temp = nodeA.next;\n nodeA.next = nodeC.next;\n nodeC.next = nodeD.next;\n nodeD.next = temp;\n return this;\n }\n\n fill(element: T, min?: number, max?: number): this {\n min = cwrap(min ?? 0, 0, this.length);\n max = cwrap(max ?? this.length, 0, this.length);\n if (min < max) {\n let node = this._get(min);\n do {\n node.value = element;\n node = node.next!;\n } while (++min < max);\n }\n return this;\n }\n\n get(index: number): T | undefined {\n if (index < 0 || index >= this.length) {\n return undefined;\n }\n return index < this.length - 1 ? this._get(index).value : this.tail.value;\n }\n\n getSet(index: number, callback: (element: T) => T): T | undefined {\n if (index < 0 || index >= this.length) {\n return undefined;\n }\n const node = index < this.length - 1 ? this._get(index) : this.tail;\n const value = node.value;\n node.value = callback(node.value);\n return value;\n }\n\n pop(): T | undefined {\n if (this.length < 1) {\n return undefined;\n }\n const value = this.tail.value;\n this.tail = this._get(this.length - 2);\n this.tail.next = this.root;\n --this.length;\n return value;\n }\n\n push(value: T): number {\n const tail: LinkedNode = { next: this.root, value };\n this.tail.next = tail;\n this.tail = tail;\n return ++this.length;\n }\n\n remove(index: number): T | undefined {\n if (index < 0 || index >= this.length) {\n return undefined;\n }\n const prev = this._get(index - 1);\n const node = prev.next!;\n prev.next = node.next;\n if (index === --this.length) {\n this.tail = prev;\n }\n return node.value;\n }\n\n reverse(min?: number, max?: number): this {\n min = cwrap(min ?? 0, 0, this.length);\n max = cwrap(max ?? this.length, 0, this.length);\n if (max - min < 2) {\n return this;\n }\n const root = this._get(min - 1);\n this.tail = max >= this.length ? root.next! : this.tail;\n const tail = root.next!;\n let prev = tail;\n let node = tail.next!;\n while (++min < max) {\n const next = node.next!;\n node.next = prev;\n prev = node;\n node = next;\n }\n root.next = prev;\n tail.next = node;\n return this;\n }\n\n set(index: number, element: T): T | undefined {\n if (index < 0 || index >= this.length) {\n return undefined;\n }\n const node = this._get(index);\n const value = node.value;\n node.value = element;\n return value;\n }\n\n shift(): T | undefined {\n return this.remove(0);\n }\n\n get size(): number {\n return this.length;\n }\n\n slice(min?: number, max?: number): LinkedList {\n return new LinkedList(this.view(min, max));\n }\n\n splice(start?: number, count?: number, elements?: Iterable): List {\n start = cwrap(start ?? 0, 0, this.size);\n count = clamp(count ?? this.size, 0, this.size - start);\n\n // If not modifying the list\n const deleted = new LinkedList();\n if (elements == null && count < 1) {\n return deleted;\n }\n\n // Delete elements\n let prev = this._get(start - 1);\n const newTail = start + count >= this.size;\n while (count-- > 0) {\n const node = prev.next!;\n deleted.push(node.value);\n prev.next = node.next;\n --this.length;\n }\n\n // Add elements\n prev = this._addAll(prev, elements ?? []);\n this.tail = newTail ? prev : this.tail;\n\n return deleted;\n }\n\n sort(compareFn: CompareFn): this {\n if (this.length > 1) {\n const [head, tail] = linkedMergeSort(this.root.next!, this.length, false, compareFn);\n this.root.next = head;\n this.tail = tail;\n }\n return this;\n }\n /**\n * Receive an iterator through the list.\n *\n * **Note:** Unexpected behavior can occur if the collection is modified during iteration.\n *\n * @returns An iterator through the list\n */\n *[Symbol.iterator](): Iterator {\n for (let node = this.root.next!; node !== this.root; node = node.next!) {\n yield node.value;\n }\n }\n\n unshift(value: T): number {\n return this.add(0, value);\n }\n\n update(callback: (element: T, index: number) => T): this;\n update(min: number | undefined, callback: (element: T, index: number) => T): this;\n update(\n min: number | undefined,\n max: number | undefined,\n callback: (element: T, index: number) => T,\n ): this;\n update(\n min: number | undefined | ((element: T, index: number) => T),\n max?: number | ((element: T, index: number) => T),\n callback?: (element: T, index: number) => T,\n ): this {\n if (callback == null) {\n if (arguments.length < 2) {\n callback = min as (element: T, index: number) => T;\n min = undefined;\n } else {\n callback = max as (element: T, index: number) => T;\n max = undefined;\n }\n }\n min = cwrap((min as number) ?? 0, 0, this.length);\n max = cwrap((max as number) ?? this.length, 0, this.length);\n if (min < max) {\n let node = this._get(min);\n do {\n node.value = callback(node.value, min);\n node = node.next!;\n } while (++min < max);\n }\n return this;\n }\n\n *view(min?: number, max?: number): Iterable {\n min = cwrap(min ?? 0, 0, this.length);\n\n let len: () => number;\n if (max == null) {\n len = () => this.length;\n } else if (max >= 0) {\n len = () => max;\n } else {\n len = () => this.length + max;\n }\n\n if (min < len()) {\n let node = this._get(min);\n do {\n yield node.value;\n node = node.next!;\n } while (++min < len() && node !== this.root);\n }\n }\n\n protected _addAll(prev: LinkedNode, elements: Iterable): LinkedNode {\n const next = prev.next!;\n for (const value of elements) {\n const node = { value };\n prev.next = node;\n prev = node;\n ++this.length;\n }\n prev.next = next;\n return prev;\n }\n /**\n * Copy values from 'from' to 'to'.\n *\n * @param from - The initial node to copy from\n * @param prev - The root of the initial node to copy to\n * @param count - The number of values to copy\n */\n protected _copyWithin(from: LinkedNode, to: LinkedNode, count: number): LinkedNode {\n while (count-- > 0) {\n from = from.next!;\n to = to.next!;\n to.value = from.value;\n }\n return to;\n }\n /**\n * Get the node at the given index.\n *\n * @param index - The index to retrieve\n *\n * @returns The node at the given index\n */\n protected _get(index: number, root: LinkedNode = this.root): LinkedNode {\n let node = root!;\n while (index-- >= 0) {\n node = node.next!;\n }\n return node;\n }\n}\n","/**\n * Bit hacks for 32-bit unsigned numbers.\n */\n\n/**\n * Get the number of bits set of a 32-bit unsigned number ([source](https://graphics.stanford.edu/~seander/bithacks.html#CountBitsSetKernighan))\n *\n * @param a\n */\nexport function bitsSet(a: number): number {\n let b = 0;\n while (a) {\n ++b;\n a &= a - 1;\n }\n return b;\n}\n/**\n * Invert the bits of a 32-bit unsigned number.\n *\n * Example: 11 (1011) -> 4 (0100)\n *\n * @param a The number to invert\n *\n * @returns The inverted number\n */\nexport function invert(a: number): number {\n const b = msp(a);\n return u32(a ^ (b | (b - 1)));\n}\n/**\n * Check whether a 32-bit unsigned number is a power of 2.\n *\n * Example: 8 (1000) -> true\n *\n * @param a The number to check\n */\nexport function isPow2(a: number): boolean {\n return (a & (a - 1)) === 0;\n}\n/**\n * Get the Least Significant Bit of a 32-bit unsigned number\n *\n * @param a\n *\n * @returns The lowest bit set\n */\nexport function lsb(a: number): number {\n let b = -1;\n for (a = lsp(a); a; a >>>= 1) {\n ++b;\n }\n return b;\n}\n/**\n * Get the Least Significant Power of a 32-bit unsigned number\n *\n * @param a\n *\n * @returns 2**lsb(a)\n */\nexport function lsp(a: number): number {\n return u32(a & -a);\n}\n/**\n * Get the Least Significant Power Set of a 32-bit unsigned number.\n *\n * Example: 54 (110110) -> 6 (000110)\n *\n * @param a\n */\nexport function lsps(a: number): number {\n return u32(a & (lsp(a + lsp(a)) - 1));\n}\n/**\n * Get the Most Significant Power of the Least Significant Power Set of a 32-bit unsigned number.\n *\n * Example: 54 (110110) -> 4 (000100)\n *\n * 111111\n * 000000\n * 000000\n *\n * 000010\n * 111000\n * 001000\n * 000100\n *\n * @param a\n */\nexport function mlsp(a: number): number {\n return lsp(a + lsp(a)) >>> 1 || u32(0x80000000 & a);\n}\n/**\n * Get the Most Significant Bit of a 32-bit unsigned number\n *\n * @param a\n *\n * @returns ⌊log2(a)⌋ : the highest bit set\n */\nexport function msb(a: number): number {\n let b = -1;\n while (a !== 0) {\n ++b;\n a >>>= 1;\n }\n return b;\n}\n/**\n * Get the Most Significant Power of a 32-bit unsigned number\n *\n * @param a\n *\n * @returns 2**msb(a)\n */\nexport function msp(a: number): number {\n let b = a & -a;\n while (a != b) {\n a ^= b;\n b = a & -a;\n }\n return u32(b);\n}\n/**\n * Get the Most Significant Power Set of a 32-bit unsigned number.\n *\n * Example: 50 (110010) -> 48 (110000)\n *\n * @param a\n */\nexport function msps(a: number): number {\n let b = a & -a;\n while (a & (a + b)) {\n a ^= b;\n b = a & -a;\n }\n return u32(a);\n}\n/**\n * Reverse a 32-bit unsigned number.\n *\n * Example: 50 (110010) -> 19 (010011)\n *\n * @param a\n */\nexport function reverse(a: number): number {\n a = ((a & 0xaaaaaaaa) >>> 1) | ((a & 0x55555555) << 1);\n a = ((a & 0xcccccccc) >>> 2) | ((a & 0x33333333) << 2);\n a = ((a & 0xf0f0f0f0) >>> 4) | ((a & 0x0f0f0f0f) << 4);\n a = ((a & 0xff00ff00) >>> 8) | ((a & 0x00ff00ff) << 8);\n return u32((a >>> 16) | (a << 16));\n}\n/**\n * Turn a number into an unsigned 32-bit number\n *\n * @param a\n */\nexport function u32(a: number): number {\n return a >>> 0;\n}\n","import { Queue } from './queue';\n\n/**\n * An implementation of the {@link Queue} interface using an array\n */\nexport class ArrayQueue implements Queue {\n /**\n * The array containing every element.\n */\n protected array: T[];\n /**\n * Instantiate the queue.\n *\n * @param elements - A set of elements to initialize the queue with.\n */\n constructor(elements?: Iterable) {\n this.array = elements ? Array.from(elements) : [];\n }\n\n clear(): void {\n this.array.length = 0;\n }\n\n dequeue(): T | undefined {\n return this.size < 1 ? undefined : this.array.shift();\n }\n\n enqueue(element: T): number {\n return this.array.push(element);\n }\n\n peek(): T | undefined {\n return this.size < 1 ? undefined : this.array[0];\n }\n\n get size(): number {\n return this.array.length;\n }\n /**\n * Receive an iterator through the queue.\n *\n * **Note:** Unexpected behavior can occur if the collection is modified during iteration.\n *\n * @returns An iterator through the queue\n */\n [Symbol.iterator](): Iterator {\n return this.array[Symbol.iterator]();\n }\n}\n","import { LinkedList, List } from '../list';\nimport { Queue } from './queue';\n\n/**\n * A linked list implementation of the {@link Queue} interface\n */\nexport class LinkedQueue implements Queue {\n /**\n * The list containing every element.\n */\n protected list: List;\n /**\n * Instantiate the queue.\n *\n * @param elements - A set of elements to initialize the queue with.\n */\n constructor(elements?: Iterable) {\n this.list = new LinkedList(elements);\n }\n\n clear(): void {\n this.list.clear();\n }\n\n dequeue(): T | undefined {\n return this.list.shift();\n }\n\n enqueue(element: T): number {\n return this.list.push(element);\n }\n\n peek(): T | undefined {\n return this.list.get(0);\n }\n\n get size(): number {\n return this.list.size;\n }\n /**\n * Receive an iterator through the queue.\n *\n * **Note:** Unexpected behavior can occur if the collection is modified during iteration.\n *\n * @returns An iterator through the queue\n */\n [Symbol.iterator](): Iterator {\n return this.list[Symbol.iterator]();\n }\n}\n","import { lsb, lsp, msb, msp } from '../math/u32';\nimport { CombineFn } from '..';\nimport { MAX_ARRAY_LENGTH } from 'src/array/utils';\nimport { SegmentTree } from './segmentTree';\n\n/*\n mca(a, b) = lsp(a | msp(b - a)) ; // where a <= b\n left(i) = i - (lsp(i + 1) >>> 1)\n right(i) = i + (lsp(i + 1) >>> 1)\n parent(i) =\n offset = lsp(i + 1)\n i + offset - ((i & 2*offset) >>> 0)\n*/\n\n/**\n * A {@link SegmentTree} with entries stored in in-order traversal.\n * Inspired by [Tristan Hume's IForestIndex](https://thume.ca/2021/03/14/iforests) ([github](https://github.com/trishume/gigatrace))\n */\nexport class InOrderSegmentTree implements SegmentTree {\n /**\n * The maximum amount of elements that can be added.\n *\n * n elements require 2n memory.\n */\n static readonly MAX_SIZE: number = MAX_ARRAY_LENGTH >>> 1;\n /**\n * The set of elements and aggregation nodes for the tree\n */\n protected array: T[];\n /**\n * The function used to aggregate elements\n */\n protected combine: CombineFn;\n /**\n * Construct a new segment tree\n *\n * @param combine - The function used to aggregate segment information\n * @param elements - A set of elements to add into the initial tree\n */\n constructor(combine: CombineFn, elements: Iterable = []) {\n this.array = [];\n this.combine = combine;\n this.build(elements);\n }\n\n clear(): void {\n this.array.length = 0;\n }\n\n pop(): T | undefined {\n // Sanitize range\n if (this.size < 1) {\n return undefined;\n }\n\n // Un-complete aggregation nodes\n const i = this.array.length - 1;\n for (let mask = 2; i & mask; mask *= 2) {\n this.array[i - mask] = this.array[i - mask - (mask >>> 1)];\n }\n\n // Return element\n const out = this.array[i - 1];\n this.array.length -= 2;\n return out;\n }\n\n push(element: T): number {\n // Sanitize range\n if (this.size >= InOrderSegmentTree.MAX_SIZE) {\n throw new RangeError(`Invalid length`);\n }\n\n // Add element\n const i = this.array.length;\n this.array[i + 1] = this.set(i, element);\n\n return this.size;\n }\n\n query(min: number, max: number): T {\n // Sanitize range\n if (min >= max) {\n throw new RangeError(`Range [${min}..${max}) is empty`);\n }\n if (min < 0 || max > this.size) {\n throw new RangeError(`Range [${min}..${max}) not in [0..${this.size})`);\n }\n\n // Translate range to interior indices\n min *= 2;\n max *= 2;\n\n // Jump to min's highest aggregation node that is fully within the range\n let offset = lsp(min | msp(max - min));\n let value = this.array[min - 1 + (offset >>> 1)];\n\n // Continue jumping aggregation nodes until max is reached\n for (min += offset; min < max; min += offset) {\n offset = lsp(min | msp(max - min));\n value = this.combine(value, this.array[min - 1 + (offset >>> 1)]);\n }\n\n return value;\n }\n\n get size(): number {\n return this.array.length >>> 1;\n }\n\n /**\n * Return an iterator through the tree's elements\n */\n *[Symbol.iterator](): Iterator {\n for (let i = 0; i < this.array.length; i += 2) {\n yield this.array[i];\n }\n }\n\n update(min: number, max: number, operation: (element: T, index: number) => T): void {\n // Sanitize range\n if (min >= max) {\n return;\n }\n if (min < 0 || max > this.size) {\n throw new RangeError(`Range [${min}..${max}) not in [0..${this.size})`);\n }\n\n // Translate range to interior indices\n min *= 2;\n max *= 2;\n\n // Update the values\n let value: T;\n do {\n value = this.set(min, operation(this.array[min], min >>> 1));\n min += 2;\n } while (min < max);\n\n // Update remaining aggregation nodes\n let dc = 0;\n let dp = lsp(min);\n max = msb(min ^ this.array.length) - lsb(min);\n for (--min; max > 0; --max) {\n value = this.combine(value, this.array[min + (dp >>> 1) - dc]);\n this.array[min] = value;\n dc = (min & (2 * dp)) >>> 0;\n min += dp - dc;\n dp *= 2;\n }\n\n // Update the incomplete aggregation node\n this.array[min] = value;\n }\n /**\n * A helper method used to build the tree\n *\n * @param elements The initial set of elements to add into the tree\n */\n protected build(elements: Iterable) {\n for (const element of elements) {\n this.push(element);\n }\n }\n /**\n * A helper method to update complete aggregation nodes for an index\n */\n protected set(index: number, element: T): T {\n // Set the index\n this.array[index++] = element;\n\n // Update complete aggregation nodes, from lowest to highest\n for (let mask = 2; index & mask; mask *= 2) {\n element = this.combine(this.array[index - mask - (mask >>> 1)], element);\n this.array[index - mask] = element;\n }\n\n return element;\n }\n}\n","/**\n * Thanks to [Douglas Wilhelm Harder](https://ece.uwaterloo.ca/~dwharder/aads/Algorithms/Array_resizing/)\n * for their analysis on array resizing\n */\nimport { isArray, MAX_ARRAY_LENGTH } from 'src/array/utils';\nimport { isCollection } from 'src/collection';\nimport { Collection } from 'src/collection/collection';\nimport { CombineFn } from '..';\nimport { isPow2, lsp, msp } from '../math/u32';\nimport { SegmentTree } from './segmentTree';\n\n/**\n * A {@link SegmentTree} with entries stored in level-order traversal.\n * Memory usage: n elements require between 2n-1 to 4(n-1)-1 entries\n *\n */\nexport class LevelOrderSegmentTree implements SegmentTree {\n /**\n * The maximum number of elements that can be added.\n *\n * n elements require 2^⌈log2(2n)⌉ - 1 memory:\n */\n static readonly MAX_SIZE: number = (MAX_ARRAY_LENGTH + 1) / 2;\n /**\n * The internal array used to store elements and aggregation nodes\n */\n protected array: Array;\n /**\n * The function used to aggregate elements\n */\n protected combine: CombineFn;\n /**\n * The used length (size) of our internal array\n */\n protected length: number;\n /**\n * The start index for the lowest level\n */\n protected level: number;\n /**\n * Construct a new {@link SegmentTree}\n *\n * @param combinFn - The function used to aggregate elements\n * @param elements - Initial elements to build into the tree\n */\n constructor(combine: CombineFn, elements: Iterable = []) {\n this.array = [];\n this.combine = combine;\n this.length = 0;\n this.level = 0;\n this.build(elements);\n }\n\n clear(): void {\n this.length = 0;\n this.level = 0;\n this.array.length = 0;\n }\n\n pop(): T | undefined {\n // Sanitize range\n if (this.length <= this.level) {\n return undefined;\n }\n\n // Remove element\n const out = this.array[--this.length];\n\n // If level is <= 1/4 full\n if (this.length <= (this.array.length + 1) >>> 2) {\n this.shrink();\n }\n\n return out;\n }\n\n push(element: T): number {\n // If array is full\n if (this.length >= this.array.length) {\n this.grow();\n }\n\n // Add the new element\n this.array[this.length++] = element;\n\n // Update aggregation nodes\n for (let i = this.length; i & 1; this.array[i - 1] = element) {\n element = this.combine(this.array[i - 2], element);\n i >>>= 1;\n }\n\n return this.size;\n }\n\n query(min: number, max: number): T {\n // Sanitize range\n if (min >= max) {\n throw new RangeError(`Range [${min}..${max}) is empty`);\n }\n if (min < 0 || max > this.size) {\n throw new RangeError(`Range [${min}..${max}) not in [0..${this.size})`);\n }\n\n // Translate range to interior indices and align with powers of 2\n min += this.level + 1;\n max += this.level + 1;\n\n // Take the longest possible jump from min\n let offset = lsp(min | msp(max - min));\n let value: T = this.array[min / offset - 1];\n min += offset;\n\n // Continue jumping until max\n while (min < max) {\n offset = lsp(min | msp(max - min));\n value = this.combine(value, this.array[min / offset - 1]);\n min += offset;\n }\n\n return value;\n }\n\n get size(): number {\n return this.length - this.level;\n }\n\n /**\n * Return an iterator through the elements\n */\n *[Symbol.iterator](): Iterator {\n for (let i = 0; i < this.size; ++i) {\n yield this.array[this.level + i];\n }\n }\n\n update(min: number, max: number, operation: (element: T, index: number) => T): void {\n // Sanitize range\n if (min >= max) {\n return;\n }\n if (min < 0 || max > this.size) {\n throw new RangeError(`Range [${min}..${max}) not in [0..${this.size})`);\n }\n\n // Translate range to interior indices\n min += this.level;\n max += this.level;\n\n // Update the range\n for (let i = min; i < max; ++i) {\n this.array[i] = operation(this.array[i], i - this.level);\n }\n\n // Update the range's aggregation nodes\n this.aggregate(min, max);\n }\n /**\n * A helper method to aggregate a range of elements\n */\n protected aggregate(min: number, max: number): void {\n // Align indices with powers of 2\n ++min;\n ++max;\n\n // Aggregate elements\n for (let cap = this.length + 1; min < max; cap >>>= 1) {\n max += max & ((max - cap) >>> 31);\n for (let i = (min | 1) >>> 0; i < max; i += 2) {\n this.array[(i >>> 1) - 1] = this.combine(this.array[i - 2], this.array[i - 1]);\n }\n min >>>= 1;\n max >>>= 1;\n }\n }\n /**\n * A helper method used to build the tree\n *\n * @param elements The initial set of elements to add into the tree\n */\n protected build(elements: Collection | Iterable): void {\n let key: string | undefined = undefined;\n\n // Check if the iterable's size can be known.\n if (isArray(elements)) {\n key = 'length';\n } else if (isCollection(elements)) {\n key = 'size';\n } else {\n for (const element of elements) {\n this.push(element);\n }\n return;\n }\n\n // Get the iterable's size\n const n: number = (elements as any)[key];\n\n // Check for base case\n if (n < 1) {\n this.array.length = 0;\n this.length = 0;\n this.level = 0;\n return;\n }\n\n // Check if max capacity reached\n if (n >= LevelOrderSegmentTree.MAX_SIZE) {\n throw new RangeError('Invalid length');\n }\n\n // Allocate the array\n this.level = 2 * msp(n - 1) - 1;\n this.length = this.level;\n this.array.length = 2 * this.level + 1;\n\n // Add the elements\n for (const element of elements) {\n this.array[this.length++] = element;\n }\n\n // Update aggregation nodes\n this.aggregate(this.level, this.length);\n }\n /**\n * Shift the tree down a level\n */\n protected grow(): void {\n // Check base case\n if (this.size < 1) {\n this.array.length = 1;\n return;\n }\n\n // Check if max capacity reached\n if (this.size >= LevelOrderSegmentTree.MAX_SIZE) {\n throw new RangeError('Invalid length');\n }\n\n // Extend capacity\n this.array.length += this.array.length + 1;\n\n // Shift the tree down a level\n let min = this.level + 1;\n for (let max = this.length + 1; min < max; max >>>= 1) {\n this.array.copyWithin(2 * min - 1, min - 1, max - 1);\n min >>>= 1;\n }\n\n // Update pointers\n this.length += this.level + 1;\n this.level += this.level + 1;\n }\n /**\n * Shrink the tree to the smallest size\n */\n protected shrink(): void {\n const length = this.length - this.level;\n\n // Check base case\n if (length < 2) {\n this.array.copyWithin(0, this.level, this.length);\n this.level = 0;\n this.length = length;\n this.array.length = length;\n return;\n }\n\n // Get the highest node\n let min = this.level + 1;\n let mask = msp(length);\n min = min / lsp(min | mask) - 1;\n\n // Update the tree\n this.level = +!isPow2(length);\n for (let max = min + 1; mask; this.level += this.level + 1) {\n this.array.copyWithin(this.level, min, max);\n mask >>>= 1;\n min += min + 1;\n max += max + 2 + +((length & mask) > 0);\n }\n\n // Update pointers\n this.length = this.level + length;\n this.array.length = 2 * this.level + 1;\n }\n}\n","import { Collection } from './collection';\n\nexport * from './collection';\n\nexport function isCollection(obj: any): obj is Collection {\n return 'size' in obj && typeof obj['size'] === 'number';\n}\n","import { Stack } from './stack';\n\n/**\n * An implementation of the {@link Stack} interface using an array\n */\nexport class ArrayStack implements Stack {\n /**\n * The array containing every element.\n */\n protected array: T[];\n /**\n * Instantiate the stack.\n *\n * @param elements - A set of elements to initialize the stack with.\n */\n constructor(elements?: Iterable) {\n this.array = elements ? Array.from(elements) : [];\n }\n\n clear(): void {\n this.array.length = 0;\n }\n\n peek(): T | undefined {\n return this.array[this.array.length - 1];\n }\n\n pop(): T | undefined {\n return this.array.pop();\n }\n\n push(element: T): number {\n return this.array.push(element);\n }\n\n get size(): number {\n return this.array.length;\n }\n /**\n * Receive an iterator through the stack.\n *\n * **Note:** Unexpected behavior can occur if the collection is modified during iteration.\n *\n * @returns An iterator through the stack\n */\n *[Symbol.iterator](): Iterator {\n const array = this.array;\n for (let i = array.length; i > 0; yield array[--i]) {}\n }\n}\n","import { LinkedList, List } from '../list';\nimport { Stack } from './stack';\n\n/**\n * A linked list implementation of the {@link Stack} interface\n */\nexport class LinkedStack implements Stack {\n /**\n * The list containing every element.\n */\n protected list: List;\n /**\n * Instantiate the stack.\n *\n * @param elements - A set of elements to initialize the stack with.\n */\n constructor(elements?: Iterable) {\n this.list = new LinkedList();\n for (const element of elements || []) {\n this.push(element);\n }\n }\n\n clear(): void {\n this.list.clear();\n }\n\n peek(): T | undefined {\n return this.list.get(0);\n }\n\n pop(): T | undefined {\n return this.list.shift();\n }\n\n push(element: T): number {\n return this.list.unshift(element);\n }\n\n get size(): number {\n return this.list.size;\n }\n /**\n * Receive an iterator through the stack.\n *\n * **Note:** Unexpected behavior can occur if the collection is modified during iteration.\n *\n * @returns An iterator through the stack\n */\n [Symbol.iterator](): Iterator {\n return this.list[Symbol.iterator]();\n }\n}\n","import { CompareFn } from '..';\nimport { AATreeNode } from './aaTreeNode';\nimport {\n clone,\n search,\n Edge,\n inOrderTraverse,\n leftmost,\n leftmostStack,\n preOrderTraverse,\n removeStack,\n rightmost,\n rightmostStack,\n searchStack,\n debug,\n} from './binaryTreeUtils';\nimport { SortedTree } from './sortedTree';\nimport { isArray } from 'src/array/utils';\nimport { LinkedNode } from 'src/list';\n\n/**\n * An AA tree is a form of balanced tree used for storing and retrieving ordered data efficiently\n * ([source](https://en.wikipedia.org/wiki/AA_tree)).\n *\n * AA trees are named for Arne Andersson, their inventor. They are a variation of the red–black tree,\n * which supports efficient addition and deletion of entries. Unlike red–black trees, additional\n * constraints on the balancing mechanism greatly simplifies the implementation as well as\n * maintenance operations; While a red–black tree needs to consider seven different shapes\n * to properly balance the tree, an AA tree only needs to consider two shapes.\n *\n * The performance of an AA tree is equivalent to the performance of a red–black tree.\n * While an AA tree makes more rotations than a red-black tree, the simpler algorithms\n * tend to be faster, which balances out to similar performance. A red-black tree is\n * more consistent in its performance, but an AA tree tends to be flatter, which results\n * in slightly faster search times.\n */\nexport class AATree implements SortedTree {\n /**\n * The function to determine the order of elements.\n */\n protected compare: CompareFn;\n /**\n * Indicates how to handle duplicates:\n * - < 0 : Add to left subtree\n * - = 0 : Do now allow duplicates\n * - > 0 : Add to right subtree\n */\n protected dupeWeight: number;\n /**\n * The number of elements in the list.\n */\n protected length: number;\n /**\n * The node at the \"top\" of the heap.\n */\n protected root: AATreeNode | undefined;\n /**\n * Instantiate a tree.\n *\n * @param compareFn - The function to determine the order of elements.\n * @param elements - A set of elements to initialize the tree with.\n */\n constructor(compareFn: CompareFn, elements?: Iterable);\n /**\n * Instantiate a tree.\n *\n * @param compareFn - The function to determine the order of elements.\n * @param allowDuplicates - Whether to allow duplicates\n * @param elements - A set of elements to initialize the tree with.\n */\n constructor(compareFn: CompareFn, allowDuplicates: boolean, elements?: Iterable);\n constructor(\n compareFn: CompareFn,\n allowDuplicates?: boolean | Iterable,\n elements?: Iterable,\n ) {\n if (typeof allowDuplicates !== 'boolean') {\n elements = allowDuplicates;\n allowDuplicates = true;\n }\n this.compare = compareFn;\n this.dupeWeight = +allowDuplicates;\n this.length = 0;\n this.build(elements ?? []);\n }\n\n add(element: T): this {\n // Find the element\n const sentinel = { left: this.root } as AATreeNode;\n let edge: Edge> = { from: sentinel, label: 'left', to: this.root };\n let stack = searchStack(element, { value: edge }, this.compare, this.dupeWeight);\n\n // If element already exists\n if (stack.value.to != null) {\n return this;\n }\n\n // Add element\n edge = stack.value;\n let label = edge.label;\n edge.from![label!] = { level: 1, value: element };\n\n // Balance the tree\n while (stack.next) {\n stack = stack.next;\n edge = stack.value;\n edge.to = split(skew(edge.to));\n edge.from![(label = edge.label!)] = edge.to;\n }\n\n // Update state\n ++this.length;\n this.root = sentinel.left;\n return this;\n }\n\n clear(): void {\n this.root = undefined;\n this.length = 0;\n }\n\n comparator(): CompareFn {\n return this.compare;\n }\n\n delete(element: T): boolean {\n // Remove the element if found\n const sentinel = { left: this.root } as AATreeNode;\n const edge: Edge> = { from: sentinel, label: 'left', to: this.root };\n const stack = searchStack(element, { value: edge }, this.compare, 0);\n const removed = remove(stack);\n\n // Update state\n this.root = sentinel.left;\n this.length -= +removed;\n return removed;\n }\n\n has(element: T): boolean {\n return search(element, this.root, this.compare) != null;\n }\n\n max(): T | undefined {\n return rightmost(this.root)?.value;\n }\n\n min(): T | undefined {\n return leftmost(this.root)?.value;\n }\n\n pop(): T | undefined {\n // Find the maximum value\n const sentinel = { left: this.root } as AATreeNode;\n const edge: Edge> = { from: sentinel, label: 'left', to: this.root };\n const stack = rightmostStack({ value: edge });\n const value = stack.value.to?.value;\n\n // Remove the value\n const removed = remove(stack);\n\n // Update state\n this.root = sentinel.left;\n this.length -= +removed;\n return value;\n }\n\n shift(): T | undefined {\n // Find the minimum value\n const sentinel = { left: this.root } as AATreeNode;\n const edge: Edge> = { from: sentinel, label: 'left', to: this.root };\n const stack = leftmostStack({ value: edge });\n const value = stack.value.to?.value;\n\n // Remove the value\n const removed = remove(stack);\n\n // Update state\n this.root = sentinel.left;\n this.length -= +removed;\n return value;\n }\n\n get size(): number {\n return this.length;\n }\n\n *sorted(): Iterable {\n for (const node of inOrderTraverse(this.root)) {\n yield node.value;\n }\n }\n /**\n * Receive an iterator through the list.\n *\n * **Note:** Unexpected behavior can occur if the collection is modified during iteration.\n *\n * @returns An iterator through the list\n */\n *[Symbol.iterator](): Iterator {\n for (const node of preOrderTraverse(this.root)) {\n yield node.value;\n }\n }\n\n update(curElement: T, newElement: T): boolean {\n if (this.delete(curElement)) {\n this.add(newElement);\n return true;\n }\n return false;\n }\n\n protected build(obj: Iterable): void {\n if (isArray(obj)) {\n for (let i = 0; i < obj.length; ++i) {\n this.add(obj[i]);\n }\n } else if (obj instanceof AATree && this.compare === obj.compare) {\n this.root = clone(obj.root);\n this.length = obj.size;\n } else {\n for (const element of obj) {\n this.add(element);\n }\n }\n }\n}\n/**\n * @internal\n */\nexport function remove(stack: LinkedNode>>): boolean {\n let edge = stack.value;\n let node = edge.to;\n\n // If not found\n if (node == null) {\n return false;\n }\n\n // Remove the node\n stack = removeStack(stack);\n\n // Update the tree\n while (stack.next) {\n stack = stack.next;\n edge = stack.value;\n node = edge.to!;\n\n // Decrease levels\n const level = 1 + Math.min(node.left?.level ?? 0, node.right?.level ?? 0);\n if (level < node.level) {\n node.level = level;\n if (node.right != null && level < node.right.level) {\n node.right.level = level;\n }\n }\n\n // Balance\n node = skew(node);\n node.right = skew(node.right);\n if (node.right != null) {\n node.right.right = skew(node.right.right);\n }\n node = split(node);\n node.right = split(node.right);\n\n // Make the update\n edge.from![edge.label!] = edge.to = node;\n }\n\n return true;\n}\n/**\n * @internal\n */\nexport function skew(node?: undefined): undefined;\nexport function skew(node: AATreeNode): AATreeNode;\nexport function skew(node?: AATreeNode): AATreeNode | undefined;\nexport function skew(node?: AATreeNode): AATreeNode | undefined {\n if (node == null || node.left == null || node.level != node.left.level) {\n return node;\n }\n const left = node.left;\n node.left = left.right;\n left.right = node;\n return left;\n}\n/**\n * @internal\n */\nexport function split(node?: undefined): undefined;\nexport function split(node: AATreeNode): AATreeNode;\nexport function split(node?: AATreeNode): AATreeNode | undefined;\nexport function split(node?: AATreeNode): AATreeNode | undefined {\n if (\n node == null ||\n node.right == null ||\n node.right.right == null ||\n node.level != node.right.right.level\n ) {\n return node;\n }\n const right = node.right;\n node.right = right.left;\n right.left = node;\n ++right.level;\n return right;\n}\n","import { CompareFn } from 'src';\nimport { AVLTreeNode } from './avlTreeNode';\nimport {\n clone,\n search,\n Edge,\n inOrderTraverse,\n leftmost,\n leftmostStack,\n preOrderTraverse,\n rightmost,\n rightmostStack,\n searchStack,\n removeStack,\n} from './binaryTreeUtils';\nimport { SortedTree } from './sortedTree';\nimport { isArray } from 'src/array/utils';\nimport { LinkedNode } from 'src/list';\n\n/**\n * An AVL tree is a self-balancing binary search tree ([source](https://en.wikipedia.org/wiki/AVL_tree)).\n *\n * It is named after inventors Georgy Adelson-Velsky and Evgenii Landis and was the first such\n * data structure to be invented. In an AVL tree, the heights of the two child\n * subtrees of any node differ by at most one; if at any time they differ by more\n * than one, rebalancing is done to restore this property.\n *\n * Lookup, insertion, and deletion all take O(log(n)) time in both the average and worst cases,\n * where n is the number of nodes in the tree prior to the operation. Insertions and deletions\n * may require the tree to be rebalanced by one or more tree rotations.\n *\n * AVL trees are often compared with red–black trees as both take O(log(n))\n * time for the basic operations. For lookup-intensive applications, AVL trees are\n * faster than red–black trees because they are more strictly balanced.\n * Similar to red–black trees, AVL trees are height-balanced.\n */\nexport class AVLTree implements SortedTree {\n /**\n * The function to determine the order of elements.\n */\n protected compare: CompareFn;\n /**\n * Indicates how to handle duplicates:\n * - < 0 : Add to left subtree\n * - = 0 : Do now allow duplicates\n * - > 0 : Add to right subtree\n */\n protected dupeWeight: number;\n /**\n * The number of elements in the list.\n */\n protected length: number;\n /**\n * The root of the tree.\n */\n protected root: AVLTreeNode;\n /**\n * Instantiate a tree.\n *\n * @param compareFn - The function to determine the order of elements.\n * @param elements - A set of elements to initialize the tree with.\n */\n constructor(compareFn: CompareFn, elements?: Iterable);\n /**\n * Instantiate a tree.\n *\n * @param compareFn - The function to determine the order of elements.\n * @param allowDuplicates - Whether to allow duplicates\n * @param elements - A set of elements to initialize the tree with.\n */\n constructor(compareFn: CompareFn, allowDuplicates: boolean, elements?: Iterable);\n constructor(\n compareFn: CompareFn,\n allowDuplicates?: boolean | Iterable,\n elements?: Iterable,\n ) {\n if (typeof allowDuplicates !== 'boolean') {\n elements = allowDuplicates;\n allowDuplicates = true;\n }\n this.compare = compareFn;\n this.dupeWeight = +allowDuplicates;\n this.length = 0;\n this.root = {} as AVLTreeNode;\n this.build(elements ?? []);\n }\n\n add(element: T): this {\n // Find the element\n let edge: Edge> = { from: this.root, label: 'left', to: this.root.left };\n let stack = searchStack(element, { value: edge }, this.compare, this.dupeWeight);\n\n // If element already exists\n if (stack.value.to != null) {\n return this;\n }\n\n // Add element\n edge = stack.value;\n let label = edge.label;\n edge.from![label!] = { balanceFactor: 0, value: element };\n\n // Balance the tree\n while (stack.next) {\n stack = stack.next;\n edge = stack.value;\n edge.to!.balanceFactor += label === 'left' ? -1 : 1;\n edge.to = balance(edge.to!);\n edge.from![(label = edge.label!)] = edge.to;\n if (edge.to!.balanceFactor === 0) {\n break;\n }\n }\n\n // Update state\n ++this.length;\n return this;\n }\n\n clear(): void {\n this.root.left = undefined;\n this.length = 0;\n }\n\n comparator(): CompareFn {\n return this.compare;\n }\n\n delete(element: T): boolean {\n // Remove the element if found\n const edge: Edge> = { from: this.root, label: 'left', to: this.root.left };\n const stack = searchStack(element, { value: edge }, this.compare, 0);\n const removed = remove(stack);\n\n // Update state\n this.length -= +removed;\n return removed;\n }\n\n has(element: T): boolean {\n return search(element, this.root.left, this.compare) != null;\n }\n\n max(): T | undefined {\n return rightmost(this.root.left)?.value;\n }\n\n min(): T | undefined {\n return leftmost(this.root.left)?.value;\n }\n\n pop(): T | undefined {\n // Find the maximum value\n const edge: Edge> = { from: this.root, label: 'left', to: this.root.left };\n const stack = rightmostStack({ value: edge });\n const value = stack.value.to?.value;\n\n // Remove the value\n const removed = remove(stack);\n\n // Update state\n this.length -= +removed;\n return value;\n }\n\n shift(): T | undefined {\n // Find the minimum value\n const edge: Edge> = { from: this.root, label: 'left', to: this.root.left };\n const stack = leftmostStack({ value: edge });\n const value = stack.value.to?.value;\n\n // Remove the value\n const removed = remove(stack);\n\n // Update state\n this.length -= +removed;\n return value;\n }\n\n get size(): number {\n return this.length;\n }\n\n *sorted(): Iterable {\n for (const node of inOrderTraverse(this.root.left)) {\n yield node.value;\n }\n }\n /**\n * Receive an iterator through the list.\n *\n * **Note:** Unexpected behavior can occur if the collection is modified during iteration.\n *\n * @returns An iterator through the list\n */\n *[Symbol.iterator](): Iterator {\n for (const node of preOrderTraverse(this.root.left)) {\n yield node.value;\n }\n }\n\n update(curElement: T, newElement: T): boolean {\n if (this.delete(curElement)) {\n this.add(newElement);\n return true;\n }\n return false;\n }\n\n protected build(obj: Iterable): void {\n if (isArray(obj)) {\n for (let i = 0; i < obj.length; ++i) {\n this.add(obj[i]);\n }\n } else if (obj instanceof AVLTree && this.compare === obj.compare) {\n this.root = clone(obj.root);\n this.length = obj.size;\n } else {\n for (const element of obj) {\n this.add(element);\n }\n }\n }\n}\n/**\n * @internal\n */\nexport function balance(node: AVLTreeNode): AVLTreeNode {\n if (node.balanceFactor > 1) {\n if (node.right!.balanceFactor < 0) {\n node.right = rotateR(node.right!);\n }\n node = rotateL(node);\n } else if (node.balanceFactor < -1) {\n if (node.left!.balanceFactor > 0) {\n node.left = rotateL(node.left!);\n }\n node = rotateR(node);\n }\n return node;\n}\n/**\n * @internal\n */\nexport function remove(stack: LinkedNode>>): boolean {\n let edge = stack.value;\n const node = edge.to;\n\n // If not found\n if (node == null) {\n return false;\n }\n\n // Remove the node\n stack = removeStack(stack);\n\n // Balance the tree\n let label = stack.value.label;\n while (stack.next) {\n stack = stack.next;\n edge = stack.value;\n edge.to!.balanceFactor -= label === 'left' ? -1 : 1;\n edge.to = balance(edge.to!);\n edge.from![(label = edge.label)!] = edge.to;\n if (edge.to!.balanceFactor !== 0) {\n break;\n }\n }\n\n return true;\n}\n/**\n * @internal\n */\nexport function rotateL(P: AVLTreeNode): AVLTreeNode {\n const R = P.right!;\n P.right = R.left;\n R.left = P;\n P.balanceFactor -= 1 + Math.max(0, R.balanceFactor);\n R.balanceFactor -= 1 - Math.min(0, P.balanceFactor);\n return R;\n}\n/**\n * @internal\n */\nexport function rotateR(P: AVLTreeNode): AVLTreeNode {\n const L = P.left!;\n P.left = L.right;\n L.right = P;\n P.balanceFactor += 1 - Math.min(0, L.balanceFactor);\n L.balanceFactor += 1 + Math.max(0, P.balanceFactor);\n return L;\n}\n"],"sourceRoot":""} \ No newline at end of file +{"version":3,"sources":["webpack://Dastal/webpack/universalModuleDefinition","webpack://Dastal/webpack/bootstrap","webpack://Dastal/webpack/runtime/define property getters","webpack://Dastal/webpack/runtime/hasOwnProperty shorthand","webpack://Dastal/webpack/runtime/make namespace object","webpack://Dastal/./src/collection/iteratorUtils.ts","webpack://Dastal/./src/math/numberUtils.ts","webpack://Dastal/./src/collection/arrayUtils.ts","webpack://Dastal/./src/collection/index.ts","webpack://Dastal/./src/heap/utils.ts","webpack://Dastal/./src/heap/binaryHeap.ts","webpack://Dastal/./src/tree/binaryTreeUtils.ts","webpack://Dastal/./src/heap/skewHeap.ts","webpack://Dastal/./src/list/arrayList.ts","webpack://Dastal/./src/list/utils.ts","webpack://Dastal/./src/list/doublyLinkedList.ts","webpack://Dastal/./src/list/linkedList.ts","webpack://Dastal/./src/math/u32.ts","webpack://Dastal/./src/queue/arrayQueue.ts","webpack://Dastal/./src/queue/linkedQueue.ts","webpack://Dastal/./src/segmentTree/inOrderSegmentTree.ts","webpack://Dastal/./src/segmentTree/levelOrderSegmentTree.ts","webpack://Dastal/./src/stack/arrayStack.ts","webpack://Dastal/./src/stack/linkedStack.ts","webpack://Dastal/./src/tree/aaTree.ts","webpack://Dastal/./src/tree/avlTree.ts"],"names":["root","factory","exports","module","define","amd","self","__webpack_require__","definition","key","o","Object","defineProperty","enumerable","get","obj","prop","prototype","hasOwnProperty","call","Symbol","toStringTag","value","always","fn","next","done","fill","length","undefined","first","n","iterator","res","join","iterators","res2","never","once","skip","bind","split","iter","clamp","num","min","max","Math","wrapLeft","wrapRight","wrap","MAX_ARRAY_LENGTH","MAX_SAFE_ARGUMENT_LENGTH","isArray","Array","isTypedArray","TypedArray","getPrototypeOf","Uint8Array","splice","array","start","count","elements","maxStepSize","stepSize","maxElems","out","RangeError","isCollection","bubbleUp","index","compareFn","parentIndex","floor","parent","heapify","i","sinkDown","childIndex","child","skewMerge","heaps","lists","push","list","tree","right","compare","a","b","tail","pop","mergeKSorted","heap","node","left","BinaryHeap","this","addAll","element","indexOf","last","size","curElement","newElement","inOrderTraverse","preOrderTraverse","removeStack","stack","dir","edge","to","temp","successorStack","predecessorStack","from","label","clone","assign","leftmost","leftmostStack","rightmostStack","rightmost","search","comp","searchStack","dupeWeight","paths","toBinaryTree","nodes","par","SkewHeap","merge","comparator","ArrayList","copyWithin","callback","prev","shift","slice","sort","unshift","arguments","len","linkedMergeSort","isDoubly","lens","ceil","heads","tails","linkedMergeSorted","DoublyLinkedList","_addAll","_get","nodeA","nodeB","head","view","LinkedList","_copyWithin","nodeC","nodeD","remove","deleted","newTail","add","bitsSet","invert","msp","u32","isPow2","lsb","lsp","lsps","msb","msps","reverse","ArrayQueue","LinkedQueue","clear","InOrderSegmentTree","combine","build","mask","MAX_SIZE","set","offset","operation","dc","dp","LevelOrderSegmentTree","level","shrink","grow","aggregate","cap","ArrayStack","LinkedStack","AATree","allowDuplicates","sentinel","skew","removed","delete","AVLTree","balanceFactor","balance","rotateR","rotateL","P","R","L"],"mappings":"CAAA,SAA2CA,EAAMC,GAC1B,iBAAZC,SAA0C,iBAAXC,OACxCA,OAAOD,QAAUD,IACQ,mBAAXG,QAAyBA,OAAOC,IAC9CD,OAAO,SAAU,GAAIH,GACK,iBAAZC,QACdA,QAAgB,OAAID,IAEpBD,EAAa,OAAIC,IARnB,CASGK,MAAM,WACT,M,mBCTA,IAAIC,EAAsB,CCA1B,EAAwB,CAACL,EAASM,KACjC,IAAI,IAAIC,KAAOD,EACXD,EAAoBG,EAAEF,EAAYC,KAASF,EAAoBG,EAAER,EAASO,IAC5EE,OAAOC,eAAeV,EAASO,EAAK,CAAEI,YAAY,EAAMC,IAAKN,EAAWC,MCJ3E,EAAwB,CAACM,EAAKC,IAAUL,OAAOM,UAAUC,eAAeC,KAAKJ,EAAKC,GCClF,EAAyBd,IACH,oBAAXkB,QAA0BA,OAAOC,aAC1CV,OAAOC,eAAeV,EAASkB,OAAOC,YAAa,CAAEC,MAAO,WAE7DX,OAAOC,eAAeV,EAAS,aAAc,CAAEoB,OAAO,M,8qBCFhD,SAASC,EAAgBC,GAC5B,MAAO,CAAEC,KAAM,iBAAO,CAAEC,MAAM,EAAOJ,MAAOE,OAKzC,SAASG,EAAcC,EAAgBJ,GAC1C,MAAO,CACHC,KAAM,WACF,OAAIG,EAAS,EACF,CAAEF,MAAM,EAAMJ,WAAOO,MAE9BD,EACK,CAAEF,MAAM,EAAOJ,MAAOE,QAYlC,SAASM,EAAeC,EAAWC,GACtC,MAAO,CACHP,KAAM,WACF,GAAIM,EAAI,EACJ,MAAO,CAAEL,MAAM,EAAMJ,WAAOO,GAEhC,IAAMI,EAAMD,EAASP,OAErB,OADAM,EAAIE,EAAIP,KAA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GAAWC,GACvB,IAAMC,EAAID,EAAE3H,MAKZ,OAJA2H,EAAE3H,MAAQ4H,EAAEnH,KACZmH,EAAEnH,KAAOkH,EACTA,EAAEJ,eAAiB,EAAI/J,KAAKD,IAAI,EAAGqK,EAAEL,eACrCK,EAAEL,eAAiB,EAAI/J,KAAKF,IAAI,EAAGqK,EAAEJ,eAC9BK,EAKJ,SAASH,GAAWE,GACvB,IAAME,EAAIF,EAAElH,KAKZ,OAJAkH,EAAElH,KAAOoH,EAAE7H,MACX6H,EAAE7H,MAAQ2H,EACVA,EAAEJ,eAAiB,EAAI/J,KAAKF,IAAI,EAAGuK,EAAEN,eACrCM,EAAEN,eAAiB,EAAI/J,KAAKD,IAAI,EAAGoK,EAAEJ,eAC9BM,E","file":"dastal.min.js","sourcesContent":["(function webpackUniversalModuleDefinition(root, factory) {\n\tif(typeof exports === 'object' && typeof module === 'object')\n\t\tmodule.exports = factory();\n\telse if(typeof define === 'function' && define.amd)\n\t\tdefine(\"Dastal\", [], factory);\n\telse if(typeof exports === 'object')\n\t\texports[\"Dastal\"] = factory();\n\telse\n\t\troot[\"Dastal\"] = factory();\n})(self, function() {\nreturn ","// The require scope\nvar __webpack_require__ = {};\n\n","// define getter functions for harmony exports\n__webpack_require__.d = (exports, definition) => {\n\tfor(var key in definition) {\n\t\tif(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {\n\t\t\tObject.defineProperty(exports, key, { enumerable: true, get: definition[key] });\n\t\t}\n\t}\n};","__webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))","// define __esModule on exports\n__webpack_require__.r = (exports) => {\n\tif(typeof Symbol !== 'undefined' && Symbol.toStringTag) {\n\t\tObject.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });\n\t}\n\tObject.defineProperty(exports, '__esModule', { value: true });\n};","/**\n * Get an iterator that always returns a given value.\n */\nexport function always(fn: () => T): Iterator {\n return { next: () => ({ done: false, value: fn() }) };\n}\n/**\n * Get an iterator that returns a value a given amount of times.\n */\nexport function fill(length: number, fn: () => T): Iterator {\n return {\n next: () => {\n if (length < 1) {\n return { done: true, value: undefined };\n }\n --length;\n return { done: false, value: fn() };\n },\n };\n}\n/**\n * Iterate through the first num elements of an iterator.\n *\n * @param n - The number of elements to iterate.\n * @param iterator - The iterator.\n *\n * @returns - An iterator limited to the next n elements.\n */\nexport function first(n: number, iterator: Iterator): Iterator {\n return {\n next: () => {\n if (n < 1) {\n return { done: true, value: undefined };\n }\n const res = iterator.next();\n n = res.done ? 0 : n - 1;\n return res;\n },\n };\n}\n/**\n * Join multiple iterators into one.\n *\n * @param iterators - The iterators to join.\n */\nexport function join(iterators: Iterator>): Iterator {\n let iterator: Iterator | undefined = { next: () => ({ done: true, value: undefined }) };\n return {\n next: () => {\n if (iterator == null) {\n return { done: true, value: undefined };\n }\n let res = iterator.next();\n while (res.done) {\n const res2 = iterators.next();\n if (res2.done) {\n iterator = undefined;\n return { done: true, value: undefined };\n }\n iterator = res2.value;\n res = iterator.next();\n }\n return res;\n },\n };\n}\n/**\n * Get an empty iterator.\n */\nexport function never(): Iterator {\n return { next: () => ({ done: true, value: undefined }) };\n}\n/**\n * Wrap a value in an iterator.\n */\nexport function once(fn: () => T): Iterator {\n let done = false;\n return {\n next: () => {\n const res = { done, value: fn() };\n done = true;\n fn = () => undefined!;\n return res;\n },\n };\n}\n/**\n * Skip the next num elements of an iterator.\n *\n * @param n - The number of elements to skip.\n * @param iterator - The iterator.\n *\n * @returns - The iterator after skipping n elements.\n */\nexport function skip(n: number, iterator: Iterator): Iterator {\n let fn = () => {\n let res: IteratorResult = { done: false, value: undefined! };\n while (n-- > 0 && !res.done) {\n res = iterator.next();\n }\n fn = iterator.next.bind(iterator);\n return res;\n };\n return { next: () => fn() };\n}\n/**\n * Split an iterator into multiple iterators of a given length.\n *\n * @param length - The length of each iterator.\n * @param iterator - The iterator to split.\n *\n * @returns - An iterator of the resulting iterators.\n */\nexport function split(length: number, iterator: Iterator): Iterator> {\n if (length < 1) {\n return { next: () => ({ done: true, value: undefined }) };\n }\n let done = false;\n return {\n next: () => {\n if (done) {\n return { done, value: undefined };\n }\n const iter = first(length, iterator);\n const res = iter.next();\n if (res.done) {\n done = true;\n return { done, value: undefined };\n }\n return { done, value: join([once(() => res.value), iter][Symbol.iterator]()) };\n },\n };\n}\n","/**\n * Limits a number to be within a given range.\n *\n * f(x, min, max) = y, where min <= y <= max\n *\n * @param num - The number to clamp\n * @param min - The minimum result value, inclusive\n * @param max - The maximum result value, inclusive\n *\n * @returns The clamped number\n */\nexport function clamp(num: number, min: number, max: number): number {\n return Math.min(max, Math.max(min, num));\n}\n/**\n * Wraps a number if below a given range\n *\n * f(x, min, max) = {\n * x, where x >= min\n * max - (min - x), where x < min\n * }\n *\n * @param num - The number to wrap\n * @param min - The minimum result value, inclusive\n * @param max - The maximum result value, inclusive\n *\n * @returns - The wrapped number\n */\nexport function wrapLeft(num: number, min: number, max: number): number {\n return num < min ? max - min + num : num;\n}\n/**\n * Wraps a number if above a given range\n *\n * f(x, min, max) = {\n * x, where x <= max\n * min + (x - max), where x > max\n * }\n *\n * @param num - The number to wrap\n * @param min - The minimum result value, inclusive\n * @param max - The maximum result value, inclusive\n *\n * @returns - The wrapped number\n */\nexport function wrapRight(num: number, min: number, max: number): number {\n return num > max ? min + (num - max) : num;\n}\n/**\n * Wraps a number if outside a given range\n *\n * @param num - The number to wrap\n * @param min - The minimum result value, inclusive\n * @param max - The maximum result value, inclusive\n *\n * @returns - The wrapped number\n */\nexport function wrap(num: number, min: number, max: number): number {\n return num < min ? max - min + num : wrapRight(num, min, max);\n}\n","import { first } from 'src/collection/iteratorUtils';\nimport { clamp, wrapLeft } from 'src/math/numberUtils';\n\n/**\n * The maximum length of an array.\n *\n * According to the [ECMA-262](https://tc39.es/ecma262/#array-index):\n * 0 <= array.length <= 2^32 - 1\n *\n * If this value should be updated, please\n * submit a pull request with details supporting a new max length.\n */\nexport const MAX_ARRAY_LENGTH = 4294967295;\n/**\n * The maximum number of arguments that can be safely accepted by a function.\n *\n * According to the [ECMA-262](https://tc39.es/ecma262/#sec-list-and-record-specification-type), there is no maximum. In practice, different\n * environments impose their own limit ([source](https://stackoverflow.com/questions/22747068/is-there-a-max-number-of-arguments-javascript-functions-can-accept)).\n *\n * This value was chosen through research, local testing and iteration. The actual number of arguments\n * accepted in an environment may be larger but hopefully not smaller. If errors are raised,\n * please submit a bug with your environment details and a new max length.\n */\nexport const MAX_SAFE_ARGUMENT_LENGTH = 32767;\n/**\n * Check if a value is an Array or TypedArray.\n *\n * @param obj - The value to check.\n *\n * @returns `true` if an Array or TypedArray, otherwise `false`.\n */\nexport function isArray(obj: unknown): obj is T[] {\n return obj instanceof Array || isTypedArray(obj);\n}\n/**\n * Check if a value is a TypedArray.\n *\n * See [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray)\n * for more details.\n *\n * @param obj - The value to check.\n *\n * @returns `true` if a TypedArray, otherwise `false`.\n */\nexport const isTypedArray = (() => {\n const TypedArray = Object.getPrototypeOf(Uint8Array);\n return function isTypedArray(obj: unknown): obj is T[] {\n return obj instanceof TypedArray;\n };\n})();\n/**\n * Removes elements from an array and, if necessary, inserts new elements in their place, returning the deleted elements.\n *\n * Contrary to Array.splice, this will not throw an error if too many new elements are given as arguments.\n *\n * @param array - The array to splice.\n * @param start - The zero-based location in the array from which to start removing elements.\n * @param count - The number of elements to remove.\n * @param elements - The new elements to splice in.\n *\n * @returns - An array containing the elements that were deleted.\n */\nexport function splice(array: T[], start?: number, count?: number, elements?: Iterable): T[] {\n start = clamp(wrapLeft(start ?? 0, 0, array.length), 0, array.length);\n count = clamp(count ?? array.length, 0, array.length - start);\n\n // Base case\n if (elements == null) {\n return array.splice(start, count);\n }\n\n const maxStepSize = MAX_SAFE_ARGUMENT_LENGTH - 2;\n const iterator = elements[Symbol.iterator]();\n\n // Perform the initial splice\n let stepSize = array.length - count;\n const maxElems = MAX_ARRAY_LENGTH - stepSize;\n let n = Math.min(maxStepSize, maxElems);\n const out = array.splice(start, count, ...{ [Symbol.iterator]: () => first(n, iterator) });\n stepSize = array.length - stepSize;\n start += stepSize;\n\n // Splice in new elements as long as there is space in the array\n for (n = maxElems - stepSize; n >= maxStepSize && stepSize >= maxStepSize; n -= stepSize) {\n stepSize = array.length;\n array.splice(start, 0, ...{ [Symbol.iterator]: () => first(maxStepSize, iterator) });\n stepSize = array.length - stepSize;\n start += stepSize;\n }\n if (n > 0 && stepSize >= maxStepSize) {\n array.splice(start, 0, ...{ [Symbol.iterator]: () => first(n, iterator) });\n }\n\n // If maximum array capacity reached\n if (iterator.next().done != true) {\n throw new RangeError('Invalid array length');\n }\n\n return out;\n}\n","import { Collection } from './collection';\n\nexport * as ArrayUtils from './arrayUtils';\nexport * from './collection';\nexport * as IteratorUtils from './iteratorUtils';\n\n/**\n * Check if a value is a {@link Collection}.\n *\n * @param obj - The value to check.\n *\n * @returns - `true` if obj is a Collection, `false` otherwise.\n */\nexport function isCollection(obj: any): obj is Collection {\n return (\n obj != null && typeof obj['size'] === 'number' && typeof obj[Symbol.iterator] === 'function'\n );\n}\n","import { LinkedNode } from 'src/list';\nimport { BinaryTreeNode } from 'src/tree/binaryTreeNode';\nimport { CompareFn } from '..';\n\n/**\n * @internal\n */\nexport function bubbleUp(index: number, compareFn: CompareFn, array: Array): void {\n const value = array[index];\n\n // Until we reach the top of the heap\n while (index > 0) {\n // Get the parent\n const parentIndex = Math.floor((index + 1) / 2) - 1;\n const parent = array[parentIndex]!;\n\n // If the parent is above or equal to value, the heap is in order\n if (compareFn(parent, value) <= 0) {\n break;\n }\n\n // Swap the parent with value and continue\n array[parentIndex] = value;\n array[index] = parent;\n index = parentIndex;\n }\n}\n/**\n * @internal\n */\nexport function heapify(compareFn: CompareFn, array: T[]): void {\n for (let i = (array.length + 1) >>> 1; i > 0; sinkDown(--i, compareFn, array)) {}\n}\n/**\n * @internal\n */\nexport function mergeKSorted(compareFn: CompareFn, lists: LinkedNode[]): LinkedNode {\n // Heapify the list of lists based on\n // the value at the head of each list.\n const compare: CompareFn> = (a, b) => compareFn(a.value, b.value);\n heapify(compare, lists);\n\n // Combine the lists into a single list.\n const list: LinkedNode = lists[0];\n for (let tail = list; lists.length > 1; tail = tail.next) {\n lists[0] = lists[0].next ?? lists.pop()!;\n sinkDown(0, compare, lists);\n tail.next = lists[0];\n }\n\n return list;\n}\n/**\n * @internal\n */\nexport function sinkDown(index: number, compareFn: CompareFn, array: Array): void {\n const n = array.length;\n const value = array[index];\n do {\n // Compute the left child's index\n let childIndex = 2 * index + 1;\n\n // If no children exist\n if (childIndex >= n) {\n break;\n }\n\n // Decide which child to compare with\n let child = array[childIndex];\n if (childIndex + 1 < n && compareFn(array[childIndex + 1], child) <= 0) {\n child = array[++childIndex]!;\n }\n\n // If value <= child\n if (compareFn(value, child) <= 0) {\n break;\n }\n\n // Swap value and child\n array[index] = child;\n array[childIndex] = value;\n index = childIndex;\n } while (true);\n}\n/**\n * See: https://en.wikipedia.org/wiki/Skew_heap#Merging_two_heaps\n *\n * @param compareFn - A function used to determine the order of the heap.\n *\n * It is expected to return:\n * - A negative value if first argument < second argument\n * - Zero if first argument == second argument\n * - A positive value if first argument > second argument\n * @param heaps - An iterable of heaps to merge\n *\n * @returns The new heap\n */\nexport function skewMerge(\n compareFn: CompareFn,\n heaps: (BinaryTreeNode | undefined)[],\n): BinaryTreeNode | undefined {\n // Remove undefineds and initialize a list for each heap\n const lists: LinkedNode>[] = [];\n for (let i = 0; i < heaps.length; ++i) {\n if (heaps[i] != null) {\n lists.push({ value: heaps[i]! });\n }\n }\n\n // Check if nothing to merge with\n if (lists.length < 2) {\n return lists[0]?.value;\n }\n\n // Split each heap into subheaps by cutting every right path; From the root\n // node, sever the right node to make the right child its own heap. Repeat\n // until you can't go right. This will turn each heap into a list of heaps\n // where the root either only has a left child or no children at all. The\n // lists of heaps will be in desc order (from bottom to top).\n for (let i = 0; i < lists.length; ++i) {\n let list = lists[i];\n let tree: BinaryTreeNode | undefined = list.value;\n while ((tree = tree.right)) {\n list = { next: list, value: tree };\n }\n lists[i] = list;\n }\n\n // Combine the lists into a single list in desc order\n let list: LinkedNode> | undefined = mergeKSorted(\n (a, b) => compareFn(b.value, a.value),\n lists,\n );\n\n // While there are still multiple heaps, iteratively combine\n // the first two (from left to right). If the root of the second-to-first\n // subtree has a left child, swap it to be the right child. Link the root\n // of the last subtree as the left child of the second-to-first subtree.\n let heap = list.value;\n while ((list = list.next)) {\n const node = list.value;\n node.right = node.left;\n node.left = heap;\n heap = node;\n }\n\n return heap;\n}\n","import { isArray, MAX_ARRAY_LENGTH } from 'src/collection/arrayUtils';\nimport { CompareFn } from '..';\nimport { Heap } from './heap';\nimport { bubbleUp, heapify, sinkDown } from './utils';\n\n/**\n * A binary heap is a heap implemented as a binary tree with an additional shape property\n * ([source](https://en.wikipedia.org/wiki/Binary_heap)).\n *\n * **Shape property**: Must be a complete binary tree. This means all levels of the tree\n * (except possibly the last one) are fully filled. If the last level of the tree is incomplete,\n * the nodes of that level are filled from left to right.\n *\n * #### Complexity\n *\n * | Property | Average | Worst |\n * | :------- | :------ | :---- |\n * | Space | O(n) | O(n)\n * | Push | O(1) | O(log n)\n * | Peek | O(1)\t| O(1)\n * | Pop | O(log n)| O(log n)\n * | Search | O(n) | O(n)\n */\nexport class BinaryHeap implements Heap {\n /**\n * The array containing every element.\n */\n protected array: T[];\n /**\n * The function to determine the order of elements.\n */\n protected compare: CompareFn;\n /**\n * Instantiate a heap.\n *\n * @param compareFn - The function to determine the order of elements.\n * @param elements - A set of elements to initialize the list with.\n */\n constructor(compareFn: CompareFn, elements?: Iterable) {\n this.compare = compareFn;\n this.array = [];\n this.addAll(elements ?? []);\n }\n\n addAll(elements: Iterable): number {\n const array = this.array;\n const length = array.length;\n\n if (isArray(elements)) {\n if (array.length + elements.length > MAX_ARRAY_LENGTH) {\n throw new RangeError('Invalid heap length');\n }\n for (let i = 0; i < elements.length; ++i) {\n array.push(elements[i]);\n }\n } else {\n for (const element of elements) {\n if (array.length >= MAX_ARRAY_LENGTH) {\n throw new RangeError('Invalid heap length');\n }\n array.push(element);\n }\n }\n\n // Update the heap\n if (length < array.length) {\n heapify(this.compare, array);\n }\n\n return array.length;\n }\n\n clear(): void {\n this.array.length = 0;\n }\n\n comparator(): CompareFn {\n return this.compare;\n }\n\n contains(element: T): boolean {\n return this.array.indexOf(element) >= 0;\n }\n\n delete(element: T): boolean {\n const index = this.array.indexOf(element);\n if (index < 0) {\n return false;\n }\n\n // If deleting the last value\n const last = this.array.pop()!;\n if (index >= this.array.length) {\n return true;\n }\n\n // Add the last value to the\n // deleted index and update the heap\n this.array[index] = last;\n sinkDown(index, this.compare, this.array);\n bubbleUp(index, this.compare, this.array);\n return true;\n }\n\n merge(heap: Heap): this {\n const array = this.array;\n\n if (heap.size < 1) {\n return this;\n }\n\n if (array.length + heap.size > MAX_ARRAY_LENGTH) {\n throw new RangeError('Invalid heap length');\n }\n\n for (const element of heap) {\n array.push(element);\n }\n\n heapify(this.compare, array);\n return this;\n }\n\n peek(): T | undefined {\n return this.array.length > 0 ? this.array[0] : undefined;\n }\n\n pop(): T | undefined {\n if (this.array.length < 1) {\n return undefined;\n }\n\n // Get the root and the last value\n const value = this.array[0];\n const last = this.array.pop();\n\n // If value != last\n if (this.array.length > 0) {\n // Move the last value to the root and update the heap\n this.array[0] = last!;\n sinkDown(0, this.compare, this.array);\n }\n\n return value;\n }\n\n push(value: T): number {\n // Add new value to the end of the heap\n this.array.push(value);\n\n // Update the heap\n bubbleUp(this.array.length - 1, this.compare, this.array);\n return this.size;\n }\n\n pushPop(value: T): T {\n // If empty or value is <= to root\n if (this.array.length < 1 || this.compare(value, this.array[0]) <= 0) {\n return value;\n }\n\n // Swap the root and value\n const root = this.array[0];\n this.array[0] = value;\n sinkDown(0, this.compare, this.array);\n return root;\n }\n\n replace(value: T): T | undefined {\n // If empty\n if (this.array.length < 1) {\n this.array.push(value);\n return undefined;\n }\n\n // Swap the root with value\n const root = this.array[0];\n this.array[0] = value;\n value = root;\n\n // Update the heap\n sinkDown(0, this.compare, this.array);\n return value;\n }\n\n get size(): number {\n return this.array.length;\n }\n\n *sorted(): Iterable {\n if (this.array.length < 1) {\n return;\n }\n const array = this.array;\n const heap = new BinaryHeap((a, b) => this.compare(array[a], array[b]), [0]);\n do {\n let index = heap.pop()!;\n if (index < array.length) {\n yield array[index];\n index = 2 * index + 1;\n index < array.length && heap.push(index);\n ++index < array.length && heap.push(index);\n }\n } while (heap.size > 0);\n }\n /**\n * Receive an iterator through the list.\n *\n * **Note:** Unexpected behavior can occur if the collection is modified during iteration.\n *\n * @returns An iterator through the list\n */\n [Symbol.iterator](): Iterator {\n return this.array[Symbol.iterator]();\n }\n\n update(curElement: T, newElement: T): boolean {\n const index = this.array.indexOf(curElement);\n if (index < 0) {\n return false;\n }\n this.array[index] = newElement;\n sinkDown(index, this.compare, this.array);\n bubbleUp(index, this.compare, this.array);\n return true;\n }\n}\n","import { LinkedNode } from 'src/list';\nimport { CompareFn } from '..';\nimport { BinaryTreeNode } from './binaryTreeNode';\n\n/**\n * @internal\n */\nexport interface Edge> {\n label?: 'left' | 'right';\n from?: Node;\n to?: Node;\n}\n/**\n * [source](https://stackoverflow.com/questions/51419176/how-to-get-a-subset-of-keyof-t-whose-value-tk-are-callable-functions-in-typ)\n * \n * @internal\n *\nexport type KeyOfType = {[K in keyof T]: T[K] extends U ? K: never}[keyof T];\n*/\n/**\n * @internal\n */\nexport function debug, T = any>(\n root: N | undefined,\n mapFn?: (node: N) => any,\n): void {\n mapFn = mapFn == null ? (n) => n.value : mapFn;\n\n // Turn the tree into an array in level-order\n const array: string[] = [];\n for (const node of levelOrderTraverse(root, true)) {\n array.push(node ? `${mapFn(node)}` : '?');\n }\n\n // If empty\n if (array.length < 1) {\n console.log('\\n');\n return;\n }\n\n // Find the longest value string\n const lenV = array.reduce((p, c) => Math.max(p, c.length), 0);\n\n // Pad each value\n for (let i = 0; i < array.length; ++i) {\n array[i] = pad(array[i], lenV, ' ');\n }\n\n // Split values into levels\n const levels = [];\n for (let n = 1; array.length > 0; n *= 2) {\n levels.push(array.splice(0, n));\n }\n\n // Initialize formatting variables\n let branch = '_'.repeat(1 + lenV / 2);\n let offset = '';\n const offsetOffset = ' '.repeat(branch.length);\n let separator = ' '.repeat(1 + ((lenV - 1) & 1));\n const separatorOffset = ' '.repeat(lenV);\n\n // Build the last level\n array.length = levels.length;\n array[array.length - 1] = levels.pop()!.join(separator);\n\n // Build remaining levels in reverse\n for (let n = levels.length - 1; n >= 0; --n) {\n const level = levels.pop()!;\n for (let j = 0; j < level.length; ++j) {\n level[j] = branch + level[j] + branch;\n }\n array[n] = offset + level.join(separator);\n branch += branch;\n offset += offset + offsetOffset;\n separator += separator + separatorOffset;\n }\n\n // Output\n console.log(array.join('\\n'), '\\n');\n}\n/**\n * @internal\n */\nexport function removeStack>(\n stack: LinkedNode>,\n dir = true,\n): LinkedNode> {\n let edge = stack.value;\n let node = edge.to;\n\n // Input check\n if (node == null) {\n return stack;\n }\n\n // Find the replacement\n if (node.right == null) {\n // If no right child, replace with left\n node = node.left;\n } else if (node.left == null) {\n // If no left child, replace with right\n node = node.right;\n } else if (dir) {\n // Replace with the successor\n stack = successorStack(stack);\n edge = stack.value;\n const temp = edge.to!;\n node.value = temp.value;\n node = temp.right;\n } else {\n // Replace with the predecessor\n stack = predecessorStack(stack);\n edge = stack.value;\n const temp = edge.to!;\n node.value = temp.value;\n node = temp.left;\n }\n\n // Make the replacement / update the tree\n edge.to = node;\n if (edge.from) {\n edge.from[edge.label!] = edge.to = node;\n }\n\n return stack;\n}\n/**\n * @internal\n */\nexport function clone>(node: undefined): undefined;\nexport function clone>(node: Node): Node;\nexport function clone>(node: Node | undefined): Node | undefined;\nexport function clone>(node: Node | undefined): Node | undefined {\n if (node == null) {\n return undefined;\n }\n const out: Node = Object.assign({}, node);\n let stack: LinkedNode | undefined = { value: out };\n do {\n node = stack.value;\n stack = stack.next;\n if (node.left) {\n stack = { next: stack, value: (node.left = Object.assign({}, node.left)) };\n }\n if (node.right) {\n stack = { next: stack, value: (node.right = Object.assign({}, node.right)) };\n }\n } while (stack);\n return out;\n}\n/**\n * @internal\n */\nexport function leftmost>(node: undefined): undefined;\nexport function leftmost>(node: Node): Node;\nexport function leftmost>(\n node: Node | undefined,\n): Node | undefined;\nexport function leftmost>(\n node: Node | undefined,\n): Node | undefined {\n if (node == null) {\n return undefined;\n }\n while (node.left) {\n node = node.left;\n }\n return node;\n}\n/**\n * @internal\n */\nexport function leftmostStack>(\n stack: LinkedNode>,\n): LinkedNode> {\n let node = stack.value.to;\n if (node == null) {\n return stack;\n }\n while (node.left) {\n stack = { next: stack, value: { label: 'left', from: node, to: node.left } };\n node = node.left;\n }\n return stack;\n}\n/**\n * @internal\n */\nexport function* inOrderTraverse>(\n node: Node | undefined,\n): Generator {\n let stack: LinkedNode | undefined = undefined;\n\n while (node) {\n stack = { next: stack, value: node };\n node = node.left;\n }\n\n while (stack) {\n node = stack.value;\n stack = stack.next;\n yield node;\n node = node.right;\n while (node) {\n stack = { next: stack, value: node };\n node = node.left;\n }\n }\n}\n/**\n * @internal\n */\nexport function levelOrderTraverse>(\n node: Node | undefined,\n padded?: false,\n): Generator;\nexport function levelOrderTraverse>(\n node: Node | undefined,\n padded: true,\n): Generator;\nexport function* levelOrderTraverse>(\n node: Node | undefined,\n padded = false,\n): Generator {\n const nil = {} as LinkedNode;\n let head: LinkedNode = { value: node };\n let tail = head;\n for (let cont = node != null; cont; head = head.next!) {\n tail = tail.next = nil;\n for (cont = false; head !== nil; head = head.next!) {\n node = head.value;\n if (node) {\n yield node;\n cont ||= node.left != null || node.right != null;\n tail = tail.next = { value: node.left };\n tail = tail.next = { value: node.right };\n } else if (padded) {\n yield undefined;\n tail = tail.next = { value: undefined };\n tail = tail.next = { value: undefined };\n }\n }\n }\n}\n/**\n * @internal\n */\nfunction pad(str: string, maxLen: number, fillString: string): string {\n const len = str.length;\n if (len >= maxLen) {\n return str;\n }\n const diff = maxLen - len;\n return str.padStart(len + diff / 2, fillString).padEnd(len + diff, fillString);\n}\n/**\n * @internal\n */\nexport function* postOrderTraverse>(\n node: Node | undefined,\n): Generator {\n interface Meta {\n seen: boolean;\n node?: Node;\n }\n let stack: LinkedNode | undefined = { value: { seen: false, node } };\n do {\n const meta = stack.value;\n stack = stack.next;\n if (meta.node) {\n if (meta.seen) {\n yield meta.node;\n } else {\n meta.seen = true;\n stack = { next: stack, value: meta };\n stack = { next: stack, value: { seen: false, node: meta.node.right } };\n stack = { next: stack, value: { seen: false, node: meta.node.left } };\n }\n }\n } while (stack);\n}\n/**\n * @internal\n */\nexport function predecessor>(\n node: Node | undefined,\n): Node | undefined {\n return node == null ? undefined : rightmost(node.left);\n}\n/**\n * @internal\n */\nexport function predecessorStack>(\n stack: LinkedNode>,\n): LinkedNode> {\n const node = stack.value.to;\n if (node == null) {\n return stack;\n }\n stack = { next: stack, value: { label: 'left', from: node, to: node.left } };\n return rightmostStack(stack);\n}\n/**\n * @internal\n */\nexport function* preOrderTraverse>(\n node: Node | undefined,\n): Generator {\n let stack: LinkedNode | undefined = { value: node };\n do {\n node = stack.value;\n stack = stack.next;\n if (node) {\n yield node;\n stack = { next: stack, value: node.right };\n stack = { next: stack, value: node.left };\n }\n } while (stack);\n}\n/**\n * @internal\n */\nexport function reverse>(root?: Node): void {\n if (root == null) {\n return;\n }\n for (const node of preOrderTraverse(root)) {\n const left = node.left;\n node.left = node.right;\n node.right = left;\n }\n}\n/**\n * @internal\n */\nexport function rightmost>(node: undefined): undefined;\nexport function rightmost>(node: Node): Node;\nexport function rightmost>(\n node: Node | undefined,\n): Node | undefined;\nexport function rightmost>(\n node: Node | undefined,\n): Node | undefined {\n if (node == null) {\n return undefined;\n }\n while (node.right) {\n node = node.right;\n }\n return node;\n}\n/**\n * @internal\n */\nexport function rightmostStack>(\n stack: LinkedNode>,\n): LinkedNode> {\n let node = stack.value.to;\n if (node == null) {\n return stack;\n }\n while (node.right) {\n stack = { next: stack, value: { label: 'right', from: node, to: node.right } };\n node = node.right;\n }\n return stack;\n}\n/**\n * Assumes sorted by compareFn\n * @internal\n */\nexport function search>(\n element: T,\n node: Node | undefined,\n compareFn: CompareFn,\n): Node | undefined {\n while (node) {\n const comp: number = compareFn(element, node.value);\n if (comp == 0) {\n break;\n }\n node = comp < 0 ? node.left : node.right;\n }\n return node;\n}\n/**\n * Assumes sorted by compareFn\n * @internal\n */\nexport function searchStack>(\n element: T,\n stack: LinkedNode>,\n compareFn: CompareFn,\n dupeWeight = 0,\n): LinkedNode> {\n const paths: ['left', 'right'] = ['left', 'right'];\n let node = stack.value.to;\n while (node) {\n const comp: number = compareFn(element, node.value) || dupeWeight;\n if (comp === 0) {\n break;\n }\n const label = paths[+(comp > 0)];\n stack = { next: stack, value: { label, from: node, to: node[label] } };\n node = node[label]!;\n }\n return stack;\n}\n/**\n * @internal\n */\nexport function successor>(\n node: Node | undefined,\n): Node | undefined {\n return node == null ? undefined : leftmost(node.right);\n}\n/**\n * @internal\n */\nexport function successorStack>(\n stack: LinkedNode>,\n): LinkedNode> {\n const node = stack.value.to;\n if (node == null) {\n return stack;\n }\n stack = { next: stack, value: { label: 'right', from: node, to: node.right } };\n return leftmostStack(stack);\n}\n/**\n * Turn an array into a binary tree. Assumes elements are in level-order.\n *\n * @internal\n */\nexport function toBinaryTree(\n elements: (T | undefined)[] | undefined,\n): BinaryTreeNode | undefined {\n if (elements == null || elements.length < 1 || elements[0] == null) {\n return undefined;\n }\n const n = elements.length;\n const nodes: BinaryTreeNode[] = new Array(n);\n nodes[0] = { value: elements[0] };\n for (let i = 1; i < n; ++i) {\n if (elements[i] == null) {\n continue;\n }\n const par = nodes[(i - 1) >>> 1];\n const node = { value: elements[i]! };\n nodes[i] = node;\n if (i & 1) {\n par.left = node;\n } else {\n par.right = node;\n }\n }\n return nodes[0];\n}\n","import { isArray } from 'src/collection/arrayUtils';\nimport { BinaryTreeNode } from 'src/tree/binaryTreeNode';\nimport { clone, preOrderTraverse, toBinaryTree } from 'src/tree/binaryTreeUtils';\nimport { CompareFn } from '..';\nimport { BinaryHeap } from './binaryHeap';\nimport { Heap } from './heap';\nimport { skewMerge } from './utils';\n\n/**\n * A skew heap is a heap implemented as a binary tree\n * ([source](https://en.wikipedia.org/wiki/Skew_heap)).\n *\n * A skew heap is a self-adjusting heap which attempts to maintain balance\n * by unconditionally swapping all nodes in the merge path when merging two heaps. Every\n * operation that modifies the heap (e.g. push, pop, merge) is considered a merge and is done\n * by using a skew heap merge.\n *\n * Skew heaps can merge more quickly than binary heaps. This can seem contradictory, since\n * skew heaps have no structural constraints and no guarantee that the height of the tree is\n * logarithmic (i.e. balanced). However, amortized complexity analysis can demonstrate that\n * all operations on a skew heap can be done in O(log(n). More specifically, the\n * amortized complexity is known to be logφ(n) where φ is the golden ratio. This is\n * approximately 1.44*log2(n).\n *\n * #### Complexity\n *\n * | Property | Average | Worst |\n * | :------- | :------ | :---- |\n * | Space | O(n) | O(n)\n * | Push | O(log n) | O(log n)\n * | Peek | O(1)\t | O(1)\n * | Pop | O(log n) | O(log n)\n * | Search | O(n) | O(n)\n */\nexport class SkewHeap implements Heap {\n /**\n * The function to determine the order of elements.\n */\n protected compare: CompareFn;\n /**\n * The number of elements in the list.\n */\n protected length: number;\n /**\n * The node at the \"top\" of the heap.\n */\n protected root: BinaryTreeNode | undefined;\n /**\n * Instantiate a heap.\n *\n * @param compareFn - The function to determine the order of elements.\n * @param elements - A set of elements to initialize the heap with.\n */\n constructor(compareFn: CompareFn, elements?: Iterable) {\n this.compare = compareFn;\n this.length = 0;\n this.addAll(elements ?? []);\n }\n\n addAll(elements: Iterable): number {\n if (isArray(elements)) {\n for (let i = 0; i < elements.length; ++i) {\n this.push(elements[i]);\n }\n } else if (elements instanceof SkewHeap || elements instanceof BinaryHeap) {\n this.merge(elements);\n } else {\n for (const element of elements) {\n this.push(element);\n }\n }\n return this.length;\n }\n\n clear(): void {\n this.length = 0;\n this.root = undefined;\n }\n\n comparator(): CompareFn {\n return this.compare;\n }\n\n contains(element: T): boolean {\n for (const node of preOrderTraverse(this.root)) {\n if (element === node.value) {\n return true;\n }\n }\n return false;\n }\n\n delete(element: T): boolean {\n if (this.root == null) {\n return false;\n }\n if (this.root.value === element) {\n this.pop()!;\n return true;\n }\n for (const par of preOrderTraverse(this.root)) {\n const key: keyof BinaryTreeNode | undefined =\n par.left && par.left.value === element\n ? 'left'\n : par.right && par.right.value === element\n ? 'right'\n : undefined;\n if (key != null) {\n const node = par[key]!;\n par[key] = skewMerge(this.compare, [node.left, node.right]);\n --this.length;\n return true;\n }\n }\n return false;\n }\n\n merge(heap: Heap): this {\n if (this.compare !== heap.comparator()) {\n this.addAll(heap);\n } else if (heap instanceof SkewHeap) {\n this.root = skewMerge(this.compare, [this.root, clone(heap.root)]);\n this.length += heap.size;\n } else if (heap instanceof BinaryHeap) {\n this.root = skewMerge(this.compare, [this.root, toBinaryTree(heap['array'])!]);\n this.length += heap.size;\n } else {\n this.addAll(heap);\n }\n return this;\n }\n\n peek(): T | undefined {\n return this.root?.value;\n }\n\n pop(): T | undefined {\n if (this.root == null) {\n return undefined;\n }\n const value = this.root.value;\n this.root = skewMerge(this.compare, [this.root.left, this.root.right]);\n --this.length;\n return value;\n }\n\n push(value: T): number {\n this.root = skewMerge(this.compare, [this.root, { value }]);\n return ++this.length;\n }\n\n pushPop(value: T): T {\n this.push(value);\n return this.pop()!;\n }\n\n replace(value: T): T | undefined {\n if (this.root == null) {\n this.root = { value };\n this.length = 1;\n return undefined;\n }\n const out = this.root.value;\n this.root = skewMerge(this.compare, [this.root.left, this.root.right, { value }]);\n return out;\n }\n\n get size(): number {\n return this.length;\n }\n\n *sorted(): Iterable {\n if (this.root == null) {\n return;\n }\n const heap = new SkewHeap>(\n (a, b) => this.compare(a.value, b.value),\n [this.root],\n );\n do {\n const node = heap.pop()!;\n yield node.value;\n node.left && heap.push(node.left);\n node.right && heap.push(node.right);\n } while (heap.size > 0);\n }\n /**\n * Receive an iterator through the list.\n *\n * **Note:** Unexpected behavior can occur if the collection is modified during iteration.\n *\n * @returns An iterator through the list\n */\n *[Symbol.iterator](): Iterator {\n for (const node of preOrderTraverse(this.root)) {\n yield node.value;\n }\n }\n\n update(curElement: T, newElement: T): boolean {\n if (this.root == null) {\n return false;\n }\n\n if (this.root.value === curElement) {\n this.root = skewMerge(this.compare, [\n this.root.left,\n this.root.right,\n { value: newElement },\n ]);\n return true;\n }\n\n let node: BinaryTreeNode | undefined = undefined;\n for (const par of preOrderTraverse(this.root)) {\n if (par.left && par.left.value === curElement) {\n node = par.left;\n par.left = undefined;\n break;\n }\n if (par.right && par.right.value === curElement) {\n node = par.right;\n par.right = undefined;\n break;\n }\n }\n\n if (node == null) {\n return false;\n }\n\n this.root = skewMerge(this.compare, [\n this.root,\n node.left,\n node.right,\n { value: newElement },\n ]);\n return true;\n }\n}\n","import { splice } from 'src/collection/arrayUtils';\nimport { clamp, wrapLeft } from 'src/math/numberUtils';\nimport { CompareFn } from '..';\nimport { List } from './list';\n\n/**\n * An implementation of the {@link List} interface using an array\n */\nexport class ArrayList implements List {\n /**\n * The array containing every element.\n */\n protected array: Array;\n /**\n * Instantiate the list.\n *\n * @param elements - A set of elements to initialize the list with.\n */\n constructor(elements?: Iterable) {\n this.array = elements ? Array.from(elements) : [];\n }\n\n add(index: number, element: T): number {\n if (index >= 0 && index <= this.size) {\n this.array.splice(index, 0, element);\n }\n return this.size;\n }\n\n addAll(index: number, elements: Iterable): number {\n if (index >= 0 && index <= this.size) {\n splice(this.array, index, 0, elements);\n }\n return this.size;\n }\n\n clear(): void {\n this.array.length = 0;\n }\n\n concat(...lists: Iterable[]): ArrayList {\n const out = new ArrayList(this);\n for (const list of lists) {\n out.addAll(out.size, list);\n }\n return out;\n }\n\n copyWithin(index: number, min?: number, max?: number): this {\n index = clamp(wrapLeft(index, 0, this.size), 0, this.size);\n min = clamp(wrapLeft(min ?? 0, 0, this.size), 0, this.size);\n max = clamp(wrapLeft(max ?? this.size, 0, this.size), 0, this.size);\n this.array.copyWithin(index, min, max);\n return this;\n }\n\n fill(element: T, min?: number, max?: number): this {\n min = clamp(wrapLeft(min ?? 0, 0, this.size), 0, this.size);\n max = clamp(wrapLeft(max ?? this.size, 0, this.size), 0, this.size);\n this.array.fill(element, min, max);\n return this;\n }\n\n get(index: number): T | undefined {\n return index < 0 || index >= this.size ? undefined : this.array[index];\n }\n\n getSet(index: number, callback: (element: T) => T): T | undefined {\n let value: T | undefined = undefined;\n if (index >= 0 && index < this.size) {\n value = this.array[index];\n this.array[index] = callback(value);\n }\n return value;\n }\n\n pop(): T | undefined {\n return this.array.pop();\n }\n\n push(element: T): number {\n return this.array.push(element);\n }\n\n remove(index: number): T | undefined {\n return index < 0 || index >= this.size ? undefined : this.array.splice(index, 1)[0];\n }\n\n reverse(min?: number, max?: number): this {\n min = clamp(wrapLeft(min ?? 0, 0, this.size), 0, this.size);\n max = clamp(wrapLeft(max ?? this.size, 0, this.size), 0, this.size) - 1;\n while (min < max) {\n const temp = this.array[min];\n this.array[min++] = this.array[max];\n this.array[max--] = temp;\n }\n return this;\n }\n\n set(index: number, element: T): T | undefined {\n let prev: T | undefined = undefined;\n if (index >= 0 && index < this.size) {\n prev = this.array[index];\n this.array[index] = element;\n }\n return prev;\n }\n\n shift(): T | undefined {\n return this.array.shift();\n }\n\n get size(): number {\n return this.array.length;\n }\n\n slice(min?: number, max?: number): ArrayList {\n return new ArrayList(this.array.slice(min, max));\n }\n\n splice(start?: number, count?: number, elements?: Iterable): List {\n return new ArrayList(splice(this.array, start, count, elements));\n }\n\n sort(compareFn: CompareFn): this {\n this.array.sort(compareFn);\n return this;\n }\n /**\n * Receive an iterator through the list.\n *\n * **Note:** Unexpected behavior can occur if the collection is modified during iteration.\n *\n * @returns An iterator through the list\n */\n [Symbol.iterator](): Iterator {\n return this.array[Symbol.iterator]();\n }\n\n unshift(element: T): number {\n return this.array.unshift(element);\n }\n\n update(callback: (element: T, index: number) => T): this;\n update(min: number | undefined, callback: (element: T, index: number) => T): this;\n update(\n min: number | undefined,\n max: number | undefined,\n callback: (element: T, index: number) => T,\n ): this;\n update(\n min: number | undefined | ((element: T, index: number) => T),\n max?: number | ((element: T, index: number) => T),\n callback?: (element: T, index: number) => T,\n ): this {\n if (callback == null) {\n if (arguments.length < 2) {\n callback = min as (element: T, index: number) => T;\n min = undefined;\n } else {\n callback = max as (element: T, index: number) => T;\n max = undefined;\n }\n }\n min = clamp(wrapLeft((min as number) ?? 0, 0, this.size), 0, this.size);\n max = clamp(wrapLeft((max as number) ?? this.size, 0, this.size), 0, this.size);\n while (min < max) {\n this.array[min] = callback(this.array[min], min);\n ++min;\n }\n return this;\n }\n\n *view(min?: number, max?: number): Iterable {\n min = clamp(wrapLeft(min ?? 0, 0, this.size), 0, this.size);\n\n let len: () => number;\n if (max == null) {\n len = () => this.size;\n } else if (max >= 0) {\n len = () => Math.min(max, this.size);\n } else {\n len = () => this.size + max;\n }\n\n while (min < len()) {\n yield this.array[min++];\n }\n }\n}\n","import { CompareFn } from '..';\nimport { DoublyLinkedNode } from './doublyLinkedNode';\nimport { LinkedNode } from './linkedNode';\n\n/**\n * Sorts a list in place.\n *\n * Works on complete lists as well as sublists and circular lists:\n * - Linked lists will keep the link to the next node beyond the sorted section\n * - Doubly linked lists will keep links to the prev and next nodes outside the sorted section\n *\n * @param node - The head of the list\n * @param len - The length of the list beginning from node\n * @param isDoubly - Whether node is a doubly linked node\n * @param compareFn - A function used to determine the order of elements.\n *\n * It is expected to return:\n * - A negative value if first argument < second argument\n * - Zero if first argument == second argument\n * - A positive value if first argument > second argument\n *\n * @returns The new head and tail of the sorted list\n *\n * @internal\n */\nexport function linkedMergeSort>(\n node: Node,\n len: number,\n isDoubly: boolean,\n compareFn: CompareFn,\n): [Node, Node] {\n // Base case\n if (len < 2) {\n return [node, node];\n }\n\n // Split the list into two halves and sort them\n len = len / 2;\n const lens: [number, number] = [Math.ceil(len), Math.floor(len)];\n const heads = linkedMergeSort(node, lens[0], isDoubly, compareFn);\n const tails = linkedMergeSort(heads[1].next as Node, lens[1], isDoubly, compareFn);\n\n // Group the heads and tails together\n node = heads[1];\n heads[1] = tails[0];\n tails[0] = node;\n tails[0].next = tails[1].next;\n\n // Merge the sorted halves\n const prev = (heads[0] as DoublyLinkedNode).prev;\n node = linkedMergeSorted(heads, lens, isDoubly, compareFn);\n if (isDoubly) {\n (node as DoublyLinkedNode).prev = prev;\n }\n\n // Return the head and tail\n return [node, tails[+(lens[0] < 1)]];\n}\n/**\n * Merges two sorted lists.\n *\n * @param nodes - The heads of the lists\n * @param lens - The lengths of the lists\n * @param isDoubly - Whether the lists are a doubly linked\n * @param compareFn - A function used to determine the order of elements.\n *\n * It is expected to return:\n * - A negative value if first argument < second argument\n * - Zero if first argument == second argument\n * - A positive value if first argument > second argument\n *\n * @returns The new head of the sorted list\n *\n * @internal\n */\nexport function linkedMergeSorted>(\n heads: [Node, Node],\n lens: [number, number],\n isDoubly: boolean,\n compareFn: CompareFn,\n): Node {\n const root = {} as Node;\n\n let node = root;\n do {\n const index = +(compareFn(heads[0].value, heads[1].value) > 0);\n node.next = heads[index];\n if (isDoubly) {\n (node.next as DoublyLinkedNode).prev = node;\n }\n node = node.next as Node;\n heads[index] = node.next as Node;\n --lens[index];\n } while (lens[0] > 0 && lens[1] > 0);\n\n // Add any remaining nodes\n node.next = heads[+(lens[0] < 1)];\n if (isDoubly && node.next) {\n (node.next as DoublyLinkedNode).prev = node;\n }\n return root.next as Node;\n}\n","import { clamp, wrapLeft } from 'src/math/numberUtils';\nimport { CompareFn } from '..';\nimport { DoublyLinkedNode } from './doublyLinkedNode';\nimport { List } from './list';\nimport { linkedMergeSort } from './utils';\n\n/**\n * A (circular) doubly-linked list implementation of the {@link List} interface.\n *\n * Operations that index into the list will traverse the list from the beginning or the end, whichever is closer to the specified index.\n */\nexport class DoublyLinkedList implements List {\n /**\n * The number of elements in the list\n */\n protected length: number;\n /**\n * The sentinel node at the fron of the list\n */\n protected root: DoublyLinkedNode;\n /**\n * Instantiate the list.\n *\n * @param elements - A set of elements to initialize the list with.\n */\n constructor(elements?: Iterable) {\n this.length = 0;\n this.root = {} as DoublyLinkedNode;\n this.root.prev = this.root.next = this.root;\n this._addAll(this.root, elements ?? []);\n }\n\n add(index: number, value: T): number {\n if (index < 0 || index > this.length) {\n return this.length;\n }\n const prev = this._get(index - 1);\n const node = { next: prev.next, prev, value };\n prev.next = node;\n node.next!.prev = node;\n return ++this.length;\n }\n\n addAll(index: number, elements: Iterable): number {\n if (index >= 0 && index <= this.length) {\n this._addAll(this._get(index), elements);\n }\n return this.length;\n }\n\n clear(): void {\n this.length = 0;\n this.root.prev = this.root.next = this.root;\n }\n\n concat(...lists: Iterable[]): DoublyLinkedList {\n const out = new DoublyLinkedList(this);\n for (const list of lists) {\n out.addAll(out.size, list);\n }\n return out;\n }\n\n copyWithin(index: number, min?: number, max?: number): this {\n // Check if copying to the same section\n index = clamp(wrapLeft(index, 0, this.length), 0, this.length);\n min = clamp(wrapLeft(min ?? 0, 0, this.length), 0, this.length);\n if (min === index) {\n return this;\n }\n\n // Check if the section to copy has no length\n max = clamp(wrapLeft(max ?? this.length, 0, this.length), 0, this.length);\n max = min + Math.min(max - min, this.length - index);\n if (min >= max) {\n return this;\n }\n\n // Check for overlap edge case\n if (min < index && index < max) {\n let nodeA = this._get(max);\n let nodeB = this._get(index + (max - min));\n do {\n nodeA = nodeA.prev!;\n nodeB = nodeB.prev!;\n nodeB.value = nodeA.value;\n } while (++min < max);\n return this;\n }\n\n // Copy the section to the destination\n let nodeA = this._get(min);\n let nodeB = this._get(index);\n do {\n nodeB.value = nodeA.value;\n nodeA = nodeA.next!;\n nodeB = nodeB.next!;\n } while (++min < max);\n return this;\n }\n\n fill(element: T, min?: number, max?: number): this {\n min = clamp(wrapLeft(min ?? 0, 0, this.length), 0, this.length);\n max = clamp(wrapLeft(max ?? this.length, 0, this.length), 0, this.length);\n if (min < max) {\n let node = this._get(min);\n do {\n node.value = element;\n node = node.next!;\n } while (++min < max);\n }\n return this;\n }\n\n get(index: number): T | undefined {\n return index < 0 || index >= this.length ? undefined : this._get(index).value;\n }\n\n getSet(index: number, callback: (element: T) => T): T | undefined {\n if (index < 0 || index >= this.length) {\n return undefined;\n }\n const node = this._get(index);\n const value = node.value;\n node.value = callback(node.value);\n return value;\n }\n\n pop(): T | undefined {\n if (this.length < 1) {\n return undefined;\n }\n const tail = this.root.prev!;\n tail.prev!.next = this.root;\n this.root.prev = tail.prev;\n --this.length;\n return tail.value;\n }\n\n push(value: T): number {\n const prev = this.root.prev!;\n const node = { next: this.root, prev, value };\n prev.next = this.root.prev = node;\n return ++this.length;\n }\n\n remove(index: number): T | undefined {\n if (index < 0 || index >= this.length) {\n return undefined;\n }\n const node = this._get(index);\n node.prev!.next = node.next;\n node.next!.prev = node.prev;\n --this.length;\n return node.value;\n }\n\n reverse(min?: number, max?: number): this {\n min = clamp(wrapLeft(min ?? 0, 0, this.length), 0, this.length);\n max = clamp(wrapLeft(max ?? this.length, 0, this.length), 0, this.length);\n if (max - min < 2) {\n return this;\n }\n const root = this._get(min - 1);\n const tail = root.next!;\n let node = tail;\n do {\n const temp = node.next!;\n node.next = node.prev;\n node.prev = temp;\n root.next = node;\n node = temp;\n } while (++min < max);\n tail.next = node;\n node.prev = tail;\n root.next!.prev = root;\n return this;\n }\n\n set(index: number, element: T): T | undefined {\n if (index < 0 || index >= this.length) {\n return undefined;\n }\n const node = this._get(index);\n const value = node.value;\n node.value = element;\n return value;\n }\n\n shift(): T | undefined {\n if (this.length < 1) {\n return undefined;\n }\n const head = this.root.next!;\n head.next!.prev = this.root;\n this.root.next = head.next;\n --this.length;\n return head.value;\n }\n\n get size(): number {\n return this.length;\n }\n\n slice(min?: number, max?: number): DoublyLinkedList {\n return new DoublyLinkedList(this.view(min, max));\n }\n\n splice(start?: number, count?: number, elements?: Iterable): List {\n start = clamp(wrapLeft(start ?? 0, 0, this.length), 0, this.length);\n count = clamp(count ?? this.size, 0, this.size - start);\n\n // If not modifying the list\n const list = new DoublyLinkedList();\n if (elements == null && count < 1) {\n return list;\n }\n\n // Delete elements\n let node = this._get(start);\n while (count-- > 0) {\n list.push(node.value);\n node.prev!.next = node.next!;\n node.next!.prev = node.prev!;\n node = node.next!;\n --this.length;\n }\n\n // Add elements\n this._addAll(node, elements ?? []);\n\n return list;\n }\n\n sort(compareFn: CompareFn): this {\n if (this.length > 1) {\n const [head, tail] = linkedMergeSort(this.root.next!, this.length, true, compareFn);\n this.root.next = head;\n tail.next!.prev = tail;\n }\n return this;\n }\n /**\n * Receive an iterator through the list.\n *\n * **Note:** Unexpected behavior can occur if the collection is modified during iteration.\n *\n * @returns An iterator through the list\n */\n *[Symbol.iterator](): Iterator {\n for (let node = this.root.next!; node !== this.root; node = node.next!) {\n yield node.value;\n }\n }\n\n unshift(value: T): number {\n const head = this.root.next!;\n const node = { next: head, prev: this.root, value };\n this.root.next = head.prev = node;\n return ++this.length;\n }\n\n update(callback: (element: T, index: number) => T): this;\n update(min: number | undefined, callback: (element: T, index: number) => T): this;\n update(\n min: number | undefined,\n max: number | undefined,\n callback: (element: T, index: number) => T,\n ): this;\n update(\n min: number | undefined | ((element: T, index: number) => T),\n max?: number | ((element: T, index: number) => T),\n callback?: (element: T, index: number) => T,\n ): this {\n if (callback == null) {\n if (arguments.length < 2) {\n callback = min as (element: T, index: number) => T;\n min = undefined;\n } else {\n callback = max as (element: T, index: number) => T;\n max = undefined;\n }\n }\n min = clamp(wrapLeft((min as number) ?? 0, 0, this.length), 0, this.length);\n max = clamp(wrapLeft((max as number) ?? this.length, 0, this.length), 0, this.length);\n if (min < max) {\n let node = this._get(min);\n do {\n node.value = callback(node.value, min);\n node = node.next!;\n } while (++min < max);\n }\n return this;\n }\n\n *view(min?: number, max?: number): Iterable {\n min = clamp(wrapLeft(min ?? 0, 0, this.length), 0, this.length);\n\n let len: () => number;\n if (max == null) {\n len = () => this.length;\n } else if (max >= 0) {\n len = () => max;\n } else {\n len = () => this.length + max;\n }\n\n if (min < len()) {\n let node = this._get(min);\n do {\n yield node.value;\n node = node.next!;\n } while (++min < len() && node !== this.root);\n }\n }\n /**\n *\n */\n protected _addAll(next: DoublyLinkedNode, elements: Iterable): void {\n let prev = next.prev!;\n for (const value of elements) {\n const node = { prev, value };\n prev.next = node;\n prev = node;\n ++this.length;\n }\n prev.next = next;\n next.prev = prev;\n }\n /**\n * A helper method to iterate and return the node at the given index.\n *\n * Depending on the index, the list will be traversed from beginning or end; whichever is closest to the specified index.\n *\n * @param index - The index to retrieve\n *\n * @returns The node at the given index\n */\n protected _get(index: number): DoublyLinkedNode {\n let node = this.root;\n if (index < this.length / 2) {\n while (index-- >= 0) {\n node = node.next!;\n }\n } else {\n for (index = this.length - index; index > 0; --index) {\n node = node.prev!;\n }\n }\n return node;\n }\n}\n","import { clamp, wrapLeft } from 'src/math/numberUtils';\nimport { CompareFn } from '..';\nimport { LinkedNode } from './linkedNode';\nimport { List } from './list';\nimport { linkedMergeSort } from './utils';\n\n/**\n * A (circular) linked list implementation of the {@link List} interface.\n */\nexport class LinkedList implements List {\n /**\n * The number of elements in the list.\n */\n protected length: number;\n /**\n * The sentinel node at the front of the list.\n */\n protected root: LinkedNode;\n /**\n * The last node of the list.\n */\n protected tail: LinkedNode;\n /**\n * Instantiate the list.\n *\n * @param elements - A set of elements to initialize the list with.\n */\n constructor(elements?: Iterable) {\n this.length = 0;\n this.root = {} as LinkedNode;\n this.root.next = this.root;\n this.tail = this._addAll(this.root, elements ?? []);\n }\n\n add(index: number, value: T): number {\n if (index >= 0 && index < this.length) {\n const prev = this._get(index - 1);\n prev.next = { value, next: prev.next };\n ++this.length;\n } else if (index === this.length) {\n this.push(value);\n }\n return this.length;\n }\n\n addAll(index: number, elements: Iterable): number {\n if (index >= 0 && index < this.length) {\n this._addAll(this._get(index - 1), elements);\n } else if (index === this.length) {\n this.tail = this._addAll(this.tail, elements);\n }\n return this.length;\n }\n\n clear(): void {\n this.length = 0;\n this.tail = this.root.next = this.root;\n }\n\n concat(...lists: Iterable[]): LinkedList {\n const out = new LinkedList(this);\n for (const list of lists) {\n out.addAll(out.size, list);\n }\n return out;\n }\n\n copyWithin(index: number, min?: number, max?: number): this {\n // Check if copying to itself\n index = clamp(wrapLeft(index, 0, this.length), 0, this.length);\n min = clamp(wrapLeft(min ?? 0, 0, this.length), 0, this.length);\n if (min === index) {\n return this;\n }\n\n // Check if the section to copy has no length\n max = clamp(wrapLeft(max ?? this.length, 0, this.length), 0, this.length);\n max = min + Math.min(max - min, this.length - index);\n if (min >= max) {\n return this;\n }\n\n // Copy to earlier in the list\n if (index < min) {\n const node = this._get(index - 1);\n this._copyWithin(this._get(min - index - 1, node), node, max - min);\n return this;\n }\n\n // Copy to later in the list\n if (index > max) {\n const node = this._get(min - 1);\n this._copyWithin(node, this._get(index - min - 1, node), max - min);\n return this;\n }\n\n // Copy to overlapping destination\n const nodeA = this._get(min - 1);\n const nodeC = this._get(max - min - 1, nodeA);\n const nodeD = this._copyWithin(nodeA, nodeC, index - min);\n if (index + (max - min) >= this.length) {\n this.tail = nodeC;\n }\n const temp = nodeA.next;\n nodeA.next = nodeC.next;\n nodeC.next = nodeD.next;\n nodeD.next = temp;\n return this;\n }\n\n fill(element: T, min?: number, max?: number): this {\n min = clamp(wrapLeft(min ?? 0, 0, this.length), 0, this.length);\n max = clamp(wrapLeft(max ?? this.length, 0, this.length), 0, this.length);\n if (min < max) {\n let node = this._get(min);\n do {\n node.value = element;\n node = node.next!;\n } while (++min < max);\n }\n return this;\n }\n\n get(index: number): T | undefined {\n if (index < 0 || index >= this.length) {\n return undefined;\n }\n return index < this.length - 1 ? this._get(index).value : this.tail.value;\n }\n\n getSet(index: number, callback: (element: T) => T): T | undefined {\n if (index < 0 || index >= this.length) {\n return undefined;\n }\n const node = index < this.length - 1 ? this._get(index) : this.tail;\n const value = node.value;\n node.value = callback(node.value);\n return value;\n }\n\n pop(): T | undefined {\n if (this.length < 1) {\n return undefined;\n }\n const value = this.tail.value;\n this.tail = this._get(this.length - 2);\n this.tail.next = this.root;\n --this.length;\n return value;\n }\n\n push(value: T): number {\n const tail: LinkedNode = { next: this.root, value };\n this.tail.next = tail;\n this.tail = tail;\n return ++this.length;\n }\n\n remove(index: number): T | undefined {\n if (index < 0 || index >= this.length) {\n return undefined;\n }\n const prev = this._get(index - 1);\n const node = prev.next!;\n prev.next = node.next;\n if (index === --this.length) {\n this.tail = prev;\n }\n return node.value;\n }\n\n reverse(min?: number, max?: number): this {\n min = clamp(wrapLeft(min ?? 0, 0, this.length), 0, this.length);\n max = clamp(wrapLeft(max ?? this.length, 0, this.length), 0, this.length);\n if (max - min < 2) {\n return this;\n }\n const root = this._get(min - 1);\n this.tail = max >= this.length ? root.next! : this.tail;\n const tail = root.next!;\n let prev = tail;\n let node = tail.next!;\n while (++min < max) {\n const next = node.next!;\n node.next = prev;\n prev = node;\n node = next;\n }\n root.next = prev;\n tail.next = node;\n return this;\n }\n\n set(index: number, element: T): T | undefined {\n if (index < 0 || index >= this.length) {\n return undefined;\n }\n const node = this._get(index);\n const value = node.value;\n node.value = element;\n return value;\n }\n\n shift(): T | undefined {\n return this.remove(0);\n }\n\n get size(): number {\n return this.length;\n }\n\n slice(min?: number, max?: number): LinkedList {\n return new LinkedList(this.view(min, max));\n }\n\n splice(start?: number, count?: number, elements?: Iterable): List {\n start = clamp(wrapLeft(start ?? 0, 0, this.length), 0, this.length);\n count = clamp(count ?? this.size, 0, this.size - start);\n\n // If not modifying the list\n const deleted = new LinkedList();\n if (elements == null && count < 1) {\n return deleted;\n }\n\n // Delete elements\n let prev = this._get(start - 1);\n const newTail = start + count >= this.size;\n while (count-- > 0) {\n const node = prev.next!;\n deleted.push(node.value);\n prev.next = node.next;\n --this.length;\n }\n\n // Add elements\n prev = this._addAll(prev, elements ?? []);\n this.tail = newTail ? prev : this.tail;\n\n return deleted;\n }\n\n sort(compareFn: CompareFn): this {\n if (this.length > 1) {\n const [head, tail] = linkedMergeSort(this.root.next!, this.length, false, compareFn);\n this.root.next = head;\n this.tail = tail;\n }\n return this;\n }\n /**\n * Receive an iterator through the list.\n *\n * **Note:** Unexpected behavior can occur if the collection is modified during iteration.\n *\n * @returns An iterator through the list\n */\n *[Symbol.iterator](): Iterator {\n for (let node = this.root.next!; node !== this.root; node = node.next!) {\n yield node.value;\n }\n }\n\n unshift(value: T): number {\n return this.add(0, value);\n }\n\n update(callback: (element: T, index: number) => T): this;\n update(min: number | undefined, callback: (element: T, index: number) => T): this;\n update(\n min: number | undefined,\n max: number | undefined,\n callback: (element: T, index: number) => T,\n ): this;\n update(\n min: number | undefined | ((element: T, index: number) => T),\n max?: number | ((element: T, index: number) => T),\n callback?: (element: T, index: number) => T,\n ): this {\n if (callback == null) {\n if (arguments.length < 2) {\n callback = min as (element: T, index: number) => T;\n min = undefined;\n } else {\n callback = max as (element: T, index: number) => T;\n max = undefined;\n }\n }\n min = clamp(wrapLeft((min as number) ?? 0, 0, this.length), 0, this.length);\n max = clamp(wrapLeft((max as number) ?? this.length, 0, this.length), 0, this.length);\n if (min < max) {\n let node = this._get(min);\n do {\n node.value = callback(node.value, min);\n node = node.next!;\n } while (++min < max);\n }\n return this;\n }\n\n *view(min?: number, max?: number): Iterable {\n min = clamp(wrapLeft(min ?? 0, 0, this.length), 0, this.length);\n\n let len: () => number;\n if (max == null) {\n len = () => this.length;\n } else if (max >= 0) {\n len = () => max;\n } else {\n len = () => this.length + max;\n }\n\n if (min < len()) {\n let node = this._get(min);\n do {\n yield node.value;\n node = node.next!;\n } while (++min < len() && node !== this.root);\n }\n }\n\n protected _addAll(prev: LinkedNode, elements: Iterable): LinkedNode {\n const next = prev.next!;\n for (const value of elements) {\n const node = { value };\n prev.next = node;\n prev = node;\n ++this.length;\n }\n prev.next = next;\n return prev;\n }\n /**\n * Copy values from 'from' to 'to'.\n *\n * @param from - The initial node to copy from\n * @param prev - The root of the initial node to copy to\n * @param count - The number of values to copy\n */\n protected _copyWithin(from: LinkedNode, to: LinkedNode, count: number): LinkedNode {\n while (count-- > 0) {\n from = from.next!;\n to = to.next!;\n to.value = from.value;\n }\n return to;\n }\n /**\n * Get the node at the given index.\n *\n * @param index - The index to retrieve\n *\n * @returns The node at the given index\n */\n protected _get(index: number, root: LinkedNode = this.root): LinkedNode {\n let node = root!;\n while (index-- >= 0) {\n node = node.next!;\n }\n return node;\n }\n}\n","/**\n * Bit hacks for 32-bit unsigned numbers.\n */\n\n/**\n * Get the number of bits set of a 32-bit unsigned number ([source](https://graphics.stanford.edu/~seander/bithacks.html#CountBitsSetKernighan))\n *\n * @param a\n */\nexport function bitsSet(a: number): number {\n let b = 0;\n while (a) {\n ++b;\n a &= a - 1;\n }\n return b;\n}\n/**\n * Invert the bits of a 32-bit unsigned number.\n *\n * Example: 11 (1011) -> 4 (0100)\n *\n * @param a The number to invert\n *\n * @returns The inverted number\n */\nexport function invert(a: number): number {\n const b = msp(a);\n return u32(a ^ (b | (b - 1)));\n}\n/**\n * Check whether a 32-bit unsigned number is a power of 2.\n *\n * Example: 8 (1000) -> true\n *\n * @param a The number to check\n */\nexport function isPow2(a: number): boolean {\n return (a & (a - 1)) === 0;\n}\n/**\n * Get the Least Significant Bit of a 32-bit unsigned number\n *\n * @param a\n *\n * @returns The lowest bit set\n */\nexport function lsb(a: number): number {\n let b = -1;\n for (a = lsp(a); a; a >>>= 1) {\n ++b;\n }\n return b;\n}\n/**\n * Get the Least Significant Power of a 32-bit unsigned number\n *\n * @param a\n *\n * @returns 2**lsb(a)\n */\nexport function lsp(a: number): number {\n return u32(a & -a);\n}\n/**\n * Get the Least Significant Power Set of a 32-bit unsigned number.\n *\n * Example: 54 (110110) -> 6 (000110)\n *\n * @param a\n */\nexport function lsps(a: number): number {\n return u32(a & (lsp(a + lsp(a)) - 1));\n}\n/**\n * Get the Most Significant Power of the Least Significant Power Set of a 32-bit unsigned number.\n *\n * Example: 54 (110110) -> 4 (000100)\n *\n * @param a\n */ /*\nexport function mlsp(a: number): number {\n return (lsp(a + lsp(a)) >>> 1) || u32(0x80000000 & a);\n}\n*/\n/**\n * Get the Most Significant Bit of a 32-bit unsigned number\n *\n * @param a\n *\n * @returns ⌊log2(a)⌋ : the highest bit set\n */\nexport function msb(a: number): number {\n let b = -1;\n while (a !== 0) {\n ++b;\n a >>>= 1;\n }\n return b;\n}\n/**\n * Get the Most Significant Power of a 32-bit unsigned number\n *\n * @param a\n *\n * @returns 2**msb(a)\n */\nexport function msp(a: number): number {\n let b = a & -a;\n while (a != b) {\n a ^= b;\n b = a & -a;\n }\n return u32(b);\n}\n/**\n * Get the Most Significant Power Set of a 32-bit unsigned number.\n *\n * Example: 50 (110010) -> 48 (110000)\n *\n * @param a\n */\nexport function msps(a: number): number {\n let b = a & -a;\n while (a & (a + b)) {\n a ^= b;\n b = a & -a;\n }\n return u32(a);\n}\n/**\n * Reverse a 32-bit unsigned number.\n *\n * Example: 50 (110010) -> 19 (010011)\n *\n * @param a\n */\nexport function reverse(a: number): number {\n a = ((a & 0xaaaaaaaa) >>> 1) | ((a & 0x55555555) << 1);\n a = ((a & 0xcccccccc) >>> 2) | ((a & 0x33333333) << 2);\n a = ((a & 0xf0f0f0f0) >>> 4) | ((a & 0x0f0f0f0f) << 4);\n a = ((a & 0xff00ff00) >>> 8) | ((a & 0x00ff00ff) << 8);\n return u32((a >>> 16) | (a << 16));\n}\n/**\n * Turn a number into an unsigned 32-bit number\n *\n * @param a\n */\nexport function u32(a: number): number {\n return a >>> 0;\n}\n","import { Queue } from './queue';\n\n/**\n * An implementation of the {@link Queue} interface using an array\n */\nexport class ArrayQueue implements Queue {\n /**\n * The array containing every element.\n */\n protected array: T[];\n /**\n * Instantiate the queue.\n *\n * @param elements - A set of elements to initialize the queue with.\n */\n constructor(elements?: Iterable) {\n this.array = elements ? Array.from(elements) : [];\n }\n\n clear(): void {\n this.array.length = 0;\n }\n\n dequeue(): T | undefined {\n return this.size < 1 ? undefined : this.array.shift();\n }\n\n enqueue(element: T): number {\n return this.array.push(element);\n }\n\n peek(): T | undefined {\n return this.size < 1 ? undefined : this.array[0];\n }\n\n get size(): number {\n return this.array.length;\n }\n /**\n * Receive an iterator through the queue.\n *\n * **Note:** Unexpected behavior can occur if the collection is modified during iteration.\n *\n * @returns An iterator through the queue\n */\n [Symbol.iterator](): Iterator {\n return this.array[Symbol.iterator]();\n }\n}\n","import { LinkedList, List } from '../list';\nimport { Queue } from './queue';\n\n/**\n * A linked list implementation of the {@link Queue} interface\n */\nexport class LinkedQueue implements Queue {\n /**\n * The list containing every element.\n */\n protected list: List;\n /**\n * Instantiate the queue.\n *\n * @param elements - A set of elements to initialize the queue with.\n */\n constructor(elements?: Iterable) {\n this.list = new LinkedList(elements);\n }\n\n clear(): void {\n this.list.clear();\n }\n\n dequeue(): T | undefined {\n return this.list.shift();\n }\n\n enqueue(element: T): number {\n return this.list.push(element);\n }\n\n peek(): T | undefined {\n return this.list.get(0);\n }\n\n get size(): number {\n return this.list.size;\n }\n /**\n * Receive an iterator through the queue.\n *\n * **Note:** Unexpected behavior can occur if the collection is modified during iteration.\n *\n * @returns An iterator through the queue\n */\n [Symbol.iterator](): Iterator {\n return this.list[Symbol.iterator]();\n }\n}\n","import { lsb, lsp, msb, msp } from '../math/u32';\nimport { CombineFn } from '..';\nimport { MAX_ARRAY_LENGTH } from 'src/collection/arrayUtils';\nimport { SegmentTree } from './segmentTree';\n\n/*\n mca(a, b) = lsp(a | msp(b - a)) ; // where a <= b\n left(i) = i - (lsp(i + 1) >>> 1)\n right(i) = i + (lsp(i + 1) >>> 1)\n parent(i) =\n offset = lsp(i + 1)\n i + offset - ((i & 2*offset) >>> 0)\n*/\n\n/**\n * A {@link SegmentTree} with entries stored in in-order traversal.\n * Inspired by [Tristan Hume's IForestIndex](https://thume.ca/2021/03/14/iforests) ([github](https://github.com/trishume/gigatrace))\n */\nexport class InOrderSegmentTree implements SegmentTree {\n /**\n * The maximum amount of elements that can be added.\n *\n * n elements require 2n memory.\n */\n static readonly MAX_SIZE: number = MAX_ARRAY_LENGTH >>> 1;\n /**\n * The set of elements and aggregation nodes for the tree\n */\n protected array: T[];\n /**\n * The function used to aggregate elements\n */\n protected combine: CombineFn;\n /**\n * Construct a new segment tree\n *\n * @param combine - The function used to aggregate segment information\n * @param elements - A set of elements to add into the initial tree\n */\n constructor(combine: CombineFn, elements: Iterable = []) {\n this.array = [];\n this.combine = combine;\n this.build(elements);\n }\n\n clear(): void {\n this.array.length = 0;\n }\n\n pop(): T | undefined {\n // Sanitize range\n if (this.size < 1) {\n return undefined;\n }\n\n // Un-complete aggregation nodes\n const i = this.array.length - 1;\n for (let mask = 2; i & mask; mask *= 2) {\n this.array[i - mask] = this.array[i - mask - (mask >>> 1)];\n }\n\n // Return element\n const out = this.array[i - 1];\n this.array.length -= 2;\n return out;\n }\n\n push(element: T): number {\n // Sanitize range\n if (this.size >= InOrderSegmentTree.MAX_SIZE) {\n throw new RangeError(`Invalid length`);\n }\n\n // Add element\n const i = this.array.length;\n this.array[i + 1] = this.set(i, element);\n\n return this.size;\n }\n\n query(min: number, max: number): T {\n // Sanitize range\n if (min >= max) {\n throw new RangeError(`Range [${min}..${max}) is empty`);\n }\n if (min < 0 || max > this.size) {\n throw new RangeError(`Range [${min}..${max}) not in [0..${this.size})`);\n }\n\n // Translate range to interior indices\n min *= 2;\n max *= 2;\n\n // Jump to min's highest aggregation node that is fully within the range\n let offset = lsp(min | msp(max - min));\n let value = this.array[min - 1 + (offset >>> 1)];\n\n // Continue jumping aggregation nodes until max is reached\n for (min += offset; min < max; min += offset) {\n offset = lsp(min | msp(max - min));\n value = this.combine(value, this.array[min - 1 + (offset >>> 1)]);\n }\n\n return value;\n }\n\n get size(): number {\n return this.array.length >>> 1;\n }\n\n /**\n * Return an iterator through the tree's elements\n */\n *[Symbol.iterator](): Iterator {\n for (let i = 0; i < this.array.length; i += 2) {\n yield this.array[i];\n }\n }\n\n update(min: number, max: number, operation: (element: T, index: number) => T): void {\n // Sanitize range\n if (min >= max) {\n return;\n }\n if (min < 0 || max > this.size) {\n throw new RangeError(`Range [${min}..${max}) not in [0..${this.size})`);\n }\n\n // Translate range to interior indices\n min *= 2;\n max *= 2;\n\n // Update the values\n let value: T;\n do {\n value = this.set(min, operation(this.array[min], min >>> 1));\n min += 2;\n } while (min < max);\n\n // Update remaining aggregation nodes\n let dc = 0;\n let dp = lsp(min);\n max = msb(min ^ this.array.length) - lsb(min);\n for (--min; max > 0; --max) {\n value = this.combine(value, this.array[min + (dp >>> 1) - dc]);\n this.array[min] = value;\n dc = (min & (2 * dp)) >>> 0;\n min += dp - dc;\n dp *= 2;\n }\n\n // Update the incomplete aggregation node\n this.array[min] = value;\n }\n /**\n * A helper method used to build the tree\n *\n * @param elements The initial set of elements to add into the tree\n */\n protected build(elements: Iterable) {\n for (const element of elements) {\n this.push(element);\n }\n }\n /**\n * A helper method to update complete aggregation nodes for an index\n */\n protected set(index: number, element: T): T {\n // Set the index\n this.array[index++] = element;\n\n // Update complete aggregation nodes, from lowest to highest\n for (let mask = 2; index & mask; mask *= 2) {\n element = this.combine(this.array[index - mask - (mask >>> 1)], element);\n this.array[index - mask] = element;\n }\n\n return element;\n }\n}\n","/**\n * Thanks to [Douglas Wilhelm Harder](https://ece.uwaterloo.ca/~dwharder/aads/Algorithms/Array_resizing/)\n * for their analysis on array resizing\n */\nimport { isArray, MAX_ARRAY_LENGTH } from 'src/collection/arrayUtils';\nimport { isCollection } from 'src/collection';\nimport { Collection } from 'src/collection/collection';\nimport { CombineFn } from '..';\nimport { isPow2, lsp, msp } from '../math/u32';\nimport { SegmentTree } from './segmentTree';\n\n/**\n * A {@link SegmentTree} with entries stored in level-order traversal.\n * Memory usage: n elements require between 2n-1 to 4(n-1)-1 entries\n *\n */\nexport class LevelOrderSegmentTree implements SegmentTree {\n /**\n * The maximum number of elements that can be added.\n *\n * n elements require 2^⌈log2(2n)⌉ - 1 memory:\n */\n static readonly MAX_SIZE: number = (MAX_ARRAY_LENGTH + 1) / 2;\n /**\n * The internal array used to store elements and aggregation nodes\n */\n protected array: Array;\n /**\n * The function used to aggregate elements\n */\n protected combine: CombineFn;\n /**\n * The used length (size) of our internal array\n */\n protected length: number;\n /**\n * The start index for the lowest level\n */\n protected level: number;\n /**\n * Construct a new {@link SegmentTree}\n *\n * @param combinFn - The function used to aggregate elements\n * @param elements - Initial elements to build into the tree\n */\n constructor(combine: CombineFn, elements: Iterable = []) {\n this.array = [];\n this.combine = combine;\n this.length = 0;\n this.level = 0;\n this.build(elements);\n }\n\n clear(): void {\n this.length = 0;\n this.level = 0;\n this.array.length = 0;\n }\n\n pop(): T | undefined {\n // Sanitize range\n if (this.length <= this.level) {\n return undefined;\n }\n\n // Remove element\n const out = this.array[--this.length];\n\n // If level is <= 1/4 full\n if (this.length <= (this.array.length + 1) >>> 2) {\n this.shrink();\n }\n\n return out;\n }\n\n push(element: T): number {\n // If array is full\n if (this.length >= this.array.length) {\n this.grow();\n }\n\n // Add the new element\n this.array[this.length++] = element;\n\n // Update aggregation nodes\n for (let i = this.length; i & 1; this.array[i - 1] = element) {\n element = this.combine(this.array[i - 2], element);\n i >>>= 1;\n }\n\n return this.size;\n }\n\n query(min: number, max: number): T {\n // Sanitize range\n if (min >= max) {\n throw new RangeError(`Range [${min}..${max}) is empty`);\n }\n if (min < 0 || max > this.size) {\n throw new RangeError(`Range [${min}..${max}) not in [0..${this.size})`);\n }\n\n // Translate range to interior indices and align with powers of 2\n min += this.level + 1;\n max += this.level + 1;\n\n // Take the longest possible jump from min\n let offset = lsp(min | msp(max - min));\n let value: T = this.array[min / offset - 1];\n min += offset;\n\n // Continue jumping until max\n while (min < max) {\n offset = lsp(min | msp(max - min));\n value = this.combine(value, this.array[min / offset - 1]);\n min += offset;\n }\n\n return value;\n }\n\n get size(): number {\n return this.length - this.level;\n }\n\n /**\n * Return an iterator through the elements\n */\n *[Symbol.iterator](): Iterator {\n for (let i = 0; i < this.size; ++i) {\n yield this.array[this.level + i];\n }\n }\n\n update(min: number, max: number, operation: (element: T, index: number) => T): void {\n // Sanitize range\n if (min >= max) {\n return;\n }\n if (min < 0 || max > this.size) {\n throw new RangeError(`Range [${min}..${max}) not in [0..${this.size})`);\n }\n\n // Translate range to interior indices\n min += this.level;\n max += this.level;\n\n // Update the range\n for (let i = min; i < max; ++i) {\n this.array[i] = operation(this.array[i], i - this.level);\n }\n\n // Update the range's aggregation nodes\n this.aggregate(min, max);\n }\n /**\n * A helper method to aggregate a range of elements\n */\n protected aggregate(min: number, max: number): void {\n // Align indices with powers of 2\n ++min;\n ++max;\n\n // Aggregate elements\n for (let cap = this.length + 1; min < max; cap >>>= 1) {\n max += max & ((max - cap) >>> 31);\n for (let i = (min | 1) >>> 0; i < max; i += 2) {\n this.array[(i >>> 1) - 1] = this.combine(this.array[i - 2], this.array[i - 1]);\n }\n min >>>= 1;\n max >>>= 1;\n }\n }\n /**\n * A helper method used to build the tree\n *\n * @param elements The initial set of elements to add into the tree\n */\n protected build(elements: Collection | Iterable): void {\n let key: string | undefined = undefined;\n\n // Check if the iterable's size can be known.\n if (isArray(elements)) {\n key = 'length';\n } else if (isCollection(elements)) {\n key = 'size';\n } else {\n for (const element of elements) {\n this.push(element);\n }\n return;\n }\n\n // Get the iterable's size\n const n: number = (elements as any)[key];\n\n // Check for base case\n if (n < 1) {\n this.array.length = 0;\n this.length = 0;\n this.level = 0;\n return;\n }\n\n // Check if max capacity reached\n if (n >= LevelOrderSegmentTree.MAX_SIZE) {\n throw new RangeError('Invalid length');\n }\n\n // Allocate the array\n this.level = 2 * msp(n - 1) - 1;\n this.length = this.level;\n this.array.length = 2 * this.level + 1;\n\n // Add the elements\n for (const element of elements) {\n this.array[this.length++] = element;\n }\n\n // Update aggregation nodes\n this.aggregate(this.level, this.length);\n }\n /**\n * Shift the tree down a level\n */\n protected grow(): void {\n // Check base case\n if (this.size < 1) {\n this.array.length = 1;\n return;\n }\n\n // Check if max capacity reached\n if (this.size >= LevelOrderSegmentTree.MAX_SIZE) {\n throw new RangeError('Invalid length');\n }\n\n // Extend capacity\n this.array.length += this.array.length + 1;\n\n // Shift the tree down a level\n let min = this.level + 1;\n for (let max = this.length + 1; min < max; max >>>= 1) {\n this.array.copyWithin(2 * min - 1, min - 1, max - 1);\n min >>>= 1;\n }\n\n // Update pointers\n this.length += this.level + 1;\n this.level += this.level + 1;\n }\n /**\n * Shrink the tree to the smallest size\n */\n protected shrink(): void {\n const length = this.length - this.level;\n\n // Check base case\n if (length < 2) {\n this.array.copyWithin(0, this.level, this.length);\n this.level = 0;\n this.length = length;\n this.array.length = length;\n return;\n }\n\n // Get the highest node\n let min = this.level + 1;\n let mask = msp(length);\n min = min / lsp(min | mask) - 1;\n\n // Update the tree\n this.level = +!isPow2(length);\n for (let max = min + 1; mask; this.level += this.level + 1) {\n this.array.copyWithin(this.level, min, max);\n mask >>>= 1;\n min += min + 1;\n max += max + 2 + +((length & mask) > 0);\n }\n\n // Update pointers\n this.length = this.level + length;\n this.array.length = 2 * this.level + 1;\n }\n}\n","import { Stack } from './stack';\n\n/**\n * An implementation of the {@link Stack} interface using an array\n */\nexport class ArrayStack implements Stack {\n /**\n * The array containing every element.\n */\n protected array: T[];\n /**\n * Instantiate the stack.\n *\n * @param elements - A set of elements to initialize the stack with.\n */\n constructor(elements?: Iterable) {\n this.array = elements ? Array.from(elements) : [];\n }\n\n clear(): void {\n this.array.length = 0;\n }\n\n peek(): T | undefined {\n return this.array[this.array.length - 1];\n }\n\n pop(): T | undefined {\n return this.array.pop();\n }\n\n push(element: T): number {\n return this.array.push(element);\n }\n\n get size(): number {\n return this.array.length;\n }\n /**\n * Receive an iterator through the stack.\n *\n * **Note:** Unexpected behavior can occur if the collection is modified during iteration.\n *\n * @returns An iterator through the stack\n */\n *[Symbol.iterator](): Iterator {\n const array = this.array;\n for (let i = array.length; i > 0; yield array[--i]) {}\n }\n}\n","import { LinkedList, List } from '../list';\nimport { Stack } from './stack';\n\n/**\n * A linked list implementation of the {@link Stack} interface\n */\nexport class LinkedStack implements Stack {\n /**\n * The list containing every element.\n */\n protected list: List;\n /**\n * Instantiate the stack.\n *\n * @param elements - A set of elements to initialize the stack with.\n */\n constructor(elements?: Iterable) {\n this.list = new LinkedList();\n for (const element of elements || []) {\n this.push(element);\n }\n }\n\n clear(): void {\n this.list.clear();\n }\n\n peek(): T | undefined {\n return this.list.get(0);\n }\n\n pop(): T | undefined {\n return this.list.shift();\n }\n\n push(element: T): number {\n return this.list.unshift(element);\n }\n\n get size(): number {\n return this.list.size;\n }\n /**\n * Receive an iterator through the stack.\n *\n * **Note:** Unexpected behavior can occur if the collection is modified during iteration.\n *\n * @returns An iterator through the stack\n */\n [Symbol.iterator](): Iterator {\n return this.list[Symbol.iterator]();\n }\n}\n","import { CompareFn } from '..';\nimport { AATreeNode } from './aaTreeNode';\nimport {\n clone,\n search,\n Edge,\n inOrderTraverse,\n leftmost,\n leftmostStack,\n preOrderTraverse,\n removeStack,\n rightmost,\n rightmostStack,\n searchStack,\n debug,\n} from './binaryTreeUtils';\nimport { SortedTree } from './sortedTree';\nimport { isArray } from 'src/collection/arrayUtils';\nimport { LinkedNode } from 'src/list';\n\n/**\n * An AA tree is a form of balanced tree used for storing and retrieving ordered data efficiently\n * ([source](https://en.wikipedia.org/wiki/AA_tree)).\n *\n * AA trees are named for Arne Andersson, their inventor. They are a variation of the red–black tree,\n * which supports efficient addition and deletion of entries. Unlike red–black trees, additional\n * constraints on the balancing mechanism greatly simplifies the implementation as well as\n * maintenance operations; While a red–black tree needs to consider seven different shapes\n * to properly balance the tree, an AA tree only needs to consider two shapes.\n *\n * The performance of an AA tree is equivalent to the performance of a red–black tree.\n * While an AA tree makes more rotations than a red-black tree, the simpler algorithms\n * tend to be faster, which balances out to similar performance. A red-black tree is\n * more consistent in its performance, but an AA tree tends to be flatter, which results\n * in slightly faster search times.\n */\nexport class AATree implements SortedTree {\n /**\n * The function to determine the order of elements.\n */\n protected compare: CompareFn;\n /**\n * Indicates how to handle duplicates:\n * - < 0 : Add to left subtree\n * - = 0 : Do now allow duplicates\n * - > 0 : Add to right subtree\n */\n protected dupeWeight: number;\n /**\n * The number of elements in the list.\n */\n protected length: number;\n /**\n * The node at the \"top\" of the heap.\n */\n protected root: AATreeNode | undefined;\n /**\n * Instantiate a tree.\n *\n * @param compareFn - The function to determine the order of elements.\n * @param elements - A set of elements to initialize the tree with.\n */\n constructor(compareFn: CompareFn, elements?: Iterable);\n /**\n * Instantiate a tree.\n *\n * @param compareFn - The function to determine the order of elements.\n * @param allowDuplicates - Whether to allow duplicates\n * @param elements - A set of elements to initialize the tree with.\n */\n constructor(compareFn: CompareFn, allowDuplicates: boolean, elements?: Iterable);\n constructor(\n compareFn: CompareFn,\n allowDuplicates?: boolean | Iterable,\n elements?: Iterable,\n ) {\n if (typeof allowDuplicates !== 'boolean') {\n elements = allowDuplicates;\n allowDuplicates = true;\n }\n this.compare = compareFn;\n this.dupeWeight = +allowDuplicates;\n this.length = 0;\n this.build(elements ?? []);\n }\n\n add(element: T): this {\n // Find the element\n const sentinel = { left: this.root } as AATreeNode;\n let edge: Edge> = { from: sentinel, label: 'left', to: this.root };\n let stack = searchStack(element, { value: edge }, this.compare, this.dupeWeight);\n\n // If element already exists\n if (stack.value.to != null) {\n return this;\n }\n\n // Add element\n edge = stack.value;\n let label = edge.label;\n edge.from![label!] = { level: 1, value: element };\n\n // Balance the tree\n while (stack.next) {\n stack = stack.next;\n edge = stack.value;\n edge.to = split(skew(edge.to));\n edge.from![(label = edge.label!)] = edge.to;\n }\n\n // Update state\n ++this.length;\n this.root = sentinel.left;\n return this;\n }\n\n clear(): void {\n this.root = undefined;\n this.length = 0;\n }\n\n comparator(): CompareFn {\n return this.compare;\n }\n\n delete(element: T): boolean {\n // Remove the element if found\n const sentinel = { left: this.root } as AATreeNode;\n const edge: Edge> = { from: sentinel, label: 'left', to: this.root };\n const stack = searchStack(element, { value: edge }, this.compare, 0);\n const removed = remove(stack);\n\n // Update state\n this.root = sentinel.left;\n this.length -= +removed;\n return removed;\n }\n\n has(element: T): boolean {\n return search(element, this.root, this.compare) != null;\n }\n\n max(): T | undefined {\n return rightmost(this.root)?.value;\n }\n\n min(): T | undefined {\n return leftmost(this.root)?.value;\n }\n\n pop(): T | undefined {\n // Find the maximum value\n const sentinel = { left: this.root } as AATreeNode;\n const edge: Edge> = { from: sentinel, label: 'left', to: this.root };\n const stack = rightmostStack({ value: edge });\n const value = stack.value.to?.value;\n\n // Remove the value\n const removed = remove(stack);\n\n // Update state\n this.root = sentinel.left;\n this.length -= +removed;\n return value;\n }\n\n shift(): T | undefined {\n // Find the minimum value\n const sentinel = { left: this.root } as AATreeNode;\n const edge: Edge> = { from: sentinel, label: 'left', to: this.root };\n const stack = leftmostStack({ value: edge });\n const value = stack.value.to?.value;\n\n // Remove the value\n const removed = remove(stack);\n\n // Update state\n this.root = sentinel.left;\n this.length -= +removed;\n return value;\n }\n\n get size(): number {\n return this.length;\n }\n\n *sorted(): Iterable {\n for (const node of inOrderTraverse(this.root)) {\n yield node.value;\n }\n }\n /**\n * Receive an iterator through the list.\n *\n * **Note:** Unexpected behavior can occur if the collection is modified during iteration.\n *\n * @returns An iterator through the list\n */\n *[Symbol.iterator](): Iterator {\n for (const node of preOrderTraverse(this.root)) {\n yield node.value;\n }\n }\n\n update(curElement: T, newElement: T): boolean {\n if (this.delete(curElement)) {\n this.add(newElement);\n return true;\n }\n return false;\n }\n\n protected build(obj: Iterable): void {\n if (isArray(obj)) {\n for (let i = 0; i < obj.length; ++i) {\n this.add(obj[i]);\n }\n } else if (obj instanceof AATree && this.compare === obj.compare) {\n this.root = clone(obj.root);\n this.length = obj.size;\n } else {\n for (const element of obj) {\n this.add(element);\n }\n }\n }\n}\n/**\n * @internal\n */\nexport function remove(stack: LinkedNode>>): boolean {\n let edge = stack.value;\n let node = edge.to;\n\n // If not found\n if (node == null) {\n return false;\n }\n\n // Remove the node\n stack = removeStack(stack);\n\n // Update the tree\n while (stack.next) {\n stack = stack.next;\n edge = stack.value;\n node = edge.to!;\n\n // Decrease levels\n const level = 1 + Math.min(node.left?.level ?? 0, node.right?.level ?? 0);\n if (level < node.level) {\n node.level = level;\n if (node.right != null && level < node.right.level) {\n node.right.level = level;\n }\n }\n\n // Balance\n node = skew(node);\n node.right = skew(node.right);\n if (node.right != null) {\n node.right.right = skew(node.right.right);\n }\n node = split(node);\n node.right = split(node.right);\n\n // Make the update\n edge.from![edge.label!] = edge.to = node;\n }\n\n return true;\n}\n/**\n * @internal\n */\nexport function skew(node?: undefined): undefined;\nexport function skew(node: AATreeNode): AATreeNode;\nexport function skew(node?: AATreeNode): AATreeNode | undefined;\nexport function skew(node?: AATreeNode): AATreeNode | undefined {\n if (node == null || node.left == null || node.level != node.left.level) {\n return node;\n }\n const left = node.left;\n node.left = left.right;\n left.right = node;\n return left;\n}\n/**\n * @internal\n */\nexport function split(node?: undefined): undefined;\nexport function split(node: AATreeNode): AATreeNode;\nexport function split(node?: AATreeNode): AATreeNode | undefined;\nexport function split(node?: AATreeNode): AATreeNode | undefined {\n if (\n node == null ||\n node.right == null ||\n node.right.right == null ||\n node.level != node.right.right.level\n ) {\n return node;\n }\n const right = node.right;\n node.right = right.left;\n right.left = node;\n ++right.level;\n return right;\n}\n","import { CompareFn } from 'src';\nimport { AVLTreeNode } from './avlTreeNode';\nimport {\n clone,\n search,\n Edge,\n inOrderTraverse,\n leftmost,\n leftmostStack,\n preOrderTraverse,\n rightmost,\n rightmostStack,\n searchStack,\n removeStack,\n} from './binaryTreeUtils';\nimport { SortedTree } from './sortedTree';\nimport { isArray } from 'src/collection/arrayUtils';\nimport { LinkedNode } from 'src/list';\n\n/**\n * An AVL tree is a self-balancing binary search tree ([source](https://en.wikipedia.org/wiki/AVL_tree)).\n *\n * It is named after inventors Georgy Adelson-Velsky and Evgenii Landis and was the first such\n * data structure to be invented. In an AVL tree, the heights of the two child\n * subtrees of any node differ by at most one; if at any time they differ by more\n * than one, rebalancing is done to restore this property.\n *\n * Lookup, insertion, and deletion all take O(log(n)) time in both the average and worst cases,\n * where n is the number of nodes in the tree prior to the operation. Insertions and deletions\n * may require the tree to be rebalanced by one or more tree rotations.\n *\n * AVL trees are often compared with red–black trees as both take O(log(n))\n * time for the basic operations. For lookup-intensive applications, AVL trees are\n * faster than red–black trees because they are more strictly balanced.\n * Similar to red–black trees, AVL trees are height-balanced.\n */\nexport class AVLTree implements SortedTree {\n /**\n * The function to determine the order of elements.\n */\n protected compare: CompareFn;\n /**\n * Indicates how to handle duplicates:\n * - < 0 : Add to left subtree\n * - = 0 : Do now allow duplicates\n * - > 0 : Add to right subtree\n */\n protected dupeWeight: number;\n /**\n * The number of elements in the list.\n */\n protected length: number;\n /**\n * The root of the tree.\n */\n protected root: AVLTreeNode;\n /**\n * Instantiate a tree.\n *\n * @param compareFn - The function to determine the order of elements.\n * @param elements - A set of elements to initialize the tree with.\n */\n constructor(compareFn: CompareFn, elements?: Iterable);\n /**\n * Instantiate a tree.\n *\n * @param compareFn - The function to determine the order of elements.\n * @param allowDuplicates - Whether to allow duplicates\n * @param elements - A set of elements to initialize the tree with.\n */\n constructor(compareFn: CompareFn, allowDuplicates: boolean, elements?: Iterable);\n constructor(\n compareFn: CompareFn,\n allowDuplicates?: boolean | Iterable,\n elements?: Iterable,\n ) {\n if (typeof allowDuplicates !== 'boolean') {\n elements = allowDuplicates;\n allowDuplicates = true;\n }\n this.compare = compareFn;\n this.dupeWeight = +allowDuplicates;\n this.length = 0;\n this.root = {} as AVLTreeNode;\n this.build(elements ?? []);\n }\n\n add(element: T): this {\n // Find the element\n let edge: Edge> = { from: this.root, label: 'left', to: this.root.left };\n let stack = searchStack(element, { value: edge }, this.compare, this.dupeWeight);\n\n // If element already exists\n if (stack.value.to != null) {\n return this;\n }\n\n // Add element\n edge = stack.value;\n let label = edge.label;\n edge.from![label!] = { balanceFactor: 0, value: element };\n\n // Balance the tree\n while (stack.next) {\n stack = stack.next;\n edge = stack.value;\n edge.to!.balanceFactor += label === 'left' ? -1 : 1;\n edge.to = balance(edge.to!);\n edge.from![(label = edge.label!)] = edge.to;\n if (edge.to!.balanceFactor === 0) {\n break;\n }\n }\n\n // Update state\n ++this.length;\n return this;\n }\n\n clear(): void {\n this.root.left = undefined;\n this.length = 0;\n }\n\n comparator(): CompareFn {\n return this.compare;\n }\n\n delete(element: T): boolean {\n // Remove the element if found\n const edge: Edge> = { from: this.root, label: 'left', to: this.root.left };\n const stack = searchStack(element, { value: edge }, this.compare, 0);\n const removed = remove(stack);\n\n // Update state\n this.length -= +removed;\n return removed;\n }\n\n has(element: T): boolean {\n return search(element, this.root.left, this.compare) != null;\n }\n\n max(): T | undefined {\n return rightmost(this.root.left)?.value;\n }\n\n min(): T | undefined {\n return leftmost(this.root.left)?.value;\n }\n\n pop(): T | undefined {\n // Find the maximum value\n const edge: Edge> = { from: this.root, label: 'left', to: this.root.left };\n const stack = rightmostStack({ value: edge });\n const value = stack.value.to?.value;\n\n // Remove the value\n const removed = remove(stack);\n\n // Update state\n this.length -= +removed;\n return value;\n }\n\n shift(): T | undefined {\n // Find the minimum value\n const edge: Edge> = { from: this.root, label: 'left', to: this.root.left };\n const stack = leftmostStack({ value: edge });\n const value = stack.value.to?.value;\n\n // Remove the value\n const removed = remove(stack);\n\n // Update state\n this.length -= +removed;\n return value;\n }\n\n get size(): number {\n return this.length;\n }\n\n *sorted(): Iterable {\n for (const node of inOrderTraverse(this.root.left)) {\n yield node.value;\n }\n }\n /**\n * Receive an iterator through the list.\n *\n * **Note:** Unexpected behavior can occur if the collection is modified during iteration.\n *\n * @returns An iterator through the list\n */\n *[Symbol.iterator](): Iterator {\n for (const node of preOrderTraverse(this.root.left)) {\n yield node.value;\n }\n }\n\n update(curElement: T, newElement: T): boolean {\n if (this.delete(curElement)) {\n this.add(newElement);\n return true;\n }\n return false;\n }\n\n protected build(obj: Iterable): void {\n if (isArray(obj)) {\n for (let i = 0; i < obj.length; ++i) {\n this.add(obj[i]);\n }\n } else if (obj instanceof AVLTree && this.compare === obj.compare) {\n this.root = clone(obj.root);\n this.length = obj.size;\n } else {\n for (const element of obj) {\n this.add(element);\n }\n }\n }\n}\n/**\n * @internal\n */\nexport function balance(node: AVLTreeNode): AVLTreeNode {\n if (node.balanceFactor > 1) {\n if (node.right!.balanceFactor < 0) {\n node.right = rotateR(node.right!);\n }\n node = rotateL(node);\n } else if (node.balanceFactor < -1) {\n if (node.left!.balanceFactor > 0) {\n node.left = rotateL(node.left!);\n }\n node = rotateR(node);\n }\n return node;\n}\n/**\n * @internal\n */\nexport function remove(stack: LinkedNode>>): boolean {\n let edge = stack.value;\n const node = edge.to;\n\n // If not found\n if (node == null) {\n return false;\n }\n\n // Remove the node\n stack = removeStack(stack);\n\n // Balance the tree\n let label = stack.value.label;\n while (stack.next) {\n stack = stack.next;\n edge = stack.value;\n edge.to!.balanceFactor -= label === 'left' ? -1 : 1;\n edge.to = balance(edge.to!);\n edge.from![(label = edge.label)!] = edge.to;\n if (edge.to!.balanceFactor !== 0) {\n break;\n }\n }\n\n return true;\n}\n/**\n * @internal\n */\nexport function rotateL(P: AVLTreeNode): AVLTreeNode {\n const R = P.right!;\n P.right = R.left;\n R.left = P;\n P.balanceFactor -= 1 + Math.max(0, R.balanceFactor);\n R.balanceFactor -= 1 - Math.min(0, P.balanceFactor);\n return R;\n}\n/**\n * @internal\n */\nexport function rotateR(P: AVLTreeNode): AVLTreeNode {\n const L = P.left!;\n P.left = L.right;\n L.right = P;\n P.balanceFactor += 1 - Math.min(0, L.balanceFactor);\n L.balanceFactor += 1 + Math.max(0, P.balanceFactor);\n return L;\n}\n"],"sourceRoot":""} \ No newline at end of file diff --git a/docs/README.md b/docs/README.md index caafe2c..470fc76 100644 --- a/docs/README.md +++ b/docs/README.md @@ -1,12 +1,15 @@ -dastal - v3.0.0 +dastal - v4.0.0 -# dastal - v3.0.0 +# dastal - v4.0.0 ## Table of contents ### Namespaces -- [math](modules/math.md) +- [ArrayUtils](modules/arrayutils.md) +- [IteratorUtils](modules/iteratorutils.md) +- [NumberUtils](modules/numberutils.md) +- [u32](modules/u32.md) ### Classes @@ -29,6 +32,7 @@ dastal - v3.0.0 - [AATreeNode](interfaces/aatreenode.md) - [AVLTreeNode](interfaces/avltreenode.md) - [BinaryTreeNode](interfaces/binarytreenode.md) +- [Collection](interfaces/collection.md) - [DoublyLinkedNode](interfaces/doublylinkednode.md) - [Heap](interfaces/heap.md) - [LinkedNode](interfaces/linkednode.md) @@ -46,6 +50,10 @@ dastal - v3.0.0 - [CombineFn](README.md#combinefn) - [CompareFn](README.md#comparefn) +### Functions + +- [isCollection](README.md#iscollection) + ## Type aliases ### CombineFn @@ -86,7 +94,7 @@ the inputs, depending on the use case. #### Defined in -[src/index.ts:21](https://github.com/havelessbemore/dastal/blob/e94627b/src/index.ts#L21) +[src/index.ts:21](https://github.com/havelessbemore/dastal/blob/2fe24da/src/index.ts#L21) ___ @@ -128,4 +136,28 @@ A function used to determine the order of a set of elements. #### Defined in -[src/index.ts:33](https://github.com/havelessbemore/dastal/blob/e94627b/src/index.ts#L33) +[src/index.ts:33](https://github.com/havelessbemore/dastal/blob/2fe24da/src/index.ts#L33) + +## Functions + +### isCollection + +▸ **isCollection**(`obj`): obj is Collection + +Check if a value is a [Collection](interfaces/collection.md). + +#### Parameters + +| Name | Type | Description | +| :------ | :------ | :------ | +| `obj` | `any` | The value to check. | + +#### Returns + +obj is Collection + +- `true` if obj is a Collection, `false` otherwise. + +#### Defined in + +[src/collection/index.ts:14](https://github.com/havelessbemore/dastal/blob/2fe24da/src/collection/index.ts#L14) diff --git a/docs/classes/aatree.md b/docs/classes/aatree.md index 2402446..f4c1ec6 100644 --- a/docs/classes/aatree.md +++ b/docs/classes/aatree.md @@ -1,4 +1,4 @@ -[dastal - v3.0.0](../README.md) / AATree +[dastal - v4.0.0](../README.md) / AATree # Class: AATree @@ -75,7 +75,7 @@ Instantiate a tree. #### Defined in -[src/tree/aaTree.ts:56](https://github.com/havelessbemore/dastal/blob/e94627b/src/tree/aaTree.ts#L56) +[src/tree/aaTree.ts:56](https://github.com/havelessbemore/dastal/blob/2fe24da/src/tree/aaTree.ts#L56) • **new AATree**(`compareFn`, `allowDuplicates`, `elements?`) @@ -97,7 +97,7 @@ Instantiate a tree. #### Defined in -[src/tree/aaTree.ts:63](https://github.com/havelessbemore/dastal/blob/e94627b/src/tree/aaTree.ts#L63) +[src/tree/aaTree.ts:63](https://github.com/havelessbemore/dastal/blob/2fe24da/src/tree/aaTree.ts#L63) ## Accessors @@ -117,7 +117,7 @@ The number of elements in the collection. #### Defined in -[src/tree/aaTree.ts:183](https://github.com/havelessbemore/dastal/blob/e94627b/src/tree/aaTree.ts#L183) +[src/tree/aaTree.ts:183](https://github.com/havelessbemore/dastal/blob/2fe24da/src/tree/aaTree.ts#L183) ## Methods @@ -141,7 +141,7 @@ An iterator through the list #### Defined in -[src/tree/aaTree.ts:199](https://github.com/havelessbemore/dastal/blob/e94627b/src/tree/aaTree.ts#L199) +[src/tree/aaTree.ts:199](https://github.com/havelessbemore/dastal/blob/2fe24da/src/tree/aaTree.ts#L199) ___ @@ -167,7 +167,7 @@ Inserts an element into the tree. #### Defined in -[src/tree/aaTree.ts:87](https://github.com/havelessbemore/dastal/blob/e94627b/src/tree/aaTree.ts#L87) +[src/tree/aaTree.ts:87](https://github.com/havelessbemore/dastal/blob/2fe24da/src/tree/aaTree.ts#L87) ___ @@ -187,7 +187,7 @@ Removes all elements. #### Defined in -[src/tree/aaTree.ts:117](https://github.com/havelessbemore/dastal/blob/e94627b/src/tree/aaTree.ts#L117) +[src/tree/aaTree.ts:117](https://github.com/havelessbemore/dastal/blob/2fe24da/src/tree/aaTree.ts#L117) ___ @@ -205,7 +205,7 @@ ___ #### Defined in -[src/tree/aaTree.ts:122](https://github.com/havelessbemore/dastal/blob/e94627b/src/tree/aaTree.ts#L122) +[src/tree/aaTree.ts:122](https://github.com/havelessbemore/dastal/blob/2fe24da/src/tree/aaTree.ts#L122) ___ @@ -231,7 +231,7 @@ Delete an element from the tree. #### Defined in -[src/tree/aaTree.ts:126](https://github.com/havelessbemore/dastal/blob/e94627b/src/tree/aaTree.ts#L126) +[src/tree/aaTree.ts:126](https://github.com/havelessbemore/dastal/blob/2fe24da/src/tree/aaTree.ts#L126) ___ @@ -257,7 +257,7 @@ Check if an element is in the tree. #### Defined in -[src/tree/aaTree.ts:139](https://github.com/havelessbemore/dastal/blob/e94627b/src/tree/aaTree.ts#L139) +[src/tree/aaTree.ts:139](https://github.com/havelessbemore/dastal/blob/2fe24da/src/tree/aaTree.ts#L139) ___ @@ -277,7 +277,7 @@ Get the maximum element. #### Defined in -[src/tree/aaTree.ts:143](https://github.com/havelessbemore/dastal/blob/e94627b/src/tree/aaTree.ts#L143) +[src/tree/aaTree.ts:143](https://github.com/havelessbemore/dastal/blob/2fe24da/src/tree/aaTree.ts#L143) ___ @@ -297,7 +297,7 @@ Get the minimum element. #### Defined in -[src/tree/aaTree.ts:147](https://github.com/havelessbemore/dastal/blob/e94627b/src/tree/aaTree.ts#L147) +[src/tree/aaTree.ts:147](https://github.com/havelessbemore/dastal/blob/2fe24da/src/tree/aaTree.ts#L147) ___ @@ -317,7 +317,7 @@ Remove the maximum element. #### Defined in -[src/tree/aaTree.ts:151](https://github.com/havelessbemore/dastal/blob/e94627b/src/tree/aaTree.ts#L151) +[src/tree/aaTree.ts:151](https://github.com/havelessbemore/dastal/blob/2fe24da/src/tree/aaTree.ts#L151) ___ @@ -337,7 +337,7 @@ Remove the minimum element. #### Defined in -[src/tree/aaTree.ts:167](https://github.com/havelessbemore/dastal/blob/e94627b/src/tree/aaTree.ts#L167) +[src/tree/aaTree.ts:167](https://github.com/havelessbemore/dastal/blob/2fe24da/src/tree/aaTree.ts#L167) ___ @@ -359,7 +359,7 @@ Iterate through the tree in sorted order (i.e in-order traversal). #### Defined in -[src/tree/aaTree.ts:187](https://github.com/havelessbemore/dastal/blob/e94627b/src/tree/aaTree.ts#L187) +[src/tree/aaTree.ts:187](https://github.com/havelessbemore/dastal/blob/2fe24da/src/tree/aaTree.ts#L187) ___ @@ -386,4 +386,4 @@ Update a specific element. #### Defined in -[src/tree/aaTree.ts:205](https://github.com/havelessbemore/dastal/blob/e94627b/src/tree/aaTree.ts#L205) +[src/tree/aaTree.ts:205](https://github.com/havelessbemore/dastal/blob/2fe24da/src/tree/aaTree.ts#L205) diff --git a/docs/classes/arraylist.md b/docs/classes/arraylist.md index 9a43ea5..d3fee98 100644 --- a/docs/classes/arraylist.md +++ b/docs/classes/arraylist.md @@ -1,4 +1,4 @@ -[dastal - v3.0.0](../README.md) / ArrayList +[dastal - v4.0.0](../README.md) / ArrayList # Class: ArrayList @@ -70,7 +70,7 @@ Instantiate the list. #### Defined in -[src/list/arrayList.ts:13](https://github.com/havelessbemore/dastal/blob/e94627b/src/list/arrayList.ts#L13) +[src/list/arrayList.ts:13](https://github.com/havelessbemore/dastal/blob/2fe24da/src/list/arrayList.ts#L13) ## Accessors @@ -90,7 +90,7 @@ The number of elements in the collection. #### Defined in -[src/list/arrayList.ts:116](https://github.com/havelessbemore/dastal/blob/e94627b/src/list/arrayList.ts#L116) +[src/list/arrayList.ts:113](https://github.com/havelessbemore/dastal/blob/2fe24da/src/list/arrayList.ts#L113) ## Methods @@ -114,7 +114,7 @@ An iterator through the list #### Defined in -[src/list/arrayList.ts:146](https://github.com/havelessbemore/dastal/blob/e94627b/src/list/arrayList.ts#L146) +[src/list/arrayList.ts:136](https://github.com/havelessbemore/dastal/blob/2fe24da/src/list/arrayList.ts#L136) ___ @@ -141,7 +141,7 @@ Add the element at the specified index. #### Defined in -[src/list/arrayList.ts:23](https://github.com/havelessbemore/dastal/blob/e94627b/src/list/arrayList.ts#L23) +[src/list/arrayList.ts:23](https://github.com/havelessbemore/dastal/blob/2fe24da/src/list/arrayList.ts#L23) ___ @@ -168,7 +168,7 @@ Add elements at the specified index. #### Defined in -[src/list/arrayList.ts:30](https://github.com/havelessbemore/dastal/blob/e94627b/src/list/arrayList.ts#L30) +[src/list/arrayList.ts:30](https://github.com/havelessbemore/dastal/blob/2fe24da/src/list/arrayList.ts#L30) ___ @@ -188,7 +188,7 @@ Removes all elements. #### Defined in -[src/list/arrayList.ts:40](https://github.com/havelessbemore/dastal/blob/e94627b/src/list/arrayList.ts#L40) +[src/list/arrayList.ts:37](https://github.com/havelessbemore/dastal/blob/2fe24da/src/list/arrayList.ts#L37) ___ @@ -214,7 +214,7 @@ Combines the list with multiple iterables into a new list. Does not modify the e #### Defined in -[src/list/arrayList.ts:44](https://github.com/havelessbemore/dastal/blob/e94627b/src/list/arrayList.ts#L44) +[src/list/arrayList.ts:41](https://github.com/havelessbemore/dastal/blob/2fe24da/src/list/arrayList.ts#L41) ___ @@ -248,7 +248,7 @@ the copied sequence will be trimmed to fit list.size #### Defined in -[src/list/arrayList.ts:52](https://github.com/havelessbemore/dastal/blob/e94627b/src/list/arrayList.ts#L52) +[src/list/arrayList.ts:49](https://github.com/havelessbemore/dastal/blob/2fe24da/src/list/arrayList.ts#L49) ___ @@ -279,7 +279,7 @@ end of the list. For example, -2 refers to the second to last element of the lis #### Defined in -[src/list/arrayList.ts:60](https://github.com/havelessbemore/dastal/blob/e94627b/src/list/arrayList.ts#L60) +[src/list/arrayList.ts:57](https://github.com/havelessbemore/dastal/blob/2fe24da/src/list/arrayList.ts#L57) ___ @@ -305,7 +305,7 @@ Return the element at the specified index. #### Defined in -[src/list/arrayList.ts:67](https://github.com/havelessbemore/dastal/blob/e94627b/src/list/arrayList.ts#L67) +[src/list/arrayList.ts:64](https://github.com/havelessbemore/dastal/blob/2fe24da/src/list/arrayList.ts#L64) ___ @@ -332,7 +332,7 @@ Update the element at the specified index. #### Defined in -[src/list/arrayList.ts:71](https://github.com/havelessbemore/dastal/blob/e94627b/src/list/arrayList.ts#L71) +[src/list/arrayList.ts:68](https://github.com/havelessbemore/dastal/blob/2fe24da/src/list/arrayList.ts#L68) ___ @@ -352,7 +352,7 @@ Retrieves and removes the end of the list. #### Defined in -[src/list/arrayList.ts:80](https://github.com/havelessbemore/dastal/blob/e94627b/src/list/arrayList.ts#L80) +[src/list/arrayList.ts:77](https://github.com/havelessbemore/dastal/blob/2fe24da/src/list/arrayList.ts#L77) ___ @@ -378,7 +378,7 @@ Inserts the specified value into the end of the list #### Defined in -[src/list/arrayList.ts:84](https://github.com/havelessbemore/dastal/blob/e94627b/src/list/arrayList.ts#L84) +[src/list/arrayList.ts:81](https://github.com/havelessbemore/dastal/blob/2fe24da/src/list/arrayList.ts#L81) ___ @@ -407,7 +407,7 @@ end of the list. For example, -2 refers to the second to last element of the lis #### Defined in -[src/list/arrayList.ts:88](https://github.com/havelessbemore/dastal/blob/e94627b/src/list/arrayList.ts#L88) +[src/list/arrayList.ts:85](https://github.com/havelessbemore/dastal/blob/2fe24da/src/list/arrayList.ts#L85) ___ @@ -437,7 +437,7 @@ end of the list. For example, -2 refers to the second to last element of the lis #### Defined in -[src/list/arrayList.ts:92](https://github.com/havelessbemore/dastal/blob/e94627b/src/list/arrayList.ts#L92) +[src/list/arrayList.ts:89](https://github.com/havelessbemore/dastal/blob/2fe24da/src/list/arrayList.ts#L89) ___ @@ -464,7 +464,7 @@ Update the element at the specified index. #### Defined in -[src/list/arrayList.ts:103](https://github.com/havelessbemore/dastal/blob/e94627b/src/list/arrayList.ts#L103) +[src/list/arrayList.ts:100](https://github.com/havelessbemore/dastal/blob/2fe24da/src/list/arrayList.ts#L100) ___ @@ -484,7 +484,7 @@ Retrieves and removes the first element in the list. #### Defined in -[src/list/arrayList.ts:112](https://github.com/havelessbemore/dastal/blob/e94627b/src/list/arrayList.ts#L112) +[src/list/arrayList.ts:109](https://github.com/havelessbemore/dastal/blob/2fe24da/src/list/arrayList.ts#L109) ___ @@ -514,7 +514,7 @@ end of the list. For example, -2 refers to the second to last element of the lis #### Defined in -[src/list/arrayList.ts:120](https://github.com/havelessbemore/dastal/blob/e94627b/src/list/arrayList.ts#L120) +[src/list/arrayList.ts:117](https://github.com/havelessbemore/dastal/blob/2fe24da/src/list/arrayList.ts#L117) ___ @@ -540,7 +540,7 @@ Sorts the elements in place. #### Defined in -[src/list/arrayList.ts:135](https://github.com/havelessbemore/dastal/blob/e94627b/src/list/arrayList.ts#L135) +[src/list/arrayList.ts:125](https://github.com/havelessbemore/dastal/blob/2fe24da/src/list/arrayList.ts#L125) ___ @@ -569,7 +569,7 @@ Returns any deleted elements. #### Defined in -[src/list/arrayList.ts:124](https://github.com/havelessbemore/dastal/blob/e94627b/src/list/arrayList.ts#L124) +[src/list/arrayList.ts:121](https://github.com/havelessbemore/dastal/blob/2fe24da/src/list/arrayList.ts#L121) ___ @@ -595,7 +595,7 @@ Inserts the specified value into the front of the list #### Defined in -[src/list/arrayList.ts:150](https://github.com/havelessbemore/dastal/blob/e94627b/src/list/arrayList.ts#L150) +[src/list/arrayList.ts:140](https://github.com/havelessbemore/dastal/blob/2fe24da/src/list/arrayList.ts#L140) ___ @@ -621,7 +621,7 @@ Update the elements of the list #### Defined in -[src/list/arrayList.ts:154](https://github.com/havelessbemore/dastal/blob/e94627b/src/list/arrayList.ts#L154) +[src/list/arrayList.ts:144](https://github.com/havelessbemore/dastal/blob/2fe24da/src/list/arrayList.ts#L144) ▸ **update**(`min`, `callback`): [ArrayList](arraylist.md) @@ -647,7 +647,7 @@ end of the list. For example, -2 refers to the second to last element of the lis #### Defined in -[src/list/arrayList.ts:155](https://github.com/havelessbemore/dastal/blob/e94627b/src/list/arrayList.ts#L155) +[src/list/arrayList.ts:145](https://github.com/havelessbemore/dastal/blob/2fe24da/src/list/arrayList.ts#L145) ▸ **update**(`min`, `max`, `callback`): [ArrayList](arraylist.md) @@ -674,7 +674,7 @@ end of the list. For example, -2 refers to the second to last element of the lis #### Defined in -[src/list/arrayList.ts:156](https://github.com/havelessbemore/dastal/blob/e94627b/src/list/arrayList.ts#L156) +[src/list/arrayList.ts:146](https://github.com/havelessbemore/dastal/blob/2fe24da/src/list/arrayList.ts#L146) ___ @@ -706,4 +706,4 @@ end of the list. For example, -2 refers to the second to last element of the lis #### Defined in -[src/list/arrayList.ts:184](https://github.com/havelessbemore/dastal/blob/e94627b/src/list/arrayList.ts#L184) +[src/list/arrayList.ts:174](https://github.com/havelessbemore/dastal/blob/2fe24da/src/list/arrayList.ts#L174) diff --git a/docs/classes/arrayqueue.md b/docs/classes/arrayqueue.md index 48fe426..1f06e8a 100644 --- a/docs/classes/arrayqueue.md +++ b/docs/classes/arrayqueue.md @@ -1,4 +1,4 @@ -[dastal - v3.0.0](../README.md) / ArrayQueue +[dastal - v4.0.0](../README.md) / ArrayQueue # Class: ArrayQueue @@ -54,7 +54,7 @@ Instantiate the queue. #### Defined in -[src/queue/arrayQueue.ts:10](https://github.com/havelessbemore/dastal/blob/e94627b/src/queue/arrayQueue.ts#L10) +[src/queue/arrayQueue.ts:10](https://github.com/havelessbemore/dastal/blob/2fe24da/src/queue/arrayQueue.ts#L10) ## Accessors @@ -74,7 +74,7 @@ The number of elements in the collection. #### Defined in -[src/queue/arrayQueue.ts:36](https://github.com/havelessbemore/dastal/blob/e94627b/src/queue/arrayQueue.ts#L36) +[src/queue/arrayQueue.ts:36](https://github.com/havelessbemore/dastal/blob/2fe24da/src/queue/arrayQueue.ts#L36) ## Methods @@ -98,7 +98,7 @@ An iterator through the queue #### Defined in -[src/queue/arrayQueue.ts:46](https://github.com/havelessbemore/dastal/blob/e94627b/src/queue/arrayQueue.ts#L46) +[src/queue/arrayQueue.ts:46](https://github.com/havelessbemore/dastal/blob/2fe24da/src/queue/arrayQueue.ts#L46) ___ @@ -118,7 +118,7 @@ Removes all elements. #### Defined in -[src/queue/arrayQueue.ts:20](https://github.com/havelessbemore/dastal/blob/e94627b/src/queue/arrayQueue.ts#L20) +[src/queue/arrayQueue.ts:20](https://github.com/havelessbemore/dastal/blob/2fe24da/src/queue/arrayQueue.ts#L20) ___ @@ -138,7 +138,7 @@ Retrieves and removes the head of this queue #### Defined in -[src/queue/arrayQueue.ts:24](https://github.com/havelessbemore/dastal/blob/e94627b/src/queue/arrayQueue.ts#L24) +[src/queue/arrayQueue.ts:24](https://github.com/havelessbemore/dastal/blob/2fe24da/src/queue/arrayQueue.ts#L24) ___ @@ -164,7 +164,7 @@ Inserts the specified value into this queue #### Defined in -[src/queue/arrayQueue.ts:28](https://github.com/havelessbemore/dastal/blob/e94627b/src/queue/arrayQueue.ts#L28) +[src/queue/arrayQueue.ts:28](https://github.com/havelessbemore/dastal/blob/2fe24da/src/queue/arrayQueue.ts#L28) ___ @@ -184,4 +184,4 @@ Retrieves, but does not remove, the head of this queue #### Defined in -[src/queue/arrayQueue.ts:32](https://github.com/havelessbemore/dastal/blob/e94627b/src/queue/arrayQueue.ts#L32) +[src/queue/arrayQueue.ts:32](https://github.com/havelessbemore/dastal/blob/2fe24da/src/queue/arrayQueue.ts#L32) diff --git a/docs/classes/arraystack.md b/docs/classes/arraystack.md index af0463b..a16f454 100644 --- a/docs/classes/arraystack.md +++ b/docs/classes/arraystack.md @@ -1,4 +1,4 @@ -[dastal - v3.0.0](../README.md) / ArrayStack +[dastal - v4.0.0](../README.md) / ArrayStack # Class: ArrayStack @@ -54,7 +54,7 @@ Instantiate the stack. #### Defined in -[src/stack/arrayStack.ts:10](https://github.com/havelessbemore/dastal/blob/e94627b/src/stack/arrayStack.ts#L10) +[src/stack/arrayStack.ts:10](https://github.com/havelessbemore/dastal/blob/2fe24da/src/stack/arrayStack.ts#L10) ## Accessors @@ -74,7 +74,7 @@ The number of elements in the collection. #### Defined in -[src/stack/arrayStack.ts:36](https://github.com/havelessbemore/dastal/blob/e94627b/src/stack/arrayStack.ts#L36) +[src/stack/arrayStack.ts:36](https://github.com/havelessbemore/dastal/blob/2fe24da/src/stack/arrayStack.ts#L36) ## Methods @@ -98,7 +98,7 @@ An iterator through the stack #### Defined in -[src/stack/arrayStack.ts:46](https://github.com/havelessbemore/dastal/blob/e94627b/src/stack/arrayStack.ts#L46) +[src/stack/arrayStack.ts:46](https://github.com/havelessbemore/dastal/blob/2fe24da/src/stack/arrayStack.ts#L46) ___ @@ -118,7 +118,7 @@ Removes all elements. #### Defined in -[src/stack/arrayStack.ts:20](https://github.com/havelessbemore/dastal/blob/e94627b/src/stack/arrayStack.ts#L20) +[src/stack/arrayStack.ts:20](https://github.com/havelessbemore/dastal/blob/2fe24da/src/stack/arrayStack.ts#L20) ___ @@ -138,7 +138,7 @@ Retrieves, but does not remove, the top of the stack #### Defined in -[src/stack/arrayStack.ts:24](https://github.com/havelessbemore/dastal/blob/e94627b/src/stack/arrayStack.ts#L24) +[src/stack/arrayStack.ts:24](https://github.com/havelessbemore/dastal/blob/2fe24da/src/stack/arrayStack.ts#L24) ___ @@ -158,7 +158,7 @@ Retrieves and removes the top of the stack #### Defined in -[src/stack/arrayStack.ts:28](https://github.com/havelessbemore/dastal/blob/e94627b/src/stack/arrayStack.ts#L28) +[src/stack/arrayStack.ts:28](https://github.com/havelessbemore/dastal/blob/2fe24da/src/stack/arrayStack.ts#L28) ___ @@ -184,4 +184,4 @@ Inserts an element into the stack #### Defined in -[src/stack/arrayStack.ts:32](https://github.com/havelessbemore/dastal/blob/e94627b/src/stack/arrayStack.ts#L32) +[src/stack/arrayStack.ts:32](https://github.com/havelessbemore/dastal/blob/2fe24da/src/stack/arrayStack.ts#L32) diff --git a/docs/classes/avltree.md b/docs/classes/avltree.md index 3dddd14..73a942e 100644 --- a/docs/classes/avltree.md +++ b/docs/classes/avltree.md @@ -1,4 +1,4 @@ -[dastal - v3.0.0](../README.md) / AVLTree +[dastal - v4.0.0](../README.md) / AVLTree # Class: AVLTree @@ -76,7 +76,7 @@ Instantiate a tree. #### Defined in -[src/tree/avlTree.ts:56](https://github.com/havelessbemore/dastal/blob/e94627b/src/tree/avlTree.ts#L56) +[src/tree/avlTree.ts:56](https://github.com/havelessbemore/dastal/blob/2fe24da/src/tree/avlTree.ts#L56) • **new AVLTree**(`compareFn`, `allowDuplicates`, `elements?`) @@ -98,7 +98,7 @@ Instantiate a tree. #### Defined in -[src/tree/avlTree.ts:63](https://github.com/havelessbemore/dastal/blob/e94627b/src/tree/avlTree.ts#L63) +[src/tree/avlTree.ts:63](https://github.com/havelessbemore/dastal/blob/2fe24da/src/tree/avlTree.ts#L63) ## Accessors @@ -118,7 +118,7 @@ The number of elements in the collection. #### Defined in -[src/tree/avlTree.ts:180](https://github.com/havelessbemore/dastal/blob/e94627b/src/tree/avlTree.ts#L180) +[src/tree/avlTree.ts:180](https://github.com/havelessbemore/dastal/blob/2fe24da/src/tree/avlTree.ts#L180) ## Methods @@ -142,7 +142,7 @@ An iterator through the list #### Defined in -[src/tree/avlTree.ts:196](https://github.com/havelessbemore/dastal/blob/e94627b/src/tree/avlTree.ts#L196) +[src/tree/avlTree.ts:196](https://github.com/havelessbemore/dastal/blob/2fe24da/src/tree/avlTree.ts#L196) ___ @@ -168,7 +168,7 @@ Inserts an element into the tree. #### Defined in -[src/tree/avlTree.ts:88](https://github.com/havelessbemore/dastal/blob/e94627b/src/tree/avlTree.ts#L88) +[src/tree/avlTree.ts:88](https://github.com/havelessbemore/dastal/blob/2fe24da/src/tree/avlTree.ts#L88) ___ @@ -188,7 +188,7 @@ Removes all elements. #### Defined in -[src/tree/avlTree.ts:120](https://github.com/havelessbemore/dastal/blob/e94627b/src/tree/avlTree.ts#L120) +[src/tree/avlTree.ts:120](https://github.com/havelessbemore/dastal/blob/2fe24da/src/tree/avlTree.ts#L120) ___ @@ -206,7 +206,7 @@ ___ #### Defined in -[src/tree/avlTree.ts:125](https://github.com/havelessbemore/dastal/blob/e94627b/src/tree/avlTree.ts#L125) +[src/tree/avlTree.ts:125](https://github.com/havelessbemore/dastal/blob/2fe24da/src/tree/avlTree.ts#L125) ___ @@ -232,7 +232,7 @@ Delete an element from the tree. #### Defined in -[src/tree/avlTree.ts:129](https://github.com/havelessbemore/dastal/blob/e94627b/src/tree/avlTree.ts#L129) +[src/tree/avlTree.ts:129](https://github.com/havelessbemore/dastal/blob/2fe24da/src/tree/avlTree.ts#L129) ___ @@ -258,7 +258,7 @@ Check if an element is in the tree. #### Defined in -[src/tree/avlTree.ts:140](https://github.com/havelessbemore/dastal/blob/e94627b/src/tree/avlTree.ts#L140) +[src/tree/avlTree.ts:140](https://github.com/havelessbemore/dastal/blob/2fe24da/src/tree/avlTree.ts#L140) ___ @@ -278,7 +278,7 @@ Get the maximum element. #### Defined in -[src/tree/avlTree.ts:144](https://github.com/havelessbemore/dastal/blob/e94627b/src/tree/avlTree.ts#L144) +[src/tree/avlTree.ts:144](https://github.com/havelessbemore/dastal/blob/2fe24da/src/tree/avlTree.ts#L144) ___ @@ -298,7 +298,7 @@ Get the minimum element. #### Defined in -[src/tree/avlTree.ts:148](https://github.com/havelessbemore/dastal/blob/e94627b/src/tree/avlTree.ts#L148) +[src/tree/avlTree.ts:148](https://github.com/havelessbemore/dastal/blob/2fe24da/src/tree/avlTree.ts#L148) ___ @@ -318,7 +318,7 @@ Remove the maximum element. #### Defined in -[src/tree/avlTree.ts:152](https://github.com/havelessbemore/dastal/blob/e94627b/src/tree/avlTree.ts#L152) +[src/tree/avlTree.ts:152](https://github.com/havelessbemore/dastal/blob/2fe24da/src/tree/avlTree.ts#L152) ___ @@ -338,7 +338,7 @@ Remove the minimum element. #### Defined in -[src/tree/avlTree.ts:166](https://github.com/havelessbemore/dastal/blob/e94627b/src/tree/avlTree.ts#L166) +[src/tree/avlTree.ts:166](https://github.com/havelessbemore/dastal/blob/2fe24da/src/tree/avlTree.ts#L166) ___ @@ -360,7 +360,7 @@ Iterate through the tree in sorted order (i.e in-order traversal). #### Defined in -[src/tree/avlTree.ts:184](https://github.com/havelessbemore/dastal/blob/e94627b/src/tree/avlTree.ts#L184) +[src/tree/avlTree.ts:184](https://github.com/havelessbemore/dastal/blob/2fe24da/src/tree/avlTree.ts#L184) ___ @@ -387,4 +387,4 @@ Update a specific element. #### Defined in -[src/tree/avlTree.ts:202](https://github.com/havelessbemore/dastal/blob/e94627b/src/tree/avlTree.ts#L202) +[src/tree/avlTree.ts:202](https://github.com/havelessbemore/dastal/blob/2fe24da/src/tree/avlTree.ts#L202) diff --git a/docs/classes/binaryheap.md b/docs/classes/binaryheap.md index 0a3bfb9..140e2d2 100644 --- a/docs/classes/binaryheap.md +++ b/docs/classes/binaryheap.md @@ -1,4 +1,4 @@ -[dastal - v3.0.0](../README.md) / BinaryHeap +[dastal - v4.0.0](../README.md) / BinaryHeap # Class: BinaryHeap @@ -79,7 +79,7 @@ Instantiate a heap. #### Defined in -[src/heap/binaryHeap.ts:32](https://github.com/havelessbemore/dastal/blob/e94627b/src/heap/binaryHeap.ts#L32) +[src/heap/binaryHeap.ts:32](https://github.com/havelessbemore/dastal/blob/2fe24da/src/heap/binaryHeap.ts#L32) ## Accessors @@ -99,7 +99,7 @@ The number of elements in the collection. #### Defined in -[src/heap/binaryHeap.ts:186](https://github.com/havelessbemore/dastal/blob/e94627b/src/heap/binaryHeap.ts#L186) +[src/heap/binaryHeap.ts:186](https://github.com/havelessbemore/dastal/blob/2fe24da/src/heap/binaryHeap.ts#L186) ## Methods @@ -123,7 +123,7 @@ An iterator through the list #### Defined in -[src/heap/binaryHeap.ts:213](https://github.com/havelessbemore/dastal/blob/e94627b/src/heap/binaryHeap.ts#L213) +[src/heap/binaryHeap.ts:213](https://github.com/havelessbemore/dastal/blob/2fe24da/src/heap/binaryHeap.ts#L213) ___ @@ -149,7 +149,7 @@ Insert a set of elements into the heap. #### Defined in -[src/heap/binaryHeap.ts:45](https://github.com/havelessbemore/dastal/blob/e94627b/src/heap/binaryHeap.ts#L45) +[src/heap/binaryHeap.ts:45](https://github.com/havelessbemore/dastal/blob/2fe24da/src/heap/binaryHeap.ts#L45) ___ @@ -169,7 +169,7 @@ Removes all elements. #### Defined in -[src/heap/binaryHeap.ts:73](https://github.com/havelessbemore/dastal/blob/e94627b/src/heap/binaryHeap.ts#L73) +[src/heap/binaryHeap.ts:73](https://github.com/havelessbemore/dastal/blob/2fe24da/src/heap/binaryHeap.ts#L73) ___ @@ -187,7 +187,7 @@ ___ #### Defined in -[src/heap/binaryHeap.ts:77](https://github.com/havelessbemore/dastal/blob/e94627b/src/heap/binaryHeap.ts#L77) +[src/heap/binaryHeap.ts:77](https://github.com/havelessbemore/dastal/blob/2fe24da/src/heap/binaryHeap.ts#L77) ___ @@ -213,7 +213,7 @@ Check if an element is in the heap. #### Defined in -[src/heap/binaryHeap.ts:81](https://github.com/havelessbemore/dastal/blob/e94627b/src/heap/binaryHeap.ts#L81) +[src/heap/binaryHeap.ts:81](https://github.com/havelessbemore/dastal/blob/2fe24da/src/heap/binaryHeap.ts#L81) ___ @@ -239,7 +239,7 @@ Delete an element from the heap. #### Defined in -[src/heap/binaryHeap.ts:85](https://github.com/havelessbemore/dastal/blob/e94627b/src/heap/binaryHeap.ts#L85) +[src/heap/binaryHeap.ts:85](https://github.com/havelessbemore/dastal/blob/2fe24da/src/heap/binaryHeap.ts#L85) ___ @@ -266,7 +266,7 @@ contain elements of both. Does not modify the input. #### Defined in -[src/heap/binaryHeap.ts:105](https://github.com/havelessbemore/dastal/blob/e94627b/src/heap/binaryHeap.ts#L105) +[src/heap/binaryHeap.ts:105](https://github.com/havelessbemore/dastal/blob/2fe24da/src/heap/binaryHeap.ts#L105) ___ @@ -286,7 +286,7 @@ Retrieves, but does not remove, the top of the heap. #### Defined in -[src/heap/binaryHeap.ts:124](https://github.com/havelessbemore/dastal/blob/e94627b/src/heap/binaryHeap.ts#L124) +[src/heap/binaryHeap.ts:124](https://github.com/havelessbemore/dastal/blob/2fe24da/src/heap/binaryHeap.ts#L124) ___ @@ -306,7 +306,7 @@ Remove the top of the heap (AKA extract). #### Defined in -[src/heap/binaryHeap.ts:128](https://github.com/havelessbemore/dastal/blob/e94627b/src/heap/binaryHeap.ts#L128) +[src/heap/binaryHeap.ts:128](https://github.com/havelessbemore/dastal/blob/2fe24da/src/heap/binaryHeap.ts#L128) ___ @@ -332,7 +332,7 @@ Inserts an element into the heap (AKA insert, add). #### Defined in -[src/heap/binaryHeap.ts:147](https://github.com/havelessbemore/dastal/blob/e94627b/src/heap/binaryHeap.ts#L147) +[src/heap/binaryHeap.ts:147](https://github.com/havelessbemore/dastal/blob/2fe24da/src/heap/binaryHeap.ts#L147) ___ @@ -358,7 +358,7 @@ Insert an element and then remove the top of the heap. #### Defined in -[src/heap/binaryHeap.ts:156](https://github.com/havelessbemore/dastal/blob/e94627b/src/heap/binaryHeap.ts#L156) +[src/heap/binaryHeap.ts:156](https://github.com/havelessbemore/dastal/blob/2fe24da/src/heap/binaryHeap.ts#L156) ___ @@ -384,7 +384,7 @@ Remove the top of the heap and then insert a new element (AKA popPush). #### Defined in -[src/heap/binaryHeap.ts:169](https://github.com/havelessbemore/dastal/blob/e94627b/src/heap/binaryHeap.ts#L169) +[src/heap/binaryHeap.ts:169](https://github.com/havelessbemore/dastal/blob/2fe24da/src/heap/binaryHeap.ts#L169) ___ @@ -406,7 +406,7 @@ Iterate through the heap in sorted order. #### Defined in -[src/heap/binaryHeap.ts:190](https://github.com/havelessbemore/dastal/blob/e94627b/src/heap/binaryHeap.ts#L190) +[src/heap/binaryHeap.ts:190](https://github.com/havelessbemore/dastal/blob/2fe24da/src/heap/binaryHeap.ts#L190) ___ @@ -433,4 +433,4 @@ Update a specific element. #### Defined in -[src/heap/binaryHeap.ts:217](https://github.com/havelessbemore/dastal/blob/e94627b/src/heap/binaryHeap.ts#L217) +[src/heap/binaryHeap.ts:217](https://github.com/havelessbemore/dastal/blob/2fe24da/src/heap/binaryHeap.ts#L217) diff --git a/docs/classes/doublylinkedlist.md b/docs/classes/doublylinkedlist.md index 6a6be4d..c56167d 100644 --- a/docs/classes/doublylinkedlist.md +++ b/docs/classes/doublylinkedlist.md @@ -1,4 +1,4 @@ -[dastal - v3.0.0](../README.md) / DoublyLinkedList +[dastal - v4.0.0](../README.md) / DoublyLinkedList # Class: DoublyLinkedList @@ -72,7 +72,7 @@ Instantiate the list. #### Defined in -[src/list/doublyLinkedList.ts:20](https://github.com/havelessbemore/dastal/blob/e94627b/src/list/doublyLinkedList.ts#L20) +[src/list/doublyLinkedList.ts:20](https://github.com/havelessbemore/dastal/blob/2fe24da/src/list/doublyLinkedList.ts#L20) ## Accessors @@ -92,7 +92,7 @@ The number of elements in the collection. #### Defined in -[src/list/doublyLinkedList.ts:201](https://github.com/havelessbemore/dastal/blob/e94627b/src/list/doublyLinkedList.ts#L201) +[src/list/doublyLinkedList.ts:201](https://github.com/havelessbemore/dastal/blob/2fe24da/src/list/doublyLinkedList.ts#L201) ## Methods @@ -116,7 +116,7 @@ An iterator through the list #### Defined in -[src/list/doublyLinkedList.ts:250](https://github.com/havelessbemore/dastal/blob/e94627b/src/list/doublyLinkedList.ts#L250) +[src/list/doublyLinkedList.ts:250](https://github.com/havelessbemore/dastal/blob/2fe24da/src/list/doublyLinkedList.ts#L250) ___ @@ -143,7 +143,7 @@ Add the element at the specified index. #### Defined in -[src/list/doublyLinkedList.ts:33](https://github.com/havelessbemore/dastal/blob/e94627b/src/list/doublyLinkedList.ts#L33) +[src/list/doublyLinkedList.ts:33](https://github.com/havelessbemore/dastal/blob/2fe24da/src/list/doublyLinkedList.ts#L33) ___ @@ -170,7 +170,7 @@ Add elements at the specified index. #### Defined in -[src/list/doublyLinkedList.ts:44](https://github.com/havelessbemore/dastal/blob/e94627b/src/list/doublyLinkedList.ts#L44) +[src/list/doublyLinkedList.ts:44](https://github.com/havelessbemore/dastal/blob/2fe24da/src/list/doublyLinkedList.ts#L44) ___ @@ -190,7 +190,7 @@ Removes all elements. #### Defined in -[src/list/doublyLinkedList.ts:51](https://github.com/havelessbemore/dastal/blob/e94627b/src/list/doublyLinkedList.ts#L51) +[src/list/doublyLinkedList.ts:51](https://github.com/havelessbemore/dastal/blob/2fe24da/src/list/doublyLinkedList.ts#L51) ___ @@ -216,7 +216,7 @@ Combines the list with multiple iterables into a new list. Does not modify the e #### Defined in -[src/list/doublyLinkedList.ts:56](https://github.com/havelessbemore/dastal/blob/e94627b/src/list/doublyLinkedList.ts#L56) +[src/list/doublyLinkedList.ts:56](https://github.com/havelessbemore/dastal/blob/2fe24da/src/list/doublyLinkedList.ts#L56) ___ @@ -250,7 +250,7 @@ the copied sequence will be trimmed to fit list.size #### Defined in -[src/list/doublyLinkedList.ts:64](https://github.com/havelessbemore/dastal/blob/e94627b/src/list/doublyLinkedList.ts#L64) +[src/list/doublyLinkedList.ts:64](https://github.com/havelessbemore/dastal/blob/2fe24da/src/list/doublyLinkedList.ts#L64) ___ @@ -281,7 +281,7 @@ end of the list. For example, -2 refers to the second to last element of the lis #### Defined in -[src/list/doublyLinkedList.ts:102](https://github.com/havelessbemore/dastal/blob/e94627b/src/list/doublyLinkedList.ts#L102) +[src/list/doublyLinkedList.ts:102](https://github.com/havelessbemore/dastal/blob/2fe24da/src/list/doublyLinkedList.ts#L102) ___ @@ -307,7 +307,7 @@ Return the element at the specified index. #### Defined in -[src/list/doublyLinkedList.ts:115](https://github.com/havelessbemore/dastal/blob/e94627b/src/list/doublyLinkedList.ts#L115) +[src/list/doublyLinkedList.ts:115](https://github.com/havelessbemore/dastal/blob/2fe24da/src/list/doublyLinkedList.ts#L115) ___ @@ -334,7 +334,7 @@ Update the element at the specified index. #### Defined in -[src/list/doublyLinkedList.ts:119](https://github.com/havelessbemore/dastal/blob/e94627b/src/list/doublyLinkedList.ts#L119) +[src/list/doublyLinkedList.ts:119](https://github.com/havelessbemore/dastal/blob/2fe24da/src/list/doublyLinkedList.ts#L119) ___ @@ -354,7 +354,7 @@ Retrieves and removes the end of the list. #### Defined in -[src/list/doublyLinkedList.ts:129](https://github.com/havelessbemore/dastal/blob/e94627b/src/list/doublyLinkedList.ts#L129) +[src/list/doublyLinkedList.ts:129](https://github.com/havelessbemore/dastal/blob/2fe24da/src/list/doublyLinkedList.ts#L129) ___ @@ -380,7 +380,7 @@ Inserts the specified value into the end of the list #### Defined in -[src/list/doublyLinkedList.ts:140](https://github.com/havelessbemore/dastal/blob/e94627b/src/list/doublyLinkedList.ts#L140) +[src/list/doublyLinkedList.ts:140](https://github.com/havelessbemore/dastal/blob/2fe24da/src/list/doublyLinkedList.ts#L140) ___ @@ -409,7 +409,7 @@ end of the list. For example, -2 refers to the second to last element of the lis #### Defined in -[src/list/doublyLinkedList.ts:147](https://github.com/havelessbemore/dastal/blob/e94627b/src/list/doublyLinkedList.ts#L147) +[src/list/doublyLinkedList.ts:147](https://github.com/havelessbemore/dastal/blob/2fe24da/src/list/doublyLinkedList.ts#L147) ___ @@ -439,7 +439,7 @@ end of the list. For example, -2 refers to the second to last element of the lis #### Defined in -[src/list/doublyLinkedList.ts:158](https://github.com/havelessbemore/dastal/blob/e94627b/src/list/doublyLinkedList.ts#L158) +[src/list/doublyLinkedList.ts:158](https://github.com/havelessbemore/dastal/blob/2fe24da/src/list/doublyLinkedList.ts#L158) ___ @@ -466,7 +466,7 @@ Update the element at the specified index. #### Defined in -[src/list/doublyLinkedList.ts:180](https://github.com/havelessbemore/dastal/blob/e94627b/src/list/doublyLinkedList.ts#L180) +[src/list/doublyLinkedList.ts:180](https://github.com/havelessbemore/dastal/blob/2fe24da/src/list/doublyLinkedList.ts#L180) ___ @@ -486,7 +486,7 @@ Retrieves and removes the first element in the list. #### Defined in -[src/list/doublyLinkedList.ts:190](https://github.com/havelessbemore/dastal/blob/e94627b/src/list/doublyLinkedList.ts#L190) +[src/list/doublyLinkedList.ts:190](https://github.com/havelessbemore/dastal/blob/2fe24da/src/list/doublyLinkedList.ts#L190) ___ @@ -516,7 +516,7 @@ end of the list. For example, -2 refers to the second to last element of the lis #### Defined in -[src/list/doublyLinkedList.ts:205](https://github.com/havelessbemore/dastal/blob/e94627b/src/list/doublyLinkedList.ts#L205) +[src/list/doublyLinkedList.ts:205](https://github.com/havelessbemore/dastal/blob/2fe24da/src/list/doublyLinkedList.ts#L205) ___ @@ -542,7 +542,7 @@ Sorts the elements in place. #### Defined in -[src/list/doublyLinkedList.ts:235](https://github.com/havelessbemore/dastal/blob/e94627b/src/list/doublyLinkedList.ts#L235) +[src/list/doublyLinkedList.ts:235](https://github.com/havelessbemore/dastal/blob/2fe24da/src/list/doublyLinkedList.ts#L235) ___ @@ -571,7 +571,7 @@ Returns any deleted elements. #### Defined in -[src/list/doublyLinkedList.ts:209](https://github.com/havelessbemore/dastal/blob/e94627b/src/list/doublyLinkedList.ts#L209) +[src/list/doublyLinkedList.ts:209](https://github.com/havelessbemore/dastal/blob/2fe24da/src/list/doublyLinkedList.ts#L209) ___ @@ -597,7 +597,7 @@ Inserts the specified value into the front of the list #### Defined in -[src/list/doublyLinkedList.ts:256](https://github.com/havelessbemore/dastal/blob/e94627b/src/list/doublyLinkedList.ts#L256) +[src/list/doublyLinkedList.ts:256](https://github.com/havelessbemore/dastal/blob/2fe24da/src/list/doublyLinkedList.ts#L256) ___ @@ -623,7 +623,7 @@ Update the elements of the list #### Defined in -[src/list/doublyLinkedList.ts:263](https://github.com/havelessbemore/dastal/blob/e94627b/src/list/doublyLinkedList.ts#L263) +[src/list/doublyLinkedList.ts:263](https://github.com/havelessbemore/dastal/blob/2fe24da/src/list/doublyLinkedList.ts#L263) ▸ **update**(`min`, `callback`): [DoublyLinkedList](doublylinkedlist.md) @@ -649,7 +649,7 @@ end of the list. For example, -2 refers to the second to last element of the lis #### Defined in -[src/list/doublyLinkedList.ts:264](https://github.com/havelessbemore/dastal/blob/e94627b/src/list/doublyLinkedList.ts#L264) +[src/list/doublyLinkedList.ts:264](https://github.com/havelessbemore/dastal/blob/2fe24da/src/list/doublyLinkedList.ts#L264) ▸ **update**(`min`, `max`, `callback`): [DoublyLinkedList](doublylinkedlist.md) @@ -676,7 +676,7 @@ end of the list. For example, -2 refers to the second to last element of the lis #### Defined in -[src/list/doublyLinkedList.ts:265](https://github.com/havelessbemore/dastal/blob/e94627b/src/list/doublyLinkedList.ts#L265) +[src/list/doublyLinkedList.ts:265](https://github.com/havelessbemore/dastal/blob/2fe24da/src/list/doublyLinkedList.ts#L265) ___ @@ -708,4 +708,4 @@ end of the list. For example, -2 refers to the second to last element of the lis #### Defined in -[src/list/doublyLinkedList.ts:296](https://github.com/havelessbemore/dastal/blob/e94627b/src/list/doublyLinkedList.ts#L296) +[src/list/doublyLinkedList.ts:296](https://github.com/havelessbemore/dastal/blob/2fe24da/src/list/doublyLinkedList.ts#L296) diff --git a/docs/classes/inordersegmenttree.md b/docs/classes/inordersegmenttree.md index 7b01e70..f0e719d 100644 --- a/docs/classes/inordersegmenttree.md +++ b/docs/classes/inordersegmenttree.md @@ -1,4 +1,4 @@ -[dastal - v3.0.0](../README.md) / InOrderSegmentTree +[dastal - v4.0.0](../README.md) / InOrderSegmentTree # Class: InOrderSegmentTree @@ -61,7 +61,7 @@ Construct a new segment tree #### Defined in -[src/segmentTree/inOrderSegmentTree.ts:33](https://github.com/havelessbemore/dastal/blob/e94627b/src/segmentTree/inOrderSegmentTree.ts#L33) +[src/segmentTree/inOrderSegmentTree.ts:33](https://github.com/havelessbemore/dastal/blob/2fe24da/src/segmentTree/inOrderSegmentTree.ts#L33) ## Properties @@ -75,7 +75,7 @@ n elements require 2n memory. #### Defined in -[src/segmentTree/inOrderSegmentTree.ts:25](https://github.com/havelessbemore/dastal/blob/e94627b/src/segmentTree/inOrderSegmentTree.ts#L25) +[src/segmentTree/inOrderSegmentTree.ts:25](https://github.com/havelessbemore/dastal/blob/2fe24da/src/segmentTree/inOrderSegmentTree.ts#L25) ## Accessors @@ -95,7 +95,7 @@ The number of elements in the collection. #### Defined in -[src/segmentTree/inOrderSegmentTree.ts:107](https://github.com/havelessbemore/dastal/blob/e94627b/src/segmentTree/inOrderSegmentTree.ts#L107) +[src/segmentTree/inOrderSegmentTree.ts:107](https://github.com/havelessbemore/dastal/blob/2fe24da/src/segmentTree/inOrderSegmentTree.ts#L107) ## Methods @@ -115,7 +115,7 @@ Return an iterator through the tree's elements #### Defined in -[src/segmentTree/inOrderSegmentTree.ts:114](https://github.com/havelessbemore/dastal/blob/e94627b/src/segmentTree/inOrderSegmentTree.ts#L114) +[src/segmentTree/inOrderSegmentTree.ts:114](https://github.com/havelessbemore/dastal/blob/2fe24da/src/segmentTree/inOrderSegmentTree.ts#L114) ___ @@ -135,7 +135,7 @@ Removes all elements. #### Defined in -[src/segmentTree/inOrderSegmentTree.ts:46](https://github.com/havelessbemore/dastal/blob/e94627b/src/segmentTree/inOrderSegmentTree.ts#L46) +[src/segmentTree/inOrderSegmentTree.ts:46](https://github.com/havelessbemore/dastal/blob/2fe24da/src/segmentTree/inOrderSegmentTree.ts#L46) ___ @@ -155,7 +155,7 @@ Retrieves and removes the last element #### Defined in -[src/segmentTree/inOrderSegmentTree.ts:50](https://github.com/havelessbemore/dastal/blob/e94627b/src/segmentTree/inOrderSegmentTree.ts#L50) +[src/segmentTree/inOrderSegmentTree.ts:50](https://github.com/havelessbemore/dastal/blob/2fe24da/src/segmentTree/inOrderSegmentTree.ts#L50) ___ @@ -181,7 +181,7 @@ Appends an element to the tree #### Defined in -[src/segmentTree/inOrderSegmentTree.ts:68](https://github.com/havelessbemore/dastal/blob/e94627b/src/segmentTree/inOrderSegmentTree.ts#L68) +[src/segmentTree/inOrderSegmentTree.ts:68](https://github.com/havelessbemore/dastal/blob/2fe24da/src/segmentTree/inOrderSegmentTree.ts#L68) ___ @@ -208,7 +208,7 @@ Get the aggregated result of a given range in the tree #### Defined in -[src/segmentTree/inOrderSegmentTree.ts:81](https://github.com/havelessbemore/dastal/blob/e94627b/src/segmentTree/inOrderSegmentTree.ts#L81) +[src/segmentTree/inOrderSegmentTree.ts:81](https://github.com/havelessbemore/dastal/blob/2fe24da/src/segmentTree/inOrderSegmentTree.ts#L81) ___ @@ -236,4 +236,4 @@ Update the elements of a given range in the tree #### Defined in -[src/segmentTree/inOrderSegmentTree.ts:120](https://github.com/havelessbemore/dastal/blob/e94627b/src/segmentTree/inOrderSegmentTree.ts#L120) +[src/segmentTree/inOrderSegmentTree.ts:120](https://github.com/havelessbemore/dastal/blob/2fe24da/src/segmentTree/inOrderSegmentTree.ts#L120) diff --git a/docs/classes/levelordersegmenttree.md b/docs/classes/levelordersegmenttree.md index 7bc7ee9..7d186d5 100644 --- a/docs/classes/levelordersegmenttree.md +++ b/docs/classes/levelordersegmenttree.md @@ -1,4 +1,4 @@ -[dastal - v3.0.0](../README.md) / LevelOrderSegmentTree +[dastal - v4.0.0](../README.md) / LevelOrderSegmentTree # Class: LevelOrderSegmentTree @@ -61,7 +61,7 @@ Construct a new [SegmentTree](../interfaces/segmenttree.md) #### Defined in -[src/segmentTree/levelOrderSegmentTree.ts:39](https://github.com/havelessbemore/dastal/blob/e94627b/src/segmentTree/levelOrderSegmentTree.ts#L39) +[src/segmentTree/levelOrderSegmentTree.ts:39](https://github.com/havelessbemore/dastal/blob/2fe24da/src/segmentTree/levelOrderSegmentTree.ts#L39) ## Properties @@ -75,7 +75,7 @@ n elements require 2^⌈log2(2n)⌉ - 1 memory: #### Defined in -[src/segmentTree/levelOrderSegmentTree.ts:23](https://github.com/havelessbemore/dastal/blob/e94627b/src/segmentTree/levelOrderSegmentTree.ts#L23) +[src/segmentTree/levelOrderSegmentTree.ts:23](https://github.com/havelessbemore/dastal/blob/2fe24da/src/segmentTree/levelOrderSegmentTree.ts#L23) ## Accessors @@ -95,7 +95,7 @@ The number of elements in the collection. #### Defined in -[src/segmentTree/levelOrderSegmentTree.ts:123](https://github.com/havelessbemore/dastal/blob/e94627b/src/segmentTree/levelOrderSegmentTree.ts#L123) +[src/segmentTree/levelOrderSegmentTree.ts:123](https://github.com/havelessbemore/dastal/blob/2fe24da/src/segmentTree/levelOrderSegmentTree.ts#L123) ## Methods @@ -115,7 +115,7 @@ Return an iterator through the elements #### Defined in -[src/segmentTree/levelOrderSegmentTree.ts:130](https://github.com/havelessbemore/dastal/blob/e94627b/src/segmentTree/levelOrderSegmentTree.ts#L130) +[src/segmentTree/levelOrderSegmentTree.ts:130](https://github.com/havelessbemore/dastal/blob/2fe24da/src/segmentTree/levelOrderSegmentTree.ts#L130) ___ @@ -135,7 +135,7 @@ Removes all elements. #### Defined in -[src/segmentTree/levelOrderSegmentTree.ts:54](https://github.com/havelessbemore/dastal/blob/e94627b/src/segmentTree/levelOrderSegmentTree.ts#L54) +[src/segmentTree/levelOrderSegmentTree.ts:54](https://github.com/havelessbemore/dastal/blob/2fe24da/src/segmentTree/levelOrderSegmentTree.ts#L54) ___ @@ -155,7 +155,7 @@ Retrieves and removes the last element #### Defined in -[src/segmentTree/levelOrderSegmentTree.ts:60](https://github.com/havelessbemore/dastal/blob/e94627b/src/segmentTree/levelOrderSegmentTree.ts#L60) +[src/segmentTree/levelOrderSegmentTree.ts:60](https://github.com/havelessbemore/dastal/blob/2fe24da/src/segmentTree/levelOrderSegmentTree.ts#L60) ___ @@ -181,7 +181,7 @@ Appends an element to the tree #### Defined in -[src/segmentTree/levelOrderSegmentTree.ts:77](https://github.com/havelessbemore/dastal/blob/e94627b/src/segmentTree/levelOrderSegmentTree.ts#L77) +[src/segmentTree/levelOrderSegmentTree.ts:77](https://github.com/havelessbemore/dastal/blob/2fe24da/src/segmentTree/levelOrderSegmentTree.ts#L77) ___ @@ -208,7 +208,7 @@ Get the aggregated result of a given range in the tree #### Defined in -[src/segmentTree/levelOrderSegmentTree.ts:95](https://github.com/havelessbemore/dastal/blob/e94627b/src/segmentTree/levelOrderSegmentTree.ts#L95) +[src/segmentTree/levelOrderSegmentTree.ts:95](https://github.com/havelessbemore/dastal/blob/2fe24da/src/segmentTree/levelOrderSegmentTree.ts#L95) ___ @@ -236,4 +236,4 @@ Update the elements of a given range in the tree #### Defined in -[src/segmentTree/levelOrderSegmentTree.ts:136](https://github.com/havelessbemore/dastal/blob/e94627b/src/segmentTree/levelOrderSegmentTree.ts#L136) +[src/segmentTree/levelOrderSegmentTree.ts:136](https://github.com/havelessbemore/dastal/blob/2fe24da/src/segmentTree/levelOrderSegmentTree.ts#L136) diff --git a/docs/classes/linkedlist.md b/docs/classes/linkedlist.md index cc764d7..1e17d01 100644 --- a/docs/classes/linkedlist.md +++ b/docs/classes/linkedlist.md @@ -1,4 +1,4 @@ -[dastal - v3.0.0](../README.md) / LinkedList +[dastal - v4.0.0](../README.md) / LinkedList # Class: LinkedList @@ -70,7 +70,7 @@ Instantiate the list. #### Defined in -[src/list/linkedList.ts:22](https://github.com/havelessbemore/dastal/blob/e94627b/src/list/linkedList.ts#L22) +[src/list/linkedList.ts:22](https://github.com/havelessbemore/dastal/blob/2fe24da/src/list/linkedList.ts#L22) ## Accessors @@ -90,7 +90,7 @@ The number of elements in the collection. #### Defined in -[src/list/linkedList.ts:208](https://github.com/havelessbemore/dastal/blob/e94627b/src/list/linkedList.ts#L208) +[src/list/linkedList.ts:208](https://github.com/havelessbemore/dastal/blob/2fe24da/src/list/linkedList.ts#L208) ## Methods @@ -114,7 +114,7 @@ An iterator through the list #### Defined in -[src/list/linkedList.ts:258](https://github.com/havelessbemore/dastal/blob/e94627b/src/list/linkedList.ts#L258) +[src/list/linkedList.ts:258](https://github.com/havelessbemore/dastal/blob/2fe24da/src/list/linkedList.ts#L258) ___ @@ -141,7 +141,7 @@ Add the element at the specified index. #### Defined in -[src/list/linkedList.ts:35](https://github.com/havelessbemore/dastal/blob/e94627b/src/list/linkedList.ts#L35) +[src/list/linkedList.ts:35](https://github.com/havelessbemore/dastal/blob/2fe24da/src/list/linkedList.ts#L35) ___ @@ -168,7 +168,7 @@ Add elements at the specified index. #### Defined in -[src/list/linkedList.ts:46](https://github.com/havelessbemore/dastal/blob/e94627b/src/list/linkedList.ts#L46) +[src/list/linkedList.ts:46](https://github.com/havelessbemore/dastal/blob/2fe24da/src/list/linkedList.ts#L46) ___ @@ -188,7 +188,7 @@ Removes all elements. #### Defined in -[src/list/linkedList.ts:55](https://github.com/havelessbemore/dastal/blob/e94627b/src/list/linkedList.ts#L55) +[src/list/linkedList.ts:55](https://github.com/havelessbemore/dastal/blob/2fe24da/src/list/linkedList.ts#L55) ___ @@ -214,7 +214,7 @@ Combines the list with multiple iterables into a new list. Does not modify the e #### Defined in -[src/list/linkedList.ts:60](https://github.com/havelessbemore/dastal/blob/e94627b/src/list/linkedList.ts#L60) +[src/list/linkedList.ts:60](https://github.com/havelessbemore/dastal/blob/2fe24da/src/list/linkedList.ts#L60) ___ @@ -248,7 +248,7 @@ the copied sequence will be trimmed to fit list.size #### Defined in -[src/list/linkedList.ts:68](https://github.com/havelessbemore/dastal/blob/e94627b/src/list/linkedList.ts#L68) +[src/list/linkedList.ts:68](https://github.com/havelessbemore/dastal/blob/2fe24da/src/list/linkedList.ts#L68) ___ @@ -279,7 +279,7 @@ end of the list. For example, -2 refers to the second to last element of the lis #### Defined in -[src/list/linkedList.ts:111](https://github.com/havelessbemore/dastal/blob/e94627b/src/list/linkedList.ts#L111) +[src/list/linkedList.ts:111](https://github.com/havelessbemore/dastal/blob/2fe24da/src/list/linkedList.ts#L111) ___ @@ -305,7 +305,7 @@ Return the element at the specified index. #### Defined in -[src/list/linkedList.ts:124](https://github.com/havelessbemore/dastal/blob/e94627b/src/list/linkedList.ts#L124) +[src/list/linkedList.ts:124](https://github.com/havelessbemore/dastal/blob/2fe24da/src/list/linkedList.ts#L124) ___ @@ -332,7 +332,7 @@ Update the element at the specified index. #### Defined in -[src/list/linkedList.ts:131](https://github.com/havelessbemore/dastal/blob/e94627b/src/list/linkedList.ts#L131) +[src/list/linkedList.ts:131](https://github.com/havelessbemore/dastal/blob/2fe24da/src/list/linkedList.ts#L131) ___ @@ -352,7 +352,7 @@ Retrieves and removes the end of the list. #### Defined in -[src/list/linkedList.ts:141](https://github.com/havelessbemore/dastal/blob/e94627b/src/list/linkedList.ts#L141) +[src/list/linkedList.ts:141](https://github.com/havelessbemore/dastal/blob/2fe24da/src/list/linkedList.ts#L141) ___ @@ -378,7 +378,7 @@ Inserts the specified value into the end of the list #### Defined in -[src/list/linkedList.ts:152](https://github.com/havelessbemore/dastal/blob/e94627b/src/list/linkedList.ts#L152) +[src/list/linkedList.ts:152](https://github.com/havelessbemore/dastal/blob/2fe24da/src/list/linkedList.ts#L152) ___ @@ -407,7 +407,7 @@ end of the list. For example, -2 refers to the second to last element of the lis #### Defined in -[src/list/linkedList.ts:159](https://github.com/havelessbemore/dastal/blob/e94627b/src/list/linkedList.ts#L159) +[src/list/linkedList.ts:159](https://github.com/havelessbemore/dastal/blob/2fe24da/src/list/linkedList.ts#L159) ___ @@ -437,7 +437,7 @@ end of the list. For example, -2 refers to the second to last element of the lis #### Defined in -[src/list/linkedList.ts:172](https://github.com/havelessbemore/dastal/blob/e94627b/src/list/linkedList.ts#L172) +[src/list/linkedList.ts:172](https://github.com/havelessbemore/dastal/blob/2fe24da/src/list/linkedList.ts#L172) ___ @@ -464,7 +464,7 @@ Update the element at the specified index. #### Defined in -[src/list/linkedList.ts:194](https://github.com/havelessbemore/dastal/blob/e94627b/src/list/linkedList.ts#L194) +[src/list/linkedList.ts:194](https://github.com/havelessbemore/dastal/blob/2fe24da/src/list/linkedList.ts#L194) ___ @@ -484,7 +484,7 @@ Retrieves and removes the first element in the list. #### Defined in -[src/list/linkedList.ts:204](https://github.com/havelessbemore/dastal/blob/e94627b/src/list/linkedList.ts#L204) +[src/list/linkedList.ts:204](https://github.com/havelessbemore/dastal/blob/2fe24da/src/list/linkedList.ts#L204) ___ @@ -514,7 +514,7 @@ end of the list. For example, -2 refers to the second to last element of the lis #### Defined in -[src/list/linkedList.ts:212](https://github.com/havelessbemore/dastal/blob/e94627b/src/list/linkedList.ts#L212) +[src/list/linkedList.ts:212](https://github.com/havelessbemore/dastal/blob/2fe24da/src/list/linkedList.ts#L212) ___ @@ -540,7 +540,7 @@ Sorts the elements in place. #### Defined in -[src/list/linkedList.ts:243](https://github.com/havelessbemore/dastal/blob/e94627b/src/list/linkedList.ts#L243) +[src/list/linkedList.ts:243](https://github.com/havelessbemore/dastal/blob/2fe24da/src/list/linkedList.ts#L243) ___ @@ -569,7 +569,7 @@ Returns any deleted elements. #### Defined in -[src/list/linkedList.ts:216](https://github.com/havelessbemore/dastal/blob/e94627b/src/list/linkedList.ts#L216) +[src/list/linkedList.ts:216](https://github.com/havelessbemore/dastal/blob/2fe24da/src/list/linkedList.ts#L216) ___ @@ -595,7 +595,7 @@ Inserts the specified value into the front of the list #### Defined in -[src/list/linkedList.ts:264](https://github.com/havelessbemore/dastal/blob/e94627b/src/list/linkedList.ts#L264) +[src/list/linkedList.ts:264](https://github.com/havelessbemore/dastal/blob/2fe24da/src/list/linkedList.ts#L264) ___ @@ -621,7 +621,7 @@ Update the elements of the list #### Defined in -[src/list/linkedList.ts:268](https://github.com/havelessbemore/dastal/blob/e94627b/src/list/linkedList.ts#L268) +[src/list/linkedList.ts:268](https://github.com/havelessbemore/dastal/blob/2fe24da/src/list/linkedList.ts#L268) ▸ **update**(`min`, `callback`): [LinkedList](linkedlist.md) @@ -647,7 +647,7 @@ end of the list. For example, -2 refers to the second to last element of the lis #### Defined in -[src/list/linkedList.ts:269](https://github.com/havelessbemore/dastal/blob/e94627b/src/list/linkedList.ts#L269) +[src/list/linkedList.ts:269](https://github.com/havelessbemore/dastal/blob/2fe24da/src/list/linkedList.ts#L269) ▸ **update**(`min`, `max`, `callback`): [LinkedList](linkedlist.md) @@ -674,7 +674,7 @@ end of the list. For example, -2 refers to the second to last element of the lis #### Defined in -[src/list/linkedList.ts:270](https://github.com/havelessbemore/dastal/blob/e94627b/src/list/linkedList.ts#L270) +[src/list/linkedList.ts:270](https://github.com/havelessbemore/dastal/blob/2fe24da/src/list/linkedList.ts#L270) ___ @@ -706,4 +706,4 @@ end of the list. For example, -2 refers to the second to last element of the lis #### Defined in -[src/list/linkedList.ts:301](https://github.com/havelessbemore/dastal/blob/e94627b/src/list/linkedList.ts#L301) +[src/list/linkedList.ts:301](https://github.com/havelessbemore/dastal/blob/2fe24da/src/list/linkedList.ts#L301) diff --git a/docs/classes/linkedqueue.md b/docs/classes/linkedqueue.md index b62d065..7584502 100644 --- a/docs/classes/linkedqueue.md +++ b/docs/classes/linkedqueue.md @@ -1,4 +1,4 @@ -[dastal - v3.0.0](../README.md) / LinkedQueue +[dastal - v4.0.0](../README.md) / LinkedQueue # Class: LinkedQueue @@ -54,7 +54,7 @@ Instantiate the queue. #### Defined in -[src/queue/linkedQueue.ts:11](https://github.com/havelessbemore/dastal/blob/e94627b/src/queue/linkedQueue.ts#L11) +[src/queue/linkedQueue.ts:11](https://github.com/havelessbemore/dastal/blob/2fe24da/src/queue/linkedQueue.ts#L11) ## Accessors @@ -74,7 +74,7 @@ The number of elements in the collection. #### Defined in -[src/queue/linkedQueue.ts:37](https://github.com/havelessbemore/dastal/blob/e94627b/src/queue/linkedQueue.ts#L37) +[src/queue/linkedQueue.ts:37](https://github.com/havelessbemore/dastal/blob/2fe24da/src/queue/linkedQueue.ts#L37) ## Methods @@ -98,7 +98,7 @@ An iterator through the queue #### Defined in -[src/queue/linkedQueue.ts:47](https://github.com/havelessbemore/dastal/blob/e94627b/src/queue/linkedQueue.ts#L47) +[src/queue/linkedQueue.ts:47](https://github.com/havelessbemore/dastal/blob/2fe24da/src/queue/linkedQueue.ts#L47) ___ @@ -118,7 +118,7 @@ Removes all elements. #### Defined in -[src/queue/linkedQueue.ts:21](https://github.com/havelessbemore/dastal/blob/e94627b/src/queue/linkedQueue.ts#L21) +[src/queue/linkedQueue.ts:21](https://github.com/havelessbemore/dastal/blob/2fe24da/src/queue/linkedQueue.ts#L21) ___ @@ -138,7 +138,7 @@ Retrieves and removes the head of this queue #### Defined in -[src/queue/linkedQueue.ts:25](https://github.com/havelessbemore/dastal/blob/e94627b/src/queue/linkedQueue.ts#L25) +[src/queue/linkedQueue.ts:25](https://github.com/havelessbemore/dastal/blob/2fe24da/src/queue/linkedQueue.ts#L25) ___ @@ -164,7 +164,7 @@ Inserts the specified value into this queue #### Defined in -[src/queue/linkedQueue.ts:29](https://github.com/havelessbemore/dastal/blob/e94627b/src/queue/linkedQueue.ts#L29) +[src/queue/linkedQueue.ts:29](https://github.com/havelessbemore/dastal/blob/2fe24da/src/queue/linkedQueue.ts#L29) ___ @@ -184,4 +184,4 @@ Retrieves, but does not remove, the head of this queue #### Defined in -[src/queue/linkedQueue.ts:33](https://github.com/havelessbemore/dastal/blob/e94627b/src/queue/linkedQueue.ts#L33) +[src/queue/linkedQueue.ts:33](https://github.com/havelessbemore/dastal/blob/2fe24da/src/queue/linkedQueue.ts#L33) diff --git a/docs/classes/linkedstack.md b/docs/classes/linkedstack.md index b739757..f4457eb 100644 --- a/docs/classes/linkedstack.md +++ b/docs/classes/linkedstack.md @@ -1,4 +1,4 @@ -[dastal - v3.0.0](../README.md) / LinkedStack +[dastal - v4.0.0](../README.md) / LinkedStack # Class: LinkedStack @@ -54,7 +54,7 @@ Instantiate the stack. #### Defined in -[src/stack/linkedStack.ts:11](https://github.com/havelessbemore/dastal/blob/e94627b/src/stack/linkedStack.ts#L11) +[src/stack/linkedStack.ts:11](https://github.com/havelessbemore/dastal/blob/2fe24da/src/stack/linkedStack.ts#L11) ## Accessors @@ -74,7 +74,7 @@ The number of elements in the collection. #### Defined in -[src/stack/linkedStack.ts:40](https://github.com/havelessbemore/dastal/blob/e94627b/src/stack/linkedStack.ts#L40) +[src/stack/linkedStack.ts:40](https://github.com/havelessbemore/dastal/blob/2fe24da/src/stack/linkedStack.ts#L40) ## Methods @@ -98,7 +98,7 @@ An iterator through the stack #### Defined in -[src/stack/linkedStack.ts:50](https://github.com/havelessbemore/dastal/blob/e94627b/src/stack/linkedStack.ts#L50) +[src/stack/linkedStack.ts:50](https://github.com/havelessbemore/dastal/blob/2fe24da/src/stack/linkedStack.ts#L50) ___ @@ -118,7 +118,7 @@ Removes all elements. #### Defined in -[src/stack/linkedStack.ts:24](https://github.com/havelessbemore/dastal/blob/e94627b/src/stack/linkedStack.ts#L24) +[src/stack/linkedStack.ts:24](https://github.com/havelessbemore/dastal/blob/2fe24da/src/stack/linkedStack.ts#L24) ___ @@ -138,7 +138,7 @@ Retrieves, but does not remove, the top of the stack #### Defined in -[src/stack/linkedStack.ts:28](https://github.com/havelessbemore/dastal/blob/e94627b/src/stack/linkedStack.ts#L28) +[src/stack/linkedStack.ts:28](https://github.com/havelessbemore/dastal/blob/2fe24da/src/stack/linkedStack.ts#L28) ___ @@ -158,7 +158,7 @@ Retrieves and removes the top of the stack #### Defined in -[src/stack/linkedStack.ts:32](https://github.com/havelessbemore/dastal/blob/e94627b/src/stack/linkedStack.ts#L32) +[src/stack/linkedStack.ts:32](https://github.com/havelessbemore/dastal/blob/2fe24da/src/stack/linkedStack.ts#L32) ___ @@ -184,4 +184,4 @@ Inserts an element into the stack #### Defined in -[src/stack/linkedStack.ts:36](https://github.com/havelessbemore/dastal/blob/e94627b/src/stack/linkedStack.ts#L36) +[src/stack/linkedStack.ts:36](https://github.com/havelessbemore/dastal/blob/2fe24da/src/stack/linkedStack.ts#L36) diff --git a/docs/classes/skewheap.md b/docs/classes/skewheap.md index 7b1a702..1fb4b57 100644 --- a/docs/classes/skewheap.md +++ b/docs/classes/skewheap.md @@ -1,4 +1,4 @@ -[dastal - v3.0.0](../README.md) / SkewHeap +[dastal - v4.0.0](../README.md) / SkewHeap # Class: SkewHeap @@ -87,7 +87,7 @@ Instantiate a heap. #### Defined in -[src/heap/skewHeap.ts:47](https://github.com/havelessbemore/dastal/blob/e94627b/src/heap/skewHeap.ts#L47) +[src/heap/skewHeap.ts:47](https://github.com/havelessbemore/dastal/blob/2fe24da/src/heap/skewHeap.ts#L47) ## Accessors @@ -107,7 +107,7 @@ The number of elements in the collection. #### Defined in -[src/heap/skewHeap.ts:168](https://github.com/havelessbemore/dastal/blob/e94627b/src/heap/skewHeap.ts#L168) +[src/heap/skewHeap.ts:168](https://github.com/havelessbemore/dastal/blob/2fe24da/src/heap/skewHeap.ts#L168) ## Methods @@ -131,7 +131,7 @@ An iterator through the list #### Defined in -[src/heap/skewHeap.ts:194](https://github.com/havelessbemore/dastal/blob/e94627b/src/heap/skewHeap.ts#L194) +[src/heap/skewHeap.ts:194](https://github.com/havelessbemore/dastal/blob/2fe24da/src/heap/skewHeap.ts#L194) ___ @@ -159,7 +159,7 @@ The new size of the list. #### Defined in -[src/heap/skewHeap.ts:60](https://github.com/havelessbemore/dastal/blob/e94627b/src/heap/skewHeap.ts#L60) +[src/heap/skewHeap.ts:60](https://github.com/havelessbemore/dastal/blob/2fe24da/src/heap/skewHeap.ts#L60) ___ @@ -179,7 +179,7 @@ Removes all elements. #### Defined in -[src/heap/skewHeap.ts:75](https://github.com/havelessbemore/dastal/blob/e94627b/src/heap/skewHeap.ts#L75) +[src/heap/skewHeap.ts:75](https://github.com/havelessbemore/dastal/blob/2fe24da/src/heap/skewHeap.ts#L75) ___ @@ -199,7 +199,7 @@ The function with which elements are sorted #### Defined in -[src/heap/skewHeap.ts:80](https://github.com/havelessbemore/dastal/blob/e94627b/src/heap/skewHeap.ts#L80) +[src/heap/skewHeap.ts:80](https://github.com/havelessbemore/dastal/blob/2fe24da/src/heap/skewHeap.ts#L80) ___ @@ -227,7 +227,7 @@ Check if an element is in the heap. #### Defined in -[src/heap/skewHeap.ts:84](https://github.com/havelessbemore/dastal/blob/e94627b/src/heap/skewHeap.ts#L84) +[src/heap/skewHeap.ts:84](https://github.com/havelessbemore/dastal/blob/2fe24da/src/heap/skewHeap.ts#L84) ___ @@ -255,7 +255,7 @@ Delete an element from the heap. #### Defined in -[src/heap/skewHeap.ts:93](https://github.com/havelessbemore/dastal/blob/e94627b/src/heap/skewHeap.ts#L93) +[src/heap/skewHeap.ts:93](https://github.com/havelessbemore/dastal/blob/2fe24da/src/heap/skewHeap.ts#L93) ___ @@ -284,7 +284,7 @@ The heap. #### Defined in -[src/heap/skewHeap.ts:118](https://github.com/havelessbemore/dastal/blob/e94627b/src/heap/skewHeap.ts#L118) +[src/heap/skewHeap.ts:118](https://github.com/havelessbemore/dastal/blob/2fe24da/src/heap/skewHeap.ts#L118) ___ @@ -306,7 +306,7 @@ The element at the top of the heap or `undefined` if empty. #### Defined in -[src/heap/skewHeap.ts:133](https://github.com/havelessbemore/dastal/blob/e94627b/src/heap/skewHeap.ts#L133) +[src/heap/skewHeap.ts:133](https://github.com/havelessbemore/dastal/blob/2fe24da/src/heap/skewHeap.ts#L133) ___ @@ -328,7 +328,7 @@ The element at the top of the heap or `undefined` if empty. #### Defined in -[src/heap/skewHeap.ts:137](https://github.com/havelessbemore/dastal/blob/e94627b/src/heap/skewHeap.ts#L137) +[src/heap/skewHeap.ts:137](https://github.com/havelessbemore/dastal/blob/2fe24da/src/heap/skewHeap.ts#L137) ___ @@ -356,7 +356,7 @@ The new size of the heap. #### Defined in -[src/heap/skewHeap.ts:147](https://github.com/havelessbemore/dastal/blob/e94627b/src/heap/skewHeap.ts#L147) +[src/heap/skewHeap.ts:147](https://github.com/havelessbemore/dastal/blob/2fe24da/src/heap/skewHeap.ts#L147) ___ @@ -384,7 +384,7 @@ The element at the top of the heap. #### Defined in -[src/heap/skewHeap.ts:152](https://github.com/havelessbemore/dastal/blob/e94627b/src/heap/skewHeap.ts#L152) +[src/heap/skewHeap.ts:152](https://github.com/havelessbemore/dastal/blob/2fe24da/src/heap/skewHeap.ts#L152) ___ @@ -412,7 +412,7 @@ The element at the top of the heap or `undefined` if empty. #### Defined in -[src/heap/skewHeap.ts:157](https://github.com/havelessbemore/dastal/blob/e94627b/src/heap/skewHeap.ts#L157) +[src/heap/skewHeap.ts:157](https://github.com/havelessbemore/dastal/blob/2fe24da/src/heap/skewHeap.ts#L157) ___ @@ -434,7 +434,7 @@ Iterate through the heap in sorted order. #### Defined in -[src/heap/skewHeap.ts:172](https://github.com/havelessbemore/dastal/blob/e94627b/src/heap/skewHeap.ts#L172) +[src/heap/skewHeap.ts:172](https://github.com/havelessbemore/dastal/blob/2fe24da/src/heap/skewHeap.ts#L172) ___ @@ -463,4 +463,4 @@ Update a specific element. #### Defined in -[src/heap/skewHeap.ts:200](https://github.com/havelessbemore/dastal/blob/e94627b/src/heap/skewHeap.ts#L200) +[src/heap/skewHeap.ts:200](https://github.com/havelessbemore/dastal/blob/2fe24da/src/heap/skewHeap.ts#L200) diff --git a/docs/interfaces/aatreenode.md b/docs/interfaces/aatreenode.md index 4cfec8f..b2f63b6 100644 --- a/docs/interfaces/aatreenode.md +++ b/docs/interfaces/aatreenode.md @@ -1,4 +1,4 @@ -[dastal - v3.0.0](../README.md) / AATreeNode +[dastal - v4.0.0](../README.md) / AATreeNode # Interface: AATreeNode @@ -48,7 +48,7 @@ A link to the node's left child. #### Defined in -[src/tree/binaryTreeNode.ts:10](https://github.com/havelessbemore/dastal/blob/e94627b/src/tree/binaryTreeNode.ts#L10) +[src/tree/binaryTreeNode.ts:10](https://github.com/havelessbemore/dastal/blob/2fe24da/src/tree/binaryTreeNode.ts#L10) ___ @@ -60,7 +60,7 @@ The level of the node. #### Defined in -[src/tree/aaTreeNode.ts:19](https://github.com/havelessbemore/dastal/blob/e94627b/src/tree/aaTreeNode.ts#L19) +[src/tree/aaTreeNode.ts:19](https://github.com/havelessbemore/dastal/blob/2fe24da/src/tree/aaTreeNode.ts#L19) ___ @@ -76,7 +76,7 @@ A link to the node's right child. #### Defined in -[src/tree/binaryTreeNode.ts:14](https://github.com/havelessbemore/dastal/blob/e94627b/src/tree/binaryTreeNode.ts#L14) +[src/tree/binaryTreeNode.ts:14](https://github.com/havelessbemore/dastal/blob/2fe24da/src/tree/binaryTreeNode.ts#L14) ___ @@ -92,4 +92,4 @@ The value of the node #### Defined in -[src/tree/binaryTreeNode.ts:18](https://github.com/havelessbemore/dastal/blob/e94627b/src/tree/binaryTreeNode.ts#L18) +[src/tree/binaryTreeNode.ts:18](https://github.com/havelessbemore/dastal/blob/2fe24da/src/tree/binaryTreeNode.ts#L18) diff --git a/docs/interfaces/avltreenode.md b/docs/interfaces/avltreenode.md index 604f61e..0bc47b1 100644 --- a/docs/interfaces/avltreenode.md +++ b/docs/interfaces/avltreenode.md @@ -1,4 +1,4 @@ -[dastal - v3.0.0](../README.md) / AVLTreeNode +[dastal - v4.0.0](../README.md) / AVLTreeNode # Interface: AVLTreeNode @@ -38,7 +38,7 @@ The delta rank of the node. #### Defined in -[src/tree/avlTreeNode.ts:13](https://github.com/havelessbemore/dastal/blob/e94627b/src/tree/avlTreeNode.ts#L13) +[src/tree/avlTreeNode.ts:13](https://github.com/havelessbemore/dastal/blob/2fe24da/src/tree/avlTreeNode.ts#L13) ___ @@ -54,7 +54,7 @@ A link to the node's left child. #### Defined in -[src/tree/binaryTreeNode.ts:10](https://github.com/havelessbemore/dastal/blob/e94627b/src/tree/binaryTreeNode.ts#L10) +[src/tree/binaryTreeNode.ts:10](https://github.com/havelessbemore/dastal/blob/2fe24da/src/tree/binaryTreeNode.ts#L10) ___ @@ -70,7 +70,7 @@ A link to the node's right child. #### Defined in -[src/tree/binaryTreeNode.ts:14](https://github.com/havelessbemore/dastal/blob/e94627b/src/tree/binaryTreeNode.ts#L14) +[src/tree/binaryTreeNode.ts:14](https://github.com/havelessbemore/dastal/blob/2fe24da/src/tree/binaryTreeNode.ts#L14) ___ @@ -86,4 +86,4 @@ The value of the node #### Defined in -[src/tree/binaryTreeNode.ts:18](https://github.com/havelessbemore/dastal/blob/e94627b/src/tree/binaryTreeNode.ts#L18) +[src/tree/binaryTreeNode.ts:18](https://github.com/havelessbemore/dastal/blob/2fe24da/src/tree/binaryTreeNode.ts#L18) diff --git a/docs/interfaces/binarytreenode.md b/docs/interfaces/binarytreenode.md index d0a1cb4..e8b6b39 100644 --- a/docs/interfaces/binarytreenode.md +++ b/docs/interfaces/binarytreenode.md @@ -1,4 +1,4 @@ -[dastal - v3.0.0](../README.md) / BinaryTreeNode +[dastal - v4.0.0](../README.md) / BinaryTreeNode # Interface: BinaryTreeNode @@ -38,7 +38,7 @@ A link to the node's left child. #### Defined in -[src/tree/binaryTreeNode.ts:10](https://github.com/havelessbemore/dastal/blob/e94627b/src/tree/binaryTreeNode.ts#L10) +[src/tree/binaryTreeNode.ts:10](https://github.com/havelessbemore/dastal/blob/2fe24da/src/tree/binaryTreeNode.ts#L10) ___ @@ -50,7 +50,7 @@ A link to the node's right child. #### Defined in -[src/tree/binaryTreeNode.ts:14](https://github.com/havelessbemore/dastal/blob/e94627b/src/tree/binaryTreeNode.ts#L14) +[src/tree/binaryTreeNode.ts:14](https://github.com/havelessbemore/dastal/blob/2fe24da/src/tree/binaryTreeNode.ts#L14) ___ @@ -62,4 +62,4 @@ The value of the node #### Defined in -[src/tree/binaryTreeNode.ts:18](https://github.com/havelessbemore/dastal/blob/e94627b/src/tree/binaryTreeNode.ts#L18) +[src/tree/binaryTreeNode.ts:18](https://github.com/havelessbemore/dastal/blob/2fe24da/src/tree/binaryTreeNode.ts#L18) diff --git a/docs/interfaces/collection.md b/docs/interfaces/collection.md new file mode 100644 index 0000000..0ae5117 --- /dev/null +++ b/docs/interfaces/collection.md @@ -0,0 +1,67 @@ +[dastal - v4.0.0](../README.md) / Collection + +# Interface: Collection + +## Type parameters + +| Name | +| :------ | +| `T` | + +## Hierarchy + +- `Iterable` + + ↳ **Collection** + + ↳↳ [Heap](heap.md) + + ↳↳ [List](list.md) + + ↳↳ [Queue](queue.md) + + ↳↳ [SegmentTree](segmenttree.md) + + ↳↳ [Stack](stack.md) + + ↳↳ [Tree](tree.md) + +## Table of contents + +### Properties + +- [size](collection.md#size) + +### Methods + +- [[Symbol.iterator]](collection.md#[symbol.iterator]) + +## Properties + +### size + +• `Readonly` **size**: `number` + +The number of elements in the collection. + +#### Defined in + +[src/collection/collection.ts:5](https://github.com/havelessbemore/dastal/blob/2fe24da/src/collection/collection.ts#L5) + +## Methods + +### [Symbol.iterator] + +▸ **[Symbol.iterator]**(): `Iterator` + +#### Returns + +`Iterator` + +#### Inherited from + +Iterable.\_\_@iterator + +#### Defined in + +node_modules/typescript/lib/lib.es2015.iterable.d.ts:51 diff --git a/docs/interfaces/doublylinkednode.md b/docs/interfaces/doublylinkednode.md index 50e14a0..d918183 100644 --- a/docs/interfaces/doublylinkednode.md +++ b/docs/interfaces/doublylinkednode.md @@ -1,4 +1,4 @@ -[dastal - v3.0.0](../README.md) / DoublyLinkedNode +[dastal - v4.0.0](../README.md) / DoublyLinkedNode # Interface: DoublyLinkedNode @@ -30,7 +30,7 @@ A link to the node's next (right) neighbor #### Defined in -[src/list/doublyLinkedNode.ts:10](https://github.com/havelessbemore/dastal/blob/e94627b/src/list/doublyLinkedNode.ts#L10) +[src/list/doublyLinkedNode.ts:10](https://github.com/havelessbemore/dastal/blob/2fe24da/src/list/doublyLinkedNode.ts#L10) ___ @@ -42,7 +42,7 @@ A link to the node's previous (left) neighbor #### Defined in -[src/list/doublyLinkedNode.ts:14](https://github.com/havelessbemore/dastal/blob/e94627b/src/list/doublyLinkedNode.ts#L14) +[src/list/doublyLinkedNode.ts:14](https://github.com/havelessbemore/dastal/blob/2fe24da/src/list/doublyLinkedNode.ts#L14) ___ @@ -54,4 +54,4 @@ The value of the node #### Defined in -[src/list/doublyLinkedNode.ts:18](https://github.com/havelessbemore/dastal/blob/e94627b/src/list/doublyLinkedNode.ts#L18) +[src/list/doublyLinkedNode.ts:18](https://github.com/havelessbemore/dastal/blob/2fe24da/src/list/doublyLinkedNode.ts#L18) diff --git a/docs/interfaces/heap.md b/docs/interfaces/heap.md index 6dcd330..bb1f552 100644 --- a/docs/interfaces/heap.md +++ b/docs/interfaces/heap.md @@ -1,4 +1,4 @@ -[dastal - v3.0.0](../README.md) / Heap +[dastal - v4.0.0](../README.md) / Heap # Interface: Heap @@ -54,7 +54,7 @@ Add & Remove ## Hierarchy -- `Collection` +- [Collection](collection.md) - [Sorted](sorted.md) @@ -98,11 +98,11 @@ The number of elements in the collection. #### Inherited from -Collection.size +[Collection](collection.md).[size](collection.md#size) #### Defined in -[src/collection/collection.ts:5](https://github.com/havelessbemore/dastal/blob/e94627b/src/collection/collection.ts#L5) +[src/collection/collection.ts:5](https://github.com/havelessbemore/dastal/blob/2fe24da/src/collection/collection.ts#L5) ## Methods @@ -116,7 +116,7 @@ Collection.size #### Inherited from -Collection.\_\_@iterator +[Collection](collection.md).[[Symbol.iterator]](collection.md#[symbol.iterator]) #### Defined in @@ -144,7 +144,7 @@ The new size of the list. #### Defined in -[src/heap/heap.ts:57](https://github.com/havelessbemore/dastal/blob/e94627b/src/heap/heap.ts#L57) +[src/heap/heap.ts:57](https://github.com/havelessbemore/dastal/blob/2fe24da/src/heap/heap.ts#L57) ___ @@ -160,7 +160,7 @@ Removes all elements. #### Defined in -[src/heap/heap.ts:61](https://github.com/havelessbemore/dastal/blob/e94627b/src/heap/heap.ts#L61) +[src/heap/heap.ts:61](https://github.com/havelessbemore/dastal/blob/2fe24da/src/heap/heap.ts#L61) ___ @@ -180,7 +180,7 @@ The function with which elements are sorted #### Defined in -[src/index.ts:59](https://github.com/havelessbemore/dastal/blob/e94627b/src/index.ts#L59) +[src/index.ts:59](https://github.com/havelessbemore/dastal/blob/2fe24da/src/index.ts#L59) ___ @@ -204,7 +204,7 @@ Check if an element is in the heap. #### Defined in -[src/heap/heap.ts:69](https://github.com/havelessbemore/dastal/blob/e94627b/src/heap/heap.ts#L69) +[src/heap/heap.ts:69](https://github.com/havelessbemore/dastal/blob/2fe24da/src/heap/heap.ts#L69) ___ @@ -228,7 +228,7 @@ Delete an element from the heap. #### Defined in -[src/heap/heap.ts:77](https://github.com/havelessbemore/dastal/blob/e94627b/src/heap/heap.ts#L77) +[src/heap/heap.ts:77](https://github.com/havelessbemore/dastal/blob/2fe24da/src/heap/heap.ts#L77) ___ @@ -253,7 +253,7 @@ The heap. #### Defined in -[src/heap/heap.ts:86](https://github.com/havelessbemore/dastal/blob/e94627b/src/heap/heap.ts#L86) +[src/heap/heap.ts:86](https://github.com/havelessbemore/dastal/blob/2fe24da/src/heap/heap.ts#L86) ___ @@ -271,7 +271,7 @@ The element at the top of the heap or `undefined` if empty. #### Defined in -[src/heap/heap.ts:92](https://github.com/havelessbemore/dastal/blob/e94627b/src/heap/heap.ts#L92) +[src/heap/heap.ts:92](https://github.com/havelessbemore/dastal/blob/2fe24da/src/heap/heap.ts#L92) ___ @@ -289,7 +289,7 @@ The element at the top of the heap or `undefined` if empty. #### Defined in -[src/heap/heap.ts:98](https://github.com/havelessbemore/dastal/blob/e94627b/src/heap/heap.ts#L98) +[src/heap/heap.ts:98](https://github.com/havelessbemore/dastal/blob/2fe24da/src/heap/heap.ts#L98) ___ @@ -313,7 +313,7 @@ The new size of the heap. #### Defined in -[src/heap/heap.ts:106](https://github.com/havelessbemore/dastal/blob/e94627b/src/heap/heap.ts#L106) +[src/heap/heap.ts:106](https://github.com/havelessbemore/dastal/blob/2fe24da/src/heap/heap.ts#L106) ___ @@ -337,7 +337,7 @@ The element at the top of the heap. #### Defined in -[src/heap/heap.ts:114](https://github.com/havelessbemore/dastal/blob/e94627b/src/heap/heap.ts#L114) +[src/heap/heap.ts:114](https://github.com/havelessbemore/dastal/blob/2fe24da/src/heap/heap.ts#L114) ___ @@ -361,7 +361,7 @@ The element at the top of the heap or `undefined` if empty. #### Defined in -[src/heap/heap.ts:122](https://github.com/havelessbemore/dastal/blob/e94627b/src/heap/heap.ts#L122) +[src/heap/heap.ts:122](https://github.com/havelessbemore/dastal/blob/2fe24da/src/heap/heap.ts#L122) ___ @@ -379,7 +379,7 @@ Iterate through the heap in sorted order. #### Defined in -[src/heap/heap.ts:128](https://github.com/havelessbemore/dastal/blob/e94627b/src/heap/heap.ts#L128) +[src/heap/heap.ts:128](https://github.com/havelessbemore/dastal/blob/2fe24da/src/heap/heap.ts#L128) ___ @@ -404,4 +404,4 @@ Update a specific element. #### Defined in -[src/heap/heap.ts:137](https://github.com/havelessbemore/dastal/blob/e94627b/src/heap/heap.ts#L137) +[src/heap/heap.ts:137](https://github.com/havelessbemore/dastal/blob/2fe24da/src/heap/heap.ts#L137) diff --git a/docs/interfaces/linkednode.md b/docs/interfaces/linkednode.md index e519a54..73e826b 100644 --- a/docs/interfaces/linkednode.md +++ b/docs/interfaces/linkednode.md @@ -1,4 +1,4 @@ -[dastal - v3.0.0](../README.md) / LinkedNode +[dastal - v4.0.0](../README.md) / LinkedNode # Interface: LinkedNode @@ -29,7 +29,7 @@ A link to the node's neighbor. #### Defined in -[src/list/linkedNode.ts:10](https://github.com/havelessbemore/dastal/blob/e94627b/src/list/linkedNode.ts#L10) +[src/list/linkedNode.ts:10](https://github.com/havelessbemore/dastal/blob/2fe24da/src/list/linkedNode.ts#L10) ___ @@ -41,4 +41,4 @@ The value of the node. #### Defined in -[src/list/linkedNode.ts:14](https://github.com/havelessbemore/dastal/blob/e94627b/src/list/linkedNode.ts#L14) +[src/list/linkedNode.ts:14](https://github.com/havelessbemore/dastal/blob/2fe24da/src/list/linkedNode.ts#L14) diff --git a/docs/interfaces/list.md b/docs/interfaces/list.md index 835d410..28e37b5 100644 --- a/docs/interfaces/list.md +++ b/docs/interfaces/list.md @@ -1,4 +1,4 @@ -[dastal - v3.0.0](../README.md) / List +[dastal - v4.0.0](../README.md) / List # Interface: List @@ -45,7 +45,7 @@ where an element is inserted. Elements can be accessed by their integer index (p ## Hierarchy -- `Collection` +- [Collection](collection.md) - [Sortable](sortable.md) @@ -97,11 +97,11 @@ The number of elements in the collection. #### Inherited from -Collection.size +[Collection](collection.md).[size](collection.md#size) #### Defined in -[src/collection/collection.ts:5](https://github.com/havelessbemore/dastal/blob/e94627b/src/collection/collection.ts#L5) +[src/collection/collection.ts:5](https://github.com/havelessbemore/dastal/blob/2fe24da/src/collection/collection.ts#L5) ## Methods @@ -115,7 +115,7 @@ Collection.size #### Inherited from -Collection.\_\_@iterator +[Collection](collection.md).[[Symbol.iterator]](collection.md#[symbol.iterator]) #### Defined in @@ -144,7 +144,7 @@ The new size of the list #### Defined in -[src/list/list.ts:49](https://github.com/havelessbemore/dastal/blob/e94627b/src/list/list.ts#L49) +[src/list/list.ts:49](https://github.com/havelessbemore/dastal/blob/2fe24da/src/list/list.ts#L49) ___ @@ -169,7 +169,7 @@ The new size of the list #### Defined in -[src/list/list.ts:58](https://github.com/havelessbemore/dastal/blob/e94627b/src/list/list.ts#L58) +[src/list/list.ts:58](https://github.com/havelessbemore/dastal/blob/2fe24da/src/list/list.ts#L58) ___ @@ -185,7 +185,7 @@ Removes all elements. #### Defined in -[src/list/list.ts:62](https://github.com/havelessbemore/dastal/blob/e94627b/src/list/list.ts#L62) +[src/list/list.ts:62](https://github.com/havelessbemore/dastal/blob/2fe24da/src/list/list.ts#L62) ___ @@ -211,7 +211,7 @@ or the argument itself. It does not recurse into nested iterable arguments #### Defined in -[src/list/list.ts:72](https://github.com/havelessbemore/dastal/blob/e94627b/src/list/list.ts#L72) +[src/list/list.ts:72](https://github.com/havelessbemore/dastal/blob/2fe24da/src/list/list.ts#L72) ___ @@ -243,7 +243,7 @@ The list #### Defined in -[src/list/list.ts:88](https://github.com/havelessbemore/dastal/blob/e94627b/src/list/list.ts#L88) +[src/list/list.ts:88](https://github.com/havelessbemore/dastal/blob/2fe24da/src/list/list.ts#L88) ___ @@ -272,7 +272,7 @@ The list on which this method was called #### Defined in -[src/list/list.ts:101](https://github.com/havelessbemore/dastal/blob/e94627b/src/list/list.ts#L101) +[src/list/list.ts:101](https://github.com/havelessbemore/dastal/blob/2fe24da/src/list/list.ts#L101) ___ @@ -296,7 +296,7 @@ The element at the index, or `undefined` if index is invalid #### Defined in -[src/list/list.ts:109](https://github.com/havelessbemore/dastal/blob/e94627b/src/list/list.ts#L109) +[src/list/list.ts:109](https://github.com/havelessbemore/dastal/blob/2fe24da/src/list/list.ts#L109) ___ @@ -321,7 +321,7 @@ The previous element at the index, or `undefined` if index is invalid #### Defined in -[src/list/list.ts:119](https://github.com/havelessbemore/dastal/blob/e94627b/src/list/list.ts#L119) +[src/list/list.ts:119](https://github.com/havelessbemore/dastal/blob/2fe24da/src/list/list.ts#L119) ___ @@ -339,7 +339,7 @@ The value at the end of the list, or `undefined` if empty. #### Defined in -[src/list/list.ts:125](https://github.com/havelessbemore/dastal/blob/e94627b/src/list/list.ts#L125) +[src/list/list.ts:125](https://github.com/havelessbemore/dastal/blob/2fe24da/src/list/list.ts#L125) ___ @@ -363,7 +363,7 @@ The new size of the list #### Defined in -[src/list/list.ts:133](https://github.com/havelessbemore/dastal/blob/e94627b/src/list/list.ts#L133) +[src/list/list.ts:133](https://github.com/havelessbemore/dastal/blob/2fe24da/src/list/list.ts#L133) ___ @@ -390,7 +390,7 @@ The value at the index, or `undefined` if the index is invalid #### Defined in -[src/list/list.ts:144](https://github.com/havelessbemore/dastal/blob/e94627b/src/list/list.ts#L144) +[src/list/list.ts:144](https://github.com/havelessbemore/dastal/blob/2fe24da/src/list/list.ts#L144) ___ @@ -418,7 +418,7 @@ a reference to the same list #### Defined in -[src/list/list.ts:156](https://github.com/havelessbemore/dastal/blob/e94627b/src/list/list.ts#L156) +[src/list/list.ts:156](https://github.com/havelessbemore/dastal/blob/2fe24da/src/list/list.ts#L156) ___ @@ -443,7 +443,7 @@ The previous element in the index, or undefined if the index is invalid #### Defined in -[src/list/list.ts:165](https://github.com/havelessbemore/dastal/blob/e94627b/src/list/list.ts#L165) +[src/list/list.ts:165](https://github.com/havelessbemore/dastal/blob/2fe24da/src/list/list.ts#L165) ___ @@ -461,7 +461,7 @@ The value at the front of the list or `undefined` if this list is empty. #### Defined in -[src/list/list.ts:171](https://github.com/havelessbemore/dastal/blob/e94627b/src/list/list.ts#L171) +[src/list/list.ts:171](https://github.com/havelessbemore/dastal/blob/2fe24da/src/list/list.ts#L171) ___ @@ -489,7 +489,7 @@ A new list with a copy of the indicated section of the original list #### Defined in -[src/list/list.ts:183](https://github.com/havelessbemore/dastal/blob/e94627b/src/list/list.ts#L183) +[src/list/list.ts:183](https://github.com/havelessbemore/dastal/blob/2fe24da/src/list/list.ts#L183) ___ @@ -517,7 +517,7 @@ The object this method was called on #### Defined in -[src/index.ts:50](https://github.com/havelessbemore/dastal/blob/e94627b/src/index.ts#L50) +[src/index.ts:50](https://github.com/havelessbemore/dastal/blob/2fe24da/src/index.ts#L50) ___ @@ -544,7 +544,7 @@ A new list of deleted elements #### Defined in -[src/list/list.ts:208](https://github.com/havelessbemore/dastal/blob/e94627b/src/list/list.ts#L208) +[src/list/list.ts:208](https://github.com/havelessbemore/dastal/blob/2fe24da/src/list/list.ts#L208) ___ @@ -568,7 +568,7 @@ The new size of the list #### Defined in -[src/list/list.ts:216](https://github.com/havelessbemore/dastal/blob/e94627b/src/list/list.ts#L216) +[src/list/list.ts:216](https://github.com/havelessbemore/dastal/blob/2fe24da/src/list/list.ts#L216) ___ @@ -592,7 +592,7 @@ The list on which this method was called #### Defined in -[src/list/list.ts:224](https://github.com/havelessbemore/dastal/blob/e94627b/src/list/list.ts#L224) +[src/list/list.ts:224](https://github.com/havelessbemore/dastal/blob/2fe24da/src/list/list.ts#L224) ▸ **update**(`min`, `callback`): [List](list.md) @@ -616,7 +616,7 @@ The list on which this method was called #### Defined in -[src/list/list.ts:236](https://github.com/havelessbemore/dastal/blob/e94627b/src/list/list.ts#L236) +[src/list/list.ts:236](https://github.com/havelessbemore/dastal/blob/2fe24da/src/list/list.ts#L236) ▸ **update**(`min`, `max`, `callback`): [List](list.md) @@ -641,7 +641,7 @@ The list on which this method was called #### Defined in -[src/list/list.ts:249](https://github.com/havelessbemore/dastal/blob/e94627b/src/list/list.ts#L249) +[src/list/list.ts:249](https://github.com/havelessbemore/dastal/blob/2fe24da/src/list/list.ts#L249) ___ @@ -671,4 +671,4 @@ An iterator through the indicated section of the list #### Defined in -[src/list/list.ts:267](https://github.com/havelessbemore/dastal/blob/e94627b/src/list/list.ts#L267) +[src/list/list.ts:267](https://github.com/havelessbemore/dastal/blob/2fe24da/src/list/list.ts#L267) diff --git a/docs/interfaces/queue.md b/docs/interfaces/queue.md index 1b56178..db2a285 100644 --- a/docs/interfaces/queue.md +++ b/docs/interfaces/queue.md @@ -1,4 +1,4 @@ -[dastal - v3.0.0](../README.md) / Queue +[dastal - v4.0.0](../README.md) / Queue # Interface: Queue @@ -21,7 +21,7 @@ Every implementation should specify its ordering properties. Otherwise, insertio ## Hierarchy -- `Collection` +- [Collection](collection.md) ↳ **Queue** @@ -54,11 +54,11 @@ The number of elements in the collection. #### Inherited from -Collection.size +[Collection](collection.md).[size](collection.md#size) #### Defined in -[src/collection/collection.ts:5](https://github.com/havelessbemore/dastal/blob/e94627b/src/collection/collection.ts#L5) +[src/collection/collection.ts:5](https://github.com/havelessbemore/dastal/blob/2fe24da/src/collection/collection.ts#L5) ## Methods @@ -72,7 +72,7 @@ Collection.size #### Inherited from -Collection.\_\_@iterator +[Collection](collection.md).[[Symbol.iterator]](collection.md#[symbol.iterator]) #### Defined in @@ -92,7 +92,7 @@ Removes all elements. #### Defined in -[src/queue/queue.ts:19](https://github.com/havelessbemore/dastal/blob/e94627b/src/queue/queue.ts#L19) +[src/queue/queue.ts:19](https://github.com/havelessbemore/dastal/blob/2fe24da/src/queue/queue.ts#L19) ___ @@ -110,7 +110,7 @@ The value at the head of the queue or `undefined` if this queue is empty. #### Defined in -[src/queue/queue.ts:25](https://github.com/havelessbemore/dastal/blob/e94627b/src/queue/queue.ts#L25) +[src/queue/queue.ts:25](https://github.com/havelessbemore/dastal/blob/2fe24da/src/queue/queue.ts#L25) ___ @@ -134,7 +134,7 @@ The new size of the queue #### Defined in -[src/queue/queue.ts:33](https://github.com/havelessbemore/dastal/blob/e94627b/src/queue/queue.ts#L33) +[src/queue/queue.ts:33](https://github.com/havelessbemore/dastal/blob/2fe24da/src/queue/queue.ts#L33) ___ @@ -152,4 +152,4 @@ The value at the head of the queue or `undefined` if this queue is empty. #### Defined in -[src/queue/queue.ts:39](https://github.com/havelessbemore/dastal/blob/e94627b/src/queue/queue.ts#L39) +[src/queue/queue.ts:39](https://github.com/havelessbemore/dastal/blob/2fe24da/src/queue/queue.ts#L39) diff --git a/docs/interfaces/segmenttree.md b/docs/interfaces/segmenttree.md index ca8a9f4..26e8303 100644 --- a/docs/interfaces/segmenttree.md +++ b/docs/interfaces/segmenttree.md @@ -1,4 +1,4 @@ -[dastal - v3.0.0](../README.md) / SegmentTree +[dastal - v4.0.0](../README.md) / SegmentTree # Interface: SegmentTree @@ -10,7 +10,7 @@ ## Hierarchy -- `Collection` +- [Collection](collection.md) ↳ **SegmentTree** @@ -44,11 +44,11 @@ The number of elements in the collection. #### Inherited from -Collection.size +[Collection](collection.md).[size](collection.md#size) #### Defined in -[src/collection/collection.ts:5](https://github.com/havelessbemore/dastal/blob/e94627b/src/collection/collection.ts#L5) +[src/collection/collection.ts:5](https://github.com/havelessbemore/dastal/blob/2fe24da/src/collection/collection.ts#L5) ## Methods @@ -62,7 +62,7 @@ Collection.size #### Inherited from -Collection.\_\_@iterator +[Collection](collection.md).[[Symbol.iterator]](collection.md#[symbol.iterator]) #### Defined in @@ -82,7 +82,7 @@ Removes all elements. #### Defined in -[src/segmentTree/segmentTree.ts:7](https://github.com/havelessbemore/dastal/blob/e94627b/src/segmentTree/segmentTree.ts#L7) +[src/segmentTree/segmentTree.ts:7](https://github.com/havelessbemore/dastal/blob/2fe24da/src/segmentTree/segmentTree.ts#L7) ___ @@ -100,7 +100,7 @@ The last element or `undefined` if empty. #### Defined in -[src/segmentTree/segmentTree.ts:13](https://github.com/havelessbemore/dastal/blob/e94627b/src/segmentTree/segmentTree.ts#L13) +[src/segmentTree/segmentTree.ts:13](https://github.com/havelessbemore/dastal/blob/2fe24da/src/segmentTree/segmentTree.ts#L13) ___ @@ -124,7 +124,7 @@ The new size of the tree #### Defined in -[src/segmentTree/segmentTree.ts:21](https://github.com/havelessbemore/dastal/blob/e94627b/src/segmentTree/segmentTree.ts#L21) +[src/segmentTree/segmentTree.ts:21](https://github.com/havelessbemore/dastal/blob/2fe24da/src/segmentTree/segmentTree.ts#L21) ___ @@ -149,7 +149,7 @@ The aggregated result for range [min, max) #### Defined in -[src/segmentTree/segmentTree.ts:30](https://github.com/havelessbemore/dastal/blob/e94627b/src/segmentTree/segmentTree.ts#L30) +[src/segmentTree/segmentTree.ts:30](https://github.com/havelessbemore/dastal/blob/2fe24da/src/segmentTree/segmentTree.ts#L30) ___ @@ -173,4 +173,4 @@ Update the elements of a given range in the tree #### Defined in -[src/segmentTree/segmentTree.ts:38](https://github.com/havelessbemore/dastal/blob/e94627b/src/segmentTree/segmentTree.ts#L38) +[src/segmentTree/segmentTree.ts:38](https://github.com/havelessbemore/dastal/blob/2fe24da/src/segmentTree/segmentTree.ts#L38) diff --git a/docs/interfaces/sortable.md b/docs/interfaces/sortable.md index dcba9c8..1ae7127 100644 --- a/docs/interfaces/sortable.md +++ b/docs/interfaces/sortable.md @@ -1,4 +1,4 @@ -[dastal - v3.0.0](../README.md) / Sortable +[dastal - v4.0.0](../README.md) / Sortable # Interface: Sortable @@ -44,4 +44,4 @@ The object this method was called on #### Defined in -[src/index.ts:50](https://github.com/havelessbemore/dastal/blob/e94627b/src/index.ts#L50) +[src/index.ts:50](https://github.com/havelessbemore/dastal/blob/2fe24da/src/index.ts#L50) diff --git a/docs/interfaces/sorted.md b/docs/interfaces/sorted.md index c68c0a0..0f7aceb 100644 --- a/docs/interfaces/sorted.md +++ b/docs/interfaces/sorted.md @@ -1,4 +1,4 @@ -[dastal - v3.0.0](../README.md) / Sorted +[dastal - v4.0.0](../README.md) / Sorted # Interface: Sorted @@ -38,4 +38,4 @@ The function with which elements are sorted #### Defined in -[src/index.ts:59](https://github.com/havelessbemore/dastal/blob/e94627b/src/index.ts#L59) +[src/index.ts:59](https://github.com/havelessbemore/dastal/blob/2fe24da/src/index.ts#L59) diff --git a/docs/interfaces/sortedtree.md b/docs/interfaces/sortedtree.md index 389f5c9..79e733b 100644 --- a/docs/interfaces/sortedtree.md +++ b/docs/interfaces/sortedtree.md @@ -1,4 +1,4 @@ -[dastal - v3.0.0](../README.md) / SortedTree +[dastal - v4.0.0](../README.md) / SortedTree # Interface: SortedTree @@ -58,7 +58,7 @@ The number of elements in the collection. #### Defined in -[src/collection/collection.ts:5](https://github.com/havelessbemore/dastal/blob/e94627b/src/collection/collection.ts#L5) +[src/collection/collection.ts:5](https://github.com/havelessbemore/dastal/blob/2fe24da/src/collection/collection.ts#L5) ## Methods @@ -104,7 +104,7 @@ The tree object. #### Defined in -[src/tree/tree.ts:38](https://github.com/havelessbemore/dastal/blob/e94627b/src/tree/tree.ts#L38) +[src/tree/tree.ts:38](https://github.com/havelessbemore/dastal/blob/2fe24da/src/tree/tree.ts#L38) ___ @@ -124,7 +124,7 @@ Removes all elements. #### Defined in -[src/tree/tree.ts:42](https://github.com/havelessbemore/dastal/blob/e94627b/src/tree/tree.ts#L42) +[src/tree/tree.ts:42](https://github.com/havelessbemore/dastal/blob/2fe24da/src/tree/tree.ts#L42) ___ @@ -144,7 +144,7 @@ The function with which elements are sorted #### Defined in -[src/index.ts:59](https://github.com/havelessbemore/dastal/blob/e94627b/src/index.ts#L59) +[src/index.ts:59](https://github.com/havelessbemore/dastal/blob/2fe24da/src/index.ts#L59) ___ @@ -172,7 +172,7 @@ Delete an element from the tree. #### Defined in -[src/tree/tree.ts:50](https://github.com/havelessbemore/dastal/blob/e94627b/src/tree/tree.ts#L50) +[src/tree/tree.ts:50](https://github.com/havelessbemore/dastal/blob/2fe24da/src/tree/tree.ts#L50) ___ @@ -200,7 +200,7 @@ Check if an element is in the tree. #### Defined in -[src/tree/tree.ts:58](https://github.com/havelessbemore/dastal/blob/e94627b/src/tree/tree.ts#L58) +[src/tree/tree.ts:58](https://github.com/havelessbemore/dastal/blob/2fe24da/src/tree/tree.ts#L58) ___ @@ -216,7 +216,7 @@ Get the maximum element. #### Defined in -[src/tree/sortedTree.ts:11](https://github.com/havelessbemore/dastal/blob/e94627b/src/tree/sortedTree.ts#L11) +[src/tree/sortedTree.ts:11](https://github.com/havelessbemore/dastal/blob/2fe24da/src/tree/sortedTree.ts#L11) ___ @@ -232,7 +232,7 @@ Get the minimum element. #### Defined in -[src/tree/sortedTree.ts:15](https://github.com/havelessbemore/dastal/blob/e94627b/src/tree/sortedTree.ts#L15) +[src/tree/sortedTree.ts:15](https://github.com/havelessbemore/dastal/blob/2fe24da/src/tree/sortedTree.ts#L15) ___ @@ -248,7 +248,7 @@ Remove the maximum element. #### Defined in -[src/tree/sortedTree.ts:19](https://github.com/havelessbemore/dastal/blob/e94627b/src/tree/sortedTree.ts#L19) +[src/tree/sortedTree.ts:19](https://github.com/havelessbemore/dastal/blob/2fe24da/src/tree/sortedTree.ts#L19) ___ @@ -264,7 +264,7 @@ Remove the minimum element. #### Defined in -[src/tree/sortedTree.ts:23](https://github.com/havelessbemore/dastal/blob/e94627b/src/tree/sortedTree.ts#L23) +[src/tree/sortedTree.ts:23](https://github.com/havelessbemore/dastal/blob/2fe24da/src/tree/sortedTree.ts#L23) ___ @@ -282,7 +282,7 @@ Iterate through the tree in sorted order (i.e in-order traversal). #### Defined in -[src/tree/sortedTree.ts:29](https://github.com/havelessbemore/dastal/blob/e94627b/src/tree/sortedTree.ts#L29) +[src/tree/sortedTree.ts:29](https://github.com/havelessbemore/dastal/blob/2fe24da/src/tree/sortedTree.ts#L29) ___ @@ -311,4 +311,4 @@ Update a specific element. #### Defined in -[src/tree/tree.ts:67](https://github.com/havelessbemore/dastal/blob/e94627b/src/tree/tree.ts#L67) +[src/tree/tree.ts:67](https://github.com/havelessbemore/dastal/blob/2fe24da/src/tree/tree.ts#L67) diff --git a/docs/interfaces/stack.md b/docs/interfaces/stack.md index 1857888..497071f 100644 --- a/docs/interfaces/stack.md +++ b/docs/interfaces/stack.md @@ -1,4 +1,4 @@ -[dastal - v3.0.0](../README.md) / Stack +[dastal - v4.0.0](../README.md) / Stack # Interface: Stack @@ -19,7 +19,7 @@ Every implementation should specify its ordering properties. Otherwise, insertio ## Hierarchy -- `Collection` +- [Collection](collection.md) ↳ **Stack** @@ -52,11 +52,11 @@ The number of elements in the collection. #### Inherited from -Collection.size +[Collection](collection.md).[size](collection.md#size) #### Defined in -[src/collection/collection.ts:5](https://github.com/havelessbemore/dastal/blob/e94627b/src/collection/collection.ts#L5) +[src/collection/collection.ts:5](https://github.com/havelessbemore/dastal/blob/2fe24da/src/collection/collection.ts#L5) ## Methods @@ -70,7 +70,7 @@ Collection.size #### Inherited from -Collection.\_\_@iterator +[Collection](collection.md).[[Symbol.iterator]](collection.md#[symbol.iterator]) #### Defined in @@ -90,7 +90,7 @@ Removes all elements. #### Defined in -[src/stack/stack.ts:17](https://github.com/havelessbemore/dastal/blob/e94627b/src/stack/stack.ts#L17) +[src/stack/stack.ts:17](https://github.com/havelessbemore/dastal/blob/2fe24da/src/stack/stack.ts#L17) ___ @@ -108,7 +108,7 @@ The element at the top of the stack or `undefined` if empty. #### Defined in -[src/stack/stack.ts:23](https://github.com/havelessbemore/dastal/blob/e94627b/src/stack/stack.ts#L23) +[src/stack/stack.ts:23](https://github.com/havelessbemore/dastal/blob/2fe24da/src/stack/stack.ts#L23) ___ @@ -126,7 +126,7 @@ The element at the top of the stack or `undefined` if empty. #### Defined in -[src/stack/stack.ts:29](https://github.com/havelessbemore/dastal/blob/e94627b/src/stack/stack.ts#L29) +[src/stack/stack.ts:29](https://github.com/havelessbemore/dastal/blob/2fe24da/src/stack/stack.ts#L29) ___ @@ -150,4 +150,4 @@ The new size of the stack #### Defined in -[src/stack/stack.ts:37](https://github.com/havelessbemore/dastal/blob/e94627b/src/stack/stack.ts#L37) +[src/stack/stack.ts:37](https://github.com/havelessbemore/dastal/blob/2fe24da/src/stack/stack.ts#L37) diff --git a/docs/interfaces/tree.md b/docs/interfaces/tree.md index 2d46a1b..444efc4 100644 --- a/docs/interfaces/tree.md +++ b/docs/interfaces/tree.md @@ -1,4 +1,4 @@ -[dastal - v3.0.0](../README.md) / Tree +[dastal - v4.0.0](../README.md) / Tree # Interface: Tree @@ -36,7 +36,7 @@ Remove ## Hierarchy -- `Collection` +- [Collection](collection.md) ↳ **Tree** @@ -67,11 +67,11 @@ The number of elements in the collection. #### Inherited from -Collection.size +[Collection](collection.md).[size](collection.md#size) #### Defined in -[src/collection/collection.ts:5](https://github.com/havelessbemore/dastal/blob/e94627b/src/collection/collection.ts#L5) +[src/collection/collection.ts:5](https://github.com/havelessbemore/dastal/blob/2fe24da/src/collection/collection.ts#L5) ## Methods @@ -85,7 +85,7 @@ Collection.size #### Inherited from -Collection.\_\_@iterator +[Collection](collection.md).[[Symbol.iterator]](collection.md#[symbol.iterator]) #### Defined in @@ -113,7 +113,7 @@ The tree object. #### Defined in -[src/tree/tree.ts:38](https://github.com/havelessbemore/dastal/blob/e94627b/src/tree/tree.ts#L38) +[src/tree/tree.ts:38](https://github.com/havelessbemore/dastal/blob/2fe24da/src/tree/tree.ts#L38) ___ @@ -129,7 +129,7 @@ Removes all elements. #### Defined in -[src/tree/tree.ts:42](https://github.com/havelessbemore/dastal/blob/e94627b/src/tree/tree.ts#L42) +[src/tree/tree.ts:42](https://github.com/havelessbemore/dastal/blob/2fe24da/src/tree/tree.ts#L42) ___ @@ -153,7 +153,7 @@ Delete an element from the tree. #### Defined in -[src/tree/tree.ts:50](https://github.com/havelessbemore/dastal/blob/e94627b/src/tree/tree.ts#L50) +[src/tree/tree.ts:50](https://github.com/havelessbemore/dastal/blob/2fe24da/src/tree/tree.ts#L50) ___ @@ -177,7 +177,7 @@ Check if an element is in the tree. #### Defined in -[src/tree/tree.ts:58](https://github.com/havelessbemore/dastal/blob/e94627b/src/tree/tree.ts#L58) +[src/tree/tree.ts:58](https://github.com/havelessbemore/dastal/blob/2fe24da/src/tree/tree.ts#L58) ___ @@ -202,4 +202,4 @@ Update a specific element. #### Defined in -[src/tree/tree.ts:67](https://github.com/havelessbemore/dastal/blob/e94627b/src/tree/tree.ts#L67) +[src/tree/tree.ts:67](https://github.com/havelessbemore/dastal/blob/2fe24da/src/tree/tree.ts#L67) diff --git a/docs/modules/arrayutils.md b/docs/modules/arrayutils.md new file mode 100644 index 0000000..81e6722 --- /dev/null +++ b/docs/modules/arrayutils.md @@ -0,0 +1,151 @@ +[dastal - v4.0.0](../README.md) / ArrayUtils + +# Namespace: ArrayUtils + +## Table of contents + +### Variables + +- [MAX\_ARRAY\_LENGTH](arrayutils.md#max_array_length) +- [MAX\_SAFE\_ARGUMENT\_LENGTH](arrayutils.md#max_safe_argument_length) + +### Functions + +- [isArray](arrayutils.md#isarray) +- [isTypedArray](arrayutils.md#istypedarray) +- [splice](arrayutils.md#splice) + +## Variables + +### MAX\_ARRAY\_LENGTH + +• `Const` **MAX\_ARRAY\_LENGTH**: ``4294967295`` + +The maximum length of an array. + +According to the [ECMA-262](https://tc39.es/ecma262/#array-index): + 0 <= array.length <= 2^32 - 1 + +If this value should be updated, please +submit a pull request with details supporting a new max length. + +#### Defined in + +src/collection/arrayUtils.ts:13 + +___ + +### MAX\_SAFE\_ARGUMENT\_LENGTH + +• `Const` **MAX\_SAFE\_ARGUMENT\_LENGTH**: ``32767`` + +The maximum number of arguments that can be safely accepted by a function. + +According to the [ECMA-262](https://tc39.es/ecma262/#sec-list-and-record-specification-type), there is no maximum. In practice, different +environments impose their own limit ([source](https://stackoverflow.com/questions/22747068/is-there-a-max-number-of-arguments-javascript-functions-can-accept)). + +This value was chosen through research, local testing and iteration. The actual number of arguments +accepted in an environment may be larger but hopefully not smaller. If errors are raised, +please submit a bug with your environment details and a new max length. + +#### Defined in + +src/collection/arrayUtils.ts:24 + +## Functions + +### isArray + +▸ **isArray**(`obj`): obj is T[] + +Check if a value is an Array or TypedArray. + +#### Type parameters + +| Name | Type | +| :------ | :------ | +| `T` | `T` = `any` | + +#### Parameters + +| Name | Type | Description | +| :------ | :------ | :------ | +| `obj` | `unknown` | The value to check. | + +#### Returns + +obj is T[] + +`true` if an Array or TypedArray, otherwise `false`. + +#### Defined in + +src/collection/arrayUtils.ts:32 + +___ + +### isTypedArray + +▸ `Const` **isTypedArray**(`obj`): obj is T[] + +Check if a value is a TypedArray. + +See [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray) +for more details. + +#### Type parameters + +| Name | Type | +| :------ | :------ | +| `T` | `T` = `any` | + +#### Parameters + +| Name | Type | Description | +| :------ | :------ | :------ | +| `obj` | `unknown` | The value to check. | + +#### Returns + +obj is T[] + +`true` if a TypedArray, otherwise `false`. + +#### Defined in + +src/collection/arrayUtils.ts:45 + +___ + +### splice + +▸ **splice**(`array`, `start?`, `count?`, `elements?`): `T`[] + +Removes elements from an array and, if necessary, inserts new elements in their place, returning the deleted elements. + +Contrary to Array.splice, this will not throw an error if too many new elements are given as arguments. + +#### Type parameters + +| Name | +| :------ | +| `T` | + +#### Parameters + +| Name | Type | Description | +| :------ | :------ | :------ | +| `array` | `T`[] | The array to splice. | +| `start?` | `number` | The zero-based location in the array from which to start removing elements. | +| `count?` | `number` | The number of elements to remove. | +| `elements?` | `Iterable` | The new elements to splice in. | + +#### Returns + +`T`[] + +- An array containing the elements that were deleted. + +#### Defined in + +src/collection/arrayUtils.ts:63 diff --git a/docs/modules/iteratorutils.md b/docs/modules/iteratorutils.md new file mode 100644 index 0000000..6d145ed --- /dev/null +++ b/docs/modules/iteratorutils.md @@ -0,0 +1,244 @@ +[dastal - v4.0.0](../README.md) / IteratorUtils + +# Namespace: IteratorUtils + +## Table of contents + +### Functions + +- [always](iteratorutils.md#always) +- [fill](iteratorutils.md#fill) +- [first](iteratorutils.md#first) +- [join](iteratorutils.md#join) +- [never](iteratorutils.md#never) +- [once](iteratorutils.md#once) +- [skip](iteratorutils.md#skip) +- [split](iteratorutils.md#split) + +## Functions + +### always + +▸ **always**(`fn`): `Iterator` + +Get an iterator that always returns a given value. + +#### Type parameters + +| Name | Type | +| :------ | :------ | +| `T` | `T` = `any` | + +#### Parameters + +| Name | Type | +| :------ | :------ | +| `fn` | () => `T` | + +#### Returns + +`Iterator` + +#### Defined in + +[src/collection/iteratorUtils.ts:4](https://github.com/havelessbemore/dastal/blob/2fe24da/src/collection/iteratorUtils.ts#L4) + +___ + +### fill + +▸ **fill**(`length`, `fn`): `Iterator` + +Get an iterator that returns a value a given amount of times. + +#### Type parameters + +| Name | Type | +| :------ | :------ | +| `T` | `T` = `any` | + +#### Parameters + +| Name | Type | +| :------ | :------ | +| `length` | `number` | +| `fn` | () => `T` | + +#### Returns + +`Iterator` + +#### Defined in + +[src/collection/iteratorUtils.ts:10](https://github.com/havelessbemore/dastal/blob/2fe24da/src/collection/iteratorUtils.ts#L10) + +___ + +### first + +▸ **first**(`n`, `iterator`): `Iterator` + +Iterate through the first num elements of an iterator. + +#### Type parameters + +| Name | Type | +| :------ | :------ | +| `T` | `T` = `any` | + +#### Parameters + +| Name | Type | Description | +| :------ | :------ | :------ | +| `n` | `number` | The number of elements to iterate. | +| `iterator` | `Iterator` | The iterator. | + +#### Returns + +`Iterator` + +- An iterator limited to the next n elements. + +#### Defined in + +[src/collection/iteratorUtils.ts:29](https://github.com/havelessbemore/dastal/blob/2fe24da/src/collection/iteratorUtils.ts#L29) + +___ + +### join + +▸ **join**(`iterators`): `Iterator` + +Join multiple iterators into one. + +#### Type parameters + +| Name | Type | +| :------ | :------ | +| `T` | `T` = `any` | + +#### Parameters + +| Name | Type | Description | +| :------ | :------ | :------ | +| `iterators` | `Iterator`\> | The iterators to join. | + +#### Returns + +`Iterator` + +#### Defined in + +[src/collection/iteratorUtils.ts:46](https://github.com/havelessbemore/dastal/blob/2fe24da/src/collection/iteratorUtils.ts#L46) + +___ + +### never + +▸ **never**(): `Iterator` + +Get an empty iterator. + +#### Type parameters + +| Name | Type | +| :------ | :------ | +| `T` | `T` = `any` | + +#### Returns + +`Iterator` + +#### Defined in + +[src/collection/iteratorUtils.ts:70](https://github.com/havelessbemore/dastal/blob/2fe24da/src/collection/iteratorUtils.ts#L70) + +___ + +### once + +▸ **once**(`fn`): `Iterator` + +Wrap a value in an iterator. + +#### Type parameters + +| Name | Type | +| :------ | :------ | +| `T` | `T` = `any` | + +#### Parameters + +| Name | Type | +| :------ | :------ | +| `fn` | () => `T` | + +#### Returns + +`Iterator` + +#### Defined in + +[src/collection/iteratorUtils.ts:76](https://github.com/havelessbemore/dastal/blob/2fe24da/src/collection/iteratorUtils.ts#L76) + +___ + +### skip + +▸ **skip**(`n`, `iterator`): `Iterator` + +Skip the next num elements of an iterator. + +#### Type parameters + +| Name | Type | +| :------ | :------ | +| `T` | `T` = `any` | + +#### Parameters + +| Name | Type | Description | +| :------ | :------ | :------ | +| `n` | `number` | The number of elements to skip. | +| `iterator` | `Iterator` | The iterator. | + +#### Returns + +`Iterator` + +- The iterator after skipping n elements. + +#### Defined in + +[src/collection/iteratorUtils.ts:95](https://github.com/havelessbemore/dastal/blob/2fe24da/src/collection/iteratorUtils.ts#L95) + +___ + +### split + +▸ **split**(`length`, `iterator`): `Iterator`\> + +Split an iterator into multiple iterators of a given length. + +#### Type parameters + +| Name | Type | +| :------ | :------ | +| `T` | `T` = `any` | + +#### Parameters + +| Name | Type | Description | +| :------ | :------ | :------ | +| `length` | `number` | The length of each iterator. | +| `iterator` | `Iterator` | The iterator to split. | + +#### Returns + +`Iterator`\> + +- An iterator of the resulting iterators. + +#### Defined in + +[src/collection/iteratorUtils.ts:114](https://github.com/havelessbemore/dastal/blob/2fe24da/src/collection/iteratorUtils.ts#L114) diff --git a/docs/modules/math.md b/docs/modules/math.md deleted file mode 100644 index caa78bd..0000000 --- a/docs/modules/math.md +++ /dev/null @@ -1,41 +0,0 @@ -[dastal - v3.0.0](../README.md) / math - -# Namespace: math - -## Table of contents - -### Namespaces - -- [u32](math.u32.md) - -### Functions - -- [clamp](math.md#clamp) - -## Functions - -### clamp - -▸ **clamp**(`num`, `min`, `max`): `number` - -Limits a number to be within a given range. - -f(x, min, max) = y, where min <= y <= max - -#### Parameters - -| Name | Type | Description | -| :------ | :------ | :------ | -| `num` | `number` | The number to clamp | -| `min` | `number` | The minimum result value, inclusive | -| `max` | `number` | The maximum result value, inclusive | - -#### Returns - -`number` - -The clamped number - -#### Defined in - -[src/math/num.ts:12](https://github.com/havelessbemore/dastal/blob/e94627b/src/math/num.ts#L12) diff --git a/docs/modules/numberutils.md b/docs/modules/numberutils.md new file mode 100644 index 0000000..fe29ddf --- /dev/null +++ b/docs/modules/numberutils.md @@ -0,0 +1,128 @@ +[dastal - v4.0.0](../README.md) / NumberUtils + +# Namespace: NumberUtils + +## Table of contents + +### Functions + +- [clamp](numberutils.md#clamp) +- [wrap](numberutils.md#wrap) +- [wrapLeft](numberutils.md#wrapleft) +- [wrapRight](numberutils.md#wrapright) + +## Functions + +### clamp + +▸ **clamp**(`num`, `min`, `max`): `number` + +Limits a number to be within a given range. + +f(x, min, max) = y, where min <= y <= max + +#### Parameters + +| Name | Type | Description | +| :------ | :------ | :------ | +| `num` | `number` | The number to clamp | +| `min` | `number` | The minimum result value, inclusive | +| `max` | `number` | The maximum result value, inclusive | + +#### Returns + +`number` + +The clamped number + +#### Defined in + +[src/math/numberUtils.ts:12](https://github.com/havelessbemore/dastal/blob/2fe24da/src/math/numberUtils.ts#L12) + +___ + +### wrap + +▸ **wrap**(`num`, `min`, `max`): `number` + +Wraps a number if outside a given range + +#### Parameters + +| Name | Type | Description | +| :------ | :------ | :------ | +| `num` | `number` | The number to wrap | +| `min` | `number` | The minimum result value, inclusive | +| `max` | `number` | The maximum result value, inclusive | + +#### Returns + +`number` + +- The wrapped number + +#### Defined in + +[src/math/numberUtils.ts:58](https://github.com/havelessbemore/dastal/blob/2fe24da/src/math/numberUtils.ts#L58) + +___ + +### wrapLeft + +▸ **wrapLeft**(`num`, `min`, `max`): `number` + +Wraps a number if below a given range + +f(x, min, max) = { + x, where x >= min + max - (min - x), where x < min +} + +#### Parameters + +| Name | Type | Description | +| :------ | :------ | :------ | +| `num` | `number` | The number to wrap | +| `min` | `number` | The minimum result value, inclusive | +| `max` | `number` | The maximum result value, inclusive | + +#### Returns + +`number` + +- The wrapped number + +#### Defined in + +[src/math/numberUtils.ts:29](https://github.com/havelessbemore/dastal/blob/2fe24da/src/math/numberUtils.ts#L29) + +___ + +### wrapRight + +▸ **wrapRight**(`num`, `min`, `max`): `number` + +Wraps a number if above a given range + +f(x, min, max) = { + x, where x <= max + min + (x - max), where x > max +} + +#### Parameters + +| Name | Type | Description | +| :------ | :------ | :------ | +| `num` | `number` | The number to wrap | +| `min` | `number` | The minimum result value, inclusive | +| `max` | `number` | The maximum result value, inclusive | + +#### Returns + +`number` + +- The wrapped number + +#### Defined in + +[src/math/numberUtils.ts:46](https://github.com/havelessbemore/dastal/blob/2fe24da/src/math/numberUtils.ts#L46) diff --git a/docs/modules/math.u32.md b/docs/modules/u32.md similarity index 68% rename from docs/modules/math.u32.md rename to docs/modules/u32.md index d9c15f1..318d32a 100644 --- a/docs/modules/math.u32.md +++ b/docs/modules/u32.md @@ -1,27 +1,24 @@ -[dastal - v3.0.0](../README.md) / [math](math.md) / u32 +[dastal - v4.0.0](../README.md) / u32 # Namespace: u32 -[math](math.md).u32 - Bit hacks for 32-bit unsigned numbers. ## Table of contents ### Functions -- [bitsSet](math.u32.md#bitsset) -- [invert](math.u32.md#invert) -- [isPow2](math.u32.md#ispow2) -- [lsb](math.u32.md#lsb) -- [lsp](math.u32.md#lsp) -- [lsps](math.u32.md#lsps) -- [mlsp](math.u32.md#mlsp) -- [msb](math.u32.md#msb) -- [msp](math.u32.md#msp) -- [msps](math.u32.md#msps) -- [reverse](math.u32.md#reverse) -- [u32](math.u32.md#u32) +- [bitsSet](u32.md#bitsset) +- [invert](u32.md#invert) +- [isPow2](u32.md#ispow2) +- [lsb](u32.md#lsb) +- [lsp](u32.md#lsp) +- [lsps](u32.md#lsps) +- [msb](u32.md#msb) +- [msp](u32.md#msp) +- [msps](u32.md#msps) +- [reverse](u32.md#reverse) +- [u32](u32.md#u32) ## Functions @@ -43,7 +40,7 @@ Get the number of bits set of a 32-bit unsigned number ([source](https://graphic #### Defined in -[src/math/u32.ts:10](https://github.com/havelessbemore/dastal/blob/e94627b/src/math/u32.ts#L10) +[src/math/u32.ts:10](https://github.com/havelessbemore/dastal/blob/2fe24da/src/math/u32.ts#L10) ___ @@ -69,7 +66,7 @@ The inverted number #### Defined in -[src/math/u32.ts:27](https://github.com/havelessbemore/dastal/blob/e94627b/src/math/u32.ts#L27) +[src/math/u32.ts:27](https://github.com/havelessbemore/dastal/blob/2fe24da/src/math/u32.ts#L27) ___ @@ -93,7 +90,7 @@ Example: 8 (1000) -> true #### Defined in -[src/math/u32.ts:38](https://github.com/havelessbemore/dastal/blob/e94627b/src/math/u32.ts#L38) +[src/math/u32.ts:38](https://github.com/havelessbemore/dastal/blob/2fe24da/src/math/u32.ts#L38) ___ @@ -117,7 +114,7 @@ The lowest bit set #### Defined in -[src/math/u32.ts:48](https://github.com/havelessbemore/dastal/blob/e94627b/src/math/u32.ts#L48) +[src/math/u32.ts:48](https://github.com/havelessbemore/dastal/blob/2fe24da/src/math/u32.ts#L48) ___ @@ -141,7 +138,7 @@ Get the Least Significant Power of a 32-bit unsigned number #### Defined in -[src/math/u32.ts:62](https://github.com/havelessbemore/dastal/blob/e94627b/src/math/u32.ts#L62) +[src/math/u32.ts:62](https://github.com/havelessbemore/dastal/blob/2fe24da/src/math/u32.ts#L62) ___ @@ -165,40 +162,7 @@ Example: 54 (110110) -> 6 (000110) #### Defined in -[src/math/u32.ts:72](https://github.com/havelessbemore/dastal/blob/e94627b/src/math/u32.ts#L72) - -___ - -### mlsp - -▸ **mlsp**(`a`): `number` - -Get the Most Significant Power of the Least Significant Power Set of a 32-bit unsigned number. - -Example: 54 (110110) -> 4 (000100) - -111111 -000000 -000000 - -000010 -111000 -001000 -000100 - -#### Parameters - -| Name | Type | -| :------ | :------ | -| `a` | `number` | - -#### Returns - -`number` - -#### Defined in - -[src/math/u32.ts:91](https://github.com/havelessbemore/dastal/blob/e94627b/src/math/u32.ts#L91) +[src/math/u32.ts:72](https://github.com/havelessbemore/dastal/blob/2fe24da/src/math/u32.ts#L72) ___ @@ -222,7 +186,7 @@ Get the Most Significant Bit of a 32-bit unsigned number #### Defined in -[src/math/u32.ts:101](https://github.com/havelessbemore/dastal/blob/e94627b/src/math/u32.ts#L101) +[src/math/u32.ts:93](https://github.com/havelessbemore/dastal/blob/2fe24da/src/math/u32.ts#L93) ___ @@ -246,7 +210,7 @@ Get the Most Significant Power of a 32-bit unsigned number #### Defined in -[src/math/u32.ts:116](https://github.com/havelessbemore/dastal/blob/e94627b/src/math/u32.ts#L116) +[src/math/u32.ts:108](https://github.com/havelessbemore/dastal/blob/2fe24da/src/math/u32.ts#L108) ___ @@ -270,7 +234,7 @@ Example: 50 (110010) -> 48 (110000) #### Defined in -[src/math/u32.ts:131](https://github.com/havelessbemore/dastal/blob/e94627b/src/math/u32.ts#L131) +[src/math/u32.ts:123](https://github.com/havelessbemore/dastal/blob/2fe24da/src/math/u32.ts#L123) ___ @@ -294,7 +258,7 @@ Example: 50 (110010) -> 19 (010011) #### Defined in -[src/math/u32.ts:146](https://github.com/havelessbemore/dastal/blob/e94627b/src/math/u32.ts#L146) +[src/math/u32.ts:138](https://github.com/havelessbemore/dastal/blob/2fe24da/src/math/u32.ts#L138) ___ @@ -316,4 +280,4 @@ Turn a number into an unsigned 32-bit number #### Defined in -[src/math/u32.ts:158](https://github.com/havelessbemore/dastal/blob/e94627b/src/math/u32.ts#L158) +[src/math/u32.ts:150](https://github.com/havelessbemore/dastal/blob/2fe24da/src/math/u32.ts#L150) diff --git a/package.json b/package.json index 3778019..a6c17ec 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "dastal", - "version": "3.0.0", + "version": "4.0.0", "description": "Data Structures & Algorithms implementations", "main": "lib/src/index.js", "types": "lib/src/index.d.ts", diff --git a/src/TODO/array/index.ts b/src/TODO/array/index.ts deleted file mode 100644 index cbc2fed..0000000 --- a/src/TODO/array/index.ts +++ /dev/null @@ -1 +0,0 @@ -export * from './bigArray'; diff --git a/src/TODO/segmentTree/composedFunction.ts b/src/TODO/segmentTree/composedFunction.ts deleted file mode 100644 index 67dd0a8..0000000 --- a/src/TODO/segmentTree/composedFunction.ts +++ /dev/null @@ -1,25 +0,0 @@ -import { Transform } from 'stream'; - -export interface ComposedFunction { - (input: I): O; -} - -export function toStream(fn: (arg: I) => O): Transform { - return new Transform({ - allowHalfOpen: false, - decodeStrings: false, - highWaterMark: 1, - objectMode: true, - transform(arg: I, _, cb) { - try { - cb(undefined, fn(arg)); - } catch (err) { - cb(err); - } - }, - }); -} - -toStream(() => 3) - .pipe(toStream((v) => console.log(v))) - .read(); diff --git a/src/TODO/segmentTree/postOrderSegmentTree.ts b/src/TODO/segmentTree/postOrderSegmentTree.ts deleted file mode 100644 index a51d264..0000000 --- a/src/TODO/segmentTree/postOrderSegmentTree.ts +++ /dev/null @@ -1,210 +0,0 @@ -import { bitsSet } from '../../math/u32'; -import { SegmentTree } from '../../segmentTree/segmentTree'; -/* -export class PostOrderSegmentTree implements SegmentTree { - protected array: T[]; - protected length: number; - - constructor() { - this.array = []; - this.length = 0; - } - - clear(): void { - this.array.length = 0; - this.length = 0; - } - - pop(): T | undefined { - throw new Error('TODO'); - } - - push(element: T): number { - throw new Error('TODO'); - } - - query(min: number, max: number): T { - throw new Error('TODO'); - } - - get size(): number { - throw new Error('TODO'); - } - - *[Symbol.iterator](): Iterator { - let i = 0; - for (let j = 0; j < this.length; j = 2 * i - onBits(i)) { - yield this.array[j]; - ++i; - } - } - - update(min: number, max: number, operation: Operation): void { - throw new Error('TODO'); - } -} -*/ - -/* -/** - * A helper method to apply updates to a given range. This method - * applies updates down only to the necessary aggregation nodes - * for the range. - * - * @param min - The start index of the range, inclusive. - * @param max - The end index of the range, exclusive. - * - protected propagate(min: number, max: number): void { - // (a +1) & -(a + 1) - const stack: number[] = []; - - // Get top complete aggregation nodes in the range - // for (let i = msp(min); i < max; stack.push(i - 1)) { - // i += lsp(i | msp(this.array.length - i)); - // } - - // Get top complete aggregation nodes in the range in reverse - - // Iterate through the range, jumping across the largest possible subranges - do { - const offset = lsp(min | msp(max - min)); - const mid = min + (offset >>> 1) - 1; - min += offset; - - // Apply updates down to the current subrange - do { - const par = stack.pop()!; - if (this.lazy[par]) { - } - } while (true); - - // let value = operation(this.array[top], min >>> 1, (min + offset) >>> 1); - } while (min < max); -} -/** - * A helper method to apply updates to a given range. This method - * applies updates down to individual elements in the range. - * - * @param min - The start index of the range, inclusive. - * @param max - The end index of the range, exclusive. - * -protected flush(min: number, max: number): void { - throw new Error('TODO'); -} -*/ - -/* - lazyUpdate(min: number, max: number, operation: LazyOperation): void { - // Sanitize range - if (min >= max) { - return; - } - if (min < 0 || max > this.size) { - throw new RangeError(`Range [${min}..${max}) not in [0..${this.size})`); - } - - // Translate range to interior indices - min *= 2; - max *= 2; - - // Apply pending updates on the range - this.propagate(min, max); - - // Taking the longest possible jumps from min to max... - let value: T; - do { - // Make the jump and update its lowest common ancestor - const offset = lsp(min | msp(max - min)); - const top = min + (offset >>> 1) - 1; - value = operation(this.array[top], min >>> 1, (min + offset) >>> 1); - this.array[top] = value; - min += offset - 1; - - // Mark children for lazy update - if (top & 1) { - (this.lazy[top] ?? new LinkedList()).push(operation); - } - - // Update aggregation nodes - for (let mask = 2 * lsp(top + 1); min & mask; mask *= 2) { - value = this.combine(this.array[min - mask - (mask >>> 1)], value); - this.array[min - mask] = value; - } - } while (++min < max); - - // Update remaining aggregation nodes - let dc = 0; - let dp = lsp(min); - max = msb(min ^ this.array.length) - lsb(min); - for (--min; max > 0; --max) { - value = this.combine(value, this.array[min + (dp >>> 1) - dc]); - this.array[min] = value; - dc = (min & (2 * dp)) >>> 0; - min += dp - dc; - dp *= 2; - } - - // Update the incomplete aggregation node - this.array[min] = value; - } - */ - -/* - protected propagate(min: number, max: number): void { - // (a +1) & -(a + 1) - const stack: number[] = []; - - // Get top complete aggregation nodes in the range - // for (let i = msp(min); i < max; stack.push(i - 1)) { - // i += lsp(i | msp(this.array.length - i)); - // } - - // Get top complete aggregation nodes in the range in reverse - - // Iterate through the range, jumping across the largest possible subranges - do { - const offset = lsp(min | msp(max - min)); - const mid = min + (offset >>> 1) - 1; - min += offset; - - // Apply updates down to the current subrange - do { - const par = stack.pop()!; - if (this.lazy[par]) { - } - } while (true); - - // let value = operation(this.array[top], min >>> 1, (min + offset) >>> 1); - } while (min < max); - - throw new Error('Figure out initial i'); - /* - let i = msp(max); - for (i = lsp(i | msp(this.array.length - i)); i > min; i -= i & -i) { - stack.push(i - (lsp(i) >>> 1) - 1); - } - - // Take the longest possible jumps from min to max - while (min < max) { - const offset = lsp(min | msp(max - min)); - min += offset; - - const i = min - 1 + (offset >>> 1); - - - } - */ - -// Check each level - -/* - // Get existing - const q = []; - for (let i = min; i < max; ) { - const offset = lsp(min | msp(max - min)); - i += offset; - } - - max = msb(min ^ this.array.length) - lsb(min); - } - */ diff --git a/src/array/utils.ts b/src/array/utils.ts deleted file mode 100644 index 3675b3e..0000000 --- a/src/array/utils.ts +++ /dev/null @@ -1,33 +0,0 @@ -/** - * The maximum length of an array. - * - * According to [ECMA-262](https://tc39.es/ecma262/#array-index): - * 0 <= array.length <= 2^32 - 1 - */ -export const MAX_ARRAY_LENGTH = 4294967295; -/** - * Check if a value is an Array or TypedArray. - * - * @param obj - The value to check. - * - * @returns `true` if an Array or TypedArray, otherwise `false`. - */ -export function isArray(obj: unknown): obj is T[] { - return obj instanceof Array || isTypedArray(obj); -} -/** - * Check if a value is a TypedArray. - * - * See [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray) - * for more details. - * - * @param obj - The value to check. - * - * @returns `true` if a TypedArray, otherwise `false`. - */ -export const isTypedArray = (() => { - const TypedArray = Object.getPrototypeOf(Uint8Array); - return function isTypedArray(obj: unknown): obj is T[] { - return obj instanceof TypedArray; - }; -})(); diff --git a/src/collection/arrayUtils.ts b/src/collection/arrayUtils.ts new file mode 100644 index 0000000..9b10267 --- /dev/null +++ b/src/collection/arrayUtils.ts @@ -0,0 +1,100 @@ +import { first } from 'src/collection/iteratorUtils'; +import { clamp, wrapLeft } from 'src/math/numberUtils'; + +/** + * The maximum length of an array. + * + * According to the [ECMA-262](https://tc39.es/ecma262/#array-index): + * 0 <= array.length <= 2^32 - 1 + * + * If this value should be updated, please + * submit a pull request with details supporting a new max length. + */ +export const MAX_ARRAY_LENGTH = 4294967295; +/** + * The maximum number of arguments that can be safely accepted by a function. + * + * According to the [ECMA-262](https://tc39.es/ecma262/#sec-list-and-record-specification-type), there is no maximum. In practice, different + * environments impose their own limit ([source](https://stackoverflow.com/questions/22747068/is-there-a-max-number-of-arguments-javascript-functions-can-accept)). + * + * This value was chosen through research, local testing and iteration. The actual number of arguments + * accepted in an environment may be larger but hopefully not smaller. If errors are raised, + * please submit a bug with your environment details and a new max length. + */ +export const MAX_SAFE_ARGUMENT_LENGTH = 32767; +/** + * Check if a value is an Array or TypedArray. + * + * @param obj - The value to check. + * + * @returns `true` if an Array or TypedArray, otherwise `false`. + */ +export function isArray(obj: unknown): obj is T[] { + return obj instanceof Array || isTypedArray(obj); +} +/** + * Check if a value is a TypedArray. + * + * See [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray) + * for more details. + * + * @param obj - The value to check. + * + * @returns `true` if a TypedArray, otherwise `false`. + */ +export const isTypedArray = (() => { + const TypedArray = Object.getPrototypeOf(Uint8Array); + return function isTypedArray(obj: unknown): obj is T[] { + return obj instanceof TypedArray; + }; +})(); +/** + * Removes elements from an array and, if necessary, inserts new elements in their place, returning the deleted elements. + * + * Contrary to Array.splice, this will not throw an error if too many new elements are given as arguments. + * + * @param array - The array to splice. + * @param start - The zero-based location in the array from which to start removing elements. + * @param count - The number of elements to remove. + * @param elements - The new elements to splice in. + * + * @returns - An array containing the elements that were deleted. + */ +export function splice(array: T[], start?: number, count?: number, elements?: Iterable): T[] { + start = clamp(wrapLeft(start ?? 0, 0, array.length), 0, array.length); + count = clamp(count ?? array.length, 0, array.length - start); + + // Base case + if (elements == null) { + return array.splice(start, count); + } + + const maxStepSize = MAX_SAFE_ARGUMENT_LENGTH - 2; + const iterator = elements[Symbol.iterator](); + + // Perform the initial splice + let stepSize = array.length - count; + const maxElems = MAX_ARRAY_LENGTH - stepSize; + let n = Math.min(maxStepSize, maxElems); + const out = array.splice(start, count, ...{ [Symbol.iterator]: () => first(n, iterator) }); + stepSize = array.length - stepSize; + start += stepSize; + + // Splice in new elements as long as there is space in the array + for (n = maxElems - stepSize; n >= maxStepSize && stepSize >= maxStepSize; n -= stepSize) { + stepSize = array.length; + array.splice(start, 0, ...{ [Symbol.iterator]: () => first(maxStepSize, iterator) }); + stepSize = array.length - stepSize; + start += stepSize; + } + if (n > 0 && stepSize >= maxStepSize) { + array.splice(start, 0, ...{ [Symbol.iterator]: () => first(n, iterator) }); + } + + // If maximum array capacity reached + if (iterator.next().done != true) { + throw new RangeError('Invalid array length'); + } + + return out; +} diff --git a/src/collection/index.ts b/src/collection/index.ts index b0ac26a..5b52cd9 100644 --- a/src/collection/index.ts +++ b/src/collection/index.ts @@ -1,7 +1,18 @@ import { Collection } from './collection'; +export * as ArrayUtils from './arrayUtils'; export * from './collection'; +export * as IteratorUtils from './iteratorUtils'; +/** + * Check if a value is a {@link Collection}. + * + * @param obj - The value to check. + * + * @returns - `true` if obj is a Collection, `false` otherwise. + */ export function isCollection(obj: any): obj is Collection { - return 'size' in obj && typeof obj['size'] === 'number'; + return ( + obj != null && typeof obj['size'] === 'number' && typeof obj[Symbol.iterator] === 'function' + ); } diff --git a/src/collection/iteratorUtils.ts b/src/collection/iteratorUtils.ts new file mode 100644 index 0000000..94fc895 --- /dev/null +++ b/src/collection/iteratorUtils.ts @@ -0,0 +1,133 @@ +/** + * Get an iterator that always returns a given value. + */ +export function always(fn: () => T): Iterator { + return { next: () => ({ done: false, value: fn() }) }; +} +/** + * Get an iterator that returns a value a given amount of times. + */ +export function fill(length: number, fn: () => T): Iterator { + return { + next: () => { + if (length < 1) { + return { done: true, value: undefined }; + } + --length; + return { done: false, value: fn() }; + }, + }; +} +/** + * Iterate through the first num elements of an iterator. + * + * @param n - The number of elements to iterate. + * @param iterator - The iterator. + * + * @returns - An iterator limited to the next n elements. + */ +export function first(n: number, iterator: Iterator): Iterator { + return { + next: () => { + if (n < 1) { + return { done: true, value: undefined }; + } + const res = iterator.next(); + n = res.done ? 0 : n - 1; + return res; + }, + }; +} +/** + * Join multiple iterators into one. + * + * @param iterators - The iterators to join. + */ +export function join(iterators: Iterator>): Iterator { + let iterator: Iterator | undefined = { next: () => ({ done: true, value: undefined }) }; + return { + next: () => { + if (iterator == null) { + return { done: true, value: undefined }; + } + let res = iterator.next(); + while (res.done) { + const res2 = iterators.next(); + if (res2.done) { + iterator = undefined; + return { done: true, value: undefined }; + } + iterator = res2.value; + res = iterator.next(); + } + return res; + }, + }; +} +/** + * Get an empty iterator. + */ +export function never(): Iterator { + return { next: () => ({ done: true, value: undefined }) }; +} +/** + * Wrap a value in an iterator. + */ +export function once(fn: () => T): Iterator { + let done = false; + return { + next: () => { + const res = { done, value: fn() }; + done = true; + fn = () => undefined!; + return res; + }, + }; +} +/** + * Skip the next num elements of an iterator. + * + * @param n - The number of elements to skip. + * @param iterator - The iterator. + * + * @returns - The iterator after skipping n elements. + */ +export function skip(n: number, iterator: Iterator): Iterator { + let fn = () => { + let res: IteratorResult = { done: false, value: undefined! }; + while (n-- > 0 && !res.done) { + res = iterator.next(); + } + fn = iterator.next.bind(iterator); + return res; + }; + return { next: () => fn() }; +} +/** + * Split an iterator into multiple iterators of a given length. + * + * @param length - The length of each iterator. + * @param iterator - The iterator to split. + * + * @returns - An iterator of the resulting iterators. + */ +export function split(length: number, iterator: Iterator): Iterator> { + if (length < 1) { + return { next: () => ({ done: true, value: undefined }) }; + } + let done = false; + return { + next: () => { + if (done) { + return { done, value: undefined }; + } + const iter = first(length, iterator); + const res = iter.next(); + if (res.done) { + done = true; + return { done, value: undefined }; + } + return { done, value: join([once(() => res.value), iter][Symbol.iterator]()) }; + }, + }; +} diff --git a/src/heap/binaryHeap.ts b/src/heap/binaryHeap.ts index 3d1048a..8b04ca5 100644 --- a/src/heap/binaryHeap.ts +++ b/src/heap/binaryHeap.ts @@ -1,4 +1,4 @@ -import { isArray, MAX_ARRAY_LENGTH } from 'src/array/utils'; +import { isArray, MAX_ARRAY_LENGTH } from 'src/collection/arrayUtils'; import { CompareFn } from '..'; import { Heap } from './heap'; import { bubbleUp, heapify, sinkDown } from './utils'; diff --git a/src/heap/skewHeap.ts b/src/heap/skewHeap.ts index 80065d9..bb3798e 100644 --- a/src/heap/skewHeap.ts +++ b/src/heap/skewHeap.ts @@ -1,4 +1,4 @@ -import { isArray } from 'src/array/utils'; +import { isArray } from 'src/collection/arrayUtils'; import { BinaryTreeNode } from 'src/tree/binaryTreeNode'; import { clone, preOrderTraverse, toBinaryTree } from 'src/tree/binaryTreeUtils'; import { CompareFn } from '..'; diff --git a/src/index.ts b/src/index.ts index 5430e33..c543ee6 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,11 +1,11 @@ +export * from './collection'; export * from './heap'; export * from './list'; -export * as math from './math'; +export * from './math'; export * from './queue'; export * from './segmentTree'; export * from './stack'; export * from './tree'; -// export * from './trie'; /** * A function that combines two elements into another. diff --git a/src/list/arrayList.ts b/src/list/arrayList.ts index 0dd3331..7a36b6a 100644 --- a/src/list/arrayList.ts +++ b/src/list/arrayList.ts @@ -1,7 +1,7 @@ -import { clamp } from 'src/math'; +import { splice } from 'src/collection/arrayUtils'; +import { clamp, wrapLeft } from 'src/math/numberUtils'; import { CompareFn } from '..'; import { List } from './list'; -import { batch, cwrap } from './utils'; /** * An implementation of the {@link List} interface using an array @@ -29,10 +29,7 @@ export class ArrayList implements List { addAll(index: number, elements: Iterable): number { if (index >= 0 && index <= this.size) { - for (const items of batch(10000, elements)) { - this.array.splice(index, 0, ...items); - index += items.length; - } + splice(this.array, index, 0, elements); } return this.size; } @@ -50,16 +47,16 @@ export class ArrayList implements List { } copyWithin(index: number, min?: number, max?: number): this { - index = cwrap(index ?? 0, 0, this.size); - min = cwrap(min ?? 0, 0, this.size); - max = cwrap(max ?? this.size, 0, this.size); + index = clamp(wrapLeft(index, 0, this.size), 0, this.size); + min = clamp(wrapLeft(min ?? 0, 0, this.size), 0, this.size); + max = clamp(wrapLeft(max ?? this.size, 0, this.size), 0, this.size); this.array.copyWithin(index, min, max); return this; } fill(element: T, min?: number, max?: number): this { - min = cwrap(min ?? 0, 0, this.size); - max = cwrap(max ?? this.size, 0, this.size); + min = clamp(wrapLeft(min ?? 0, 0, this.size), 0, this.size); + max = clamp(wrapLeft(max ?? this.size, 0, this.size), 0, this.size); this.array.fill(element, min, max); return this; } @@ -90,8 +87,8 @@ export class ArrayList implements List { } reverse(min?: number, max?: number): this { - min = cwrap(min ?? 0, 0, this.size); - max = cwrap(max ?? this.size, 0, this.size) - 1; + min = clamp(wrapLeft(min ?? 0, 0, this.size), 0, this.size); + max = clamp(wrapLeft(max ?? this.size, 0, this.size), 0, this.size) - 1; while (min < max) { const temp = this.array[min]; this.array[min++] = this.array[max]; @@ -122,14 +119,7 @@ export class ArrayList implements List { } splice(start?: number, count?: number, elements?: Iterable): List { - start = cwrap(start ?? 0, 0, this.size); - count = clamp(count ?? this.size, 0, this.size - start); - const list = new ArrayList(this.array.splice(start, count)); - for (const items of batch(10000, elements ?? [])) { - this.array.splice(start, 0, ...items); - start += items.length; - } - return list; + return new ArrayList(splice(this.array, start, count, elements)); } sort(compareFn: CompareFn): this { @@ -172,8 +162,8 @@ export class ArrayList implements List { max = undefined; } } - min = cwrap((min as number) ?? 0, 0, this.size); - max = cwrap((max as number) ?? this.size, 0, this.size); + min = clamp(wrapLeft((min as number) ?? 0, 0, this.size), 0, this.size); + max = clamp(wrapLeft((max as number) ?? this.size, 0, this.size), 0, this.size); while (min < max) { this.array[min] = callback(this.array[min], min); ++min; @@ -182,7 +172,7 @@ export class ArrayList implements List { } *view(min?: number, max?: number): Iterable { - min = cwrap(min ?? 0, 0, this.size); + min = clamp(wrapLeft(min ?? 0, 0, this.size), 0, this.size); let len: () => number; if (max == null) { diff --git a/src/list/doublyLinkedList.ts b/src/list/doublyLinkedList.ts index cb8d6a2..6e7abf2 100644 --- a/src/list/doublyLinkedList.ts +++ b/src/list/doublyLinkedList.ts @@ -1,8 +1,8 @@ -import { clamp } from 'src/math'; +import { clamp, wrapLeft } from 'src/math/numberUtils'; import { CompareFn } from '..'; import { DoublyLinkedNode } from './doublyLinkedNode'; import { List } from './list'; -import { linkedMergeSort, cwrap } from './utils'; +import { linkedMergeSort } from './utils'; /** * A (circular) doubly-linked list implementation of the {@link List} interface. @@ -63,14 +63,14 @@ export class DoublyLinkedList implements List { copyWithin(index: number, min?: number, max?: number): this { // Check if copying to the same section - index = cwrap(index, 0, this.length); - min = cwrap(min ?? 0, 0, this.length); + index = clamp(wrapLeft(index, 0, this.length), 0, this.length); + min = clamp(wrapLeft(min ?? 0, 0, this.length), 0, this.length); if (min === index) { return this; } // Check if the section to copy has no length - max = cwrap(max ?? this.length, 0, this.length); + max = clamp(wrapLeft(max ?? this.length, 0, this.length), 0, this.length); max = min + Math.min(max - min, this.length - index); if (min >= max) { return this; @@ -100,8 +100,8 @@ export class DoublyLinkedList implements List { } fill(element: T, min?: number, max?: number): this { - min = cwrap(min ?? 0, 0, this.length); - max = cwrap(max ?? this.length, 0, this.length); + min = clamp(wrapLeft(min ?? 0, 0, this.length), 0, this.length); + max = clamp(wrapLeft(max ?? this.length, 0, this.length), 0, this.length); if (min < max) { let node = this._get(min); do { @@ -156,8 +156,8 @@ export class DoublyLinkedList implements List { } reverse(min?: number, max?: number): this { - min = cwrap(min ?? 0, 0, this.length); - max = cwrap(max ?? this.length, 0, this.length); + min = clamp(wrapLeft(min ?? 0, 0, this.length), 0, this.length); + max = clamp(wrapLeft(max ?? this.length, 0, this.length), 0, this.length); if (max - min < 2) { return this; } @@ -207,7 +207,7 @@ export class DoublyLinkedList implements List { } splice(start?: number, count?: number, elements?: Iterable): List { - start = cwrap(start ?? 0, 0, this.size); + start = clamp(wrapLeft(start ?? 0, 0, this.length), 0, this.length); count = clamp(count ?? this.size, 0, this.size - start); // If not modifying the list @@ -281,8 +281,8 @@ export class DoublyLinkedList implements List { max = undefined; } } - min = cwrap((min as number) ?? 0, 0, this.length); - max = cwrap((max as number) ?? this.length, 0, this.length); + min = clamp(wrapLeft((min as number) ?? 0, 0, this.length), 0, this.length); + max = clamp(wrapLeft((max as number) ?? this.length, 0, this.length), 0, this.length); if (min < max) { let node = this._get(min); do { @@ -294,7 +294,7 @@ export class DoublyLinkedList implements List { } *view(min?: number, max?: number): Iterable { - min = cwrap(min ?? 0, 0, this.length); + min = clamp(wrapLeft(min ?? 0, 0, this.length), 0, this.length); let len: () => number; if (max == null) { diff --git a/src/list/linkedList.ts b/src/list/linkedList.ts index 9508c9b..cd39d0c 100644 --- a/src/list/linkedList.ts +++ b/src/list/linkedList.ts @@ -1,8 +1,8 @@ -import { clamp } from 'src/math'; +import { clamp, wrapLeft } from 'src/math/numberUtils'; import { CompareFn } from '..'; import { LinkedNode } from './linkedNode'; import { List } from './list'; -import { linkedMergeSort, cwrap } from './utils'; +import { linkedMergeSort } from './utils'; /** * A (circular) linked list implementation of the {@link List} interface. @@ -67,14 +67,14 @@ export class LinkedList implements List { copyWithin(index: number, min?: number, max?: number): this { // Check if copying to itself - index = cwrap(index, 0, this.length); - min = cwrap(min ?? 0, 0, this.length); + index = clamp(wrapLeft(index, 0, this.length), 0, this.length); + min = clamp(wrapLeft(min ?? 0, 0, this.length), 0, this.length); if (min === index) { return this; } // Check if the section to copy has no length - max = cwrap(max ?? this.length, 0, this.length); + max = clamp(wrapLeft(max ?? this.length, 0, this.length), 0, this.length); max = min + Math.min(max - min, this.length - index); if (min >= max) { return this; @@ -109,8 +109,8 @@ export class LinkedList implements List { } fill(element: T, min?: number, max?: number): this { - min = cwrap(min ?? 0, 0, this.length); - max = cwrap(max ?? this.length, 0, this.length); + min = clamp(wrapLeft(min ?? 0, 0, this.length), 0, this.length); + max = clamp(wrapLeft(max ?? this.length, 0, this.length), 0, this.length); if (min < max) { let node = this._get(min); do { @@ -170,8 +170,8 @@ export class LinkedList implements List { } reverse(min?: number, max?: number): this { - min = cwrap(min ?? 0, 0, this.length); - max = cwrap(max ?? this.length, 0, this.length); + min = clamp(wrapLeft(min ?? 0, 0, this.length), 0, this.length); + max = clamp(wrapLeft(max ?? this.length, 0, this.length), 0, this.length); if (max - min < 2) { return this; } @@ -214,7 +214,7 @@ export class LinkedList implements List { } splice(start?: number, count?: number, elements?: Iterable): List { - start = cwrap(start ?? 0, 0, this.size); + start = clamp(wrapLeft(start ?? 0, 0, this.length), 0, this.length); count = clamp(count ?? this.size, 0, this.size - start); // If not modifying the list @@ -286,8 +286,8 @@ export class LinkedList implements List { max = undefined; } } - min = cwrap((min as number) ?? 0, 0, this.length); - max = cwrap((max as number) ?? this.length, 0, this.length); + min = clamp(wrapLeft((min as number) ?? 0, 0, this.length), 0, this.length); + max = clamp(wrapLeft((max as number) ?? this.length, 0, this.length), 0, this.length); if (min < max) { let node = this._get(min); do { @@ -299,7 +299,7 @@ export class LinkedList implements List { } *view(min?: number, max?: number): Iterable { - min = cwrap(min ?? 0, 0, this.length); + min = clamp(wrapLeft(min ?? 0, 0, this.length), 0, this.length); let len: () => number; if (max == null) { diff --git a/src/list/utils.ts b/src/list/utils.ts index d33d3ba..1d855ec 100644 --- a/src/list/utils.ts +++ b/src/list/utils.ts @@ -1,85 +1,7 @@ -import { isArray } from '../array/utils'; import { CompareFn } from '..'; import { DoublyLinkedNode } from './doublyLinkedNode'; import { LinkedNode } from './linkedNode'; -import { clamp } from 'src/math'; -/** - * Groups an iterable into batches of a given size. - * - * @param size - The maximum batch size - * @param iterable - The iterable to batch - * - * @returns An iterable of batches - * - * @internal - */ -export function batch( - size: number, - iterable: Iterable, -): Generator { - if (isArray(iterable)) { - return batchArray(size, iterable); - } - return batchIterable(size, iterable); -} -/** - * Groups an iterable into batches of a given size. - * - * @param size - The maximum batch size - * @param iterable - The iterable to batch - * - * @returns An iterable of batches - * - * @internal - */ -export function* batchArray(size: number, array: T[]): Generator { - let min = 0; - while (min < array.length) { - const max = min + size; - size = (yield array.slice(min, max)) ?? size; - min = max; - } -} -/** - * Groups an iterable into batches of a given size. - * - * @param size - The maximum batch size - * @param iterable - The iterable to batch - * - * @returns An iterable of batches - * - * @internal - */ -export function* batchIterable( - size: number, - iterable: Iterable, -): Generator { - let array: T[] = []; - for (const value of iterable) { - if (array.push(value) >= size) { - size = (yield array) ?? size; - array = []; - } - } - if (array.length > 0) { - yield array; - } -} -/** - * Wraps and then clamps a number within a given range. - * - * @param num - The number to wrap and then clamp - * @param min - The minimum result value, inclusive - * @param max - The wrap pivot and maximum result value, inclusive - * - * @returns The crwapped number - * - * @internal - */ -export function cwrap(num: number, min: number, max: number): number { - return clamp(nwrap(num, max), min, max); -} /** * Sorts a list in place. * @@ -178,21 +100,3 @@ export function linkedMergeSorted>( } return root.next as Node; } -/** - * Wraps negative numbers around a pivot - * - * f(x, min, pivot) = { - * x, where x >= 0 - * pivot + x, where x < 0 - * } - * - * @param num - The number to wrap - * @param pivot - The number to pivot on - * - * @returns - The wrapped number - * - * @internal - */ -export function nwrap(num: number, pivot: number): number { - return num < 0 ? pivot + num : num; -} diff --git a/src/math/index.ts b/src/math/index.ts index bf7f5d0..90bef3f 100644 --- a/src/math/index.ts +++ b/src/math/index.ts @@ -1,2 +1,2 @@ export * as u32 from './u32'; -export * from './num'; +export * as NumberUtils from './numberUtils'; diff --git a/src/math/num.ts b/src/math/num.ts deleted file mode 100644 index 043dbb9..0000000 --- a/src/math/num.ts +++ /dev/null @@ -1,14 +0,0 @@ -/** - * Limits a number to be within a given range. - * - * f(x, min, max) = y, where min <= y <= max - * - * @param num - The number to clamp - * @param min - The minimum result value, inclusive - * @param max - The maximum result value, inclusive - * - * @returns The clamped number - */ -export function clamp(num: number, min: number, max: number): number { - return Math.min(max, Math.max(min, num)); -} diff --git a/src/math/numberUtils.ts b/src/math/numberUtils.ts new file mode 100644 index 0000000..5bfc50f --- /dev/null +++ b/src/math/numberUtils.ts @@ -0,0 +1,60 @@ +/** + * Limits a number to be within a given range. + * + * f(x, min, max) = y, where min <= y <= max + * + * @param num - The number to clamp + * @param min - The minimum result value, inclusive + * @param max - The maximum result value, inclusive + * + * @returns The clamped number + */ +export function clamp(num: number, min: number, max: number): number { + return Math.min(max, Math.max(min, num)); +} +/** + * Wraps a number if below a given range + * + * f(x, min, max) = { + * x, where x >= min + * max - (min - x), where x < min + * } + * + * @param num - The number to wrap + * @param min - The minimum result value, inclusive + * @param max - The maximum result value, inclusive + * + * @returns - The wrapped number + */ +export function wrapLeft(num: number, min: number, max: number): number { + return num < min ? max - min + num : num; +} +/** + * Wraps a number if above a given range + * + * f(x, min, max) = { + * x, where x <= max + * min + (x - max), where x > max + * } + * + * @param num - The number to wrap + * @param min - The minimum result value, inclusive + * @param max - The maximum result value, inclusive + * + * @returns - The wrapped number + */ +export function wrapRight(num: number, min: number, max: number): number { + return num > max ? min + (num - max) : num; +} +/** + * Wraps a number if outside a given range + * + * @param num - The number to wrap + * @param min - The minimum result value, inclusive + * @param max - The maximum result value, inclusive + * + * @returns - The wrapped number + */ +export function wrap(num: number, min: number, max: number): number { + return num < min ? max - min + num : wrapRight(num, min, max); +} diff --git a/src/math/u32.ts b/src/math/u32.ts index e0949ae..a1ba56a 100644 --- a/src/math/u32.ts +++ b/src/math/u32.ts @@ -77,20 +77,12 @@ export function lsps(a: number): number { * * Example: 54 (110110) -> 4 (000100) * - * 111111 - * 000000 - * 000000 - * - * 000010 - * 111000 - * 001000 - * 000100 - * * @param a - */ + */ /* export function mlsp(a: number): number { - return lsp(a + lsp(a)) >>> 1 || u32(0x80000000 & a); + return (lsp(a + lsp(a)) >>> 1) || u32(0x80000000 & a); } +*/ /** * Get the Most Significant Bit of a 32-bit unsigned number * diff --git a/src/segmentTree/inOrderSegmentTree.ts b/src/segmentTree/inOrderSegmentTree.ts index 0cb62b9..bd21d07 100644 --- a/src/segmentTree/inOrderSegmentTree.ts +++ b/src/segmentTree/inOrderSegmentTree.ts @@ -1,6 +1,6 @@ import { lsb, lsp, msb, msp } from '../math/u32'; import { CombineFn } from '..'; -import { MAX_ARRAY_LENGTH } from 'src/array/utils'; +import { MAX_ARRAY_LENGTH } from 'src/collection/arrayUtils'; import { SegmentTree } from './segmentTree'; /* diff --git a/src/segmentTree/levelOrderSegmentTree.ts b/src/segmentTree/levelOrderSegmentTree.ts index a1bd7b8..1f64083 100644 --- a/src/segmentTree/levelOrderSegmentTree.ts +++ b/src/segmentTree/levelOrderSegmentTree.ts @@ -2,7 +2,7 @@ * Thanks to [Douglas Wilhelm Harder](https://ece.uwaterloo.ca/~dwharder/aads/Algorithms/Array_resizing/) * for their analysis on array resizing */ -import { isArray, MAX_ARRAY_LENGTH } from 'src/array/utils'; +import { isArray, MAX_ARRAY_LENGTH } from 'src/collection/arrayUtils'; import { isCollection } from 'src/collection'; import { Collection } from 'src/collection/collection'; import { CombineFn } from '..'; diff --git a/src/tree/aaTree.ts b/src/tree/aaTree.ts index 072e96d..c60a11f 100644 --- a/src/tree/aaTree.ts +++ b/src/tree/aaTree.ts @@ -15,7 +15,7 @@ import { debug, } from './binaryTreeUtils'; import { SortedTree } from './sortedTree'; -import { isArray } from 'src/array/utils'; +import { isArray } from 'src/collection/arrayUtils'; import { LinkedNode } from 'src/list'; /** diff --git a/src/tree/avlTree.ts b/src/tree/avlTree.ts index 69068ae..e5d3143 100644 --- a/src/tree/avlTree.ts +++ b/src/tree/avlTree.ts @@ -14,7 +14,7 @@ import { removeStack, } from './binaryTreeUtils'; import { SortedTree } from './sortedTree'; -import { isArray } from 'src/array/utils'; +import { isArray } from 'src/collection/arrayUtils'; import { LinkedNode } from 'src/list'; /** diff --git a/src/tree/binaryTreeUtils.ts b/src/tree/binaryTreeUtils.ts index 353f420..0c4d5be 100644 --- a/src/tree/binaryTreeUtils.ts +++ b/src/tree/binaryTreeUtils.ts @@ -428,6 +428,8 @@ export function successorStack>( return leftmostStack(stack); } /** + * Turn an array into a binary tree. Assumes elements are in level-order. + * * @internal */ export function toBinaryTree( diff --git a/test/collection/index.ts b/test/collection/index.ts new file mode 100644 index 0000000..c18bc1c --- /dev/null +++ b/test/collection/index.ts @@ -0,0 +1,30 @@ +import { expect } from 'chai'; +import { isCollection } from 'src/collection/index'; + +describe('collection unit tests', function () { + describe('#isCollection()', function () { + it('Should return false for undefined', function () { + expect(isCollection(undefined)).to.equal(false); + }); + it('Should return false for null', function () { + expect(isCollection(null)).to.equal(false); + }); + it('Should return false if no `size` property', function () { + expect(isCollection({})).to.equal(false); + expect(isCollection([])).to.equal(false); + }); + it('Should return false if size property is not correct type', function () { + expect(isCollection({ size: 'd' })).to.equal(false); + expect(isCollection({ size: {} })).to.equal(false); + expect(isCollection({ size: false })).to.equal(false); + }); + it('Should return false if not an iterable', function () { + expect(isCollection(true)).to.equal(false); + expect(isCollection(12)).to.equal(false); + expect(isCollection({ size: 12 })).to.equal(false); + }); + it('Should return true if a Collection', function () { + expect(isCollection({ size: 0, [Symbol.iterator]: () => undefined })).to.equal(true); + }); + }); +}); diff --git a/test/collection/iteratorUtils.ts b/test/collection/iteratorUtils.ts new file mode 100644 index 0000000..c2dc957 --- /dev/null +++ b/test/collection/iteratorUtils.ts @@ -0,0 +1,183 @@ +import { expect } from 'chai'; +import { always, fill, first, join, never, once, skip, split } from 'src/collection/iteratorUtils'; + +describe('IteratorUtils unit tests', function () { + describe('#always()', function () { + it('Should return an infinite iterable', function () { + let i = 0; + const fn = () => ++i; + const it = always(fn); + while (i < 100) { + const res = it.next(); + expect(res.done).to.equal(false); + expect(res.value).to.equal(i); + } + }); + }); + describe('#fill()', function () { + it('Should call a function a given amount of times', function () { + const n = 10; + let i = 0; + const fn = () => ++i; + for (const v of { [Symbol.iterator]: () => fill(n, fn) }) { + expect(v).to.equal(i); + } + expect(i).to.equal(n); + }); + }); + describe('#first()', function () { + it('Should walk through a given amount of elements in an iterable', function () { + let i = 0; + const n = 100; + const jump = 5; + const fn = () => ++i; + const it = always(fn); + while (i < n) { + const j = i; + for (const v of { [Symbol.iterator]: () => first(jump, it) }) { + expect(v).to.equal(i); + } + expect(i).to.equal(j + jump); + } + expect(i).to.equal(n); + }); + it('Should walk through an iterable until the end', function () { + let i = 0; + const n = 100; + const jump = 17; + const fn = () => ++i; + const it = fill(n, fn); + while (i + jump <= n) { + const j = i; + for (const v of { [Symbol.iterator]: () => first(jump, it) }) { + expect(v).to.equal(i); + } + expect(i).to.equal(j + jump); + } + if (i < n) { + for (const v of { [Symbol.iterator]: () => first(jump, it) }) { + expect(v).to.equal(i); + } + } + expect(i).to.equal(n); + }); + }); + describe('#join()', function () { + it('Should join multiple iterators together', function () { + let i = 0; + const n = 100; + const fn = () => ++i; + const iterators = [fill(20, fn), fill(55, fn), fill(25, fn)]; + const iterator = join(iterators[Symbol.iterator]()); + for (const v of { [Symbol.iterator]: () => iterator }) { + expect(v).to.equal(i); + } + expect(i).to.equal(n); + const res = iterator.next(); + expect(res.done).to.equal(true); + expect(res.value).to.equal(undefined); + }); + }); + describe('#never()', function () { + it('Should return an empty iterable', function () { + const res = never().next(); + expect(res.done).to.equal(true); + expect(res.value).to.equal(undefined); + }); + }); + describe('#once()', function () { + it('Should return an iterable of size 1', function () { + let i = 0; + const fn = () => ++i; + for (const v of { [Symbol.iterator]: () => once(fn) }) { + expect(v).to.equal(i); + } + expect(i).to.equal(1); + }); + }); + describe('#skip()', function () { + it('Should skip a fixed amount', function () { + let i = 0; + const n = 100; + const jump = 5; + const fn = () => ++i; + const it = always(fn); + while (i < n) { + const j = i; + const res = skip(jump, it).next(); + expect(res.done).to.equal(false); + expect(res.value).to.equal(i); + expect(i).to.equal(j + jump); + } + expect(i).to.equal(n); + }); + it('Should skip until the end of the iterable', function () { + let i = 0; + const n = 100; + const jump = 17; + const fn = () => ++i; + const it = fill(n, fn); + while (i + jump <= n) { + const j = i; + const res = skip(jump, it).next(); + expect(res.done).to.equal(false); + expect(res.value).to.equal(i); + expect(i).to.equal(j + jump); + } + if (i < n) { + const res = skip(jump, it).next(); + expect(res.done).to.equal(true); + expect(res.value).to.equal(undefined); + } + expect(i).to.equal(n); + }); + }); + describe('#split()', function () { + it('Should return an empty iterator if amount < 0', function () { + const iterators = split( + -12, + fill(10, () => 1), + ); + const res = never().next(); + expect(res.done).to.equal(true); + expect(res.value).to.equal(undefined); + }); + it('Should return an empty iterator if amount = 0', function () { + const iterators = split( + 0, + fill(10, () => 1), + ); + const res = never().next(); + expect(res.done).to.equal(true); + expect(res.value).to.equal(undefined); + }); + it('Should split an iterator to a given amount', function () { + let i = 0; + const n = 100; + const jump = 17; + const fn = () => ++i; + const iterators = split(jump, fill(n, fn)); + while (i + jump <= n) { + const j = i; + const res = iterators.next(); + expect(res.done).to.equal(false); + expect(res.value).to.not.equal(null); + for (const v of { [Symbol.iterator]: () => res.value }) { + expect(v).to.equal(i); + } + expect(i).to.equal(j + jump); + } + if (i < n) { + const res = iterators.next(); + expect(res.done).to.equal(false); + expect(res.value).to.not.equal(null); + for (const v of { [Symbol.iterator]: () => res.value }) { + expect(v).to.equal(i); + } + } + expect(iterators.next().done).to.equal(true); + expect(iterators.next().done).to.equal(true); + expect(i).to.equal(n); + }); + }); +}); diff --git a/test/list/arrayList.ts b/test/list/arrayList.ts index 4b5df94..dcbf68c 100644 --- a/test/list/arrayList.ts +++ b/test/list/arrayList.ts @@ -2,8 +2,11 @@ import { expect } from 'chai'; import { randomFill, randomInt } from 'crypto'; import { CompareFn } from 'src'; import { ArrayList } from 'src/list/arrayList'; -import { cwrap } from 'src/list/utils'; -import { clamp } from 'src/math'; +import { clamp, wrapLeft } from 'src/math/numberUtils'; + +export function cwrap(num: number, min: number, max: number): number { + return clamp(wrapLeft(num, 0, max), min, max); +} describe('ArrayList unit tests', function () { let empty: ArrayList; diff --git a/test/list/doublyLinkedList.ts b/test/list/doublyLinkedList.ts index dfa0d5a..3c96310 100644 --- a/test/list/doublyLinkedList.ts +++ b/test/list/doublyLinkedList.ts @@ -2,8 +2,11 @@ import { expect } from 'chai'; import { randomFill, randomInt } from 'crypto'; import { CompareFn } from 'src'; import { DoublyLinkedList } from 'src/list/doublyLinkedList'; -import { cwrap } from 'src/list/utils'; -import { clamp } from 'src/math'; +import { clamp, wrapLeft } from 'src/math/numberUtils'; + +export function cwrap(num: number, min: number, max: number): number { + return clamp(wrapLeft(num, 0, max), min, max); +} describe('DoublyLinkedList unit tests', function () { let empty: DoublyLinkedList; diff --git a/test/list/linkedList.ts b/test/list/linkedList.ts index b59f732..e5bd008 100644 --- a/test/list/linkedList.ts +++ b/test/list/linkedList.ts @@ -2,8 +2,11 @@ import { expect } from 'chai'; import { randomFill, randomInt } from 'crypto'; import { CompareFn } from 'src'; import { LinkedList } from 'src/list/linkedList'; -import { cwrap } from 'src/list/utils'; -import { clamp } from 'src/math'; +import { clamp, wrapLeft } from 'src/math/numberUtils'; + +export function cwrap(num: number, min: number, max: number): number { + return clamp(wrapLeft(num, 0, max), min, max); +} describe('LinkedList unit tests', function () { let empty: LinkedList; diff --git a/test/math/num.ts b/test/math/num.ts deleted file mode 100644 index f4c40e7..0000000 --- a/test/math/num.ts +++ /dev/null @@ -1,27 +0,0 @@ -import { expect } from 'chai'; -import { clamp } from 'src/math/num'; - -describe('math/num unit tests', function () { - describe('#clamp()', function () { - it('Should return the given number if within [min, max]', function () { - expect(clamp(-5, -10, 0)).to.equal(-5); - expect(clamp(5, 0, 10)).to.equal(5); - }); - it('Should return min if before [min, max]', function () { - expect(clamp(-15, -10, 0)).to.equal(-10); - expect(clamp(-5, 0, 10)).to.equal(0); - }); - it('Should return min if equal to min', function () { - expect(clamp(-10, -10, 0)).to.equal(-10); - expect(clamp(0, 0, 10)).to.equal(0); - }); - it('Should return max if equal to max', function () { - expect(clamp(0, -10, 0)).to.equal(0); - expect(clamp(10, 0, 10)).to.equal(10); - }); - it('Should return max if after [min, max]', function () { - expect(clamp(5, -10, 0)).to.equal(0); - expect(clamp(15, 0, 10)).to.equal(10); - }); - }); -}); diff --git a/test/math/numberUtils.ts b/test/math/numberUtils.ts new file mode 100644 index 0000000..eb27598 --- /dev/null +++ b/test/math/numberUtils.ts @@ -0,0 +1,93 @@ +import { expect } from 'chai'; +import { clamp, wrap, wrapLeft, wrapRight } from 'src/math/numberUtils'; + +describe('numberUtils unit tests', function () { + describe('#clamp()', function () { + it('Should return min if < min', function () { + expect(clamp(-150, -10, 0)).to.equal(-10); + expect(clamp(-500, 0, 10)).to.equal(0); + }); + it('Should return the given number if = min', function () { + expect(clamp(-10, -10, 0)).to.equal(-10); + expect(clamp(0, 0, 10)).to.equal(0); + }); + it('Should return the given number if within [min, max]', function () { + expect(clamp(-5, -10, 0)).to.equal(-5); + expect(clamp(5, 0, 10)).to.equal(5); + }); + it('Should return the given number if = max', function () { + expect(clamp(0, -10, 0)).to.equal(0); + expect(clamp(10, 0, 10)).to.equal(10); + }); + it('Should return max if > max', function () { + expect(clamp(500, -10, 0)).to.equal(0); + expect(clamp(150, 0, 10)).to.equal(10); + }); + }); + describe('#wrap()', function () { + it('Should wrap around max if < min', function () { + expect(wrap(-150, -10, 10)).to.equal(-130); + expect(wrap(-500, 0, 10)).to.equal(-490); + }); + it('Should return the given number if = min', function () { + expect(wrap(-10, -10, 0)).to.equal(-10); + expect(wrap(0, 0, 10)).to.equal(0); + }); + it('Should return the given number if within [min, max]', function () { + expect(wrap(-5, -10, 0)).to.equal(-5); + expect(wrap(5, 0, 10)).to.equal(5); + }); + it('Should return the given number if = max', function () { + expect(wrap(0, -10, 0)).to.equal(0); + expect(wrap(10, 0, 10)).to.equal(10); + }); + it('Should wrap around min if > max', function () { + expect(wrap(500, -10, 0)).to.equal(490); + expect(wrap(150, -5, 10)).to.equal(135); + }); + }); + describe('#wrapLeft()', function () { + it('Should wrap around max if < min', function () { + expect(wrapLeft(9, 10, 20)).to.equal(19); + expect(wrapLeft(-500, 10, 20)).to.equal(-490); + }); + it('Should return the given number if = min', function () { + expect(wrapLeft(-10, -10, 0)).to.equal(-10); + expect(wrapLeft(0, 0, 10)).to.equal(0); + }); + it('Should return the given number if within [min, max]', function () { + expect(wrapLeft(-5, -10, 0)).to.equal(-5); + expect(wrapLeft(5, 0, 10)).to.equal(5); + }); + it('Should return the given number if = max', function () { + expect(wrapLeft(0, -10, 0)).to.equal(0); + expect(wrapLeft(10, 0, 10)).to.equal(10); + }); + it('Should return the given number if > max', function () { + expect(wrapLeft(150, -10, 0)).to.equal(150); + expect(wrapLeft(500, 0, 10)).to.equal(500); + }); + }); + describe('#wrapRight()', function () { + it('Should return the given number if < min', function () { + expect(wrapRight(-150, -10, 0)).to.equal(-150); + expect(wrapRight(-500, 0, 10)).to.equal(-500); + }); + it('Should return the given number if = min', function () { + expect(wrapRight(-10, -10, 0)).to.equal(-10); + expect(wrapRight(0, 0, 10)).to.equal(0); + }); + it('Should return the given number if within [min, max]', function () { + expect(wrapRight(-5, -10, 0)).to.equal(-5); + expect(wrapRight(5, 0, 10)).to.equal(5); + }); + it('Should return the given number if = max', function () { + expect(wrapRight(0, -10, 0)).to.equal(0); + expect(wrapRight(10, 0, 10)).to.equal(10); + }); + it('Should wrap around min if > max', function () { + expect(wrapRight(500, -20, -10)).to.equal(490); + expect(wrapRight(150, 10, 20)).to.equal(140); + }); + }); +}); diff --git a/test/math/u32.ts b/test/math/u32.ts index ec4119c..0583fb7 100644 --- a/test/math/u32.ts +++ b/test/math/u32.ts @@ -1,7 +1,20 @@ import { expect } from 'chai'; -import { invert, lsb, lsp, lsps, msb, msp, msps, bitsSet, reverse, u32 } from 'src/math/u32'; +import { + invert, + lsb, + lsp, + lsps, + msb, + msp, + msps, + bitsSet, + reverse, + u32, + isPow2, +} from 'src/math/u32'; -describe('math/bits unit tests', function () { +describe('u32 unit tests', function () { + const p32 = 4294967296; const neg = [-1, -2, -3, -4, -5, -6, -7, -8, -9, -10, -11, -12, -13, -14, -15, -16]; const pos = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16]; describe('#bitsSet()', function () { @@ -38,6 +51,21 @@ describe('math/bits unit tests', function () { } }); }); + describe('#isPow2()', function () { + it('Should work for all powers of 2', function () { + for (let i = 1; i <= p32; i *= 2) { + expect(isPow2(i)).to.equal(true); + } + }); + it('Should work for zero', function () { + expect(isPow2(0)).to.equal(true); + }); + it('Should work for non powers of 2', function () { + for (let i = 3; i < 36; ++i) { + expect(isPow2(i)).to.equal(Math.log2(i) % 1 === 0); + } + }); + }); describe('#lsb()', function () { const nVals = [0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0, 4]; const pVals = [0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0, 4]; @@ -73,7 +101,6 @@ describe('math/bits unit tests', function () { }); }); describe('#lsps()', function () { - const p32 = 4294967296; const nVals = [ p32 - 1, p32 - 2, @@ -143,7 +170,6 @@ describe('math/bits unit tests', function () { }); }); describe('#msps()', function () { - const p32 = 4294967296; const nVals = [1, 2, 4, 4, 8, 8, 8, 8, 16, 16, 16, 16, 16, 16, 16, 16].map((v) => p32 - v); const pVals = [1, 2, 3, 4, 4, 6, 7, 8, 8, 8, 8, 12, 12, 14, 15, 16]; it('Should work for "negative" values', function () { @@ -190,7 +216,6 @@ describe('math/bits unit tests', function () { }); }); describe('#u32()', function () { - const p32 = 2 ** 32; const nVals = [ p32 - 1, p32 - 2,