queue-typed 2.2.4 → 2.2.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/index.cjs +0 -34
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs-legacy/index.cjs +0 -34
- package/dist/cjs-legacy/index.cjs.map +1 -1
- package/dist/esm/index.mjs +0 -34
- package/dist/esm/index.mjs.map +1 -1
- package/dist/esm-legacy/index.mjs +0 -34
- package/dist/esm-legacy/index.mjs.map +1 -1
- package/dist/types/data-structures/base/iterable-entry-base.d.ts +6 -0
- package/dist/types/data-structures/binary-tree/binary-tree.d.ts +14 -57
- package/dist/types/data-structures/binary-tree/bst.d.ts +110 -96
- package/dist/umd/queue-typed.js +0 -31
- package/dist/umd/queue-typed.js.map +1 -1
- package/dist/umd/queue-typed.min.js +1 -1
- package/dist/umd/queue-typed.min.js.map +1 -1
- package/package.json +2 -2
- package/src/common/index.ts +2 -4
- package/src/data-structures/base/iterable-entry-base.ts +9 -0
- package/src/data-structures/binary-tree/avl-tree-multi-map.ts +3 -1
- package/src/data-structures/binary-tree/binary-tree.ts +67 -0
- package/src/data-structures/binary-tree/bst.ts +658 -71
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";var queueTyped=(()=>{var _=Object.defineProperty;var C=Object.getOwnPropertyDescriptor;var O=Object.getOwnPropertyNames;var F=Object.prototype.hasOwnProperty;var z=(o,s,e)=>s in o?_(o,s,{enumerable:!0,configurable:!0,writable:!0,value:e}):o[s]=e;var A=(o,s)=>{for(var e in s)_(o,e,{get:s[e],enumerable:!0})},T=(o,s,e,t)=>{if(s&&typeof s=="object"||typeof s=="function")for(let n of O(s))!F.call(o,n)&&n!==e&&_(o,n,{get:()=>s[n],enumerable:!(t=C(s,n))||t.enumerable});return o};var U=o=>T(_({},"__esModule",{value:!0}),o);var u=(o,s,e)=>z(o,typeof s!="symbol"?s+"":s,e);var q={};A(q,{DFSOperation:()=>M,Deque:()=>S,LinkedListQueue:()=>R,Queue:()=>x,Range:()=>N});var m=class{constructor(s){u(this,"_toElementFn");if(s){let{toElementFn:e}=s;if(typeof e=="function")this._toElementFn=e;else if(e)throw new TypeError("toElementFn must be a function type")}}get toElementFn(){return this._toElementFn}*[Symbol.iterator](...s){yield*this._getIterator(...s)}*values(){for(let s of this)yield s}every(s,e){let t=0;for(let n of this)if(e===void 0){if(!s(n,t++,this))return!1}else if(!s.call(e,n,t++,this))return!1;return!0}some(s,e){let t=0;for(let n of this)if(e===void 0){if(s(n,t++,this))return!0}else if(s.call(e,n,t++,this))return!0;return!1}forEach(s,e){let t=0;for(let n of this)e===void 0?s(n,t++,this):s.call(e,n,t++,this)}find(s,e){let t=0;for(let n of this)if(e===void 0){if(s(n,t++,this))return n}else if(s.call(e,n,t++,this))return n}has(s){for(let e of this)if(e===s)return!0;return!1}reduce(s,e){let t=0,n=this[Symbol.iterator](),i;if(arguments.length>=2)i=e;else{let r=n.next();if(r.done)throw new TypeError("Reduce of empty structure with no initial value");i=r.value,t=1}for(let r of n)i=s(i,r,t++,this);return i}toArray(){return[...this]}toVisual(){return[...this]}print(){console.log(this.toVisual())}};var k=class{constructor(s){u(this,"_value");u(this,"_next");this._value=s,this._next=void 0}get value(){return this._value}set value(s){this._value=s}get next(){return this._next}set next(s){this._next=s}},d=class o extends m{constructor(e){super(e);u(this,"_maxLen",-1);if(e){let{maxLen:t}=e;typeof t=="number"&&t>0&&t%1===0&&(this._maxLen=t)}}get maxLen(){return this._maxLen}indexOf(e,t=0){if(this.length===0)return-1;t<0&&(t=this.length+t),t<0&&(t=0);for(let n=t;n<this.length;n++)if(this.at(n)===e)return n;return-1}lastIndexOf(e,t=this.length-1){if(this.length===0)return-1;t>=this.length&&(t=this.length-1),t<0&&(t=this.length+t);for(let n=t;n>=0;n--)if(this.at(n)===e)return n;return-1}findIndex(e,t){for(let n=0;n<this.length;n++){let i=this.at(n);if(i!==void 0&&e.call(t,i,n,this))return n}return-1}concat(...e){let t=this.clone();for(let n of e)n instanceof o?t.pushMany(n):t.push(n);return t}sort(e){let t=this.toArray();t.sort(e),this.clear();for(let n of t)this.push(n);return this}splice(e,t=0,...n){let i=this._createInstance();e=e<0?this.length+e:e,e=Math.max(0,Math.min(e,this.length)),t=Math.max(0,Math.min(t,this.length-e));for(let r=0;r<t;r++){let h=this.deleteAt(e);h!==void 0&&i.push(h)}for(let r=0;r<n.length;r++)this.addAt(e+r,n[r]);return i}join(e=","){return this.toArray().join(e)}toReversedArray(){let e=[];for(let t=this.length-1;t>=0;t--)e.push(this.at(t));return e}reduceRight(e,t){let n=t!=null?t:0;for(let i=this.length-1;i>=0;i--)n=e(n,this.at(i),i,this);return n}slice(e=0,t=this.length){e=e<0?this.length+e:e,t=t<0?this.length+t:t;let n=this._createInstance();for(let i=e;i<t;i++)n.push(this.at(i));return n}fill(e,t=0,n=this.length){if(t=t<0?this.length+t:t,n=n<0?this.length+n:n,t<0&&(t=0),n>this.length&&(n=this.length),t>=n)return this;for(let i=t;i<n;i++)this.setAt(i,e);return this}},g=class extends d{constructor(s){if(super(s),s){let{maxLen:e}=s;typeof e=="number"&&e>0&&e%1===0&&(this._maxLen=e)}}indexOf(s,e=0){let t=this._getIterator(),n=t.next(),i=0;for(;i<e;)n=t.next(),i++;for(;!n.done;){if(n.value===s)return i;n=t.next(),i++}return-1}lastIndexOf(s,e=this.length-1){let t=this._getReverseIterator(),n=t.next(),i=this.length-1;for(;i>e;)n=t.next(),i--;for(;!n.done;){if(n.value===s)return i;n=t.next(),i--}return-1}concat(...s){let e=this.clone();for(let t of s)t instanceof d?e.pushMany(t):e.push(t);return e}slice(s=0,e=this.length){s=s<0?this.length+s:s,e=e<0?this.length+e:e;let t=this._createInstance(),n=this._getIterator(),i=n.next(),r=0;for(;r<s;)i=n.next(),r++;for(let h=s;h<e;h++)t.push(i.value),i=n.next();return t}splice(s,e=0,...t){let n=this._createInstance();s=s<0?this.length+s:s,s=Math.max(0,Math.min(s,this.length)),e=Math.max(0,e);let i=0,r,h,l=this._getNodeIterator();for(let a of l){if(i===s){r=a;break}h=a,i++}for(let a=0;a<e&&r;a++){n.push(r.value);let c=r.next;this.delete(r),r=c}for(let a=0;a<t.length;a++)h?(this.addAfter(h,t[a]),h=h.next):(this.addAt(0,t[a]),h=this._getNodeIterator().next().value);return n}reduceRight(s,e){let t=e!=null?e:0,n=this.length-1;for(let i of this._getReverseIterator())t=s(t,i,n--,this);return t}};var b=class extends k{constructor(e){super(e);u(this,"_next");this._value=e,this._next=void 0}get next(){return this._next}set next(e){this._next=e}},p=class extends g{constructor(e=[],t){super(t);u(this,"_equals",Object.is);u(this,"_head");u(this,"_tail");u(this,"_length",0);this.pushMany(e)}get head(){return this._head}get tail(){return this._tail}get length(){return this._length}get first(){var e;return(e=this.head)==null?void 0:e.value}get last(){var e;return(e=this.tail)==null?void 0:e.value}static from(e,t){let n=new this([],t);for(let i of e)n.push(i);return n}push(e){let t=this._ensureNode(e);return this.head?(this.tail.next=t,this._tail=t):this._head=this._tail=t,this._length++,this._maxLen>0&&this.length>this._maxLen&&this.shift(),!0}pop(){if(!this.head)return;if(this.head===this.tail){let n=this.head.value;return this._head=void 0,this._tail=void 0,this._length--,n}let e=this.head;for(;e.next!==this.tail;)e=e.next;let t=this.tail.value;return e.next=void 0,this._tail=e,this._length--,t}shift(){if(!this.head)return;let e=this.head;return this._head=this.head.next,this._head||(this._tail=void 0),this._length--,e.value}unshift(e){let t=this._ensureNode(e);return this.head?(t.next=this.head,this._head=t):this._head=this._tail=t,this._length++,!0}pushMany(e){let t=[];for(let n of e)this.toElementFn?t.push(this.push(this.toElementFn(n))):t.push(this.push(n));return t}unshiftMany(e){let t=[];for(let n of e)this.toElementFn?t.push(this.unshift(this.toElementFn(n))):t.push(this.unshift(n));return t}search(e){let t=this._ensurePredicate(e),n=this.head;for(;n;){if(t(n))return n.value;n=n.next}}at(e){if(e<0||e>=this._length)return;let t=this.head;for(let n=0;n<e;n++)t=t.next;return t.value}isNode(e){return e instanceof b}getNodeAt(e){if(e<0||e>=this._length)return;let t=this.head;for(let n=0;n<e;n++)t=t.next;return t}deleteAt(e){if(e<0||e>=this._length)return;if(e===0)return this.shift();let t=this.getNodeAt(e),n=this._getPrevNode(t),i=t.value;return n.next=t.next,t===this.tail&&(this._tail=n),this._length--,i}delete(e){if(e===void 0||!this.head)return!1;let t=this.isNode(e)?e:this.getNode(e);if(!t)return!1;let n=this._getPrevNode(t);return n?(n.next=t.next,t===this.tail&&(this._tail=n)):(this._head=t.next,t===this.tail&&(this._tail=void 0)),this._length--,!0}addAt(e,t){if(e<0||e>this._length)return!1;if(e===0)return this.unshift(t);if(e===this._length)return this.push(t);let n=this._ensureNode(t),i=this.getNodeAt(e-1);return n.next=i.next,i.next=n,this._length++,!0}setAt(e,t){let n=this.getNodeAt(e);return n?(n.value=t,!0):!1}isEmpty(){return this._length===0}clear(){this._head=void 0,this._tail=void 0,this._length=0}reverse(){if(!this.head||this.head===this.tail)return this;let e,t=this.head,n;for(;t;)n=t.next,t.next=e,e=t,t=n;return[this._head,this._tail]=[this.tail,this.head],this}getNode(e){if(e===void 0)return;if(this.isNode(e))return e;let t=this._ensurePredicate(e),n=this.head;for(;n;){if(t(n))return n;n=n.next}}addBefore(e,t){let n=this.getNode(e);if(!n)return!1;let i=this._getPrevNode(n),r=this._ensureNode(t);return i?(i.next=r,r.next=n,this._length++):(r.next=this._head,this._head=r,this._tail||(this._tail=r),this._length++),!0}addAfter(e,t){let n=this.getNode(e);if(!n)return!1;let i=this._ensureNode(t);return i.next=n.next,n.next=i,n===this.tail&&(this._tail=i),this._length++,!0}splice(e,t=0,...n){e=Math.max(0,Math.min(e,this.length)),t=Math.max(0,t);let i=this._createInstance(),r=e===0?void 0:this.getNodeAt(e-1),h=r?r.next:this.head,l=0;for(;l<t&&h;)i.push(h.value),h=h.next,l++;let a=h;if(r?r.next=a:this._head=a,a||(this._tail=r),n.length>0){let c,f;for(let B of n){let L=this._ensureNode(B);c||(c=L),f&&(f.next=L),f=L}r?r.next=c:this._head=c,f.next=a,a||(this._tail=f)}return this._length+=n.length-l,this._length===0&&(this._head=void 0,this._tail=void 0),i}countOccurrences(e){let t=D(e,this._equals),n=0,i=this.head;for(;i;)t(i)&&n++,i=i.next;return n}setEquality(e){return this._equals=e,this}deleteWhere(e){let t,n=this.head,i=0;for(;n;){if(e(n.value,i++,this))return t?(t.next=n.next,n===this._tail&&(this._tail=t)):(this._head=n.next,n===this._tail&&(this._tail=void 0)),this._length--,!0;t=n,n=n.next}return!1}clone(){let e=this._createInstance();for(let t of this)e.push(t);return e}filter(e,t){let n=this._createInstance(),i=0;for(let r of this)e.call(t,r,i++,this)&&n.push(r);return n}mapSame(e,t){let n=this._createInstance(),i=0;for(let r of this){let h=t===void 0?e(r,i++,this):e.call(t,r,i++,this);n.push(h)}return n}map(e,t,n){let i=this._createLike([],{...t!=null?t:{},maxLen:this._maxLen}),r=0;for(let h of this)i.push(e.call(n,h,r++,this));return i}createNode(e){return new b(e)}_isPredicate(e){return typeof e=="function"}_ensureNode(e){return this.isNode(e)?e:this.createNode(e)}_ensurePredicate(e){if(this.isNode(e))return n=>n===e;if(this._isPredicate(e))return e;let t=e;return n=>this._equals(n.value,t)}_getPrevNode(e){if(!this.head||this.head===e)return;let t=this.head;for(;t.next&&t.next!==e;)t=t.next;return t.next===e?t:void 0}*_getIterator(){let e=this.head;for(;e;)yield e.value,e=e.next}*_getReverseIterator(){let e=[...this].reverse();for(let t of e)yield t}*_getNodeIterator(){let e=this.head;for(;e;)yield e,e=e.next}_createInstance(e){let t=this.constructor;return new t([],e)}_createLike(e=[],t){let n=this.constructor;return new n(e,t)}_spawnLike(e){return this._createLike([],e)}};function D(o,s){if(o instanceof b)return t=>t===o;if(typeof o=="function")return o;let e=o;return t=>s(t.value,e)}var x=class o extends d{constructor(e=[],t){super(t);u(this,"_elements",[]);u(this,"_offset",0);u(this,"_autoCompactRatio",.5);if(t){let{autoCompactRatio:n=.5}=t;this._autoCompactRatio=n}this.pushMany(e)}get elements(){return this._elements}get offset(){return this._offset}get autoCompactRatio(){return this._autoCompactRatio}set autoCompactRatio(e){this._autoCompactRatio=e}get length(){return this.elements.length-this._offset}get first(){return this.length>0?this.elements[this._offset]:void 0}get last(){return this.length>0?this.elements[this.elements.length-1]:void 0}static fromArray(e){return new o(e)}isEmpty(){return this.length===0}push(e){return this.elements.push(e),this._maxLen>0&&this.length>this._maxLen&&this.shift(),!0}pushMany(e){let t=[];for(let n of e)this.toElementFn?t.push(this.push(this.toElementFn(n))):t.push(this.push(n));return t}shift(){if(this.length===0)return;let e=this.first;return this._offset+=1,this.elements.length>0&&this.offset/this.elements.length>this.autoCompactRatio&&this.compact(),e}delete(e){for(let t=this._offset;t<this.elements.length;t++)if(Object.is(this.elements[t],e))return this.elements.splice(t,1),!0;return!1}at(e){if(!(e<0||e>=this.length))return this._elements[this._offset+e]}deleteAt(e){if(e<0||e>=this.length)return;let t=this._offset+e,[n]=this.elements.splice(t,1);return n}addAt(e,t){return e<0||e>this.length?!1:(this._elements.splice(this._offset+e,0,t),!0)}setAt(e,t){return e<0||e>=this.length?!1:(this._elements[this._offset+e]=t,!0)}reverse(){return this._elements=this.elements.slice(this._offset).reverse(),this._offset=0,this}clear(){this._elements=[],this._offset=0}compact(){return this._elements=this.elements.slice(this._offset),this._offset=0,!0}splice(e,t=0,...n){e=Math.max(0,Math.min(e,this.length)),t=Math.max(0,Math.min(t,this.length-e));let i=this._offset+e,r=this._elements.splice(i,t,...n);this.elements.length>0&&this.offset/this.elements.length>this.autoCompactRatio&&this.compact();let h=this._createInstance({toElementFn:this.toElementFn,maxLen:this._maxLen});return h._setAutoCompactRatio(this._autoCompactRatio),h.pushMany(r),h}clone(){let e=this._createInstance({toElementFn:this.toElementFn,maxLen:this._maxLen});e._setAutoCompactRatio(this._autoCompactRatio);for(let t=this._offset;t<this.elements.length;t++)e.push(this.elements[t]);return e}filter(e,t){let n=this._createInstance({toElementFn:this.toElementFn,maxLen:this._maxLen});n._setAutoCompactRatio(this._autoCompactRatio);let i=0;for(let r of this)e.call(t,r,i,this)&&n.push(r),i++;return n}map(e,t,n){var h,l;let i=new this.constructor([],{toElementFn:t==null?void 0:t.toElementFn,maxLen:(h=t==null?void 0:t.maxLen)!=null?h:this._maxLen,autoCompactRatio:(l=t==null?void 0:t.autoCompactRatio)!=null?l:this._autoCompactRatio}),r=0;for(let a of this)i.push(n===void 0?e(a,r++,this):e.call(n,a,r++,this));return i}mapSame(e,t){var h;let n=this.constructor,i=new n([],{toElementFn:this.toElementFn,maxLen:this._maxLen,autoCompactRatio:this._autoCompactRatio});(h=i._setAutoCompactRatio)==null||h.call(i,this._autoCompactRatio);let r=0;for(let l of this){let a=t===void 0?e(l,r++,this):e.call(t,l,r++,this);i.push(a)}return i}_setAutoCompactRatio(e){this._autoCompactRatio=e}*_getIterator(){for(let e=this._offset;e<this.elements.length;e++)yield this.elements[e]}*_getReverseIterator(){for(let e=this.length-1;e>=0;e--){let t=this.at(e);t!==void 0&&(yield t)}}_createInstance(e){let t=this.constructor;return new t([],e)}_createLike(e=[],t){let n=this.constructor;return new n(e,t)}},R=class extends p{clone(){let s=this._createInstance({toElementFn:this.toElementFn,maxLen:this._maxLen});for(let e of this)s.push(e);return s}};var E=(o,s,e,t="Index out of bounds.")=>{if(o<s||o>e)throw new RangeError(t)};var I=(o,s)=>Math.floor((o+s-1)/s);function y(o){let s=typeof o;return s==="number"?!0:s==="bigint"||s==="string"||s==="boolean"}function w(o){if(typeof o.valueOf=="function"){let s=o.valueOf();if(s!==o){if(y(s))return s;if(typeof s=="object"&&s!==null)return w(s)}}if(typeof o.toString=="function"){let s=o.toString();if(s!=="[object Object]")return s}return null}function v(o,s=!1){if(o==null)return!1;if(y(o))return!0;if(typeof o!="object")return!1;if(o instanceof Date||s)return!0;let e=w(o);return e==null?!1:y(e)}var S=class extends d{constructor(e=[],t){super(t);u(this,"_equals",Object.is);u(this,"_bucketSize",4096);u(this,"_bucketFirst",0);u(this,"_firstInBucket",0);u(this,"_bucketLast",0);u(this,"_lastInBucket",0);u(this,"_bucketCount",0);u(this,"_buckets",[]);u(this,"_length",0);if(t){let{bucketSize:r}=t;typeof r=="number"&&(this._bucketSize=r)}let n;"length"in e?n=typeof e.length=="function"?e.length():e.length:n=typeof e.size=="function"?e.size():e.size,this._bucketCount=I(n,this._bucketSize)||1;for(let r=0;r<this._bucketCount;++r)this._buckets.push(new Array(this._bucketSize));let i=I(n,this._bucketSize);this._bucketFirst=this._bucketLast=(this._bucketCount>>1)-(i>>1),this._firstInBucket=this._lastInBucket=this._bucketSize-n%this._bucketSize>>1,this.pushMany(e)}get bucketSize(){return this._bucketSize}get bucketFirst(){return this._bucketFirst}get firstInBucket(){return this._firstInBucket}get bucketLast(){return this._bucketLast}get lastInBucket(){return this._lastInBucket}get bucketCount(){return this._bucketCount}get buckets(){return this._buckets}get length(){return this._length}get first(){if(this._length!==0)return this._buckets[this._bucketFirst][this._firstInBucket]}get last(){if(this._length!==0)return this._buckets[this._bucketLast][this._lastInBucket]}static fromArray(e,t){return new this(e,t)}push(e){return this._length&&(this._lastInBucket<this._bucketSize-1?this._lastInBucket+=1:this._bucketLast<this._bucketCount-1?(this._bucketLast+=1,this._lastInBucket=0):(this._bucketLast=0,this._lastInBucket=0),this._bucketLast===this._bucketFirst&&this._lastInBucket===this._firstInBucket&&this._reallocate()),this._length+=1,this._buckets[this._bucketLast][this._lastInBucket]=e,this._maxLen>0&&this._length>this._maxLen&&this.shift(),!0}pop(){if(this._length===0)return;let e=this._buckets[this._bucketLast][this._lastInBucket];return this._length!==1&&(this._lastInBucket>0?this._lastInBucket-=1:this._bucketLast>0?(this._bucketLast-=1,this._lastInBucket=this._bucketSize-1):(this._bucketLast=this._bucketCount-1,this._lastInBucket=this._bucketSize-1)),this._length-=1,e}shift(){if(this._length===0)return;let e=this._buckets[this._bucketFirst][this._firstInBucket];return this._length!==1&&(this._firstInBucket<this._bucketSize-1?this._firstInBucket+=1:this._bucketFirst<this._bucketCount-1?(this._bucketFirst+=1,this._firstInBucket=0):(this._bucketFirst=0,this._firstInBucket=0)),this._length-=1,e}unshift(e){return this._length&&(this._firstInBucket>0?this._firstInBucket-=1:this._bucketFirst>0?(this._bucketFirst-=1,this._firstInBucket=this._bucketSize-1):(this._bucketFirst=this._bucketCount-1,this._firstInBucket=this._bucketSize-1),this._bucketFirst===this._bucketLast&&this._firstInBucket===this._lastInBucket&&this._reallocate()),this._length+=1,this._buckets[this._bucketFirst][this._firstInBucket]=e,this._maxLen>0&&this._length>this._maxLen&&this.pop(),!0}pushMany(e){let t=[];for(let n of e)this.toElementFn?t.push(this.push(this.toElementFn(n))):t.push(this.push(n));return t}unshiftMany(e=[]){let t=[];for(let n of e)this.toElementFn?t.push(this.unshift(this.toElementFn(n))):t.push(this.unshift(n));return t}isEmpty(){return this._length===0}clear(){this._buckets=[new Array(this._bucketSize)],this._bucketCount=1,this._bucketFirst=this._bucketLast=this._length=0,this._firstInBucket=this._lastInBucket=this._bucketSize>>1}at(e){if(e<0||e>=this._length)return;let{bucketIndex:t,indexInBucket:n}=this._getBucketAndPosition(e);return this._buckets[t][n]}setAt(e,t){E(e,0,this._length-1);let{bucketIndex:n,indexInBucket:i}=this._getBucketAndPosition(e);return this._buckets[n][i]=t,!0}addAt(e,t,n=1){let i=this._length;if(E(e,0,i),e===0)for(;n--;)this.unshift(t);else if(e===this._length)for(;n--;)this.push(t);else{let r=[];for(let h=e;h<this._length;++h){let l=this.at(h);l!==void 0&&r.push(l)}this.cut(e-1,!0);for(let h=0;h<n;++h)this.push(t);for(let h=0;h<r.length;++h)this.push(r[h])}return!0}cut(e,t=!1){if(t){if(e<0)return this.clear(),this;let{bucketIndex:n,indexInBucket:i}=this._getBucketAndPosition(e);return this._bucketLast=n,this._lastInBucket=i,this._length=e+1,this}else{let n=this._createInstance({toElementFn:this._toElementFn,maxLen:this._maxLen});n._setBucketSize(this._bucketSize);for(let i=0;i<=e;i++){let r=this.at(i);r!==void 0&&n.push(r)}return n}}splice(e,t=this._length-e,...n){E(e,0,this._length),t<0&&(t=0),e+t>this._length&&(t=this._length-e);let i=this._createInstance({toElementFn:this._toElementFn,maxLen:this._maxLen});i._setBucketSize(this._bucketSize);for(let h=0;h<t;h++){let l=this.at(e+h);l!==void 0&&i.push(l)}let r=[];for(let h=e+t;h<this._length;h++){let l=this.at(h);l!==void 0&&r.push(l)}this.cut(e-1,!0);for(let h of n)this.push(h);for(let h of r)this.push(h);return i}cutRest(e,t=!1){if(t){if(e<0)return this;let{bucketIndex:n,indexInBucket:i}=this._getBucketAndPosition(e);return this._bucketFirst=n,this._firstInBucket=i,this._length=this._length-e,this}else{let n=this._createInstance({toElementFn:this._toElementFn,maxLen:this._maxLen});n._setBucketSize(this._bucketSize),e<0&&(e=0);for(let i=e;i<this._length;i++){let r=this.at(i);r!==void 0&&n.push(r)}return n}}deleteAt(e){E(e,0,this._length-1);let t;if(e===0)return this.shift();if(e===this._length-1)return t=this.last,this.pop(),t;{let n=this._length-1,{bucketIndex:i,indexInBucket:r}=this._getBucketAndPosition(e);t=this._buckets[i][r];for(let h=e;h<n;h++){let{bucketIndex:l,indexInBucket:a}=this._getBucketAndPosition(h),{bucketIndex:c,indexInBucket:f}=this._getBucketAndPosition(h+1);this._buckets[l][a]=this._buckets[c][f]}return this.pop(),t}}delete(e){let t=this._length;if(t===0)return!1;let n=0,i=0;for(;n<t;){let r=this.at(n);this._equals(r,e)||(this.setAt(i,r),i+=1),n+=1}return this.cut(i-1,!0),!0}deleteWhere(e){for(let t=0;t<this._length;t++){let n=this.at(t);if(e(n,t,this))return this.deleteAt(t),!0}return!1}setEquality(e){return this._equals=e,this}reverse(){this._buckets.reverse().forEach(function(r){r.reverse()});let{_bucketFirst:e,_bucketLast:t,_firstInBucket:n,_lastInBucket:i}=this;return this._bucketFirst=this._bucketCount-t-1,this._bucketLast=this._bucketCount-e-1,this._firstInBucket=this._bucketSize-i-1,this._lastInBucket=this._bucketSize-n-1,this}unique(){if(this._length<=1)return this;let e=1,t=this.at(0);for(let n=1;n<this._length;++n){let i=this.at(n);this._equals(i,t)||(t=i,this.setAt(e++,i))}return this.cut(e-1,!0),this}shrinkToFit(){if(this._length===0)return;let e=[];if(this._bucketFirst!==this._bucketLast){if(this._bucketFirst<this._bucketLast)for(let t=this._bucketFirst;t<=this._bucketLast;++t)e.push(this._buckets[t]);else{for(let t=this._bucketFirst;t<this._bucketCount;++t)e.push(this._buckets[t]);for(let t=0;t<=this._bucketLast;++t)e.push(this._buckets[t])}this._bucketFirst=0,this._bucketLast=e.length-1,this._buckets=e}}clone(){return this._createLike(this,{bucketSize:this.bucketSize,toElementFn:this.toElementFn,maxLen:this._maxLen})}filter(e,t){let n=this._createInstance({toElementFn:this.toElementFn,maxLen:this._maxLen});n._setBucketSize(this._bucketSize);let i=0;for(let r of this)e.call(t,r,i,this)&&n.push(r),i++;return n}mapSame(e,t){let n=this._createInstance({toElementFn:this._toElementFn,maxLen:this._maxLen});n._setBucketSize(this._bucketSize);let i=0;for(let r of this){let h=t===void 0?e(r,i++,this):e.call(t,r,i++,this);n.push(h)}return n}map(e,t,n){let i=this._createLike([],{...t!=null?t:{},bucketSize:this._bucketSize,maxLen:this._maxLen}),r=0;for(let h of this){let l=n===void 0?e(h,r,this):e.call(n,h,r,this);i.push(l),r++}return i}_setBucketSize(e){this._bucketSize=e}*_getIterator(){for(let e=0;e<this._length;++e){let t=this.at(e);t!==void 0&&(yield t)}}_reallocate(e){let t=[],n=e||this._bucketCount>>1||1;for(let i=0;i<n;++i)t[i]=new Array(this._bucketSize);for(let i=this._bucketFirst;i<this._bucketCount;++i)t[t.length]=this._buckets[i];for(let i=0;i<this._bucketLast;++i)t[t.length]=this._buckets[i];t[t.length]=[...this._buckets[this._bucketLast]],this._bucketFirst=n,this._bucketLast=t.length-1;for(let i=0;i<n;++i)t[t.length]=new Array(this._bucketSize);this._buckets=t,this._bucketCount=t.length}_getBucketAndPosition(e){let t,n,i=this._firstInBucket+e;return t=this._bucketFirst+Math.floor(i/this._bucketSize),t>=this._bucketCount&&(t-=this._bucketCount),n=(i+1)%this._bucketSize-1,n<0&&(n=this._bucketSize-1),{bucketIndex:t,indexInBucket:n}}_createInstance(e){let t=this.constructor;return new t([],e)}_createLike(e=[],t){let n=this.constructor;return new n(e,t)}*_getReverseIterator(){for(let e=this._length-1;e>-1;e--){let t=this.at(e);t!==void 0&&(yield t)}}};var M=(e=>(e[e.VISIT=0]="VISIT",e[e.PROCESS=1]="PROCESS",e))(M||{}),N=class{constructor(s,e,t=!0,n=!0){this.low=s;this.high=e;this.includeLow=t;this.includeHigh=n;if(!(v(s)&&v(e)))throw new RangeError("low or high is not comparable");if(s>e)throw new RangeError("low must be less than or equal to high")}isInRange(s,e){let t=this.includeLow?e(s,this.low)>=0:e(s,this.low)>0,n=this.includeHigh?e(s,this.high)<=0:e(s,this.high)<0;return t&&n}};return U(q);})();
|
|
1
|
+
"use strict";var queueTyped=(()=>{var _=Object.defineProperty;var w=Object.getOwnPropertyDescriptor;var M=Object.getOwnPropertyNames;var B=Object.prototype.hasOwnProperty;var C=(o,s,e)=>s in o?_(o,s,{enumerable:!0,configurable:!0,writable:!0,value:e}):o[s]=e;var O=(o,s)=>{for(var e in s)_(o,e,{get:s[e],enumerable:!0})},F=(o,s,e,t)=>{if(s&&typeof s=="object"||typeof s=="function")for(let n of M(s))!B.call(o,n)&&n!==e&&_(o,n,{get:()=>s[n],enumerable:!(t=w(s,n))||t.enumerable});return o};var z=o=>F(_({},"__esModule",{value:!0}),o);var u=(o,s,e)=>C(o,typeof s!="symbol"?s+"":s,e);var T={};O(T,{DFSOperation:()=>S,Deque:()=>I,LinkedListQueue:()=>R,Queue:()=>x,Range:()=>v});var m=class{constructor(s){u(this,"_toElementFn");if(s){let{toElementFn:e}=s;if(typeof e=="function")this._toElementFn=e;else if(e)throw new TypeError("toElementFn must be a function type")}}get toElementFn(){return this._toElementFn}*[Symbol.iterator](...s){yield*this._getIterator(...s)}*values(){for(let s of this)yield s}every(s,e){let t=0;for(let n of this)if(e===void 0){if(!s(n,t++,this))return!1}else if(!s.call(e,n,t++,this))return!1;return!0}some(s,e){let t=0;for(let n of this)if(e===void 0){if(s(n,t++,this))return!0}else if(s.call(e,n,t++,this))return!0;return!1}forEach(s,e){let t=0;for(let n of this)e===void 0?s(n,t++,this):s.call(e,n,t++,this)}find(s,e){let t=0;for(let n of this)if(e===void 0){if(s(n,t++,this))return n}else if(s.call(e,n,t++,this))return n}has(s){for(let e of this)if(e===s)return!0;return!1}reduce(s,e){let t=0,n=this[Symbol.iterator](),i;if(arguments.length>=2)i=e;else{let r=n.next();if(r.done)throw new TypeError("Reduce of empty structure with no initial value");i=r.value,t=1}for(let r of n)i=s(i,r,t++,this);return i}toArray(){return[...this]}toVisual(){return[...this]}print(){console.log(this.toVisual())}};var k=class{constructor(s){u(this,"_value");u(this,"_next");this._value=s,this._next=void 0}get value(){return this._value}set value(s){this._value=s}get next(){return this._next}set next(s){this._next=s}},d=class o extends m{constructor(e){super(e);u(this,"_maxLen",-1);if(e){let{maxLen:t}=e;typeof t=="number"&&t>0&&t%1===0&&(this._maxLen=t)}}get maxLen(){return this._maxLen}indexOf(e,t=0){if(this.length===0)return-1;t<0&&(t=this.length+t),t<0&&(t=0);for(let n=t;n<this.length;n++)if(this.at(n)===e)return n;return-1}lastIndexOf(e,t=this.length-1){if(this.length===0)return-1;t>=this.length&&(t=this.length-1),t<0&&(t=this.length+t);for(let n=t;n>=0;n--)if(this.at(n)===e)return n;return-1}findIndex(e,t){for(let n=0;n<this.length;n++){let i=this.at(n);if(i!==void 0&&e.call(t,i,n,this))return n}return-1}concat(...e){let t=this.clone();for(let n of e)n instanceof o?t.pushMany(n):t.push(n);return t}sort(e){let t=this.toArray();t.sort(e),this.clear();for(let n of t)this.push(n);return this}splice(e,t=0,...n){let i=this._createInstance();e=e<0?this.length+e:e,e=Math.max(0,Math.min(e,this.length)),t=Math.max(0,Math.min(t,this.length-e));for(let r=0;r<t;r++){let h=this.deleteAt(e);h!==void 0&&i.push(h)}for(let r=0;r<n.length;r++)this.addAt(e+r,n[r]);return i}join(e=","){return this.toArray().join(e)}toReversedArray(){let e=[];for(let t=this.length-1;t>=0;t--)e.push(this.at(t));return e}reduceRight(e,t){let n=t!=null?t:0;for(let i=this.length-1;i>=0;i--)n=e(n,this.at(i),i,this);return n}slice(e=0,t=this.length){e=e<0?this.length+e:e,t=t<0?this.length+t:t;let n=this._createInstance();for(let i=e;i<t;i++)n.push(this.at(i));return n}fill(e,t=0,n=this.length){if(t=t<0?this.length+t:t,n=n<0?this.length+n:n,t<0&&(t=0),n>this.length&&(n=this.length),t>=n)return this;for(let i=t;i<n;i++)this.setAt(i,e);return this}},g=class extends d{constructor(s){if(super(s),s){let{maxLen:e}=s;typeof e=="number"&&e>0&&e%1===0&&(this._maxLen=e)}}indexOf(s,e=0){let t=this._getIterator(),n=t.next(),i=0;for(;i<e;)n=t.next(),i++;for(;!n.done;){if(n.value===s)return i;n=t.next(),i++}return-1}lastIndexOf(s,e=this.length-1){let t=this._getReverseIterator(),n=t.next(),i=this.length-1;for(;i>e;)n=t.next(),i--;for(;!n.done;){if(n.value===s)return i;n=t.next(),i--}return-1}concat(...s){let e=this.clone();for(let t of s)t instanceof d?e.pushMany(t):e.push(t);return e}slice(s=0,e=this.length){s=s<0?this.length+s:s,e=e<0?this.length+e:e;let t=this._createInstance(),n=this._getIterator(),i=n.next(),r=0;for(;r<s;)i=n.next(),r++;for(let h=s;h<e;h++)t.push(i.value),i=n.next();return t}splice(s,e=0,...t){let n=this._createInstance();s=s<0?this.length+s:s,s=Math.max(0,Math.min(s,this.length)),e=Math.max(0,e);let i=0,r,h,l=this._getNodeIterator();for(let a of l){if(i===s){r=a;break}h=a,i++}for(let a=0;a<e&&r;a++){n.push(r.value);let c=r.next;this.delete(r),r=c}for(let a=0;a<t.length;a++)h?(this.addAfter(h,t[a]),h=h.next):(this.addAt(0,t[a]),h=this._getNodeIterator().next().value);return n}reduceRight(s,e){let t=e!=null?e:0,n=this.length-1;for(let i of this._getReverseIterator())t=s(t,i,n--,this);return t}};var b=class extends k{constructor(e){super(e);u(this,"_next");this._value=e,this._next=void 0}get next(){return this._next}set next(e){this._next=e}},p=class extends g{constructor(e=[],t){super(t);u(this,"_equals",Object.is);u(this,"_head");u(this,"_tail");u(this,"_length",0);this.pushMany(e)}get head(){return this._head}get tail(){return this._tail}get length(){return this._length}get first(){var e;return(e=this.head)==null?void 0:e.value}get last(){var e;return(e=this.tail)==null?void 0:e.value}static from(e,t){let n=new this([],t);for(let i of e)n.push(i);return n}push(e){let t=this._ensureNode(e);return this.head?(this.tail.next=t,this._tail=t):this._head=this._tail=t,this._length++,this._maxLen>0&&this.length>this._maxLen&&this.shift(),!0}pop(){if(!this.head)return;if(this.head===this.tail){let n=this.head.value;return this._head=void 0,this._tail=void 0,this._length--,n}let e=this.head;for(;e.next!==this.tail;)e=e.next;let t=this.tail.value;return e.next=void 0,this._tail=e,this._length--,t}shift(){if(!this.head)return;let e=this.head;return this._head=this.head.next,this._head||(this._tail=void 0),this._length--,e.value}unshift(e){let t=this._ensureNode(e);return this.head?(t.next=this.head,this._head=t):this._head=this._tail=t,this._length++,!0}pushMany(e){let t=[];for(let n of e)this.toElementFn?t.push(this.push(this.toElementFn(n))):t.push(this.push(n));return t}unshiftMany(e){let t=[];for(let n of e)this.toElementFn?t.push(this.unshift(this.toElementFn(n))):t.push(this.unshift(n));return t}search(e){let t=this._ensurePredicate(e),n=this.head;for(;n;){if(t(n))return n.value;n=n.next}}at(e){if(e<0||e>=this._length)return;let t=this.head;for(let n=0;n<e;n++)t=t.next;return t.value}isNode(e){return e instanceof b}getNodeAt(e){if(e<0||e>=this._length)return;let t=this.head;for(let n=0;n<e;n++)t=t.next;return t}deleteAt(e){if(e<0||e>=this._length)return;if(e===0)return this.shift();let t=this.getNodeAt(e),n=this._getPrevNode(t),i=t.value;return n.next=t.next,t===this.tail&&(this._tail=n),this._length--,i}delete(e){if(e===void 0||!this.head)return!1;let t=this.isNode(e)?e:this.getNode(e);if(!t)return!1;let n=this._getPrevNode(t);return n?(n.next=t.next,t===this.tail&&(this._tail=n)):(this._head=t.next,t===this.tail&&(this._tail=void 0)),this._length--,!0}addAt(e,t){if(e<0||e>this._length)return!1;if(e===0)return this.unshift(t);if(e===this._length)return this.push(t);let n=this._ensureNode(t),i=this.getNodeAt(e-1);return n.next=i.next,i.next=n,this._length++,!0}setAt(e,t){let n=this.getNodeAt(e);return n?(n.value=t,!0):!1}isEmpty(){return this._length===0}clear(){this._head=void 0,this._tail=void 0,this._length=0}reverse(){if(!this.head||this.head===this.tail)return this;let e,t=this.head,n;for(;t;)n=t.next,t.next=e,e=t,t=n;return[this._head,this._tail]=[this.tail,this.head],this}getNode(e){if(e===void 0)return;if(this.isNode(e))return e;let t=this._ensurePredicate(e),n=this.head;for(;n;){if(t(n))return n;n=n.next}}addBefore(e,t){let n=this.getNode(e);if(!n)return!1;let i=this._getPrevNode(n),r=this._ensureNode(t);return i?(i.next=r,r.next=n,this._length++):(r.next=this._head,this._head=r,this._tail||(this._tail=r),this._length++),!0}addAfter(e,t){let n=this.getNode(e);if(!n)return!1;let i=this._ensureNode(t);return i.next=n.next,n.next=i,n===this.tail&&(this._tail=i),this._length++,!0}splice(e,t=0,...n){e=Math.max(0,Math.min(e,this.length)),t=Math.max(0,t);let i=this._createInstance(),r=e===0?void 0:this.getNodeAt(e-1),h=r?r.next:this.head,l=0;for(;l<t&&h;)i.push(h.value),h=h.next,l++;let a=h;if(r?r.next=a:this._head=a,a||(this._tail=r),n.length>0){let c,f;for(let N of n){let L=this._ensureNode(N);c||(c=L),f&&(f.next=L),f=L}r?r.next=c:this._head=c,f.next=a,a||(this._tail=f)}return this._length+=n.length-l,this._length===0&&(this._head=void 0,this._tail=void 0),i}countOccurrences(e){let t=A(e,this._equals),n=0,i=this.head;for(;i;)t(i)&&n++,i=i.next;return n}setEquality(e){return this._equals=e,this}deleteWhere(e){let t,n=this.head,i=0;for(;n;){if(e(n.value,i++,this))return t?(t.next=n.next,n===this._tail&&(this._tail=t)):(this._head=n.next,n===this._tail&&(this._tail=void 0)),this._length--,!0;t=n,n=n.next}return!1}clone(){let e=this._createInstance();for(let t of this)e.push(t);return e}filter(e,t){let n=this._createInstance(),i=0;for(let r of this)e.call(t,r,i++,this)&&n.push(r);return n}mapSame(e,t){let n=this._createInstance(),i=0;for(let r of this){let h=t===void 0?e(r,i++,this):e.call(t,r,i++,this);n.push(h)}return n}map(e,t,n){let i=this._createLike([],{...t!=null?t:{},maxLen:this._maxLen}),r=0;for(let h of this)i.push(e.call(n,h,r++,this));return i}createNode(e){return new b(e)}_isPredicate(e){return typeof e=="function"}_ensureNode(e){return this.isNode(e)?e:this.createNode(e)}_ensurePredicate(e){if(this.isNode(e))return n=>n===e;if(this._isPredicate(e))return e;let t=e;return n=>this._equals(n.value,t)}_getPrevNode(e){if(!this.head||this.head===e)return;let t=this.head;for(;t.next&&t.next!==e;)t=t.next;return t.next===e?t:void 0}*_getIterator(){let e=this.head;for(;e;)yield e.value,e=e.next}*_getReverseIterator(){let e=[...this].reverse();for(let t of e)yield t}*_getNodeIterator(){let e=this.head;for(;e;)yield e,e=e.next}_createInstance(e){let t=this.constructor;return new t([],e)}_createLike(e=[],t){let n=this.constructor;return new n(e,t)}_spawnLike(e){return this._createLike([],e)}};function A(o,s){if(o instanceof b)return t=>t===o;if(typeof o=="function")return o;let e=o;return t=>s(t.value,e)}var x=class o extends d{constructor(e=[],t){super(t);u(this,"_elements",[]);u(this,"_offset",0);u(this,"_autoCompactRatio",.5);if(t){let{autoCompactRatio:n=.5}=t;this._autoCompactRatio=n}this.pushMany(e)}get elements(){return this._elements}get offset(){return this._offset}get autoCompactRatio(){return this._autoCompactRatio}set autoCompactRatio(e){this._autoCompactRatio=e}get length(){return this.elements.length-this._offset}get first(){return this.length>0?this.elements[this._offset]:void 0}get last(){return this.length>0?this.elements[this.elements.length-1]:void 0}static fromArray(e){return new o(e)}isEmpty(){return this.length===0}push(e){return this.elements.push(e),this._maxLen>0&&this.length>this._maxLen&&this.shift(),!0}pushMany(e){let t=[];for(let n of e)this.toElementFn?t.push(this.push(this.toElementFn(n))):t.push(this.push(n));return t}shift(){if(this.length===0)return;let e=this.first;return this._offset+=1,this.elements.length>0&&this.offset/this.elements.length>this.autoCompactRatio&&this.compact(),e}delete(e){for(let t=this._offset;t<this.elements.length;t++)if(Object.is(this.elements[t],e))return this.elements.splice(t,1),!0;return!1}at(e){if(!(e<0||e>=this.length))return this._elements[this._offset+e]}deleteAt(e){if(e<0||e>=this.length)return;let t=this._offset+e,[n]=this.elements.splice(t,1);return n}addAt(e,t){return e<0||e>this.length?!1:(this._elements.splice(this._offset+e,0,t),!0)}setAt(e,t){return e<0||e>=this.length?!1:(this._elements[this._offset+e]=t,!0)}reverse(){return this._elements=this.elements.slice(this._offset).reverse(),this._offset=0,this}clear(){this._elements=[],this._offset=0}compact(){return this._elements=this.elements.slice(this._offset),this._offset=0,!0}splice(e,t=0,...n){e=Math.max(0,Math.min(e,this.length)),t=Math.max(0,Math.min(t,this.length-e));let i=this._offset+e,r=this._elements.splice(i,t,...n);this.elements.length>0&&this.offset/this.elements.length>this.autoCompactRatio&&this.compact();let h=this._createInstance({toElementFn:this.toElementFn,maxLen:this._maxLen});return h._setAutoCompactRatio(this._autoCompactRatio),h.pushMany(r),h}clone(){let e=this._createInstance({toElementFn:this.toElementFn,maxLen:this._maxLen});e._setAutoCompactRatio(this._autoCompactRatio);for(let t=this._offset;t<this.elements.length;t++)e.push(this.elements[t]);return e}filter(e,t){let n=this._createInstance({toElementFn:this.toElementFn,maxLen:this._maxLen});n._setAutoCompactRatio(this._autoCompactRatio);let i=0;for(let r of this)e.call(t,r,i,this)&&n.push(r),i++;return n}map(e,t,n){var h,l;let i=new this.constructor([],{toElementFn:t==null?void 0:t.toElementFn,maxLen:(h=t==null?void 0:t.maxLen)!=null?h:this._maxLen,autoCompactRatio:(l=t==null?void 0:t.autoCompactRatio)!=null?l:this._autoCompactRatio}),r=0;for(let a of this)i.push(n===void 0?e(a,r++,this):e.call(n,a,r++,this));return i}mapSame(e,t){var h;let n=this.constructor,i=new n([],{toElementFn:this.toElementFn,maxLen:this._maxLen,autoCompactRatio:this._autoCompactRatio});(h=i._setAutoCompactRatio)==null||h.call(i,this._autoCompactRatio);let r=0;for(let l of this){let a=t===void 0?e(l,r++,this):e.call(t,l,r++,this);i.push(a)}return i}_setAutoCompactRatio(e){this._autoCompactRatio=e}*_getIterator(){for(let e=this._offset;e<this.elements.length;e++)yield this.elements[e]}*_getReverseIterator(){for(let e=this.length-1;e>=0;e--){let t=this.at(e);t!==void 0&&(yield t)}}_createInstance(e){let t=this.constructor;return new t([],e)}_createLike(e=[],t){let n=this.constructor;return new n(e,t)}},R=class extends p{clone(){let s=this._createInstance({toElementFn:this.toElementFn,maxLen:this._maxLen});for(let e of this)s.push(e);return s}};var E=(o,s,e,t="Index out of bounds.")=>{if(o<s||o>e)throw new RangeError(t)};var y=(o,s)=>Math.floor((o+s-1)/s);var I=class extends d{constructor(e=[],t){super(t);u(this,"_equals",Object.is);u(this,"_bucketSize",4096);u(this,"_bucketFirst",0);u(this,"_firstInBucket",0);u(this,"_bucketLast",0);u(this,"_lastInBucket",0);u(this,"_bucketCount",0);u(this,"_buckets",[]);u(this,"_length",0);if(t){let{bucketSize:r}=t;typeof r=="number"&&(this._bucketSize=r)}let n;"length"in e?n=typeof e.length=="function"?e.length():e.length:n=typeof e.size=="function"?e.size():e.size,this._bucketCount=y(n,this._bucketSize)||1;for(let r=0;r<this._bucketCount;++r)this._buckets.push(new Array(this._bucketSize));let i=y(n,this._bucketSize);this._bucketFirst=this._bucketLast=(this._bucketCount>>1)-(i>>1),this._firstInBucket=this._lastInBucket=this._bucketSize-n%this._bucketSize>>1,this.pushMany(e)}get bucketSize(){return this._bucketSize}get bucketFirst(){return this._bucketFirst}get firstInBucket(){return this._firstInBucket}get bucketLast(){return this._bucketLast}get lastInBucket(){return this._lastInBucket}get bucketCount(){return this._bucketCount}get buckets(){return this._buckets}get length(){return this._length}get first(){if(this._length!==0)return this._buckets[this._bucketFirst][this._firstInBucket]}get last(){if(this._length!==0)return this._buckets[this._bucketLast][this._lastInBucket]}static fromArray(e,t){return new this(e,t)}push(e){return this._length&&(this._lastInBucket<this._bucketSize-1?this._lastInBucket+=1:this._bucketLast<this._bucketCount-1?(this._bucketLast+=1,this._lastInBucket=0):(this._bucketLast=0,this._lastInBucket=0),this._bucketLast===this._bucketFirst&&this._lastInBucket===this._firstInBucket&&this._reallocate()),this._length+=1,this._buckets[this._bucketLast][this._lastInBucket]=e,this._maxLen>0&&this._length>this._maxLen&&this.shift(),!0}pop(){if(this._length===0)return;let e=this._buckets[this._bucketLast][this._lastInBucket];return this._length!==1&&(this._lastInBucket>0?this._lastInBucket-=1:this._bucketLast>0?(this._bucketLast-=1,this._lastInBucket=this._bucketSize-1):(this._bucketLast=this._bucketCount-1,this._lastInBucket=this._bucketSize-1)),this._length-=1,e}shift(){if(this._length===0)return;let e=this._buckets[this._bucketFirst][this._firstInBucket];return this._length!==1&&(this._firstInBucket<this._bucketSize-1?this._firstInBucket+=1:this._bucketFirst<this._bucketCount-1?(this._bucketFirst+=1,this._firstInBucket=0):(this._bucketFirst=0,this._firstInBucket=0)),this._length-=1,e}unshift(e){return this._length&&(this._firstInBucket>0?this._firstInBucket-=1:this._bucketFirst>0?(this._bucketFirst-=1,this._firstInBucket=this._bucketSize-1):(this._bucketFirst=this._bucketCount-1,this._firstInBucket=this._bucketSize-1),this._bucketFirst===this._bucketLast&&this._firstInBucket===this._lastInBucket&&this._reallocate()),this._length+=1,this._buckets[this._bucketFirst][this._firstInBucket]=e,this._maxLen>0&&this._length>this._maxLen&&this.pop(),!0}pushMany(e){let t=[];for(let n of e)this.toElementFn?t.push(this.push(this.toElementFn(n))):t.push(this.push(n));return t}unshiftMany(e=[]){let t=[];for(let n of e)this.toElementFn?t.push(this.unshift(this.toElementFn(n))):t.push(this.unshift(n));return t}isEmpty(){return this._length===0}clear(){this._buckets=[new Array(this._bucketSize)],this._bucketCount=1,this._bucketFirst=this._bucketLast=this._length=0,this._firstInBucket=this._lastInBucket=this._bucketSize>>1}at(e){if(e<0||e>=this._length)return;let{bucketIndex:t,indexInBucket:n}=this._getBucketAndPosition(e);return this._buckets[t][n]}setAt(e,t){E(e,0,this._length-1);let{bucketIndex:n,indexInBucket:i}=this._getBucketAndPosition(e);return this._buckets[n][i]=t,!0}addAt(e,t,n=1){let i=this._length;if(E(e,0,i),e===0)for(;n--;)this.unshift(t);else if(e===this._length)for(;n--;)this.push(t);else{let r=[];for(let h=e;h<this._length;++h){let l=this.at(h);l!==void 0&&r.push(l)}this.cut(e-1,!0);for(let h=0;h<n;++h)this.push(t);for(let h=0;h<r.length;++h)this.push(r[h])}return!0}cut(e,t=!1){if(t){if(e<0)return this.clear(),this;let{bucketIndex:n,indexInBucket:i}=this._getBucketAndPosition(e);return this._bucketLast=n,this._lastInBucket=i,this._length=e+1,this}else{let n=this._createInstance({toElementFn:this._toElementFn,maxLen:this._maxLen});n._setBucketSize(this._bucketSize);for(let i=0;i<=e;i++){let r=this.at(i);r!==void 0&&n.push(r)}return n}}splice(e,t=this._length-e,...n){E(e,0,this._length),t<0&&(t=0),e+t>this._length&&(t=this._length-e);let i=this._createInstance({toElementFn:this._toElementFn,maxLen:this._maxLen});i._setBucketSize(this._bucketSize);for(let h=0;h<t;h++){let l=this.at(e+h);l!==void 0&&i.push(l)}let r=[];for(let h=e+t;h<this._length;h++){let l=this.at(h);l!==void 0&&r.push(l)}this.cut(e-1,!0);for(let h of n)this.push(h);for(let h of r)this.push(h);return i}cutRest(e,t=!1){if(t){if(e<0)return this;let{bucketIndex:n,indexInBucket:i}=this._getBucketAndPosition(e);return this._bucketFirst=n,this._firstInBucket=i,this._length=this._length-e,this}else{let n=this._createInstance({toElementFn:this._toElementFn,maxLen:this._maxLen});n._setBucketSize(this._bucketSize),e<0&&(e=0);for(let i=e;i<this._length;i++){let r=this.at(i);r!==void 0&&n.push(r)}return n}}deleteAt(e){E(e,0,this._length-1);let t;if(e===0)return this.shift();if(e===this._length-1)return t=this.last,this.pop(),t;{let n=this._length-1,{bucketIndex:i,indexInBucket:r}=this._getBucketAndPosition(e);t=this._buckets[i][r];for(let h=e;h<n;h++){let{bucketIndex:l,indexInBucket:a}=this._getBucketAndPosition(h),{bucketIndex:c,indexInBucket:f}=this._getBucketAndPosition(h+1);this._buckets[l][a]=this._buckets[c][f]}return this.pop(),t}}delete(e){let t=this._length;if(t===0)return!1;let n=0,i=0;for(;n<t;){let r=this.at(n);this._equals(r,e)||(this.setAt(i,r),i+=1),n+=1}return this.cut(i-1,!0),!0}deleteWhere(e){for(let t=0;t<this._length;t++){let n=this.at(t);if(e(n,t,this))return this.deleteAt(t),!0}return!1}setEquality(e){return this._equals=e,this}reverse(){this._buckets.reverse().forEach(function(r){r.reverse()});let{_bucketFirst:e,_bucketLast:t,_firstInBucket:n,_lastInBucket:i}=this;return this._bucketFirst=this._bucketCount-t-1,this._bucketLast=this._bucketCount-e-1,this._firstInBucket=this._bucketSize-i-1,this._lastInBucket=this._bucketSize-n-1,this}unique(){if(this._length<=1)return this;let e=1,t=this.at(0);for(let n=1;n<this._length;++n){let i=this.at(n);this._equals(i,t)||(t=i,this.setAt(e++,i))}return this.cut(e-1,!0),this}shrinkToFit(){if(this._length===0)return;let e=[];if(this._bucketFirst!==this._bucketLast){if(this._bucketFirst<this._bucketLast)for(let t=this._bucketFirst;t<=this._bucketLast;++t)e.push(this._buckets[t]);else{for(let t=this._bucketFirst;t<this._bucketCount;++t)e.push(this._buckets[t]);for(let t=0;t<=this._bucketLast;++t)e.push(this._buckets[t])}this._bucketFirst=0,this._bucketLast=e.length-1,this._buckets=e}}clone(){return this._createLike(this,{bucketSize:this.bucketSize,toElementFn:this.toElementFn,maxLen:this._maxLen})}filter(e,t){let n=this._createInstance({toElementFn:this.toElementFn,maxLen:this._maxLen});n._setBucketSize(this._bucketSize);let i=0;for(let r of this)e.call(t,r,i,this)&&n.push(r),i++;return n}mapSame(e,t){let n=this._createInstance({toElementFn:this._toElementFn,maxLen:this._maxLen});n._setBucketSize(this._bucketSize);let i=0;for(let r of this){let h=t===void 0?e(r,i++,this):e.call(t,r,i++,this);n.push(h)}return n}map(e,t,n){let i=this._createLike([],{...t!=null?t:{},bucketSize:this._bucketSize,maxLen:this._maxLen}),r=0;for(let h of this){let l=n===void 0?e(h,r,this):e.call(n,h,r,this);i.push(l),r++}return i}_setBucketSize(e){this._bucketSize=e}*_getIterator(){for(let e=0;e<this._length;++e){let t=this.at(e);t!==void 0&&(yield t)}}_reallocate(e){let t=[],n=e||this._bucketCount>>1||1;for(let i=0;i<n;++i)t[i]=new Array(this._bucketSize);for(let i=this._bucketFirst;i<this._bucketCount;++i)t[t.length]=this._buckets[i];for(let i=0;i<this._bucketLast;++i)t[t.length]=this._buckets[i];t[t.length]=[...this._buckets[this._bucketLast]],this._bucketFirst=n,this._bucketLast=t.length-1;for(let i=0;i<n;++i)t[t.length]=new Array(this._bucketSize);this._buckets=t,this._bucketCount=t.length}_getBucketAndPosition(e){let t,n,i=this._firstInBucket+e;return t=this._bucketFirst+Math.floor(i/this._bucketSize),t>=this._bucketCount&&(t-=this._bucketCount),n=(i+1)%this._bucketSize-1,n<0&&(n=this._bucketSize-1),{bucketIndex:t,indexInBucket:n}}_createInstance(e){let t=this.constructor;return new t([],e)}_createLike(e=[],t){let n=this.constructor;return new n(e,t)}*_getReverseIterator(){for(let e=this._length-1;e>-1;e--){let t=this.at(e);t!==void 0&&(yield t)}}};var S=(e=>(e[e.VISIT=0]="VISIT",e[e.PROCESS=1]="PROCESS",e))(S||{}),v=class{constructor(s,e,t=!0,n=!0){this.low=s;this.high=e;this.includeLow=t;this.includeHigh=n}isInRange(s,e){let t=this.includeLow?e(s,this.low)>=0:e(s,this.low)>0,n=this.includeHigh?e(s,this.high)<=0:e(s,this.high)<0;return t&&n}};return z(T);})();
|
|
2
2
|
/**
|
|
3
3
|
* data-structure-typed
|
|
4
4
|
*
|