avl-tree-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 +1 -1
  2. package/dist/cjs/index.cjs.map +1 -1
  3. package/dist/cjs-legacy/index.cjs +1 -1
  4. package/dist/cjs-legacy/index.cjs.map +1 -1
  5. package/dist/esm/index.mjs +1 -1
  6. package/dist/esm/index.mjs.map +1 -1
  7. package/dist/esm-legacy/index.mjs +1 -1
  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/avl-tree-typed.js +1 -1
  25. package/dist/umd/avl-tree-typed.js.map +1 -1
  26. package/dist/umd/avl-tree-typed.min.js +1 -1
  27. package/dist/umd/avl-tree-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 avlTreeTyped=(()=>{var x=Object.defineProperty;var Q=Object.getOwnPropertyDescriptor;var j=Object.getOwnPropertyNames;var q=Object.prototype.hasOwnProperty;var W=(c,o,e)=>o in c?x(c,o,{enumerable:!0,configurable:!0,writable:!0,value:e}):c[o]=e;var X=(c,o)=>{for(var e in o)x(c,e,{get:o[e],enumerable:!0})},J=(c,o,e,t)=>{if(o&&typeof o=="object"||typeof o=="function")for(let n of j(o))!q.call(c,n)&&n!==e&&x(c,n,{get:()=>o[n],enumerable:!(t=Q(o,n))||t.enumerable});return c};var Y=c=>J(x({},"__esModule",{value:!0}),c);var K=(c,o,e)=>W(c,typeof o!="symbol"?o+"":o,e);var ee={};X(ee,{AVLTree:()=>P,AVLTreeNode:()=>L,BST:()=>I,BSTNode:()=>S,BinaryTree:()=>E,BinaryTreeNode:()=>C});function O(c){let o=typeof c;return o==="number"?!0:o==="bigint"||o==="string"||o==="boolean"}function H(c){if(typeof c.valueOf=="function"){let o=c.valueOf();if(o!==c){if(O(o))return o;if(typeof o=="object"&&o!==null)return H(o)}}if(typeof c.toString=="function"){let o=c.toString();if(o!=="[object Object]")return o}return null}function b(c,o=!1){if(c==null)return!1;if(O(c))return!0;if(typeof c!="object")return!1;if(c instanceof Date||o)return!0;let e=H(c);return e==null?!1:O(e)}var D=c=>({isThunk:!0,fn:c}),Z=c=>typeof c=="object"&&c!==null&&"isThunk"in c&&c.isThunk;function $(c){let o=c;for(;Z(o);)o=o.fn();return o}function F(c){return(...o)=>$(c(...o))}var M=class{constructor(o){K(this,"_toElementFn");if(o){let{toElementFn:e}=o;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](...o){yield*this._getIterator(...o)}*values(){for(let o of this)yield o}every(o,e){let t=0;for(let n of this)if(e===void 0){if(!o(n,t++,this))return!1}else if(!o.call(e,n,t++,this))return!1;return!0}some(o,e){let t=0;for(let n of this)if(e===void 0){if(o(n,t++,this))return!0}else if(o.call(e,n,t++,this))return!0;return!1}forEach(o,e){let t=0;for(let n of this)e===void 0?o(n,t++,this):o.call(e,n,t++,this)}find(o,e){let t=0;for(let n of this)if(e===void 0){if(o(n,t++,this))return n}else if(o.call(e,n,t++,this))return n}has(o){for(let e of this)if(e===o)return!0;return!1}reduce(o,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=o(i,r,t++,this);return i}toArray(){return[...this]}toVisual(){return[...this]}print(){console.log(this.toVisual())}};var w=class c extends M{constructor(e){super(e);K(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 c?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 s=this.deleteAt(e);s!==void 0&&i.push(s)}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}};var g=class c extends w{constructor(e=[],t){super(t);K(this,"_elements",[]);K(this,"_offset",0);K(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 c(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 s=this._createInstance({toElementFn:this.toElementFn,maxLen:this._maxLen});return s._setAutoCompactRatio(this._autoCompactRatio),s.pushMany(r),s}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 s,d;let i=new this.constructor([],{toElementFn:t==null?void 0:t.toElementFn,maxLen:(s=t==null?void 0:t.maxLen)!=null?s:this._maxLen,autoCompactRatio:(d=t==null?void 0:t.autoCompactRatio)!=null?d:this._autoCompactRatio}),r=0;for(let l of this)i.push(n===void 0?e(l,r++,this):e.call(n,l,r++,this));return i}mapSame(e,t){var s;let n=this.constructor,i=new n([],{toElementFn:this.toElementFn,maxLen:this._maxLen,autoCompactRatio:this._autoCompactRatio});(s=i._setAutoCompactRatio)==null||s.call(i,this._autoCompactRatio);let r=0;for(let d of this){let l=t===void 0?e(d,r++,this):e.call(t,d,r++,this);i.push(l)}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)}};var v=class{*[Symbol.iterator](...o){yield*this._getIterator(...o)}*entries(){for(let o of this)yield o}*keys(){for(let o of this)yield o[0]}*values(){for(let o of this)yield o[1]}every(o,e){let t=0;for(let n of this)if(!o.call(e,n[1],n[0],t++,this))return!1;return!0}some(o,e){let t=0;for(let n of this)if(o.call(e,n[1],n[0],t++,this))return!0;return!1}forEach(o,e){let t=0;for(let n of this){let[i,r]=n;o.call(e,r,i,t++,this)}}find(o,e){let t=0;for(let n of this){let[i,r]=n;if(o.call(e,r,i,t++,this))return n}}has(o){for(let e of this){let[t]=e;if(t===o)return!0}return!1}hasValue(o){for(let[,e]of this)if(e===o)return!0;return!1}get(o){for(let e of this){let[t,n]=e;if(t===o)return n}}reduce(o,e){let t=e,n=0;for(let i of this){let[r,s]=i;t=o(t,s,r,n++,this)}return t}toArray(){return[...this]}toVisual(){return[...this]}print(){console.log(this.toVisual())}};var m=class{constructor(o,e,t=!0,n=!0){this.low=o;this.high=e;this.includeLow=t;this.includeHigh=n}isInRange(o,e){let t=this.includeLow?e(o,this.low)>=0:e(o,this.low)>0,n=this.includeHigh?e(o,this.high)<=0:e(o,this.high)<0;return t&&n}};var C=class{constructor(o,e){K(this,"key");K(this,"value");K(this,"parent");K(this,"_left");K(this,"_right");K(this,"_height",0);K(this,"_color","BLACK");K(this,"_count",1);this.key=o,this.value=e}get left(){return this._left}set left(o){o&&(o.parent=this),this._left=o}get right(){return this._right}set right(o){o&&(o.parent=this),this._right=o}get height(){return this._height}set height(o){this._height=o}get color(){return this._color}set color(o){this._color=o}get count(){return this._count}set count(o){this._count=o}get familyPosition(){return this.parent?this.parent.left===this?this.left||this.right?"ROOT_LEFT":"LEFT":this.parent.right===this?this.left||this.right?"ROOT_RIGHT":"RIGHT":"MAL_NODE":this.left||this.right?"ROOT":"ISOLATED"}},E=class extends v{constructor(e=[],t){super();K(this,"iterationType","ITERATIVE");K(this,"_isMapMode",!0);K(this,"_isDuplicate",!1);K(this,"_store",new Map);K(this,"_root");K(this,"_size",0);K(this,"_NIL",new C(NaN));K(this,"_toEntryFn");K(this,"_DEFAULT_NODE_CALLBACK",e=>e?e.key:void 0);if(t){let{iterationType:n,toEntryFn:i,isMapMode:r,isDuplicate:s}=t;if(n&&(this.iterationType=n),r!==void 0&&(this._isMapMode=r),s!==void 0&&(this._isDuplicate=s),typeof i=="function")this._toEntryFn=i;else if(i)throw TypeError("toEntryFn must be a function type")}e&&this.setMany(e)}get isMapMode(){return this._isMapMode}get isDuplicate(){return this._isDuplicate}get store(){return this._store}get root(){return this._root}get size(){return this._size}get NIL(){return this._NIL}get toEntryFn(){return this._toEntryFn}createNode(e,t){return new C(e,t)}createTree(e){return this._createInstance(e)}ensureNode(e,t=this.iterationType){if(e===null)return null;if(e!==void 0&&e!==this._NIL){if(this.isNode(e))return e;if(this.isEntry(e)){let n=e[0];return n===null?null:n===void 0?void 0:this.getNode(n,this._root,t)}return this.getNode(e,this._root,t)}}isNode(e){return e instanceof C}isRaw(e){return this._toEntryFn!==void 0&&typeof e=="object"}isRealNode(e){return e===this._NIL||e===null||e===void 0?!1:this.isNode(e)}isRealNodeOrNull(e){return e===null||this.isRealNode(e)}isNIL(e){return e===this._NIL}isRange(e){return e instanceof m}isLeaf(e){return e=this.ensureNode(e),e===void 0?!1:e===null?!0:!this.isRealNode(e.left)&&!this.isRealNode(e.right)}isEntry(e){return Array.isArray(e)&&e.length===2}isValidKey(e){return e===null?!0:b(e)}add(e){return this.set(e)}set(e,t){let[n]=this._keyValueNodeOrEntryToNodeAndValue(e,t);if(n===void 0)return!1;if(!this._root)return this._setRoot(n),this._isMapMode&&n!==null&&n!==void 0&&this._store.set(n.key,n),this._size=1,!0;let i=new g([this._root]),r;for(;i.length>0;){let s=i.shift();if(s){if(!this._isDuplicate&&n!==null&&s.key===n.key)return this._replaceNode(s,n),this._isMapMode&&n!==null&&this._store.set(s.key,n),!0;r===void 0&&(s.left===void 0||s.right===void 0)&&(r=s),s.left!==null&&s.left&&i.push(s.left),s.right!==null&&s.right&&i.push(s.right)}}return r?(r.left===void 0?r.left=n:r.right===void 0&&(r.right=n),this._isMapMode&&n!==null&&n!==void 0&&this._store.set(n.key,n),this._size++,!0):!1}addMany(e){return this.setMany(e)}setMany(e,t){let n=[],i;t&&(i=t[Symbol.iterator]());for(let r of e){let s;if(i){let d=i.next();d.done||(s=d.value)}this.isRaw(r)&&(r=this._toEntryFn(r)),n.push(this.set(r,s))}return n}merge(e){this.setMany(e,[])}refill(e,t){this.clear(),this.setMany(e,t)}delete(e){let t=[];if(!this._root)return t;let n=this.getNode(e);if(!n)return t;let i=n==null?void 0:n.parent,r,s=n;if(!n.left&&!n.right&&!i)this._setRoot(void 0);else if(n.left){let d=this.getRightMost(l=>l,n.left);if(d){let l=d.parent;s=this._swapProperties(n,d),this._isMapMode&&(this._store.set(n.key,n),this._store.set(d.key,d)),l&&(l.right===d?l.right=d.left:l.left=d.left,r=l)}}else if(i){let{familyPosition:d}=n;d==="LEFT"||d==="ROOT_LEFT"?i.left=n.right:(d==="RIGHT"||d==="ROOT_RIGHT")&&(i.right=n.right),r=i}else this._setRoot(n.right),n.right=void 0;return this._size=this._size-1,t.push({deleted:s,needBalanced:r}),this._isMapMode&&s&&this._store.delete(s.key),t}search(e,t=!1,n=this._DEFAULT_NODE_CALLBACK,i=this._root,r=this.iterationType){if(e===void 0)return[];if(e===null)return[];if(i=this.ensureNode(i),!i)return[];let s=this._ensurePredicate(e),d=[];if(r==="RECURSIVE"){let l=u=>{s(u)&&(d.push(n(u)),t)||!this.isRealNode(u.left)&&!this.isRealNode(u.right)||(this.isRealNode(u.left)&&l(u.left),this.isRealNode(u.right)&&l(u.right))};l(i)}else{let l=[i];for(;l.length>0;){let u=l.pop();if(this.isRealNode(u)){if(s(u)&&(d.push(n(u)),t))return d;this.isRealNode(u.left)&&l.push(u.left),this.isRealNode(u.right)&&l.push(u.right)}}}return d}getNodes(e,t=!1,n=this._root,i=this.iterationType){return this.search(e,t,r=>r,n,i)}getNode(e,t=this._root,n=this.iterationType){if(this._isMapMode&&e!==null&&e!==void 0&&!this._isPredicate(e)){let i=this._extractKey(e);return i==null?void 0:this._store.get(i)}return this.search(e,!0,i=>i,t,n)[0]}get(e,t=this._root,n=this.iterationType){var i,r;if(this._isMapMode){let s=this._extractKey(e);return s==null||(i=this._store.get(s))==null?void 0:i.value}return(r=this.getNode(e,t,n))==null?void 0:r.value}has(e,t=this._root,n=this.iterationType){if(this._isMapMode&&e!==void 0&&e!==null&&!this._isPredicate(e)){let i=this._extractKey(e);return i==null?!1:this._store.has(i)}return this.search(e,!0,i=>i,t,n).length>0}clear(){this._clearNodes(),this._isMapMode&&this._clearValues()}isEmpty(){return this._size===0}isPerfectlyBalanced(e=this._root){return this.getMinHeight(e)+1>=this.getHeight(e)}isBST(e=this._root,t=this.iterationType){let n=this.ensureNode(e);if(!n)return!0;if(t==="RECURSIVE"){let i=(d,l,u)=>{if(!this.isRealNode(d))return!0;let f=Number(d.key);return f<=l||f>=u?!1:i(d.left,l,f)&&i(d.right,f,u)},r=i(n,Number.MIN_SAFE_INTEGER,Number.MAX_SAFE_INTEGER),s=i(n,Number.MAX_SAFE_INTEGER,Number.MIN_SAFE_INTEGER);return r||s}else{let i=(d=!1)=>{let l=[],u=d?Number.MAX_SAFE_INTEGER:Number.MIN_SAFE_INTEGER,f=n;for(;this.isRealNode(f)||l.length>0;){for(;this.isRealNode(f);)l.push(f),f=f.left;f=l.pop();let h=Number(f.key);if(!this.isRealNode(f)||!d&&u>=h||d&&u<=h)return!1;u=h,f=f.right}return!0},r=i(),s=i(!0);return r||s}}getDepth(e,t=this._root){let n=this.ensureNode(e),i=this.ensureNode(t),r=0;for(;n!=null&&n.parent;){if(n===i)return r;r++,n=n.parent}return r}getHeight(e=this._root,t=this.iterationType){if(e=this.ensureNode(e),!this.isRealNode(e))return-1;if(t==="RECURSIVE"){let n=i=>{if(!this.isRealNode(i))return-1;let r=n(i.left),s=n(i.right);return Math.max(r,s)+1};return n(e)}else{let n=[{node:e,depth:0}],i=0;for(;n.length>0;){let{node:r,depth:s}=n.pop();this.isRealNode(r.left)&&n.push({node:r.left,depth:s+1}),this.isRealNode(r.right)&&n.push({node:r.right,depth:s+1}),i=Math.max(i,s)}return i}}getMinHeight(e=this._root,t=this.iterationType){if(e=this.ensureNode(e),!e)return-1;if(t==="RECURSIVE"){let n=i=>{if(!this.isRealNode(i)||!this.isRealNode(i.left)&&!this.isRealNode(i.right))return 0;let r=n(i.left),s=n(i.right);return Math.min(r,s)+1};return n(e)}else{let n=[],i=e,r=null,s=new Map;for(;n.length>0||i;)if(this.isRealNode(i))n.push(i),i=i.left;else if(i=n[n.length-1],!this.isRealNode(i.right)||r===i.right){if(i=n.pop(),this.isRealNode(i)){let d=this.isRealNode(i.left)?s.get(i.left):-1,l=this.isRealNode(i.right)?s.get(i.right):-1;s.set(i,1+Math.min(d,l)),r=i,i=null}}else i=i.right;return s.get(e)}}getPathToRoot(e,t=this._DEFAULT_NODE_CALLBACK,n=!1){let i=[],r=this.ensureNode(e);if(!r)return i;for(;r.parent;)i.push(t(r)),r=r.parent;return i.push(t(r)),n?i.reverse():i}getLeftMost(e=this._DEFAULT_NODE_CALLBACK,t=this._root,n=this.iterationType){if(this.isNIL(t))return e(void 0);let i=this.ensureNode(t);if(!this.isRealNode(i))return e(void 0);if(n==="RECURSIVE"){let r=s=>{let{left:d}=s;return this.isRealNode(d)?r(d):s};return e(r(i))}else{let r=F(s=>{let{left:d}=s;return this.isRealNode(d)?D(()=>r(d)):s});return e(r(i))}}getRightMost(e=this._DEFAULT_NODE_CALLBACK,t=this._root,n=this.iterationType){if(this.isNIL(t)||(t=this.ensureNode(t),!t))return e(void 0);if(n==="RECURSIVE"){let i=r=>{let{right:s}=r;return this.isRealNode(s)?i(s):r};return e(i(t))}else{let i=F(r=>{let{right:s}=r;return this.isRealNode(s)?D(()=>i(s)):r});return e(i(t))}}getPredecessor(e){if(this.isRealNode(e.left)){let t=e.left;for(;!this.isRealNode(t)||this.isRealNode(t.right)&&t.right!==e;)this.isRealNode(t)&&(t=t.right);return t}else return e}getSuccessor(e){if(e=this.ensureNode(e),!this.isRealNode(e))return;if(this.isRealNode(e.right))return this.getLeftMost(n=>n,e.right);let t=e.parent;for(;this.isRealNode(t)&&e===t.right;)e=t,t=t.parent;return t}dfs(e=this._DEFAULT_NODE_CALLBACK,t="IN",n=!1,i=this._root,r=this.iterationType,s=!1){return i=this.ensureNode(i),i?this._dfs(e,t,n,i,r,s):[]}bfs(e=this._DEFAULT_NODE_CALLBACK,t=this._root,n=this.iterationType,i=!1){if(t=this.ensureNode(t),!t)return[];let r=[];if(n==="RECURSIVE"){let s=new g([t]),d=l=>{if(s.length===0)return;let u=s.shift();r.push(e(u)),i?(u&&this.isRealNodeOrNull(u.left)&&s.push(u.left),u&&this.isRealNodeOrNull(u.right)&&s.push(u.right)):(this.isRealNode(u.left)&&s.push(u.left),this.isRealNode(u.right)&&s.push(u.right)),d(l+1)};d(0)}else{let s=new g([t]);for(;s.length>0;){let d=s.length;for(let l=0;l<d;l++){let u=s.shift();r.push(e(u)),i?(u&&this.isRealNodeOrNull(u.left)&&s.push(u.left),u&&this.isRealNodeOrNull(u.right)&&s.push(u.right)):(this.isRealNode(u.left)&&s.push(u.left),this.isRealNode(u.right)&&s.push(u.right))}}}return r}leaves(e=this._DEFAULT_NODE_CALLBACK,t=this._root,n=this.iterationType){t=this.ensureNode(t);let i=[];if(!this.isRealNode(t))return[];if(n==="RECURSIVE"){let r=s=>{this.isLeaf(s)&&i.push(e(s)),!(!this.isRealNode(s.left)&&!this.isRealNode(s.right))&&(this.isRealNode(s.left)&&r(s.left),this.isRealNode(s.right)&&r(s.right))};r(t)}else{let r=new g([t]);for(;r.length>0;){let s=r.shift();this.isRealNode(s)&&(this.isLeaf(s)&&i.push(e(s)),this.isRealNode(s.left)&&r.push(s.left),this.isRealNode(s.right)&&r.push(s.right))}}return i}listLevels(e=this._DEFAULT_NODE_CALLBACK,t=this._root,n=this.iterationType,i=!1){t=this.ensureNode(t);let r=[];if(!t)return r;if(n==="RECURSIVE"){let s=(d,l)=>{r[l]||(r[l]=[]),r[l].push(e(d)),i?(d&&this.isRealNodeOrNull(d.left)&&s(d.left,l+1),d&&this.isRealNodeOrNull(d.right)&&s(d.right,l+1)):(d&&d.left&&s(d.left,l+1),d&&d.right&&s(d.right,l+1))};s(t,0)}else{let s=[[t,0]];for(;s.length>0;){let d=s.pop(),[l,u]=d;r[u]||(r[u]=[]),r[u].push(e(l)),i?(l&&this.isRealNodeOrNull(l.right)&&s.push([l.right,u+1]),l&&this.isRealNodeOrNull(l.left)&&s.push([l.left,u+1])):(l&&l.right&&s.push([l.right,u+1]),l&&l.left&&s.push([l.left,u+1]))}}return r}morris(e=this._DEFAULT_NODE_CALLBACK,t="IN",n=this._root){if(n=this.ensureNode(n),!n)return[];let i=[],r=n,s=l=>{let u=null,f=null;for(;l;)f=l.right,l.right=u,u=l,l=f;return u},d=l=>{let u=s(l),f=u;for(;f;)i.push(e(f)),f=f.right;s(u)};switch(t){case"IN":for(;r;){if(r.left){let l=this.getPredecessor(r);if(l.right)l.right=null;else{l.right=r,r=r.left;continue}}i.push(e(r)),r=r.right}break;case"PRE":for(;r;){if(r.left){let l=this.getPredecessor(r);if(l.right)l.right=null;else{l.right=r,i.push(e(r)),r=r.left;continue}}else i.push(e(r));r=r.right}break;case"POST":for(;r;){if(r.left){let l=this.getPredecessor(r);if(l.right===null){l.right=r,r=r.left;continue}else l.right=null,d(r.left)}r=r.right}d(n);break}return i}clone(){let e=this._createInstance();return this._clone(e),e}filter(e,t){let n=this._createInstance(),i=0;for(let[r,s]of this)e.call(t,s,r,i++,this)&&n.set([r,s]);return n}map(e,t,n){let i=this._createLike([],t),r=0;for(let[s,d]of this)i.set(e.call(n,d,s,r++,this));return i}toVisual(e=this._root,t){let n={isShowUndefined:!1,isShowNull:!0,isShowRedBlackNIL:!1,...t};e=this.ensureNode(e);let i="";return e&&(n.isShowUndefined&&(i+=`U for undefined
1
+ "use strict";var avlTreeTyped=(()=>{var x=Object.defineProperty;var Q=Object.getOwnPropertyDescriptor;var j=Object.getOwnPropertyNames;var q=Object.prototype.hasOwnProperty;var W=(c,o,e)=>o in c?x(c,o,{enumerable:!0,configurable:!0,writable:!0,value:e}):c[o]=e;var X=(c,o)=>{for(var e in o)x(c,e,{get:o[e],enumerable:!0})},J=(c,o,e,t)=>{if(o&&typeof o=="object"||typeof o=="function")for(let n of j(o))!q.call(c,n)&&n!==e&&x(c,n,{get:()=>o[n],enumerable:!(t=Q(o,n))||t.enumerable});return c};var Y=c=>J(x({},"__esModule",{value:!0}),c);var K=(c,o,e)=>W(c,typeof o!="symbol"?o+"":o,e);var ee={};X(ee,{AVLTree:()=>P,AVLTreeNode:()=>L,BST:()=>I,BSTNode:()=>S,BinaryTree:()=>E,BinaryTreeNode:()=>C});function O(c){let o=typeof c;return o==="number"?!0:o==="bigint"||o==="string"||o==="boolean"}function H(c){if(typeof c.valueOf=="function"){let o=c.valueOf();if(o!==c){if(O(o))return o;if(typeof o=="object"&&o!==null)return H(o)}}if(typeof c.toString=="function"){let o=c.toString();if(o!=="[object Object]")return o}return null}function b(c,o=!1){if(c==null)return!1;if(O(c))return!0;if(typeof c!="object")return!1;if(c instanceof Date||o)return!0;let e=H(c);return e==null?!1:O(e)}var D=c=>({isThunk:!0,fn:c}),Z=c=>typeof c=="object"&&c!==null&&"isThunk"in c&&c.isThunk;function $(c){let o=c;for(;Z(o);)o=o.fn();return o}function F(c){return(...o)=>$(c(...o))}var M=class{constructor(o){K(this,"_toElementFn");if(o){let{toElementFn:e}=o;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](...o){yield*this._getIterator(...o)}*values(){for(let o of this)yield o}every(o,e){let t=0;for(let n of this)if(e===void 0){if(!o(n,t++,this))return!1}else if(!o.call(e,n,t++,this))return!1;return!0}some(o,e){let t=0;for(let n of this)if(e===void 0){if(o(n,t++,this))return!0}else if(o.call(e,n,t++,this))return!0;return!1}forEach(o,e){let t=0;for(let n of this)e===void 0?o(n,t++,this):o.call(e,n,t++,this)}find(o,e){let t=0;for(let n of this)if(e===void 0){if(o(n,t++,this))return n}else if(o.call(e,n,t++,this))return n}has(o){for(let e of this)if(e===o)return!0;return!1}reduce(o,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=o(i,r,t++,this);return i}toArray(){return[...this]}toVisual(){return[...this]}print(){console.log(this.toVisual())}};var w=class c extends M{constructor(e){super(e);K(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 c?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 s=this.deleteAt(e);s!==void 0&&i.push(s)}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}};var g=class c extends w{constructor(e=[],t){super(t);K(this,"_elements",[]);K(this,"_offset",0);K(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 c(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 s=this._createInstance({toElementFn:this.toElementFn,maxLen:this._maxLen});return s._setAutoCompactRatio(this._autoCompactRatio),s.pushMany(r),s}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 s,d;let i=new this.constructor([],{toElementFn:t==null?void 0:t.toElementFn,maxLen:(s=t==null?void 0:t.maxLen)!=null?s:this._maxLen,autoCompactRatio:(d=t==null?void 0:t.autoCompactRatio)!=null?d:this._autoCompactRatio}),r=0;for(let l of this)i.push(n===void 0?e(l,r++,this):e.call(n,l,r++,this));return i}mapSame(e,t){var s;let n=this.constructor,i=new n([],{toElementFn:this.toElementFn,maxLen:this._maxLen,autoCompactRatio:this._autoCompactRatio});(s=i._setAutoCompactRatio)==null||s.call(i,this._autoCompactRatio);let r=0;for(let d of this){let l=t===void 0?e(d,r++,this):e.call(t,d,r++,this);i.push(l)}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)}};var v=class{*[Symbol.iterator](...o){yield*this._getIterator(...o)}*entries(){for(let o of this)yield o}*keys(){for(let o of this)yield o[0]}*values(){for(let o of this)yield o[1]}every(o,e){let t=0;for(let n of this)if(!o.call(e,n[1],n[0],t++,this))return!1;return!0}some(o,e){let t=0;for(let n of this)if(o.call(e,n[1],n[0],t++,this))return!0;return!1}forEach(o,e){let t=0;for(let n of this){let[i,r]=n;o.call(e,r,i,t++,this)}}find(o,e){let t=0;for(let n of this){let[i,r]=n;if(o.call(e,r,i,t++,this))return n}}has(o){for(let e of this){let[t]=e;if(t===o)return!0}return!1}hasValue(o){for(let[,e]of this)if(e===o)return!0;return!1}get(o){for(let e of this){let[t,n]=e;if(t===o)return n}}reduce(o,e){let t=e,n=0;for(let i of this){let[r,s]=i;t=o(t,s,r,n++,this)}return t}toArray(){return[...this]}toVisual(){return[...this]}print(){console.log(this.toVisual())}};var m=class{constructor(o,e,t=!0,n=!0){this.low=o;this.high=e;this.includeLow=t;this.includeHigh=n}isInRange(o,e){let t=this.includeLow?e(o,this.low)>=0:e(o,this.low)>0,n=this.includeHigh?e(o,this.high)<=0:e(o,this.high)<0;return t&&n}};var C=class{constructor(o,e){K(this,"key");K(this,"value");K(this,"parent");K(this,"_left");K(this,"_right");K(this,"_height",0);K(this,"_color","BLACK");K(this,"_count",1);this.key=o,this.value=e}get left(){return this._left}set left(o){o&&(o.parent=this),this._left=o}get right(){return this._right}set right(o){o&&(o.parent=this),this._right=o}get height(){return this._height}set height(o){this._height=o}get color(){return this._color}set color(o){this._color=o}get count(){return this._count}set count(o){this._count=o}get familyPosition(){return this.parent?this.parent.left===this?this.left||this.right?"ROOT_LEFT":"LEFT":this.parent.right===this?this.left||this.right?"ROOT_RIGHT":"RIGHT":"MAL_NODE":this.left||this.right?"ROOT":"ISOLATED"}},E=class extends v{constructor(e=[],t){super();K(this,"iterationType","ITERATIVE");K(this,"_isMapMode",!0);K(this,"_isDuplicate",!1);K(this,"_store",new Map);K(this,"_root");K(this,"_size",0);K(this,"_NIL",new C(NaN));K(this,"_toEntryFn");K(this,"_DEFAULT_NODE_CALLBACK",e=>e==null?void 0:e.key);if(t){let{iterationType:n,toEntryFn:i,isMapMode:r,isDuplicate:s}=t;if(n&&(this.iterationType=n),r!==void 0&&(this._isMapMode=r),s!==void 0&&(this._isDuplicate=s),typeof i=="function")this._toEntryFn=i;else if(i)throw TypeError("toEntryFn must be a function type")}e&&this.setMany(e)}get isMapMode(){return this._isMapMode}get isDuplicate(){return this._isDuplicate}get store(){return this._store}get root(){return this._root}get size(){return this._size}get NIL(){return this._NIL}get toEntryFn(){return this._toEntryFn}createNode(e,t){return new C(e,t)}createTree(e){return this._createInstance(e)}ensureNode(e,t=this.iterationType){if(e===null)return null;if(e!==void 0&&e!==this._NIL){if(this.isNode(e))return e;if(this.isEntry(e)){let n=e[0];return n===null?null:n===void 0?void 0:this.getNode(n,this._root,t)}return this.getNode(e,this._root,t)}}isNode(e){return e instanceof C}isRaw(e){return this._toEntryFn!==void 0&&typeof e=="object"}isRealNode(e){return e===this._NIL||e===null||e===void 0?!1:this.isNode(e)}isRealNodeOrNull(e){return e===null||this.isRealNode(e)}isNIL(e){return e===this._NIL}isRange(e){return e instanceof m}isLeaf(e){return e=this.ensureNode(e),e===void 0?!1:e===null?!0:!this.isRealNode(e.left)&&!this.isRealNode(e.right)}isEntry(e){return Array.isArray(e)&&e.length===2}isValidKey(e){return e===null?!0:b(e)}add(e){return this.set(e)}set(e,t){let[n]=this._keyValueNodeOrEntryToNodeAndValue(e,t);if(n===void 0)return!1;if(!this._root)return this._setRoot(n),this._isMapMode&&n!==null&&n!==void 0&&this._store.set(n.key,n),this._size=1,!0;let i=new g([this._root]),r;for(;i.length>0;){let s=i.shift();if(s){if(!this._isDuplicate&&n!==null&&s.key===n.key)return this._replaceNode(s,n),this._isMapMode&&n!==null&&this._store.set(s.key,n),!0;r===void 0&&(s.left===void 0||s.right===void 0)&&(r=s),s.left!==null&&s.left&&i.push(s.left),s.right!==null&&s.right&&i.push(s.right)}}return r?(r.left===void 0?r.left=n:r.right===void 0&&(r.right=n),this._isMapMode&&n!==null&&n!==void 0&&this._store.set(n.key,n),this._size++,!0):!1}addMany(e){return this.setMany(e)}setMany(e,t){let n=[],i;t&&(i=t[Symbol.iterator]());for(let r of e){let s;if(i){let d=i.next();d.done||(s=d.value)}this.isRaw(r)&&(r=this._toEntryFn(r)),n.push(this.set(r,s))}return n}merge(e){this.setMany(e,[])}refill(e,t){this.clear(),this.setMany(e,t)}delete(e){let t=[];if(!this._root)return t;let n=this.getNode(e);if(!n)return t;let i=n==null?void 0:n.parent,r,s=n;if(!n.left&&!n.right&&!i)this._setRoot(void 0);else if(n.left){let d=this.getRightMost(l=>l,n.left);if(d){let l=d.parent;s=this._swapProperties(n,d),this._isMapMode&&(this._store.set(n.key,n),this._store.set(d.key,d)),l&&(l.right===d?l.right=d.left:l.left=d.left,r=l)}}else if(i){let{familyPosition:d}=n;d==="LEFT"||d==="ROOT_LEFT"?i.left=n.right:(d==="RIGHT"||d==="ROOT_RIGHT")&&(i.right=n.right),r=i}else this._setRoot(n.right),n.right=void 0;return this._size=this._size-1,t.push({deleted:s,needBalanced:r}),this._isMapMode&&s&&this._store.delete(s.key),t}search(e,t=!1,n=this._DEFAULT_NODE_CALLBACK,i=this._root,r=this.iterationType){if(e===void 0)return[];if(e===null)return[];if(i=this.ensureNode(i),!i)return[];let s=this._ensurePredicate(e),d=[];if(r==="RECURSIVE"){let l=u=>{s(u)&&(d.push(n(u)),t)||!this.isRealNode(u.left)&&!this.isRealNode(u.right)||(this.isRealNode(u.left)&&l(u.left),this.isRealNode(u.right)&&l(u.right))};l(i)}else{let l=[i];for(;l.length>0;){let u=l.pop();if(this.isRealNode(u)){if(s(u)&&(d.push(n(u)),t))return d;this.isRealNode(u.left)&&l.push(u.left),this.isRealNode(u.right)&&l.push(u.right)}}}return d}getNodes(e,t=!1,n=this._root,i=this.iterationType){return this.search(e,t,r=>r,n,i)}getNode(e,t=this._root,n=this.iterationType){if(this._isMapMode&&e!==null&&e!==void 0&&!this._isPredicate(e)){let i=this._extractKey(e);return i==null?void 0:this._store.get(i)}return this.search(e,!0,i=>i,t,n)[0]}get(e,t=this._root,n=this.iterationType){var i,r;if(this._isMapMode){let s=this._extractKey(e);return s==null||(i=this._store.get(s))==null?void 0:i.value}return(r=this.getNode(e,t,n))==null?void 0:r.value}has(e,t=this._root,n=this.iterationType){if(this._isMapMode&&e!==void 0&&e!==null&&!this._isPredicate(e)){let i=this._extractKey(e);return i==null?!1:this._store.has(i)}return this.search(e,!0,i=>i,t,n).length>0}clear(){this._clearNodes(),this._isMapMode&&this._clearValues()}isEmpty(){return this._size===0}isPerfectlyBalanced(e=this._root){return this.getMinHeight(e)+1>=this.getHeight(e)}isBST(e=this._root,t=this.iterationType){let n=this.ensureNode(e);if(!n)return!0;if(t==="RECURSIVE"){let i=(d,l,u)=>{if(!this.isRealNode(d))return!0;let f=Number(d.key);return f<=l||f>=u?!1:i(d.left,l,f)&&i(d.right,f,u)},r=i(n,Number.MIN_SAFE_INTEGER,Number.MAX_SAFE_INTEGER),s=i(n,Number.MAX_SAFE_INTEGER,Number.MIN_SAFE_INTEGER);return r||s}else{let i=(d=!1)=>{let l=[],u=d?Number.MAX_SAFE_INTEGER:Number.MIN_SAFE_INTEGER,f=n;for(;this.isRealNode(f)||l.length>0;){for(;this.isRealNode(f);)l.push(f),f=f.left;f=l.pop();let h=Number(f.key);if(!this.isRealNode(f)||!d&&u>=h||d&&u<=h)return!1;u=h,f=f.right}return!0},r=i(),s=i(!0);return r||s}}getDepth(e,t=this._root){let n=this.ensureNode(e),i=this.ensureNode(t),r=0;for(;n!=null&&n.parent;){if(n===i)return r;r++,n=n.parent}return r}getHeight(e=this._root,t=this.iterationType){if(e=this.ensureNode(e),!this.isRealNode(e))return-1;if(t==="RECURSIVE"){let n=i=>{if(!this.isRealNode(i))return-1;let r=n(i.left),s=n(i.right);return Math.max(r,s)+1};return n(e)}else{let n=[{node:e,depth:0}],i=0;for(;n.length>0;){let{node:r,depth:s}=n.pop();this.isRealNode(r.left)&&n.push({node:r.left,depth:s+1}),this.isRealNode(r.right)&&n.push({node:r.right,depth:s+1}),i=Math.max(i,s)}return i}}getMinHeight(e=this._root,t=this.iterationType){if(e=this.ensureNode(e),!e)return-1;if(t==="RECURSIVE"){let n=i=>{if(!this.isRealNode(i)||!this.isRealNode(i.left)&&!this.isRealNode(i.right))return 0;let r=n(i.left),s=n(i.right);return Math.min(r,s)+1};return n(e)}else{let n=[],i=e,r=null,s=new Map;for(;n.length>0||i;)if(this.isRealNode(i))n.push(i),i=i.left;else if(i=n[n.length-1],!this.isRealNode(i.right)||r===i.right){if(i=n.pop(),this.isRealNode(i)){let d=this.isRealNode(i.left)?s.get(i.left):-1,l=this.isRealNode(i.right)?s.get(i.right):-1;s.set(i,1+Math.min(d,l)),r=i,i=null}}else i=i.right;return s.get(e)}}getPathToRoot(e,t=this._DEFAULT_NODE_CALLBACK,n=!1){let i=[],r=this.ensureNode(e);if(!r)return i;for(;r.parent;)i.push(t(r)),r=r.parent;return i.push(t(r)),n?i.reverse():i}getLeftMost(e=this._DEFAULT_NODE_CALLBACK,t=this._root,n=this.iterationType){if(this.isNIL(t))return e(void 0);let i=this.ensureNode(t);if(!this.isRealNode(i))return e(void 0);if(n==="RECURSIVE"){let r=s=>{let{left:d}=s;return this.isRealNode(d)?r(d):s};return e(r(i))}else{let r=F(s=>{let{left:d}=s;return this.isRealNode(d)?D(()=>r(d)):s});return e(r(i))}}getRightMost(e=this._DEFAULT_NODE_CALLBACK,t=this._root,n=this.iterationType){if(this.isNIL(t)||(t=this.ensureNode(t),!t))return e(void 0);if(n==="RECURSIVE"){let i=r=>{let{right:s}=r;return this.isRealNode(s)?i(s):r};return e(i(t))}else{let i=F(r=>{let{right:s}=r;return this.isRealNode(s)?D(()=>i(s)):r});return e(i(t))}}getPredecessor(e){if(this.isRealNode(e.left)){let t=e.left;for(;!this.isRealNode(t)||this.isRealNode(t.right)&&t.right!==e;)this.isRealNode(t)&&(t=t.right);return t}else return e}getSuccessor(e){if(e=this.ensureNode(e),!this.isRealNode(e))return;if(this.isRealNode(e.right))return this.getLeftMost(n=>n,e.right);let t=e.parent;for(;this.isRealNode(t)&&e===t.right;)e=t,t=t.parent;return t}dfs(e=this._DEFAULT_NODE_CALLBACK,t="IN",n=!1,i=this._root,r=this.iterationType,s=!1){return i=this.ensureNode(i),i?this._dfs(e,t,n,i,r,s):[]}bfs(e=this._DEFAULT_NODE_CALLBACK,t=this._root,n=this.iterationType,i=!1){if(t=this.ensureNode(t),!t)return[];let r=[];if(n==="RECURSIVE"){let s=new g([t]),d=l=>{if(s.length===0)return;let u=s.shift();r.push(e(u)),i?(u&&this.isRealNodeOrNull(u.left)&&s.push(u.left),u&&this.isRealNodeOrNull(u.right)&&s.push(u.right)):(this.isRealNode(u.left)&&s.push(u.left),this.isRealNode(u.right)&&s.push(u.right)),d(l+1)};d(0)}else{let s=new g([t]);for(;s.length>0;){let d=s.length;for(let l=0;l<d;l++){let u=s.shift();r.push(e(u)),i?(u&&this.isRealNodeOrNull(u.left)&&s.push(u.left),u&&this.isRealNodeOrNull(u.right)&&s.push(u.right)):(this.isRealNode(u.left)&&s.push(u.left),this.isRealNode(u.right)&&s.push(u.right))}}}return r}leaves(e=this._DEFAULT_NODE_CALLBACK,t=this._root,n=this.iterationType){t=this.ensureNode(t);let i=[];if(!this.isRealNode(t))return[];if(n==="RECURSIVE"){let r=s=>{this.isLeaf(s)&&i.push(e(s)),!(!this.isRealNode(s.left)&&!this.isRealNode(s.right))&&(this.isRealNode(s.left)&&r(s.left),this.isRealNode(s.right)&&r(s.right))};r(t)}else{let r=new g([t]);for(;r.length>0;){let s=r.shift();this.isRealNode(s)&&(this.isLeaf(s)&&i.push(e(s)),this.isRealNode(s.left)&&r.push(s.left),this.isRealNode(s.right)&&r.push(s.right))}}return i}listLevels(e=this._DEFAULT_NODE_CALLBACK,t=this._root,n=this.iterationType,i=!1){t=this.ensureNode(t);let r=[];if(!t)return r;if(n==="RECURSIVE"){let s=(d,l)=>{r[l]||(r[l]=[]),r[l].push(e(d)),i?(d&&this.isRealNodeOrNull(d.left)&&s(d.left,l+1),d&&this.isRealNodeOrNull(d.right)&&s(d.right,l+1)):(d&&d.left&&s(d.left,l+1),d&&d.right&&s(d.right,l+1))};s(t,0)}else{let s=[[t,0]];for(;s.length>0;){let d=s.pop(),[l,u]=d;r[u]||(r[u]=[]),r[u].push(e(l)),i?(l&&this.isRealNodeOrNull(l.right)&&s.push([l.right,u+1]),l&&this.isRealNodeOrNull(l.left)&&s.push([l.left,u+1])):(l&&l.right&&s.push([l.right,u+1]),l&&l.left&&s.push([l.left,u+1]))}}return r}morris(e=this._DEFAULT_NODE_CALLBACK,t="IN",n=this._root){if(n=this.ensureNode(n),!n)return[];let i=[],r=n,s=l=>{let u=null,f=null;for(;l;)f=l.right,l.right=u,u=l,l=f;return u},d=l=>{let u=s(l),f=u;for(;f;)i.push(e(f)),f=f.right;s(u)};switch(t){case"IN":for(;r;){if(r.left){let l=this.getPredecessor(r);if(l.right)l.right=null;else{l.right=r,r=r.left;continue}}i.push(e(r)),r=r.right}break;case"PRE":for(;r;){if(r.left){let l=this.getPredecessor(r);if(l.right)l.right=null;else{l.right=r,i.push(e(r)),r=r.left;continue}}else i.push(e(r));r=r.right}break;case"POST":for(;r;){if(r.left){let l=this.getPredecessor(r);if(l.right===null){l.right=r,r=r.left;continue}else l.right=null,d(r.left)}r=r.right}d(n);break}return i}clone(){let e=this._createInstance();return this._clone(e),e}filter(e,t){let n=this._createInstance(),i=0;for(let[r,s]of this)e.call(t,s,r,i++,this)&&n.set([r,s]);return n}map(e,t,n){let i=this._createLike([],t),r=0;for(let[s,d]of this)i.set(e.call(n,d,s,r++,this));return i}toVisual(e=this._root,t){let n={isShowUndefined:!1,isShowNull:!0,isShowRedBlackNIL:!1,...t};e=this.ensureNode(e);let i="";return e&&(n.isShowUndefined&&(i+=`U for undefined
2
2
  `),n.isShowNull&&(i+=`N for null
3
3
  `),n.isShowRedBlackNIL&&(i+=`S for Sentinel Node(NIL)
4
4
  `),(s=>{let[d]=this._displayAux(s,n),l="";for(let u of d)l+=u+`