linked-list-typed 2.4.2 → 2.4.4

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.
Files changed (51) hide show
  1. package/dist/cjs/index.cjs +10 -10
  2. package/dist/cjs/index.cjs.map +1 -1
  3. package/dist/cjs-legacy/index.cjs +11 -10
  4. package/dist/cjs-legacy/index.cjs.map +1 -1
  5. package/dist/esm/index.mjs +10 -10
  6. package/dist/esm/index.mjs.map +1 -1
  7. package/dist/esm-legacy/index.mjs +11 -10
  8. package/dist/esm-legacy/index.mjs.map +1 -1
  9. package/dist/types/data-structures/base/iterable-element-base.d.ts +1 -1
  10. package/dist/types/data-structures/binary-tree/binary-tree.d.ts +5 -5
  11. package/dist/types/data-structures/binary-tree/bst.d.ts +1 -1
  12. package/dist/types/data-structures/binary-tree/tree-map.d.ts +10 -0
  13. package/dist/types/data-structures/binary-tree/tree-set.d.ts +10 -0
  14. package/dist/types/data-structures/graph/directed-graph.d.ts +2 -2
  15. package/dist/types/data-structures/graph/undirected-graph.d.ts +2 -2
  16. package/dist/types/data-structures/hash/hash-map.d.ts +2 -2
  17. package/dist/types/data-structures/heap/heap.d.ts +3 -7
  18. package/dist/types/types/data-structures/binary-tree/avl-tree.d.ts +1 -1
  19. package/dist/types/types/data-structures/binary-tree/red-black-tree.d.ts +1 -1
  20. package/dist/types/types/data-structures/linked-list/doubly-linked-list.d.ts +1 -1
  21. package/dist/types/types/data-structures/linked-list/singly-linked-list.d.ts +1 -1
  22. package/dist/types/types/data-structures/priority-queue/priority-queue.d.ts +1 -1
  23. package/dist/types/types/data-structures/stack/stack.d.ts +1 -1
  24. package/dist/umd/linked-list-typed.js +11 -10
  25. package/dist/umd/linked-list-typed.js.map +1 -1
  26. package/dist/umd/linked-list-typed.min.js +1 -1
  27. package/dist/umd/linked-list-typed.min.js.map +1 -1
  28. package/package.json +2 -2
  29. package/src/data-structures/base/iterable-element-base.ts +2 -2
  30. package/src/data-structures/binary-tree/binary-tree.ts +8 -7
  31. package/src/data-structures/binary-tree/bst.ts +1 -1
  32. package/src/data-structures/binary-tree/tree-map.ts +16 -0
  33. package/src/data-structures/binary-tree/tree-multi-set.ts +5 -5
  34. package/src/data-structures/binary-tree/tree-set.ts +16 -0
  35. package/src/data-structures/graph/abstract-graph.ts +18 -18
  36. package/src/data-structures/graph/directed-graph.ts +4 -4
  37. package/src/data-structures/graph/map-graph.ts +1 -1
  38. package/src/data-structures/graph/undirected-graph.ts +4 -4
  39. package/src/data-structures/hash/hash-map.ts +6 -4
  40. package/src/data-structures/heap/heap.ts +17 -14
  41. package/src/data-structures/linked-list/doubly-linked-list.ts +4 -4
  42. package/src/data-structures/linked-list/singly-linked-list.ts +15 -9
  43. package/src/data-structures/queue/deque.ts +1 -1
  44. package/src/data-structures/stack/stack.ts +1 -1
  45. package/src/data-structures/trie/trie.ts +10 -5
  46. package/src/types/data-structures/binary-tree/avl-tree.ts +1 -1
  47. package/src/types/data-structures/binary-tree/red-black-tree.ts +1 -1
  48. package/src/types/data-structures/linked-list/doubly-linked-list.ts +1 -1
  49. package/src/types/data-structures/linked-list/singly-linked-list.ts +1 -1
  50. package/src/types/data-structures/priority-queue/priority-queue.ts +1 -1
  51. package/src/types/data-structures/stack/stack.ts +1 -1
