tree-multimap-typed 2.1.1 → 2.2.0
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 +4298 -0
- package/dist/cjs/index.cjs.map +1 -0
- package/dist/cjs-legacy/index.cjs +4300 -0
- package/dist/cjs-legacy/index.cjs.map +1 -0
- package/dist/esm/index.mjs +4287 -0
- package/dist/esm/index.mjs.map +1 -0
- package/dist/esm-legacy/index.mjs +4289 -0
- package/dist/esm-legacy/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 +236 -2
- package/dist/types/data-structures/binary-tree/avl-tree-multi-map.d.ts +197 -2
- package/dist/types/data-structures/binary-tree/avl-tree.d.ts +345 -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 +467 -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 +262 -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 +244 -2
- package/dist/types/data-structures/binary-tree/tree-multi-map.d.ts +332 -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 +17 -2
- 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/tree-multimap-typed.js +4289 -0
- package/dist/umd/tree-multimap-typed.js.map +1 -0
- package/dist/umd/tree-multimap-typed.min.js +13 -0
- package/dist/umd/tree-multimap-typed.min.js.map +1 -0
- package/package.json +43 -5
- package/src/data-structures/binary-tree/avl-tree-counter.ts +106 -15
- package/src/data-structures/binary-tree/avl-tree-multi-map.ts +116 -12
- package/src/data-structures/binary-tree/avl-tree.ts +107 -16
- package/src/data-structures/binary-tree/binary-tree.ts +4 -4
- package/src/data-structures/binary-tree/bst.ts +103 -12
- package/src/data-structures/binary-tree/red-black-tree.ts +110 -20
- package/src/data-structures/binary-tree/tree-counter.ts +105 -14
- package/src/data-structures/binary-tree/tree-multi-map.ts +123 -12
- package/src/data-structures/graph/abstract-graph.ts +5 -5
- package/src/data-structures/graph/directed-graph.ts +5 -5
- package/src/data-structures/graph/undirected-graph.ts +5 -5
- 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 +71 -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 -18
- package/dist/index.js +0 -34
- 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 -24
- 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 treeMultimapTyped=(()=>{var w=Object.defineProperty;var X=Object.getOwnPropertyDescriptor;var J=Object.getOwnPropertyNames;var Y=Object.prototype.hasOwnProperty;var Z=(c,l,e)=>l in c?w(c,l,{enumerable:!0,configurable:!0,writable:!0,value:e}):c[l]=e;var $=(c,l)=>{for(var e in l)w(c,e,{get:l[e],enumerable:!0})},z=(c,l,e,t)=>{if(l&&typeof l=="object"||typeof l=="function")for(let n of J(l))!Y.call(c,n)&&n!==e&&w(c,n,{get:()=>l[n],enumerable:!(t=X(l,n))||t.enumerable});return c};var ee=c=>z(w({},"__esModule",{value:!0}),c);var f=(c,l,e)=>Z(c,typeof l!="symbol"?l+"":l,e);var ie={};$(ie,{BST:()=>M,BSTNode:()=>k,BinaryTree:()=>C,BinaryTreeNode:()=>E,DFSOperation:()=>H,Range:()=>_,RedBlackTree:()=>L,RedBlackTreeNode:()=>I,TreeMultiMap:()=>G,TreeMultiMapNode:()=>x});function F(c){let l=typeof c;return l==="number"?!0:l==="bigint"||l==="string"||l==="boolean"}function j(c){if(typeof c.valueOf=="function"){let l=c.valueOf();if(l!==c){if(F(l))return l;if(typeof l=="object"&&l!==null)return j(l)}}if(typeof c.toString=="function"){let l=c.toString();if(l!=="[object Object]")return l}return null}function y(c,l=!1){if(c==null)return!1;if(F(c))return!0;if(typeof c!="object")return!1;if(c instanceof Date||l)return!0;let e=j(c);return e==null?!1:F(e)}var P=c=>({isThunk:!0,fn:c}),te=c=>typeof c=="object"&&c!==null&&"isThunk"in c&&c.isThunk;function ne(c){let l=c;for(;te(l);)l=l.fn();return l}function U(c){return(...l)=>ne(c(...l))}var O=class{constructor(l){f(this,"_toElementFn");if(l){let{toElementFn:e}=l;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](...l){yield*this._getIterator(...l)}*values(){for(let l of this)yield l}every(l,e){let t=0;for(let n of this)if(e===void 0){if(!l(n,t++,this))return!1}else if(!l.call(e,n,t++,this))return!1;return!0}some(l,e){let t=0;for(let n of this)if(e===void 0){if(l(n,t++,this))return!0}else if(l.call(e,n,t++,this))return!0;return!1}forEach(l,e){let t=0;for(let n of this)e===void 0?l(n,t++,this):l.call(e,n,t++,this)}find(l,e){let t=0;for(let n of this)if(e===void 0){if(l(n,t++,this))return n}else if(l.call(e,n,t++,this))return n}has(l){for(let e of this)if(e===l)return!0;return!1}reduce(l,e){let t=0,n=this[Symbol.iterator](),i;if(arguments.length>=2)i=e;else{let s=n.next();if(s.done)throw new TypeError("Reduce of empty structure with no initial value");i=s.value,t=1}for(let s of n)i=l(i,s,t++,this);return i}toArray(){return[...this]}toVisual(){return[...this]}print(){console.log(this.toVisual())}};var A=class c extends O{constructor(e){super(e);f(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 s=0;s<t;s++){let r=this.deleteAt(e);r!==void 0&&i.push(r)}for(let s=0;s<n.length;s++)this.addAt(e+s,n[s]);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 c extends A{constructor(e=[],t){super(t);f(this,"_elements",[]);f(this,"_offset",0);f(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,s=this._elements.splice(i,t,...n);this.elements.length>0&&this.offset/this.elements.length>this.autoCompactRatio&&this.compact();let r=this._createInstance({toElementFn:this.toElementFn,maxLen:this._maxLen});return r._setAutoCompactRatio(this._autoCompactRatio),r.pushMany(s),r}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 s of this)e.call(t,s,i,this)&&n.push(s),i++;return n}map(e,t,n){var r,o;let i=new this.constructor([],{toElementFn:t==null?void 0:t.toElementFn,maxLen:(r=t==null?void 0:t.maxLen)!=null?r:this._maxLen,autoCompactRatio:(o=t==null?void 0:t.autoCompactRatio)!=null?o:this._autoCompactRatio}),s=0;for(let d of this)i.push(n===void 0?e(d,s++,this):e.call(n,d,s++,this));return i}mapSame(e,t){var r;let n=this.constructor,i=new n([],{toElementFn:this.toElementFn,maxLen:this._maxLen,autoCompactRatio:this._autoCompactRatio});(r=i._setAutoCompactRatio)==null||r.call(i,this._autoCompactRatio);let s=0;for(let o of this){let d=t===void 0?e(o,s++,this):e.call(t,o,s++,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 v=class{*[Symbol.iterator](...l){yield*this._getIterator(...l)}*entries(){for(let l of this)yield l}*keys(){for(let l of this)yield l[0]}*values(){for(let l of this)yield l[1]}every(l,e){let t=0;for(let n of this)if(!l.call(e,n[0],n[1],t++,this))return!1;return!0}some(l,e){let t=0;for(let n of this)if(l.call(e,n[0],n[1],t++,this))return!0;return!1}forEach(l,e){let t=0;for(let n of this){let[i,s]=n;l.call(e,i,s,t++,this)}}find(l,e){let t=0;for(let n of this){let[i,s]=n;if(l.call(e,i,s,t++,this))return n}}has(l){for(let e of this){let[t]=e;if(t===l)return!0}return!1}hasValue(l){for(let[,e]of this)if(e===l)return!0;return!1}get(l){for(let e of this){let[t,n]=e;if(t===l)return n}}reduce(l,e){let t=e,n=0;for(let i of this){let[s,r]=i;t=l(t,r,s,n++,this)}return t}toVisual(){return[...this]}print(){console.log(this.toVisual())}};var H=(e=>(e[e.VISIT=0]="VISIT",e[e.PROCESS=1]="PROCESS",e))(H||{}),_=class{constructor(l,e,t=!0,n=!0){this.low=l;this.high=e;this.includeLow=t;this.includeHigh=n;if(!(y(l)&&y(e)))throw new RangeError("low or high is not comparable");if(l>e)throw new RangeError("low must be less than or equal to high")}isInRange(l,e){let t=this.includeLow?e(l,this.low)>=0:e(l,this.low)>0,n=this.includeHigh?e(l,this.high)<=0:e(l,this.high)<0;return t&&n}};var E=class{constructor(l,e){f(this,"key");f(this,"value");f(this,"parent");f(this,"_left");f(this,"_right");f(this,"_height",0);f(this,"_color","BLACK");f(this,"_count",1);this.key=l,this.value=e}get left(){return this._left}set left(l){l&&(l.parent=this),this._left=l}get right(){return this._right}set right(l){l&&(l.parent=this),this._right=l}get height(){return this._height}set height(l){this._height=l}get color(){return this._color}set color(l){this._color=l}get count(){return this._count}set count(l){this._count=l}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"}},C=class extends v{constructor(e=[],t){super();f(this,"iterationType","ITERATIVE");f(this,"_isMapMode",!0);f(this,"_isDuplicate",!1);f(this,"_store",new Map);f(this,"_root");f(this,"_size",0);f(this,"_NIL",new E(NaN));f(this,"_toEntryFn");f(this,"_DEFAULT_NODE_CALLBACK",e=>e?e.key:void 0);if(t){let{iterationType:n,toEntryFn:i,isMapMode:s,isDuplicate:r}=t;if(n&&(this.iterationType=n),s!==void 0&&(this._isMapMode=s),r!==void 0&&(this._isDuplicate=r),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(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 E}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 _}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:y(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 s=new m([this._root]),r;for(;s.length>0;){let o=s.shift();if(o){if(!this._isDuplicate&&n!==null&&o.key===n.key)return this._replaceNode(o,n),this._isMapMode&&this._setValue(o.key,i),!0;r===void 0&&(o.left===void 0||o.right===void 0)&&(r=o),o.left!==null&&o.left&&s.push(o.left),o.right!==null&&o.right&&s.push(o.right)}}return r?(r.left===void 0?r.left=n:r.right===void 0&&(r.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 s of e){let r;if(i){let o=i.next();o.done||(r=o.value)}this.isRaw(s)&&(s=this._toEntryFn(s)),n.push(this.add(s,r))}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,s,r=n;if(!n.left&&!n.right&&!i)this._setRoot(void 0);else if(n.left){let o=this.getRightMost(d=>d,n.left);if(o){let d=o.parent;r=this._swapProperties(n,o),d&&(d.right===o?d.right=o.left:d.left=o.left,s=d)}}else if(i){let{familyPosition:o}=n;o==="LEFT"||o==="ROOT_LEFT"?i.left=n.right:(o==="RIGHT"||o==="ROOT_RIGHT")&&(i.right=n.right),s=i}else this._setRoot(n.right),n.right=void 0;return this._size=this._size-1,t.push({deleted:r,needBalanced:s}),this._isMapMode&&r&&this._store.delete(r.key),t}search(e,t=!1,n=this._DEFAULT_NODE_CALLBACK,i=this._root,s=this.iterationType){if(e===void 0)return[];if(e===null)return[];if(i=this.ensureNode(i),!i)return[];let r=this._ensurePredicate(e),o=[];if(s==="RECURSIVE"){let d=u=>{r(u)&&(o.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(r(u)&&(o.push(n(u)),t))return o;this.isRealNode(u.left)&&d.push(u.left),this.isRealNode(u.right)&&d.push(u.right)}}}return o}getNodes(e,t=!1,n=this._root,i=this.iterationType){return this.search(e,t,s=>s,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 s=this._extractKey(e);return s==null?void 0:this._store.get(s)}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=(o,d,u)=>{if(!this.isRealNode(o))return!0;let a=Number(o.key);return a<=d||a>=u?!1:i(o.left,d,a)&&i(o.right,a,u)},s=i(n,Number.MIN_SAFE_INTEGER,Number.MAX_SAFE_INTEGER),r=i(n,Number.MAX_SAFE_INTEGER,Number.MIN_SAFE_INTEGER);return s||r}else{let i=(o=!1)=>{let d=[],u=o?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 T=Number(a.key);if(!this.isRealNode(a)||!o&&u>=T||o&&u<=T)return!1;u=T,a=a.right}return!0},s=i(!1),r=i(!0);return s||r}}getDepth(e,t=this._root){let n=this.ensureNode(e),i=this.ensureNode(t),s=0;for(;n!=null&&n.parent;){if(n===i)return s;s++,n=n.parent}return s}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 s=n(i.left),r=n(i.right);return Math.max(s,r)+1};return n(e)}else{let n=[{node:e,depth:0}],i=0;for(;n.length>0;){let{node:s,depth:r}=n.pop();this.isRealNode(s.left)&&n.push({node:s.left,depth:r+1}),this.isRealNode(s.right)&&n.push({node:s.right,depth:r+1}),i=Math.max(i,r)}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 s=n(i.left),r=n(i.right);return Math.min(s,r)+1};return n(e)}else{let n=[],i=e,s=null,r=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)||s===i.right){if(i=n.pop(),this.isRealNode(i)){let o=this.isRealNode(i.left)?r.get(i.left):-1,d=this.isRealNode(i.right)?r.get(i.right):-1;r.set(i,1+Math.min(o,d)),s=i,i=null}}else i=i.right;return r.get(e)}}getPathToRoot(e,t=this._DEFAULT_NODE_CALLBACK,n=!1){let i=[],s=this.ensureNode(e);if(!s)return i;for(;s.parent;)i.push(t(s)),s=s.parent;return i.push(t(s)),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 s=r=>{let{left:o}=r;return this.isRealNode(o)?s(o):r};return e(s(i))}else{let s=U(r=>{let{left:o}=r;return this.isRealNode(o)?P(()=>s(o)):r});return e(s(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=s=>{let{right:r}=s;return this.isRealNode(r)?i(r):s};return e(i(t))}else{let i=U(s=>{let{right:r}=s;return this.isRealNode(r)?P(()=>i(r)):s});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,s=this.iterationType,r=!1){return i=this.ensureNode(i),i?this._dfs(e,t,n,i,s,r):[]}bfs(e=this._DEFAULT_NODE_CALLBACK,t=this._root,n=this.iterationType,i=!1){if(t=this.ensureNode(t),!t)return[];let s=[];if(n==="RECURSIVE"){let r=new m([t]),o=d=>{if(r.length===0)return;let u=r.shift();s.push(e(u)),i?(u&&this.isRealNodeOrNull(u.left)&&r.push(u.left),u&&this.isRealNodeOrNull(u.right)&&r.push(u.right)):(this.isRealNode(u.left)&&r.push(u.left),this.isRealNode(u.right)&&r.push(u.right)),o(d+1)};o(0)}else{let r=new m([t]);for(;r.length>0;){let o=r.length;for(let d=0;d<o;d++){let u=r.shift();s.push(e(u)),i?(u&&this.isRealNodeOrNull(u.left)&&r.push(u.left),u&&this.isRealNodeOrNull(u.right)&&r.push(u.right)):(this.isRealNode(u.left)&&r.push(u.left),this.isRealNode(u.right)&&r.push(u.right))}}}return s}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 s=r=>{this.isLeaf(r)&&i.push(e(r)),!(!this.isRealNode(r.left)&&!this.isRealNode(r.right))&&(this.isRealNode(r.left)&&s(r.left),this.isRealNode(r.right)&&s(r.right))};s(t)}else{let s=new m([t]);for(;s.length>0;){let r=s.shift();this.isRealNode(r)&&(this.isLeaf(r)&&i.push(e(r)),this.isRealNode(r.left)&&s.push(r.left),this.isRealNode(r.right)&&s.push(r.right))}}return i}listLevels(e=this._DEFAULT_NODE_CALLBACK,t=this._root,n=this.iterationType,i=!1){t=this.ensureNode(t);let s=[];if(!t)return s;if(n==="RECURSIVE"){let r=(o,d)=>{s[d]||(s[d]=[]),s[d].push(e(o)),i?(o&&this.isRealNodeOrNull(o.left)&&r(o.left,d+1),o&&this.isRealNodeOrNull(o.right)&&r(o.right,d+1)):(o&&o.left&&r(o.left,d+1),o&&o.right&&r(o.right,d+1))};r(t,0)}else{let r=[[t,0]];for(;r.length>0;){let o=r.pop(),[d,u]=o;s[u]||(s[u]=[]),s[u].push(e(d)),i?(d&&this.isRealNodeOrNull(d.right)&&r.push([d.right,u+1]),d&&this.isRealNodeOrNull(d.left)&&r.push([d.left,u+1])):(d&&d.right&&r.push([d.right,u+1]),d&&d.left&&r.push([d.left,u+1]))}}return s}morris(e=this._DEFAULT_NODE_CALLBACK,t="IN",n=this._root){if(n=this.ensureNode(n),!n)return[];let i=[],s=n,r=d=>{let u=null,a=null;for(;d;)a=d.right,d.right=u,u=d,d=a;return u},o=d=>{let u=r(d),a=u;for(;a;)i.push(e(a)),a=a.right;r(u)};switch(t){case"IN":for(;s;){if(s.left){let d=this.getPredecessor(s);if(d.right)d.right=null;else{d.right=s,s=s.left;continue}}i.push(e(s)),s=s.right}break;case"PRE":for(;s;){if(s.left){let d=this.getPredecessor(s);if(d.right)d.right=null;else{d.right=s,i.push(e(s)),s=s.left;continue}}else i.push(e(s));s=s.right}break;case"POST":for(;s;){if(s.left){let d=this.getPredecessor(s);if(d.right===null){d.right=s,s=s.left;continue}else d.right=null,o(s.left)}s=s.right}o(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[s,r]of this)e.call(t,s,r,i++,this)&&n.add([s,r]);return n}map(e,t,n){let i=this._createLike([],t),s=0;for(let[r,o]of this)i.add(e.call(n,r,o,s++,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
|
+
`),(r=>{let[o]=this._displayAux(r,n),d="";for(let u of o)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,s=this.iterationType,r=!1,o=T=>!!T,d=T=>!!T,u=T=>r?this.isRealNodeOrNull(T):this.isRealNode(T),a=T=>this.isRealNodeOrNull(T)){if(i=this.ensureNode(i),!i)return[];let T=[];if(s==="RECURSIVE"){let p=h=>{if(!u(h))return;let V=()=>{o(h)&&(h==null?void 0:h.left)!==void 0&&p(h==null?void 0:h.left)},R=()=>{d(h)&&(h==null?void 0:h.right)!==void 0&&p(h==null?void 0:h.right)};switch(t){case"IN":if(V(),a(h)&&(T.push(e(h)),n))return;R();break;case"PRE":if(a(h)&&(T.push(e(h)),n))return;V(),R();break;case"POST":if(V(),R(),a(h)&&(T.push(e(h)),n))return;break}};p(i)}else{let p=[{opt:0,node:i}],h=K=>{var N;o(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})},R=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&&(T.push(e(K.node)),n))return T}else switch(t){case"IN":V(K),R(K),h(K);break;case"PRE":V(K),h(K),R(K);break;case"POST":R(K),V(K),h(K);break}}}return T}*_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 s=t!=null?t:i;return[this.createNode(n,s),s]}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:s}=t,r=[["\u2500"],1,0,0];if(e===null&&!n)return r;if(e===void 0&&!i)return r;if(this.isNIL(e)&&!s)return r;if(e!=null){let d=e.key,u=this.isNIL(e)?"S":String(d),a=u.length;return o(u,a,this._displayAux(e.left,t),this._displayAux(e.right,t))}else{let d=e===void 0?"U":"N",u=d.length;return o(d,u,[[""],1,0,0],[[""],1,0,0])}function o(d,u,a,T){let[p,h,V,R]=a,[K,N,g,B]=T,S=" ".repeat(Math.max(0,R+1))+"_".repeat(Math.max(0,h-R-1))+d+"_".repeat(Math.max(0,B))+" ".repeat(Math.max(0,N-B)),D=(V>0?" ".repeat(R)+"/"+" ".repeat(h-R-1):" ".repeat(h))+" ".repeat(u)+(g>0?" ".repeat(B)+"\\"+" ".repeat(N-B-1):" ".repeat(N)),Q=[S,D];for(let b=0;b<Math.max(V,g);b++){let q=b<V?p[b]:" ".repeat(h),W=b<g?K[b]:" ".repeat(N);Q.push(q+" ".repeat(u)+W)}return[Q,h+u+N,Math.max(V,g)+2,h+Math.floor(u/2)]}}_swapProperties(e,t){if(e=this.ensureNode(e),t=this.ensureNode(t),e&&t){let{key:n,value:i}=t,s=this.createNode(n,i);return s&&(t.key=e.key,this._isMapMode||(t.value=e.value),e.key=s.key,this._isMapMode||(e.value=s.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 k=class{constructor(l,e){f(this,"key");f(this,"value");f(this,"parent");f(this,"_left");f(this,"_right");f(this,"_height",0);f(this,"_color","BLACK");f(this,"_count",1);this.key=l,this.value=e}get left(){return this._left}set left(l){l&&(l.parent=this),this._left=l}get right(){return this._right}set right(l){l&&(l.parent=this),this._right=l}get height(){return this._height}set height(l){this._height=l}get color(){return this._color}set color(l){this._color=l}get count(){return this._count}set count(l){this._count=l}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"}},M=class extends C{constructor(e=[],t){super([],t);f(this,"_root");f(this,"_isReverse",!1);f(this,"_comparator",(e,t)=>{if(y(e)&&y(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});f(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 k(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 k}isValidKey(e){return y(e,this._specifyComparable!==void 0)}dfs(e=this._DEFAULT_NODE_CALLBACK,t="IN",n=!1,i=this._root,s=this.iterationType){return super.dfs(e,t,n,i,s)}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,s=this.iterationType){if(e===void 0)return[];if(e===null)return[];if(i=this.ensureNode(i),!i)return[];let r,o=this.isRange(e);o?r=a=>a?e.isInRange(a.key,this._comparator):!1:r=this._ensurePredicate(e);let d=a=>{if(!a||!this.isRealNode(a.left))return!1;if(o){let T=e,p=this.isReverse?T.high:T.low,h=this.isReverse?T.includeHigh:T.includeLow;return h&&this._compare(a.key,p)>=0||!h&&this._compare(a.key,p)>0}if(!o&&!this._isPredicate(e)){let T=this._extractKey(e);return T!=null&&this._compare(a.key,T)>0}return!0},u=a=>{if(!a||!this.isRealNode(a.right))return!1;if(o){let T=e,p=this.isReverse?T.low:T.high,h=this.isReverse?T.includeLow:T.includeHigh;return h&&this._compare(a.key,p)<=0||!h&&this._compare(a.key,p)<0}if(!o&&!this._isPredicate(e)){let T=this._extractKey(e);return T!=null&&this._compare(a.key,T)<0}return!0};return super._dfs(n,"IN",t,i,s,!1,d,u,()=>!0,a=>!!a&&r(a))}rangeSearch(e,t=this._DEFAULT_NODE_CALLBACK,n=this._root,i=this.iterationType){let s=e instanceof _?e:new _(e[0],e[1]);return this.search(s,!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 s=this._root;for(;s!==void 0;){if(this._compare(s.key,n.key)===0)return this._replaceNode(s,n),this._isMapMode&&this._setValue(s.key,i),!0;if(this._compare(s.key,n.key)>0){if(s.left===void 0)return s.left=n,this._isMapMode&&this._setValue(n==null?void 0:n.key,i),this._size++,!0;s.left!==null&&(s=s.left)}else{if(s.right===void 0)return s.right=n,this._isMapMode&&this._setValue(n==null?void 0:n.key,i),this._size++,!0;s.right!==null&&(s=s.right)}}return!1}addMany(e,t,n=!0,i=this.iterationType){let s=[],r=t==null?void 0:t[Symbol.iterator]();if(!n){for(let p of e){let h=r==null?void 0:r.next().value;this.isRaw(p)&&(p=this._toEntryFn(p)),s.push(this.add(p,h))}return s}let o=[],d=0;for(let p of e)o.push({key:p,value:r==null?void 0:r.next().value,orgIndex:d++});let u=o.sort(({key:p},{key:h})=>{let V,R;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(h)?R=this._toEntryFn(h)[0]:this.isEntry(h)?R=h[0]:this.isRealNode(h)?R=h.key:R=h,V!=null&&R!=null?this._compare(V,R):0}),a=p=>{if(p.length===0)return;let h=Math.floor((p.length-1)/2),{key:V,value:R,orgIndex:K}=p[h];if(this.isRaw(V)){let N=this._toEntryFn(V);s[K]=this.add(N)}else s[K]=this.add(V,R);a(p.slice(0,h)),a(p.slice(h+1))};return i==="RECURSIVE"?a(u):(()=>{let h=[[0,u.length-1]];for(;h.length>0;){let V=h.pop();if(!V)continue;let[R,K]=V;if(R>K)continue;let N=R+Math.floor((K-R)/2),{key:g,value:B,orgIndex:S}=u[N];if(this.isRaw(g)){let D=this._toEntryFn(g);s[S]=this.add(D)}else s[S]=this.add(g,B);h.push([N+1,K]),h.push([R,N-1])}})(),s}lesserOrGreaterTraverse(e=this._DEFAULT_NODE_CALLBACK,t=-1,n=this._root,i=this.iterationType){let s=this.ensureNode(n),r=[];if(!this._root||!s)return r;let o=s.key;if(i==="RECURSIVE"){let d=u=>{let a=this._compare(u.key,o);Math.sign(a)==t&&r.push(e(u)),this.isRealNode(u.left)&&d(u.left),this.isRealNode(u.right)&&d(u.right)};return d(this._root),r}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,o);Math.sign(a)==t&&r.push(e(u)),this.isRealNode(u.left)&&d.push(u.left),this.isRealNode(u.right)&&d.push(u.right)}}return r}}perfectlyBalance(e=this.iterationType){let t=this.dfs(r=>r,"IN",!1,this._root,e),n=t.length;if(this._clearNodes(),n===0)return!1;let i=(r,o,d)=>{if(r>o)return;let u=r+(o-r>>1),a=t[u],T=i(r,u-1,a),p=i(u+1,o,a);return a.left=T,a.right=p,a.parent=d,a},s=i(0,n-1,void 0);return this._setRoot(s),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 s=n(i.left),r=n(i.right);return Math.abs(s-r)>1&&(t=!1),Math.max(s,r)+1};n(this._root)}else{let n=[],i=this._root,s,r=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||s===i.right){if(i=n.pop(),i){let o=i.left?r.get(i.left):-1,d=i.right?r.get(i.right):-1;if(Math.abs(o-d)>1)return!1;r.set(i,1+Math.max(o,d)),s=i,i=void 0}}else i=i.right}return t}map(e,t,n){let i=this._createLike([],t),s=0;for(let[r,o]of this)i.add(e.call(n,r,o,s++,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 s=t.pop();if(!s)break;let r=s.key,o=s.value;if(e(r,o,i++,this))return this._deleteByKey(r);n=s.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 s;let t=this._root;for(;t;){let r=this._compare(t.key,e);if(r===0)break;t=r>0?t.left:t.right}if(!t)return!1;let n=(r,o)=>{let d=r==null?void 0:r.parent;d?d.left===r?d.left=o:d.right=o:this._setRoot(o),o&&(o.parent=d)},i=r=>{if(r){for(;r.left!==void 0&&r.left!==null;)r=r.left;return r}};if(t.left===void 0)n(t,t.right);else if(t.right===void 0)n(t,t.left);else{let r=i(t.right);r.parent!==t&&(n(r,r.right),r.right=t.right,r.right&&(r.right.parent=r)),n(t,r),r.left=t.left,r.left&&(r.left.parent=r)}return this._size=Math.max(0,((s=this._size)!=null?s:0)-1),!0}};var I=class{constructor(l,e,t="BLACK"){f(this,"key");f(this,"value");f(this,"parent");f(this,"_left");f(this,"_right");f(this,"_height",0);f(this,"_color","BLACK");f(this,"_count",1);this.key=l,this.value=e,this.color=t}get left(){return this._left}set left(l){l&&(l.parent=this),this._left=l}get right(){return this._right}set right(l){l&&(l.parent=this),this._right=l}get height(){return this._height}set height(l){this._height=l}get color(){return this._color}set color(l){this._color=l}get count(){return this._count}set count(l){this._count=l}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"}},L=class extends M{constructor(e=[],t){super([],t);f(this,"_root");this._root=this.NIL,e&&this.addMany(e)}get root(){return this._root}createNode(e,t,n="BLACK"){return new I(e,this._isMapMode?void 0:t,n)}isNode(e){return e instanceof I}clear(){super.clear(),this._root=this.NIL}add(e,t){let[n,i]=this._keyValueNodeOrEntryToNodeAndValue(e,t);if(!this.isRealNode(n))return!1;let s=this._insert(n);if(s==="CREATED"){if(this.isRealNode(this._root))this._root.color="BLACK";else return!1;return this._isMapMode&&this._setValue(n.key,i),this._size++,!0}return s==="UPDATED"?(this._isMapMode&&this._setValue(n.key,i),!0):!1}delete(e){if(e===null)return[];let t=[],n;if(this._isPredicate(e)?n=this.getNode(e):n=this.isRealNode(e)?e:this.getNode(e),!n)return t;let i=n.color,s;if(!this.isRealNode(n.left))n.right!==null&&(s=n.right,this._transplant(n,n.right));else if(!this.isRealNode(n.right))s=n.left,this._transplant(n,n.left);else{let r=this.getLeftMost(o=>o,n.right);r&&(i=r.color,r.right!==null&&(s=r.right),r.parent===n?this.isRealNode(s)&&(s.parent=r):(r.right!==null&&(this._transplant(r,r.right),r.right=n.right),this.isRealNode(r.right)&&(r.right.parent=r)),this._transplant(n,r),r.left=n.left,this.isRealNode(r.left)&&(r.left.parent=r),r.color=n.color)}return this._isMapMode&&this._store.delete(n.key),this._size--,i==="BLACK"&&this._deleteFixup(s),t.push({deleted:n,needBalanced:void 0}),t}map(e,t,n){let i=this._createLike([],t),s=0;for(let[r,o]of this)i.add(e.call(n,r,o,s++,this));return i}_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:{}})}_setRoot(e){e&&(e.parent=void 0),this._root=e}_replaceNode(e,t){return t.color=e.color,super._replaceNode(e,t)}_insert(e){var i,s,r;let t=(i=this.root)!=null?i:this.NIL,n;for(;t!==this.NIL;){n=t;let o=this._compare(e.key,t.key);if(o<0)t=(s=t.left)!=null?s:this.NIL;else if(o>0)t=(r=t.right)!=null?r:this.NIL;else return this._replaceNode(t,e),"UPDATED"}return e.parent=n,n?this._compare(e.key,n.key)<0?n.left=e:n.right=e:this._setRoot(e),e.left=this.NIL,e.right=this.NIL,e.color="RED",this._insertFixup(e),"CREATED"}_transplant(e,t){e.parent?e===e.parent.left?e.parent.left=t:e.parent.right=t:this._setRoot(t),t&&(t.parent=e.parent)}_insertFixup(e){var t,n,i,s,r;for(;((t=e==null?void 0:e.parent)==null?void 0:t.color)==="RED";)if(e.parent===((n=e.parent.parent)==null?void 0:n.left)){let o=e.parent.parent.right;(o==null?void 0:o.color)==="RED"?(e.parent.color="BLACK",o.color="BLACK",e.parent.parent.color="RED",e=e.parent.parent):(e===e.parent.right&&(e=e.parent,this._leftRotate(e)),e&&e.parent&&e.parent.parent&&(e.parent.color="BLACK",e.parent.parent.color="RED",this._rightRotate(e.parent.parent)))}else{let o=(r=(s=(i=e==null?void 0:e.parent)==null?void 0:i.parent)==null?void 0:s.left)!=null?r:void 0;(o==null?void 0:o.color)==="RED"?(e.parent.color="BLACK",o.color="BLACK",e.parent.parent.color="RED",e=e.parent.parent):(e===e.parent.left&&(e=e.parent,this._rightRotate(e)),e&&e.parent&&e.parent.parent&&(e.parent.color="BLACK",e.parent.parent.color="RED",this._leftRotate(e.parent.parent)))}this.isRealNode(this._root)&&(this._root.color="BLACK")}_deleteFixup(e){var t,n,i,s;if(!e||e===this.root||e.color==="BLACK"){e&&(e.color="BLACK");return}for(;e&&e!==this.root&&e.color==="BLACK";){let r=e.parent;if(!r)break;if(e===r.left){let o=r.right;(o==null?void 0:o.color)==="RED"&&(o.color="BLACK",r.color="RED",this._leftRotate(r),o=r.right),((n=(t=o==null?void 0:o.left)==null?void 0:t.color)!=null?n:"BLACK")==="BLACK"?(o&&(o.color="RED"),e=r):(o!=null&&o.left&&(o.left.color="BLACK"),o&&(o.color=r.color),r.color="BLACK",this._rightRotate(r),e=this.root)}else{let o=r.left;(o==null?void 0:o.color)==="RED"&&(o.color="BLACK",r&&(r.color="RED"),this._rightRotate(r),r&&(o=r.left)),((s=(i=o==null?void 0:o.right)==null?void 0:i.color)!=null?s:"BLACK")==="BLACK"?(o&&(o.color="RED"),e=r):(o!=null&&o.right&&(o.right.color="BLACK"),o&&(o.color=r.color),r&&(r.color="BLACK"),this._leftRotate(r),e=this.root)}}e&&(e.color="BLACK")}_leftRotate(e){if(!e||!e.right)return;let t=e.right;e.right=t.left,t.left&&t.left!==this.NIL&&(t.left.parent=e),t.parent=e.parent,e.parent?e===e.parent.left?e.parent.left=t:e.parent.right=t:this._setRoot(t),t.left=e,e.parent=t}_rightRotate(e){if(!e||!e.left)return;let t=e.left;e.left=t.right,t.right&&t.right!==this.NIL&&(t.right.parent=e),t.parent=e.parent,e.parent?e===e.parent.left?e.parent.left=t:e.parent.right=t:this._setRoot(t),t.right=e,e.parent=t}};var x=class{constructor(l,e=[],t="BLACK"){f(this,"key");f(this,"value");f(this,"parent");f(this,"_left");f(this,"_right");f(this,"_height",0);f(this,"_color","BLACK");f(this,"_count",1);this.key=l,this.value=e,this.color=t}get left(){return this._left}set left(l){l&&(l.parent=this),this._left=l}get right(){return this._right}set right(l){l&&(l.parent=this),this._right=l}get height(){return this._height}set height(l){this._height=l}get color(){return this._color}set color(l){this._color=l}get count(){return this._count}set count(l){this._count=l}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"}},G=class extends L{constructor(l=[],e){super([],{...e}),l&&this.addMany(l)}createNode(l,e=[]){return new x(l,this._isMapMode?[]:e)}isNode(l){return l instanceof x}add(l,e){if(this.isRealNode(l))return super.add(l);let t=(n,i)=>{if(n==null)return!1;let s=()=>{let o=this.get(n);if(o!==void 0&&i!==void 0){for(let d of i)o.push(d);return!0}return!1},r=()=>{let o=this.getNode(n);if(this.isRealNode(o)){let d=this.get(o);if(d===void 0)return super.add(n,i),!0;if(i!==void 0){for(let u of i)d.push(u);return!0}else return!1}else return super.add(n,i)};return this._isMapMode?r()||s():s()||r()};if(this.isEntry(l)){let[n,i]=l;return t(n,e!==void 0?[e]:i)}return t(l,e!==void 0?[e]:void 0)}deleteValue(l,e){let t=this.get(l);if(Array.isArray(t)){let n=t.indexOf(e);return n===-1?!1:(t.splice(n,1),t.length===0&&this.delete(l),!0)}return!1}map(l,e,t){let n=this._createLike([],e),i=0;for(let[s,r]of this)n.add(l.call(t,s,r,i++,this));return n}_createInstance(l){var t,n;let e=this.constructor;return new e([],{...(n=(t=this._snapshotOptions)==null?void 0:t.call(this))!=null?n:{},...l!=null?l:{}})}_createLike(l=[],e){var n,i;let t=this.constructor;return new t(l,{...(i=(n=this._snapshotOptions)==null?void 0:n.call(this))!=null?i:{},...e!=null?e:{}})}};return ee(ie);})();
|
|
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=tree-multimap-typed.min.js.map
|