avl-tree-typed 2.1.1 → 2.1.2
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 +3859 -0
- package/dist/cjs/index.cjs.map +1 -0
- package/dist/esm/index.mjs +3852 -0
- package/dist/esm/index.mjs.map +1 -0
- package/dist/types/data-structures/base/index.d.ts +2 -1
- package/dist/types/data-structures/binary-tree/avl-tree-counter.d.ts +182 -2
- package/dist/types/data-structures/binary-tree/avl-tree-multi-map.d.ts +135 -2
- package/dist/types/data-structures/binary-tree/avl-tree.d.ts +291 -2
- package/dist/types/data-structures/binary-tree/binary-indexed-tree.d.ts +174 -1
- package/dist/types/data-structures/binary-tree/binary-tree.d.ts +754 -29
- package/dist/types/data-structures/binary-tree/bst.d.ts +413 -12
- package/dist/types/data-structures/binary-tree/index.d.ts +3 -2
- package/dist/types/data-structures/binary-tree/red-black-tree.d.ts +208 -3
- package/dist/types/data-structures/binary-tree/segment-tree.d.ts +160 -1
- package/dist/types/data-structures/binary-tree/tree-counter.d.ts +190 -2
- package/dist/types/data-structures/binary-tree/tree-multi-map.d.ts +270 -2
- package/dist/types/data-structures/graph/abstract-graph.d.ts +340 -14
- package/dist/types/data-structures/graph/directed-graph.d.ts +207 -1
- package/dist/types/data-structures/graph/index.d.ts +2 -1
- package/dist/types/data-structures/graph/map-graph.d.ts +78 -1
- package/dist/types/data-structures/graph/undirected-graph.d.ts +188 -1
- package/dist/types/data-structures/hash/hash-map.d.ts +345 -19
- package/dist/types/data-structures/hash/index.d.ts +0 -1
- package/dist/types/data-structures/heap/heap.d.ts +503 -5
- package/dist/types/data-structures/heap/index.d.ts +2 -0
- package/dist/types/data-structures/heap/max-heap.d.ts +32 -1
- package/dist/types/data-structures/heap/min-heap.d.ts +33 -1
- package/dist/types/data-structures/index.d.ts +7 -7
- package/dist/types/data-structures/linked-list/doubly-linked-list.d.ts +769 -2
- package/dist/types/data-structures/linked-list/singly-linked-list.d.ts +451 -2
- package/dist/types/data-structures/linked-list/skip-linked-list.d.ts +27 -4
- package/dist/types/data-structures/matrix/index.d.ts +1 -1
- package/dist/types/data-structures/matrix/matrix.d.ts +168 -7
- package/dist/types/data-structures/matrix/navigator.d.ts +54 -13
- package/dist/types/data-structures/priority-queue/max-priority-queue.d.ts +27 -1
- package/dist/types/data-structures/priority-queue/min-priority-queue.d.ts +26 -1
- package/dist/types/data-structures/priority-queue/priority-queue.d.ts +15 -2
- package/dist/types/data-structures/queue/deque.d.ts +431 -4
- package/dist/types/data-structures/queue/queue.d.ts +308 -4
- package/dist/types/data-structures/stack/stack.d.ts +306 -2
- package/dist/types/data-structures/tree/tree.d.ts +62 -1
- package/dist/types/data-structures/trie/trie.d.ts +350 -4
- package/dist/types/index.d.ts +15 -3
- package/dist/{interfaces → types/interfaces}/binary-tree.d.ts +1 -1
- package/dist/types/types/data-structures/base/index.d.ts +1 -0
- package/dist/types/types/data-structures/binary-tree/avl-tree-counter.d.ts +2 -0
- package/dist/types/types/data-structures/binary-tree/avl-tree-multi-map.d.ts +2 -0
- package/dist/types/types/data-structures/binary-tree/avl-tree.d.ts +2 -0
- package/dist/types/types/data-structures/binary-tree/binary-indexed-tree.d.ts +1 -0
- package/dist/types/types/data-structures/binary-tree/binary-tree.d.ts +29 -0
- package/dist/types/types/data-structures/binary-tree/bst.d.ts +12 -0
- package/dist/{data-structures → types/types/data-structures}/binary-tree/index.d.ts +2 -3
- package/dist/types/types/data-structures/binary-tree/red-black-tree.d.ts +3 -0
- package/dist/types/types/data-structures/binary-tree/segment-tree.d.ts +1 -0
- package/dist/types/types/data-structures/binary-tree/tree-counter.d.ts +2 -0
- package/dist/types/types/data-structures/binary-tree/tree-multi-map.d.ts +2 -0
- package/dist/types/types/data-structures/graph/abstract-graph.d.ts +14 -0
- package/dist/types/types/data-structures/graph/directed-graph.d.ts +1 -0
- package/dist/{data-structures → types/types/data-structures}/graph/index.d.ts +1 -2
- package/dist/types/types/data-structures/graph/map-graph.d.ts +1 -0
- package/dist/types/types/data-structures/graph/undirected-graph.d.ts +1 -0
- package/dist/types/types/data-structures/hash/hash-map.d.ts +19 -0
- package/dist/types/types/data-structures/hash/index.d.ts +2 -0
- package/dist/types/types/data-structures/heap/heap.d.ts +5 -0
- package/dist/types/types/data-structures/heap/index.d.ts +1 -0
- package/dist/types/types/data-structures/heap/max-heap.d.ts +1 -0
- package/dist/types/types/data-structures/heap/min-heap.d.ts +1 -0
- package/dist/types/types/data-structures/linked-list/doubly-linked-list.d.ts +2 -0
- package/dist/types/types/data-structures/linked-list/singly-linked-list.d.ts +2 -0
- package/dist/types/types/data-structures/linked-list/skip-linked-list.d.ts +4 -0
- package/dist/types/types/data-structures/matrix/matrix.d.ts +7 -0
- package/dist/types/types/data-structures/matrix/navigator.d.ts +14 -0
- package/dist/types/types/data-structures/priority-queue/max-priority-queue.d.ts +1 -0
- package/dist/types/types/data-structures/priority-queue/min-priority-queue.d.ts +1 -0
- package/dist/types/types/data-structures/priority-queue/priority-queue.d.ts +2 -0
- package/dist/types/types/data-structures/queue/deque.d.ts +4 -0
- package/dist/types/types/data-structures/queue/queue.d.ts +4 -0
- package/dist/types/types/data-structures/stack/stack.d.ts +2 -0
- package/dist/types/types/data-structures/tree/tree.d.ts +1 -0
- package/dist/types/types/data-structures/trie/trie.d.ts +4 -0
- package/dist/types/types/index.d.ts +3 -0
- package/dist/types/types/utils/index.d.ts +2 -0
- package/dist/types/types/utils/utils.d.ts +22 -0
- package/dist/types/utils/index.d.ts +1 -1
- package/dist/types/utils/utils.d.ts +209 -22
- package/dist/umd/avl-tree-typed.js +3852 -0
- package/dist/umd/avl-tree-typed.js.map +1 -0
- package/dist/umd/avl-tree-typed.min.js +13 -0
- package/dist/umd/avl-tree-typed.min.js.map +1 -0
- package/package.json +25 -5
- package/src/data-structures/binary-tree/avl-tree-counter.ts +4 -4
- package/src/data-structures/binary-tree/avl-tree-multi-map.ts +1 -1
- package/src/data-structures/binary-tree/avl-tree.ts +2 -2
- package/src/data-structures/binary-tree/binary-tree.ts +4 -4
- package/src/data-structures/binary-tree/bst.ts +1 -1
- package/src/data-structures/binary-tree/red-black-tree.ts +2 -2
- package/src/data-structures/binary-tree/tree-counter.ts +4 -4
- package/src/data-structures/binary-tree/tree-multi-map.ts +1 -1
- package/src/data-structures/heap/heap.ts +5 -5
- package/src/data-structures/linked-list/singly-linked-list.ts +2 -2
- package/src/interfaces/binary-tree.ts +1 -1
- package/tsconfig.base.json +23 -0
- package/tsconfig.json +8 -34
- package/tsconfig.test.json +8 -0
- package/tsconfig.types.json +15 -0
- package/tsup.config.js +28 -0
- package/tsup.node.config.js +37 -0
- package/dist/common/index.js +0 -28
- package/dist/constants/index.js +0 -8
- package/dist/data-structures/base/index.d.ts +0 -2
- package/dist/data-structures/base/index.js +0 -18
- package/dist/data-structures/base/iterable-element-base.js +0 -243
- package/dist/data-structures/base/iterable-entry-base.js +0 -183
- package/dist/data-structures/base/linear-base.js +0 -415
- package/dist/data-structures/binary-tree/avl-tree-counter.d.ts +0 -182
- package/dist/data-structures/binary-tree/avl-tree-counter.js +0 -374
- package/dist/data-structures/binary-tree/avl-tree-multi-map.d.ts +0 -135
- package/dist/data-structures/binary-tree/avl-tree-multi-map.js +0 -250
- package/dist/data-structures/binary-tree/avl-tree.d.ts +0 -291
- package/dist/data-structures/binary-tree/avl-tree.js +0 -611
- package/dist/data-structures/binary-tree/binary-indexed-tree.d.ts +0 -174
- package/dist/data-structures/binary-tree/binary-indexed-tree.js +0 -294
- package/dist/data-structures/binary-tree/binary-tree.d.ts +0 -754
- package/dist/data-structures/binary-tree/binary-tree.js +0 -1925
- package/dist/data-structures/binary-tree/bst.d.ts +0 -413
- package/dist/data-structures/binary-tree/bst.js +0 -903
- package/dist/data-structures/binary-tree/index.js +0 -26
- package/dist/data-structures/binary-tree/red-black-tree.d.ts +0 -208
- package/dist/data-structures/binary-tree/red-black-tree.js +0 -546
- package/dist/data-structures/binary-tree/segment-tree.d.ts +0 -160
- package/dist/data-structures/binary-tree/segment-tree.js +0 -297
- package/dist/data-structures/binary-tree/tree-counter.d.ts +0 -190
- package/dist/data-structures/binary-tree/tree-counter.js +0 -413
- package/dist/data-structures/binary-tree/tree-multi-map.d.ts +0 -270
- package/dist/data-structures/binary-tree/tree-multi-map.js +0 -384
- package/dist/data-structures/graph/abstract-graph.d.ts +0 -340
- package/dist/data-structures/graph/abstract-graph.js +0 -896
- package/dist/data-structures/graph/directed-graph.d.ts +0 -207
- package/dist/data-structures/graph/directed-graph.js +0 -525
- package/dist/data-structures/graph/index.js +0 -20
- package/dist/data-structures/graph/map-graph.d.ts +0 -78
- package/dist/data-structures/graph/map-graph.js +0 -107
- package/dist/data-structures/graph/undirected-graph.d.ts +0 -188
- package/dist/data-structures/graph/undirected-graph.js +0 -424
- package/dist/data-structures/hash/hash-map.d.ts +0 -345
- package/dist/data-structures/hash/hash-map.js +0 -692
- package/dist/data-structures/hash/index.d.ts +0 -1
- package/dist/data-structures/hash/index.js +0 -17
- package/dist/data-structures/heap/heap.d.ts +0 -503
- package/dist/data-structures/heap/heap.js +0 -901
- package/dist/data-structures/heap/index.d.ts +0 -3
- package/dist/data-structures/heap/index.js +0 -19
- package/dist/data-structures/heap/max-heap.d.ts +0 -32
- package/dist/data-structures/heap/max-heap.js +0 -40
- package/dist/data-structures/heap/min-heap.d.ts +0 -33
- package/dist/data-structures/heap/min-heap.js +0 -31
- package/dist/data-structures/index.js +0 -28
- package/dist/data-structures/linked-list/doubly-linked-list.d.ts +0 -769
- package/dist/data-structures/linked-list/doubly-linked-list.js +0 -1111
- package/dist/data-structures/linked-list/index.js +0 -19
- package/dist/data-structures/linked-list/singly-linked-list.d.ts +0 -451
- package/dist/data-structures/linked-list/singly-linked-list.js +0 -850
- package/dist/data-structures/linked-list/skip-linked-list.d.ts +0 -27
- package/dist/data-structures/linked-list/skip-linked-list.js +0 -144
- package/dist/data-structures/matrix/index.js +0 -18
- package/dist/data-structures/matrix/matrix.d.ts +0 -168
- package/dist/data-structures/matrix/matrix.js +0 -448
- package/dist/data-structures/matrix/navigator.d.ts +0 -55
- package/dist/data-structures/matrix/navigator.js +0 -111
- package/dist/data-structures/priority-queue/index.js +0 -19
- package/dist/data-structures/priority-queue/max-priority-queue.d.ts +0 -27
- package/dist/data-structures/priority-queue/max-priority-queue.js +0 -34
- package/dist/data-structures/priority-queue/min-priority-queue.d.ts +0 -26
- package/dist/data-structures/priority-queue/min-priority-queue.js +0 -24
- package/dist/data-structures/priority-queue/priority-queue.d.ts +0 -15
- package/dist/data-structures/priority-queue/priority-queue.js +0 -20
- package/dist/data-structures/queue/deque.d.ts +0 -431
- package/dist/data-structures/queue/deque.js +0 -879
- package/dist/data-structures/queue/index.js +0 -18
- package/dist/data-structures/queue/queue.d.ts +0 -308
- package/dist/data-structures/queue/queue.js +0 -473
- package/dist/data-structures/stack/index.js +0 -17
- package/dist/data-structures/stack/stack.d.ts +0 -306
- package/dist/data-structures/stack/stack.js +0 -401
- package/dist/data-structures/tree/index.js +0 -17
- package/dist/data-structures/tree/tree.d.ts +0 -62
- package/dist/data-structures/tree/tree.js +0 -107
- package/dist/data-structures/trie/index.js +0 -17
- package/dist/data-structures/trie/trie.d.ts +0 -350
- package/dist/data-structures/trie/trie.js +0 -610
- package/dist/index.d.ts +0 -15
- package/dist/index.js +0 -31
- package/dist/interfaces/binary-tree.js +0 -2
- package/dist/interfaces/doubly-linked-list.js +0 -2
- package/dist/interfaces/graph.js +0 -2
- package/dist/interfaces/heap.js +0 -2
- package/dist/interfaces/index.js +0 -24
- package/dist/interfaces/navigator.js +0 -2
- package/dist/interfaces/priority-queue.js +0 -2
- package/dist/interfaces/segment-tree.js +0 -2
- package/dist/interfaces/singly-linked-list.js +0 -2
- package/dist/types/common.js +0 -2
- package/dist/types/data-structures/base/base.js +0 -2
- package/dist/types/data-structures/base/index.js +0 -17
- package/dist/types/data-structures/binary-tree/avl-tree-counter.js +0 -2
- package/dist/types/data-structures/binary-tree/avl-tree-multi-map.js +0 -2
- package/dist/types/data-structures/binary-tree/avl-tree.js +0 -2
- package/dist/types/data-structures/binary-tree/binary-indexed-tree.js +0 -2
- package/dist/types/data-structures/binary-tree/binary-tree.js +0 -2
- package/dist/types/data-structures/binary-tree/bst.js +0 -2
- package/dist/types/data-structures/binary-tree/index.js +0 -25
- package/dist/types/data-structures/binary-tree/red-black-tree.js +0 -2
- package/dist/types/data-structures/binary-tree/segment-tree.js +0 -2
- package/dist/types/data-structures/binary-tree/tree-counter.js +0 -2
- package/dist/types/data-structures/binary-tree/tree-multi-map.js +0 -2
- package/dist/types/data-structures/graph/abstract-graph.js +0 -2
- package/dist/types/data-structures/graph/directed-graph.js +0 -2
- package/dist/types/data-structures/graph/index.js +0 -19
- package/dist/types/data-structures/graph/map-graph.js +0 -2
- package/dist/types/data-structures/graph/undirected-graph.js +0 -2
- package/dist/types/data-structures/hash/hash-map.js +0 -2
- package/dist/types/data-structures/hash/index.js +0 -17
- package/dist/types/data-structures/heap/heap.js +0 -2
- package/dist/types/data-structures/heap/index.js +0 -17
- package/dist/types/data-structures/heap/max-heap.js +0 -2
- package/dist/types/data-structures/heap/min-heap.js +0 -2
- package/dist/types/data-structures/index.js +0 -28
- package/dist/types/data-structures/linked-list/doubly-linked-list.js +0 -2
- package/dist/types/data-structures/linked-list/index.js +0 -19
- package/dist/types/data-structures/linked-list/singly-linked-list.js +0 -2
- package/dist/types/data-structures/linked-list/skip-linked-list.js +0 -2
- package/dist/types/data-structures/matrix/index.js +0 -18
- package/dist/types/data-structures/matrix/matrix.js +0 -2
- package/dist/types/data-structures/matrix/navigator.js +0 -2
- package/dist/types/data-structures/priority-queue/index.js +0 -19
- package/dist/types/data-structures/priority-queue/max-priority-queue.js +0 -2
- package/dist/types/data-structures/priority-queue/min-priority-queue.js +0 -2
- package/dist/types/data-structures/priority-queue/priority-queue.js +0 -2
- package/dist/types/data-structures/queue/deque.js +0 -2
- package/dist/types/data-structures/queue/index.js +0 -18
- package/dist/types/data-structures/queue/queue.js +0 -2
- package/dist/types/data-structures/stack/index.js +0 -17
- package/dist/types/data-structures/stack/stack.js +0 -2
- package/dist/types/data-structures/tree/index.js +0 -17
- package/dist/types/data-structures/tree/tree.js +0 -2
- package/dist/types/data-structures/trie/index.js +0 -17
- package/dist/types/data-structures/trie/trie.js +0 -2
- package/dist/types/index.js +0 -19
- package/dist/types/utils/index.js +0 -18
- package/dist/types/utils/utils.js +0 -2
- package/dist/types/utils/validate-type.js +0 -2
- package/dist/utils/index.d.ts +0 -2
- package/dist/utils/index.js +0 -18
- package/dist/utils/number.js +0 -23
- package/dist/utils/utils.d.ts +0 -209
- package/dist/utils/utils.js +0 -353
- package/dist/{common → types/common}/index.d.ts +0 -0
- package/dist/{constants → types/constants}/index.d.ts +0 -0
- package/dist/{data-structures → types/data-structures}/base/iterable-element-base.d.ts +0 -0
- package/dist/{data-structures → types/data-structures}/base/iterable-entry-base.d.ts +0 -0
- package/dist/{data-structures → types/data-structures}/base/linear-base.d.ts +0 -0
- package/dist/{interfaces → types/interfaces}/doubly-linked-list.d.ts +0 -0
- package/dist/{interfaces → types/interfaces}/graph.d.ts +0 -0
- package/dist/{interfaces → types/interfaces}/heap.d.ts +0 -0
- package/dist/{interfaces → types/interfaces}/index.d.ts +0 -0
- package/dist/{interfaces → types/interfaces}/navigator.d.ts +0 -0
- package/dist/{interfaces → types/interfaces}/priority-queue.d.ts +0 -0
- package/dist/{interfaces → types/interfaces}/segment-tree.d.ts +0 -0
- package/dist/{interfaces → types/interfaces}/singly-linked-list.d.ts +0 -0
- package/dist/types/{common.d.ts → types/common.d.ts} +0 -0
- package/dist/types/{data-structures → types/data-structures}/base/base.d.ts +0 -0
- package/dist/{data-structures → types/types/data-structures}/index.d.ts +7 -7
- package/dist/{data-structures → types/types/data-structures}/linked-list/index.d.ts +0 -0
- package/dist/{data-structures → types/types/data-structures}/matrix/index.d.ts +1 -1
- /package/dist/{data-structures → types/types/data-structures}/priority-queue/index.d.ts +0 -0
- /package/dist/{data-structures → types/types/data-structures}/queue/index.d.ts +0 -0
- /package/dist/{data-structures → types/types/data-structures}/stack/index.d.ts +0 -0
- /package/dist/{data-structures → types/types/data-structures}/tree/index.d.ts +0 -0
- /package/dist/{data-structures → types/types/data-structures}/trie/index.d.ts +0 -0
- /package/dist/types/{utils → types/utils}/validate-type.d.ts +0 -0
- /package/dist/{utils → types/utils}/number.d.ts +0 -0
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";var avlTreeTyped=(()=>{var S=Object.defineProperty;var j=Object.getOwnPropertyDescriptor;var G=Object.getOwnPropertyNames;var q=Object.prototype.hasOwnProperty;var W=(h,s,e)=>s in h?S(h,s,{enumerable:!0,configurable:!0,writable:!0,value:e}):h[s]=e;var X=(h,s)=>{for(var e in s)S(h,e,{get:s[e],enumerable:!0})},J=(h,s,e,t)=>{if(s&&typeof s=="object"||typeof s=="function")for(let n of G(s))!q.call(h,n)&&n!==e&&S(h,n,{get:()=>s[n],enumerable:!(t=j(s,n))||t.enumerable});return h};var Y=h=>J(S({},"__esModule",{value:!0}),h);var T=(h,s,e)=>W(h,typeof s!="symbol"?s+"":s,e);var ee={};X(ee,{AVLTree:()=>P,AVLTreeNode:()=>k,BST:()=>L,BSTNode:()=>B,BinaryTree:()=>I,BinaryTreeNode:()=>_});function A(h){let s=typeof h;return s==="number"?!0:s==="bigint"||s==="string"||s==="boolean"}function H(h){if(typeof h.valueOf=="function"){let s=h.valueOf();if(s!==h){if(A(s))return s;if(typeof s=="object"&&s!==null)return H(s)}}if(typeof h.toString=="function"){let s=h.toString();if(s!=="[object Object]")return s}return null}function g(h,s=!1){if(h==null)return!1;if(A(h))return!0;if(typeof h!="object")return!1;if(h instanceof Date||s)return!0;let e=H(h);return e==null?!1:A(e)}var D=h=>({isThunk:!0,fn:h}),Z=h=>typeof h=="object"&&h!==null&&"isThunk"in h&&h.isThunk;function $(h){let s=h;for(;Z(s);)s=s.fn();return s}function F(h){return(...s)=>$(h(...s))}var x=class{constructor(s){T(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 v=class h extends x{constructor(e){super(e);T(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 h?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 o=this.deleteAt(e);o!==void 0&&i.push(o)}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 m=class h extends v{constructor(e=[],t){super(t);T(this,"_elements",[]);T(this,"_offset",0);T(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 h(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 o=this._createInstance({toElementFn:this.toElementFn,maxLen:this._maxLen});return o._setAutoCompactRatio(this._autoCompactRatio),o.pushMany(r),o}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 o,l;let i=new this.constructor([],{toElementFn:t==null?void 0:t.toElementFn,maxLen:(o=t==null?void 0:t.maxLen)!=null?o:this._maxLen,autoCompactRatio:(l=t==null?void 0:t.autoCompactRatio)!=null?l:this._autoCompactRatio}),r=0;for(let d of this)i.push(n===void 0?e(d,r++,this):e.call(n,d,r++,this));return i}mapSame(e,t){var o;let n=this.constructor,i=new n([],{toElementFn:this.toElementFn,maxLen:this._maxLen,autoCompactRatio:this._autoCompactRatio});(o=i._setAutoCompactRatio)==null||o.call(i,this._autoCompactRatio);let r=0;for(let l of this){let d=t===void 0?e(l,r++,this):e.call(t,l,r++,this);i.push(d)}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 w=class{*[Symbol.iterator](...s){yield*this._getIterator(...s)}*entries(){for(let s of this)yield s}*keys(){for(let s of this)yield s[0]}*values(){for(let s of this)yield s[1]}every(s,e){let t=0;for(let n of this)if(!s.call(e,n[0],n[1],t++,this))return!1;return!0}some(s,e){let t=0;for(let n of this)if(s.call(e,n[0],n[1],t++,this))return!0;return!1}forEach(s,e){let t=0;for(let n of this){let[i,r]=n;s.call(e,i,r,t++,this)}}find(s,e){let t=0;for(let n of this){let[i,r]=n;if(s.call(e,i,r,t++,this))return n}}has(s){for(let e of this){let[t]=e;if(t===s)return!0}return!1}hasValue(s){for(let[,e]of this)if(e===s)return!0;return!1}get(s){for(let e of this){let[t,n]=e;if(t===s)return n}}reduce(s,e){let t=e,n=0;for(let i of this){let[r,o]=i;t=s(t,o,r,n++,this)}return t}toVisual(){return[...this]}print(){console.log(this.toVisual())}};var b=class{constructor(s,e,t=!0,n=!0){this.low=s;this.high=e;this.includeLow=t;this.includeHigh=n;if(!(g(s)&&g(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}};var _=class{constructor(s,e){T(this,"key");T(this,"value");T(this,"parent");T(this,"_left");T(this,"_right");T(this,"_height",0);T(this,"_color","BLACK");T(this,"_count",1);this.key=s,this.value=e}get left(){return this._left}set left(s){s&&(s.parent=this),this._left=s}get right(){return this._right}set right(s){s&&(s.parent=this),this._right=s}get height(){return this._height}set height(s){this._height=s}get color(){return this._color}set color(s){this._color=s}get count(){return this._count}set count(s){this._count=s}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"}},I=class extends w{constructor(e=[],t){super();T(this,"iterationType","ITERATIVE");T(this,"_isMapMode",!0);T(this,"_isDuplicate",!1);T(this,"_store",new Map);T(this,"_root");T(this,"_size",0);T(this,"_NIL",new _(NaN));T(this,"_toEntryFn");T(this,"_DEFAULT_NODE_CALLBACK",e=>e?e.key:void 0);if(t){let{iterationType:n,toEntryFn:i,isMapMode:r,isDuplicate:o}=t;if(n&&(this.iterationType=n),r!==void 0&&(this._isMapMode=r),o!==void 0&&(this._isDuplicate=o),typeof i=="function")this._toEntryFn=i;else if(i)throw TypeError("toEntryFn must be a function type")}e&&this.addMany(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 _(e,this._isMapMode?void 0: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 _}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 b}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:g(e)}add(e,t){let[n,i]=this._keyValueNodeOrEntryToNodeAndValue(e,t);if(n===void 0)return!1;if(!this._root)return this._setRoot(n),this._isMapMode&&this._setValue(n==null?void 0:n.key,i),this._size=1,!0;let r=new m([this._root]),o;for(;r.length>0;){let l=r.shift();if(l){if(!this._isDuplicate&&n!==null&&l.key===n.key)return this._replaceNode(l,n),this._isMapMode&&this._setValue(l.key,i),!0;o===void 0&&(l.left===void 0||l.right===void 0)&&(o=l),l.left!==null&&l.left&&r.push(l.left),l.right!==null&&l.right&&r.push(l.right)}}return o?(o.left===void 0?o.left=n:o.right===void 0&&(o.right=n),this._isMapMode&&this._setValue(n==null?void 0:n.key,i),this._size++,!0):!1}addMany(e,t){let n=[],i;t&&(i=t[Symbol.iterator]());for(let r of e){let o;if(i){let l=i.next();l.done||(o=l.value)}this.isRaw(r)&&(r=this._toEntryFn(r)),n.push(this.add(r,o))}return n}merge(e){this.addMany(e,[])}refill(e,t){this.clear(),this.addMany(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,o=n;if(!n.left&&!n.right&&!i)this._setRoot(void 0);else if(n.left){let l=this.getRightMost(d=>d,n.left);if(l){let d=l.parent;o=this._swapProperties(n,l),d&&(d.right===l?d.right=l.left:d.left=l.left,r=d)}}else if(i){let{familyPosition:l}=n;l==="LEFT"||l==="ROOT_LEFT"?i.left=n.right:(l==="RIGHT"||l==="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:o,needBalanced:r}),this._isMapMode&&o&&this._store.delete(o.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 o=this._ensurePredicate(e),l=[];if(r==="RECURSIVE"){let d=u=>{o(u)&&(l.push(n(u)),t)||!this.isRealNode(u.left)&&!this.isRealNode(u.right)||(this.isRealNode(u.left)&&d(u.left),this.isRealNode(u.right)&&d(u.right))};d(i)}else{let d=[i];for(;d.length>0;){let u=d.pop();if(this.isRealNode(u)){if(o(u)&&(l.push(n(u)),t))return l;this.isRealNode(u.left)&&d.push(u.left),this.isRealNode(u.right)&&d.push(u.right)}}}return l}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){return this.search(e,!0,i=>i,t,n)[0]}get(e,t=this._root,n=this.iterationType){var i;if(this._isMapMode){let r=this._extractKey(e);return r==null?void 0:this._store.get(r)}return(i=this.getNode(e,t,n))==null?void 0:i.value}has(e,t=this._root,n=this.iterationType){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=(l,d,u)=>{if(!this.isRealNode(l))return!0;let a=Number(l.key);return a<=d||a>=u?!1:i(l.left,d,a)&&i(l.right,a,u)},r=i(n,Number.MIN_SAFE_INTEGER,Number.MAX_SAFE_INTEGER),o=i(n,Number.MAX_SAFE_INTEGER,Number.MIN_SAFE_INTEGER);return r||o}else{let i=(l=!1)=>{let d=[],u=l?Number.MAX_SAFE_INTEGER:Number.MIN_SAFE_INTEGER,a=n;for(;this.isRealNode(a)||d.length>0;){for(;this.isRealNode(a);)d.push(a),a=a.left;a=d.pop();let c=Number(a.key);if(!this.isRealNode(a)||!l&&u>=c||l&&u<=c)return!1;u=c,a=a.right}return!0},r=i(!1),o=i(!0);return r||o}}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),o=n(i.right);return Math.max(r,o)+1};return n(e)}else{let n=[{node:e,depth:0}],i=0;for(;n.length>0;){let{node:r,depth:o}=n.pop();this.isRealNode(r.left)&&n.push({node:r.left,depth:o+1}),this.isRealNode(r.right)&&n.push({node:r.right,depth:o+1}),i=Math.max(i,o)}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),o=n(i.right);return Math.min(r,o)+1};return n(e)}else{let n=[],i=e,r=null,o=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 l=this.isRealNode(i.left)?o.get(i.left):-1,d=this.isRealNode(i.right)?o.get(i.right):-1;o.set(i,1+Math.min(l,d)),r=i,i=null}}else i=i.right;return o.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=o=>{let{left:l}=o;return this.isRealNode(l)?r(l):o};return e(r(i))}else{let r=F(o=>{let{left:l}=o;return this.isRealNode(l)?D(()=>r(l)):o});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:o}=r;return this.isRealNode(o)?i(o):r};return e(i(t))}else{let i=F(r=>{let{right:o}=r;return this.isRealNode(o)?D(()=>i(o)):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,o=!1){return i=this.ensureNode(i),i?this._dfs(e,t,n,i,r,o):[]}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 o=new m([t]),l=d=>{if(o.length===0)return;let u=o.shift();r.push(e(u)),i?(u&&this.isRealNodeOrNull(u.left)&&o.push(u.left),u&&this.isRealNodeOrNull(u.right)&&o.push(u.right)):(this.isRealNode(u.left)&&o.push(u.left),this.isRealNode(u.right)&&o.push(u.right)),l(d+1)};l(0)}else{let o=new m([t]);for(;o.length>0;){let l=o.length;for(let d=0;d<l;d++){let u=o.shift();r.push(e(u)),i?(u&&this.isRealNodeOrNull(u.left)&&o.push(u.left),u&&this.isRealNodeOrNull(u.right)&&o.push(u.right)):(this.isRealNode(u.left)&&o.push(u.left),this.isRealNode(u.right)&&o.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=o=>{this.isLeaf(o)&&i.push(e(o)),!(!this.isRealNode(o.left)&&!this.isRealNode(o.right))&&(this.isRealNode(o.left)&&r(o.left),this.isRealNode(o.right)&&r(o.right))};r(t)}else{let r=new m([t]);for(;r.length>0;){let o=r.shift();this.isRealNode(o)&&(this.isLeaf(o)&&i.push(e(o)),this.isRealNode(o.left)&&r.push(o.left),this.isRealNode(o.right)&&r.push(o.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 o=(l,d)=>{r[d]||(r[d]=[]),r[d].push(e(l)),i?(l&&this.isRealNodeOrNull(l.left)&&o(l.left,d+1),l&&this.isRealNodeOrNull(l.right)&&o(l.right,d+1)):(l&&l.left&&o(l.left,d+1),l&&l.right&&o(l.right,d+1))};o(t,0)}else{let o=[[t,0]];for(;o.length>0;){let l=o.pop(),[d,u]=l;r[u]||(r[u]=[]),r[u].push(e(d)),i?(d&&this.isRealNodeOrNull(d.right)&&o.push([d.right,u+1]),d&&this.isRealNodeOrNull(d.left)&&o.push([d.left,u+1])):(d&&d.right&&o.push([d.right,u+1]),d&&d.left&&o.push([d.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,o=d=>{let u=null,a=null;for(;d;)a=d.right,d.right=u,u=d,d=a;return u},l=d=>{let u=o(d),a=u;for(;a;)i.push(e(a)),a=a.right;o(u)};switch(t){case"IN":for(;r;){if(r.left){let d=this.getPredecessor(r);if(d.right)d.right=null;else{d.right=r,r=r.left;continue}}i.push(e(r)),r=r.right}break;case"PRE":for(;r;){if(r.left){let d=this.getPredecessor(r);if(d.right)d.right=null;else{d.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 d=this.getPredecessor(r);if(d.right===null){d.right=r,r=r.left;continue}else d.right=null,l(r.left)}r=r.right}l(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,o]of this)e.call(t,r,o,i++,this)&&n.add([r,o]);return n}map(e,t,n){let i=this._createLike([],t),r=0;for(let[o,l]of this)i.add(e.call(n,o,l,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
|
+
`),n.isShowNull&&(i+=`N for null
|
|
3
|
+
`),n.isShowRedBlackNIL&&(i+=`S for Sentinel Node(NIL)
|
|
4
|
+
`),(o=>{let[l]=this._displayAux(o,n),d="";for(let u of l)d+=u+`
|
|
5
|
+
`;i+=d})(e)),i}print(e,t=this._root){console.log(this.toVisual(t,e))}_dfs(e=this._DEFAULT_NODE_CALLBACK,t="IN",n=!1,i=this._root,r=this.iterationType,o=!1,l=c=>!!c,d=c=>!!c,u=c=>o?this.isRealNodeOrNull(c):this.isRealNode(c),a=c=>this.isRealNodeOrNull(c)){if(i=this.ensureNode(i),!i)return[];let c=[];if(r==="RECURSIVE"){let p=f=>{if(!u(f))return;let V=()=>{l(f)&&(f==null?void 0:f.left)!==void 0&&p(f==null?void 0:f.left)},y=()=>{d(f)&&(f==null?void 0:f.right)!==void 0&&p(f==null?void 0:f.right)};switch(t){case"IN":if(V(),a(f)&&(c.push(e(f)),n))return;y();break;case"PRE":if(a(f)&&(c.push(e(f)),n))return;V(),y();break;case"POST":if(V(),y(),a(f)&&(c.push(e(f)),n))return;break}};p(i)}else{let p=[{opt:0,node:i}],f=K=>{var N;l(K.node)&&p.push({opt:0,node:(N=K.node)==null?void 0:N.left})},V=K=>{var N;d(K.node)&&p.push({opt:0,node:(N=K.node)==null?void 0:N.right})},y=K=>{u(K.node)&&p.push({opt:1,node:K.node})};for(;p.length>0;){let K=p.pop();if(K!==void 0&&u(K.node))if(K.opt===1){if(a(K.node)&&K.node!==void 0&&(c.push(e(K.node)),n))return c}else switch(t){case"IN":V(K),y(K),f(K);break;case"PRE":V(K),f(K),y(K);break;case"POST":y(K),V(K),f(K);break}}}return c}*_getIterator(e=this._root){if(e)if(this.iterationType==="ITERATIVE"){let t=[],n=e;for(;n||t.length>0;){for(;this.isRealNode(n);)t.push(n),n=n.left;n=t.pop(),this.isRealNode(n)&&(this._isMapMode?yield[n.key,this._store.get(n.key)]:yield[n.key,n.value],n=n.right)}}else e.left&&this.isRealNode(e)&&(yield*this[Symbol.iterator](e.left)),this._isMapMode?yield[e.key,this._store.get(e.key)]:yield[e.key,e.value],e.right&&this.isRealNode(e)&&(yield*this[Symbol.iterator](e.right))}_snapshotOptions(){return{iterationType:this.iterationType,toEntryFn:this.toEntryFn,isMapMode:this.isMapMode,isDuplicate:this.isDuplicate}}_createInstance(e){let t=this.constructor;return new t([],{...this._snapshotOptions(),...e!=null?e:{}})}_createLike(e=[],t){let n=this.constructor;return new n(e,{...this._snapshotOptions(),...t!=null?t:{}})}_keyValueNodeOrEntryToNodeAndValue(e,t){if(e===void 0)return[void 0,void 0];if(e===null)return[null,void 0];if(this.isNode(e))return[e,t];if(this.isEntry(e)){let[n,i]=e;if(n===void 0)return[void 0,void 0];if(n===null)return[null,void 0];let r=t!=null?t:i;return[this.createNode(n,r),r]}return[this.createNode(e,t),t]}_clone(e){this.bfs(t=>{t===null?e.add(null):this._isMapMode?e.add([t.key,this._store.get(t.key)]):e.add([t.key,t.value])},this._root,this.iterationType,!0),this._isMapMode&&(e._store=this._store)}_displayAux(e,t){let{isShowNull:n,isShowUndefined:i,isShowRedBlackNIL:r}=t,o=[["\u2500"],1,0,0];if(e===null&&!n)return o;if(e===void 0&&!i)return o;if(this.isNIL(e)&&!r)return o;if(e!=null){let d=e.key,u=this.isNIL(e)?"S":String(d),a=u.length;return l(u,a,this._displayAux(e.left,t),this._displayAux(e.right,t))}else{let d=e===void 0?"U":"N",u=d.length;return l(d,u,[[""],1,0,0],[[""],1,0,0])}function l(d,u,a,c){let[p,f,V,y]=a,[K,N,R,E]=c,M=" ".repeat(Math.max(0,y+1))+"_".repeat(Math.max(0,f-y-1))+d+"_".repeat(Math.max(0,E))+" ".repeat(Math.max(0,N-E)),O=(V>0?" ".repeat(y)+"/"+" ".repeat(f-y-1):" ".repeat(f))+" ".repeat(u)+(R>0?" ".repeat(E)+"\\"+" ".repeat(N-E-1):" ".repeat(N)),U=[M,O];for(let C=0;C<Math.max(V,R);C++){let z=C<V?p[C]:" ".repeat(f),Q=C<R?K[C]:" ".repeat(N);U.push(z+" ".repeat(u)+Q)}return[U,f+u+N,Math.max(V,R)+2,f+Math.floor(u/2)]}}_swapProperties(e,t){if(e=this.ensureNode(e),t=this.ensureNode(t),e&&t){let{key:n,value:i}=t,r=this.createNode(n,i);return r&&(t.key=e.key,this._isMapMode||(t.value=e.value),e.key=r.key,this._isMapMode||(e.value=r.value)),t}}_replaceNode(e,t){return e.parent&&(e.parent.left===e?e.parent.left=t:e.parent.right===e&&(e.parent.right=t)),t.left=e.left,t.right=e.right,t.parent=e.parent,this._root===e&&this._setRoot(t),t}_setRoot(e){e&&(e.parent=void 0),this._root=e}_ensurePredicate(e){if(e==null)return t=>!1;if(this._isPredicate(e))return e;if(this.isRealNode(e))return t=>t===e;if(this.isEntry(e)){let[t]=e;return n=>n?n.key===t:!1}return t=>t?t.key===e:!1}_isPredicate(e){return typeof e=="function"}_extractKey(e){if(e===null)return null;if(e!==void 0&&e!==this._NIL)return this.isNode(e)?e.key:this.isEntry(e)?e[0]:e}_setValue(e,t){return e==null||t===void 0?!1:this._store.set(e,t)}_clearNodes(){this._setRoot(void 0),this._size=0}_clearValues(){this._store.clear()}};var B=class extends _{constructor(e,t){super(e,t);T(this,"parent");T(this,"_left");T(this,"_right")}get left(){return this._left}set left(e){e&&(e.parent=this),this._left=e}get right(){return this._right}set right(e){e&&(e.parent=this),this._right=e}},L=class extends I{constructor(e=[],t){super([],t);T(this,"_root");T(this,"_isReverse",!1);T(this,"_comparator",(e,t)=>{if(g(e)&&g(t))return e>t?1:e<t?-1:0;if(this._specifyComparable){let n=this._specifyComparable(e),i=this._specifyComparable(t);return n>i?1:n<i?-1:0}if(typeof e=="object"||typeof t=="object")throw TypeError("When comparing object types, a custom specifyComparable must be defined in the constructor's options.");return 0});T(this,"_specifyComparable");if(t){let{specifyComparable:n,isReverse:i}=t;typeof n=="function"&&(this._specifyComparable=n),i!==void 0&&(this._isReverse=i)}e&&this.addMany(e)}get root(){return this._root}get isReverse(){return this._isReverse}get comparator(){return this._comparator}get specifyComparable(){return this._specifyComparable}createNode(e,t){return new B(e,this._isMapMode?void 0:t)}ensureNode(e,t=this.iterationType){var n;return(n=super.ensureNode(e,t))!=null?n:void 0}isNode(e){return e instanceof B}isValidKey(e){return g(e,this._specifyComparable!==void 0)}dfs(e=this._DEFAULT_NODE_CALLBACK,t="IN",n=!1,i=this._root,r=this.iterationType){return super.dfs(e,t,n,i,r)}bfs(e=this._DEFAULT_NODE_CALLBACK,t=this._root,n=this.iterationType){return super.bfs(e,t,n,!1)}listLevels(e=this._DEFAULT_NODE_CALLBACK,t=this._root,n=this.iterationType){return super.listLevels(e,t,n,!1)}getNode(e,t=this._root,n=this.iterationType){var i;return(i=this.getNodes(e,!0,t,n)[0])!=null?i:void 0}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 o,l=this.isRange(e);l?o=a=>a?e.isInRange(a.key,this._comparator):!1:o=this._ensurePredicate(e);let d=a=>{if(!a||!this.isRealNode(a.left))return!1;if(l){let c=e,p=this.isReverse?c.high:c.low,f=this.isReverse?c.includeHigh:c.includeLow;return f&&this._compare(a.key,p)>=0||!f&&this._compare(a.key,p)>0}if(!l&&!this._isPredicate(e)){let c=this._extractKey(e);return c!=null&&this._compare(a.key,c)>0}return!0},u=a=>{if(!a||!this.isRealNode(a.right))return!1;if(l){let c=e,p=this.isReverse?c.low:c.high,f=this.isReverse?c.includeLow:c.includeHigh;return f&&this._compare(a.key,p)<=0||!f&&this._compare(a.key,p)<0}if(!l&&!this._isPredicate(e)){let c=this._extractKey(e);return c!=null&&this._compare(a.key,c)<0}return!0};return super._dfs(n,"IN",t,i,r,!1,d,u,()=>!0,a=>!!a&&o(a))}rangeSearch(e,t=this._DEFAULT_NODE_CALLBACK,n=this._root,i=this.iterationType){let r=e instanceof b?e:new b(e[0],e[1]);return this.search(r,!1,t,n,i)}add(e,t){let[n,i]=this._keyValueNodeOrEntryToNodeAndValue(e,t);if(n===void 0)return!1;if(this._root===void 0)return this._setRoot(n),this._isMapMode&&this._setValue(n==null?void 0:n.key,i),this._size++,!0;let r=this._root;for(;r!==void 0;){if(this._compare(r.key,n.key)===0)return this._replaceNode(r,n),this._isMapMode&&this._setValue(r.key,i),!0;if(this._compare(r.key,n.key)>0){if(r.left===void 0)return r.left=n,this._isMapMode&&this._setValue(n==null?void 0:n.key,i),this._size++,!0;r.left!==null&&(r=r.left)}else{if(r.right===void 0)return r.right=n,this._isMapMode&&this._setValue(n==null?void 0:n.key,i),this._size++,!0;r.right!==null&&(r=r.right)}}return!1}addMany(e,t,n=!0,i=this.iterationType){let r=[],o=t==null?void 0:t[Symbol.iterator]();if(!n){for(let p of e){let f=o==null?void 0:o.next().value;this.isRaw(p)&&(p=this._toEntryFn(p)),r.push(this.add(p,f))}return r}let l=[],d=0;for(let p of e)l.push({key:p,value:o==null?void 0:o.next().value,orgIndex:d++});let u=l.sort(({key:p},{key:f})=>{let V,y;return this.isRaw(p)?V=this._toEntryFn(p)[0]:this.isEntry(p)?V=p[0]:this.isRealNode(p)?V=p.key:V=p,this.isRaw(f)?y=this._toEntryFn(f)[0]:this.isEntry(f)?y=f[0]:this.isRealNode(f)?y=f.key:y=f,V!=null&&y!=null?this._compare(V,y):0}),a=p=>{if(p.length===0)return;let f=Math.floor((p.length-1)/2),{key:V,value:y,orgIndex:K}=p[f];if(this.isRaw(V)){let N=this._toEntryFn(V);r[K]=this.add(N)}else r[K]=this.add(V,y);a(p.slice(0,f)),a(p.slice(f+1))};return i==="RECURSIVE"?a(u):(()=>{let f=[[0,u.length-1]];for(;f.length>0;){let V=f.pop();if(!V)continue;let[y,K]=V;if(y>K)continue;let N=y+Math.floor((K-y)/2),{key:R,value:E,orgIndex:M}=u[N];if(this.isRaw(R)){let O=this._toEntryFn(R);r[M]=this.add(O)}else r[M]=this.add(R,E);f.push([N+1,K]),f.push([y,N-1])}})(),r}lesserOrGreaterTraverse(e=this._DEFAULT_NODE_CALLBACK,t=-1,n=this._root,i=this.iterationType){let r=this.ensureNode(n),o=[];if(!this._root||!r)return o;let l=r.key;if(i==="RECURSIVE"){let d=u=>{let a=this._compare(u.key,l);Math.sign(a)==t&&o.push(e(u)),this.isRealNode(u.left)&&d(u.left),this.isRealNode(u.right)&&d(u.right)};return d(this._root),o}else{let d=new m([this._root]);for(;d.length>0;){let u=d.shift();if(this.isRealNode(u)){let a=this._compare(u.key,l);Math.sign(a)==t&&o.push(e(u)),this.isRealNode(u.left)&&d.push(u.left),this.isRealNode(u.right)&&d.push(u.right)}}return o}}perfectlyBalance(e=this.iterationType){let t=this.dfs(o=>o,"IN",!1,this._root,e),n=t.length;if(this._clearNodes(),n===0)return!1;let i=(o,l,d)=>{if(o>l)return;let u=o+(l-o>>1),a=t[u],c=i(o,u-1,a),p=i(u+1,l,a);return a.left=c,a.right=p,a.parent=d,a},r=i(0,n-1,void 0);return this._setRoot(r),this._size=n,!0}isAVLBalanced(e=this.iterationType){if(!this._root)return!0;let t=!0;if(e==="RECURSIVE"){let n=i=>{if(!i)return 0;let r=n(i.left),o=n(i.right);return Math.abs(r-o)>1&&(t=!1),Math.max(r,o)+1};n(this._root)}else{let n=[],i=this._root,r,o=new Map;for(;n.length>0||i;)if(i)n.push(i),i.left!==null&&(i=i.left);else if(i=n[n.length-1],!i.right||r===i.right){if(i=n.pop(),i){let l=i.left?o.get(i.left):-1,d=i.right?o.get(i.right):-1;if(Math.abs(l-d)>1)return!1;o.set(i,1+Math.max(l,d)),r=i,i=void 0}}else i=i.right}return t}map(e,t,n){let i=this._createLike([],t),r=0;for(let[o,l]of this)i.add(e.call(n,o,l,r++,this));return i}deleteWhere(e){let t=[],n=this._root,i=0;for(;t.length>0||n!==void 0;){for(;n!=null;)t.push(n),n=n.left;let r=t.pop();if(!r)break;let o=r.key,l=r.value;if(e(o,l,i++,this))return this._deleteByKey(o);n=r.right}return!1}_createInstance(e){let t=this.constructor;return new t([],{...this._snapshotOptions(),...e!=null?e:{}})}_createLike(e=[],t){let n=this.constructor;return new n(e,{...this._snapshotOptions(),...t!=null?t:{}})}_snapshotOptions(){return{...super._snapshotOptions(),specifyComparable:this.specifyComparable,isReverse:this.isReverse}}_keyValueNodeOrEntryToNodeAndValue(e,t){let[n,i]=super._keyValueNodeOrEntryToNodeAndValue(e,t);return n===null?[void 0,void 0]:[n,t!=null?t:i]}_setRoot(e){e&&(e.parent=void 0),this._root=e}_compare(e,t){return this._isReverse?-this._comparator(e,t):this._comparator(e,t)}_deleteByKey(e){var r;let t=this._root;for(;t;){let o=this._compare(t.key,e);if(o===0)break;t=o>0?t.left:t.right}if(!t)return!1;let n=(o,l)=>{let d=o==null?void 0:o.parent;d?d.left===o?d.left=l:d.right=l:this._setRoot(l),l&&(l.parent=d)},i=o=>{if(o){for(;o.left!==void 0&&o.left!==null;)o=o.left;return o}};if(t.left===void 0)n(t,t.right);else if(t.right===void 0)n(t,t.left);else{let o=i(t.right);o.parent!==t&&(n(o,o.right),o.right=t.right,o.right&&(o.right.parent=o)),n(t,o),o.left=t.left,o.left&&(o.left.parent=o)}return this._size=Math.max(0,((r=this._size)!=null?r:0)-1),!0}};var k=class extends B{constructor(e,t){super(e,t);T(this,"parent");T(this,"_left");T(this,"_right")}get left(){return this._left}set left(e){e&&(e.parent=this),this._left=e}get right(){return this._right}set right(e){e&&(e.parent=this),this._right=e}},P=class extends L{constructor(s=[],e){super([],e),s&&super.addMany(s)}createNode(s,e){return new k(s,this._isMapMode?void 0:e)}isNode(s){return s instanceof k}add(s,e){if(s===null)return!1;let t=super.add(s,e);return t&&this._balancePath(s),t}delete(s){let e=super.delete(s);for(let{needBalanced:t}of e)t&&this._balancePath(t);return e}perfectlyBalance(s=this.iterationType){let e=this.dfs(r=>r,"IN",!1,this._root,s),t=e.length;if(t===0)return!1;this._clearNodes();let n=(r,o,l)=>{if(r>o)return;let d=r+(o-r>>1),u=e[d];u.left=n(r,d-1,u),u.right=n(d+1,o,u),u.parent=l;let a=u.left?u.left.height:-1,c=u.right?u.right.height:-1;return u.height=Math.max(a,c)+1,u},i=n(0,t-1,void 0);return this._setRoot(i),this._size=t,!0}map(s,e,t){let n=this._createLike([],e),i=0;for(let[r,o]of this)n.add(s.call(t,r,o,i++,this));return n}_createInstance(s){let e=this.constructor;return new e([],{...this._snapshotOptions(),...s!=null?s:{}})}_createLike(s=[],e){let t=this.constructor;return new t(s,{...this._snapshotOptions(),...e!=null?e:{}})}_swapProperties(s,e){let t=this.ensureNode(s),n=this.ensureNode(e);if(t&&n){let{key:i,value:r,height:o}=n,l=this.createNode(i,r);return l&&(l.height=o,n.key=t.key,this._isMapMode||(n.value=t.value),n.height=t.height,t.key=l.key,this._isMapMode||(t.value=l.value),t.height=l.height),n}}_balanceFactor(s){let e=s.left?s.left.height:-1;return(s.right?s.right.height:-1)-e}_updateHeight(s){let e=s.left?s.left.height:-1,t=s.right?s.right.height:-1;s.height=1+Math.max(e,t)}_balanceLL(s){let e=s.parent,t=s.left;t!==null&&(s.parent=t),t&&t.right&&(t.right.parent=s),t&&(t.parent=e),s===this.root?t&&this._setRoot(t):(e==null?void 0:e.left)===s?e.left=t:e&&(e.right=t),t&&(s.left=t.right,t.right=s),this._updateHeight(s),t&&this._updateHeight(t)}_balanceLR(s){let e=s.parent,t=s.left,n;t&&(n=t.right),s&&n!==null&&(s.parent=n),t&&n!==null&&(t.parent=n),n&&(n.left&&t!==null&&(n.left.parent=t),n.right&&(n.right.parent=s),n.parent=e),s===this.root?n&&this._setRoot(n):e&&(e.left===s?e.left=n:e.right=n),n&&(s.left=n.right,t&&(t.right=n.left),n.left=t,n.right=s),this._updateHeight(s),t&&this._updateHeight(t),n&&this._updateHeight(n)}_balanceRR(s){let e=s.parent,t=s.right;t!==null&&(s.parent=t),t&&(t.left&&(t.left.parent=s),t.parent=e),s===this.root?t&&this._setRoot(t):e&&(e.left===s?e.left=t:e.right=t),t&&(s.right=t.left,t.left=s),this._updateHeight(s),t&&this._updateHeight(t)}_balanceRL(s){let e=s.parent,t=s.right,n;t&&(n=t.left),n!==null&&(s.parent=n),t&&n!==null&&(t.parent=n),n&&(n.left&&(n.left.parent=s),n.right&&t!==null&&(n.right.parent=t),n.parent=e),s===this.root?n&&this._setRoot(n):e&&(e.left===s?e.left=n:e.right=n),n&&(s.right=n.left),t&&n&&(t.left=n.right),n&&(n.left=s),n&&(n.right=t),this._updateHeight(s),t&&this._updateHeight(t),n&&this._updateHeight(n)}_balancePath(s){s=this.ensureNode(s);let e=this.getPathToRoot(s,t=>t,!1);for(let t=0;t<e.length;t++){let n=e[t];if(n)switch(this._updateHeight(n),this._balanceFactor(n)){case-2:n&&n.left&&(this._balanceFactor(n.left)<=0?this._balanceLL(n):this._balanceLR(n));break;case 2:n&&n.right&&(this._balanceFactor(n.right)>=0?this._balanceRR(n):this._balanceRL(n))}}}_replaceNode(s,e){return e.height=s.height,super._replaceNode(s,e)}};return Y(ee);})();
|
|
6
|
+
/**
|
|
7
|
+
* data-structure-typed
|
|
8
|
+
*
|
|
9
|
+
* @author Pablo Zeng
|
|
10
|
+
* @copyright Copyright (c) 2022 Pablo Zeng <zrwusa@gmail.com>
|
|
11
|
+
* @license MIT License
|
|
12
|
+
*/
|
|
13
|
+
//# sourceMappingURL=avl-tree-typed.min.js.map
|