@@ -1,4 +1,4 @@
1
- "use strict";var linkedListTyped=(()=>{var _=Object.defineProperty;var I=Object.getOwnPropertyDescriptor;var S=Object.getOwnPropertyNames;var M=Object.prototype.hasOwnProperty;var D=(o,s,e)=>s in o?_(o,s,{enumerable:!0,configurable:!0,writable:!0,value:e}):o[s]=e;var C=(o,s)=>{for(var e in s)_(o,e,{get:s[e],enumerable:!0})},A=(o,s,e,t)=>{if(s&&typeof s=="object"||typeof s=="function")for(let n of S(s))!M.call(o,n)&&n!==e&&_(o,n,{get:()=>s[n],enumerable:!(t=I(s,n))||t.enumerable});return o};var O=o=>A(_({},"__esModule",{value:!0}),o);var d=(o,s,e)=>D(o,typeof s!="symbol"?s+"":s,e);var K={};C(K,{DFSOperation:()=>w,DoublyLinkedList:()=>m,DoublyLinkedListNode:()=>L,Range:()=>x,SinglyLinkedList:()=>N,SinglyLinkedListNode:()=>E,SkipList:()=>v,SkipListNode:()=>g});var p=class{constructor(s){d(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 f=class{constructor(s){d(this,"_value");d(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}},k=class o extends p{constructor(e){super(e);d(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 l=this.deleteAt(e);l!==void 0&&i.push(l)}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}},c=class extends k{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 k?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 l=s;l<e;l++)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,l,h=this._getNodeIterator();for(let a of h){if(i===s){r=a;break}l=a,i++}for(let a=0;a<e&&r;a++){n.push(r.value);let u=r.next;this.delete(r),r=u}for(let a=0;a<t.length;a++)l?(this.addAfter(l,t[a]),l=l.next):(this.addAt(0,t[a]),l=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 E=class extends f{constructor(e){super(e);d(this,"_next");this._value=e,this._next=void 0}get next(){return this._next}set next(e){this._next=e}},N=class extends c{constructor(e=[],t){super(t);d(this,"_equals",Object.is);d(this,"_head");d(this,"_tail");d(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 E}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),l=r?r.next:this.head,h=0;for(;h<t&&l;)i.push(l.value),l=l.next,h++;let a=l;if(r?r.next=a:this._head=a,a||(this._tail=r),n.length>0){let u,b;for(let R of n){let y=this._ensureNode(R);u||(u=y),b&&(b.next=y),b=y}r?r.next=u:this._head=u,b.next=a,a||(this._tail=b)}return this._length+=n.length-h,this._length===0&&(this._head=void 0,this._tail=void 0),i}countOccurrences(e){let t=U(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 l=t===void 0?e(r,i++,this):e.call(t,r,i++,this);n.push(l)}return n}map(e,t,n){let i=this._createLike([],{...t!=null?t:{},maxLen:this._maxLen}),r=0;for(let l of this)i.push(e.call(n,l,r++,this));return i}createNode(e){return new E(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 U(o,s){if(o instanceof E)return t=>t===o;if(typeof o=="function")return o;let e=o;return t=>s(t.value,e)}var L=class extends f{constructor(e){super(e);d(this,"_next");d(this,"_prev");this._value=e,this._next=void 0,this._prev=void 0}get next(){return this._next}set next(e){this._next=e}get prev(){return this._prev}set prev(e){this._prev=e}},m=class extends c{constructor(e=[],t){super(t);d(this,"_equals",Object.is);d(this,"_head");d(this,"_tail");d(this,"_length",0);this._head=void 0,this._tail=void 0,this._length=0,t!=null&&t.maxLen&&Number.isInteger(t.maxLen)&&t.maxLen>0&&(this._maxLen=t.maxLen),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 fromArray(e){return new this(e)}isNode(e){return e instanceof L}push(e){let t=this._ensureNode(e);return this.head?(t.prev=this.tail,this.tail.next=t,this._tail=t):(this._head=t,this._tail=t),this._length++,this._maxLen>0&&this.length>this._maxLen&&this.shift(),!0}pop(){if(!this.tail)return;let e=this.tail;return this.head===this.tail?(this._head=void 0,this._tail=void 0):(this._tail=e.prev,this.tail.next=void 0),this._length--,e.value}shift(){if(!this.head)return;let e=this.head;return this.head===this.tail?(this._head=void 0,this._tail=void 0):(this._head=e.next,this.head.prev=void 0),this._length--,e.value}unshift(e){let t=this._ensureNode(e);return this.head?(t.next=this.head,this.head.prev=t,this._head=t):(this._head=t,this._tail=t),this._length++,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}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}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}getNode(e){if(e===void 0)return;if(this.isNode(e)){let i=e,r=this.head;for(;r;){if(r===i)return i;r=r.next}let l=h=>this._equals(h.value,i.value);for(r=this.head;r;){if(l(r))return r;r=r.next}return}let t=this._ensurePredicate(e),n=this.head;for(;n;){if(t(n))return n;n=n.next}}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),r=i.next;return n.prev=i,n.next=r,i.next=n,r.prev=n,this._length++,!0}addBefore(e,t){let n=this.isNode(e)?e:this.getNode(e);if(!n)return!1;let i=this._ensureNode(t);return i.prev=n.prev,n.prev&&(n.prev.next=i),i.next=n,n.prev=i,n===this.head&&(this._head=i),this._length++,!0}addAfter(e,t){let n=this.isNode(e)?e:this.getNode(e);if(!n)return!1;let i=this._ensureNode(t);return i.next=n.next,n.next&&(n.next.prev=i),i.prev=n,n.next=i,n===this.tail&&(this._tail=i),this._length++,!0}setAt(e,t){let n=this.getNodeAt(e);return n?(n.value=t,!0):!1}deleteAt(e){if(e<0||e>=this._length)return;if(e===0)return this.shift();if(e===this._length-1)return this.pop();let t=this.getNodeAt(e),n=t.prev,i=t.next;return n.next=i,i.prev=n,this._length--,t.value}delete(e){let t=this.getNode(e);if(!t)return!1;if(t===this.head)this.shift();else if(t===this.tail)this.pop();else{let n=t.prev,i=t.next;n.next=i,i.prev=n,this._length--}return!0}isEmpty(){return this._length===0}clear(){this._head=void 0,this._tail=void 0,this._length=0}search(e){let t=this._ensurePredicate(e),n=this.head;for(;n;){if(t(n))return n.value;n=n.next}}getBackward(e){let t=this._ensurePredicate(e),n=this.tail;for(;n;){if(t(n))return n.value;n=n.prev}}reverse(){let e=this.head;for([this._head,this._tail]=[this.tail,this.head];e;){let t=e.next;[e.prev,e.next]=[e.next,e.prev],e=t}return this}setEquality(e){return this._equals=e,this}clone(){let e=this._createInstance({toElementFn:this._toElementFn,maxLen:this._maxLen});for(let t of this)e.push(t);return e}filter(e,t){let n=this._createInstance({toElementFn:this._toElementFn,maxLen:this._maxLen}),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({toElementFn:this._toElementFn,maxLen:this._maxLen}),i=0;for(let r of this){let l=t===void 0?e(r,i++,this):e.call(t,r,i++,this);n.push(l)}return n}map(e,t,n){let i=this._createLike([],{...t!=null?t:{},maxLen:this._maxLen}),r=0;for(let l of this)i.push(e.call(n,l,r++,this));return i}_ensureNode(e){return this.isNode(e)?e:new L(e)}_ensurePredicate(e){if(this.isNode(e)){let n=e;return i=>i===n}if(typeof e=="function")return e;let t=e;return n=>this._equals(n.value,t)}_getPrevNode(e){return e.prev}_createInstance(e){let t=this.constructor;return new t([],e)}_createLike(e=[],t){let n=this.constructor;return new n(e,t)}*_getIterator(){let e=this.head;for(;e;)yield e.value,e=e.next}*_getReverseIterator(){let e=this.tail;for(;e;)yield e.value,e=e.prev}*_getNodeIterator(){let e=this.head;for(;e;)yield e,e=e.next}};var g=class{constructor(s,e,t){d(this,"key");d(this,"value");d(this,"forward");this.key=s,this.value=e,this.forward=new Array(t)}},v=class{constructor(s=[],e){d(this,"_head",new g(void 0,void 0,this.maxLevel));d(this,"_level",0);d(this,"_maxLevel",16);d(this,"_probability",.5);if(e){let{maxLevel:t,probability:n}=e;typeof t=="number"&&(this._maxLevel=t),typeof n=="number"&&(this._probability=n)}if(s)for(let[t,n]of s)this.add(t,n)}get head(){return this._head}get level(){return this._level}get maxLevel(){return this._maxLevel}get probability(){return this._probability}get first(){let s=this.head.forward[0];return s?s.value:void 0}get last(){let s=this.head;for(let e=this.level-1;e>=0;e--)for(;s.forward[e];)s=s.forward[e];return s.value}add(s,e){let t=new g(s,e,this._randomLevel()),n=new Array(this.maxLevel).fill(this.head),i=this.head;for(let r=this.level-1;r>=0;r--){for(;i.forward[r]&&i.forward[r].key<s;)i=i.forward[r];n[r]=i}for(let r=0;r<t.forward.length;r++)t.forward[r]=n[r].forward[r],n[r].forward[r]=t;t.forward[0]||(this._level=Math.max(this.level,t.forward.length))}get(s){let e=this.head;for(let t=this.level-1;t>=0;t--)for(;e.forward[t]&&e.forward[t].key<s;)e=e.forward[t];if(e=e.forward[0],e&&e.key===s)return e.value}has(s){return this.get(s)!==void 0}delete(s){let e=new Array(this.maxLevel).fill(this.head),t=this.head;for(let n=this.level-1;n>=0;n--){for(;t.forward[n]&&t.forward[n].key<s;)t=t.forward[n];e[n]=t}if(t=t.forward[0],t&&t.key===s){for(let n=0;n<this.level&&e[n].forward[n]===t;n++)e[n].forward[n]=t.forward[n];for(;this.level>0&&!this.head.forward[this.level-1];)this._level--;return!0}return!1}higher(s){let e=this.head;for(let n=this.level-1;n>=0;n--)for(;e.forward[n]&&e.forward[n].key<=s;)e=e.forward[n];let t=e.forward[0];return t?t.value:void 0}lower(s){let e=this.head,t;for(let n=this.level-1;n>=0;n--){for(;e.forward[n]&&e.forward[n].key<s;)e=e.forward[n];e.key<s&&(t=e)}return t?t.value:void 0}_randomLevel(){let s=1;for(;Math.random()<this.probability&&s<this.maxLevel;)s++;return s}};var w=(e=>(e[e.VISIT=0]="VISIT",e[e.PROCESS=1]="PROCESS",e))(w||{}),x=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 O(K);})();
1
+ "use strict";var linkedListTyped=(()=>{var _=Object.defineProperty;var I=Object.getOwnPropertyDescriptor;var S=Object.getOwnPropertyNames;var M=Object.prototype.hasOwnProperty;var D=(o,s,e)=>s in o?_(o,s,{enumerable:!0,configurable:!0,writable:!0,value:e}):o[s]=e;var C=(o,s)=>{for(var e in s)_(o,e,{get:s[e],enumerable:!0})},O=(o,s,e,t)=>{if(s&&typeof s=="object"||typeof s=="function")for(let n of S(s))!M.call(o,n)&&n!==e&&_(o,n,{get:()=>s[n],enumerable:!(t=I(s,n))||t.enumerable});return o};var A=o=>O(_({},"__esModule",{value:!0}),o);var d=(o,s,e)=>D(o,typeof s!="symbol"?s+"":s,e);var K={};C(K,{DFSOperation:()=>w,DoublyLinkedList:()=>m,DoublyLinkedListNode:()=>b,Range:()=>x,SinglyLinkedList:()=>N,SinglyLinkedListNode:()=>E,SkipList:()=>v,SkipListNode:()=>g});var p=class{constructor(s){d(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 f=class{constructor(s){d(this,"_value");d(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}},k=class o extends p{constructor(e){super(e);d(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 l=this.deleteAt(e);l!==void 0&&i.push(l)}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}},c=class extends k{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 k?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 l=s;l<e;l++)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,l,h=this._getNodeIterator();for(let a of h){if(i===s){r=a;break}l=a,i++}for(let a=0;a<e&&r;a++){n.push(r.value);let u=r.next;this.delete(r),r=u}for(let a=0;a<t.length;a++)l?(this.addAfter(l,t[a]),l=l.next):(this.addAt(0,t[a]),l=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 E=class extends f{constructor(e){super(e);d(this,"_next");this._value=e,this._next=void 0}get next(){return this._next}set next(e){this._next=e}},N=class extends c{constructor(e=[],t){super(t);d(this,"_equals",(e,t)=>Object.is(e,t));d(this,"_head");d(this,"_tail");d(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(){var n;if(!this.head)return;if(this.head===this.tail){let i=this.head.value;return this._head=void 0,this._tail=void 0,this._length--,i}let e=this.head;for(;e.next&&e.next!==this.tail;)e=e.next;let t=(n=this.tail)==null?void 0:n.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&&t;n++)t=t.next;return t==null?void 0:t.value}isNode(e){return e instanceof E}getNodeAt(e){if(e<0||e>=this._length)return;let t=this.head;for(let n=0;n<e&&t;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),l=r?r.next:this.head,h=0;for(;h<t&&l;)i.push(l.value),l=l.next,h++;let a=l;if(r?r.next=a:this._head=a,a||(this._tail=r),n.length>0){let u,L;for(let R of n){let y=this._ensureNode(R);u||(u=y),L&&(L.next=y),L=y}r?r.next=u:this._head=u,L.next=a,a||(this._tail=L)}return this._length+=n.length-h,this._length===0&&(this._head=void 0,this._tail=void 0),i}countOccurrences(e){let t=U(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 l=t===void 0?e(r,i++,this):e.call(t,r,i++,this);n.push(l)}return n}map(e,t,n){let i=this._createLike([],{...t!=null?t:{},maxLen:this._maxLen}),r=0;for(let l of this)i.push(e.call(n,l,r++,this));return i}createNode(e){return new E(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 U(o,s){if(o instanceof E)return t=>t===o;if(typeof o=="function")return o;let e=o;return t=>s(t.value,e)}var b=class extends f{constructor(e){super(e);d(this,"_next");d(this,"_prev");this._value=e,this._next=void 0,this._prev=void 0}get next(){return this._next}set next(e){this._next=e}get prev(){return this._prev}set prev(e){this._prev=e}},m=class extends c{constructor(e=[],t){super(t);d(this,"_equals",(e,t)=>Object.is(e,t));d(this,"_head");d(this,"_tail");d(this,"_length",0);this._head=void 0,this._tail=void 0,this._length=0,t!=null&&t.maxLen&&Number.isInteger(t.maxLen)&&t.maxLen>0&&(this._maxLen=t.maxLen),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 fromArray(e){return new this(e)}isNode(e){return e instanceof b}push(e){let t=this._ensureNode(e);return this.head?(t.prev=this.tail,this.tail.next=t,this._tail=t):(this._head=t,this._tail=t),this._length++,this._maxLen>0&&this.length>this._maxLen&&this.shift(),!0}pop(){if(!this.tail)return;let e=this.tail;return this.head===this.tail?(this._head=void 0,this._tail=void 0):(this._tail=e.prev,this.tail.next=void 0),this._length--,e.value}shift(){if(!this.head)return;let e=this.head;return this.head===this.tail?(this._head=void 0,this._tail=void 0):(this._head=e.next,this.head.prev=void 0),this._length--,e.value}unshift(e){let t=this._ensureNode(e);return this.head?(t.next=this.head,this.head.prev=t,this._head=t):(this._head=t,this._tail=t),this._length++,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}at(e){if(e<0||e>=this._length)return;let t=this.head;for(let n=0;n<e&&t;n++)t=t.next;return t==null?void 0:t.value}getNodeAt(e){if(e<0||e>=this._length)return;let t=this.head;for(let n=0;n<e&&t;n++)t=t.next;return t}getNode(e){if(e===void 0)return;if(this.isNode(e)){let i=e,r=this.head;for(;r;){if(r===i)return i;r=r.next}let l=h=>this._equals(h.value,i.value);for(r=this.head;r;){if(l(r))return r;r=r.next}return}let t=this._ensurePredicate(e),n=this.head;for(;n;){if(t(n))return n;n=n.next}}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),r=i.next;return n.prev=i,n.next=r,i.next=n,r.prev=n,this._length++,!0}addBefore(e,t){let n=this.isNode(e)?e:this.getNode(e);if(!n)return!1;let i=this._ensureNode(t);return i.prev=n.prev,n.prev&&(n.prev.next=i),i.next=n,n.prev=i,n===this.head&&(this._head=i),this._length++,!0}addAfter(e,t){let n=this.isNode(e)?e:this.getNode(e);if(!n)return!1;let i=this._ensureNode(t);return i.next=n.next,n.next&&(n.next.prev=i),i.prev=n,n.next=i,n===this.tail&&(this._tail=i),this._length++,!0}setAt(e,t){let n=this.getNodeAt(e);return n?(n.value=t,!0):!1}deleteAt(e){if(e<0||e>=this._length)return;if(e===0)return this.shift();if(e===this._length-1)return this.pop();let t=this.getNodeAt(e),n=t.prev,i=t.next;return n.next=i,i.prev=n,this._length--,t.value}delete(e){let t=this.getNode(e);if(!t)return!1;if(t===this.head)this.shift();else if(t===this.tail)this.pop();else{let n=t.prev,i=t.next;n.next=i,i.prev=n,this._length--}return!0}isEmpty(){return this._length===0}clear(){this._head=void 0,this._tail=void 0,this._length=0}search(e){let t=this._ensurePredicate(e),n=this.head;for(;n;){if(t(n))return n.value;n=n.next}}getBackward(e){let t=this._ensurePredicate(e),n=this.tail;for(;n;){if(t(n))return n.value;n=n.prev}}reverse(){let e=this.head;for([this._head,this._tail]=[this.tail,this.head];e;){let t=e.next;[e.prev,e.next]=[e.next,e.prev],e=t}return this}setEquality(e){return this._equals=e,this}clone(){let e=this._createInstance({toElementFn:this._toElementFn,maxLen:this._maxLen});for(let t of this)e.push(t);return e}filter(e,t){let n=this._createInstance({toElementFn:this._toElementFn,maxLen:this._maxLen}),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({toElementFn:this._toElementFn,maxLen:this._maxLen}),i=0;for(let r of this){let l=t===void 0?e(r,i++,this):e.call(t,r,i++,this);n.push(l)}return n}map(e,t,n){let i=this._createLike([],{...t!=null?t:{},maxLen:this._maxLen}),r=0;for(let l of this)i.push(e.call(n,l,r++,this));return i}_ensureNode(e){return this.isNode(e)?e:new b(e)}_ensurePredicate(e){if(this.isNode(e)){let n=e;return i=>i===n}if(typeof e=="function")return e;let t=e;return n=>this._equals(n.value,t)}_getPrevNode(e){return e.prev}_createInstance(e){let t=this.constructor;return new t([],e)}_createLike(e=[],t){let n=this.constructor;return new n(e,t)}*_getIterator(){let e=this.head;for(;e;)yield e.value,e=e.next}*_getReverseIterator(){let e=this.tail;for(;e;)yield e.value,e=e.prev}*_getNodeIterator(){let e=this.head;for(;e;)yield e,e=e.next}};var g=class{constructor(s,e,t){d(this,"key");d(this,"value");d(this,"forward");this.key=s,this.value=e,this.forward=new Array(t)}},v=class{constructor(s=[],e){d(this,"_head",new g(void 0,void 0,this.maxLevel));d(this,"_level",0);d(this,"_maxLevel",16);d(this,"_probability",.5);if(e){let{maxLevel:t,probability:n}=e;typeof t=="number"&&(this._maxLevel=t),typeof n=="number"&&(this._probability=n)}if(s)for(let[t,n]of s)this.add(t,n)}get head(){return this._head}get level(){return this._level}get maxLevel(){return this._maxLevel}get probability(){return this._probability}get first(){let s=this.head.forward[0];return s?s.value:void 0}get last(){let s=this.head;for(let e=this.level-1;e>=0;e--)for(;s.forward[e];)s=s.forward[e];return s.value}add(s,e){let t=new g(s,e,this._randomLevel()),n=new Array(this.maxLevel).fill(this.head),i=this.head;for(let r=this.level-1;r>=0;r--){for(;i.forward[r]&&i.forward[r].key<s;)i=i.forward[r];n[r]=i}for(let r=0;r<t.forward.length;r++)t.forward[r]=n[r].forward[r],n[r].forward[r]=t;t.forward[0]||(this._level=Math.max(this.level,t.forward.length))}get(s){let e=this.head;for(let t=this.level-1;t>=0;t--)for(;e.forward[t]&&e.forward[t].key<s;)e=e.forward[t];if(e=e.forward[0],e&&e.key===s)return e.value}has(s){return this.get(s)!==void 0}delete(s){let e=new Array(this.maxLevel).fill(this.head),t=this.head;for(let n=this.level-1;n>=0;n--){for(;t.forward[n]&&t.forward[n].key<s;)t=t.forward[n];e[n]=t}if(t=t.forward[0],t&&t.key===s){for(let n=0;n<this.level&&e[n].forward[n]===t;n++)e[n].forward[n]=t.forward[n];for(;this.level>0&&!this.head.forward[this.level-1];)this._level--;return!0}return!1}higher(s){let e=this.head;for(let n=this.level-1;n>=0;n--)for(;e.forward[n]&&e.forward[n].key<=s;)e=e.forward[n];let t=e.forward[0];return t?t.value:void 0}lower(s){let e=this.head,t;for(let n=this.level-1;n>=0;n--){for(;e.forward[n]&&e.forward[n].key<s;)e=e.forward[n];e.key<s&&(t=e)}return t?t.value:void 0}_randomLevel(){let s=1;for(;Math.random()<this.probability&&s<this.maxLevel;)s++;return s}};var w=(e=>(e[e.VISIT=0]="VISIT",e[e.PROCESS=1]="PROCESS",e))(w||{}),x=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 A(K);})();
2
2
  /**
3
3
  * data-structure-typed
4
4
  *