data-structure-typed 2.4.2 → 2.4.3
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/CHANGELOG.md +1 -1
- package/dist/cjs/index.cjs +30 -0
- package/dist/cjs-legacy/index.cjs +30 -0
- package/dist/esm/index.mjs +30 -0
- package/dist/esm-legacy/index.mjs +30 -0
- package/dist/types/data-structures/binary-tree/tree-map.d.ts +10 -0
- package/dist/types/data-structures/binary-tree/tree-set.d.ts +10 -0
- package/dist/umd/data-structure-typed.js +30 -0
- package/dist/umd/data-structure-typed.min.js +2 -2
- package/package.json +2 -2
- package/src/data-structures/binary-tree/tree-map.ts +16 -0
- package/src/data-structures/binary-tree/tree-set.ts +16 -0
package/CHANGELOG.md
CHANGED
|
@@ -8,7 +8,7 @@ All notable changes to this project will be documented in this file.
|
|
|
8
8
|
- [Semantic Versioning](https://semver.org/spec/v2.0.0.html)
|
|
9
9
|
- [`auto-changelog`](https://github.com/CookPete/auto-changelog)
|
|
10
10
|
|
|
11
|
-
## [v2.4.
|
|
11
|
+
## [v2.4.3](https://github.com/zrwusa/data-structure-typed/compare/v2.2.3...main) (upcoming)
|
|
12
12
|
|
|
13
13
|
## [v2.2.3](https://github.com/zrwusa/data-structure-typed/compare/v2.2.2...v2.2.3) (6 January 2026)
|
|
14
14
|
|
package/dist/cjs/index.cjs
CHANGED
|
@@ -12175,6 +12175,21 @@ var TreeSet = class _TreeSet {
|
|
|
12175
12175
|
}
|
|
12176
12176
|
return out;
|
|
12177
12177
|
}
|
|
12178
|
+
/**
|
|
12179
|
+
* Creates a shallow clone of this set.
|
|
12180
|
+
* @remarks Time O(n log n), Space O(n)
|
|
12181
|
+
* @example
|
|
12182
|
+
* const original = new TreeSet([1, 2, 3]);
|
|
12183
|
+
* const copy = original.clone();
|
|
12184
|
+
* copy.add(4);
|
|
12185
|
+
* original.has(4); // false (original unchanged)
|
|
12186
|
+
*/
|
|
12187
|
+
clone() {
|
|
12188
|
+
return new _TreeSet(this, {
|
|
12189
|
+
comparator: this.#isDefaultComparator ? void 0 : this.#userComparator,
|
|
12190
|
+
isMapMode: this.#core.isMapMode
|
|
12191
|
+
});
|
|
12192
|
+
}
|
|
12178
12193
|
};
|
|
12179
12194
|
|
|
12180
12195
|
// src/data-structures/binary-tree/tree-multi-map.ts
|
|
@@ -12989,6 +13004,21 @@ var TreeMap = class _TreeMap {
|
|
|
12989
13004
|
}
|
|
12990
13005
|
return out;
|
|
12991
13006
|
}
|
|
13007
|
+
/**
|
|
13008
|
+
* Creates a shallow clone of this map.
|
|
13009
|
+
* @remarks Time O(n log n), Space O(n)
|
|
13010
|
+
* @example
|
|
13011
|
+
* const original = new TreeMap([['a', 1], ['b', 2]]);
|
|
13012
|
+
* const copy = original.clone();
|
|
13013
|
+
* copy.set('c', 3);
|
|
13014
|
+
* original.has('c'); // false (original unchanged)
|
|
13015
|
+
*/
|
|
13016
|
+
clone() {
|
|
13017
|
+
return new _TreeMap(this, {
|
|
13018
|
+
comparator: this.#isDefaultComparator ? void 0 : this.#userComparator,
|
|
13019
|
+
isMapMode: this.#core.isMapMode
|
|
13020
|
+
});
|
|
13021
|
+
}
|
|
12992
13022
|
};
|
|
12993
13023
|
|
|
12994
13024
|
// src/data-structures/binary-tree/tree-multi-set.ts
|
|
@@ -12167,6 +12167,21 @@ var _TreeSet = class _TreeSet {
|
|
|
12167
12167
|
}
|
|
12168
12168
|
return out;
|
|
12169
12169
|
}
|
|
12170
|
+
/**
|
|
12171
|
+
* Creates a shallow clone of this set.
|
|
12172
|
+
* @remarks Time O(n log n), Space O(n)
|
|
12173
|
+
* @example
|
|
12174
|
+
* const original = new TreeSet([1, 2, 3]);
|
|
12175
|
+
* const copy = original.clone();
|
|
12176
|
+
* copy.add(4);
|
|
12177
|
+
* original.has(4); // false (original unchanged)
|
|
12178
|
+
*/
|
|
12179
|
+
clone() {
|
|
12180
|
+
return new _TreeSet(this, {
|
|
12181
|
+
comparator: __privateGet(this, _isDefaultComparator) ? void 0 : __privateGet(this, _userComparator),
|
|
12182
|
+
isMapMode: __privateGet(this, _core).isMapMode
|
|
12183
|
+
});
|
|
12184
|
+
}
|
|
12170
12185
|
};
|
|
12171
12186
|
_core = new WeakMap();
|
|
12172
12187
|
_isDefaultComparator = new WeakMap();
|
|
@@ -12988,6 +13003,21 @@ var _TreeMap = class _TreeMap {
|
|
|
12988
13003
|
}
|
|
12989
13004
|
return out;
|
|
12990
13005
|
}
|
|
13006
|
+
/**
|
|
13007
|
+
* Creates a shallow clone of this map.
|
|
13008
|
+
* @remarks Time O(n log n), Space O(n)
|
|
13009
|
+
* @example
|
|
13010
|
+
* const original = new TreeMap([['a', 1], ['b', 2]]);
|
|
13011
|
+
* const copy = original.clone();
|
|
13012
|
+
* copy.set('c', 3);
|
|
13013
|
+
* original.has('c'); // false (original unchanged)
|
|
13014
|
+
*/
|
|
13015
|
+
clone() {
|
|
13016
|
+
return new _TreeMap(this, {
|
|
13017
|
+
comparator: __privateGet(this, _isDefaultComparator3) ? void 0 : __privateGet(this, _userComparator2),
|
|
13018
|
+
isMapMode: __privateGet(this, _core3).isMapMode
|
|
13019
|
+
});
|
|
13020
|
+
}
|
|
12991
13021
|
};
|
|
12992
13022
|
_core3 = new WeakMap();
|
|
12993
13023
|
_isDefaultComparator3 = new WeakMap();
|
package/dist/esm/index.mjs
CHANGED
|
@@ -12173,6 +12173,21 @@ var TreeSet = class _TreeSet {
|
|
|
12173
12173
|
}
|
|
12174
12174
|
return out;
|
|
12175
12175
|
}
|
|
12176
|
+
/**
|
|
12177
|
+
* Creates a shallow clone of this set.
|
|
12178
|
+
* @remarks Time O(n log n), Space O(n)
|
|
12179
|
+
* @example
|
|
12180
|
+
* const original = new TreeSet([1, 2, 3]);
|
|
12181
|
+
* const copy = original.clone();
|
|
12182
|
+
* copy.add(4);
|
|
12183
|
+
* original.has(4); // false (original unchanged)
|
|
12184
|
+
*/
|
|
12185
|
+
clone() {
|
|
12186
|
+
return new _TreeSet(this, {
|
|
12187
|
+
comparator: this.#isDefaultComparator ? void 0 : this.#userComparator,
|
|
12188
|
+
isMapMode: this.#core.isMapMode
|
|
12189
|
+
});
|
|
12190
|
+
}
|
|
12176
12191
|
};
|
|
12177
12192
|
|
|
12178
12193
|
// src/data-structures/binary-tree/tree-multi-map.ts
|
|
@@ -12987,6 +13002,21 @@ var TreeMap = class _TreeMap {
|
|
|
12987
13002
|
}
|
|
12988
13003
|
return out;
|
|
12989
13004
|
}
|
|
13005
|
+
/**
|
|
13006
|
+
* Creates a shallow clone of this map.
|
|
13007
|
+
* @remarks Time O(n log n), Space O(n)
|
|
13008
|
+
* @example
|
|
13009
|
+
* const original = new TreeMap([['a', 1], ['b', 2]]);
|
|
13010
|
+
* const copy = original.clone();
|
|
13011
|
+
* copy.set('c', 3);
|
|
13012
|
+
* original.has('c'); // false (original unchanged)
|
|
13013
|
+
*/
|
|
13014
|
+
clone() {
|
|
13015
|
+
return new _TreeMap(this, {
|
|
13016
|
+
comparator: this.#isDefaultComparator ? void 0 : this.#userComparator,
|
|
13017
|
+
isMapMode: this.#core.isMapMode
|
|
13018
|
+
});
|
|
13019
|
+
}
|
|
12990
13020
|
};
|
|
12991
13021
|
|
|
12992
13022
|
// src/data-structures/binary-tree/tree-multi-set.ts
|
|
@@ -12165,6 +12165,21 @@ var _TreeSet = class _TreeSet {
|
|
|
12165
12165
|
}
|
|
12166
12166
|
return out;
|
|
12167
12167
|
}
|
|
12168
|
+
/**
|
|
12169
|
+
* Creates a shallow clone of this set.
|
|
12170
|
+
* @remarks Time O(n log n), Space O(n)
|
|
12171
|
+
* @example
|
|
12172
|
+
* const original = new TreeSet([1, 2, 3]);
|
|
12173
|
+
* const copy = original.clone();
|
|
12174
|
+
* copy.add(4);
|
|
12175
|
+
* original.has(4); // false (original unchanged)
|
|
12176
|
+
*/
|
|
12177
|
+
clone() {
|
|
12178
|
+
return new _TreeSet(this, {
|
|
12179
|
+
comparator: __privateGet(this, _isDefaultComparator) ? void 0 : __privateGet(this, _userComparator),
|
|
12180
|
+
isMapMode: __privateGet(this, _core).isMapMode
|
|
12181
|
+
});
|
|
12182
|
+
}
|
|
12168
12183
|
};
|
|
12169
12184
|
_core = new WeakMap();
|
|
12170
12185
|
_isDefaultComparator = new WeakMap();
|
|
@@ -12986,6 +13001,21 @@ var _TreeMap = class _TreeMap {
|
|
|
12986
13001
|
}
|
|
12987
13002
|
return out;
|
|
12988
13003
|
}
|
|
13004
|
+
/**
|
|
13005
|
+
* Creates a shallow clone of this map.
|
|
13006
|
+
* @remarks Time O(n log n), Space O(n)
|
|
13007
|
+
* @example
|
|
13008
|
+
* const original = new TreeMap([['a', 1], ['b', 2]]);
|
|
13009
|
+
* const copy = original.clone();
|
|
13010
|
+
* copy.set('c', 3);
|
|
13011
|
+
* original.has('c'); // false (original unchanged)
|
|
13012
|
+
*/
|
|
13013
|
+
clone() {
|
|
13014
|
+
return new _TreeMap(this, {
|
|
13015
|
+
comparator: __privateGet(this, _isDefaultComparator3) ? void 0 : __privateGet(this, _userComparator2),
|
|
13016
|
+
isMapMode: __privateGet(this, _core3).isMapMode
|
|
13017
|
+
});
|
|
13018
|
+
}
|
|
12989
13019
|
};
|
|
12990
13020
|
_core3 = new WeakMap();
|
|
12991
13021
|
_isDefaultComparator3 = new WeakMap();
|
|
@@ -185,4 +185,14 @@ export declare class TreeMap<K = any, V = any, R = [K, V]> implements Iterable<[
|
|
|
185
185
|
* @param options Inclusive/exclusive bounds (defaults to inclusive).
|
|
186
186
|
*/
|
|
187
187
|
rangeSearch(range: [K, K], options?: TreeMapRangeOptions): Array<[K, V | undefined]>;
|
|
188
|
+
/**
|
|
189
|
+
* Creates a shallow clone of this map.
|
|
190
|
+
* @remarks Time O(n log n), Space O(n)
|
|
191
|
+
* @example
|
|
192
|
+
* const original = new TreeMap([['a', 1], ['b', 2]]);
|
|
193
|
+
* const copy = original.clone();
|
|
194
|
+
* copy.set('c', 3);
|
|
195
|
+
* original.has('c'); // false (original unchanged)
|
|
196
|
+
*/
|
|
197
|
+
clone(): TreeMap<K, V>;
|
|
188
198
|
}
|
|
@@ -178,4 +178,14 @@ export declare class TreeSet<K = any, R = K> implements Iterable<K> {
|
|
|
178
178
|
* @param options Inclusive/exclusive bounds (defaults to inclusive).
|
|
179
179
|
*/
|
|
180
180
|
rangeSearch(range: [K, K], options?: TreeSetRangeOptions): K[];
|
|
181
|
+
/**
|
|
182
|
+
* Creates a shallow clone of this set.
|
|
183
|
+
* @remarks Time O(n log n), Space O(n)
|
|
184
|
+
* @example
|
|
185
|
+
* const original = new TreeSet([1, 2, 3]);
|
|
186
|
+
* const copy = original.clone();
|
|
187
|
+
* copy.add(4);
|
|
188
|
+
* original.has(4); // false (original unchanged)
|
|
189
|
+
*/
|
|
190
|
+
clone(): TreeSet<K>;
|
|
181
191
|
}
|
|
@@ -12160,6 +12160,21 @@ var dataStructureTyped = (() => {
|
|
|
12160
12160
|
}
|
|
12161
12161
|
return out;
|
|
12162
12162
|
}
|
|
12163
|
+
/**
|
|
12164
|
+
* Creates a shallow clone of this set.
|
|
12165
|
+
* @remarks Time O(n log n), Space O(n)
|
|
12166
|
+
* @example
|
|
12167
|
+
* const original = new TreeSet([1, 2, 3]);
|
|
12168
|
+
* const copy = original.clone();
|
|
12169
|
+
* copy.add(4);
|
|
12170
|
+
* original.has(4); // false (original unchanged)
|
|
12171
|
+
*/
|
|
12172
|
+
clone() {
|
|
12173
|
+
return new _TreeSet(this, {
|
|
12174
|
+
comparator: __privateGet(this, _isDefaultComparator) ? void 0 : __privateGet(this, _userComparator),
|
|
12175
|
+
isMapMode: __privateGet(this, _core).isMapMode
|
|
12176
|
+
});
|
|
12177
|
+
}
|
|
12163
12178
|
};
|
|
12164
12179
|
_core = new WeakMap();
|
|
12165
12180
|
_isDefaultComparator = new WeakMap();
|
|
@@ -12977,6 +12992,21 @@ var dataStructureTyped = (() => {
|
|
|
12977
12992
|
}
|
|
12978
12993
|
return out;
|
|
12979
12994
|
}
|
|
12995
|
+
/**
|
|
12996
|
+
* Creates a shallow clone of this map.
|
|
12997
|
+
* @remarks Time O(n log n), Space O(n)
|
|
12998
|
+
* @example
|
|
12999
|
+
* const original = new TreeMap([['a', 1], ['b', 2]]);
|
|
13000
|
+
* const copy = original.clone();
|
|
13001
|
+
* copy.set('c', 3);
|
|
13002
|
+
* original.has('c'); // false (original unchanged)
|
|
13003
|
+
*/
|
|
13004
|
+
clone() {
|
|
13005
|
+
return new _TreeMap(this, {
|
|
13006
|
+
comparator: __privateGet(this, _isDefaultComparator3) ? void 0 : __privateGet(this, _userComparator2),
|
|
13007
|
+
isMapMode: __privateGet(this, _core3).isMapMode
|
|
13008
|
+
});
|
|
13009
|
+
}
|
|
12980
13010
|
};
|
|
12981
13011
|
_core3 = new WeakMap();
|
|
12982
13012
|
_isDefaultComparator3 = new WeakMap();
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
"use strict";var dataStructureTyped=(()=>{var Re=Object.defineProperty;var mt=Object.getOwnPropertyDescriptor;var Kt=Object.getOwnPropertyNames;var Vt=Object.prototype.hasOwnProperty;var ct=h=>{throw TypeError(h)};var yt=(h,i,e)=>i in h?Re(h,i,{enumerable:!0,configurable:!0,writable:!0,value:e}):h[i]=e;var Tt=(h,i)=>{for(var e in i)Re(h,e,{get:i[e],enumerable:!0})},Et=(h,i,e,t)=>{if(i&&typeof i=="object"||typeof i=="function")for(let n of Kt(i))!Vt.call(h,n)&&n!==e&&Re(h,n,{get:()=>i[n],enumerable:!(t=mt(i,n))||t.enumerable});return h};var Nt=h=>Et(Re({},"__esModule",{value:!0}),h);var u=(h,i,e)=>yt(h,typeof i!="symbol"?i+"":i,e),pt=(h,i,e)=>i.has(h)||ct("Cannot "+e);var _=(h,i,e)=>(pt(h,i,"read from private field"),e?e.call(h):i.get(h)),C=(h,i,e)=>i.has(h)?ct("Cannot add the same private member more than once"):i instanceof WeakSet?i.add(h):i.set(h,e),S=(h,i,e,t)=>(pt(h,i,"write to private field"),t?t.call(h,e):i.set(h,e),e);var Bt={};Tt(Bt,{AVLTree:()=>tt,AVLTreeNode:()=>_e,AbstractEdge:()=>q,AbstractGraph:()=>X,AbstractVertex:()=>v,BST:()=>J,BSTNode:()=>pe,BinaryIndexedTree:()=>Ze,BinaryTree:()=>ce,BinaryTreeNode:()=>oe,Character:()=>Ce,DFSOperation:()=>Ye,Deque:()=>Ge,DirectedEdge:()=>se,DirectedGraph:()=>fe,DirectedVertex:()=>$,DoublyLinkedList:()=>je,DoublyLinkedListNode:()=>ue,FibonacciHeap:()=>We,FibonacciHeapNode:()=>Le,HashMap:()=>ze,Heap:()=>D,IterableElementBase:()=>F,IterableEntryBase:()=>z,LinkedHashMap:()=>Pe,LinkedListQueue:()=>qe,MapEdge:()=>we,MapGraph:()=>Je,MapVertex:()=>ve,Matrix:()=>at,MaxHeap:()=>Qe,MaxPriorityQueue:()=>dt,MinHeap:()=>Xe,MinPriorityQueue:()=>ot,Navigator:()=>lt,PriorityQueue:()=>ee,Queue:()=>O,Range:()=>H,RedBlackTree:()=>A,RedBlackTreeNode:()=>G,SegmentTree:()=>et,SegmentTreeNode:()=>de,SinglyLinkedList:()=>le,SinglyLinkedListNode:()=>re,SkipList:()=>He,SkipListNode:()=>he,Stack:()=>Ue,TreeMap:()=>rt,TreeMultiMap:()=>it,TreeMultiMapNode:()=>nt,TreeMultiSet:()=>st,TreeNode:()=>ht,TreeSet:()=>Y,Trie:()=>ut,TrieNode:()=>ae,UndirectedEdge:()=>Ie,UndirectedGraph:()=>$e,UndirectedVertex:()=>Be,arrayRemove:()=>P,asyncTrampoline:()=>bt,calcMinUnitsRequired:()=>ke,getMSB:()=>De,isComparable:()=>Q,isTrampolineThunk:()=>Ae,isWeakKey:()=>W,makeAsyncTrampoline:()=>Mt,makeTrampoline:()=>xe,makeTrampolineThunk:()=>Me,rangeCheck:()=>j,roundFixed:()=>kt,throwRangeError:()=>Rt,toBinaryString:()=>xt,trampoline:()=>gt,uuidV4:()=>Fe});var z=class{*[Symbol.iterator](...i){yield*this._getIterator(...i)}*entries(){for(let i of this)yield i}*keys(){for(let i of this)yield i[0]}*values(){for(let i of this)yield i[1]}every(i,e){let t=0;for(let n of this)if(!i.call(e,n[1],n[0],t++,this))return!1;return!0}some(i,e){let t=0;for(let n of this)if(i.call(e,n[1],n[0],t++,this))return!0;return!1}forEach(i,e){let t=0;for(let n of this){let[r,s]=n;i.call(e,s,r,t++,this)}}find(i,e){let t=0;for(let n of this){let[r,s]=n;if(i.call(e,s,r,t++,this))return n}}has(i){for(let e of this){let[t]=e;if(t===i)return!0}return!1}hasValue(i){for(let[,e]of this)if(e===i)return!0;return!1}get(i){for(let e of this){let[t,n]=e;if(t===i)return n}}reduce(i,e){let t=e,n=0;for(let r of this){let[s,o]=r;t=i(t,o,s,n++,this)}return t}toArray(){return[...this]}toVisual(){return[...this]}print(){console.log(this.toVisual())}};var F=class{constructor(i){u(this,"_toElementFn");if(i){let{toElementFn:e}=i;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](...i){yield*this._getIterator(...i)}*values(){for(let i of this)yield i}every(i,e){let t=0;for(let n of this)if(e===void 0){if(!i(n,t++,this))return!1}else if(!i.call(e,n,t++,this))return!1;return!0}some(i,e){let t=0;for(let n of this)if(e===void 0){if(i(n,t++,this))return!0}else if(i.call(e,n,t++,this))return!0;return!1}forEach(i,e){let t=0;for(let n of this)e===void 0?i(n,t++,this):i.call(e,n,t++,this)}find(i,e){let t=0;for(let n of this)if(e===void 0){if(i(n,t++,this))return n}else if(i.call(e,n,t++,this))return n}has(i){for(let e of this)if(e===i)return!0;return!1}reduce(i,e){let t=0,n=this[Symbol.iterator](),r;if(arguments.length>=2)r=e;else{let s=n.next();if(s.done)throw new TypeError("Reduce of empty structure with no initial value");r=s.value,t=1}for(let s of n)r=i(r,s,t++,this);return r}toArray(){return[...this]}toVisual(){return[...this]}print(){console.log(this.toVisual())}};var Fe=function(){return"xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx".replace(/[x]/g,function(h){let i=Math.random()*16|0;return(h=="x"?i:i&3|8).toString(16)})},P=function(h,i){let e=-1,t=h?h.length:0,n=[];for(;++e<t;){let r=h[e];i(r,e,h)&&(n.push(r),Array.prototype.splice.call(h,e--,1),t--)}return n},De=h=>h<=0?0:1<<31-Math.clz32(h),j=(h,i,e,t="Index out of bounds.")=>{if(h<i||h>e)throw new RangeError(t)},Rt=(h="The value is off-limits.")=>{throw new RangeError(h)},W=h=>{let i=typeof h;return i==="object"&&h!==null||i==="function"},ke=(h,i)=>Math.floor((h+i-1)/i),kt=(h,i=10)=>{let e=Math.pow(10,i);return Math.round(h*e)/e};function Oe(h){let i=typeof h;return i==="number"?!0:i==="bigint"||i==="string"||i==="boolean"}function _t(h){if(typeof h.valueOf=="function"){let i=h.valueOf();if(i!==h){if(Oe(i))return i;if(typeof i=="object"&&i!==null)return _t(i)}}if(typeof h.toString=="function"){let i=h.toString();if(i!=="[object Object]")return i}return null}function Q(h,i=!1){if(h==null)return!1;if(Oe(h))return!0;if(typeof h!="object")return!1;if(h instanceof Date||i)return!0;let e=_t(h);return e==null?!1:Oe(e)}var Me=h=>({isThunk:!0,fn:h}),Ae=h=>typeof h=="object"&&h!==null&&"isThunk"in h&&h.isThunk;function gt(h){let i=h;for(;Ae(i);)i=i.fn();return i}function xe(h){return(...i)=>gt(h(...i))}async function bt(h){let i=await h;for(;Ae(i);)i=await i.fn();return i}function Mt(h){return async(...i)=>bt(h(...i))}function xt(h,i=32){let e=(h>>>0).toString(2);return e=e.padStart(i,"0"),e}var ze=class extends z{constructor(e=[],t){super();u(this,"_store",{});u(this,"_objMap",new Map);u(this,"_toEntryFn");u(this,"_size",0);u(this,"_hashFn",e=>String(e));if(t){let{hashFn:n,toEntryFn:r}=t;n&&(this._hashFn=n),r&&(this._toEntryFn=r)}e&&this.setMany(e)}get store(){return this._store}get objMap(){return this._objMap}get toEntryFn(){return this._toEntryFn}get size(){return this._size}get hashFn(){return this._hashFn}isEmpty(){return this._size===0}clear(){this._store={},this._objMap.clear(),this._size=0}isEntry(e){return Array.isArray(e)&&e.length===2}set(e,t){if(this._isObjKey(e))this.objMap.has(e)||this._size++,this.objMap.set(e,t);else{let n=this._getNoObjKey(e);this.store[n]===void 0&&this._size++,this._store[n]={key:e,value:t}}return!0}setMany(e){let t=[];for(let n of e){let r,s;this.isEntry(n)?[r,s]=n:this._toEntryFn&&([r,s]=this._toEntryFn(n)),r!==void 0&&s!==void 0&&t.push(this.set(r,s))}return t}get(e){var n;if(this._isObjKey(e))return this.objMap.get(e);let t=this._getNoObjKey(e);return(n=this._store[t])==null?void 0:n.value}has(e){return this._isObjKey(e)?this.objMap.has(e):this._getNoObjKey(e)in this.store}delete(e){if(this._isObjKey(e))return this.objMap.has(e)&&this._size--,this.objMap.delete(e);let t=this._getNoObjKey(e);return t in this.store?(delete this.store[t],this._size--,!0):!1}setHashFn(e){return this._hashFn===e?this:(this._hashFn=e,this._rehashNoObj(),this)}clone(){let e={hashFn:this._hashFn,toEntryFn:this._toEntryFn};return this._createLike(this,e)}map(e,t){let n=this._createLike(),r=0;for(let[s,o]of this)n.set(s,e.call(t,o,s,r++,this));return n}filter(e,t){let n=this._createLike(),r=0;for(let[s,o]of this)e.call(t,o,s,r++,this)&&n.set(s,o);return n}_createLike(e=[],t){let n=this.constructor;return new n(e,t)}_rehashNoObj(){let e={};for(let{key:t,value:n}of Object.values(this._store)){let r=this._getNoObjKey(t);e[r]={key:t,value:n}}this._store=e}*_getIterator(){for(let e of Object.values(this.store))yield[e.key,e.value];for(let e of this.objMap)yield e}_isObjKey(e){let t=typeof e;return(t==="object"||t==="function")&&e!==null}_getNoObjKey(e){let t=typeof e,n;return t!=="string"&&t!=="number"&&t!=="symbol"?n=this._hashFn(e):n=e,n}},Pe=class extends z{constructor(e=[],t){super();u(this,"_sentinel");u(this,"_hashFn",e=>String(e));u(this,"_objHashFn",e=>e);u(this,"_noObjMap",{});u(this,"_objMap",new WeakMap);u(this,"_head");u(this,"_tail");u(this,"_toEntryFn",e=>{if(this.isEntry(e))return e;throw new Error("If `entryOrRawElements` does not adhere to [key,value], provide `options.toEntryFn` to transform raw records.")});u(this,"_size",0);if(this._sentinel={},this._sentinel.prev=this._sentinel.next=this._head=this._tail=this._sentinel,t){let{hashFn:n,objHashFn:r,toEntryFn:s}=t;n&&(this._hashFn=n),r&&(this._objHashFn=r),s&&(this._toEntryFn=s)}e&&this.setMany(e)}get hashFn(){return this._hashFn}get objHashFn(){return this._objHashFn}get noObjMap(){return this._noObjMap}get objMap(){return this._objMap}get head(){return this._head}get tail(){return this._tail}get toEntryFn(){return this._toEntryFn}get size(){return this._size}get first(){if(this._size!==0)return[this.head.key,this.head.value]}get last(){if(this._size!==0)return[this.tail.key,this.tail.value]}*begin(){let e=this.head;for(;e!==this._sentinel;)yield[e.key,e.value],e=e.next}*reverseBegin(){let e=this.tail;for(;e!==this._sentinel;)yield[e.key,e.value],e=e.prev}set(e,t){let n,r=!this.has(e);if(W(e)){let s=this._objHashFn(e);n=this.objMap.get(s),!n&&r?(n={key:s,value:t,prev:this.tail,next:this._sentinel},this.objMap.set(s,n)):n&&(n.value=t)}else{let s=this._hashFn(e);n=this.noObjMap[s],!n&&r?this.noObjMap[s]=n={key:e,value:t,prev:this.tail,next:this._sentinel}:n&&(n.value=t)}return n&&r&&(this._size===0?(this._head=n,this._sentinel.next=n):(this.tail.next=n,n.prev=this.tail),this._tail=n,this._sentinel.prev=n,this._size++),!0}setMany(e){let t=[];for(let n of e){let r,s;this.isEntry(n)?[r,s]=n:this._toEntryFn&&([r,s]=this._toEntryFn(n)),r!==void 0&&s!==void 0&&t.push(this.set(r,s))}return t}has(e){if(W(e)){let n=this._objHashFn(e);return this.objMap.has(n)}return this._hashFn(e)in this.noObjMap}get(e){if(W(e)){let r=this._objHashFn(e),s=this.objMap.get(r);return s?s.value:void 0}let t=this._hashFn(e),n=this.noObjMap[t];return n?n.value:void 0}at(e){j(e,0,this._size-1);let t=this.head;for(;e--;)t=t.next;return t.value}delete(e){let t;if(W(e)){let n=this._objHashFn(e);if(t=this.objMap.get(n),!t)return!1;this.objMap.delete(n)}else{let n=this._hashFn(e);if(t=this.noObjMap[n],!t)return!1;delete this.noObjMap[n]}return this._deleteNode(t)}deleteWhere(e){let t=this._head,n=0;for(;t!==this._sentinel;){let r=t;if(t=t.next,e(r.key,r.value,n++,this)){if(W(r.key))this._objMap.delete(r.key);else{let s=this._hashFn(r.key);delete this._noObjMap[s]}return this._deleteNode(r)}}return!1}deleteAt(e){j(e,0,this._size-1);let t=this.head;for(;e--;)t=t.next;return this._deleteNode(t)}isEmpty(){return this._size===0}isEntry(e){return Array.isArray(e)&&e.length===2}clear(){this._noObjMap={},this._size=0,this._head=this._tail=this._sentinel.prev=this._sentinel.next=this._sentinel}clone(){let e={hashFn:this._hashFn,objHashFn:this._objHashFn};return this._createLike(this,e)}filter(e,t){let n=this._createLike(),r=0;for(let[s,o]of this)e.call(t,o,s,r,this)&&n.set(s,o),r++;return n}map(e,t){let n=this._createLike(),r=0;for(let[s,o]of this){let[d,a]=e.call(t,o,s,r,this);n.set(d,a),r++}return n}*_getIterator(){let e=this.head;for(;e!==this._sentinel;)yield[e.key,e.value],e=e.next}_deleteNode(e){let{prev:t,next:n}=e;return t.next=n,n.prev=t,e===this.head&&(this._head=n),e===this.tail&&(this._tail=t),this._size-=1,!0}_createLike(e=[],t){let n=this.constructor;return new n(e,t)}};var ne=class{constructor(i){u(this,"_value");u(this,"_next");this._value=i,this._next=void 0}get value(){return this._value}set value(i){this._value=i}get next(){return this._next}set next(i){this._next=i}},U=class h extends F{constructor(e){super(e);u(this,"_maxLen",-1);if(e){let{maxLen:t}=e;typeof t=="number"&&t>0&&t%1===0&&(this._maxLen=t)}}get maxLen(){return this._maxLen}indexOf(e,t=0){if(this.length===0)return-1;t<0&&(t=this.length+t),t<0&&(t=0);for(let n=t;n<this.length;n++)if(this.at(n)===e)return n;return-1}lastIndexOf(e,t=this.length-1){if(this.length===0)return-1;t>=this.length&&(t=this.length-1),t<0&&(t=this.length+t);for(let n=t;n>=0;n--)if(this.at(n)===e)return n;return-1}findIndex(e,t){for(let n=0;n<this.length;n++){let r=this.at(n);if(r!==void 0&&e.call(t,r,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 r=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 o=this.deleteAt(e);o!==void 0&&r.push(o)}for(let s=0;s<n.length;s++)this.addAt(e+s,n[s]);return r}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 r=this.length-1;r>=0;r--)n=e(n,this.at(r),r,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 r=e;r<t;r++)n.push(this.at(r));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 r=t;r<n;r++)this.setAt(r,e);return this}},ie=class extends U{constructor(i){if(super(i),i){let{maxLen:e}=i;typeof e=="number"&&e>0&&e%1===0&&(this._maxLen=e)}}indexOf(i,e=0){let t=this._getIterator(),n=t.next(),r=0;for(;r<e;)n=t.next(),r++;for(;!n.done;){if(n.value===i)return r;n=t.next(),r++}return-1}lastIndexOf(i,e=this.length-1){let t=this._getReverseIterator(),n=t.next(),r=this.length-1;for(;r>e;)n=t.next(),r--;for(;!n.done;){if(n.value===i)return r;n=t.next(),r--}return-1}concat(...i){let e=this.clone();for(let t of i)t instanceof U?e.pushMany(t):e.push(t);return e}slice(i=0,e=this.length){i=i<0?this.length+i:i,e=e<0?this.length+e:e;let t=this._createInstance(),n=this._getIterator(),r=n.next(),s=0;for(;s<i;)r=n.next(),s++;for(let o=i;o<e;o++)t.push(r.value),r=n.next();return t}splice(i,e=0,...t){let n=this._createInstance();i=i<0?this.length+i:i,i=Math.max(0,Math.min(i,this.length)),e=Math.max(0,e);let r=0,s,o,d=this._getNodeIterator();for(let a of d){if(r===i){s=a;break}o=a,r++}for(let a=0;a<e&&s;a++){n.push(s.value);let l=s.next;this.delete(s),s=l}for(let a=0;a<t.length;a++)o?(this.addAfter(o,t[a]),o=o.next):(this.addAt(0,t[a]),o=this._getNodeIterator().next().value);return n}reduceRight(i,e){let t=e!=null?e:0,n=this.length-1;for(let r of this._getReverseIterator())t=i(t,r,n--,this);return t}};var re=class extends ne{constructor(e){super(e);u(this,"_next");this._value=e,this._next=void 0}get next(){return this._next}set next(e){this._next=e}},le=class extends ie{constructor(e=[],t){super(t);u(this,"_equals",Object.is);u(this,"_head");u(this,"_tail");u(this,"_length",0);this.pushMany(e)}get head(){return this._head}get tail(){return this._tail}get length(){return this._length}get first(){var e;return(e=this.head)==null?void 0:e.value}get last(){var e;return(e=this.tail)==null?void 0:e.value}static from(e,t){let n=new this([],t);for(let r of e)n.push(r);return n}push(e){let t=this._ensureNode(e);return this.head?(this.tail.next=t,this._tail=t):this._head=this._tail=t,this._length++,this._maxLen>0&&this.length>this._maxLen&&this.shift(),!0}pop(){if(!this.head)return;if(this.head===this.tail){let n=this.head.value;return this._head=void 0,this._tail=void 0,this._length--,n}let e=this.head;for(;e.next!==this.tail;)e=e.next;let t=this.tail.value;return e.next=void 0,this._tail=e,this._length--,t}shift(){if(!this.head)return;let e=this.head;return this._head=this.head.next,this._head||(this._tail=void 0),this._length--,e.value}unshift(e){let t=this._ensureNode(e);return this.head?(t.next=this.head,this._head=t):this._head=this._tail=t,this._length++,!0}pushMany(e){let t=[];for(let n of e)this.toElementFn?t.push(this.push(this.toElementFn(n))):t.push(this.push(n));return t}unshiftMany(e){let t=[];for(let n of e)this.toElementFn?t.push(this.unshift(this.toElementFn(n))):t.push(this.unshift(n));return t}search(e){let t=this._ensurePredicate(e),n=this.head;for(;n;){if(t(n))return n.value;n=n.next}}at(e){if(e<0||e>=this._length)return;let t=this.head;for(let n=0;n<e;n++)t=t.next;return t.value}isNode(e){return e instanceof re}getNodeAt(e){if(e<0||e>=this._length)return;let t=this.head;for(let n=0;n<e;n++)t=t.next;return t}deleteAt(e){if(e<0||e>=this._length)return;if(e===0)return this.shift();let t=this.getNodeAt(e),n=this._getPrevNode(t),r=t.value;return n.next=t.next,t===this.tail&&(this._tail=n),this._length--,r}delete(e){if(e===void 0||!this.head)return!1;let t=this.isNode(e)?e:this.getNode(e);if(!t)return!1;let n=this._getPrevNode(t);return n?(n.next=t.next,t===this.tail&&(this._tail=n)):(this._head=t.next,t===this.tail&&(this._tail=void 0)),this._length--,!0}addAt(e,t){if(e<0||e>this._length)return!1;if(e===0)return this.unshift(t);if(e===this._length)return this.push(t);let n=this._ensureNode(t),r=this.getNodeAt(e-1);return n.next=r.next,r.next=n,this._length++,!0}setAt(e,t){let n=this.getNodeAt(e);return n?(n.value=t,!0):!1}isEmpty(){return this._length===0}clear(){this._head=void 0,this._tail=void 0,this._length=0}reverse(){if(!this.head||this.head===this.tail)return this;let e,t=this.head,n;for(;t;)n=t.next,t.next=e,e=t,t=n;return[this._head,this._tail]=[this.tail,this.head],this}getNode(e){if(e===void 0)return;if(this.isNode(e))return e;let t=this._ensurePredicate(e),n=this.head;for(;n;){if(t(n))return n;n=n.next}}addBefore(e,t){let n=this.getNode(e);if(!n)return!1;let r=this._getPrevNode(n),s=this._ensureNode(t);return r?(r.next=s,s.next=n,this._length++):(s.next=this._head,this._head=s,this._tail||(this._tail=s),this._length++),!0}addAfter(e,t){let n=this.getNode(e);if(!n)return!1;let r=this._ensureNode(t);return r.next=n.next,n.next=r,n===this.tail&&(this._tail=r),this._length++,!0}splice(e,t=0,...n){e=Math.max(0,Math.min(e,this.length)),t=Math.max(0,t);let r=this._createInstance(),s=e===0?void 0:this.getNodeAt(e-1),o=s?s.next:this.head,d=0;for(;d<t&&o;)r.push(o.value),o=o.next,d++;let a=o;if(s?s.next=a:this._head=a,a||(this._tail=s),n.length>0){let l,f;for(let c of n){let g=this._ensureNode(c);l||(l=g),f&&(f.next=g),f=g}s?s.next=l:this._head=l,f.next=a,a||(this._tail=f)}return this._length+=n.length-d,this._length===0&&(this._head=void 0,this._tail=void 0),r}countOccurrences(e){let t=Lt(e,this._equals),n=0,r=this.head;for(;r;)t(r)&&n++,r=r.next;return n}setEquality(e){return this._equals=e,this}deleteWhere(e){let t,n=this.head,r=0;for(;n;){if(e(n.value,r++,this))return t?(t.next=n.next,n===this._tail&&(this._tail=t)):(this._head=n.next,n===this._tail&&(this._tail=void 0)),this._length--,!0;t=n,n=n.next}return!1}clone(){let e=this._createInstance();for(let t of this)e.push(t);return e}filter(e,t){let n=this._createInstance(),r=0;for(let s of this)e.call(t,s,r++,this)&&n.push(s);return n}mapSame(e,t){let n=this._createInstance(),r=0;for(let s of this){let o=t===void 0?e(s,r++,this):e.call(t,s,r++,this);n.push(o)}return n}map(e,t,n){let r=this._createLike([],{...t!=null?t:{},maxLen:this._maxLen}),s=0;for(let o of this)r.push(e.call(n,o,s++,this));return r}createNode(e){return new re(e)}_isPredicate(e){return typeof e=="function"}_ensureNode(e){return this.isNode(e)?e:this.createNode(e)}_ensurePredicate(e){if(this.isNode(e))return n=>n===e;if(this._isPredicate(e))return e;let t=e;return n=>this._equals(n.value,t)}_getPrevNode(e){if(!this.head||this.head===e)return;let t=this.head;for(;t.next&&t.next!==e;)t=t.next;return t.next===e?t:void 0}*_getIterator(){let e=this.head;for(;e;)yield e.value,e=e.next}*_getReverseIterator(){let e=[...this].reverse();for(let t of e)yield t}*_getNodeIterator(){let e=this.head;for(;e;)yield e,e=e.next}_createInstance(e){let t=this.constructor;return new t([],e)}_createLike(e=[],t){let n=this.constructor;return new n(e,t)}_spawnLike(e){return this._createLike([],e)}};function Lt(h,i){if(h instanceof re)return t=>t===h;if(typeof h=="function")return h;let e=h;return t=>i(t.value,e)}var ue=class extends ne{constructor(e){super(e);u(this,"_next");u(this,"_prev");this._value=e,this._next=void 0,this._prev=void 0}get next(){return this._next}set next(e){this._next=e}get prev(){return this._prev}set prev(e){this._prev=e}},je=class extends ie{constructor(e=[],t){super(t);u(this,"_equals",Object.is);u(this,"_head");u(this,"_tail");u(this,"_length",0);this._head=void 0,this._tail=void 0,this._length=0,t!=null&&t.maxLen&&Number.isInteger(t.maxLen)&&t.maxLen>0&&(this._maxLen=t.maxLen),this.pushMany(e)}get head(){return this._head}get tail(){return this._tail}get length(){return this._length}get first(){var e;return(e=this.head)==null?void 0:e.value}get last(){var e;return(e=this.tail)==null?void 0:e.value}static fromArray(e){return new this(e)}isNode(e){return e instanceof ue}push(e){let t=this._ensureNode(e);return this.head?(t.prev=this.tail,this.tail.next=t,this._tail=t):(this._head=t,this._tail=t),this._length++,this._maxLen>0&&this.length>this._maxLen&&this.shift(),!0}pop(){if(!this.tail)return;let e=this.tail;return this.head===this.tail?(this._head=void 0,this._tail=void 0):(this._tail=e.prev,this.tail.next=void 0),this._length--,e.value}shift(){if(!this.head)return;let e=this.head;return this.head===this.tail?(this._head=void 0,this._tail=void 0):(this._head=e.next,this.head.prev=void 0),this._length--,e.value}unshift(e){let t=this._ensureNode(e);return this.head?(t.next=this.head,this.head.prev=t,this._head=t):(this._head=t,this._tail=t),this._length++,this._maxLen>0&&this._length>this._maxLen&&this.pop(),!0}pushMany(e){let t=[];for(let n of e)this.toElementFn?t.push(this.push(this.toElementFn(n))):t.push(this.push(n));return t}unshiftMany(e){let t=[];for(let n of e)this.toElementFn?t.push(this.unshift(this.toElementFn(n))):t.push(this.unshift(n));return t}at(e){if(e<0||e>=this._length)return;let t=this.head;for(let n=0;n<e;n++)t=t.next;return t.value}getNodeAt(e){if(e<0||e>=this._length)return;let t=this.head;for(let n=0;n<e;n++)t=t.next;return t}getNode(e){if(e===void 0)return;if(this.isNode(e)){let r=e,s=this.head;for(;s;){if(s===r)return r;s=s.next}let o=d=>this._equals(d.value,r.value);for(s=this.head;s;){if(o(s))return s;s=s.next}return}let t=this._ensurePredicate(e),n=this.head;for(;n;){if(t(n))return n;n=n.next}}addAt(e,t){if(e<0||e>this._length)return!1;if(e===0)return this.unshift(t);if(e===this._length)return this.push(t);let n=this._ensureNode(t),r=this.getNodeAt(e-1),s=r.next;return n.prev=r,n.next=s,r.next=n,s.prev=n,this._length++,!0}addBefore(e,t){let n=this.isNode(e)?e:this.getNode(e);if(!n)return!1;let r=this._ensureNode(t);return r.prev=n.prev,n.prev&&(n.prev.next=r),r.next=n,n.prev=r,n===this.head&&(this._head=r),this._length++,!0}addAfter(e,t){let n=this.isNode(e)?e:this.getNode(e);if(!n)return!1;let r=this._ensureNode(t);return r.next=n.next,n.next&&(n.next.prev=r),r.prev=n,n.next=r,n===this.tail&&(this._tail=r),this._length++,!0}setAt(e,t){let n=this.getNodeAt(e);return n?(n.value=t,!0):!1}deleteAt(e){if(e<0||e>=this._length)return;if(e===0)return this.shift();if(e===this._length-1)return this.pop();let t=this.getNodeAt(e),n=t.prev,r=t.next;return n.next=r,r.prev=n,this._length--,t.value}delete(e){let t=this.getNode(e);if(!t)return!1;if(t===this.head)this.shift();else if(t===this.tail)this.pop();else{let n=t.prev,r=t.next;n.next=r,r.prev=n,this._length--}return!0}isEmpty(){return this._length===0}clear(){this._head=void 0,this._tail=void 0,this._length=0}search(e){let t=this._ensurePredicate(e),n=this.head;for(;n;){if(t(n))return n.value;n=n.next}}getBackward(e){let t=this._ensurePredicate(e),n=this.tail;for(;n;){if(t(n))return n.value;n=n.prev}}reverse(){let e=this.head;for([this._head,this._tail]=[this.tail,this.head];e;){let t=e.next;[e.prev,e.next]=[e.next,e.prev],e=t}return this}setEquality(e){return this._equals=e,this}clone(){let e=this._createInstance({toElementFn:this._toElementFn,maxLen:this._maxLen});for(let t of this)e.push(t);return e}filter(e,t){let n=this._createInstance({toElementFn:this._toElementFn,maxLen:this._maxLen}),r=0;for(let s of this)e.call(t,s,r++,this)&&n.push(s);return n}mapSame(e,t){let n=this._createInstance({toElementFn:this._toElementFn,maxLen:this._maxLen}),r=0;for(let s of this){let o=t===void 0?e(s,r++,this):e.call(t,s,r++,this);n.push(o)}return n}map(e,t,n){let r=this._createLike([],{...t!=null?t:{},maxLen:this._maxLen}),s=0;for(let o of this)r.push(e.call(n,o,s++,this));return r}_ensureNode(e){return this.isNode(e)?e:new ue(e)}_ensurePredicate(e){if(this.isNode(e)){let n=e;return r=>r===n}if(typeof e=="function")return e;let t=e;return n=>this._equals(n.value,t)}_getPrevNode(e){return e.prev}_createInstance(e){let t=this.constructor;return new t([],e)}_createLike(e=[],t){let n=this.constructor;return new n(e,t)}*_getIterator(){let e=this.head;for(;e;)yield e.value,e=e.next}*_getReverseIterator(){let e=this.tail;for(;e;)yield e.value,e=e.prev}*_getNodeIterator(){let e=this.head;for(;e;)yield e,e=e.next}};var he=class{constructor(i,e,t){u(this,"key");u(this,"value");u(this,"forward");this.key=i,this.value=e,this.forward=new Array(t)}},He=class{constructor(i=[],e){u(this,"_head",new he(void 0,void 0,this.maxLevel));u(this,"_level",0);u(this,"_maxLevel",16);u(this,"_probability",.5);if(e){let{maxLevel:t,probability:n}=e;typeof t=="number"&&(this._maxLevel=t),typeof n=="number"&&(this._probability=n)}if(i)for(let[t,n]of i)this.add(t,n)}get head(){return this._head}get level(){return this._level}get maxLevel(){return this._maxLevel}get probability(){return this._probability}get first(){let i=this.head.forward[0];return i?i.value:void 0}get last(){let i=this.head;for(let e=this.level-1;e>=0;e--)for(;i.forward[e];)i=i.forward[e];return i.value}add(i,e){let t=new he(i,e,this._randomLevel()),n=new Array(this.maxLevel).fill(this.head),r=this.head;for(let s=this.level-1;s>=0;s--){for(;r.forward[s]&&r.forward[s].key<i;)r=r.forward[s];n[s]=r}for(let s=0;s<t.forward.length;s++)t.forward[s]=n[s].forward[s],n[s].forward[s]=t;t.forward[0]||(this._level=Math.max(this.level,t.forward.length))}get(i){let e=this.head;for(let t=this.level-1;t>=0;t--)for(;e.forward[t]&&e.forward[t].key<i;)e=e.forward[t];if(e=e.forward[0],e&&e.key===i)return e.value}has(i){return this.get(i)!==void 0}delete(i){let e=new Array(this.maxLevel).fill(this.head),t=this.head;for(let n=this.level-1;n>=0;n--){for(;t.forward[n]&&t.forward[n].key<i;)t=t.forward[n];e[n]=t}if(t=t.forward[0],t&&t.key===i){for(let n=0;n<this.level&&e[n].forward[n]===t;n++)e[n].forward[n]=t.forward[n];for(;this.level>0&&!this.head.forward[this.level-1];)this._level--;return!0}return!1}higher(i){let e=this.head;for(let n=this.level-1;n>=0;n--)for(;e.forward[n]&&e.forward[n].key<=i;)e=e.forward[n];let t=e.forward[0];return t?t.value:void 0}lower(i){let e=this.head,t;for(let n=this.level-1;n>=0;n--){for(;e.forward[n]&&e.forward[n].key<i;)e=e.forward[n];e.key<i&&(t=e)}return t?t.value:void 0}_randomLevel(){let i=1;for(;Math.random()<this.probability&&i<this.maxLevel;)i++;return i}};var Ue=class extends F{constructor(e=[],t){super(t);u(this,"_equals",Object.is);u(this,"_elements",[]);this.pushMany(e)}get elements(){return this._elements}get size(){return this.elements.length}static fromArray(e,t){return new this(e,t)}isEmpty(){return this.elements.length===0}peek(){return this.isEmpty()?void 0:this.elements[this.elements.length-1]}push(e){return this.elements.push(e),!0}pop(){return this.isEmpty()?void 0:this.elements.pop()}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}delete(e){let t=this._indexOfByEquals(e);return this.deleteAt(t)}deleteAt(e){return e<0||e>=this.elements.length?!1:this.elements.splice(e,1).length===1}deleteWhere(e){for(let t=0;t<this.elements.length;t++)if(e(this.elements[t],t,this))return this.elements.splice(t,1),!0;return!1}clear(){this._elements=[]}clone(){let e=this._createInstance({toElementFn:this.toElementFn});for(let t of this)e.push(t);return e}filter(e,t){let n=this._createInstance({toElementFn:this.toElementFn}),r=0;for(let s of this)e.call(t,s,r,this)&&n.push(s),r++;return n}mapSame(e,t){let n=this._createInstance({toElementFn:this.toElementFn}),r=0;for(let s of this){let o=t===void 0?e(s,r++,this):e.call(t,s,r++,this);n.push(o)}return n}map(e,t,n){let r=this._createLike([],{...t!=null?t:{}}),s=0;for(let o of this)r.push(n===void 0?e(o,s,this):e.call(n,o,s,this)),s++;return r}setEquality(e){return this._equals=e,this}_indexOfByEquals(e){for(let t=0;t<this.elements.length;t++)if(this._equals(this.elements[t],e))return t;return-1}_createInstance(e){let t=this.constructor;return new t([],e)}_createLike(e=[],t){let n=this.constructor;return new n(e,t)}*_getIterator(){for(let e=0;e<this.elements.length;e++)yield this.elements[e]}};var O=class h extends U{constructor(e=[],t){super(t);u(this,"_elements",[]);u(this,"_offset",0);u(this,"_autoCompactRatio",.5);if(t){let{autoCompactRatio:n=.5}=t;this._autoCompactRatio=n}this.pushMany(e)}get elements(){return this._elements}get offset(){return this._offset}get autoCompactRatio(){return this._autoCompactRatio}set autoCompactRatio(e){this._autoCompactRatio=e}get length(){return this.elements.length-this._offset}get first(){return this.length>0?this.elements[this._offset]:void 0}get last(){return this.length>0?this.elements[this.elements.length-1]:void 0}static fromArray(e){return new 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 r=this._offset+e,s=this._elements.splice(r,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(s),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 r=0;for(let s of this)e.call(t,s,r,this)&&n.push(s),r++;return n}map(e,t,n){var o,d;let r=new this.constructor([],{toElementFn:t==null?void 0:t.toElementFn,maxLen:(o=t==null?void 0:t.maxLen)!=null?o:this._maxLen,autoCompactRatio:(d=t==null?void 0:t.autoCompactRatio)!=null?d:this._autoCompactRatio}),s=0;for(let a of this)r.push(n===void 0?e(a,s++,this):e.call(n,a,s++,this));return r}mapSame(e,t){var o;let n=this.constructor,r=new n([],{toElementFn:this.toElementFn,maxLen:this._maxLen,autoCompactRatio:this._autoCompactRatio});(o=r._setAutoCompactRatio)==null||o.call(r,this._autoCompactRatio);let s=0;for(let d of this){let a=t===void 0?e(d,s++,this):e.call(t,d,s++,this);r.push(a)}return r}_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)}},qe=class extends le{clone(){let i=this._createInstance({toElementFn:this.toElementFn,maxLen:this._maxLen});for(let e of this)i.push(e);return i}};var Ge=class extends U{constructor(e=[],t){super(t);u(this,"_equals",Object.is);u(this,"_bucketSize",4096);u(this,"_bucketFirst",0);u(this,"_firstInBucket",0);u(this,"_bucketLast",0);u(this,"_lastInBucket",0);u(this,"_bucketCount",0);u(this,"_buckets",[]);u(this,"_length",0);if(t){let{bucketSize:s}=t;typeof s=="number"&&(this._bucketSize=s)}let n;"length"in e?n=typeof e.length=="function"?e.length():e.length:n=typeof e.size=="function"?e.size():e.size,this._bucketCount=ke(n,this._bucketSize)||1;for(let s=0;s<this._bucketCount;++s)this._buckets.push(new Array(this._bucketSize));let r=ke(n,this._bucketSize);this._bucketFirst=this._bucketLast=(this._bucketCount>>1)-(r>>1),this._firstInBucket=this._lastInBucket=this._bucketSize-n%this._bucketSize>>1,this.pushMany(e)}get bucketSize(){return this._bucketSize}get bucketFirst(){return this._bucketFirst}get firstInBucket(){return this._firstInBucket}get bucketLast(){return this._bucketLast}get lastInBucket(){return this._lastInBucket}get bucketCount(){return this._bucketCount}get buckets(){return this._buckets}get length(){return this._length}get first(){if(this._length!==0)return this._buckets[this._bucketFirst][this._firstInBucket]}get last(){if(this._length!==0)return this._buckets[this._bucketLast][this._lastInBucket]}static fromArray(e,t){return new this(e,t)}push(e){return this._length&&(this._lastInBucket<this._bucketSize-1?this._lastInBucket+=1:this._bucketLast<this._bucketCount-1?(this._bucketLast+=1,this._lastInBucket=0):(this._bucketLast=0,this._lastInBucket=0),this._bucketLast===this._bucketFirst&&this._lastInBucket===this._firstInBucket&&this._reallocate()),this._length+=1,this._buckets[this._bucketLast][this._lastInBucket]=e,this._maxLen>0&&this._length>this._maxLen&&this.shift(),!0}pop(){if(this._length===0)return;let e=this._buckets[this._bucketLast][this._lastInBucket];return this._length!==1&&(this._lastInBucket>0?this._lastInBucket-=1:this._bucketLast>0?(this._bucketLast-=1,this._lastInBucket=this._bucketSize-1):(this._bucketLast=this._bucketCount-1,this._lastInBucket=this._bucketSize-1)),this._length-=1,e}shift(){if(this._length===0)return;let e=this._buckets[this._bucketFirst][this._firstInBucket];return this._length!==1&&(this._firstInBucket<this._bucketSize-1?this._firstInBucket+=1:this._bucketFirst<this._bucketCount-1?(this._bucketFirst+=1,this._firstInBucket=0):(this._bucketFirst=0,this._firstInBucket=0)),this._length-=1,e}unshift(e){return this._length&&(this._firstInBucket>0?this._firstInBucket-=1:this._bucketFirst>0?(this._bucketFirst-=1,this._firstInBucket=this._bucketSize-1):(this._bucketFirst=this._bucketCount-1,this._firstInBucket=this._bucketSize-1),this._bucketFirst===this._bucketLast&&this._firstInBucket===this._lastInBucket&&this._reallocate()),this._length+=1,this._buckets[this._bucketFirst][this._firstInBucket]=e,this._maxLen>0&&this._length>this._maxLen&&this.pop(),!0}pushMany(e){let t=[];for(let n of e)this.toElementFn?t.push(this.push(this.toElementFn(n))):t.push(this.push(n));return t}unshiftMany(e=[]){let t=[];for(let n of e)this.toElementFn?t.push(this.unshift(this.toElementFn(n))):t.push(this.unshift(n));return t}isEmpty(){return this._length===0}clear(){this._buckets=[new Array(this._bucketSize)],this._bucketCount=1,this._bucketFirst=this._bucketLast=this._length=0,this._firstInBucket=this._lastInBucket=this._bucketSize>>1}at(e){if(e<0||e>=this._length)return;let{bucketIndex:t,indexInBucket:n}=this._getBucketAndPosition(e);return this._buckets[t][n]}setAt(e,t){j(e,0,this._length-1);let{bucketIndex:n,indexInBucket:r}=this._getBucketAndPosition(e);return this._buckets[n][r]=t,!0}addAt(e,t,n=1){let r=this._length;if(j(e,0,r),e===0)for(;n--;)this.unshift(t);else if(e===this._length)for(;n--;)this.push(t);else{let s=[];for(let o=e;o<this._length;++o){let d=this.at(o);d!==void 0&&s.push(d)}this.cut(e-1,!0);for(let o=0;o<n;++o)this.push(t);for(let o=0;o<s.length;++o)this.push(s[o])}return!0}cut(e,t=!1){if(t){if(e<0)return this.clear(),this;let{bucketIndex:n,indexInBucket:r}=this._getBucketAndPosition(e);return this._bucketLast=n,this._lastInBucket=r,this._length=e+1,this}else{let n=this._createInstance({toElementFn:this._toElementFn,maxLen:this._maxLen});n._setBucketSize(this._bucketSize);for(let r=0;r<=e;r++){let s=this.at(r);s!==void 0&&n.push(s)}return n}}splice(e,t=this._length-e,...n){j(e,0,this._length),t<0&&(t=0),e+t>this._length&&(t=this._length-e);let r=this._createInstance({toElementFn:this._toElementFn,maxLen:this._maxLen});r._setBucketSize(this._bucketSize);for(let o=0;o<t;o++){let d=this.at(e+o);d!==void 0&&r.push(d)}let s=[];for(let o=e+t;o<this._length;o++){let d=this.at(o);d!==void 0&&s.push(d)}this.cut(e-1,!0);for(let o of n)this.push(o);for(let o of s)this.push(o);return r}cutRest(e,t=!1){if(t){if(e<0)return this;let{bucketIndex:n,indexInBucket:r}=this._getBucketAndPosition(e);return this._bucketFirst=n,this._firstInBucket=r,this._length=this._length-e,this}else{let n=this._createInstance({toElementFn:this._toElementFn,maxLen:this._maxLen});n._setBucketSize(this._bucketSize),e<0&&(e=0);for(let r=e;r<this._length;r++){let s=this.at(r);s!==void 0&&n.push(s)}return n}}deleteAt(e){j(e,0,this._length-1);let t;if(e===0)return this.shift();if(e===this._length-1)return t=this.last,this.pop(),t;{let n=this._length-1,{bucketIndex:r,indexInBucket:s}=this._getBucketAndPosition(e);t=this._buckets[r][s];for(let o=e;o<n;o++){let{bucketIndex:d,indexInBucket:a}=this._getBucketAndPosition(o),{bucketIndex:l,indexInBucket:f}=this._getBucketAndPosition(o+1);this._buckets[d][a]=this._buckets[l][f]}return this.pop(),t}}delete(e){let t=this._length;if(t===0)return!1;let n=0,r=0;for(;n<t;){let s=this.at(n);this._equals(s,e)||(this.setAt(r,s),r+=1),n+=1}return this.cut(r-1,!0),!0}deleteWhere(e){for(let t=0;t<this._length;t++){let n=this.at(t);if(e(n,t,this))return this.deleteAt(t),!0}return!1}setEquality(e){return this._equals=e,this}reverse(){this._buckets.reverse().forEach(function(s){s.reverse()});let{_bucketFirst:e,_bucketLast:t,_firstInBucket:n,_lastInBucket:r}=this;return this._bucketFirst=this._bucketCount-t-1,this._bucketLast=this._bucketCount-e-1,this._firstInBucket=this._bucketSize-r-1,this._lastInBucket=this._bucketSize-n-1,this}unique(){if(this._length<=1)return this;let e=1,t=this.at(0);for(let n=1;n<this._length;++n){let r=this.at(n);this._equals(r,t)||(t=r,this.setAt(e++,r))}return this.cut(e-1,!0),this}shrinkToFit(){if(this._length===0)return;let e=[];if(this._bucketFirst!==this._bucketLast){if(this._bucketFirst<this._bucketLast)for(let t=this._bucketFirst;t<=this._bucketLast;++t)e.push(this._buckets[t]);else{for(let t=this._bucketFirst;t<this._bucketCount;++t)e.push(this._buckets[t]);for(let t=0;t<=this._bucketLast;++t)e.push(this._buckets[t])}this._bucketFirst=0,this._bucketLast=e.length-1,this._buckets=e}}clone(){return this._createLike(this,{bucketSize:this.bucketSize,toElementFn:this.toElementFn,maxLen:this._maxLen})}filter(e,t){let n=this._createInstance({toElementFn:this.toElementFn,maxLen:this._maxLen});n._setBucketSize(this._bucketSize);let r=0;for(let s of this)e.call(t,s,r,this)&&n.push(s),r++;return n}mapSame(e,t){let n=this._createInstance({toElementFn:this._toElementFn,maxLen:this._maxLen});n._setBucketSize(this._bucketSize);let r=0;for(let s of this){let o=t===void 0?e(s,r++,this):e.call(t,s,r++,this);n.push(o)}return n}map(e,t,n){let r=this._createLike([],{...t!=null?t:{},bucketSize:this._bucketSize,maxLen:this._maxLen}),s=0;for(let o of this){let d=n===void 0?e(o,s,this):e.call(n,o,s,this);r.push(d),s++}return r}_setBucketSize(e){this._bucketSize=e,this._length===0&&(this._buckets=[new Array(this._bucketSize)],this._bucketCount=1,this._bucketFirst=this._bucketLast=0,this._firstInBucket=this._lastInBucket=this._bucketSize>>1)}*_getIterator(){for(let e=0;e<this._length;++e){let t=this.at(e);t!==void 0&&(yield t)}}_reallocate(e){let t=[],n=e||this._bucketCount>>1||1;for(let r=0;r<n;++r)t[r]=new Array(this._bucketSize);for(let r=this._bucketFirst;r<this._bucketCount;++r)t[t.length]=this._buckets[r];for(let r=0;r<this._bucketLast;++r)t[t.length]=this._buckets[r];t[t.length]=[...this._buckets[this._bucketLast]],this._bucketFirst=n,this._bucketLast=t.length-1;for(let r=0;r<n;++r)t[t.length]=new Array(this._bucketSize);this._buckets=t,this._bucketCount=t.length}_getBucketAndPosition(e){let t,n,r=this._firstInBucket+e;return t=this._bucketFirst+Math.floor(r/this._bucketSize),t>=this._bucketCount&&(t-=this._bucketCount),n=(r+1)%this._bucketSize-1,n<0&&(n=this._bucketSize-1),{bucketIndex:t,indexInBucket:n}}_createInstance(e){let t=this.constructor;return new t([],e)}_createLike(e=[],t){let n=this.constructor;return new n(e,t)}*_getReverseIterator(){for(let e=this._length-1;e>-1;e--){let t=this.at(e);t!==void 0&&(yield t)}}};var D=class h extends F{constructor(e=[],t){super(t);u(this,"_equals",Object.is);u(this,"_elements",[]);u(this,"_DEFAULT_COMPARATOR",(e,t)=>{if(typeof e=="object"||typeof t=="object")throw TypeError("When comparing object types, define a custom comparator in options.");return e>t?1:e<t?-1:0});u(this,"_comparator",this._DEFAULT_COMPARATOR);if(t){let{comparator:n}=t;n&&(this._comparator=n)}this.addMany(e)}get elements(){return this._elements}get size(){return this.elements.length}get leaf(){var e;return(e=this.elements[this.size-1])!=null?e:void 0}static from(e,t){return new this(e,t)}static heapify(e,t){return new h(e,t)}add(e){return this._elements.push(e),this._bubbleUp(this.elements.length-1)}addMany(e){let t=[];for(let n of e)if(this.toElementFn){let r=this.add(this.toElementFn(n));t.push(r)}else{let r=this.add(n);t.push(r)}return t}poll(){if(this.elements.length===0)return;let e=this.elements[0],t=this.elements.pop();return this.elements.length&&(this.elements[0]=t,this._sinkDown(0,this.elements.length>>1)),e}peek(){return this.elements[0]}isEmpty(){return this.size===0}clear(){this._elements=[]}refill(e){return this._elements=Array.from(e),this.fix()}has(e){for(let t of this.elements)if(this._equals(t,e))return!0;return!1}delete(e){let t=-1;for(let n=0;n<this.elements.length;n++)if(this._equals(this.elements[n],e)){t=n;break}return t<0?!1:(t===0?this.poll():t===this.elements.length-1?this.elements.pop():(this.elements.splice(t,1,this.elements.pop()),this._bubbleUp(t),this._sinkDown(t,this.elements.length>>1)),!0)}deleteBy(e){let t=-1;for(let n=0;n<this.elements.length;n++)if(e(this.elements[n],n,this)){t=n;break}return t<0?!1:(t===0?this.poll():t===this.elements.length-1?this.elements.pop():(this.elements.splice(t,1,this.elements.pop()),this._bubbleUp(t),this._sinkDown(t,this.elements.length>>1)),!0)}setEquality(e){return this._equals=e,this}dfs(e="PRE"){let t=[],n=r=>{let s=2*r+1,o=s+1;r<this.size&&(e==="IN"?(n(s),t.push(this.elements[r]),n(o)):e==="PRE"?(t.push(this.elements[r]),n(s),n(o)):e==="POST"&&(n(s),n(o),t.push(this.elements[r])))};return n(0),t}fix(){let e=[];for(let t=Math.floor(this.size/2)-1;t>=0;t--)e.push(this._sinkDown(t,this.elements.length>>1));return e}sort(){let e=[],t=this._createInstance();for(let n of this.elements)t.add(n);for(;!t.isEmpty();){let n=t.poll();n!==void 0&&e.push(n)}return e}clone(){let e=this._createInstance();for(let t of this.elements)e.add(t);return e}filter(e,t){let n=this._createInstance(),r=0;for(let s of this)(t===void 0?e(s,r++,this):e.call(t,s,r++,this))?n.add(s):r++;return n}map(e,t,n){let{comparator:r,toElementFn:s,...o}=t!=null?t:{};if(!r)throw new TypeError("Heap.map requires options.comparator for EM");let d=this._createLike([],{...o,comparator:r,toElementFn:s}),a=0;for(let l of this){let f=n===void 0?e(l,a++,this):e.call(n,l,a++,this);d.add(f)}return d}mapSame(e,t){let n=this._createInstance(),r=0;for(let s of this){let o=t===void 0?e(s,r++,this):e.call(t,s,r++,this);n.add(o)}return n}get comparator(){return this._comparator}*_getIterator(){for(let e of this.elements)yield e}_bubbleUp(e){let t=this.elements[e];for(;e>0;){let n=e-1>>1,r=this.elements[n];if(this.comparator(r,t)<=0)break;this.elements[e]=r,e=n}return this.elements[e]=t,!0}_sinkDown(e,t){let n=this.elements[e];for(;e<t;){let r=e<<1|1,s=r+1,o=this.elements[r];if(s<this.elements.length&&this.comparator(o,this.elements[s])>0&&(r=s,o=this.elements[s]),this.comparator(o,n)>=0)break;this.elements[e]=o,e=r}return this.elements[e]=n,!0}_createInstance(e){let t=this.constructor;return new t([],{comparator:this.comparator,toElementFn:this.toElementFn,...e!=null?e:{}})}_createLike(e=[],t){let n=this.constructor;return new n(e,t)}_spawnLike(e){return this._createLike([],e)}},Le=class{constructor(i,e=0){u(this,"element");u(this,"degree");u(this,"left");u(this,"right");u(this,"child");u(this,"parent");u(this,"marked");this.element=i,this.degree=e,this.marked=!1}},We=class{constructor(i){u(this,"_root");u(this,"_size",0);u(this,"_min");u(this,"_comparator");if(this.clear(),this._comparator=i||this._defaultComparator,typeof this.comparator!="function")throw new Error("FibonacciHeap: comparator must be a function.")}get root(){return this._root}get size(){return this._size}get min(){return this._min}get comparator(){return this._comparator}clear(){this._root=void 0,this._min=void 0,this._size=0}add(i){return this.push(i),!0}push(i){let e=this.createNode(i);return e.left=e,e.right=e,this.mergeWithRoot(e),(!this.min||this.comparator(e.element,this.min.element)<=0)&&(this._min=e),this._size++,this}peek(){return this.min?this.min.element:void 0}consumeLinkedList(i){let e=[];if(!i)return e;let t=i,n=!1;for(;!(t===i&&n);)t===i&&(n=!0),e.push(t),t=t.right;return e}mergeWithChild(i,e){i.child?(e.right=i.child.right,e.left=i.child,i.child.right.left=e,i.child.right=e):i.child=e}poll(){return this.pop()}pop(){if(this._size===0)return;let i=this.min;if(i.child){let e=this.consumeLinkedList(i.child);for(let t of e)this.mergeWithRoot(t),t.parent=void 0}return this.removeFromRoot(i),i===i.right?(this._min=void 0,this._root=void 0):(this._min=i.right,this._consolidate()),this._size--,i.element}merge(i){if(i.size!==0){if(this.root&&i.root){let e=this.root,t=i.root,n=e.right,r=t.left;e.right=t,t.left=e,n.left=r,r.right=n}else!this.root&&i.root&&(this._root=i.root);(!this.min||i.min&&this.comparator(i.min.element,this.min.element)<0)&&(this._min=i.min),this._size+=i.size,i.clear()}}createNode(i){return new Le(i)}isEmpty(){return this._size===0}_defaultComparator(i,e){return i<e?-1:i>e?1:0}mergeWithRoot(i){this.root?(i.right=this.root.right,i.left=this.root,this.root.right.left=i,this.root.right=i):this._root=i}removeFromRoot(i){this.root===i&&(this._root=i.right),i.left&&(i.left.right=i.right),i.right&&(i.right.left=i.left)}_link(i,e){this.removeFromRoot(i),i.left=i,i.right=i,this.mergeWithChild(e,i),e.degree++,i.parent=e}_consolidate(){let i=new Array(this._size),e=this.consumeLinkedList(this.root),t,n,r,s;for(let o of e){for(t=o,r=t.degree;i[r];)n=i[r],this.comparator(t.element,n.element)>0&&(s=t,t=n,n=s),this._link(n,t),i[r]=void 0,r++;i[r]=t}for(let o=0;o<i.length;o++)i[o]&&(!this.min||this.comparator(i[o].element,this.min.element)<=0)&&(this._min=i[o])}};var Qe=class extends D{constructor(i=[],e){super(i,{comparator:(t,n)=>{if(typeof t=="object"||typeof n=="object")throw TypeError("When comparing object types, a custom comparator must be defined in the constructor's options parameter.");return t<n?1:t>n?-1:0},...e})}};var Xe=class extends D{constructor(i=[],e){super(i,e)}};var v=class{constructor(i,e){u(this,"key");u(this,"value");this.key=i,this.value=e}},q=class{constructor(i,e){u(this,"value");u(this,"weight");u(this,"_hashCode");this.weight=i!==void 0?i:1,this.value=e,this._hashCode=Fe()}get hashCode(){return this._hashCode}},X=class extends z{constructor(e){super();u(this,"_options",{defaultEdgeWeight:1});u(this,"_vertexMap",new Map);let t=e==null?void 0:e.graph;this._options={defaultEdgeWeight:1,...t!=null?t:{}}}get options(){return this._options}get vertexMap(){return this._vertexMap}set vertexMap(e){this._vertexMap=e}get size(){return this._vertexMap.size}getVertex(e){return this._vertexMap.get(e)||void 0}hasVertex(e){return this._vertexMap.has(this._getVertexKey(e))}addVertex(e,t){if(e instanceof v)return this._addVertex(e);{let n=this.createVertex(e,t);return this._addVertex(n)}}isVertexKey(e){let t=typeof e;return t==="string"||t==="number"}removeManyVertices(e){let t=[];for(let n of e)t.push(this.deleteVertex(n));return t.length>0}hasEdge(e,t){return!!this.getEdge(e,t)}addEdge(e,t,n,r){if(e instanceof q)return this._addEdge(e);if(t instanceof v||typeof t=="string"||typeof t=="number"){if(!(this.hasVertex(e)&&this.hasVertex(t)))return!1;e instanceof v&&(e=e.key),t instanceof v&&(t=t.key);let s=this.createEdge(e,t,n,r);return this._addEdge(s)}else throw new Error("dest must be a Vertex or vertex key while srcOrEdge is an Edge")}setEdgeWeight(e,t,n){let r=this.getEdge(e,t);return r?(r.weight=n,!0):!1}getAllPathsBetween(e,t,n=1e3){let r=[],s=this._getVertex(e),o=this._getVertex(t);if(!(s&&o))return[];let d=[];for(d.push({vertex:s,path:[s]});d.length>0;){let{vertex:a,path:l}=d.pop();if(a===o&&(r.push(l),r.length>=n))return r;let f=this.getNeighbors(a);for(let c of f)if(!l.includes(c)){let g=[...l,c];d.push({vertex:c,path:g})}}return r}getPathSumWeight(e){var n;let t=0;for(let r=0;r<e.length;r++)t+=((n=this.getEdge(e[r],e[r+1]))==null?void 0:n.weight)||0;return t}getMinCostBetween(e,t,n){if(n===void 0&&(n=!1),n){let r=this.getAllPathsBetween(e,t),s=Number.MAX_SAFE_INTEGER;for(let o of r)s=Math.min(this.getPathSumWeight(o),s);return s}else{let r=this._getVertex(t),s=this._getVertex(e);if(!(s&&r))return;let o=new Map,d=new O([s]);o.set(s,!0);let a=0;for(;d.length>0;){for(let l=0,f=d.length;l<f;l++){let c=d.shift();if(c===r)return a;if(c!==void 0){let g=this.getNeighbors(c);for(let p of g)o.has(p)||(o.set(p,!0),d.push(p))}}a++}return}}getMinPathBetween(e,t,n,r=!1){var s,o;if(n===void 0&&(n=!1),n)if(r){let d=this.getAllPathsBetween(e,t,1e4),a=Number.MAX_SAFE_INTEGER,l=-1,f=0;for(let c of d){let g=this.getPathSumWeight(c);g<a&&(a=g,l=f),f++}return d[l]||void 0}else return(o=(s=this.dijkstra(e,t,!0,!0))==null?void 0:s.minPath)!=null?o:[];else{let d=[],a=this._getVertex(e),l=this._getVertex(t);if(!(a&&l))return[];let f=(c,g,p,b)=>{if(p.add(c),c===g){d=[a,...b];return}let T=this.getNeighbors(c);for(let E of T)p.has(E)||(b.push(E),f(E,g,p,b),b.pop());p.delete(c)};return f(a,l,new Set,[]),d}}dijkstraWithoutHeap(e,t=void 0,n=!1,r=!1){let s=Number.MAX_SAFE_INTEGER,o,d=[],a=[],l=this._vertexMap,f=new Map,c=new Set,g=new Map,p=this._getVertex(e),b=t?this._getVertex(t):void 0;if(!p)return;for(let y of l){let m=y[1];m instanceof v&&f.set(m,Number.MAX_SAFE_INTEGER)}f.set(p,0),g.set(p,void 0);let T=()=>{let y=Number.MAX_SAFE_INTEGER,m;for(let[N,K]of f)c.has(N)||K<y&&(y=K,m=N);return m},E=y=>{for(let m of l){let N=m[1];if(N instanceof v){let K=[N],V=g.get(N);for(;V;)K.push(V),V=g.get(V);let R=K.reverse();m[1]===y&&(d=R),a.push(R)}}};for(let y=1;y<l.size;y++){let m=T();if(m){if(c.add(m),b&&b===m)return n&&(s=f.get(b)||Number.MAX_SAFE_INTEGER),r&&E(b),{distMap:f,preMap:g,seen:c,paths:a,minDist:s,minPath:d};let N=this.getNeighbors(m);for(let K of N)if(!c.has(K)){let V=this.getEdge(m,K);if(V){let R=f.get(m),k=f.get(K);R!==void 0&&k!==void 0&&V.weight+R<k&&(f.set(K,V.weight+R),g.set(K,m))}}}}return n&&f.forEach((y,m)=>{m!==p&&y<s&&(s=y,r&&(o=m))}),r&&E(o),{distMap:f,preMap:g,seen:c,paths:a,minDist:s,minPath:d}}dijkstra(e,t=void 0,n=!1,r=!1){var y;let s=Number.MAX_SAFE_INTEGER,o,d=[],a=[],l=this._vertexMap,f=new Map,c=new Set,g=new Map,p=this._getVertex(e),b=t?this._getVertex(t):void 0;if(!p)return;for(let m of l){let N=m[1];N instanceof v&&f.set(N,Number.MAX_SAFE_INTEGER)}let T=new D([],{comparator:(m,N)=>m.key-N.key});T.add({key:0,value:p}),f.set(p,0),g.set(p,void 0);let E=m=>{for(let N of l){let K=N[1];if(K instanceof v){let V=[K],R=g.get(K);for(;R;)V.push(R),R=g.get(R);let k=V.reverse();N[1]===m&&(d=k),a.push(k)}}};for(;T.size>0;){let m=T.poll(),N=m==null?void 0:m.key,K=m==null?void 0:m.value;if(N!==void 0&&K){if(c.add(K),b&&b===K)return n&&(s=f.get(b)||Number.MAX_SAFE_INTEGER),r&&E(b),{distMap:f,preMap:g,seen:c,paths:a,minDist:s,minPath:d};let V=this.getNeighbors(K);for(let R of V)if(!c.has(R)){let k=(y=this.getEdge(K,R))==null?void 0:y.weight;if(typeof k=="number"){let I=f.get(R);I!==void 0&&N+k<I&&(T.add({key:N+k,value:R}),g.set(R,K),f.set(R,N+k))}}}}return n&&f.forEach((m,N)=>{N!==p&&m<s&&(s=m,r&&(o=N))}),r&&E(o),{distMap:f,preMap:g,seen:c,paths:a,minDist:s,minPath:d}}bellmanFord(e,t,n,r){n===void 0&&(n=!1),r===void 0&&(r=!1);let s=this._getVertex(e),o=[],d=new Map,a=new Map,l=Number.MAX_SAFE_INTEGER,f=[],c;if(t&&(c=!1),!s)return{hasNegativeCycle:c,distMap:d,preMap:a,paths:o,min:l,minPath:f};let g=this._vertexMap,p=g.size,b=this.edgeSet(),T=b.length;this._vertexMap.forEach(y=>{d.set(y,Number.MAX_SAFE_INTEGER)}),d.set(s,0);for(let y=1;y<p;++y)for(let m=0;m<T;++m){let N=this.getEndsOfEdge(b[m]);if(N){let[K,V]=N,R=b[m].weight,k=d.get(K),I=d.get(V);k!==void 0&&I!==void 0&&d.get(K)!==Number.MAX_SAFE_INTEGER&&k+R<I&&(d.set(V,k+R),r&&a.set(V,K))}}let E;if(n&&d.forEach((y,m)=>{m!==s&&y<l&&(l=y,r&&(E=m))}),r)for(let y of g){let m=y[1];if(m instanceof v){let N=[m],K=a.get(m);for(;K!==void 0;)N.push(K),K=a.get(K);let V=N.reverse();y[1]===E&&(f=V),o.push(V)}}for(let y=0;y<T;++y){let m=this.getEndsOfEdge(b[y]);if(m){let[N]=m,K=b[y].weight,V=d.get(N);V&&V!==Number.MAX_SAFE_INTEGER&&V+K<V&&(c=!0)}}return{hasNegativeCycle:c,distMap:d,preMap:a,paths:o,min:l,minPath:f}}floydWarshall(){var s;let e=[...this._vertexMap],t=e.length,n=[],r=[];for(let o=0;o<t;o++){n[o]=[],r[o]=[];for(let d=0;d<t;d++)r[o][d]=void 0}for(let o=0;o<t;o++)for(let d=0;d<t;d++)n[o][d]=((s=this.getEdge(e[o][1],e[d][1]))==null?void 0:s.weight)||Number.MAX_SAFE_INTEGER;for(let o=0;o<t;o++)for(let d=0;d<t;d++)for(let a=0;a<t;a++)n[d][a]>n[d][o]+n[o][a]&&(n[d][a]=n[d][o]+n[o][a],r[d][a]=e[o][1]);return{costs:n,predecessor:r}}getCycles(e=!1){let t=[],n=new Set,r=(o,d,a)=>{if(a.has(o)){(!e&&d.length>2||e&&d.length>=2)&&d[0]===o.key&&t.push([...d]);return}a.add(o),d.push(o.key);for(let l of this.getNeighbors(o))l&&r(l,d,a);a.delete(o),d.pop()};for(let o of this.vertexMap.values())r(o,[],n);let s=new Map;for(let o of t){let d=[...o].sort().toString();s.has(d)||s.set(d,o)}return[...s].map(o=>o[1])}filter(e,t){let n=[],r=0;for(let[s,o]of this)e.call(t,o,s,r,this)&&n.push([s,o]),r++;return this._createLike(n,this._snapshotOptions())}filterEntries(e,t){let n=[],r=0;for(let[s,o]of this)e.call(t,o,s,r,this)&&n.push([s,o]),r++;return n}map(e,t){let n=[],r=0;for(let[s,o]of this)n.push(e.call(t,o,s,r,this)),r++;return n}clone(){return this._createLike(void 0,this._snapshotOptions())}*_getIterator(){for(let e of this._vertexMap.values())yield[e.key,e.value]}_snapshotOptions(){return{graph:{...this._options}}}_createInstance(e){let t=this.constructor,n=new t,r=e==null?void 0:e.graph;return r?n._options={...n._options,...r}:n._options={...n._options,...this._options},n}_createLike(e,t){let n=this._createInstance(t);if(e)for(let[s,o]of e)n.addVertex(s,o);else for(let[s,o]of this)n.addVertex(s,o);let r=this.edgeSet();for(let s of r){let o=this.getEndsOfEdge(s);if(!o)continue;let[d,a]=o,l=d.key,f=a.key,c=n.hasVertex?n.hasVertex(l):!1,g=n.hasVertex?n.hasVertex(f):!1;if(c&&g){let p=s.weight,b=s.value,T=n.createEdge(l,f,p,b);n._addEdge(T)}}return n}_addVertex(e){return this.hasVertex(e)?!1:(this._vertexMap.set(e.key,e),!0)}_getVertex(e){let t=this._getVertexKey(e);return this._vertexMap.get(t)||void 0}_getVertexKey(e){return e instanceof v?e.key:e}};var $=class extends v{constructor(i,e){super(i,e)}},se=class extends q{constructor(e,t,n,r){super(n,r);u(this,"src");u(this,"dest");this.src=e,this.dest=t}},fe=class h extends X{constructor(e){super(e);u(this,"_outEdgeMap",new Map);u(this,"_inEdgeMap",new Map)}get outEdgeMap(){return this._outEdgeMap}set outEdgeMap(e){this._outEdgeMap=e}get inEdgeMap(){return this._inEdgeMap}set inEdgeMap(e){this._inEdgeMap=e}static fromKeys(e){let t=new h({vertexValueInitializer:n=>n});for(let n of e)t.addVertex(n);return t}static fromEntries(e){let t=new h;for(let[n,r]of e)t.addVertex(n,r);return t}createVertex(e,t){return new $(e,t)}createEdge(e,t,n,r){var s;return new se(e,t,(s=n!=null?n:this.options.defaultEdgeWeight)!=null?s:1,r)}getEdge(e,t){let n=[];if(e!==void 0&&t!==void 0){let r=this._getVertex(e),s=this._getVertex(t);if(r&&s){let o=this._outEdgeMap.get(r);o&&(n=o.filter(d=>d.dest===s.key))}}return n[0]||void 0}deleteEdgeSrcToDest(e,t){let n=this._getVertex(e),r=this._getVertex(t),s;if(!n||!r)return;let o=this._outEdgeMap.get(n);o&&P(o,a=>a.dest===r.key);let d=this._inEdgeMap.get(r);return d&&(s=P(d,a=>a.src===n.key)[0]||void 0),s}deleteEdge(e,t){let n,r,s;if(this.isVertexKey(e))if(this.isVertexKey(t))r=this._getVertex(e),s=this._getVertex(t);else return;else r=this._getVertex(e.src),s=this._getVertex(e.dest);if(r&&s){let o=this._outEdgeMap.get(r);o&&o.length>0&&P(o,a=>a.src===r.key&&a.dest===(s==null?void 0:s.key));let d=this._inEdgeMap.get(s);d&&d.length>0&&(n=P(d,a=>a.src===r.key&&a.dest===s.key)[0])}return n}deleteVertex(e){let t,n;if(this.isVertexKey(e)?(n=this.getVertex(e),t=e):(n=e,t=this._getVertexKey(e)),n){let r=this.getNeighbors(n);for(let s of r)this.deleteEdgeSrcToDest(n,s);this._outEdgeMap.delete(n),this._inEdgeMap.delete(n)}return this._vertexMap.delete(t)}deleteEdgesBetween(e,t){let n=[];if(e&&t){let r=this.deleteEdgeSrcToDest(e,t),s=this.deleteEdgeSrcToDest(t,e);r&&n.push(r),s&&n.push(s)}return n}incomingEdgesOf(e){let t=this._getVertex(e);return t?this.inEdgeMap.get(t)||[]:[]}outgoingEdgesOf(e){let t=this._getVertex(e);return t?this._outEdgeMap.get(t)||[]:[]}degreeOf(e){return this.outDegreeOf(e)+this.inDegreeOf(e)}inDegreeOf(e){return this.incomingEdgesOf(e).length}outDegreeOf(e){return this.outgoingEdgesOf(e).length}edgesOf(e){return[...this.outgoingEdgesOf(e),...this.incomingEdgesOf(e)]}getEdgeSrc(e){return this._getVertex(e.src)}getEdgeDest(e){return this._getVertex(e.dest)}getDestinations(e){if(e===void 0)return[];let t=[],n=this.outgoingEdgesOf(e);for(let r of n){let s=this.getEdgeDest(r);s&&t.push(s)}return t}topologicalSort(e){e=e!=null?e:"key";let t=new Map;for(let o of this.vertexMap)t.set(o[1],0);let n=[],r=!1,s=o=>{t.set(o,1);let d=this.getDestinations(o);for(let a of d){let l=t.get(a);l===0?s(a):l===1&&(r=!0)}t.set(o,2),n.push(o)};for(let o of this.vertexMap)t.get(o[1])===0&&s(o[1]);if(!r)return e==="key"&&(n=n.map(o=>o instanceof $?o.key:o)),n.reverse()}edgeSet(){let e=[];return this._outEdgeMap.forEach(t=>{e=[...e,...t]}),e}getNeighbors(e){let t=[],n=this._getVertex(e);if(n){let r=this.outgoingEdgesOf(n);for(let s of r){let o=this._getVertex(s.dest);o&&t.push(o)}}return t}getEndsOfEdge(e){if(!this.hasEdge(e.src,e.dest))return;let t=this._getVertex(e.src),n=this._getVertex(e.dest);if(t&&n)return[t,n]}isEmpty(){return this.vertexMap.size===0&&this.inEdgeMap.size===0&&this.outEdgeMap.size===0}clear(){this._vertexMap=new Map,this._inEdgeMap=new Map,this._outEdgeMap=new Map}clone(){return super.clone()}tarjan(){let e=new Map,t=new Map,n=new Map,r=0,s=[],o=new Set,d=a=>{e.set(a,r),t.set(a,r),r++,s.push(a),o.add(a);let l=this.getNeighbors(a);for(let f of l)e.has(f)?o.has(f)&&t.set(a,Math.min(t.get(a),e.get(f))):(d(f),t.set(a,Math.min(t.get(a),t.get(f))));if(e.get(a)===t.get(a)){let f=[],c;do c=s.pop(),o.delete(c),f.push(c);while(c!==a);n.set(n.size,f)}};for(let a of this.vertexMap.values())e.has(a)||d(a);return{dfnMap:e,lowMap:t,SCCs:n}}getDFNMap(){return this.tarjan().dfnMap}getLowMap(){return this.tarjan().lowMap}getSCCs(){return this.tarjan().SCCs}_addEdge(e){if(!(this.hasVertex(e.src)&&this.hasVertex(e.dest)))return!1;let t=this._getVertex(e.src),n=this._getVertex(e.dest);if(t&&n){let r=this._outEdgeMap.get(t);r?r.push(e):this._outEdgeMap.set(t,[e]);let s=this._inEdgeMap.get(n);return s?s.push(e):this._inEdgeMap.set(n,[e]),!0}else return!1}};var Be=class extends v{constructor(i,e){super(i,e)}},Ie=class extends q{constructor(e,t,n,r){super(n,r);u(this,"endpoints");this.endpoints=[e,t]}},$e=class h extends X{constructor(e){super(e);u(this,"_edgeMap");this._edgeMap=new Map}get edgeMap(){return this._edgeMap}set edgeMap(e){this._edgeMap=e}static fromKeys(e){let t=new h({vertexValueInitializer:n=>n});for(let n of e)t.addVertex(n);return t}static fromEntries(e){let t=new h;for(let[n,r]of e)t.addVertex(n,r);return t}createVertex(e,t){return new Be(e,t)}createEdge(e,t,n,r){var s;return new Ie(e,t,(s=n!=null?n:this.options.defaultEdgeWeight)!=null?s:1,r)}getEdge(e,t){var r;let n=[];if(e!==void 0&&t!==void 0){let s=this._getVertex(e),o=this._getVertex(t);s&&o&&(n=(r=this._edgeMap.get(s))==null?void 0:r.filter(d=>d.endpoints.includes(o.key)))}return n&&n[0]||void 0}deleteEdgeBetween(e,t){let n=this._getVertex(e),r=this._getVertex(t);if(!n||!r)return;let s=this._edgeMap.get(n),o;s&&(o=P(s,a=>a.endpoints.includes(r.key))[0]||void 0);let d=this._edgeMap.get(r);return d&&P(d,a=>a.endpoints.includes(n.key)),o}deleteEdge(e,t){let n,r;if(this.isVertexKey(e))if(this.isVertexKey(t))n=this._getVertex(e),r=this._getVertex(t);else return;else n=this._getVertex(e.endpoints[0]),r=this._getVertex(e.endpoints[1]);if(n&&r)return this.deleteEdgeBetween(n,r)}deleteVertex(e){let t,n;this.isVertexKey(e)?(n=this.getVertex(e),t=e):(n=e,t=this._getVertexKey(e));let r=this.getNeighbors(e);return n&&(r.forEach(s=>{let o=this._edgeMap.get(s);if(o){let d=o.filter(a=>!a.endpoints.includes(t));this._edgeMap.set(s,d)}}),this._edgeMap.delete(n)),this._vertexMap.delete(t)}degreeOf(e){var n;let t=this._getVertex(e);return t&&((n=this._edgeMap.get(t))==null?void 0:n.length)||0}edgesOf(e){let t=this._getVertex(e);return t?this._edgeMap.get(t)||[]:[]}edgeSet(){let e=new Set;return this._edgeMap.forEach(t=>{t.forEach(n=>{e.add(n)})}),[...e]}getNeighbors(e){let t=[],n=this._getVertex(e);if(n){let r=this.edgesOf(n);for(let s of r){let o=this._getVertex(s.endpoints.filter(d=>d!==n.key)[0]);o&&t.push(o)}}return t}getEndsOfEdge(e){if(!this.hasEdge(e.endpoints[0],e.endpoints[1]))return;let t=this._getVertex(e.endpoints[0]),n=this._getVertex(e.endpoints[1]);if(t&&n)return[t,n]}isEmpty(){return this.vertexMap.size===0&&this.edgeMap.size===0}clear(){this._vertexMap=new Map,this._edgeMap=new Map}clone(){return super.clone()}tarjan(){let e=new Map,t=new Map,n=[],r=[],s=0,o=(d,a)=>{e.set(d,s),t.set(d,s),s++;let l=this.getNeighbors(d),f=0;for(let c of l)if(e.has(c))c!==a&&t.set(d,Math.min(t.get(d),e.get(c)));else{if(f++,o(c,d),t.set(d,Math.min(t.get(d),t.get(c))),t.get(c)>e.get(d)){let g=this.getEdge(d,c);g&&n.push(g)}a!==void 0&&t.get(c)>=e.get(d)&&r.push(d)}a===void 0&&f>1&&r.push(d)};for(let d of this.vertexMap.values())e.has(d)||o(d,void 0);return{dfnMap:e,lowMap:t,bridges:n,cutVertices:r}}getBridges(){return this.tarjan().bridges}getCutVertices(){return this.tarjan().cutVertices}getDFNMap(){return this.tarjan().dfnMap}getLowMap(){return this.tarjan().lowMap}_addEdge(e){for(let t of e.endpoints){let n=this._getVertex(t);if(n===void 0)return!1;if(n){let r=this._edgeMap.get(n);r?r.push(e):this._edgeMap.set(n,[e])}}return!0}};var ve=class extends ${constructor(e,t,n,r){super(e,t);u(this,"lat");u(this,"long");this.lat=n,this.long=r}},we=class extends se{constructor(i,e,t,n){super(i,e,t,n)}},Je=class h extends fe{constructor(e,t){super();u(this,"_originCoord",[0,0]);u(this,"_bottomRight");this._originCoord=e,this._bottomRight=t}get originCoord(){return this._originCoord}get bottomRight(){return this._bottomRight}createVertex(e,t,n=this.originCoord[0],r=this.originCoord[1]){return new ve(e,t,n,r)}createEdge(e,t,n,r){return new we(e,t,n,r)}clone(){return super.clone()}_snapshotOptions(){return{...super._snapshotOptions(),originCoord:this.originCoord,bottomRight:this.bottomRight}}_createInstance(e){let{originCoord:t,bottomRight:n}=e||{},r=t!=null?t:this.originCoord,s=n!=null?n:this.bottomRight;return new h(r,s)}};var Ye=(e=>(e[e.VISIT=0]="VISIT",e[e.PROCESS=1]="PROCESS",e))(Ye||{}),H=class{constructor(i,e,t=!0,n=!0){this.low=i;this.high=e;this.includeLow=t;this.includeHigh=n}isInRange(i,e){let t=this.includeLow?e(i,this.low)>=0:e(i,this.low)>0,n=this.includeHigh?e(i,this.high)<=0:e(i,this.high)<0;return t&&n}};var oe=class{constructor(i,e){u(this,"key");u(this,"value");u(this,"parent");u(this,"_left");u(this,"_right");u(this,"_height",0);u(this,"_color","BLACK");u(this,"_count",1);this.key=i,this.value=e}get left(){return this._left}set left(i){i&&(i.parent=this),this._left=i}get right(){return this._right}set right(i){i&&(i.parent=this),this._right=i}get height(){return this._height}set height(i){this._height=i}get color(){return this._color}set color(i){this._color=i}get count(){return this._count}set count(i){this._count=i}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"}},ce=class extends z{constructor(e=[],t){super();u(this,"iterationType","ITERATIVE");u(this,"_isMapMode",!0);u(this,"_isDuplicate",!1);u(this,"_store",new Map);u(this,"_root");u(this,"_size",0);u(this,"_NIL",new oe(NaN));u(this,"_toEntryFn");u(this,"_DEFAULT_NODE_CALLBACK",e=>e?e.key:void 0);if(t){let{iterationType:n,toEntryFn:r,isMapMode:s,isDuplicate:o}=t;if(n&&(this.iterationType=n),s!==void 0&&(this._isMapMode=s),o!==void 0&&(this._isDuplicate=o),typeof r=="function")this._toEntryFn=r;else if(r)throw TypeError("toEntryFn must be a function type")}e&&this.setMany(e)}get isMapMode(){return this._isMapMode}get isDuplicate(){return this._isDuplicate}get store(){return this._store}get root(){return this._root}get size(){return this._size}get NIL(){return this._NIL}get toEntryFn(){return this._toEntryFn}createNode(e,t){return new oe(e,t)}createTree(e){return this._createInstance(e)}ensureNode(e,t=this.iterationType){if(e===null)return null;if(e!==void 0&&e!==this._NIL){if(this.isNode(e))return e;if(this.isEntry(e)){let n=e[0];return n===null?null:n===void 0?void 0:this.getNode(n,this._root,t)}return this.getNode(e,this._root,t)}}isNode(e){return e instanceof oe}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 H}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:Q(e)}add(e){return this.set(e)}set(e,t){let[n]=this._keyValueNodeOrEntryToNodeAndValue(e,t);if(n===void 0)return!1;if(!this._root)return this._setRoot(n),this._isMapMode&&n!==null&&n!==void 0&&this._store.set(n.key,n),this._size=1,!0;let r=new O([this._root]),s;for(;r.length>0;){let o=r.shift();if(o){if(!this._isDuplicate&&n!==null&&o.key===n.key)return this._replaceNode(o,n),this._isMapMode&&n!==null&&this._store.set(o.key,n),!0;s===void 0&&(o.left===void 0||o.right===void 0)&&(s=o),o.left!==null&&o.left&&r.push(o.left),o.right!==null&&o.right&&r.push(o.right)}}return s?(s.left===void 0?s.left=n:s.right===void 0&&(s.right=n),this._isMapMode&&n!==null&&n!==void 0&&this._store.set(n.key,n),this._size++,!0):!1}addMany(e){return this.setMany(e)}setMany(e,t){let n=[],r;t&&(r=t[Symbol.iterator]());for(let s of e){let o;if(r){let d=r.next();d.done||(o=d.value)}this.isRaw(s)&&(s=this._toEntryFn(s)),n.push(this.set(s,o))}return n}merge(e){this.setMany(e,[])}refill(e,t){this.clear(),this.setMany(e,t)}delete(e){let t=[];if(!this._root)return t;let n=this.getNode(e);if(!n)return t;let r=n==null?void 0:n.parent,s,o=n;if(!n.left&&!n.right&&!r)this._setRoot(void 0);else if(n.left){let d=this.getRightMost(a=>a,n.left);if(d){let a=d.parent;o=this._swapProperties(n,d),this._isMapMode&&(this._store.set(n.key,n),this._store.set(d.key,d)),a&&(a.right===d?a.right=d.left:a.left=d.left,s=a)}}else if(r){let{familyPosition:d}=n;d==="LEFT"||d==="ROOT_LEFT"?r.left=n.right:(d==="RIGHT"||d==="ROOT_RIGHT")&&(r.right=n.right),s=r}else this._setRoot(n.right),n.right=void 0;return this._size=this._size-1,t.push({deleted:o,needBalanced:s}),this._isMapMode&&o&&this._store.delete(o.key),t}search(e,t=!1,n=this._DEFAULT_NODE_CALLBACK,r=this._root,s=this.iterationType){if(e===void 0)return[];if(e===null)return[];if(r=this.ensureNode(r),!r)return[];let o=this._ensurePredicate(e),d=[];if(s==="RECURSIVE"){let a=l=>{o(l)&&(d.push(n(l)),t)||!this.isRealNode(l.left)&&!this.isRealNode(l.right)||(this.isRealNode(l.left)&&a(l.left),this.isRealNode(l.right)&&a(l.right))};a(r)}else{let a=[r];for(;a.length>0;){let l=a.pop();if(this.isRealNode(l)){if(o(l)&&(d.push(n(l)),t))return d;this.isRealNode(l.left)&&a.push(l.left),this.isRealNode(l.right)&&a.push(l.right)}}}return d}getNodes(e,t=!1,n=this._root,r=this.iterationType){return this.search(e,t,s=>s,n,r)}getNode(e,t=this._root,n=this.iterationType){if(this._isMapMode&&e!==null&&e!==void 0&&!this._isPredicate(e)){let r=this._extractKey(e);return r==null?void 0:this._store.get(r)}return this.search(e,!0,r=>r,t,n)[0]}get(e,t=this._root,n=this.iterationType){var r,s;if(this._isMapMode){let o=this._extractKey(e);return o==null||(r=this._store.get(o))==null?void 0:r.value}return(s=this.getNode(e,t,n))==null?void 0:s.value}has(e,t=this._root,n=this.iterationType){if(this._isMapMode&&e!==void 0&&e!==null&&!this._isPredicate(e)){let r=this._extractKey(e);return r==null?!1:this._store.has(r)}return this.search(e,!0,r=>r,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 r=(d,a,l)=>{if(!this.isRealNode(d))return!0;let f=Number(d.key);return f<=a||f>=l?!1:r(d.left,a,f)&&r(d.right,f,l)},s=r(n,Number.MIN_SAFE_INTEGER,Number.MAX_SAFE_INTEGER),o=r(n,Number.MAX_SAFE_INTEGER,Number.MIN_SAFE_INTEGER);return s||o}else{let r=(d=!1)=>{let a=[],l=d?Number.MAX_SAFE_INTEGER:Number.MIN_SAFE_INTEGER,f=n;for(;this.isRealNode(f)||a.length>0;){for(;this.isRealNode(f);)a.push(f),f=f.left;f=a.pop();let c=Number(f.key);if(!this.isRealNode(f)||!d&&l>=c||d&&l<=c)return!1;l=c,f=f.right}return!0},s=r(),o=r(!0);return s||o}}getDepth(e,t=this._root){let n=this.ensureNode(e),r=this.ensureNode(t),s=0;for(;n!=null&&n.parent;){if(n===r)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=r=>{if(!this.isRealNode(r))return-1;let s=n(r.left),o=n(r.right);return Math.max(s,o)+1};return n(e)}else{let n=[{node:e,depth:0}],r=0;for(;n.length>0;){let{node:s,depth:o}=n.pop();this.isRealNode(s.left)&&n.push({node:s.left,depth:o+1}),this.isRealNode(s.right)&&n.push({node:s.right,depth:o+1}),r=Math.max(r,o)}return r}}getMinHeight(e=this._root,t=this.iterationType){if(e=this.ensureNode(e),!e)return-1;if(t==="RECURSIVE"){let n=r=>{if(!this.isRealNode(r)||!this.isRealNode(r.left)&&!this.isRealNode(r.right))return 0;let s=n(r.left),o=n(r.right);return Math.min(s,o)+1};return n(e)}else{let n=[],r=e,s=null,o=new Map;for(;n.length>0||r;)if(this.isRealNode(r))n.push(r),r=r.left;else if(r=n[n.length-1],!this.isRealNode(r.right)||s===r.right){if(r=n.pop(),this.isRealNode(r)){let d=this.isRealNode(r.left)?o.get(r.left):-1,a=this.isRealNode(r.right)?o.get(r.right):-1;o.set(r,1+Math.min(d,a)),s=r,r=null}}else r=r.right;return o.get(e)}}getPathToRoot(e,t=this._DEFAULT_NODE_CALLBACK,n=!1){let r=[],s=this.ensureNode(e);if(!s)return r;for(;s.parent;)r.push(t(s)),s=s.parent;return r.push(t(s)),n?r.reverse():r}getLeftMost(e=this._DEFAULT_NODE_CALLBACK,t=this._root,n=this.iterationType){if(this.isNIL(t))return e(void 0);let r=this.ensureNode(t);if(!this.isRealNode(r))return e(void 0);if(n==="RECURSIVE"){let s=o=>{let{left:d}=o;return this.isRealNode(d)?s(d):o};return e(s(r))}else{let s=xe(o=>{let{left:d}=o;return this.isRealNode(d)?Me(()=>s(d)):o});return e(s(r))}}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 r=s=>{let{right:o}=s;return this.isRealNode(o)?r(o):s};return e(r(t))}else{let r=xe(s=>{let{right:o}=s;return this.isRealNode(o)?Me(()=>r(o)):s});return e(r(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,r=this._root,s=this.iterationType,o=!1){return r=this.ensureNode(r),r?this._dfs(e,t,n,r,s,o):[]}bfs(e=this._DEFAULT_NODE_CALLBACK,t=this._root,n=this.iterationType,r=!1){if(t=this.ensureNode(t),!t)return[];let s=[];if(n==="RECURSIVE"){let o=new O([t]),d=a=>{if(o.length===0)return;let l=o.shift();s.push(e(l)),r?(l&&this.isRealNodeOrNull(l.left)&&o.push(l.left),l&&this.isRealNodeOrNull(l.right)&&o.push(l.right)):(this.isRealNode(l.left)&&o.push(l.left),this.isRealNode(l.right)&&o.push(l.right)),d(a+1)};d(0)}else{let o=new O([t]);for(;o.length>0;){let d=o.length;for(let a=0;a<d;a++){let l=o.shift();s.push(e(l)),r?(l&&this.isRealNodeOrNull(l.left)&&o.push(l.left),l&&this.isRealNodeOrNull(l.right)&&o.push(l.right)):(this.isRealNode(l.left)&&o.push(l.left),this.isRealNode(l.right)&&o.push(l.right))}}}return s}leaves(e=this._DEFAULT_NODE_CALLBACK,t=this._root,n=this.iterationType){t=this.ensureNode(t);let r=[];if(!this.isRealNode(t))return[];if(n==="RECURSIVE"){let s=o=>{this.isLeaf(o)&&r.push(e(o)),!(!this.isRealNode(o.left)&&!this.isRealNode(o.right))&&(this.isRealNode(o.left)&&s(o.left),this.isRealNode(o.right)&&s(o.right))};s(t)}else{let s=new O([t]);for(;s.length>0;){let o=s.shift();this.isRealNode(o)&&(this.isLeaf(o)&&r.push(e(o)),this.isRealNode(o.left)&&s.push(o.left),this.isRealNode(o.right)&&s.push(o.right))}}return r}listLevels(e=this._DEFAULT_NODE_CALLBACK,t=this._root,n=this.iterationType,r=!1){t=this.ensureNode(t);let s=[];if(!t)return s;if(n==="RECURSIVE"){let o=(d,a)=>{s[a]||(s[a]=[]),s[a].push(e(d)),r?(d&&this.isRealNodeOrNull(d.left)&&o(d.left,a+1),d&&this.isRealNodeOrNull(d.right)&&o(d.right,a+1)):(d&&d.left&&o(d.left,a+1),d&&d.right&&o(d.right,a+1))};o(t,0)}else{let o=[[t,0]];for(;o.length>0;){let d=o.pop(),[a,l]=d;s[l]||(s[l]=[]),s[l].push(e(a)),r?(a&&this.isRealNodeOrNull(a.right)&&o.push([a.right,l+1]),a&&this.isRealNodeOrNull(a.left)&&o.push([a.left,l+1])):(a&&a.right&&o.push([a.right,l+1]),a&&a.left&&o.push([a.left,l+1]))}}return s}morris(e=this._DEFAULT_NODE_CALLBACK,t="IN",n=this._root){if(n=this.ensureNode(n),!n)return[];let r=[],s=n,o=a=>{let l=null,f=null;for(;a;)f=a.right,a.right=l,l=a,a=f;return l},d=a=>{let l=o(a),f=l;for(;f;)r.push(e(f)),f=f.right;o(l)};switch(t){case"IN":for(;s;){if(s.left){let a=this.getPredecessor(s);if(a.right)a.right=null;else{a.right=s,s=s.left;continue}}r.push(e(s)),s=s.right}break;case"PRE":for(;s;){if(s.left){let a=this.getPredecessor(s);if(a.right)a.right=null;else{a.right=s,r.push(e(s)),s=s.left;continue}}else r.push(e(s));s=s.right}break;case"POST":for(;s;){if(s.left){let a=this.getPredecessor(s);if(a.right===null){a.right=s,s=s.left;continue}else a.right=null,d(s.left)}s=s.right}d(n);break}return r}clone(){let e=this._createInstance();return this._clone(e),e}filter(e,t){let n=this._createInstance(),r=0;for(let[s,o]of this)e.call(t,o,s,r++,this)&&n.set([s,o]);return n}map(e,t,n){let r=this._createLike([],t),s=0;for(let[o,d]of this)r.set(e.call(n,d,o,s++,this));return r}toVisual(e=this._root,t){let n={isShowUndefined:!1,isShowNull:!0,isShowRedBlackNIL:!1,...t};e=this.ensureNode(e);let r="";return e&&(n.isShowUndefined&&(r+=`U for undefined
|
|
1
|
+
"use strict";var dataStructureTyped=(()=>{var Re=Object.defineProperty;var mt=Object.getOwnPropertyDescriptor;var Kt=Object.getOwnPropertyNames;var Vt=Object.prototype.hasOwnProperty;var ct=h=>{throw TypeError(h)};var yt=(h,i,e)=>i in h?Re(h,i,{enumerable:!0,configurable:!0,writable:!0,value:e}):h[i]=e;var Tt=(h,i)=>{for(var e in i)Re(h,e,{get:i[e],enumerable:!0})},Et=(h,i,e,t)=>{if(i&&typeof i=="object"||typeof i=="function")for(let n of Kt(i))!Vt.call(h,n)&&n!==e&&Re(h,n,{get:()=>i[n],enumerable:!(t=mt(i,n))||t.enumerable});return h};var Nt=h=>Et(Re({},"__esModule",{value:!0}),h);var u=(h,i,e)=>yt(h,typeof i!="symbol"?i+"":i,e),pt=(h,i,e)=>i.has(h)||ct("Cannot "+e);var _=(h,i,e)=>(pt(h,i,"read from private field"),e?e.call(h):i.get(h)),C=(h,i,e)=>i.has(h)?ct("Cannot add the same private member more than once"):i instanceof WeakSet?i.add(h):i.set(h,e),S=(h,i,e,t)=>(pt(h,i,"write to private field"),t?t.call(h,e):i.set(h,e),e);var Bt={};Tt(Bt,{AVLTree:()=>tt,AVLTreeNode:()=>ye,AbstractEdge:()=>q,AbstractGraph:()=>X,AbstractVertex:()=>w,BST:()=>J,BSTNode:()=>Ve,BinaryIndexedTree:()=>Ze,BinaryTree:()=>Ke,BinaryTreeNode:()=>oe,Character:()=>Ce,DFSOperation:()=>Ye,Deque:()=>Ge,DirectedEdge:()=>se,DirectedGraph:()=>me,DirectedVertex:()=>$,DoublyLinkedList:()=>je,DoublyLinkedListNode:()=>ge,FibonacciHeap:()=>We,FibonacciHeapNode:()=>Le,HashMap:()=>ze,Heap:()=>D,IterableElementBase:()=>F,IterableEntryBase:()=>z,LinkedHashMap:()=>Pe,LinkedListQueue:()=>qe,MapEdge:()=>ve,MapGraph:()=>Je,MapVertex:()=>we,Matrix:()=>at,MaxHeap:()=>Qe,MaxPriorityQueue:()=>dt,MinHeap:()=>Xe,MinPriorityQueue:()=>ot,Navigator:()=>lt,PriorityQueue:()=>ee,Queue:()=>O,Range:()=>H,RedBlackTree:()=>A,RedBlackTreeNode:()=>G,SegmentTree:()=>et,SegmentTreeNode:()=>de,SinglyLinkedList:()=>_e,SinglyLinkedListNode:()=>re,SkipList:()=>He,SkipListNode:()=>be,Stack:()=>Ue,TreeMap:()=>rt,TreeMultiMap:()=>it,TreeMultiMapNode:()=>nt,TreeMultiSet:()=>st,TreeNode:()=>ht,TreeSet:()=>Y,Trie:()=>ut,TrieNode:()=>pe,UndirectedEdge:()=>Ie,UndirectedGraph:()=>$e,UndirectedVertex:()=>Be,arrayRemove:()=>P,asyncTrampoline:()=>bt,calcMinUnitsRequired:()=>ke,getMSB:()=>De,isComparable:()=>Q,isTrampolineThunk:()=>Ae,isWeakKey:()=>W,makeAsyncTrampoline:()=>Mt,makeTrampoline:()=>xe,makeTrampolineThunk:()=>Me,rangeCheck:()=>j,roundFixed:()=>kt,throwRangeError:()=>Rt,toBinaryString:()=>xt,trampoline:()=>gt,uuidV4:()=>Fe});var z=class{*[Symbol.iterator](...i){yield*this._getIterator(...i)}*entries(){for(let i of this)yield i}*keys(){for(let i of this)yield i[0]}*values(){for(let i of this)yield i[1]}every(i,e){let t=0;for(let n of this)if(!i.call(e,n[1],n[0],t++,this))return!1;return!0}some(i,e){let t=0;for(let n of this)if(i.call(e,n[1],n[0],t++,this))return!0;return!1}forEach(i,e){let t=0;for(let n of this){let[r,s]=n;i.call(e,s,r,t++,this)}}find(i,e){let t=0;for(let n of this){let[r,s]=n;if(i.call(e,s,r,t++,this))return n}}has(i){for(let e of this){let[t]=e;if(t===i)return!0}return!1}hasValue(i){for(let[,e]of this)if(e===i)return!0;return!1}get(i){for(let e of this){let[t,n]=e;if(t===i)return n}}reduce(i,e){let t=e,n=0;for(let r of this){let[s,o]=r;t=i(t,o,s,n++,this)}return t}toArray(){return[...this]}toVisual(){return[...this]}print(){console.log(this.toVisual())}};var F=class{constructor(i){u(this,"_toElementFn");if(i){let{toElementFn:e}=i;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](...i){yield*this._getIterator(...i)}*values(){for(let i of this)yield i}every(i,e){let t=0;for(let n of this)if(e===void 0){if(!i(n,t++,this))return!1}else if(!i.call(e,n,t++,this))return!1;return!0}some(i,e){let t=0;for(let n of this)if(e===void 0){if(i(n,t++,this))return!0}else if(i.call(e,n,t++,this))return!0;return!1}forEach(i,e){let t=0;for(let n of this)e===void 0?i(n,t++,this):i.call(e,n,t++,this)}find(i,e){let t=0;for(let n of this)if(e===void 0){if(i(n,t++,this))return n}else if(i.call(e,n,t++,this))return n}has(i){for(let e of this)if(e===i)return!0;return!1}reduce(i,e){let t=0,n=this[Symbol.iterator](),r;if(arguments.length>=2)r=e;else{let s=n.next();if(s.done)throw new TypeError("Reduce of empty structure with no initial value");r=s.value,t=1}for(let s of n)r=i(r,s,t++,this);return r}toArray(){return[...this]}toVisual(){return[...this]}print(){console.log(this.toVisual())}};var Fe=function(){return"xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx".replace(/[x]/g,function(h){let i=Math.random()*16|0;return(h=="x"?i:i&3|8).toString(16)})},P=function(h,i){let e=-1,t=h?h.length:0,n=[];for(;++e<t;){let r=h[e];i(r,e,h)&&(n.push(r),Array.prototype.splice.call(h,e--,1),t--)}return n},De=h=>h<=0?0:1<<31-Math.clz32(h),j=(h,i,e,t="Index out of bounds.")=>{if(h<i||h>e)throw new RangeError(t)},Rt=(h="The value is off-limits.")=>{throw new RangeError(h)},W=h=>{let i=typeof h;return i==="object"&&h!==null||i==="function"},ke=(h,i)=>Math.floor((h+i-1)/i),kt=(h,i=10)=>{let e=Math.pow(10,i);return Math.round(h*e)/e};function Oe(h){let i=typeof h;return i==="number"?!0:i==="bigint"||i==="string"||i==="boolean"}function _t(h){if(typeof h.valueOf=="function"){let i=h.valueOf();if(i!==h){if(Oe(i))return i;if(typeof i=="object"&&i!==null)return _t(i)}}if(typeof h.toString=="function"){let i=h.toString();if(i!=="[object Object]")return i}return null}function Q(h,i=!1){if(h==null)return!1;if(Oe(h))return!0;if(typeof h!="object")return!1;if(h instanceof Date||i)return!0;let e=_t(h);return e==null?!1:Oe(e)}var Me=h=>({isThunk:!0,fn:h}),Ae=h=>typeof h=="object"&&h!==null&&"isThunk"in h&&h.isThunk;function gt(h){let i=h;for(;Ae(i);)i=i.fn();return i}function xe(h){return(...i)=>gt(h(...i))}async function bt(h){let i=await h;for(;Ae(i);)i=await i.fn();return i}function Mt(h){return async(...i)=>bt(h(...i))}function xt(h,i=32){let e=(h>>>0).toString(2);return e=e.padStart(i,"0"),e}var ze=class extends z{constructor(e=[],t){super();u(this,"_store",{});u(this,"_objMap",new Map);u(this,"_toEntryFn");u(this,"_size",0);u(this,"_hashFn",e=>String(e));if(t){let{hashFn:n,toEntryFn:r}=t;n&&(this._hashFn=n),r&&(this._toEntryFn=r)}e&&this.setMany(e)}get store(){return this._store}get objMap(){return this._objMap}get toEntryFn(){return this._toEntryFn}get size(){return this._size}get hashFn(){return this._hashFn}isEmpty(){return this._size===0}clear(){this._store={},this._objMap.clear(),this._size=0}isEntry(e){return Array.isArray(e)&&e.length===2}set(e,t){if(this._isObjKey(e))this.objMap.has(e)||this._size++,this.objMap.set(e,t);else{let n=this._getNoObjKey(e);this.store[n]===void 0&&this._size++,this._store[n]={key:e,value:t}}return!0}setMany(e){let t=[];for(let n of e){let r,s;this.isEntry(n)?[r,s]=n:this._toEntryFn&&([r,s]=this._toEntryFn(n)),r!==void 0&&s!==void 0&&t.push(this.set(r,s))}return t}get(e){var n;if(this._isObjKey(e))return this.objMap.get(e);let t=this._getNoObjKey(e);return(n=this._store[t])==null?void 0:n.value}has(e){return this._isObjKey(e)?this.objMap.has(e):this._getNoObjKey(e)in this.store}delete(e){if(this._isObjKey(e))return this.objMap.has(e)&&this._size--,this.objMap.delete(e);let t=this._getNoObjKey(e);return t in this.store?(delete this.store[t],this._size--,!0):!1}setHashFn(e){return this._hashFn===e?this:(this._hashFn=e,this._rehashNoObj(),this)}clone(){let e={hashFn:this._hashFn,toEntryFn:this._toEntryFn};return this._createLike(this,e)}map(e,t){let n=this._createLike(),r=0;for(let[s,o]of this)n.set(s,e.call(t,o,s,r++,this));return n}filter(e,t){let n=this._createLike(),r=0;for(let[s,o]of this)e.call(t,o,s,r++,this)&&n.set(s,o);return n}_createLike(e=[],t){let n=this.constructor;return new n(e,t)}_rehashNoObj(){let e={};for(let{key:t,value:n}of Object.values(this._store)){let r=this._getNoObjKey(t);e[r]={key:t,value:n}}this._store=e}*_getIterator(){for(let e of Object.values(this.store))yield[e.key,e.value];for(let e of this.objMap)yield e}_isObjKey(e){let t=typeof e;return(t==="object"||t==="function")&&e!==null}_getNoObjKey(e){let t=typeof e,n;return t!=="string"&&t!=="number"&&t!=="symbol"?n=this._hashFn(e):n=e,n}},Pe=class extends z{constructor(e=[],t){super();u(this,"_sentinel");u(this,"_hashFn",e=>String(e));u(this,"_objHashFn",e=>e);u(this,"_noObjMap",{});u(this,"_objMap",new WeakMap);u(this,"_head");u(this,"_tail");u(this,"_toEntryFn",e=>{if(this.isEntry(e))return e;throw new Error("If `entryOrRawElements` does not adhere to [key,value], provide `options.toEntryFn` to transform raw records.")});u(this,"_size",0);if(this._sentinel={},this._sentinel.prev=this._sentinel.next=this._head=this._tail=this._sentinel,t){let{hashFn:n,objHashFn:r,toEntryFn:s}=t;n&&(this._hashFn=n),r&&(this._objHashFn=r),s&&(this._toEntryFn=s)}e&&this.setMany(e)}get hashFn(){return this._hashFn}get objHashFn(){return this._objHashFn}get noObjMap(){return this._noObjMap}get objMap(){return this._objMap}get head(){return this._head}get tail(){return this._tail}get toEntryFn(){return this._toEntryFn}get size(){return this._size}get first(){if(this._size!==0)return[this.head.key,this.head.value]}get last(){if(this._size!==0)return[this.tail.key,this.tail.value]}*begin(){let e=this.head;for(;e!==this._sentinel;)yield[e.key,e.value],e=e.next}*reverseBegin(){let e=this.tail;for(;e!==this._sentinel;)yield[e.key,e.value],e=e.prev}set(e,t){let n,r=!this.has(e);if(W(e)){let s=this._objHashFn(e);n=this.objMap.get(s),!n&&r?(n={key:s,value:t,prev:this.tail,next:this._sentinel},this.objMap.set(s,n)):n&&(n.value=t)}else{let s=this._hashFn(e);n=this.noObjMap[s],!n&&r?this.noObjMap[s]=n={key:e,value:t,prev:this.tail,next:this._sentinel}:n&&(n.value=t)}return n&&r&&(this._size===0?(this._head=n,this._sentinel.next=n):(this.tail.next=n,n.prev=this.tail),this._tail=n,this._sentinel.prev=n,this._size++),!0}setMany(e){let t=[];for(let n of e){let r,s;this.isEntry(n)?[r,s]=n:this._toEntryFn&&([r,s]=this._toEntryFn(n)),r!==void 0&&s!==void 0&&t.push(this.set(r,s))}return t}has(e){if(W(e)){let n=this._objHashFn(e);return this.objMap.has(n)}return this._hashFn(e)in this.noObjMap}get(e){if(W(e)){let r=this._objHashFn(e),s=this.objMap.get(r);return s?s.value:void 0}let t=this._hashFn(e),n=this.noObjMap[t];return n?n.value:void 0}at(e){j(e,0,this._size-1);let t=this.head;for(;e--;)t=t.next;return t.value}delete(e){let t;if(W(e)){let n=this._objHashFn(e);if(t=this.objMap.get(n),!t)return!1;this.objMap.delete(n)}else{let n=this._hashFn(e);if(t=this.noObjMap[n],!t)return!1;delete this.noObjMap[n]}return this._deleteNode(t)}deleteWhere(e){let t=this._head,n=0;for(;t!==this._sentinel;){let r=t;if(t=t.next,e(r.key,r.value,n++,this)){if(W(r.key))this._objMap.delete(r.key);else{let s=this._hashFn(r.key);delete this._noObjMap[s]}return this._deleteNode(r)}}return!1}deleteAt(e){j(e,0,this._size-1);let t=this.head;for(;e--;)t=t.next;return this._deleteNode(t)}isEmpty(){return this._size===0}isEntry(e){return Array.isArray(e)&&e.length===2}clear(){this._noObjMap={},this._size=0,this._head=this._tail=this._sentinel.prev=this._sentinel.next=this._sentinel}clone(){let e={hashFn:this._hashFn,objHashFn:this._objHashFn};return this._createLike(this,e)}filter(e,t){let n=this._createLike(),r=0;for(let[s,o]of this)e.call(t,o,s,r,this)&&n.set(s,o),r++;return n}map(e,t){let n=this._createLike(),r=0;for(let[s,o]of this){let[d,a]=e.call(t,o,s,r,this);n.set(d,a),r++}return n}*_getIterator(){let e=this.head;for(;e!==this._sentinel;)yield[e.key,e.value],e=e.next}_deleteNode(e){let{prev:t,next:n}=e;return t.next=n,n.prev=t,e===this.head&&(this._head=n),e===this.tail&&(this._tail=t),this._size-=1,!0}_createLike(e=[],t){let n=this.constructor;return new n(e,t)}};var ne=class{constructor(i){u(this,"_value");u(this,"_next");this._value=i,this._next=void 0}get value(){return this._value}set value(i){this._value=i}get next(){return this._next}set next(i){this._next=i}},U=class h extends F{constructor(e){super(e);u(this,"_maxLen",-1);if(e){let{maxLen:t}=e;typeof t=="number"&&t>0&&t%1===0&&(this._maxLen=t)}}get maxLen(){return this._maxLen}indexOf(e,t=0){if(this.length===0)return-1;t<0&&(t=this.length+t),t<0&&(t=0);for(let n=t;n<this.length;n++)if(this.at(n)===e)return n;return-1}lastIndexOf(e,t=this.length-1){if(this.length===0)return-1;t>=this.length&&(t=this.length-1),t<0&&(t=this.length+t);for(let n=t;n>=0;n--)if(this.at(n)===e)return n;return-1}findIndex(e,t){for(let n=0;n<this.length;n++){let r=this.at(n);if(r!==void 0&&e.call(t,r,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 r=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 o=this.deleteAt(e);o!==void 0&&r.push(o)}for(let s=0;s<n.length;s++)this.addAt(e+s,n[s]);return r}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 r=this.length-1;r>=0;r--)n=e(n,this.at(r),r,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 r=e;r<t;r++)n.push(this.at(r));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 r=t;r<n;r++)this.setAt(r,e);return this}},ie=class extends U{constructor(i){if(super(i),i){let{maxLen:e}=i;typeof e=="number"&&e>0&&e%1===0&&(this._maxLen=e)}}indexOf(i,e=0){let t=this._getIterator(),n=t.next(),r=0;for(;r<e;)n=t.next(),r++;for(;!n.done;){if(n.value===i)return r;n=t.next(),r++}return-1}lastIndexOf(i,e=this.length-1){let t=this._getReverseIterator(),n=t.next(),r=this.length-1;for(;r>e;)n=t.next(),r--;for(;!n.done;){if(n.value===i)return r;n=t.next(),r--}return-1}concat(...i){let e=this.clone();for(let t of i)t instanceof U?e.pushMany(t):e.push(t);return e}slice(i=0,e=this.length){i=i<0?this.length+i:i,e=e<0?this.length+e:e;let t=this._createInstance(),n=this._getIterator(),r=n.next(),s=0;for(;s<i;)r=n.next(),s++;for(let o=i;o<e;o++)t.push(r.value),r=n.next();return t}splice(i,e=0,...t){let n=this._createInstance();i=i<0?this.length+i:i,i=Math.max(0,Math.min(i,this.length)),e=Math.max(0,e);let r=0,s,o,d=this._getNodeIterator();for(let a of d){if(r===i){s=a;break}o=a,r++}for(let a=0;a<e&&s;a++){n.push(s.value);let l=s.next;this.delete(s),s=l}for(let a=0;a<t.length;a++)o?(this.addAfter(o,t[a]),o=o.next):(this.addAt(0,t[a]),o=this._getNodeIterator().next().value);return n}reduceRight(i,e){let t=e!=null?e:0,n=this.length-1;for(let r of this._getReverseIterator())t=i(t,r,n--,this);return t}};var re=class extends ne{constructor(e){super(e);u(this,"_next");this._value=e,this._next=void 0}get next(){return this._next}set next(e){this._next=e}},_e=class extends ie{constructor(e=[],t){super(t);u(this,"_equals",Object.is);u(this,"_head");u(this,"_tail");u(this,"_length",0);this.pushMany(e)}get head(){return this._head}get tail(){return this._tail}get length(){return this._length}get first(){var e;return(e=this.head)==null?void 0:e.value}get last(){var e;return(e=this.tail)==null?void 0:e.value}static from(e,t){let n=new this([],t);for(let r of e)n.push(r);return n}push(e){let t=this._ensureNode(e);return this.head?(this.tail.next=t,this._tail=t):this._head=this._tail=t,this._length++,this._maxLen>0&&this.length>this._maxLen&&this.shift(),!0}pop(){if(!this.head)return;if(this.head===this.tail){let n=this.head.value;return this._head=void 0,this._tail=void 0,this._length--,n}let e=this.head;for(;e.next!==this.tail;)e=e.next;let t=this.tail.value;return e.next=void 0,this._tail=e,this._length--,t}shift(){if(!this.head)return;let e=this.head;return this._head=this.head.next,this._head||(this._tail=void 0),this._length--,e.value}unshift(e){let t=this._ensureNode(e);return this.head?(t.next=this.head,this._head=t):this._head=this._tail=t,this._length++,!0}pushMany(e){let t=[];for(let n of e)this.toElementFn?t.push(this.push(this.toElementFn(n))):t.push(this.push(n));return t}unshiftMany(e){let t=[];for(let n of e)this.toElementFn?t.push(this.unshift(this.toElementFn(n))):t.push(this.unshift(n));return t}search(e){let t=this._ensurePredicate(e),n=this.head;for(;n;){if(t(n))return n.value;n=n.next}}at(e){if(e<0||e>=this._length)return;let t=this.head;for(let n=0;n<e;n++)t=t.next;return t.value}isNode(e){return e instanceof re}getNodeAt(e){if(e<0||e>=this._length)return;let t=this.head;for(let n=0;n<e;n++)t=t.next;return t}deleteAt(e){if(e<0||e>=this._length)return;if(e===0)return this.shift();let t=this.getNodeAt(e),n=this._getPrevNode(t),r=t.value;return n.next=t.next,t===this.tail&&(this._tail=n),this._length--,r}delete(e){if(e===void 0||!this.head)return!1;let t=this.isNode(e)?e:this.getNode(e);if(!t)return!1;let n=this._getPrevNode(t);return n?(n.next=t.next,t===this.tail&&(this._tail=n)):(this._head=t.next,t===this.tail&&(this._tail=void 0)),this._length--,!0}addAt(e,t){if(e<0||e>this._length)return!1;if(e===0)return this.unshift(t);if(e===this._length)return this.push(t);let n=this._ensureNode(t),r=this.getNodeAt(e-1);return n.next=r.next,r.next=n,this._length++,!0}setAt(e,t){let n=this.getNodeAt(e);return n?(n.value=t,!0):!1}isEmpty(){return this._length===0}clear(){this._head=void 0,this._tail=void 0,this._length=0}reverse(){if(!this.head||this.head===this.tail)return this;let e,t=this.head,n;for(;t;)n=t.next,t.next=e,e=t,t=n;return[this._head,this._tail]=[this.tail,this.head],this}getNode(e){if(e===void 0)return;if(this.isNode(e))return e;let t=this._ensurePredicate(e),n=this.head;for(;n;){if(t(n))return n;n=n.next}}addBefore(e,t){let n=this.getNode(e);if(!n)return!1;let r=this._getPrevNode(n),s=this._ensureNode(t);return r?(r.next=s,s.next=n,this._length++):(s.next=this._head,this._head=s,this._tail||(this._tail=s),this._length++),!0}addAfter(e,t){let n=this.getNode(e);if(!n)return!1;let r=this._ensureNode(t);return r.next=n.next,n.next=r,n===this.tail&&(this._tail=r),this._length++,!0}splice(e,t=0,...n){e=Math.max(0,Math.min(e,this.length)),t=Math.max(0,t);let r=this._createInstance(),s=e===0?void 0:this.getNodeAt(e-1),o=s?s.next:this.head,d=0;for(;d<t&&o;)r.push(o.value),o=o.next,d++;let a=o;if(s?s.next=a:this._head=a,a||(this._tail=s),n.length>0){let l,f;for(let c of n){let g=this._ensureNode(c);l||(l=g),f&&(f.next=g),f=g}s?s.next=l:this._head=l,f.next=a,a||(this._tail=f)}return this._length+=n.length-d,this._length===0&&(this._head=void 0,this._tail=void 0),r}countOccurrences(e){let t=Lt(e,this._equals),n=0,r=this.head;for(;r;)t(r)&&n++,r=r.next;return n}setEquality(e){return this._equals=e,this}deleteWhere(e){let t,n=this.head,r=0;for(;n;){if(e(n.value,r++,this))return t?(t.next=n.next,n===this._tail&&(this._tail=t)):(this._head=n.next,n===this._tail&&(this._tail=void 0)),this._length--,!0;t=n,n=n.next}return!1}clone(){let e=this._createInstance();for(let t of this)e.push(t);return e}filter(e,t){let n=this._createInstance(),r=0;for(let s of this)e.call(t,s,r++,this)&&n.push(s);return n}mapSame(e,t){let n=this._createInstance(),r=0;for(let s of this){let o=t===void 0?e(s,r++,this):e.call(t,s,r++,this);n.push(o)}return n}map(e,t,n){let r=this._createLike([],{...t!=null?t:{},maxLen:this._maxLen}),s=0;for(let o of this)r.push(e.call(n,o,s++,this));return r}createNode(e){return new re(e)}_isPredicate(e){return typeof e=="function"}_ensureNode(e){return this.isNode(e)?e:this.createNode(e)}_ensurePredicate(e){if(this.isNode(e))return n=>n===e;if(this._isPredicate(e))return e;let t=e;return n=>this._equals(n.value,t)}_getPrevNode(e){if(!this.head||this.head===e)return;let t=this.head;for(;t.next&&t.next!==e;)t=t.next;return t.next===e?t:void 0}*_getIterator(){let e=this.head;for(;e;)yield e.value,e=e.next}*_getReverseIterator(){let e=[...this].reverse();for(let t of e)yield t}*_getNodeIterator(){let e=this.head;for(;e;)yield e,e=e.next}_createInstance(e){let t=this.constructor;return new t([],e)}_createLike(e=[],t){let n=this.constructor;return new n(e,t)}_spawnLike(e){return this._createLike([],e)}};function Lt(h,i){if(h instanceof re)return t=>t===h;if(typeof h=="function")return h;let e=h;return t=>i(t.value,e)}var ge=class extends ne{constructor(e){super(e);u(this,"_next");u(this,"_prev");this._value=e,this._next=void 0,this._prev=void 0}get next(){return this._next}set next(e){this._next=e}get prev(){return this._prev}set prev(e){this._prev=e}},je=class extends ie{constructor(e=[],t){super(t);u(this,"_equals",Object.is);u(this,"_head");u(this,"_tail");u(this,"_length",0);this._head=void 0,this._tail=void 0,this._length=0,t!=null&&t.maxLen&&Number.isInteger(t.maxLen)&&t.maxLen>0&&(this._maxLen=t.maxLen),this.pushMany(e)}get head(){return this._head}get tail(){return this._tail}get length(){return this._length}get first(){var e;return(e=this.head)==null?void 0:e.value}get last(){var e;return(e=this.tail)==null?void 0:e.value}static fromArray(e){return new this(e)}isNode(e){return e instanceof ge}push(e){let t=this._ensureNode(e);return this.head?(t.prev=this.tail,this.tail.next=t,this._tail=t):(this._head=t,this._tail=t),this._length++,this._maxLen>0&&this.length>this._maxLen&&this.shift(),!0}pop(){if(!this.tail)return;let e=this.tail;return this.head===this.tail?(this._head=void 0,this._tail=void 0):(this._tail=e.prev,this.tail.next=void 0),this._length--,e.value}shift(){if(!this.head)return;let e=this.head;return this.head===this.tail?(this._head=void 0,this._tail=void 0):(this._head=e.next,this.head.prev=void 0),this._length--,e.value}unshift(e){let t=this._ensureNode(e);return this.head?(t.next=this.head,this.head.prev=t,this._head=t):(this._head=t,this._tail=t),this._length++,this._maxLen>0&&this._length>this._maxLen&&this.pop(),!0}pushMany(e){let t=[];for(let n of e)this.toElementFn?t.push(this.push(this.toElementFn(n))):t.push(this.push(n));return t}unshiftMany(e){let t=[];for(let n of e)this.toElementFn?t.push(this.unshift(this.toElementFn(n))):t.push(this.unshift(n));return t}at(e){if(e<0||e>=this._length)return;let t=this.head;for(let n=0;n<e;n++)t=t.next;return t.value}getNodeAt(e){if(e<0||e>=this._length)return;let t=this.head;for(let n=0;n<e;n++)t=t.next;return t}getNode(e){if(e===void 0)return;if(this.isNode(e)){let r=e,s=this.head;for(;s;){if(s===r)return r;s=s.next}let o=d=>this._equals(d.value,r.value);for(s=this.head;s;){if(o(s))return s;s=s.next}return}let t=this._ensurePredicate(e),n=this.head;for(;n;){if(t(n))return n;n=n.next}}addAt(e,t){if(e<0||e>this._length)return!1;if(e===0)return this.unshift(t);if(e===this._length)return this.push(t);let n=this._ensureNode(t),r=this.getNodeAt(e-1),s=r.next;return n.prev=r,n.next=s,r.next=n,s.prev=n,this._length++,!0}addBefore(e,t){let n=this.isNode(e)?e:this.getNode(e);if(!n)return!1;let r=this._ensureNode(t);return r.prev=n.prev,n.prev&&(n.prev.next=r),r.next=n,n.prev=r,n===this.head&&(this._head=r),this._length++,!0}addAfter(e,t){let n=this.isNode(e)?e:this.getNode(e);if(!n)return!1;let r=this._ensureNode(t);return r.next=n.next,n.next&&(n.next.prev=r),r.prev=n,n.next=r,n===this.tail&&(this._tail=r),this._length++,!0}setAt(e,t){let n=this.getNodeAt(e);return n?(n.value=t,!0):!1}deleteAt(e){if(e<0||e>=this._length)return;if(e===0)return this.shift();if(e===this._length-1)return this.pop();let t=this.getNodeAt(e),n=t.prev,r=t.next;return n.next=r,r.prev=n,this._length--,t.value}delete(e){let t=this.getNode(e);if(!t)return!1;if(t===this.head)this.shift();else if(t===this.tail)this.pop();else{let n=t.prev,r=t.next;n.next=r,r.prev=n,this._length--}return!0}isEmpty(){return this._length===0}clear(){this._head=void 0,this._tail=void 0,this._length=0}search(e){let t=this._ensurePredicate(e),n=this.head;for(;n;){if(t(n))return n.value;n=n.next}}getBackward(e){let t=this._ensurePredicate(e),n=this.tail;for(;n;){if(t(n))return n.value;n=n.prev}}reverse(){let e=this.head;for([this._head,this._tail]=[this.tail,this.head];e;){let t=e.next;[e.prev,e.next]=[e.next,e.prev],e=t}return this}setEquality(e){return this._equals=e,this}clone(){let e=this._createInstance({toElementFn:this._toElementFn,maxLen:this._maxLen});for(let t of this)e.push(t);return e}filter(e,t){let n=this._createInstance({toElementFn:this._toElementFn,maxLen:this._maxLen}),r=0;for(let s of this)e.call(t,s,r++,this)&&n.push(s);return n}mapSame(e,t){let n=this._createInstance({toElementFn:this._toElementFn,maxLen:this._maxLen}),r=0;for(let s of this){let o=t===void 0?e(s,r++,this):e.call(t,s,r++,this);n.push(o)}return n}map(e,t,n){let r=this._createLike([],{...t!=null?t:{},maxLen:this._maxLen}),s=0;for(let o of this)r.push(e.call(n,o,s++,this));return r}_ensureNode(e){return this.isNode(e)?e:new ge(e)}_ensurePredicate(e){if(this.isNode(e)){let n=e;return r=>r===n}if(typeof e=="function")return e;let t=e;return n=>this._equals(n.value,t)}_getPrevNode(e){return e.prev}_createInstance(e){let t=this.constructor;return new t([],e)}_createLike(e=[],t){let n=this.constructor;return new n(e,t)}*_getIterator(){let e=this.head;for(;e;)yield e.value,e=e.next}*_getReverseIterator(){let e=this.tail;for(;e;)yield e.value,e=e.prev}*_getNodeIterator(){let e=this.head;for(;e;)yield e,e=e.next}};var be=class{constructor(i,e,t){u(this,"key");u(this,"value");u(this,"forward");this.key=i,this.value=e,this.forward=new Array(t)}},He=class{constructor(i=[],e){u(this,"_head",new be(void 0,void 0,this.maxLevel));u(this,"_level",0);u(this,"_maxLevel",16);u(this,"_probability",.5);if(e){let{maxLevel:t,probability:n}=e;typeof t=="number"&&(this._maxLevel=t),typeof n=="number"&&(this._probability=n)}if(i)for(let[t,n]of i)this.add(t,n)}get head(){return this._head}get level(){return this._level}get maxLevel(){return this._maxLevel}get probability(){return this._probability}get first(){let i=this.head.forward[0];return i?i.value:void 0}get last(){let i=this.head;for(let e=this.level-1;e>=0;e--)for(;i.forward[e];)i=i.forward[e];return i.value}add(i,e){let t=new be(i,e,this._randomLevel()),n=new Array(this.maxLevel).fill(this.head),r=this.head;for(let s=this.level-1;s>=0;s--){for(;r.forward[s]&&r.forward[s].key<i;)r=r.forward[s];n[s]=r}for(let s=0;s<t.forward.length;s++)t.forward[s]=n[s].forward[s],n[s].forward[s]=t;t.forward[0]||(this._level=Math.max(this.level,t.forward.length))}get(i){let e=this.head;for(let t=this.level-1;t>=0;t--)for(;e.forward[t]&&e.forward[t].key<i;)e=e.forward[t];if(e=e.forward[0],e&&e.key===i)return e.value}has(i){return this.get(i)!==void 0}delete(i){let e=new Array(this.maxLevel).fill(this.head),t=this.head;for(let n=this.level-1;n>=0;n--){for(;t.forward[n]&&t.forward[n].key<i;)t=t.forward[n];e[n]=t}if(t=t.forward[0],t&&t.key===i){for(let n=0;n<this.level&&e[n].forward[n]===t;n++)e[n].forward[n]=t.forward[n];for(;this.level>0&&!this.head.forward[this.level-1];)this._level--;return!0}return!1}higher(i){let e=this.head;for(let n=this.level-1;n>=0;n--)for(;e.forward[n]&&e.forward[n].key<=i;)e=e.forward[n];let t=e.forward[0];return t?t.value:void 0}lower(i){let e=this.head,t;for(let n=this.level-1;n>=0;n--){for(;e.forward[n]&&e.forward[n].key<i;)e=e.forward[n];e.key<i&&(t=e)}return t?t.value:void 0}_randomLevel(){let i=1;for(;Math.random()<this.probability&&i<this.maxLevel;)i++;return i}};var Ue=class extends F{constructor(e=[],t){super(t);u(this,"_equals",Object.is);u(this,"_elements",[]);this.pushMany(e)}get elements(){return this._elements}get size(){return this.elements.length}static fromArray(e,t){return new this(e,t)}isEmpty(){return this.elements.length===0}peek(){return this.isEmpty()?void 0:this.elements[this.elements.length-1]}push(e){return this.elements.push(e),!0}pop(){return this.isEmpty()?void 0:this.elements.pop()}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}delete(e){let t=this._indexOfByEquals(e);return this.deleteAt(t)}deleteAt(e){return e<0||e>=this.elements.length?!1:this.elements.splice(e,1).length===1}deleteWhere(e){for(let t=0;t<this.elements.length;t++)if(e(this.elements[t],t,this))return this.elements.splice(t,1),!0;return!1}clear(){this._elements=[]}clone(){let e=this._createInstance({toElementFn:this.toElementFn});for(let t of this)e.push(t);return e}filter(e,t){let n=this._createInstance({toElementFn:this.toElementFn}),r=0;for(let s of this)e.call(t,s,r,this)&&n.push(s),r++;return n}mapSame(e,t){let n=this._createInstance({toElementFn:this.toElementFn}),r=0;for(let s of this){let o=t===void 0?e(s,r++,this):e.call(t,s,r++,this);n.push(o)}return n}map(e,t,n){let r=this._createLike([],{...t!=null?t:{}}),s=0;for(let o of this)r.push(n===void 0?e(o,s,this):e.call(n,o,s,this)),s++;return r}setEquality(e){return this._equals=e,this}_indexOfByEquals(e){for(let t=0;t<this.elements.length;t++)if(this._equals(this.elements[t],e))return t;return-1}_createInstance(e){let t=this.constructor;return new t([],e)}_createLike(e=[],t){let n=this.constructor;return new n(e,t)}*_getIterator(){for(let e=0;e<this.elements.length;e++)yield this.elements[e]}};var O=class h extends U{constructor(e=[],t){super(t);u(this,"_elements",[]);u(this,"_offset",0);u(this,"_autoCompactRatio",.5);if(t){let{autoCompactRatio:n=.5}=t;this._autoCompactRatio=n}this.pushMany(e)}get elements(){return this._elements}get offset(){return this._offset}get autoCompactRatio(){return this._autoCompactRatio}set autoCompactRatio(e){this._autoCompactRatio=e}get length(){return this.elements.length-this._offset}get first(){return this.length>0?this.elements[this._offset]:void 0}get last(){return this.length>0?this.elements[this.elements.length-1]:void 0}static fromArray(e){return new 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 r=this._offset+e,s=this._elements.splice(r,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(s),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 r=0;for(let s of this)e.call(t,s,r,this)&&n.push(s),r++;return n}map(e,t,n){var o,d;let r=new this.constructor([],{toElementFn:t==null?void 0:t.toElementFn,maxLen:(o=t==null?void 0:t.maxLen)!=null?o:this._maxLen,autoCompactRatio:(d=t==null?void 0:t.autoCompactRatio)!=null?d:this._autoCompactRatio}),s=0;for(let a of this)r.push(n===void 0?e(a,s++,this):e.call(n,a,s++,this));return r}mapSame(e,t){var o;let n=this.constructor,r=new n([],{toElementFn:this.toElementFn,maxLen:this._maxLen,autoCompactRatio:this._autoCompactRatio});(o=r._setAutoCompactRatio)==null||o.call(r,this._autoCompactRatio);let s=0;for(let d of this){let a=t===void 0?e(d,s++,this):e.call(t,d,s++,this);r.push(a)}return r}_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)}},qe=class extends _e{clone(){let i=this._createInstance({toElementFn:this.toElementFn,maxLen:this._maxLen});for(let e of this)i.push(e);return i}};var Ge=class extends U{constructor(e=[],t){super(t);u(this,"_equals",Object.is);u(this,"_bucketSize",4096);u(this,"_bucketFirst",0);u(this,"_firstInBucket",0);u(this,"_bucketLast",0);u(this,"_lastInBucket",0);u(this,"_bucketCount",0);u(this,"_buckets",[]);u(this,"_length",0);if(t){let{bucketSize:s}=t;typeof s=="number"&&(this._bucketSize=s)}let n;"length"in e?n=typeof e.length=="function"?e.length():e.length:n=typeof e.size=="function"?e.size():e.size,this._bucketCount=ke(n,this._bucketSize)||1;for(let s=0;s<this._bucketCount;++s)this._buckets.push(new Array(this._bucketSize));let r=ke(n,this._bucketSize);this._bucketFirst=this._bucketLast=(this._bucketCount>>1)-(r>>1),this._firstInBucket=this._lastInBucket=this._bucketSize-n%this._bucketSize>>1,this.pushMany(e)}get bucketSize(){return this._bucketSize}get bucketFirst(){return this._bucketFirst}get firstInBucket(){return this._firstInBucket}get bucketLast(){return this._bucketLast}get lastInBucket(){return this._lastInBucket}get bucketCount(){return this._bucketCount}get buckets(){return this._buckets}get length(){return this._length}get first(){if(this._length!==0)return this._buckets[this._bucketFirst][this._firstInBucket]}get last(){if(this._length!==0)return this._buckets[this._bucketLast][this._lastInBucket]}static fromArray(e,t){return new this(e,t)}push(e){return this._length&&(this._lastInBucket<this._bucketSize-1?this._lastInBucket+=1:this._bucketLast<this._bucketCount-1?(this._bucketLast+=1,this._lastInBucket=0):(this._bucketLast=0,this._lastInBucket=0),this._bucketLast===this._bucketFirst&&this._lastInBucket===this._firstInBucket&&this._reallocate()),this._length+=1,this._buckets[this._bucketLast][this._lastInBucket]=e,this._maxLen>0&&this._length>this._maxLen&&this.shift(),!0}pop(){if(this._length===0)return;let e=this._buckets[this._bucketLast][this._lastInBucket];return this._length!==1&&(this._lastInBucket>0?this._lastInBucket-=1:this._bucketLast>0?(this._bucketLast-=1,this._lastInBucket=this._bucketSize-1):(this._bucketLast=this._bucketCount-1,this._lastInBucket=this._bucketSize-1)),this._length-=1,e}shift(){if(this._length===0)return;let e=this._buckets[this._bucketFirst][this._firstInBucket];return this._length!==1&&(this._firstInBucket<this._bucketSize-1?this._firstInBucket+=1:this._bucketFirst<this._bucketCount-1?(this._bucketFirst+=1,this._firstInBucket=0):(this._bucketFirst=0,this._firstInBucket=0)),this._length-=1,e}unshift(e){return this._length&&(this._firstInBucket>0?this._firstInBucket-=1:this._bucketFirst>0?(this._bucketFirst-=1,this._firstInBucket=this._bucketSize-1):(this._bucketFirst=this._bucketCount-1,this._firstInBucket=this._bucketSize-1),this._bucketFirst===this._bucketLast&&this._firstInBucket===this._lastInBucket&&this._reallocate()),this._length+=1,this._buckets[this._bucketFirst][this._firstInBucket]=e,this._maxLen>0&&this._length>this._maxLen&&this.pop(),!0}pushMany(e){let t=[];for(let n of e)this.toElementFn?t.push(this.push(this.toElementFn(n))):t.push(this.push(n));return t}unshiftMany(e=[]){let t=[];for(let n of e)this.toElementFn?t.push(this.unshift(this.toElementFn(n))):t.push(this.unshift(n));return t}isEmpty(){return this._length===0}clear(){this._buckets=[new Array(this._bucketSize)],this._bucketCount=1,this._bucketFirst=this._bucketLast=this._length=0,this._firstInBucket=this._lastInBucket=this._bucketSize>>1}at(e){if(e<0||e>=this._length)return;let{bucketIndex:t,indexInBucket:n}=this._getBucketAndPosition(e);return this._buckets[t][n]}setAt(e,t){j(e,0,this._length-1);let{bucketIndex:n,indexInBucket:r}=this._getBucketAndPosition(e);return this._buckets[n][r]=t,!0}addAt(e,t,n=1){let r=this._length;if(j(e,0,r),e===0)for(;n--;)this.unshift(t);else if(e===this._length)for(;n--;)this.push(t);else{let s=[];for(let o=e;o<this._length;++o){let d=this.at(o);d!==void 0&&s.push(d)}this.cut(e-1,!0);for(let o=0;o<n;++o)this.push(t);for(let o=0;o<s.length;++o)this.push(s[o])}return!0}cut(e,t=!1){if(t){if(e<0)return this.clear(),this;let{bucketIndex:n,indexInBucket:r}=this._getBucketAndPosition(e);return this._bucketLast=n,this._lastInBucket=r,this._length=e+1,this}else{let n=this._createInstance({toElementFn:this._toElementFn,maxLen:this._maxLen});n._setBucketSize(this._bucketSize);for(let r=0;r<=e;r++){let s=this.at(r);s!==void 0&&n.push(s)}return n}}splice(e,t=this._length-e,...n){j(e,0,this._length),t<0&&(t=0),e+t>this._length&&(t=this._length-e);let r=this._createInstance({toElementFn:this._toElementFn,maxLen:this._maxLen});r._setBucketSize(this._bucketSize);for(let o=0;o<t;o++){let d=this.at(e+o);d!==void 0&&r.push(d)}let s=[];for(let o=e+t;o<this._length;o++){let d=this.at(o);d!==void 0&&s.push(d)}this.cut(e-1,!0);for(let o of n)this.push(o);for(let o of s)this.push(o);return r}cutRest(e,t=!1){if(t){if(e<0)return this;let{bucketIndex:n,indexInBucket:r}=this._getBucketAndPosition(e);return this._bucketFirst=n,this._firstInBucket=r,this._length=this._length-e,this}else{let n=this._createInstance({toElementFn:this._toElementFn,maxLen:this._maxLen});n._setBucketSize(this._bucketSize),e<0&&(e=0);for(let r=e;r<this._length;r++){let s=this.at(r);s!==void 0&&n.push(s)}return n}}deleteAt(e){j(e,0,this._length-1);let t;if(e===0)return this.shift();if(e===this._length-1)return t=this.last,this.pop(),t;{let n=this._length-1,{bucketIndex:r,indexInBucket:s}=this._getBucketAndPosition(e);t=this._buckets[r][s];for(let o=e;o<n;o++){let{bucketIndex:d,indexInBucket:a}=this._getBucketAndPosition(o),{bucketIndex:l,indexInBucket:f}=this._getBucketAndPosition(o+1);this._buckets[d][a]=this._buckets[l][f]}return this.pop(),t}}delete(e){let t=this._length;if(t===0)return!1;let n=0,r=0;for(;n<t;){let s=this.at(n);this._equals(s,e)||(this.setAt(r,s),r+=1),n+=1}return this.cut(r-1,!0),!0}deleteWhere(e){for(let t=0;t<this._length;t++){let n=this.at(t);if(e(n,t,this))return this.deleteAt(t),!0}return!1}setEquality(e){return this._equals=e,this}reverse(){this._buckets.reverse().forEach(function(s){s.reverse()});let{_bucketFirst:e,_bucketLast:t,_firstInBucket:n,_lastInBucket:r}=this;return this._bucketFirst=this._bucketCount-t-1,this._bucketLast=this._bucketCount-e-1,this._firstInBucket=this._bucketSize-r-1,this._lastInBucket=this._bucketSize-n-1,this}unique(){if(this._length<=1)return this;let e=1,t=this.at(0);for(let n=1;n<this._length;++n){let r=this.at(n);this._equals(r,t)||(t=r,this.setAt(e++,r))}return this.cut(e-1,!0),this}shrinkToFit(){if(this._length===0)return;let e=[];if(this._bucketFirst!==this._bucketLast){if(this._bucketFirst<this._bucketLast)for(let t=this._bucketFirst;t<=this._bucketLast;++t)e.push(this._buckets[t]);else{for(let t=this._bucketFirst;t<this._bucketCount;++t)e.push(this._buckets[t]);for(let t=0;t<=this._bucketLast;++t)e.push(this._buckets[t])}this._bucketFirst=0,this._bucketLast=e.length-1,this._buckets=e}}clone(){return this._createLike(this,{bucketSize:this.bucketSize,toElementFn:this.toElementFn,maxLen:this._maxLen})}filter(e,t){let n=this._createInstance({toElementFn:this.toElementFn,maxLen:this._maxLen});n._setBucketSize(this._bucketSize);let r=0;for(let s of this)e.call(t,s,r,this)&&n.push(s),r++;return n}mapSame(e,t){let n=this._createInstance({toElementFn:this._toElementFn,maxLen:this._maxLen});n._setBucketSize(this._bucketSize);let r=0;for(let s of this){let o=t===void 0?e(s,r++,this):e.call(t,s,r++,this);n.push(o)}return n}map(e,t,n){let r=this._createLike([],{...t!=null?t:{},bucketSize:this._bucketSize,maxLen:this._maxLen}),s=0;for(let o of this){let d=n===void 0?e(o,s,this):e.call(n,o,s,this);r.push(d),s++}return r}_setBucketSize(e){this._bucketSize=e,this._length===0&&(this._buckets=[new Array(this._bucketSize)],this._bucketCount=1,this._bucketFirst=this._bucketLast=0,this._firstInBucket=this._lastInBucket=this._bucketSize>>1)}*_getIterator(){for(let e=0;e<this._length;++e){let t=this.at(e);t!==void 0&&(yield t)}}_reallocate(e){let t=[],n=e||this._bucketCount>>1||1;for(let r=0;r<n;++r)t[r]=new Array(this._bucketSize);for(let r=this._bucketFirst;r<this._bucketCount;++r)t[t.length]=this._buckets[r];for(let r=0;r<this._bucketLast;++r)t[t.length]=this._buckets[r];t[t.length]=[...this._buckets[this._bucketLast]],this._bucketFirst=n,this._bucketLast=t.length-1;for(let r=0;r<n;++r)t[t.length]=new Array(this._bucketSize);this._buckets=t,this._bucketCount=t.length}_getBucketAndPosition(e){let t,n,r=this._firstInBucket+e;return t=this._bucketFirst+Math.floor(r/this._bucketSize),t>=this._bucketCount&&(t-=this._bucketCount),n=(r+1)%this._bucketSize-1,n<0&&(n=this._bucketSize-1),{bucketIndex:t,indexInBucket:n}}_createInstance(e){let t=this.constructor;return new t([],e)}_createLike(e=[],t){let n=this.constructor;return new n(e,t)}*_getReverseIterator(){for(let e=this._length-1;e>-1;e--){let t=this.at(e);t!==void 0&&(yield t)}}};var D=class h extends F{constructor(e=[],t){super(t);u(this,"_equals",Object.is);u(this,"_elements",[]);u(this,"_DEFAULT_COMPARATOR",(e,t)=>{if(typeof e=="object"||typeof t=="object")throw TypeError("When comparing object types, define a custom comparator in options.");return e>t?1:e<t?-1:0});u(this,"_comparator",this._DEFAULT_COMPARATOR);if(t){let{comparator:n}=t;n&&(this._comparator=n)}this.addMany(e)}get elements(){return this._elements}get size(){return this.elements.length}get leaf(){var e;return(e=this.elements[this.size-1])!=null?e:void 0}static from(e,t){return new this(e,t)}static heapify(e,t){return new h(e,t)}add(e){return this._elements.push(e),this._bubbleUp(this.elements.length-1)}addMany(e){let t=[];for(let n of e)if(this.toElementFn){let r=this.add(this.toElementFn(n));t.push(r)}else{let r=this.add(n);t.push(r)}return t}poll(){if(this.elements.length===0)return;let e=this.elements[0],t=this.elements.pop();return this.elements.length&&(this.elements[0]=t,this._sinkDown(0,this.elements.length>>1)),e}peek(){return this.elements[0]}isEmpty(){return this.size===0}clear(){this._elements=[]}refill(e){return this._elements=Array.from(e),this.fix()}has(e){for(let t of this.elements)if(this._equals(t,e))return!0;return!1}delete(e){let t=-1;for(let n=0;n<this.elements.length;n++)if(this._equals(this.elements[n],e)){t=n;break}return t<0?!1:(t===0?this.poll():t===this.elements.length-1?this.elements.pop():(this.elements.splice(t,1,this.elements.pop()),this._bubbleUp(t),this._sinkDown(t,this.elements.length>>1)),!0)}deleteBy(e){let t=-1;for(let n=0;n<this.elements.length;n++)if(e(this.elements[n],n,this)){t=n;break}return t<0?!1:(t===0?this.poll():t===this.elements.length-1?this.elements.pop():(this.elements.splice(t,1,this.elements.pop()),this._bubbleUp(t),this._sinkDown(t,this.elements.length>>1)),!0)}setEquality(e){return this._equals=e,this}dfs(e="PRE"){let t=[],n=r=>{let s=2*r+1,o=s+1;r<this.size&&(e==="IN"?(n(s),t.push(this.elements[r]),n(o)):e==="PRE"?(t.push(this.elements[r]),n(s),n(o)):e==="POST"&&(n(s),n(o),t.push(this.elements[r])))};return n(0),t}fix(){let e=[];for(let t=Math.floor(this.size/2)-1;t>=0;t--)e.push(this._sinkDown(t,this.elements.length>>1));return e}sort(){let e=[],t=this._createInstance();for(let n of this.elements)t.add(n);for(;!t.isEmpty();){let n=t.poll();n!==void 0&&e.push(n)}return e}clone(){let e=this._createInstance();for(let t of this.elements)e.add(t);return e}filter(e,t){let n=this._createInstance(),r=0;for(let s of this)(t===void 0?e(s,r++,this):e.call(t,s,r++,this))?n.add(s):r++;return n}map(e,t,n){let{comparator:r,toElementFn:s,...o}=t!=null?t:{};if(!r)throw new TypeError("Heap.map requires options.comparator for EM");let d=this._createLike([],{...o,comparator:r,toElementFn:s}),a=0;for(let l of this){let f=n===void 0?e(l,a++,this):e.call(n,l,a++,this);d.add(f)}return d}mapSame(e,t){let n=this._createInstance(),r=0;for(let s of this){let o=t===void 0?e(s,r++,this):e.call(t,s,r++,this);n.add(o)}return n}get comparator(){return this._comparator}*_getIterator(){for(let e of this.elements)yield e}_bubbleUp(e){let t=this.elements[e];for(;e>0;){let n=e-1>>1,r=this.elements[n];if(this.comparator(r,t)<=0)break;this.elements[e]=r,e=n}return this.elements[e]=t,!0}_sinkDown(e,t){let n=this.elements[e];for(;e<t;){let r=e<<1|1,s=r+1,o=this.elements[r];if(s<this.elements.length&&this.comparator(o,this.elements[s])>0&&(r=s,o=this.elements[s]),this.comparator(o,n)>=0)break;this.elements[e]=o,e=r}return this.elements[e]=n,!0}_createInstance(e){let t=this.constructor;return new t([],{comparator:this.comparator,toElementFn:this.toElementFn,...e!=null?e:{}})}_createLike(e=[],t){let n=this.constructor;return new n(e,t)}_spawnLike(e){return this._createLike([],e)}},Le=class{constructor(i,e=0){u(this,"element");u(this,"degree");u(this,"left");u(this,"right");u(this,"child");u(this,"parent");u(this,"marked");this.element=i,this.degree=e,this.marked=!1}},We=class{constructor(i){u(this,"_root");u(this,"_size",0);u(this,"_min");u(this,"_comparator");if(this.clear(),this._comparator=i||this._defaultComparator,typeof this.comparator!="function")throw new Error("FibonacciHeap: comparator must be a function.")}get root(){return this._root}get size(){return this._size}get min(){return this._min}get comparator(){return this._comparator}clear(){this._root=void 0,this._min=void 0,this._size=0}add(i){return this.push(i),!0}push(i){let e=this.createNode(i);return e.left=e,e.right=e,this.mergeWithRoot(e),(!this.min||this.comparator(e.element,this.min.element)<=0)&&(this._min=e),this._size++,this}peek(){return this.min?this.min.element:void 0}consumeLinkedList(i){let e=[];if(!i)return e;let t=i,n=!1;for(;!(t===i&&n);)t===i&&(n=!0),e.push(t),t=t.right;return e}mergeWithChild(i,e){i.child?(e.right=i.child.right,e.left=i.child,i.child.right.left=e,i.child.right=e):i.child=e}poll(){return this.pop()}pop(){if(this._size===0)return;let i=this.min;if(i.child){let e=this.consumeLinkedList(i.child);for(let t of e)this.mergeWithRoot(t),t.parent=void 0}return this.removeFromRoot(i),i===i.right?(this._min=void 0,this._root=void 0):(this._min=i.right,this._consolidate()),this._size--,i.element}merge(i){if(i.size!==0){if(this.root&&i.root){let e=this.root,t=i.root,n=e.right,r=t.left;e.right=t,t.left=e,n.left=r,r.right=n}else!this.root&&i.root&&(this._root=i.root);(!this.min||i.min&&this.comparator(i.min.element,this.min.element)<0)&&(this._min=i.min),this._size+=i.size,i.clear()}}createNode(i){return new Le(i)}isEmpty(){return this._size===0}_defaultComparator(i,e){return i<e?-1:i>e?1:0}mergeWithRoot(i){this.root?(i.right=this.root.right,i.left=this.root,this.root.right.left=i,this.root.right=i):this._root=i}removeFromRoot(i){this.root===i&&(this._root=i.right),i.left&&(i.left.right=i.right),i.right&&(i.right.left=i.left)}_link(i,e){this.removeFromRoot(i),i.left=i,i.right=i,this.mergeWithChild(e,i),e.degree++,i.parent=e}_consolidate(){let i=new Array(this._size),e=this.consumeLinkedList(this.root),t,n,r,s;for(let o of e){for(t=o,r=t.degree;i[r];)n=i[r],this.comparator(t.element,n.element)>0&&(s=t,t=n,n=s),this._link(n,t),i[r]=void 0,r++;i[r]=t}for(let o=0;o<i.length;o++)i[o]&&(!this.min||this.comparator(i[o].element,this.min.element)<=0)&&(this._min=i[o])}};var Qe=class extends D{constructor(i=[],e){super(i,{comparator:(t,n)=>{if(typeof t=="object"||typeof n=="object")throw TypeError("When comparing object types, a custom comparator must be defined in the constructor's options parameter.");return t<n?1:t>n?-1:0},...e})}};var Xe=class extends D{constructor(i=[],e){super(i,e)}};var w=class{constructor(i,e){u(this,"key");u(this,"value");this.key=i,this.value=e}},q=class{constructor(i,e){u(this,"value");u(this,"weight");u(this,"_hashCode");this.weight=i!==void 0?i:1,this.value=e,this._hashCode=Fe()}get hashCode(){return this._hashCode}},X=class extends z{constructor(e){super();u(this,"_options",{defaultEdgeWeight:1});u(this,"_vertexMap",new Map);let t=e==null?void 0:e.graph;this._options={defaultEdgeWeight:1,...t!=null?t:{}}}get options(){return this._options}get vertexMap(){return this._vertexMap}set vertexMap(e){this._vertexMap=e}get size(){return this._vertexMap.size}getVertex(e){return this._vertexMap.get(e)||void 0}hasVertex(e){return this._vertexMap.has(this._getVertexKey(e))}addVertex(e,t){if(e instanceof w)return this._addVertex(e);{let n=this.createVertex(e,t);return this._addVertex(n)}}isVertexKey(e){let t=typeof e;return t==="string"||t==="number"}removeManyVertices(e){let t=[];for(let n of e)t.push(this.deleteVertex(n));return t.length>0}hasEdge(e,t){return!!this.getEdge(e,t)}addEdge(e,t,n,r){if(e instanceof q)return this._addEdge(e);if(t instanceof w||typeof t=="string"||typeof t=="number"){if(!(this.hasVertex(e)&&this.hasVertex(t)))return!1;e instanceof w&&(e=e.key),t instanceof w&&(t=t.key);let s=this.createEdge(e,t,n,r);return this._addEdge(s)}else throw new Error("dest must be a Vertex or vertex key while srcOrEdge is an Edge")}setEdgeWeight(e,t,n){let r=this.getEdge(e,t);return r?(r.weight=n,!0):!1}getAllPathsBetween(e,t,n=1e3){let r=[],s=this._getVertex(e),o=this._getVertex(t);if(!(s&&o))return[];let d=[];for(d.push({vertex:s,path:[s]});d.length>0;){let{vertex:a,path:l}=d.pop();if(a===o&&(r.push(l),r.length>=n))return r;let f=this.getNeighbors(a);for(let c of f)if(!l.includes(c)){let g=[...l,c];d.push({vertex:c,path:g})}}return r}getPathSumWeight(e){var n;let t=0;for(let r=0;r<e.length;r++)t+=((n=this.getEdge(e[r],e[r+1]))==null?void 0:n.weight)||0;return t}getMinCostBetween(e,t,n){if(n===void 0&&(n=!1),n){let r=this.getAllPathsBetween(e,t),s=Number.MAX_SAFE_INTEGER;for(let o of r)s=Math.min(this.getPathSumWeight(o),s);return s}else{let r=this._getVertex(t),s=this._getVertex(e);if(!(s&&r))return;let o=new Map,d=new O([s]);o.set(s,!0);let a=0;for(;d.length>0;){for(let l=0,f=d.length;l<f;l++){let c=d.shift();if(c===r)return a;if(c!==void 0){let g=this.getNeighbors(c);for(let p of g)o.has(p)||(o.set(p,!0),d.push(p))}}a++}return}}getMinPathBetween(e,t,n,r=!1){var s,o;if(n===void 0&&(n=!1),n)if(r){let d=this.getAllPathsBetween(e,t,1e4),a=Number.MAX_SAFE_INTEGER,l=-1,f=0;for(let c of d){let g=this.getPathSumWeight(c);g<a&&(a=g,l=f),f++}return d[l]||void 0}else return(o=(s=this.dijkstra(e,t,!0,!0))==null?void 0:s.minPath)!=null?o:[];else{let d=[],a=this._getVertex(e),l=this._getVertex(t);if(!(a&&l))return[];let f=(c,g,p,b)=>{if(p.add(c),c===g){d=[a,...b];return}let T=this.getNeighbors(c);for(let E of T)p.has(E)||(b.push(E),f(E,g,p,b),b.pop());p.delete(c)};return f(a,l,new Set,[]),d}}dijkstraWithoutHeap(e,t=void 0,n=!1,r=!1){let s=Number.MAX_SAFE_INTEGER,o,d=[],a=[],l=this._vertexMap,f=new Map,c=new Set,g=new Map,p=this._getVertex(e),b=t?this._getVertex(t):void 0;if(!p)return;for(let y of l){let m=y[1];m instanceof w&&f.set(m,Number.MAX_SAFE_INTEGER)}f.set(p,0),g.set(p,void 0);let T=()=>{let y=Number.MAX_SAFE_INTEGER,m;for(let[N,K]of f)c.has(N)||K<y&&(y=K,m=N);return m},E=y=>{for(let m of l){let N=m[1];if(N instanceof w){let K=[N],V=g.get(N);for(;V;)K.push(V),V=g.get(V);let R=K.reverse();m[1]===y&&(d=R),a.push(R)}}};for(let y=1;y<l.size;y++){let m=T();if(m){if(c.add(m),b&&b===m)return n&&(s=f.get(b)||Number.MAX_SAFE_INTEGER),r&&E(b),{distMap:f,preMap:g,seen:c,paths:a,minDist:s,minPath:d};let N=this.getNeighbors(m);for(let K of N)if(!c.has(K)){let V=this.getEdge(m,K);if(V){let R=f.get(m),k=f.get(K);R!==void 0&&k!==void 0&&V.weight+R<k&&(f.set(K,V.weight+R),g.set(K,m))}}}}return n&&f.forEach((y,m)=>{m!==p&&y<s&&(s=y,r&&(o=m))}),r&&E(o),{distMap:f,preMap:g,seen:c,paths:a,minDist:s,minPath:d}}dijkstra(e,t=void 0,n=!1,r=!1){var y;let s=Number.MAX_SAFE_INTEGER,o,d=[],a=[],l=this._vertexMap,f=new Map,c=new Set,g=new Map,p=this._getVertex(e),b=t?this._getVertex(t):void 0;if(!p)return;for(let m of l){let N=m[1];N instanceof w&&f.set(N,Number.MAX_SAFE_INTEGER)}let T=new D([],{comparator:(m,N)=>m.key-N.key});T.add({key:0,value:p}),f.set(p,0),g.set(p,void 0);let E=m=>{for(let N of l){let K=N[1];if(K instanceof w){let V=[K],R=g.get(K);for(;R;)V.push(R),R=g.get(R);let k=V.reverse();N[1]===m&&(d=k),a.push(k)}}};for(;T.size>0;){let m=T.poll(),N=m==null?void 0:m.key,K=m==null?void 0:m.value;if(N!==void 0&&K){if(c.add(K),b&&b===K)return n&&(s=f.get(b)||Number.MAX_SAFE_INTEGER),r&&E(b),{distMap:f,preMap:g,seen:c,paths:a,minDist:s,minPath:d};let V=this.getNeighbors(K);for(let R of V)if(!c.has(R)){let k=(y=this.getEdge(K,R))==null?void 0:y.weight;if(typeof k=="number"){let I=f.get(R);I!==void 0&&N+k<I&&(T.add({key:N+k,value:R}),g.set(R,K),f.set(R,N+k))}}}}return n&&f.forEach((m,N)=>{N!==p&&m<s&&(s=m,r&&(o=N))}),r&&E(o),{distMap:f,preMap:g,seen:c,paths:a,minDist:s,minPath:d}}bellmanFord(e,t,n,r){n===void 0&&(n=!1),r===void 0&&(r=!1);let s=this._getVertex(e),o=[],d=new Map,a=new Map,l=Number.MAX_SAFE_INTEGER,f=[],c;if(t&&(c=!1),!s)return{hasNegativeCycle:c,distMap:d,preMap:a,paths:o,min:l,minPath:f};let g=this._vertexMap,p=g.size,b=this.edgeSet(),T=b.length;this._vertexMap.forEach(y=>{d.set(y,Number.MAX_SAFE_INTEGER)}),d.set(s,0);for(let y=1;y<p;++y)for(let m=0;m<T;++m){let N=this.getEndsOfEdge(b[m]);if(N){let[K,V]=N,R=b[m].weight,k=d.get(K),I=d.get(V);k!==void 0&&I!==void 0&&d.get(K)!==Number.MAX_SAFE_INTEGER&&k+R<I&&(d.set(V,k+R),r&&a.set(V,K))}}let E;if(n&&d.forEach((y,m)=>{m!==s&&y<l&&(l=y,r&&(E=m))}),r)for(let y of g){let m=y[1];if(m instanceof w){let N=[m],K=a.get(m);for(;K!==void 0;)N.push(K),K=a.get(K);let V=N.reverse();y[1]===E&&(f=V),o.push(V)}}for(let y=0;y<T;++y){let m=this.getEndsOfEdge(b[y]);if(m){let[N]=m,K=b[y].weight,V=d.get(N);V&&V!==Number.MAX_SAFE_INTEGER&&V+K<V&&(c=!0)}}return{hasNegativeCycle:c,distMap:d,preMap:a,paths:o,min:l,minPath:f}}floydWarshall(){var s;let e=[...this._vertexMap],t=e.length,n=[],r=[];for(let o=0;o<t;o++){n[o]=[],r[o]=[];for(let d=0;d<t;d++)r[o][d]=void 0}for(let o=0;o<t;o++)for(let d=0;d<t;d++)n[o][d]=((s=this.getEdge(e[o][1],e[d][1]))==null?void 0:s.weight)||Number.MAX_SAFE_INTEGER;for(let o=0;o<t;o++)for(let d=0;d<t;d++)for(let a=0;a<t;a++)n[d][a]>n[d][o]+n[o][a]&&(n[d][a]=n[d][o]+n[o][a],r[d][a]=e[o][1]);return{costs:n,predecessor:r}}getCycles(e=!1){let t=[],n=new Set,r=(o,d,a)=>{if(a.has(o)){(!e&&d.length>2||e&&d.length>=2)&&d[0]===o.key&&t.push([...d]);return}a.add(o),d.push(o.key);for(let l of this.getNeighbors(o))l&&r(l,d,a);a.delete(o),d.pop()};for(let o of this.vertexMap.values())r(o,[],n);let s=new Map;for(let o of t){let d=[...o].sort().toString();s.has(d)||s.set(d,o)}return[...s].map(o=>o[1])}filter(e,t){let n=[],r=0;for(let[s,o]of this)e.call(t,o,s,r,this)&&n.push([s,o]),r++;return this._createLike(n,this._snapshotOptions())}filterEntries(e,t){let n=[],r=0;for(let[s,o]of this)e.call(t,o,s,r,this)&&n.push([s,o]),r++;return n}map(e,t){let n=[],r=0;for(let[s,o]of this)n.push(e.call(t,o,s,r,this)),r++;return n}clone(){return this._createLike(void 0,this._snapshotOptions())}*_getIterator(){for(let e of this._vertexMap.values())yield[e.key,e.value]}_snapshotOptions(){return{graph:{...this._options}}}_createInstance(e){let t=this.constructor,n=new t,r=e==null?void 0:e.graph;return r?n._options={...n._options,...r}:n._options={...n._options,...this._options},n}_createLike(e,t){let n=this._createInstance(t);if(e)for(let[s,o]of e)n.addVertex(s,o);else for(let[s,o]of this)n.addVertex(s,o);let r=this.edgeSet();for(let s of r){let o=this.getEndsOfEdge(s);if(!o)continue;let[d,a]=o,l=d.key,f=a.key,c=n.hasVertex?n.hasVertex(l):!1,g=n.hasVertex?n.hasVertex(f):!1;if(c&&g){let p=s.weight,b=s.value,T=n.createEdge(l,f,p,b);n._addEdge(T)}}return n}_addVertex(e){return this.hasVertex(e)?!1:(this._vertexMap.set(e.key,e),!0)}_getVertex(e){let t=this._getVertexKey(e);return this._vertexMap.get(t)||void 0}_getVertexKey(e){return e instanceof w?e.key:e}};var $=class extends w{constructor(i,e){super(i,e)}},se=class extends q{constructor(e,t,n,r){super(n,r);u(this,"src");u(this,"dest");this.src=e,this.dest=t}},me=class h extends X{constructor(e){super(e);u(this,"_outEdgeMap",new Map);u(this,"_inEdgeMap",new Map)}get outEdgeMap(){return this._outEdgeMap}set outEdgeMap(e){this._outEdgeMap=e}get inEdgeMap(){return this._inEdgeMap}set inEdgeMap(e){this._inEdgeMap=e}static fromKeys(e){let t=new h({vertexValueInitializer:n=>n});for(let n of e)t.addVertex(n);return t}static fromEntries(e){let t=new h;for(let[n,r]of e)t.addVertex(n,r);return t}createVertex(e,t){return new $(e,t)}createEdge(e,t,n,r){var s;return new se(e,t,(s=n!=null?n:this.options.defaultEdgeWeight)!=null?s:1,r)}getEdge(e,t){let n=[];if(e!==void 0&&t!==void 0){let r=this._getVertex(e),s=this._getVertex(t);if(r&&s){let o=this._outEdgeMap.get(r);o&&(n=o.filter(d=>d.dest===s.key))}}return n[0]||void 0}deleteEdgeSrcToDest(e,t){let n=this._getVertex(e),r=this._getVertex(t),s;if(!n||!r)return;let o=this._outEdgeMap.get(n);o&&P(o,a=>a.dest===r.key);let d=this._inEdgeMap.get(r);return d&&(s=P(d,a=>a.src===n.key)[0]||void 0),s}deleteEdge(e,t){let n,r,s;if(this.isVertexKey(e))if(this.isVertexKey(t))r=this._getVertex(e),s=this._getVertex(t);else return;else r=this._getVertex(e.src),s=this._getVertex(e.dest);if(r&&s){let o=this._outEdgeMap.get(r);o&&o.length>0&&P(o,a=>a.src===r.key&&a.dest===(s==null?void 0:s.key));let d=this._inEdgeMap.get(s);d&&d.length>0&&(n=P(d,a=>a.src===r.key&&a.dest===s.key)[0])}return n}deleteVertex(e){let t,n;if(this.isVertexKey(e)?(n=this.getVertex(e),t=e):(n=e,t=this._getVertexKey(e)),n){let r=this.getNeighbors(n);for(let s of r)this.deleteEdgeSrcToDest(n,s);this._outEdgeMap.delete(n),this._inEdgeMap.delete(n)}return this._vertexMap.delete(t)}deleteEdgesBetween(e,t){let n=[];if(e&&t){let r=this.deleteEdgeSrcToDest(e,t),s=this.deleteEdgeSrcToDest(t,e);r&&n.push(r),s&&n.push(s)}return n}incomingEdgesOf(e){let t=this._getVertex(e);return t?this.inEdgeMap.get(t)||[]:[]}outgoingEdgesOf(e){let t=this._getVertex(e);return t?this._outEdgeMap.get(t)||[]:[]}degreeOf(e){return this.outDegreeOf(e)+this.inDegreeOf(e)}inDegreeOf(e){return this.incomingEdgesOf(e).length}outDegreeOf(e){return this.outgoingEdgesOf(e).length}edgesOf(e){return[...this.outgoingEdgesOf(e),...this.incomingEdgesOf(e)]}getEdgeSrc(e){return this._getVertex(e.src)}getEdgeDest(e){return this._getVertex(e.dest)}getDestinations(e){if(e===void 0)return[];let t=[],n=this.outgoingEdgesOf(e);for(let r of n){let s=this.getEdgeDest(r);s&&t.push(s)}return t}topologicalSort(e){e=e!=null?e:"key";let t=new Map;for(let o of this.vertexMap)t.set(o[1],0);let n=[],r=!1,s=o=>{t.set(o,1);let d=this.getDestinations(o);for(let a of d){let l=t.get(a);l===0?s(a):l===1&&(r=!0)}t.set(o,2),n.push(o)};for(let o of this.vertexMap)t.get(o[1])===0&&s(o[1]);if(!r)return e==="key"&&(n=n.map(o=>o instanceof $?o.key:o)),n.reverse()}edgeSet(){let e=[];return this._outEdgeMap.forEach(t=>{e=[...e,...t]}),e}getNeighbors(e){let t=[],n=this._getVertex(e);if(n){let r=this.outgoingEdgesOf(n);for(let s of r){let o=this._getVertex(s.dest);o&&t.push(o)}}return t}getEndsOfEdge(e){if(!this.hasEdge(e.src,e.dest))return;let t=this._getVertex(e.src),n=this._getVertex(e.dest);if(t&&n)return[t,n]}isEmpty(){return this.vertexMap.size===0&&this.inEdgeMap.size===0&&this.outEdgeMap.size===0}clear(){this._vertexMap=new Map,this._inEdgeMap=new Map,this._outEdgeMap=new Map}clone(){return super.clone()}tarjan(){let e=new Map,t=new Map,n=new Map,r=0,s=[],o=new Set,d=a=>{e.set(a,r),t.set(a,r),r++,s.push(a),o.add(a);let l=this.getNeighbors(a);for(let f of l)e.has(f)?o.has(f)&&t.set(a,Math.min(t.get(a),e.get(f))):(d(f),t.set(a,Math.min(t.get(a),t.get(f))));if(e.get(a)===t.get(a)){let f=[],c;do c=s.pop(),o.delete(c),f.push(c);while(c!==a);n.set(n.size,f)}};for(let a of this.vertexMap.values())e.has(a)||d(a);return{dfnMap:e,lowMap:t,SCCs:n}}getDFNMap(){return this.tarjan().dfnMap}getLowMap(){return this.tarjan().lowMap}getSCCs(){return this.tarjan().SCCs}_addEdge(e){if(!(this.hasVertex(e.src)&&this.hasVertex(e.dest)))return!1;let t=this._getVertex(e.src),n=this._getVertex(e.dest);if(t&&n){let r=this._outEdgeMap.get(t);r?r.push(e):this._outEdgeMap.set(t,[e]);let s=this._inEdgeMap.get(n);return s?s.push(e):this._inEdgeMap.set(n,[e]),!0}else return!1}};var Be=class extends w{constructor(i,e){super(i,e)}},Ie=class extends q{constructor(e,t,n,r){super(n,r);u(this,"endpoints");this.endpoints=[e,t]}},$e=class h extends X{constructor(e){super(e);u(this,"_edgeMap");this._edgeMap=new Map}get edgeMap(){return this._edgeMap}set edgeMap(e){this._edgeMap=e}static fromKeys(e){let t=new h({vertexValueInitializer:n=>n});for(let n of e)t.addVertex(n);return t}static fromEntries(e){let t=new h;for(let[n,r]of e)t.addVertex(n,r);return t}createVertex(e,t){return new Be(e,t)}createEdge(e,t,n,r){var s;return new Ie(e,t,(s=n!=null?n:this.options.defaultEdgeWeight)!=null?s:1,r)}getEdge(e,t){var r;let n=[];if(e!==void 0&&t!==void 0){let s=this._getVertex(e),o=this._getVertex(t);s&&o&&(n=(r=this._edgeMap.get(s))==null?void 0:r.filter(d=>d.endpoints.includes(o.key)))}return n&&n[0]||void 0}deleteEdgeBetween(e,t){let n=this._getVertex(e),r=this._getVertex(t);if(!n||!r)return;let s=this._edgeMap.get(n),o;s&&(o=P(s,a=>a.endpoints.includes(r.key))[0]||void 0);let d=this._edgeMap.get(r);return d&&P(d,a=>a.endpoints.includes(n.key)),o}deleteEdge(e,t){let n,r;if(this.isVertexKey(e))if(this.isVertexKey(t))n=this._getVertex(e),r=this._getVertex(t);else return;else n=this._getVertex(e.endpoints[0]),r=this._getVertex(e.endpoints[1]);if(n&&r)return this.deleteEdgeBetween(n,r)}deleteVertex(e){let t,n;this.isVertexKey(e)?(n=this.getVertex(e),t=e):(n=e,t=this._getVertexKey(e));let r=this.getNeighbors(e);return n&&(r.forEach(s=>{let o=this._edgeMap.get(s);if(o){let d=o.filter(a=>!a.endpoints.includes(t));this._edgeMap.set(s,d)}}),this._edgeMap.delete(n)),this._vertexMap.delete(t)}degreeOf(e){var n;let t=this._getVertex(e);return t&&((n=this._edgeMap.get(t))==null?void 0:n.length)||0}edgesOf(e){let t=this._getVertex(e);return t?this._edgeMap.get(t)||[]:[]}edgeSet(){let e=new Set;return this._edgeMap.forEach(t=>{t.forEach(n=>{e.add(n)})}),[...e]}getNeighbors(e){let t=[],n=this._getVertex(e);if(n){let r=this.edgesOf(n);for(let s of r){let o=this._getVertex(s.endpoints.filter(d=>d!==n.key)[0]);o&&t.push(o)}}return t}getEndsOfEdge(e){if(!this.hasEdge(e.endpoints[0],e.endpoints[1]))return;let t=this._getVertex(e.endpoints[0]),n=this._getVertex(e.endpoints[1]);if(t&&n)return[t,n]}isEmpty(){return this.vertexMap.size===0&&this.edgeMap.size===0}clear(){this._vertexMap=new Map,this._edgeMap=new Map}clone(){return super.clone()}tarjan(){let e=new Map,t=new Map,n=[],r=[],s=0,o=(d,a)=>{e.set(d,s),t.set(d,s),s++;let l=this.getNeighbors(d),f=0;for(let c of l)if(e.has(c))c!==a&&t.set(d,Math.min(t.get(d),e.get(c)));else{if(f++,o(c,d),t.set(d,Math.min(t.get(d),t.get(c))),t.get(c)>e.get(d)){let g=this.getEdge(d,c);g&&n.push(g)}a!==void 0&&t.get(c)>=e.get(d)&&r.push(d)}a===void 0&&f>1&&r.push(d)};for(let d of this.vertexMap.values())e.has(d)||o(d,void 0);return{dfnMap:e,lowMap:t,bridges:n,cutVertices:r}}getBridges(){return this.tarjan().bridges}getCutVertices(){return this.tarjan().cutVertices}getDFNMap(){return this.tarjan().dfnMap}getLowMap(){return this.tarjan().lowMap}_addEdge(e){for(let t of e.endpoints){let n=this._getVertex(t);if(n===void 0)return!1;if(n){let r=this._edgeMap.get(n);r?r.push(e):this._edgeMap.set(n,[e])}}return!0}};var we=class extends ${constructor(e,t,n,r){super(e,t);u(this,"lat");u(this,"long");this.lat=n,this.long=r}},ve=class extends se{constructor(i,e,t,n){super(i,e,t,n)}},Je=class h extends me{constructor(e,t){super();u(this,"_originCoord",[0,0]);u(this,"_bottomRight");this._originCoord=e,this._bottomRight=t}get originCoord(){return this._originCoord}get bottomRight(){return this._bottomRight}createVertex(e,t,n=this.originCoord[0],r=this.originCoord[1]){return new we(e,t,n,r)}createEdge(e,t,n,r){return new ve(e,t,n,r)}clone(){return super.clone()}_snapshotOptions(){return{...super._snapshotOptions(),originCoord:this.originCoord,bottomRight:this.bottomRight}}_createInstance(e){let{originCoord:t,bottomRight:n}=e||{},r=t!=null?t:this.originCoord,s=n!=null?n:this.bottomRight;return new h(r,s)}};var Ye=(e=>(e[e.VISIT=0]="VISIT",e[e.PROCESS=1]="PROCESS",e))(Ye||{}),H=class{constructor(i,e,t=!0,n=!0){this.low=i;this.high=e;this.includeLow=t;this.includeHigh=n}isInRange(i,e){let t=this.includeLow?e(i,this.low)>=0:e(i,this.low)>0,n=this.includeHigh?e(i,this.high)<=0:e(i,this.high)<0;return t&&n}};var oe=class{constructor(i,e){u(this,"key");u(this,"value");u(this,"parent");u(this,"_left");u(this,"_right");u(this,"_height",0);u(this,"_color","BLACK");u(this,"_count",1);this.key=i,this.value=e}get left(){return this._left}set left(i){i&&(i.parent=this),this._left=i}get right(){return this._right}set right(i){i&&(i.parent=this),this._right=i}get height(){return this._height}set height(i){this._height=i}get color(){return this._color}set color(i){this._color=i}get count(){return this._count}set count(i){this._count=i}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"}},Ke=class extends z{constructor(e=[],t){super();u(this,"iterationType","ITERATIVE");u(this,"_isMapMode",!0);u(this,"_isDuplicate",!1);u(this,"_store",new Map);u(this,"_root");u(this,"_size",0);u(this,"_NIL",new oe(NaN));u(this,"_toEntryFn");u(this,"_DEFAULT_NODE_CALLBACK",e=>e?e.key:void 0);if(t){let{iterationType:n,toEntryFn:r,isMapMode:s,isDuplicate:o}=t;if(n&&(this.iterationType=n),s!==void 0&&(this._isMapMode=s),o!==void 0&&(this._isDuplicate=o),typeof r=="function")this._toEntryFn=r;else if(r)throw TypeError("toEntryFn must be a function type")}e&&this.setMany(e)}get isMapMode(){return this._isMapMode}get isDuplicate(){return this._isDuplicate}get store(){return this._store}get root(){return this._root}get size(){return this._size}get NIL(){return this._NIL}get toEntryFn(){return this._toEntryFn}createNode(e,t){return new oe(e,t)}createTree(e){return this._createInstance(e)}ensureNode(e,t=this.iterationType){if(e===null)return null;if(e!==void 0&&e!==this._NIL){if(this.isNode(e))return e;if(this.isEntry(e)){let n=e[0];return n===null?null:n===void 0?void 0:this.getNode(n,this._root,t)}return this.getNode(e,this._root,t)}}isNode(e){return e instanceof oe}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 H}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:Q(e)}add(e){return this.set(e)}set(e,t){let[n]=this._keyValueNodeOrEntryToNodeAndValue(e,t);if(n===void 0)return!1;if(!this._root)return this._setRoot(n),this._isMapMode&&n!==null&&n!==void 0&&this._store.set(n.key,n),this._size=1,!0;let r=new O([this._root]),s;for(;r.length>0;){let o=r.shift();if(o){if(!this._isDuplicate&&n!==null&&o.key===n.key)return this._replaceNode(o,n),this._isMapMode&&n!==null&&this._store.set(o.key,n),!0;s===void 0&&(o.left===void 0||o.right===void 0)&&(s=o),o.left!==null&&o.left&&r.push(o.left),o.right!==null&&o.right&&r.push(o.right)}}return s?(s.left===void 0?s.left=n:s.right===void 0&&(s.right=n),this._isMapMode&&n!==null&&n!==void 0&&this._store.set(n.key,n),this._size++,!0):!1}addMany(e){return this.setMany(e)}setMany(e,t){let n=[],r;t&&(r=t[Symbol.iterator]());for(let s of e){let o;if(r){let d=r.next();d.done||(o=d.value)}this.isRaw(s)&&(s=this._toEntryFn(s)),n.push(this.set(s,o))}return n}merge(e){this.setMany(e,[])}refill(e,t){this.clear(),this.setMany(e,t)}delete(e){let t=[];if(!this._root)return t;let n=this.getNode(e);if(!n)return t;let r=n==null?void 0:n.parent,s,o=n;if(!n.left&&!n.right&&!r)this._setRoot(void 0);else if(n.left){let d=this.getRightMost(a=>a,n.left);if(d){let a=d.parent;o=this._swapProperties(n,d),this._isMapMode&&(this._store.set(n.key,n),this._store.set(d.key,d)),a&&(a.right===d?a.right=d.left:a.left=d.left,s=a)}}else if(r){let{familyPosition:d}=n;d==="LEFT"||d==="ROOT_LEFT"?r.left=n.right:(d==="RIGHT"||d==="ROOT_RIGHT")&&(r.right=n.right),s=r}else this._setRoot(n.right),n.right=void 0;return this._size=this._size-1,t.push({deleted:o,needBalanced:s}),this._isMapMode&&o&&this._store.delete(o.key),t}search(e,t=!1,n=this._DEFAULT_NODE_CALLBACK,r=this._root,s=this.iterationType){if(e===void 0)return[];if(e===null)return[];if(r=this.ensureNode(r),!r)return[];let o=this._ensurePredicate(e),d=[];if(s==="RECURSIVE"){let a=l=>{o(l)&&(d.push(n(l)),t)||!this.isRealNode(l.left)&&!this.isRealNode(l.right)||(this.isRealNode(l.left)&&a(l.left),this.isRealNode(l.right)&&a(l.right))};a(r)}else{let a=[r];for(;a.length>0;){let l=a.pop();if(this.isRealNode(l)){if(o(l)&&(d.push(n(l)),t))return d;this.isRealNode(l.left)&&a.push(l.left),this.isRealNode(l.right)&&a.push(l.right)}}}return d}getNodes(e,t=!1,n=this._root,r=this.iterationType){return this.search(e,t,s=>s,n,r)}getNode(e,t=this._root,n=this.iterationType){if(this._isMapMode&&e!==null&&e!==void 0&&!this._isPredicate(e)){let r=this._extractKey(e);return r==null?void 0:this._store.get(r)}return this.search(e,!0,r=>r,t,n)[0]}get(e,t=this._root,n=this.iterationType){var r,s;if(this._isMapMode){let o=this._extractKey(e);return o==null||(r=this._store.get(o))==null?void 0:r.value}return(s=this.getNode(e,t,n))==null?void 0:s.value}has(e,t=this._root,n=this.iterationType){if(this._isMapMode&&e!==void 0&&e!==null&&!this._isPredicate(e)){let r=this._extractKey(e);return r==null?!1:this._store.has(r)}return this.search(e,!0,r=>r,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 r=(d,a,l)=>{if(!this.isRealNode(d))return!0;let f=Number(d.key);return f<=a||f>=l?!1:r(d.left,a,f)&&r(d.right,f,l)},s=r(n,Number.MIN_SAFE_INTEGER,Number.MAX_SAFE_INTEGER),o=r(n,Number.MAX_SAFE_INTEGER,Number.MIN_SAFE_INTEGER);return s||o}else{let r=(d=!1)=>{let a=[],l=d?Number.MAX_SAFE_INTEGER:Number.MIN_SAFE_INTEGER,f=n;for(;this.isRealNode(f)||a.length>0;){for(;this.isRealNode(f);)a.push(f),f=f.left;f=a.pop();let c=Number(f.key);if(!this.isRealNode(f)||!d&&l>=c||d&&l<=c)return!1;l=c,f=f.right}return!0},s=r(),o=r(!0);return s||o}}getDepth(e,t=this._root){let n=this.ensureNode(e),r=this.ensureNode(t),s=0;for(;n!=null&&n.parent;){if(n===r)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=r=>{if(!this.isRealNode(r))return-1;let s=n(r.left),o=n(r.right);return Math.max(s,o)+1};return n(e)}else{let n=[{node:e,depth:0}],r=0;for(;n.length>0;){let{node:s,depth:o}=n.pop();this.isRealNode(s.left)&&n.push({node:s.left,depth:o+1}),this.isRealNode(s.right)&&n.push({node:s.right,depth:o+1}),r=Math.max(r,o)}return r}}getMinHeight(e=this._root,t=this.iterationType){if(e=this.ensureNode(e),!e)return-1;if(t==="RECURSIVE"){let n=r=>{if(!this.isRealNode(r)||!this.isRealNode(r.left)&&!this.isRealNode(r.right))return 0;let s=n(r.left),o=n(r.right);return Math.min(s,o)+1};return n(e)}else{let n=[],r=e,s=null,o=new Map;for(;n.length>0||r;)if(this.isRealNode(r))n.push(r),r=r.left;else if(r=n[n.length-1],!this.isRealNode(r.right)||s===r.right){if(r=n.pop(),this.isRealNode(r)){let d=this.isRealNode(r.left)?o.get(r.left):-1,a=this.isRealNode(r.right)?o.get(r.right):-1;o.set(r,1+Math.min(d,a)),s=r,r=null}}else r=r.right;return o.get(e)}}getPathToRoot(e,t=this._DEFAULT_NODE_CALLBACK,n=!1){let r=[],s=this.ensureNode(e);if(!s)return r;for(;s.parent;)r.push(t(s)),s=s.parent;return r.push(t(s)),n?r.reverse():r}getLeftMost(e=this._DEFAULT_NODE_CALLBACK,t=this._root,n=this.iterationType){if(this.isNIL(t))return e(void 0);let r=this.ensureNode(t);if(!this.isRealNode(r))return e(void 0);if(n==="RECURSIVE"){let s=o=>{let{left:d}=o;return this.isRealNode(d)?s(d):o};return e(s(r))}else{let s=xe(o=>{let{left:d}=o;return this.isRealNode(d)?Me(()=>s(d)):o});return e(s(r))}}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 r=s=>{let{right:o}=s;return this.isRealNode(o)?r(o):s};return e(r(t))}else{let r=xe(s=>{let{right:o}=s;return this.isRealNode(o)?Me(()=>r(o)):s});return e(r(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,r=this._root,s=this.iterationType,o=!1){return r=this.ensureNode(r),r?this._dfs(e,t,n,r,s,o):[]}bfs(e=this._DEFAULT_NODE_CALLBACK,t=this._root,n=this.iterationType,r=!1){if(t=this.ensureNode(t),!t)return[];let s=[];if(n==="RECURSIVE"){let o=new O([t]),d=a=>{if(o.length===0)return;let l=o.shift();s.push(e(l)),r?(l&&this.isRealNodeOrNull(l.left)&&o.push(l.left),l&&this.isRealNodeOrNull(l.right)&&o.push(l.right)):(this.isRealNode(l.left)&&o.push(l.left),this.isRealNode(l.right)&&o.push(l.right)),d(a+1)};d(0)}else{let o=new O([t]);for(;o.length>0;){let d=o.length;for(let a=0;a<d;a++){let l=o.shift();s.push(e(l)),r?(l&&this.isRealNodeOrNull(l.left)&&o.push(l.left),l&&this.isRealNodeOrNull(l.right)&&o.push(l.right)):(this.isRealNode(l.left)&&o.push(l.left),this.isRealNode(l.right)&&o.push(l.right))}}}return s}leaves(e=this._DEFAULT_NODE_CALLBACK,t=this._root,n=this.iterationType){t=this.ensureNode(t);let r=[];if(!this.isRealNode(t))return[];if(n==="RECURSIVE"){let s=o=>{this.isLeaf(o)&&r.push(e(o)),!(!this.isRealNode(o.left)&&!this.isRealNode(o.right))&&(this.isRealNode(o.left)&&s(o.left),this.isRealNode(o.right)&&s(o.right))};s(t)}else{let s=new O([t]);for(;s.length>0;){let o=s.shift();this.isRealNode(o)&&(this.isLeaf(o)&&r.push(e(o)),this.isRealNode(o.left)&&s.push(o.left),this.isRealNode(o.right)&&s.push(o.right))}}return r}listLevels(e=this._DEFAULT_NODE_CALLBACK,t=this._root,n=this.iterationType,r=!1){t=this.ensureNode(t);let s=[];if(!t)return s;if(n==="RECURSIVE"){let o=(d,a)=>{s[a]||(s[a]=[]),s[a].push(e(d)),r?(d&&this.isRealNodeOrNull(d.left)&&o(d.left,a+1),d&&this.isRealNodeOrNull(d.right)&&o(d.right,a+1)):(d&&d.left&&o(d.left,a+1),d&&d.right&&o(d.right,a+1))};o(t,0)}else{let o=[[t,0]];for(;o.length>0;){let d=o.pop(),[a,l]=d;s[l]||(s[l]=[]),s[l].push(e(a)),r?(a&&this.isRealNodeOrNull(a.right)&&o.push([a.right,l+1]),a&&this.isRealNodeOrNull(a.left)&&o.push([a.left,l+1])):(a&&a.right&&o.push([a.right,l+1]),a&&a.left&&o.push([a.left,l+1]))}}return s}morris(e=this._DEFAULT_NODE_CALLBACK,t="IN",n=this._root){if(n=this.ensureNode(n),!n)return[];let r=[],s=n,o=a=>{let l=null,f=null;for(;a;)f=a.right,a.right=l,l=a,a=f;return l},d=a=>{let l=o(a),f=l;for(;f;)r.push(e(f)),f=f.right;o(l)};switch(t){case"IN":for(;s;){if(s.left){let a=this.getPredecessor(s);if(a.right)a.right=null;else{a.right=s,s=s.left;continue}}r.push(e(s)),s=s.right}break;case"PRE":for(;s;){if(s.left){let a=this.getPredecessor(s);if(a.right)a.right=null;else{a.right=s,r.push(e(s)),s=s.left;continue}}else r.push(e(s));s=s.right}break;case"POST":for(;s;){if(s.left){let a=this.getPredecessor(s);if(a.right===null){a.right=s,s=s.left;continue}else a.right=null,d(s.left)}s=s.right}d(n);break}return r}clone(){let e=this._createInstance();return this._clone(e),e}filter(e,t){let n=this._createInstance(),r=0;for(let[s,o]of this)e.call(t,o,s,r++,this)&&n.set([s,o]);return n}map(e,t,n){let r=this._createLike([],t),s=0;for(let[o,d]of this)r.set(e.call(n,d,o,s++,this));return r}toVisual(e=this._root,t){let n={isShowUndefined:!1,isShowNull:!0,isShowRedBlackNIL:!1,...t};e=this.ensureNode(e);let r="";return e&&(n.isShowUndefined&&(r+=`U for undefined
|
|
2
2
|
`),n.isShowNull&&(r+=`N for null
|
|
3
3
|
`),n.isShowRedBlackNIL&&(r+=`S for Sentinel Node(NIL)
|
|
4
4
|
`),(o=>{let[d]=this._displayAux(o,n),a="";for(let l of d)a+=l+`
|
|
5
|
-
`;r+=a})(e)),r}print(e,t=this._root){console.log(this.toVisual(t,e))}_dfs(e=this._DEFAULT_NODE_CALLBACK,t="IN",n=!1,r=this._root,s=this.iterationType,o=!1,d=c=>!!c,a=c=>!!c,l=c=>o?this.isRealNodeOrNull(c):this.isRealNode(c),f=c=>this.isRealNodeOrNull(c)){if(r=this.ensureNode(r),!r)return[];let c=[];if(s==="RECURSIVE"){let g=p=>{if(!l(p))return;let b=()=>{d(p)&&(p==null?void 0:p.left)!==void 0&&g(p==null?void 0:p.left)},T=()=>{a(p)&&(p==null?void 0:p.right)!==void 0&&g(p==null?void 0:p.right)};switch(t){case"IN":if(b(),f(p)&&(c.push(e(p)),n))return;T();break;case"PRE":if(f(p)&&(c.push(e(p)),n))return;b(),T();break;case"POST":if(b(),T(),f(p)&&(c.push(e(p)),n))return;break}};g(r)}else{let g=[{opt:0,node:r}],p=E=>{var y;d(E.node)&&g.push({opt:0,node:(y=E.node)==null?void 0:y.left})},b=E=>{var y;a(E.node)&&g.push({opt:0,node:(y=E.node)==null?void 0:y.right})},T=E=>{l(E.node)&&g.push({opt:1,node:E.node})};for(;g.length>0;){let E=g.pop();if(E!==void 0&&l(E.node))if(E.opt===1){if(f(E.node)&&E.node!==void 0&&(c.push(e(E.node)),n))return c}else switch(t){case"IN":b(E),T(E),p(E);break;case"PRE":b(E),p(E),T(E);break;case"POST":T(E),b(E),p(E);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)&&(yield[n.key,n.value],n=n.right)}}else e.left&&this.isRealNode(e)&&(yield*this[Symbol.iterator](e.left)),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,r]=e;if(n===void 0)return[void 0,void 0];if(n===null)return[null,void 0];let s=t!=null?t:r;return[this.createNode(n,s),s]}return[this.createNode(e,t),t]}_clone(e){this.bfs(t=>{t===null?e.set(null):e.set([t.key,t.value])},this._root,this.iterationType,!0)}_displayAux(e,t){let{isShowNull:n,isShowUndefined:r,isShowRedBlackNIL:s}=t,o=[["\u2500"],1,0,0];if(e===null&&!n)return o;if(e===void 0&&!r)return o;if(this.isNIL(e)&&!s)return o;if(e!=null){let a=e.key,l=this.isNIL(e)?"S":String(a),f=l.length;return d(l,f,this._displayAux(e.left,t),this._displayAux(e.right,t))}else{let a=e===void 0?"U":"N",l=a.length;return d(a,l,[[""],1,0,0],[[""],1,0,0])}function d(a,l,f,c){let[g,p,b,T]=f,[E,y,m,N]=c,K=" ".repeat(Math.max(0,T+1))+"_".repeat(Math.max(0,p-T-1))+a+"_".repeat(Math.max(0,N))+" ".repeat(Math.max(0,y-N)),V=(b>0?" ".repeat(T)+"/"+" ".repeat(p-T-1):" ".repeat(p))+" ".repeat(l)+(m>0?" ".repeat(N)+"\\"+" ".repeat(y-N-1):" ".repeat(y)),R=[K,V];for(let k=0;k<Math.max(b,m);k++){let I=k<b?g[k]:" ".repeat(p),w=k<m?E[k]:" ".repeat(y);R.push(I+" ".repeat(l)+w)}return[R,p+l+y,Math.max(b,m)+2,p+Math.floor(l/2)]}}_swapProperties(e,t){if(e=this.ensureNode(e),t=this.ensureNode(t),e&&t){let{key:n,value:r}=t,s=this.createNode(n,r);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){if(e==null)return!1;let n=this._store.get(e);return n?(n.value=t,!0):!1}_clearNodes(){this._setRoot(void 0),this._size=0}_clearValues(){this._store.clear()}};var pe=class{constructor(i,e){u(this,"key");u(this,"value");u(this,"parent");u(this,"_left");u(this,"_right");u(this,"_height",0);u(this,"_color","BLACK");u(this,"_count",1);this.key=i,this.value=e}get left(){return this._left}set left(i){i&&(i.parent=this),this._left=i}get right(){return this._right}set right(i){i&&(i.parent=this),this._right=i}get height(){return this._height}set height(i){this._height=i}get color(){return this._color}set color(i){this._color=i}get count(){return this._count}set count(i){this._count=i}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"}},J=class extends ce{constructor(e=[],t){super([],t);u(this,"_root");u(this,"_comparator");t?"comparator"in t&&t.comparator!==void 0?this._comparator=t.comparator:this._comparator=this._createDefaultComparator():this._comparator=this._createDefaultComparator(),e&&this.setMany(e)}get root(){return this._root}get comparator(){return this._comparator}createNode(e,t){return new pe(e,t)}ensureNode(e,t=this.iterationType){var n;return(n=super.ensureNode(e,t))!=null?n:void 0}isNode(e){return e instanceof pe}isValidKey(e){return Q(e)}dfs(e=this._DEFAULT_NODE_CALLBACK,t="IN",n=!1,r=this._root,s=this.iterationType){return super.dfs(e,t,n,r,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 l,f;if(e==null)return;if(this._isPredicate(e))return(l=this.getNodes(e,!0,t,n)[0])!=null?l:void 0;if(e instanceof H)return(f=this.getNodes(e,!0,t,n)[0])!=null?f:void 0;let r;if(this.isNode(e))r=e.key;else if(this.isEntry(e)){let c=e[0];if(c==null)return;r=c}else r=e;let s=this.ensureNode(t);if(!s)return;let o=this._NIL,d=s,a=this._comparator;for(;d&&d!==o;){let c=a(r,d.key);if(c===0)return d;d=c<0?d._left:d._right}}search(e,t=!1,n=this._DEFAULT_NODE_CALLBACK,r=this._root,s=this.iterationType){if(e===void 0)return[];if(e===null)return[];if(r=this.ensureNode(r),!r)return[];let o=this.isRange(e),d=!o&&this._isPredicate(e);if(!o&&!d){let c;if(this.isNode(e))c=e.key;else if(this.isEntry(e)){let T=e[0];T!=null&&(c=T)}else c=e;if(c===void 0)return[];let g=this._NIL,p=this._comparator,b=r;for(;b&&b!==g;){let T=p(c,b.key);if(T===0)return[n(b)];b=T<0?b._left:b._right}return[]}let a;o?a=c=>c?e.isInRange(c.key,this._comparator):!1:a=this._ensurePredicate(e);let l=c=>{if(!c||!this.isRealNode(c.left))return!1;if(o){let g=e,p=g.low,b=g.includeLow;return b&&this._compare(c.key,p)>=0||!b&&this._compare(c.key,p)>0}if(!o&&!this._isPredicate(e)){let g=this._extractKey(e);return g!=null&&this._compare(c.key,g)>0}return!0},f=c=>{if(!c||!this.isRealNode(c.right))return!1;if(o){let g=e,p=g.high,b=g.includeHigh;return b&&this._compare(c.key,p)<=0||!b&&this._compare(c.key,p)<0}if(!o&&!this._isPredicate(e)){let g=this._extractKey(e);return g!=null&&this._compare(c.key,g)<0}return!0};return super._dfs(n,"IN",t,r,s,!1,l,f,()=>!0,c=>!!c&&a(c))}rangeSearch(e,t=this._DEFAULT_NODE_CALLBACK,n=this._root,r=this.iterationType){let s=e instanceof H?e:new H(e[0],e[1]);return this.search(s,!1,t,n,r)}set(e,t){let[n]=this._keyValueNodeOrEntryToNodeAndValue(e,t);if(n===void 0)return!1;if(this._root===void 0)return this._setRoot(n),this._isMapMode&&this.isRealNode(n)&&this._store.set(n.key,n),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.isRealNode(n)&&this._store.set(r.key,n),!0;if(this._compare(r.key,n.key)>0){if(r.left===void 0)return r.left=n,this._isMapMode&&this.isRealNode(n)&&this._store.set(n.key,n),this._size++,!0;r.left!==null&&(r=r.left)}else{if(r.right===void 0)return r.right=n,this._isMapMode&&this.isRealNode(n)&&this._store.set(n.key,n),this._size++,!0;r.right!==null&&(r=r.right)}}return!1}setMany(e,t,n=!0,r=this.iterationType){let s=[],o=t==null?void 0:t[Symbol.iterator]();if(!n){for(let g of e){let p=o==null?void 0:o.next().value;this.isRaw(g)&&(g=this._toEntryFn(g)),s.push(this.set(g,p))}return s}let d=[],a=0;for(let g of e)d.push({key:g,value:o==null?void 0:o.next().value,orgIndex:a++});let l=d.sort(({key:g},{key:p})=>{let b,T;return this.isRaw(g)?b=this._toEntryFn(g)[0]:this.isEntry(g)?b=g[0]:this.isRealNode(g)?b=g.key:b=g,this.isRaw(p)?T=this._toEntryFn(p)[0]:this.isEntry(p)?T=p[0]:this.isRealNode(p)?T=p.key:T=p,b!=null&&T!=null?this._compare(b,T):0}),f=g=>{if(g.length===0)return;let p=Math.floor((g.length-1)/2),{key:b,value:T,orgIndex:E}=g[p];if(this.isRaw(b)){let y=this._toEntryFn(b);s[E]=this.set(y)}else s[E]=this.set(b,T);f(g.slice(0,p)),f(g.slice(p+1))};return r==="RECURSIVE"?f(l):(()=>{let p=[[0,l.length-1]];for(;p.length>0;){let b=p.pop();if(!b)continue;let[T,E]=b;if(T>E)continue;let y=T+Math.floor((E-T)/2),{key:m,value:N,orgIndex:K}=l[y];if(this.isRaw(m)){let V=this._toEntryFn(m);s[K]=this.set(V)}else s[K]=this.set(m,N);p.push([y+1,E]),p.push([T,y-1])}})(),s}ceiling(e,t=this._DEFAULT_NODE_CALLBACK,n){let r,s=this.iterationType;typeof t=="string"?s=t:t&&(r=t,n&&(s=n));let o=this._bound(e,!0,s);return r?o?r(o):void 0:o==null?void 0:o.key}higher(e,t=this._DEFAULT_NODE_CALLBACK,n){let r,s=this.iterationType;typeof t=="string"?s=t:t&&(r=t,n&&(s=n));let o=this._bound(e,!1,s);return r?o?r(o):void 0:o==null?void 0:o.key}floor(e,t=this._DEFAULT_NODE_CALLBACK,n){if(e==null)return void 0;let r,s=this.iterationType;if(typeof t=="string"?s=t:t&&(r=t,n&&(s=n)),this._isPredicate(e)){let d=this._floorByPredicate(e,s);return r?d?r(d):void 0:d==null?void 0:d.key}let o;if(this.isNode(e))o=e.key;else if(this.isEntry(e)){let d=e[0];if(d==null)return void 0;o=d}else o=e;if(o!==void 0){let d=this._floorByKey(o,s);return r?d?r(d):void 0:d==null?void 0:d.key}}lower(e,t,n){if(e==null)return void 0;let r,s=this.iterationType;if(typeof t=="string"?s=t:t&&(r=t,n&&(s=n)),this._isPredicate(e)){let d=this._lowerByPredicate(e,s);return r?d?r(d):void 0:d==null?void 0:d.key}let o;if(this.isNode(e))o=e.key;else if(this.isEntry(e)){let d=e[0];if(d==null)return void 0;o=d}else o=e;if(o!==void 0){let d=this._lowerByKey(o,s);return r?d?r(d):void 0:d==null?void 0:d.key}}lesserOrGreaterTraverse(e=this._DEFAULT_NODE_CALLBACK,t=-1,n=this._root,r=this.iterationType){let s=this.ensureNode(n),o=[];if(!this._root||!s)return o;let d=s.key;if(r==="RECURSIVE"){let a=l=>{let f=this._compare(l.key,d);Math.sign(f)==t&&o.push(e(l)),this.isRealNode(l.left)&&a(l.left),this.isRealNode(l.right)&&a(l.right)};return a(this._root),o}else{let a=new O([this._root]);for(;a.length>0;){let l=a.shift();if(this.isRealNode(l)){let f=this._compare(l.key,d);Math.sign(f)==t&&o.push(e(l)),this.isRealNode(l.left)&&a.push(l.left),this.isRealNode(l.right)&&a.push(l.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 r=(o,d,a)=>{if(o>d)return;let l=o+(d-o>>1),f=t[l],c=r(o,l-1,f),g=r(l+1,d,f);return f.left=c,f.right=g,f.parent=a,f},s=r(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=r=>{if(!r)return 0;let s=n(r.left),o=n(r.right);return Math.abs(s-o)>1&&(t=!1),Math.max(s,o)+1};n(this._root)}else{let n=[],r=this._root,s,o=new Map;for(;n.length>0||r;)if(r)n.push(r),r.left!==null&&(r=r.left);else if(r=n[n.length-1],!r.right||s===r.right){if(r=n.pop(),r){let d=r.left?o.get(r.left):-1,a=r.right?o.get(r.right):-1;if(Math.abs(d-a)>1)return!1;o.set(r,1+Math.max(d,a)),s=r,r=void 0}}else r=r.right}return t}map(e,t,n){let r=this._createLike([],t),s=0;for(let[o,d]of this)r.set(e.call(n,d,o,s++,this));return r}deleteWhere(e,t=!1,n=this._root,r=this.iterationType){let s=this.search(e,t,d=>d,n,r),o=[];for(let d of s){let a=this.delete(d);o=o.concat(a)}return o}_createDefaultComparator(){return(e,t)=>{if(Q(e)&&Q(t))return e>t?1:e<t?-1:0;if(typeof e=="object"||typeof t=="object")throw TypeError("When comparing object type keys, a custom comparator must be provided in the constructor's options!");return 0}}_floorByKey(e,t){var n,r;if(t==="RECURSIVE"){let s=o=>{if(!this.isRealNode(o))return;if(this.comparator(o.key,e)<=0){let a=s(o.right);return a!=null?a:o}else return s(o.left)};return s(this.root)}else{let s=this.root,o;for(;this.isRealNode(s);)this.comparator(s.key,e)<=0?(o=s,s=(n=s.right)!=null?n:void 0):s=(r=s.left)!=null?r:void 0;return o}}_floorByPredicate(e,t){if(t==="RECURSIVE"){let n,r=s=>{this.isRealNode(s)&&(this.isRealNode(s.left)&&r(s.left),e(s)&&(n=s),this.isRealNode(s.right)&&r(s.right))};return r(this.root),n}else{let n=[],r=this.root,s;for(;n.length>0||this.isRealNode(r);)if(this.isRealNode(r))n.push(r),r=r.left;else{let o=n.pop();if(!this.isRealNode(o))break;e(o)&&(s=o),r=o.right}return s}}_lowerByKey(e,t){var n,r;if(t==="RECURSIVE"){let s=o=>{if(!this.isRealNode(o))return;if(this.comparator(o.key,e)<0){let a=s(o.right);return a!=null?a:o}else return s(o.left)};return s(this.root)}else{let s=this.root,o;for(;this.isRealNode(s);)this.comparator(s.key,e)<0?(o=s,s=(n=s.right)!=null?n:void 0):s=(r=s.left)!=null?r:void 0;return o}}_lowerByPredicate(e,t){if(t==="RECURSIVE"){let n,r=s=>{this.isRealNode(s)&&(this.isRealNode(s.left)&&r(s.left),e(s)&&(n=s),this.isRealNode(s.right)&&r(s.right))};return r(this.root),n}else{let n=[],r=this.root,s;for(;n.length>0||this.isRealNode(r);)if(this.isRealNode(r))n.push(r),r=r.left;else{let o=n.pop();if(!this.isRealNode(o))break;e(o)&&(s=o),r=o.right}return s}}_bound(e,t,n){if(e==null)return;if(this._isPredicate(e))return this._boundByPredicate(e,n);let r;if(this.isNode(e))r=e.key;else if(this.isEntry(e)){let s=e[0];if(s==null)return;r=s}else r=e;if(r!==void 0)return this._boundByKey(r,t,n)}_boundByKey(e,t,n){var r,s;if(n==="RECURSIVE"){let o=d=>{if(!this.isRealNode(d))return;let a=this.comparator(d.key,e);if(t?a>=0:a>0){let f=o(d.left);return f!=null?f:d}else return o(d.right)};return o(this.root)}else{let o=this.root,d;for(;this.isRealNode(o);){let a=this.comparator(o.key,e);(t?a>=0:a>0)?(d=o,o=(r=o.left)!=null?r:void 0):o=(s=o.right)!=null?s:void 0}return d}}_boundByPredicate(e,t){if(t==="RECURSIVE"){let n,r=s=>{n||!this.isRealNode(s)||(this.isRealNode(s.left)&&r(s.left),!n&&e(s)&&(n=s),!n&&this.isRealNode(s.right)&&r(s.right))};return r(this.root),n}else{let n=[],r=this.root;for(;n.length>0||this.isRealNode(r);)if(this.isRealNode(r))n.push(r),r=r.left;else{let s=n.pop();if(!this.isRealNode(s))break;if(e(s))return s;r=s.right}return}}_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(),comparator:this._comparator}}_keyValueNodeOrEntryToNodeAndValue(e,t){let[n,r]=super._keyValueNodeOrEntryToNodeAndValue(e,t);return n===null?[void 0,void 0]:[n,t!=null?t:r]}_setRoot(e){e&&(e.parent=void 0),this._root=e}_compare(e,t){return this._comparator(e,t)}_deleteByKey(e){let t=this._root;for(;t;){let s=this._compare(t.key,e);if(s===0)break;t=s>0?t.left:t.right}if(!t)return!1;let n=(s,o)=>{let d=s==null?void 0:s.parent;d?d.left===s?d.left=o:d.right=o:this._setRoot(o),o&&(o.parent=d)},r=s=>{if(s){for(;s.left!==void 0&&s.left!==null;)s=s.left;return s}};if(t.left===void 0)n(t,t.right);else if(t.right===void 0)n(t,t.left);else{let s=r(t.right);s.parent!==t&&(n(s,s.right),s.right=t.right,s.right&&(s.right.parent=s)),n(t,s),s.left=t.left,s.left&&(s.left.parent=s)}return this._size=Math.max(0,this._size-1),!0}};var Ze=class{constructor({frequency:i=0,max:e}){u(this,"_freq");u(this,"_max");u(this,"_freqMap");u(this,"_msb");u(this,"_negativeCount");this._freq=i,this._max=e,this._freqMap={0:0},this._msb=De(e),this._negativeCount=i<0?e:0}get freqMap(){return this._freqMap}get msb(){return this._msb}get negativeCount(){return this._negativeCount}get freq(){return this._freq}get max(){return this._max}readSingle(i){return this._checkIndex(i),this._readSingle(i)}update(i,e){this._checkIndex(i);let t=this._readSingle(i);this._update(i,e),this._updateNegativeCount(t,t+e)}writeSingle(i,e){this._checkIndex(i),this._writeSingle(i,e)}read(i){if(!Number.isInteger(i))throw new Error("Invalid count");return this._read(Math.max(Math.min(i,this.max),0))}lowerBound(i){if(this.negativeCount>0)throw new Error("Sequence is not non-descending");return this._binarySearch(i,(e,t)=>e<t)}upperBound(i){if(this.negativeCount>0)throw new Error("Must not be descending");return this._binarySearch(i,(e,t)=>e<=t)}getPrefixSum(i){this._checkIndex(i),i++;let e=0;for(;i>0;)e+=this._getFrequency(i),i-=i&-i;return e}_getFrequency(i){return i in this.freqMap?this.freqMap[i]:this.freq*(i&-i)}_updateFrequency(i,e){this.freqMap[i]=this._getFrequency(i)+e}_checkIndex(i){if(!Number.isInteger(i))throw new Error("Invalid index: Index must be an integer.");if(i<0||i>=this.max)throw new Error("Index out of range: Index must be within the range [0, this.max).")}_readSingle(i){i=i+1;let e=this._getFrequency(i),t=i-(i&-i);for(i--;i!==t;)e-=this._getFrequency(i),i-=i&-i;return e}_updateNegativeCount(i,e){i<0&&e>=0?this._negativeCount--:i>=0&&e<0&&this._negativeCount++}_update(i,e){for(i=i+1;i<=this.max;)this._updateFrequency(i,e),i+=i&-i}_writeSingle(i,e){let t=this._readSingle(i);this._update(i,e-t),this._updateNegativeCount(t,e)}_read(i){let e=i,t=0;for(;e;)t+=this._getFrequency(e),e-=e&-e;return t}_binarySearch(i,e){let t=0,n=this.msb<<1,r=i;for(;n>t+1;){let s=t+n>>1,o=this._getFrequency(s);s<=this.max&&e(o,r)?(r-=o,t=s):n=s}return t}};var de=class{constructor(i,e,t,n){u(this,"_start",0);u(this,"_end",0);u(this,"_value");u(this,"_sum",0);u(this,"_left");u(this,"_right");this._start=i,this._end=e,this._sum=t,this._value=n||void 0}get start(){return this._start}set start(i){this._start=i}get end(){return this._end}set end(i){this._end=i}get value(){return this._value}set value(i){this._value=i}get sum(){return this._sum}set sum(i){this._sum=i}get left(){return this._left}set left(i){this._left=i}get right(){return this._right}set right(i){this._right=i}},et=class{constructor(i,e,t){u(this,"_values",[]);u(this,"_start",0);u(this,"_end");u(this,"_root");e=e||0,t=t||i.length-1,this._values=i,this._start=e,this._end=t,i.length>0?this._root=this.build(e,t):(this._root=void 0,this._values=[])}get values(){return this._values}get start(){return this._start}get end(){return this._end}get root(){return this._root}build(i,e){if(i>e)return new de(i,e,0);if(i===e)return new de(i,e,this._values[i]);let t=i+Math.floor((e-i)/2),n=this.build(i,t),r=this.build(t+1,e),s=new de(i,e,n.sum+r.sum);return s.left=n,s.right=r,s}updateNode(i,e,t){let n=this.root||void 0;if(!n)return;let r=(s,o,d,a)=>{if(s.start===s.end&&s.start===o){s.sum=d,a!==void 0&&(s.value=a);return}let l=s.start+Math.floor((s.end-s.start)/2);o<=l?s.left&&r(s.left,o,d,a):s.right&&r(s.right,o,d,a),s.left&&s.right&&(s.sum=s.left.sum+s.right.sum)};r(n,i,e,t)}querySumByRange(i,e){let t=this.root||void 0;if(!t)return 0;if(i<0||e>=this.values.length||i>e)return NaN;let n=(r,s,o)=>{if(s<=r.start&&o>=r.end)return r.sum;let d=r.start+Math.floor((r.end-r.start)/2);if(o<=d)return r.left?n(r.left,s,o):NaN;if(s>d)return r.right?n(r.right,s,o):NaN;{let a=0,l=0;return r.left&&(a=n(r.left,s,d)),r.right&&(l=n(r.right,d+1,o)),a+l}};return n(t,i,e)}};var _e=class{constructor(i,e){u(this,"key");u(this,"value");u(this,"parent");u(this,"_left");u(this,"_right");u(this,"_height",0);u(this,"_color","BLACK");u(this,"_count",1);this.key=i,this.value=e}get left(){return this._left}set left(i){i&&(i.parent=this),this._left=i}get right(){return this._right}set right(i){i&&(i.parent=this),this._right=i}get height(){return this._height}set height(i){this._height=i}get color(){return this._color}set color(i){this._color=i}get count(){return this._count}set count(i){this._count=i}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"}},tt=class extends J{constructor(i=[],e){super([],e),i&&super.setMany(i)}createNode(i,e){return new _e(i,e)}isNode(i){return i instanceof _e}set(i,e){if(i===null)return!1;let t=super.set(i,e);return t&&this._balancePath(i),t}delete(i){let e=super.delete(i);for(let{needBalanced:t}of e)t&&this._balancePath(t);return e}perfectlyBalance(i=this.iterationType){let e=this.dfs(s=>s,"IN",!1,this._root,i),t=e.length;if(t===0)return!1;this._clearNodes();let n=(s,o,d)=>{if(s>o)return;let a=s+(o-s>>1),l=e[a];l.left=n(s,a-1,l),l.right=n(a+1,o,l),l.parent=d;let f=l.left?l.left.height:-1,c=l.right?l.right.height:-1;return l.height=Math.max(f,c)+1,l},r=n(0,t-1,void 0);return this._setRoot(r),this._size=t,!0}map(i,e,t){let n=this._createLike([],e),r=0;for(let[s,o]of this)n.set(i.call(t,o,s,r++,this));return n}_createInstance(i){let e=this.constructor;return new e([],{...this._snapshotOptions(),...i!=null?i:{}})}_createLike(i=[],e){let t=this.constructor;return new t(i,{...this._snapshotOptions(),...e!=null?e:{}})}_swapProperties(i,e){let t=this.ensureNode(i),n=this.ensureNode(e);if(t&&n){let{key:r,value:s,height:o}=n,d=this.createNode(r,s);return d&&(d.height=o,n.key=t.key,this._isMapMode||(n.value=t.value),n.height=t.height,t.key=d.key,this._isMapMode||(t.value=d.value),t.height=d.height),n}}_balanceFactor(i){let e=i.left?i.left.height:-1;return(i.right?i.right.height:-1)-e}_updateHeight(i){let e=i.left?i.left.height:-1,t=i.right?i.right.height:-1;i.height=1+Math.max(e,t)}_balanceLL(i){let e=i.parent,t=i.left;t!==null&&(i.parent=t),t&&t.right&&(t.right.parent=i),t&&(t.parent=e),i===this.root?t&&this._setRoot(t):(e==null?void 0:e.left)===i?e.left=t:e&&(e.right=t),t&&(i.left=t.right,t.right=i),this._updateHeight(i),t&&this._updateHeight(t)}_balanceLR(i){let e=i.parent,t=i.left,n;t&&(n=t.right),i&&n!==null&&(i.parent=n),t&&n!==null&&(t.parent=n),n&&(n.left&&t!==null&&(n.left.parent=t),n.right&&(n.right.parent=i),n.parent=e),i===this.root?n&&this._setRoot(n):e&&(e.left===i?e.left=n:e.right=n),n&&(i.left=n.right,t&&(t.right=n.left),n.left=t,n.right=i),this._updateHeight(i),t&&this._updateHeight(t),n&&this._updateHeight(n)}_balanceRR(i){let e=i.parent,t=i.right;t!==null&&(i.parent=t),t&&(t.left&&(t.left.parent=i),t.parent=e),i===this.root?t&&this._setRoot(t):e&&(e.left===i?e.left=t:e.right=t),t&&(i.right=t.left,t.left=i),this._updateHeight(i),t&&this._updateHeight(t)}_balanceRL(i){let e=i.parent,t=i.right,n;t&&(n=t.left),n!==null&&(i.parent=n),t&&n!==null&&(t.parent=n),n&&(n.left&&(n.left.parent=i),n.right&&t!==null&&(n.right.parent=t),n.parent=e),i===this.root?n&&this._setRoot(n):e&&(e.left===i?e.left=n:e.right=n),n&&(i.right=n.left),t&&n&&(t.left=n.right),n&&(n.left=i),n&&(n.right=t),this._updateHeight(i),t&&this._updateHeight(t),n&&this._updateHeight(n)}_balancePath(i){i=this.ensureNode(i);let e=this.getPathToRoot(i,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(i,e){return e.height=i.height,super._replaceNode(i,e)}};var G=class{constructor(i,e,t="BLACK"){u(this,"key");u(this,"value");u(this,"parent");u(this,"_left");u(this,"_right");u(this,"_height",0);u(this,"_color","BLACK");u(this,"_count",1);this.key=i,this.value=e,this.color=t}get left(){return this._left}set left(i){i&&(i.parent=this),this._left=i}get right(){return this._right}set right(i){i&&(i.parent=this),this._right=i}get height(){return this._height}set height(i){this._height=i}get color(){return this._color}set color(i){this._color=i}get count(){return this._count}set count(i){this._count=i}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"}},A=class extends J{constructor(e=[],t){super([],t);u(this,"_root");u(this,"_header");u(this,"_minNode");u(this,"_maxNode");this._root=this.NIL,this._header=new G(void 0,void 0,"BLACK"),this._header.parent=this.NIL,this._header._left=this.NIL,this._header._right=this.NIL,e&&this.setMany(e)}get root(){return this._root}createNode(e,t,n="BLACK"){return new G(e,t,n)}isNode(e){return e instanceof G}clear(){super.clear(),this._root=this.NIL,this._header.parent=this.NIL,this._setMinCache(void 0),this._setMaxCache(void 0)}_findNodeByKey(e){var s,o,d;let t=this.NIL,n=this._compare.bind(this),r=(s=this._header.parent)!=null?s:t;for(;r!==t;){let a=n(e,r.key);if(a<0)r=(o=r.left)!=null?o:t;else if(a>0)r=(d=r.right)!=null?d:t;else return r}}_predecessorOf(e){let t=this.NIL;if(e.left&&e.left!==t){let s=e.left;for(;s.right&&s.right!==t;)s=s.right;return s}let n=e,r=e.parent;for(;r&&n===r.left;)n=r,r=r.parent;return r}_successorOf(e){let t=this.NIL;if(e.right&&e.right!==t){let s=e.right;for(;s.left&&s.left!==t;)s=s.left;return s}let n=e,r=e.parent;for(;r&&n===r.right;)n=r,r=r.parent;return r}_attachNewNode(e,t,n){let r=this.NIL;n.parent=e,t==="left"?e.left=n:e.right=n,n.left=r,n.right=r,n.color="RED",this._insertFixup(n),this.isRealNode(this._root)&&(this._root.color="BLACK")}_setMinCache(e){this._minNode=e,this._header._left=e!=null?e:this.NIL}_setMaxCache(e){this._maxNode=e,this._header._right=e!=null?e:this.NIL}_setKVNode(e,t){var E,y,m,N,K,V,R;let n=this.NIL,r=this._comparator,s=this._header,o=(E=s._left)!=null?E:n;if(o!==n){let k=r(e,o.key);if(k===0)return o.value=t,this._isMapMode&&this._store.set(e,o),{node:o,created:!1};let I=o.left;if(k<0&&(I===n||I===null||I===void 0)){let w=this.createNode(e,t);return this._attachNewNode(o,"left",w),this._isMapMode&&this._store.set(w.key,w),this._size++,this._setMinCache(w),s._right===n&&this._setMaxCache(w),{node:w,created:!0}}if(k>0){let w=(y=s._right)!=null?y:n,ft=r(e,w.key);if(ft===0)return w.value=t,this._isMapMode&&this._store.set(e,w),{node:w,created:!1};let Se=w.right;if(ft>0&&(Se===n||Se===null||Se===void 0)){let te=this.createNode(e,t);return this._attachNewNode(w,"right",te),this._isMapMode&&this._store.set(te.key,te),this._size++,this._setMaxCache(te),s._left===n&&this._setMinCache(te),{node:te,created:!0}}}}let d=r,a=this._isMapMode,l=this._store,f=(m=this._header.parent)!=null?m:n,c,g=0;for(;f!==n;)if(c=f,g=d(e,f.key),g<0)f=(N=f.left)!=null?N:n;else if(g>0)f=(K=f.right)!=null?K:n;else return f.value=t,a&&l.set(e,f),{node:f,created:!1};let p=this.createNode(e,t);if(p.parent=c,c?g<0?c.left=p:c.right=p:this._setRoot(p),p.left=n,p.right=n,p.color="RED",this._insertFixup(p),this.isRealNode(this._root))this._root.color="BLACK";else return;a&&l.set(p.key,p),this._size++;let b=(V=this._header._left)!=null?V:n,T=(R=this._header._right)!=null?R:n;return b===n||T===n?(this._setMinCache(p),this._setMaxCache(p)):c===T&&g>0?this._setMaxCache(p):c===b&&g<0?this._setMinCache(p):(d(p.key,b.key)<0&&this._setMinCache(p),d(p.key,T.key)>0&&this._setMaxCache(p)),{node:p,created:!0}}_setKV(e,t){if(this._isMapMode){let r=this._store.get(e);if(r)return r.value=t,!0}return this._setKVNode(e,t)!==void 0}setWithHintNode(e,t,n){var d,a,l,f,c,g,p,b,T,E,y,m,N;if(!n||!this.isRealNode(n))return(d=this._setKVNode(e,t))==null?void 0:d.node;let r=this._compare.bind(this),s=r(e,n.key);if(s===0)return n.value=t,this._isMapMode&&this._store.set(e,n),n;if(s<0){if(!this.isRealNode(n.left)){let V=this.createNode(e,t);if(!this.isRealNode(V))return;this._attachNewNode(n,"left",V),this._isMapMode&&this._store.set(e,V),this._size++;let R=this.NIL,k=(a=this._header._left)!=null?a:R;(k===R||this._compare(V.key,k.key)<0)&&this._setMinCache(V);let I=(l=this._header._right)!=null?l:R;return(I===R||this._compare(V.key,I.key)>0)&&this._setMaxCache(V),V}let K=this._predecessorOf(n);if(K&&r(K.key,e)>=0)return(f=this._setKVNode(e,t))==null?void 0:f.node;if(K&&!this.isRealNode(K.right)){let V=this.createNode(e,t);if(!this.isRealNode(V))return;this._attachNewNode(K,"right",V),this._isMapMode&&this._store.set(e,V),this._size++;let R=this.NIL,k=(c=this._header._left)!=null?c:R;(k===R||this._compare(V.key,k.key)<0)&&this._setMinCache(V);let I=(g=this._header._right)!=null?g:R;return(I===R||this._compare(V.key,I.key)>0)&&this._setMaxCache(V),V}return(p=this._setKVNode(e,t))==null?void 0:p.node}if(!this.isRealNode(n.right)){let K=this.createNode(e,t);if(!this.isRealNode(K))return;this._attachNewNode(n,"right",K),this._isMapMode&&this._store.set(e,K),this._size++;let V=this.NIL,R=(b=this._header._left)!=null?b:V;(R===V||this._compare(K.key,R.key)<0)&&this._setMinCache(K);let k=(T=this._header._right)!=null?T:V;return(k===V||this._compare(K.key,k.key)>0)&&this._setMaxCache(K),K}let o=this._successorOf(n);if(o&&r(o.key,e)<=0)return(E=this._setKVNode(e,t))==null?void 0:E.node;if(o&&!this.isRealNode(o.left)){let K=this.createNode(e,t);if(!this.isRealNode(K))return;this._attachNewNode(o,"left",K),this._isMapMode&&this._store.set(e,K),this._size++;let V=this.NIL,R=(y=this._header._left)!=null?y:V;(R===V||this._compare(K.key,R.key)<0)&&this._setMinCache(K);let k=(m=this._header._right)!=null?m:V;return(k===V||this._compare(K.key,k.key)>0)&&this._setMaxCache(K),K}return(N=this._setKVNode(e,t))==null?void 0:N.node}setWithHint(e,t,n){return this.setWithHintNode(e,t,n)!==void 0}set(e,t){if(!this.isNode(e)){if(e==null)return!1;if(this.isEntry(e)){let o=e[0];if(o==null)return!1;let d=t!=null?t:e[1];return this._setKV(o,d)}return this._setKV(e,t)}let[n,r]=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;if(this._isMapMode){let o=this.getNode(n.key);this.isRealNode(o)&&(o.value=r,this._store.set(o.key,o))}return this._size++,!0}if(s==="UPDATED"){if(this._isMapMode){let o=this.getNode(n.key);this.isRealNode(o)&&(o.value=r,this._store.set(o.key,o))}return!0}return!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 r=n===this._minNode,s=n===this._maxNode,o=r?this._successorOf(n):void 0,d=s?this._predecessorOf(n):void 0,a=n.color,l;if(!this.isRealNode(n.left))n.right!==null&&(l=n.right,this._transplant(n,n.right));else if(!this.isRealNode(n.right))l=n.left,this._transplant(n,n.left);else{let f=this.getLeftMost(c=>c,n.right);f&&(a=f.color,f.right!==null&&(l=f.right),f.parent===n?this.isRealNode(l)&&(l.parent=f):(f.right!==null&&(this._transplant(f,f.right),f.right=n.right),this.isRealNode(f.right)&&(f.right.parent=f)),this._transplant(n,f),f.left=n.left,this.isRealNode(f.left)&&(f.left.parent=f),f.color=n.color)}return this._isMapMode&&this._store.delete(n.key),this._size--,this._size<=0?(this._setMinCache(void 0),this._setMaxCache(void 0)):(r&&this._setMinCache(o),s&&this._setMaxCache(d),(!this._minNode||!this.isRealNode(this._minNode))&&this._setMinCache(this.isRealNode(this._root)?this.getLeftMost(f=>f,this._root):void 0),(!this._maxNode||!this.isRealNode(this._maxNode))&&this._setMaxCache(this.isRealNode(this._root)?this.getRightMost(f=>f,this._root):void 0)),a==="BLACK"&&this._deleteFixup(l),t.push({deleted:n,needBalanced:void 0}),t}map(e,t,n){let r=this._createLike([],t),s=0;for(let[o,d]of this)r.set(e.call(n,d,o,s++,this));return r}_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){let t=this.NIL;e&&(e.parent=void 0),this._root=e,this._header.parent=e!=null?e:t}_replaceNode(e,t){return t.color=e.color,super._replaceNode(e,t)}_insert(e){var d,a,l;let t=this.NIL,n=this._compare.bind(this),r=(d=this._header.parent)!=null?d:t,s,o=0;for(;r!==t;)if(s=r,o=n(e.key,r.key),o<0)r=(a=r.left)!=null?a:t;else if(o>0)r=(l=r.right)!=null?l:t;else return this._replaceNode(r,e),"UPDATED";return e.parent=s,s?o<0?s.left=e:s.right=e:this._setRoot(e),e.left=t,e.right=t,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){let t=this._leftRotate.bind(this),n=this._rightRotate.bind(this);for(;e;){let r=e.parent;if(!r||r.color!=="RED")break;let s=r.parent;if(!s)break;if(r===s.left){let o=s.right;if((o==null?void 0:o.color)==="RED"){r.color="BLACK",o.color="BLACK",s.color="RED",e=s;continue}e===r.right&&(e=r,t(e));let d=e==null?void 0:e.parent,a=d==null?void 0:d.parent;d&&a&&(d.color="BLACK",a.color="RED",n(a))}else{let o=s.left;if((o==null?void 0:o.color)==="RED"){r.color="BLACK",o.color="BLACK",s.color="RED",e=s;continue}e===r.left&&(e=r,n(e));let d=e==null?void 0:e.parent,a=d==null?void 0:d.parent;d&&a&&(d.color="BLACK",a.color="RED",t(a))}break}this.isRealNode(this._root)&&(this._root.color="BLACK")}_deleteFixup(e){var t,n,r,s;if(!e||e===this.root||e.color==="BLACK"){e&&(e.color="BLACK");return}for(;e&&e!==this.root&&e.color==="BLACK";){let o=e.parent;if(!o)break;if(e===o.left){let d=o.right;(d==null?void 0:d.color)==="RED"&&(d.color="BLACK",o.color="RED",this._leftRotate(o),d=o.right),((n=(t=d==null?void 0:d.left)==null?void 0:t.color)!=null?n:"BLACK")==="BLACK"?(d&&(d.color="RED"),e=o):(d!=null&&d.left&&(d.left.color="BLACK"),d&&(d.color=o.color),o.color="BLACK",this._rightRotate(o),e=this.root)}else{let d=o.left;(d==null?void 0:d.color)==="RED"&&(d.color="BLACK",o&&(o.color="RED"),this._rightRotate(o),o&&(d=o.left)),((s=(r=d==null?void 0:d.right)==null?void 0:r.color)!=null?s:"BLACK")==="BLACK"?(d&&(d.color="RED"),e=o):(d!=null&&d.right&&(d.right.color="BLACK"),d&&(d.color=o.color),o&&(o.color="BLACK"),this._leftRotate(o),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 B,be,me,ge=class ge{constructor(i=[],e={}){C(this,B);C(this,be);C(this,me);var r;S(this,me,e.comparator);let t=e.toElementFn,n=(r=e.comparator)!=null?r:ge.createDefaultComparator();S(this,be,e.comparator===void 0),S(this,B,new A([],{comparator:n,isMapMode:e.isMapMode}));for(let s of i){let o=t?t(s):s;this.add(o)}}static createDefaultComparator(){return(i,e)=>{if(typeof i=="number"&&typeof e=="number"){if(Number.isNaN(i)||Number.isNaN(e))throw new TypeError("TreeSet: NaN is not a valid key");let t=Object.is(i,-0)?0:i,n=Object.is(e,-0)?0:e;return t>n?1:t<n?-1:0}if(typeof i=="string"&&typeof e=="string")return i>e?1:i<e?-1:0;if(i instanceof Date&&e instanceof Date){let t=i.getTime(),n=e.getTime();if(Number.isNaN(t)||Number.isNaN(n))throw new TypeError("TreeSet: invalid Date key");return t>n?1:t<n?-1:0}throw new TypeError("TreeSet: comparator is required for non-number/non-string/non-Date keys")}}get size(){return _(this,B).size}isEmpty(){return this.size===0}_validateKey(i){if(_(this,be)){if(typeof i=="number"){if(Number.isNaN(i))throw new TypeError("TreeSet: NaN is not a valid key");return}if(typeof i!="string"){if(i instanceof Date){if(Number.isNaN(i.getTime()))throw new TypeError("TreeSet: invalid Date key");return}throw new TypeError("TreeSet: comparator is required for non-number/non-string/non-Date keys")}}}add(i){return this._validateKey(i),_(this,B).set(i,void 0),this}has(i){return this._validateKey(i),_(this,B).has(i)}delete(i){var t;this._validateKey(i);let e=_(this,B).delete(i);return Array.isArray(e)&&e.length>0&&!!((t=e[0])!=null&&t.deleted)}clear(){_(this,B).clear()}keys(){return _(this,B).keys()}values(){return this.keys()}*entries(){for(let i of this.keys())yield[i,i]}[Symbol.iterator](){return this.keys()}forEach(i,e){for(let t of this)i.call(e,t,t,this)}map(i,e={},t){let n=new ge([],e),r=0;for(let s of this){let o=t===void 0?i(s,r++,this):i.call(t,s,r++,this);n.add(o)}return n}filter(i,e){let t=new ge([],{comparator:_(this,me)}),n=0;for(let r of this)(e===void 0?i(r,n++,this):i.call(e,r,n++,this))&&t.add(r);return t}reduce(i,e){let t=e,n=0;for(let r of this)t=i(t,r,n++,this);return t}every(i,e){let t=0;for(let n of this)if(!(e===void 0?i(n,t++,this):i.call(e,n,t++,this)))return!1;return!0}some(i,e){let t=0;for(let n of this)if(e===void 0?i(n,t++,this):i.call(e,n,t++,this))return!0;return!1}find(i,e){let t=0;for(let n of this)if(e===void 0?i(n,t++,this):i.call(e,n,t++,this))return n}toArray(){return[...this]}print(){_(this,B).print()}first(){return _(this,B).getLeftMost()}last(){return _(this,B).getRightMost()}pollFirst(){let i=this.first();if(i!==void 0)return this.delete(i),i}pollLast(){let i=this.last();if(i!==void 0)return this.delete(i),i}ceiling(i){return this._validateKey(i),_(this,B).ceiling(i)}floor(i){return this._validateKey(i),_(this,B).floor(i)}higher(i){return this._validateKey(i),_(this,B).higher(i)}lower(i){return this._validateKey(i),_(this,B).lower(i)}rangeSearch(i,e={}){let{lowInclusive:t=!0,highInclusive:n=!0}=e,[r,s]=i;this._validateKey(r),this._validateKey(s);let o=_(this,B).rangeSearch([r,s]),d=[],a=_(this,B).comparator;for(let l of o)l!==void 0&&(!t&&a(l,r)===0||!n&&a(l,s)===0||d.push(l));return d}};B=new WeakMap,be=new WeakMap,me=new WeakMap;var Y=ge;var nt=class extends G{constructor(i,e=[]){super(i,e)}},M,Ve,Ke=class Ke{constructor(i=[],e={}){C(this,M);C(this,Ve);var r;let t=(r=e.comparator)!=null?r:Y.createDefaultComparator();S(this,Ve,e.comparator===void 0);let n=e.toEntryFn;S(this,M,new A([],{...e,comparator:t,isMapMode:e.isMapMode}));for(let s of i)if(s!=null){if(n){let[o,d]=n(s);if(o==null)continue;d!==void 0?_(this,M).set(o,Array.isArray(d)?[...d]:[d]):_(this,M).set(o,[]);continue}if(Array.isArray(s)){let[o,d]=s;if(o==null)continue;d!==void 0?_(this,M).set(o,[...d]):_(this,M).set(o,[]);continue}_(this,M).set(s,[])}}_validateKey(i){if(_(this,Ve)){if(typeof i=="number"){if(Number.isNaN(i))throw new TypeError("TreeMultiMap: NaN is not a valid key");return}if(typeof i!="string"){if(i instanceof Date){if(Number.isNaN(i.getTime()))throw new TypeError("TreeMultiMap: invalid Date key");return}throw new TypeError("TreeMultiMap: comparator is required for non-number/non-string/non-Date keys")}}}get size(){return _(this,M).size}isEmpty(){return this.size===0}clear(){_(this,M).clear()}count(i){let e=this.get(i);return Array.isArray(e)?e.length:0}get totalSize(){let i=0;for(let[,e]of this)i+=e.length;return i}has(i){return this._validateKey(i),_(this,M).has(i)}get(i){return this._validateKey(i),_(this,M).get(i)}add(i,e){this._validateKey(i);let t=_(this,M).get(i);return t?(t.push(e),!0):_(this,M).set(i,[e])}set(i,e){if(i==null)return!1;if(Array.isArray(i)){let[t,n]=i;if(t==null)return!1;if(e!==void 0)return this.add(t,e);if(n===void 0)return _(this,M).set(t,[]);let r=_(this,M).get(t);return r?(r.push(...n),!0):_(this,M).set(t,[...n])}return e!==void 0?this.add(i,e):_(this,M).set(i,[])}delete(i){return this._validateKey(i),_(this,M).delete(i).length>0}hasEntry(i,e,t=Object.is){let n=this.get(i);return Array.isArray(n)?n.some(r=>t(r,e)):!1}deleteValue(i,e,t=Object.is){let n=this.get(i);if(!Array.isArray(n))return!1;let r=n.findIndex(s=>t(s,e));return r===-1?!1:(n.splice(r,1),n.length===0&&this.delete(i),!0)}deleteValues(i,e,t=Object.is){let n=this.get(i);if(!Array.isArray(n)||n.length===0)return 0;let r=0;for(let s=n.length-1;s>=0;s--)t(n[s],e)&&(n.splice(s,1),r++);return n.length===0&&r>0&&this.delete(i),r}*[Symbol.iterator](){for(let[i,e]of _(this,M))yield[i,e!=null?e:[]]}*keys(){yield*_(this,M).keys()}*values(){for(let[,i]of this)yield i}*entriesOf(i){let e=this.get(i);if(Array.isArray(e))for(let t of e)yield[i,t]}*valuesOf(i){let e=this.get(i);Array.isArray(e)&&(yield*e)}*flatEntries(){for(let[i,e]of this)for(let t of e)yield[i,t]}first(){let i=_(this,M).getLeftMost();if(i===void 0)return;let e=this.get(i);return e===void 0?void 0:[i,e]}last(){let i=_(this,M).getRightMost();if(i===void 0)return;let e=this.get(i);return e===void 0?void 0:[i,e]}pollFirst(){let i=this.first();if(i)return this.delete(i[0]),i}pollLast(){let i=this.last();if(i)return this.delete(i[0]),i}ceiling(i){this._validateKey(i);let e=_(this,M).ceiling(i);if(e===void 0)return;let t=this.get(e);return t===void 0?void 0:[e,t]}floor(i){this._validateKey(i);let e=_(this,M).floor(i);if(e===void 0)return;let t=this.get(e);return t===void 0?void 0:[e,t]}higher(i){this._validateKey(i);let e=_(this,M).higher(i);if(e===void 0)return;let t=this.get(e);return t===void 0?void 0:[e,t]}lower(i){this._validateKey(i);let e=_(this,M).lower(i);if(e===void 0)return;let t=this.get(e);return t===void 0?void 0:[e,t]}print(){_(this,M).print()}forEach(i){for(let[e,t]of this)i(t,e,this)}filter(i){let e=[];for(let[t,n]of this)i(n,t,this)&&e.push([t,n]);return new Ke(e,{comparator:this.comparator})}map(i){let e=[];for(let[t,n]of this)e.push(i(n,t,this));return new Ke(e,{comparator:this.comparator})}reduce(i,e){let t=e;for(let[n,r]of this)t=i(t,r,n,this);return t}setMany(i){let e=[];for(let t of i)e.push(this.set(t));return e}rangeSearch(i,e){return _(this,M).rangeSearch(i,e)}clone(){return new Ke(this,{comparator:this.comparator,isMapMode:_(this,M).isMapMode})}get comparator(){return _(this,M).comparator}};M=new WeakMap,Ve=new WeakMap;var it=Ke;var L,Te,Ee,ye=class ye{constructor(i=[],e={}){C(this,L);C(this,Te);C(this,Ee);var r;S(this,Ee,e.comparator);let t=e.toEntryFn,n=(r=e.comparator)!=null?r:ye.createDefaultComparator();S(this,Te,e.comparator===void 0),S(this,L,new A([],{comparator:n,isMapMode:e.isMapMode}));for(let s of i){let o,d;if(t)[o,d]=t(s);else{if(!Array.isArray(s)||s.length<2)throw new TypeError("TreeMap: each entry must be a [key, value] tuple");o=s[0],d=s[1]}this.set(o,d)}}static createDefaultComparator(){return(i,e)=>{if(typeof i=="number"&&typeof e=="number"){if(Number.isNaN(i)||Number.isNaN(e))throw new TypeError("TreeMap: NaN is not a valid key");let t=Object.is(i,-0)?0:i,n=Object.is(e,-0)?0:e;return t>n?1:t<n?-1:0}if(typeof i=="string"&&typeof e=="string")return i>e?1:i<e?-1:0;if(i instanceof Date&&e instanceof Date){let t=i.getTime(),n=e.getTime();if(Number.isNaN(t)||Number.isNaN(n))throw new TypeError("TreeMap: invalid Date key");return t>n?1:t<n?-1:0}throw new TypeError("TreeMap: comparator is required for non-number/non-string/non-Date keys")}}_validateKey(i){if(_(this,Te)){if(typeof i=="number"){if(Number.isNaN(i))throw new TypeError("TreeMap: NaN is not a valid key");return}if(typeof i!="string"){if(i instanceof Date){if(Number.isNaN(i.getTime()))throw new TypeError("TreeMap: invalid Date key");return}throw new TypeError("TreeMap: comparator is required for non-number/non-string/non-Date keys")}}}get size(){return _(this,L).size}isEmpty(){return this.size===0}set(i,e){return this._validateKey(i),_(this,L).set(i,e),this}get(i){return this._validateKey(i),_(this,L).get(i)}has(i){return this._validateKey(i),_(this,L).has(i)}delete(i){var t;this._validateKey(i);let e=_(this,L).delete(i);return Array.isArray(e)&&e.length>0&&!!((t=e[0])!=null&&t.deleted)}clear(){_(this,L).clear()}keys(){return _(this,L).keys()}_entryFromKey(i){return[i,_(this,L).get(i)]}*values(){for(let i of this.keys())yield this._entryFromKey(i)[1]}*entries(){for(let i of this.keys())yield this._entryFromKey(i)}[Symbol.iterator](){return this.entries()}forEach(i,e){for(let[t,n]of this)i.call(e,n,t,this)}map(i,e={},t){let n=new ye([],e),r=0;for(let[s,o]of this){let[d,a]=t===void 0?i(o,s,r++,this):i.call(t,o,s,r++,this);n.set(d,a)}return n}filter(i,e){let t=new ye([],{comparator:_(this,Ee)}),n=0;for(let[r,s]of this)(e===void 0?i(s,r,n++,this):i.call(e,s,r,n++,this))&&t.set(r,s);return t}reduce(i,e){let t=e,n=0;for(let[r,s]of this)t=i(t,s,r,n++,this);return t}every(i,e){let t=0;for(let[n,r]of this)if(!(e===void 0?i(r,n,t++,this):i.call(e,r,n,t++,this)))return!1;return!0}some(i,e){let t=0;for(let[n,r]of this)if(e===void 0?i(r,n,t++,this):i.call(e,r,n,t++,this))return!0;return!1}find(i,e){let t=0;for(let[n,r]of this)if(e===void 0?i(r,n,t++,this):i.call(e,r,n,t++,this))return[n,r]}toArray(){return[...this]}print(){_(this,L).print()}first(){let i=_(this,L).getLeftMost();return i===void 0?void 0:this._entryFromKey(i)}last(){let i=_(this,L).getRightMost();return i===void 0?void 0:this._entryFromKey(i)}pollFirst(){let i=this.first();if(i)return this.delete(i[0]),i}pollLast(){let i=this.last();if(i)return this.delete(i[0]),i}ceiling(i){this._validateKey(i);let e=_(this,L).ceiling(i);return e===void 0?void 0:this._entryFromKey(e)}floor(i){this._validateKey(i);let e=_(this,L).floor(i);return e===void 0?void 0:this._entryFromKey(e)}higher(i){this._validateKey(i);let e=_(this,L).higher(i);return e===void 0?void 0:this._entryFromKey(e)}lower(i){this._validateKey(i);let e=_(this,L).lower(i);return e===void 0?void 0:this._entryFromKey(e)}rangeSearch(i,e={}){let{lowInclusive:t=!0,highInclusive:n=!0}=e,[r,s]=i;this._validateKey(r),this._validateKey(s);let o=_(this,L).rangeSearch([r,s]),d=[],a=_(this,L).comparator;for(let l of o)l!==void 0&&(!t&&a(l,r)===0||!n&&a(l,s)===0||d.push(this._entryFromKey(l)));return d}};L=new WeakMap,Te=new WeakMap,Ee=new WeakMap;var rt=ye;var x,Z,Ne=class Ne{constructor(i=[],e={}){C(this,x);C(this,Z);u(this,"_size",0);var r;let t=e.toElementFn,n=(r=e.comparator)!=null?r:Y.createDefaultComparator();S(this,Z,e.comparator===void 0),S(this,x,new A([],{comparator:n,isMapMode:e.isMapMode}));for(let s of i){let o=t?t(s):s;this.add(o)}}_validateKey(i){if(_(this,Z)){if(typeof i=="number"){if(Number.isNaN(i))throw new TypeError("TreeMultiSet: NaN is not a valid key");return}if(typeof i!="string"){if(i instanceof Date){if(Number.isNaN(i.getTime()))throw new TypeError("TreeMultiSet: invalid Date key");return}throw new TypeError("TreeMultiSet: comparator is required for non-number/non-string/non-Date keys")}}}_validateCount(i){if(!Number.isSafeInteger(i)||i<0)throw new RangeError("TreeMultiSet: count must be a safe integer >= 0")}get size(){return this._size}get distinctSize(){return _(this,x).size}isEmpty(){return this.size===0}has(i){return this._validateKey(i),this.count(i)>0}count(i){var e;return this._validateKey(i),(e=_(this,x).get(i))!=null?e:0}add(i,e=1){var r;if(this._validateKey(i),this._validateCount(e),e===0)return!1;let n=((r=_(this,x).get(i))!=null?r:0)+e;return _(this,x).set(i,n),this._size+=e,!0}setCount(i,e){var n;this._validateKey(i),this._validateCount(e);let t=(n=_(this,x).get(i))!=null?n:0;return t===e?!1:(e===0?t!==0&&_(this,x).delete(i):_(this,x).set(i,e),this._size+=e-t,!0)}delete(i,e=1){var s;if(this._validateKey(i),this._validateCount(e),e===0)return!1;let t=(s=_(this,x).get(i))!=null?s:0;if(t===0)return!1;let n=Math.min(t,e),r=t-n;return r===0?_(this,x).delete(i):_(this,x).set(i,r),this._size-=n,!0}deleteAll(i){var t;this._validateKey(i);let e=(t=_(this,x).get(i))!=null?t:0;return e===0?!1:(_(this,x).delete(i),this._size-=e,!0)}*keysDistinct(){yield*_(this,x).keys()}*entries(){for(let[i,e]of _(this,x))yield[i,e!=null?e:0]}*[Symbol.iterator](){for(let[i,e]of this.entries())for(let t=0;t<e;t++)yield i}toArray(){return[...this]}toDistinctArray(){return[...this.keysDistinct()]}toEntries(){return[...this.entries()]}get comparator(){return _(this,x)._comparator}clear(){_(this,x).clear(),this._size=0}first(){return _(this,x).getLeftMost()}last(){return _(this,x).getRightMost()}pollFirst(){let i=this.first();if(i!==void 0)return this.deleteAll(i),i}pollLast(){let i=this.last();if(i!==void 0)return this.deleteAll(i),i}ceiling(i){return this._validateKey(i),_(this,x).ceiling(i)}floor(i){return this._validateKey(i),_(this,x).floor(i)}higher(i){return this._validateKey(i),_(this,x).higher(i)}lower(i){return this._validateKey(i),_(this,x).lower(i)}forEach(i){for(let[e,t]of this.entries())i(e,t)}filter(i){let e=new Ne([],{comparator:_(this,Z)?void 0:this.comparator,isMapMode:_(this,x)._isMapMode});for(let[t,n]of this.entries())i(t,n)&&e.add(t,n);return e}reduce(i,e){let t=e;for(let[n,r]of this.entries())t=i(t,n,r);return t}map(i,e){let t=new Ne([],{comparator:e==null?void 0:e.comparator,isMapMode:_(this,x)._isMapMode});for(let[n,r]of this.entries()){let[s,o]=i(n,r);t.add(s,o)}return t}clone(){let i=new Ne([],{comparator:_(this,Z)?void 0:this.comparator,isMapMode:_(this,x)._isMapMode});for(let[e,t]of this.entries())i.add(e,t);return i}rangeSearch(i,e){let t=e!=null?e:(n=>n);return _(this,x).rangeSearch(i,n=>t(n.key))}print(){_(this,x).print()}};x=new WeakMap,Z=new WeakMap;var st=Ne;var ee=class extends D{constructor(i=[],e){super(i,e)}};var ot=class extends ee{constructor(i=[],e){super(i,e)}};var dt=class extends ee{constructor(i=[],e){super(i,{comparator:(t,n)=>{if(typeof t=="object"||typeof n=="object")throw TypeError("When comparing object types, a custom comparator must be defined in the constructor's options parameter.");return t<n?1:t>n?-1:0},...e})}};var at=class h{constructor(i,e){u(this,"_rows",0);u(this,"_cols",0);u(this,"_data");var t,n,r;if(e){let{rows:s,cols:o,addFn:d,subtractFn:a,multiplyFn:l}=e;typeof s=="number"&&s>0?this._rows=s:this._rows=i.length,typeof o=="number"&&o>0?this._cols=o:this._cols=((t=i[0])==null?void 0:t.length)||0,d&&(this._addFn=d),a&&(this._subtractFn=a),l&&(this._multiplyFn=l)}else this._rows=i.length,this._cols=(r=(n=i[0])==null?void 0:n.length)!=null?r:0;if(i.length>0)this._data=i;else{this._data=[];for(let s=0;s<this.rows;s++)this._data[s]=new Array(this.cols).fill(0)}}get rows(){return this._rows}get cols(){return this._cols}get data(){return this._data}get addFn(){return this._addFn}get subtractFn(){return this._subtractFn}get multiplyFn(){return this._multiplyFn}get(i,e){if(this.isValidIndex(i,e))return this.data[i][e]}set(i,e,t){return this.isValidIndex(i,e)?(this.data[i][e]=t,!0):!1}isMatchForCalculate(i){return this.rows===i.rows&&this.cols===i.cols}add(i){if(!this.isMatchForCalculate(i))throw new Error("Matrix dimensions must match for addition.");let e=[];for(let t=0;t<this.rows;t++){e[t]=[];for(let n=0;n<this.cols;n++){let r=this.get(t,n),s=i.get(t,n);if(r!==void 0&&s!==void 0){let o=this._addFn(r,s);o&&(e[t][n]=o)}}}return new h(e,{rows:this.rows,cols:this.cols,addFn:this.addFn,subtractFn:this.subtractFn,multiplyFn:this.multiplyFn})}subtract(i){if(!this.isMatchForCalculate(i))throw new Error("Matrix dimensions must match for subtraction.");let e=[];for(let t=0;t<this.rows;t++){e[t]=[];for(let n=0;n<this.cols;n++){let r=this.get(t,n),s=i.get(t,n);if(r!==void 0&&s!==void 0){let o=this._subtractFn(r,s);o&&(e[t][n]=o)}}}return new h(e,{rows:this.rows,cols:this.cols,addFn:this.addFn,subtractFn:this.subtractFn,multiplyFn:this.multiplyFn})}multiply(i){if(this.cols!==i.rows)throw new Error("Matrix dimensions must be compatible for multiplication (A.cols = B.rows).");let e=[];for(let t=0;t<this.rows;t++){e[t]=[];for(let n=0;n<i.cols;n++){let r;for(let s=0;s<this.cols;s++){let o=this.get(t,s),d=i.get(s,n);if(o!==void 0&&d!==void 0){let a=this.multiplyFn(o,d);a!==void 0&&(r=this.addFn(r,a))}}r!==void 0&&(e[t][n]=r)}}return new h(e,{rows:this.rows,cols:i.cols,addFn:this.addFn,subtractFn:this.subtractFn,multiplyFn:this.multiplyFn})}transpose(){if(this.data.some(e=>e.length!==this.rows))throw new Error("Matrix must be rectangular for transposition.");let i=[];for(let e=0;e<this.cols;e++){i[e]=[];for(let t=0;t<this.rows;t++){let n=this.get(t,e);n!==void 0&&(i[e][t]=n)}}return new h(i,{rows:this.cols,cols:this.rows,addFn:this.addFn,subtractFn:this.subtractFn,multiplyFn:this.multiplyFn})}inverse(){var n;if(this.rows!==this.cols)throw new Error("Matrix must be square for inversion.");let i=[];for(let r=0;r<this.rows;r++){i[r]=this.data[r].slice();for(let s=0;s<this.cols;s++)i[r][this.cols+s]=r===s?1:0}let e=new h(i,{rows:this.rows,cols:this.cols*2,addFn:this.addFn,subtractFn:this.subtractFn,multiplyFn:this.multiplyFn});for(let r=0;r<this.rows;r++){let s=r;for(;s<this.rows&&e.get(s,r)===0;)s++;if(s===this.rows)throw new Error("Matrix is singular, and its inverse does not exist.");e._swapRows(r,s);let o=(n=e.get(r,r))!=null?n:1;if(o===0)throw new Error("Matrix is singular, and its inverse does not exist (division by zero).");e._scaleRow(r,1/o);for(let d=0;d<this.rows;d++)if(d!==r){let a=e.get(d,r);a===void 0&&(a=0),e._addScaledRow(d,r,-a)}}let t=[];for(let r=0;r<this.rows;r++)t[r]=e.data[r].slice(this.cols);return new h(t,{rows:this.rows,cols:this.cols,addFn:this.addFn,subtractFn:this.subtractFn,multiplyFn:this.multiplyFn})}dot(i){if(this.cols!==i.rows)throw new Error("Number of columns in the first matrix must be equal to the number of rows in the second matrix for dot product.");let e=[];for(let t=0;t<this.rows;t++){e[t]=[];for(let n=0;n<i.cols;n++){let r;for(let s=0;s<this.cols;s++){let o=this.get(t,s),d=i.get(s,n);if(o!==void 0&&d!==void 0){let a=this.multiplyFn(o,d);a!==void 0&&(r=this.addFn(r,a))}}r!==void 0&&(e[t][n]=r)}}return new h(e,{rows:this.rows,cols:i.cols,addFn:this.addFn,subtractFn:this.subtractFn,multiplyFn:this.multiplyFn})}isValidIndex(i,e){return i>=0&&i<this.rows&&e>=0&&e<this.cols}clone(){return new h(this.data,{rows:this.rows,cols:this.cols,addFn:this.addFn,subtractFn:this.subtractFn,multiplyFn:this.multiplyFn})}_addFn(i,e){return i===void 0?e:i+e}_subtractFn(i,e){return i-e}_multiplyFn(i,e){return i*e}_swapRows(i,e){let t=this.data[i];this.data[i]=this.data[e],this.data[e]=t}_scaleRow(i,e){for(let t=0;t<this.cols;t++){let n=this.multiplyFn(this.data[i][t],e);n===void 0&&(n=0),this.data[i][t]=n}}_addScaledRow(i,e,t){for(let n=0;n<this.cols;n++){let r=this.multiplyFn(this.data[e][n],t);r===void 0&&(r=0);let s=r,o=this.addFn(this.data[i][n],s);o===void 0&&(o=0),this.data[i][n]=o}}};var Ce=class h{constructor(i,e){u(this,"direction");u(this,"turn");this.direction=i,this.turn=()=>new h(e[i],e)}},lt=class{constructor({matrix:i,turning:e,onMove:t,init:{cur:n,charDir:r,VISITED:s}}){u(this,"onMove");u(this,"_matrix");u(this,"_cur");u(this,"_character");u(this,"_VISITED");this._matrix=i,this._cur=n,this._character=new Ce(r,e),this.onMove=t,this.onMove&&this.onMove(this._cur),this._VISITED=s,this._matrix[this._cur[0]][this._cur[1]]=this._VISITED}start(){for(;this.check(this._character.direction)||this.check(this._character.turn().direction);){let{direction:i}=this._character;this.check(i)?this.move(i):this.check(this._character.turn().direction)&&(this._character=this._character.turn())}}check(i){let e,t,n=this._matrix,[r,s]=this._cur;switch(i){case"up":if(t=n[r-1],!t)return!1;e=t[s];break;case"right":e=n[r][s+1];break;case"down":if(t=n[r+1],!t)return!1;e=t[s];break;case"left":e=n[r][s-1];break}return e!==void 0&&e!==this._VISITED}move(i){switch(i){case"up":this._cur[0]--;break;case"right":this._cur[1]++;break;case"down":this._cur[0]++;break;case"left":this._cur[1]--;break}let[e,t]=this._cur;this._matrix[e][t]=this._VISITED,this.onMove&&this.onMove(this._cur)}};var ae=class{constructor(i){u(this,"_key");u(this,"_children");u(this,"_isEnd");this._key=i,this._isEnd=!1,this._children=new Map}get key(){return this._key}set key(i){this._key=i}get children(){return this._children}set children(i){this._children=i}get isEnd(){return this._isEnd}set isEnd(i){this._isEnd=i}},ut=class extends F{constructor(e=[],t){super(t);u(this,"_size",0);u(this,"_caseSensitive",!0);u(this,"_root",new ae(""));if(t){let{caseSensitive:n}=t;n!==void 0&&(this._caseSensitive=n)}e&&this.addMany(e)}get size(){return this._size}get caseSensitive(){return this._caseSensitive}get root(){return this._root}get _total(){return this._size}add(e){e=this._caseProcess(e);let t=this.root,n=!1;for(let r of e){let s=t.children.get(r);s||(s=new ae(r),t.children.set(r,s)),t=s}return t.isEnd||(n=!0,t.isEnd=!0,this._size++),n}addMany(e){let t=[];for(let n of e)this.toElementFn?t.push(this.add(this.toElementFn(n))):t.push(this.add(n));return t}has(e){e=this._caseProcess(e);let t=this.root;for(let n of e){let r=t.children.get(n);if(!r)return!1;t=r}return t.isEnd}isEmpty(){return this._size===0}clear(){this._size=0,this._root=new ae("")}delete(e){e=this._caseProcess(e);let t=!1,n=(r,s)=>{let o=e[s],d=r.children.get(o);return d?s===e.length-1?d.isEnd?(d.children.size>0?d.isEnd=!1:r.children.delete(o),t=!0,!0):!1:n(d,s+1)&&!r.isEnd&&d.children.size===0?(r.children.delete(o),!0):!1:!1};return n(this.root,0),t&&this._size--,t}getHeight(){let e=this.root,t=0;if(e){let n=(r,s)=>{s>t&&(t=s);let{children:o}=r;if(o)for(let d of o.entries())n(d[1],s+1)};n(e,0)}return t}hasPurePrefix(e){e=this._caseProcess(e);let t=this.root;for(let n of e){let r=t.children.get(n);if(!r)return!1;t=r}return!t.isEnd}hasPrefix(e){e=this._caseProcess(e);let t=this.root;for(let n of e){let r=t.children.get(n);if(!r)return!1;t=r}return!0}hasCommonPrefix(e){e=this._caseProcess(e);let t="",n=r=>{if(t+=r.key,t!==e&&!r.isEnd)if(r&&r.children&&r.children.size===1)n(Array.from(r.children.values())[0]);else return};return n(this.root),t===e}getLongestCommonPrefix(){let e="",t=n=>{if(e+=n.key,!n.isEnd)if(n&&n.children&&n.children.size===1)t(Array.from(n.children.values())[0]);else return};return t(this.root),e}getWords(e="",t=Number.MAX_SAFE_INTEGER,n=!1){e=this._caseProcess(e);let r=[],s=0,o=(a,l)=>{for(let[f,c]of a.children){if(s>=t)return;o(c,l+f)}if(a.isEnd){if(s>=t)return;r.push(l),s++}},d=this.root;if(e)for(let a of e){let l=d.children.get(a);if(l)d=l;else return[]}return(n||d!==this.root)&&o(d,e),r}clone(){let e=this._createInstance();for(let t of this)e.add(t);return e}filter(e,t){let n=this._createInstance(),r=0;for(let s of this)e.call(t,s,r,this)&&n.add(s),r++;return n}map(e,t,n){let r=this._createLike([],t),s=0;for(let o of this){let d=n===void 0?e(o,s++,this):e.call(n,o,s++,this);if(typeof d!="string")throw new TypeError(`Trie.map callback must return string; got ${typeof d}`);r.add(d)}return r}mapSame(e,t){let n=this._createInstance(),r=0;for(let s of this){let o=t===void 0?e(s,r++,this):e.call(t,s,r++,this);n.add(o)}return n}_createInstance(e){let t=this.constructor;return new t([],{toElementFn:this.toElementFn,caseSensitive:this.caseSensitive,...e!=null?e:{}})}_createLike(e=[],t){let n=this.constructor;return new n(e,t)}_spawnLike(e){return this._createLike([],e)}*_getIterator(){function*e(t,n){t.isEnd&&(yield n);for(let[r,s]of t.children)yield*e(s,n+r)}yield*e(this.root,"")}_caseProcess(e){return this._caseSensitive||(e=e.toLowerCase()),e}};var ht=class h{constructor(i,e,t){u(this,"_key");u(this,"_value");u(this,"_children");this._key=i,this._value=e||void 0,t&&(this._children=t)}get key(){return this._key}set key(i){this._key=i}get value(){return this._value}set value(i){this._value=i}get children(){return this._children}set children(i){this._children=i}addChildren(i){this._children||(this._children=[]),i instanceof h?this._children.push(i):this._children=this._children.concat(i)}getHeight(){let i=0;if(this){let e=(t,n)=>{n>i&&(i=n);let{_children:r}=t;if(r)for(let s=0,o=r.length;s<o;s++)e(r[s],n+1)};e(this,0)}return i}};return Nt(Bt);})();
|
|
5
|
+
`;r+=a})(e)),r}print(e,t=this._root){console.log(this.toVisual(t,e))}_dfs(e=this._DEFAULT_NODE_CALLBACK,t="IN",n=!1,r=this._root,s=this.iterationType,o=!1,d=c=>!!c,a=c=>!!c,l=c=>o?this.isRealNodeOrNull(c):this.isRealNode(c),f=c=>this.isRealNodeOrNull(c)){if(r=this.ensureNode(r),!r)return[];let c=[];if(s==="RECURSIVE"){let g=p=>{if(!l(p))return;let b=()=>{d(p)&&(p==null?void 0:p.left)!==void 0&&g(p==null?void 0:p.left)},T=()=>{a(p)&&(p==null?void 0:p.right)!==void 0&&g(p==null?void 0:p.right)};switch(t){case"IN":if(b(),f(p)&&(c.push(e(p)),n))return;T();break;case"PRE":if(f(p)&&(c.push(e(p)),n))return;b(),T();break;case"POST":if(b(),T(),f(p)&&(c.push(e(p)),n))return;break}};g(r)}else{let g=[{opt:0,node:r}],p=E=>{var y;d(E.node)&&g.push({opt:0,node:(y=E.node)==null?void 0:y.left})},b=E=>{var y;a(E.node)&&g.push({opt:0,node:(y=E.node)==null?void 0:y.right})},T=E=>{l(E.node)&&g.push({opt:1,node:E.node})};for(;g.length>0;){let E=g.pop();if(E!==void 0&&l(E.node))if(E.opt===1){if(f(E.node)&&E.node!==void 0&&(c.push(e(E.node)),n))return c}else switch(t){case"IN":b(E),T(E),p(E);break;case"PRE":b(E),p(E),T(E);break;case"POST":T(E),b(E),p(E);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)&&(yield[n.key,n.value],n=n.right)}}else e.left&&this.isRealNode(e)&&(yield*this[Symbol.iterator](e.left)),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,r]=e;if(n===void 0)return[void 0,void 0];if(n===null)return[null,void 0];let s=t!=null?t:r;return[this.createNode(n,s),s]}return[this.createNode(e,t),t]}_clone(e){this.bfs(t=>{t===null?e.set(null):e.set([t.key,t.value])},this._root,this.iterationType,!0)}_displayAux(e,t){let{isShowNull:n,isShowUndefined:r,isShowRedBlackNIL:s}=t,o=[["\u2500"],1,0,0];if(e===null&&!n)return o;if(e===void 0&&!r)return o;if(this.isNIL(e)&&!s)return o;if(e!=null){let a=e.key,l=this.isNIL(e)?"S":String(a),f=l.length;return d(l,f,this._displayAux(e.left,t),this._displayAux(e.right,t))}else{let a=e===void 0?"U":"N",l=a.length;return d(a,l,[[""],1,0,0],[[""],1,0,0])}function d(a,l,f,c){let[g,p,b,T]=f,[E,y,m,N]=c,K=" ".repeat(Math.max(0,T+1))+"_".repeat(Math.max(0,p-T-1))+a+"_".repeat(Math.max(0,N))+" ".repeat(Math.max(0,y-N)),V=(b>0?" ".repeat(T)+"/"+" ".repeat(p-T-1):" ".repeat(p))+" ".repeat(l)+(m>0?" ".repeat(N)+"\\"+" ".repeat(y-N-1):" ".repeat(y)),R=[K,V];for(let k=0;k<Math.max(b,m);k++){let I=k<b?g[k]:" ".repeat(p),v=k<m?E[k]:" ".repeat(y);R.push(I+" ".repeat(l)+v)}return[R,p+l+y,Math.max(b,m)+2,p+Math.floor(l/2)]}}_swapProperties(e,t){if(e=this.ensureNode(e),t=this.ensureNode(t),e&&t){let{key:n,value:r}=t,s=this.createNode(n,r);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){if(e==null)return!1;let n=this._store.get(e);return n?(n.value=t,!0):!1}_clearNodes(){this._setRoot(void 0),this._size=0}_clearValues(){this._store.clear()}};var Ve=class{constructor(i,e){u(this,"key");u(this,"value");u(this,"parent");u(this,"_left");u(this,"_right");u(this,"_height",0);u(this,"_color","BLACK");u(this,"_count",1);this.key=i,this.value=e}get left(){return this._left}set left(i){i&&(i.parent=this),this._left=i}get right(){return this._right}set right(i){i&&(i.parent=this),this._right=i}get height(){return this._height}set height(i){this._height=i}get color(){return this._color}set color(i){this._color=i}get count(){return this._count}set count(i){this._count=i}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"}},J=class extends Ke{constructor(e=[],t){super([],t);u(this,"_root");u(this,"_comparator");t?"comparator"in t&&t.comparator!==void 0?this._comparator=t.comparator:this._comparator=this._createDefaultComparator():this._comparator=this._createDefaultComparator(),e&&this.setMany(e)}get root(){return this._root}get comparator(){return this._comparator}createNode(e,t){return new Ve(e,t)}ensureNode(e,t=this.iterationType){var n;return(n=super.ensureNode(e,t))!=null?n:void 0}isNode(e){return e instanceof Ve}isValidKey(e){return Q(e)}dfs(e=this._DEFAULT_NODE_CALLBACK,t="IN",n=!1,r=this._root,s=this.iterationType){return super.dfs(e,t,n,r,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 l,f;if(e==null)return;if(this._isPredicate(e))return(l=this.getNodes(e,!0,t,n)[0])!=null?l:void 0;if(e instanceof H)return(f=this.getNodes(e,!0,t,n)[0])!=null?f:void 0;let r;if(this.isNode(e))r=e.key;else if(this.isEntry(e)){let c=e[0];if(c==null)return;r=c}else r=e;let s=this.ensureNode(t);if(!s)return;let o=this._NIL,d=s,a=this._comparator;for(;d&&d!==o;){let c=a(r,d.key);if(c===0)return d;d=c<0?d._left:d._right}}search(e,t=!1,n=this._DEFAULT_NODE_CALLBACK,r=this._root,s=this.iterationType){if(e===void 0)return[];if(e===null)return[];if(r=this.ensureNode(r),!r)return[];let o=this.isRange(e),d=!o&&this._isPredicate(e);if(!o&&!d){let c;if(this.isNode(e))c=e.key;else if(this.isEntry(e)){let T=e[0];T!=null&&(c=T)}else c=e;if(c===void 0)return[];let g=this._NIL,p=this._comparator,b=r;for(;b&&b!==g;){let T=p(c,b.key);if(T===0)return[n(b)];b=T<0?b._left:b._right}return[]}let a;o?a=c=>c?e.isInRange(c.key,this._comparator):!1:a=this._ensurePredicate(e);let l=c=>{if(!c||!this.isRealNode(c.left))return!1;if(o){let g=e,p=g.low,b=g.includeLow;return b&&this._compare(c.key,p)>=0||!b&&this._compare(c.key,p)>0}if(!o&&!this._isPredicate(e)){let g=this._extractKey(e);return g!=null&&this._compare(c.key,g)>0}return!0},f=c=>{if(!c||!this.isRealNode(c.right))return!1;if(o){let g=e,p=g.high,b=g.includeHigh;return b&&this._compare(c.key,p)<=0||!b&&this._compare(c.key,p)<0}if(!o&&!this._isPredicate(e)){let g=this._extractKey(e);return g!=null&&this._compare(c.key,g)<0}return!0};return super._dfs(n,"IN",t,r,s,!1,l,f,()=>!0,c=>!!c&&a(c))}rangeSearch(e,t=this._DEFAULT_NODE_CALLBACK,n=this._root,r=this.iterationType){let s=e instanceof H?e:new H(e[0],e[1]);return this.search(s,!1,t,n,r)}set(e,t){let[n]=this._keyValueNodeOrEntryToNodeAndValue(e,t);if(n===void 0)return!1;if(this._root===void 0)return this._setRoot(n),this._isMapMode&&this.isRealNode(n)&&this._store.set(n.key,n),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.isRealNode(n)&&this._store.set(r.key,n),!0;if(this._compare(r.key,n.key)>0){if(r.left===void 0)return r.left=n,this._isMapMode&&this.isRealNode(n)&&this._store.set(n.key,n),this._size++,!0;r.left!==null&&(r=r.left)}else{if(r.right===void 0)return r.right=n,this._isMapMode&&this.isRealNode(n)&&this._store.set(n.key,n),this._size++,!0;r.right!==null&&(r=r.right)}}return!1}setMany(e,t,n=!0,r=this.iterationType){let s=[],o=t==null?void 0:t[Symbol.iterator]();if(!n){for(let g of e){let p=o==null?void 0:o.next().value;this.isRaw(g)&&(g=this._toEntryFn(g)),s.push(this.set(g,p))}return s}let d=[],a=0;for(let g of e)d.push({key:g,value:o==null?void 0:o.next().value,orgIndex:a++});let l=d.sort(({key:g},{key:p})=>{let b,T;return this.isRaw(g)?b=this._toEntryFn(g)[0]:this.isEntry(g)?b=g[0]:this.isRealNode(g)?b=g.key:b=g,this.isRaw(p)?T=this._toEntryFn(p)[0]:this.isEntry(p)?T=p[0]:this.isRealNode(p)?T=p.key:T=p,b!=null&&T!=null?this._compare(b,T):0}),f=g=>{if(g.length===0)return;let p=Math.floor((g.length-1)/2),{key:b,value:T,orgIndex:E}=g[p];if(this.isRaw(b)){let y=this._toEntryFn(b);s[E]=this.set(y)}else s[E]=this.set(b,T);f(g.slice(0,p)),f(g.slice(p+1))};return r==="RECURSIVE"?f(l):(()=>{let p=[[0,l.length-1]];for(;p.length>0;){let b=p.pop();if(!b)continue;let[T,E]=b;if(T>E)continue;let y=T+Math.floor((E-T)/2),{key:m,value:N,orgIndex:K}=l[y];if(this.isRaw(m)){let V=this._toEntryFn(m);s[K]=this.set(V)}else s[K]=this.set(m,N);p.push([y+1,E]),p.push([T,y-1])}})(),s}ceiling(e,t=this._DEFAULT_NODE_CALLBACK,n){let r,s=this.iterationType;typeof t=="string"?s=t:t&&(r=t,n&&(s=n));let o=this._bound(e,!0,s);return r?o?r(o):void 0:o==null?void 0:o.key}higher(e,t=this._DEFAULT_NODE_CALLBACK,n){let r,s=this.iterationType;typeof t=="string"?s=t:t&&(r=t,n&&(s=n));let o=this._bound(e,!1,s);return r?o?r(o):void 0:o==null?void 0:o.key}floor(e,t=this._DEFAULT_NODE_CALLBACK,n){if(e==null)return void 0;let r,s=this.iterationType;if(typeof t=="string"?s=t:t&&(r=t,n&&(s=n)),this._isPredicate(e)){let d=this._floorByPredicate(e,s);return r?d?r(d):void 0:d==null?void 0:d.key}let o;if(this.isNode(e))o=e.key;else if(this.isEntry(e)){let d=e[0];if(d==null)return void 0;o=d}else o=e;if(o!==void 0){let d=this._floorByKey(o,s);return r?d?r(d):void 0:d==null?void 0:d.key}}lower(e,t,n){if(e==null)return void 0;let r,s=this.iterationType;if(typeof t=="string"?s=t:t&&(r=t,n&&(s=n)),this._isPredicate(e)){let d=this._lowerByPredicate(e,s);return r?d?r(d):void 0:d==null?void 0:d.key}let o;if(this.isNode(e))o=e.key;else if(this.isEntry(e)){let d=e[0];if(d==null)return void 0;o=d}else o=e;if(o!==void 0){let d=this._lowerByKey(o,s);return r?d?r(d):void 0:d==null?void 0:d.key}}lesserOrGreaterTraverse(e=this._DEFAULT_NODE_CALLBACK,t=-1,n=this._root,r=this.iterationType){let s=this.ensureNode(n),o=[];if(!this._root||!s)return o;let d=s.key;if(r==="RECURSIVE"){let a=l=>{let f=this._compare(l.key,d);Math.sign(f)==t&&o.push(e(l)),this.isRealNode(l.left)&&a(l.left),this.isRealNode(l.right)&&a(l.right)};return a(this._root),o}else{let a=new O([this._root]);for(;a.length>0;){let l=a.shift();if(this.isRealNode(l)){let f=this._compare(l.key,d);Math.sign(f)==t&&o.push(e(l)),this.isRealNode(l.left)&&a.push(l.left),this.isRealNode(l.right)&&a.push(l.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 r=(o,d,a)=>{if(o>d)return;let l=o+(d-o>>1),f=t[l],c=r(o,l-1,f),g=r(l+1,d,f);return f.left=c,f.right=g,f.parent=a,f},s=r(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=r=>{if(!r)return 0;let s=n(r.left),o=n(r.right);return Math.abs(s-o)>1&&(t=!1),Math.max(s,o)+1};n(this._root)}else{let n=[],r=this._root,s,o=new Map;for(;n.length>0||r;)if(r)n.push(r),r.left!==null&&(r=r.left);else if(r=n[n.length-1],!r.right||s===r.right){if(r=n.pop(),r){let d=r.left?o.get(r.left):-1,a=r.right?o.get(r.right):-1;if(Math.abs(d-a)>1)return!1;o.set(r,1+Math.max(d,a)),s=r,r=void 0}}else r=r.right}return t}map(e,t,n){let r=this._createLike([],t),s=0;for(let[o,d]of this)r.set(e.call(n,d,o,s++,this));return r}deleteWhere(e,t=!1,n=this._root,r=this.iterationType){let s=this.search(e,t,d=>d,n,r),o=[];for(let d of s){let a=this.delete(d);o=o.concat(a)}return o}_createDefaultComparator(){return(e,t)=>{if(Q(e)&&Q(t))return e>t?1:e<t?-1:0;if(typeof e=="object"||typeof t=="object")throw TypeError("When comparing object type keys, a custom comparator must be provided in the constructor's options!");return 0}}_floorByKey(e,t){var n,r;if(t==="RECURSIVE"){let s=o=>{if(!this.isRealNode(o))return;if(this.comparator(o.key,e)<=0){let a=s(o.right);return a!=null?a:o}else return s(o.left)};return s(this.root)}else{let s=this.root,o;for(;this.isRealNode(s);)this.comparator(s.key,e)<=0?(o=s,s=(n=s.right)!=null?n:void 0):s=(r=s.left)!=null?r:void 0;return o}}_floorByPredicate(e,t){if(t==="RECURSIVE"){let n,r=s=>{this.isRealNode(s)&&(this.isRealNode(s.left)&&r(s.left),e(s)&&(n=s),this.isRealNode(s.right)&&r(s.right))};return r(this.root),n}else{let n=[],r=this.root,s;for(;n.length>0||this.isRealNode(r);)if(this.isRealNode(r))n.push(r),r=r.left;else{let o=n.pop();if(!this.isRealNode(o))break;e(o)&&(s=o),r=o.right}return s}}_lowerByKey(e,t){var n,r;if(t==="RECURSIVE"){let s=o=>{if(!this.isRealNode(o))return;if(this.comparator(o.key,e)<0){let a=s(o.right);return a!=null?a:o}else return s(o.left)};return s(this.root)}else{let s=this.root,o;for(;this.isRealNode(s);)this.comparator(s.key,e)<0?(o=s,s=(n=s.right)!=null?n:void 0):s=(r=s.left)!=null?r:void 0;return o}}_lowerByPredicate(e,t){if(t==="RECURSIVE"){let n,r=s=>{this.isRealNode(s)&&(this.isRealNode(s.left)&&r(s.left),e(s)&&(n=s),this.isRealNode(s.right)&&r(s.right))};return r(this.root),n}else{let n=[],r=this.root,s;for(;n.length>0||this.isRealNode(r);)if(this.isRealNode(r))n.push(r),r=r.left;else{let o=n.pop();if(!this.isRealNode(o))break;e(o)&&(s=o),r=o.right}return s}}_bound(e,t,n){if(e==null)return;if(this._isPredicate(e))return this._boundByPredicate(e,n);let r;if(this.isNode(e))r=e.key;else if(this.isEntry(e)){let s=e[0];if(s==null)return;r=s}else r=e;if(r!==void 0)return this._boundByKey(r,t,n)}_boundByKey(e,t,n){var r,s;if(n==="RECURSIVE"){let o=d=>{if(!this.isRealNode(d))return;let a=this.comparator(d.key,e);if(t?a>=0:a>0){let f=o(d.left);return f!=null?f:d}else return o(d.right)};return o(this.root)}else{let o=this.root,d;for(;this.isRealNode(o);){let a=this.comparator(o.key,e);(t?a>=0:a>0)?(d=o,o=(r=o.left)!=null?r:void 0):o=(s=o.right)!=null?s:void 0}return d}}_boundByPredicate(e,t){if(t==="RECURSIVE"){let n,r=s=>{n||!this.isRealNode(s)||(this.isRealNode(s.left)&&r(s.left),!n&&e(s)&&(n=s),!n&&this.isRealNode(s.right)&&r(s.right))};return r(this.root),n}else{let n=[],r=this.root;for(;n.length>0||this.isRealNode(r);)if(this.isRealNode(r))n.push(r),r=r.left;else{let s=n.pop();if(!this.isRealNode(s))break;if(e(s))return s;r=s.right}return}}_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(),comparator:this._comparator}}_keyValueNodeOrEntryToNodeAndValue(e,t){let[n,r]=super._keyValueNodeOrEntryToNodeAndValue(e,t);return n===null?[void 0,void 0]:[n,t!=null?t:r]}_setRoot(e){e&&(e.parent=void 0),this._root=e}_compare(e,t){return this._comparator(e,t)}_deleteByKey(e){let t=this._root;for(;t;){let s=this._compare(t.key,e);if(s===0)break;t=s>0?t.left:t.right}if(!t)return!1;let n=(s,o)=>{let d=s==null?void 0:s.parent;d?d.left===s?d.left=o:d.right=o:this._setRoot(o),o&&(o.parent=d)},r=s=>{if(s){for(;s.left!==void 0&&s.left!==null;)s=s.left;return s}};if(t.left===void 0)n(t,t.right);else if(t.right===void 0)n(t,t.left);else{let s=r(t.right);s.parent!==t&&(n(s,s.right),s.right=t.right,s.right&&(s.right.parent=s)),n(t,s),s.left=t.left,s.left&&(s.left.parent=s)}return this._size=Math.max(0,this._size-1),!0}};var Ze=class{constructor({frequency:i=0,max:e}){u(this,"_freq");u(this,"_max");u(this,"_freqMap");u(this,"_msb");u(this,"_negativeCount");this._freq=i,this._max=e,this._freqMap={0:0},this._msb=De(e),this._negativeCount=i<0?e:0}get freqMap(){return this._freqMap}get msb(){return this._msb}get negativeCount(){return this._negativeCount}get freq(){return this._freq}get max(){return this._max}readSingle(i){return this._checkIndex(i),this._readSingle(i)}update(i,e){this._checkIndex(i);let t=this._readSingle(i);this._update(i,e),this._updateNegativeCount(t,t+e)}writeSingle(i,e){this._checkIndex(i),this._writeSingle(i,e)}read(i){if(!Number.isInteger(i))throw new Error("Invalid count");return this._read(Math.max(Math.min(i,this.max),0))}lowerBound(i){if(this.negativeCount>0)throw new Error("Sequence is not non-descending");return this._binarySearch(i,(e,t)=>e<t)}upperBound(i){if(this.negativeCount>0)throw new Error("Must not be descending");return this._binarySearch(i,(e,t)=>e<=t)}getPrefixSum(i){this._checkIndex(i),i++;let e=0;for(;i>0;)e+=this._getFrequency(i),i-=i&-i;return e}_getFrequency(i){return i in this.freqMap?this.freqMap[i]:this.freq*(i&-i)}_updateFrequency(i,e){this.freqMap[i]=this._getFrequency(i)+e}_checkIndex(i){if(!Number.isInteger(i))throw new Error("Invalid index: Index must be an integer.");if(i<0||i>=this.max)throw new Error("Index out of range: Index must be within the range [0, this.max).")}_readSingle(i){i=i+1;let e=this._getFrequency(i),t=i-(i&-i);for(i--;i!==t;)e-=this._getFrequency(i),i-=i&-i;return e}_updateNegativeCount(i,e){i<0&&e>=0?this._negativeCount--:i>=0&&e<0&&this._negativeCount++}_update(i,e){for(i=i+1;i<=this.max;)this._updateFrequency(i,e),i+=i&-i}_writeSingle(i,e){let t=this._readSingle(i);this._update(i,e-t),this._updateNegativeCount(t,e)}_read(i){let e=i,t=0;for(;e;)t+=this._getFrequency(e),e-=e&-e;return t}_binarySearch(i,e){let t=0,n=this.msb<<1,r=i;for(;n>t+1;){let s=t+n>>1,o=this._getFrequency(s);s<=this.max&&e(o,r)?(r-=o,t=s):n=s}return t}};var de=class{constructor(i,e,t,n){u(this,"_start",0);u(this,"_end",0);u(this,"_value");u(this,"_sum",0);u(this,"_left");u(this,"_right");this._start=i,this._end=e,this._sum=t,this._value=n||void 0}get start(){return this._start}set start(i){this._start=i}get end(){return this._end}set end(i){this._end=i}get value(){return this._value}set value(i){this._value=i}get sum(){return this._sum}set sum(i){this._sum=i}get left(){return this._left}set left(i){this._left=i}get right(){return this._right}set right(i){this._right=i}},et=class{constructor(i,e,t){u(this,"_values",[]);u(this,"_start",0);u(this,"_end");u(this,"_root");e=e||0,t=t||i.length-1,this._values=i,this._start=e,this._end=t,i.length>0?this._root=this.build(e,t):(this._root=void 0,this._values=[])}get values(){return this._values}get start(){return this._start}get end(){return this._end}get root(){return this._root}build(i,e){if(i>e)return new de(i,e,0);if(i===e)return new de(i,e,this._values[i]);let t=i+Math.floor((e-i)/2),n=this.build(i,t),r=this.build(t+1,e),s=new de(i,e,n.sum+r.sum);return s.left=n,s.right=r,s}updateNode(i,e,t){let n=this.root||void 0;if(!n)return;let r=(s,o,d,a)=>{if(s.start===s.end&&s.start===o){s.sum=d,a!==void 0&&(s.value=a);return}let l=s.start+Math.floor((s.end-s.start)/2);o<=l?s.left&&r(s.left,o,d,a):s.right&&r(s.right,o,d,a),s.left&&s.right&&(s.sum=s.left.sum+s.right.sum)};r(n,i,e,t)}querySumByRange(i,e){let t=this.root||void 0;if(!t)return 0;if(i<0||e>=this.values.length||i>e)return NaN;let n=(r,s,o)=>{if(s<=r.start&&o>=r.end)return r.sum;let d=r.start+Math.floor((r.end-r.start)/2);if(o<=d)return r.left?n(r.left,s,o):NaN;if(s>d)return r.right?n(r.right,s,o):NaN;{let a=0,l=0;return r.left&&(a=n(r.left,s,d)),r.right&&(l=n(r.right,d+1,o)),a+l}};return n(t,i,e)}};var ye=class{constructor(i,e){u(this,"key");u(this,"value");u(this,"parent");u(this,"_left");u(this,"_right");u(this,"_height",0);u(this,"_color","BLACK");u(this,"_count",1);this.key=i,this.value=e}get left(){return this._left}set left(i){i&&(i.parent=this),this._left=i}get right(){return this._right}set right(i){i&&(i.parent=this),this._right=i}get height(){return this._height}set height(i){this._height=i}get color(){return this._color}set color(i){this._color=i}get count(){return this._count}set count(i){this._count=i}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"}},tt=class extends J{constructor(i=[],e){super([],e),i&&super.setMany(i)}createNode(i,e){return new ye(i,e)}isNode(i){return i instanceof ye}set(i,e){if(i===null)return!1;let t=super.set(i,e);return t&&this._balancePath(i),t}delete(i){let e=super.delete(i);for(let{needBalanced:t}of e)t&&this._balancePath(t);return e}perfectlyBalance(i=this.iterationType){let e=this.dfs(s=>s,"IN",!1,this._root,i),t=e.length;if(t===0)return!1;this._clearNodes();let n=(s,o,d)=>{if(s>o)return;let a=s+(o-s>>1),l=e[a];l.left=n(s,a-1,l),l.right=n(a+1,o,l),l.parent=d;let f=l.left?l.left.height:-1,c=l.right?l.right.height:-1;return l.height=Math.max(f,c)+1,l},r=n(0,t-1,void 0);return this._setRoot(r),this._size=t,!0}map(i,e,t){let n=this._createLike([],e),r=0;for(let[s,o]of this)n.set(i.call(t,o,s,r++,this));return n}_createInstance(i){let e=this.constructor;return new e([],{...this._snapshotOptions(),...i!=null?i:{}})}_createLike(i=[],e){let t=this.constructor;return new t(i,{...this._snapshotOptions(),...e!=null?e:{}})}_swapProperties(i,e){let t=this.ensureNode(i),n=this.ensureNode(e);if(t&&n){let{key:r,value:s,height:o}=n,d=this.createNode(r,s);return d&&(d.height=o,n.key=t.key,this._isMapMode||(n.value=t.value),n.height=t.height,t.key=d.key,this._isMapMode||(t.value=d.value),t.height=d.height),n}}_balanceFactor(i){let e=i.left?i.left.height:-1;return(i.right?i.right.height:-1)-e}_updateHeight(i){let e=i.left?i.left.height:-1,t=i.right?i.right.height:-1;i.height=1+Math.max(e,t)}_balanceLL(i){let e=i.parent,t=i.left;t!==null&&(i.parent=t),t&&t.right&&(t.right.parent=i),t&&(t.parent=e),i===this.root?t&&this._setRoot(t):(e==null?void 0:e.left)===i?e.left=t:e&&(e.right=t),t&&(i.left=t.right,t.right=i),this._updateHeight(i),t&&this._updateHeight(t)}_balanceLR(i){let e=i.parent,t=i.left,n;t&&(n=t.right),i&&n!==null&&(i.parent=n),t&&n!==null&&(t.parent=n),n&&(n.left&&t!==null&&(n.left.parent=t),n.right&&(n.right.parent=i),n.parent=e),i===this.root?n&&this._setRoot(n):e&&(e.left===i?e.left=n:e.right=n),n&&(i.left=n.right,t&&(t.right=n.left),n.left=t,n.right=i),this._updateHeight(i),t&&this._updateHeight(t),n&&this._updateHeight(n)}_balanceRR(i){let e=i.parent,t=i.right;t!==null&&(i.parent=t),t&&(t.left&&(t.left.parent=i),t.parent=e),i===this.root?t&&this._setRoot(t):e&&(e.left===i?e.left=t:e.right=t),t&&(i.right=t.left,t.left=i),this._updateHeight(i),t&&this._updateHeight(t)}_balanceRL(i){let e=i.parent,t=i.right,n;t&&(n=t.left),n!==null&&(i.parent=n),t&&n!==null&&(t.parent=n),n&&(n.left&&(n.left.parent=i),n.right&&t!==null&&(n.right.parent=t),n.parent=e),i===this.root?n&&this._setRoot(n):e&&(e.left===i?e.left=n:e.right=n),n&&(i.right=n.left),t&&n&&(t.left=n.right),n&&(n.left=i),n&&(n.right=t),this._updateHeight(i),t&&this._updateHeight(t),n&&this._updateHeight(n)}_balancePath(i){i=this.ensureNode(i);let e=this.getPathToRoot(i,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(i,e){return e.height=i.height,super._replaceNode(i,e)}};var G=class{constructor(i,e,t="BLACK"){u(this,"key");u(this,"value");u(this,"parent");u(this,"_left");u(this,"_right");u(this,"_height",0);u(this,"_color","BLACK");u(this,"_count",1);this.key=i,this.value=e,this.color=t}get left(){return this._left}set left(i){i&&(i.parent=this),this._left=i}get right(){return this._right}set right(i){i&&(i.parent=this),this._right=i}get height(){return this._height}set height(i){this._height=i}get color(){return this._color}set color(i){this._color=i}get count(){return this._count}set count(i){this._count=i}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"}},A=class extends J{constructor(e=[],t){super([],t);u(this,"_root");u(this,"_header");u(this,"_minNode");u(this,"_maxNode");this._root=this.NIL,this._header=new G(void 0,void 0,"BLACK"),this._header.parent=this.NIL,this._header._left=this.NIL,this._header._right=this.NIL,e&&this.setMany(e)}get root(){return this._root}createNode(e,t,n="BLACK"){return new G(e,t,n)}isNode(e){return e instanceof G}clear(){super.clear(),this._root=this.NIL,this._header.parent=this.NIL,this._setMinCache(void 0),this._setMaxCache(void 0)}_findNodeByKey(e){var s,o,d;let t=this.NIL,n=this._compare.bind(this),r=(s=this._header.parent)!=null?s:t;for(;r!==t;){let a=n(e,r.key);if(a<0)r=(o=r.left)!=null?o:t;else if(a>0)r=(d=r.right)!=null?d:t;else return r}}_predecessorOf(e){let t=this.NIL;if(e.left&&e.left!==t){let s=e.left;for(;s.right&&s.right!==t;)s=s.right;return s}let n=e,r=e.parent;for(;r&&n===r.left;)n=r,r=r.parent;return r}_successorOf(e){let t=this.NIL;if(e.right&&e.right!==t){let s=e.right;for(;s.left&&s.left!==t;)s=s.left;return s}let n=e,r=e.parent;for(;r&&n===r.right;)n=r,r=r.parent;return r}_attachNewNode(e,t,n){let r=this.NIL;n.parent=e,t==="left"?e.left=n:e.right=n,n.left=r,n.right=r,n.color="RED",this._insertFixup(n),this.isRealNode(this._root)&&(this._root.color="BLACK")}_setMinCache(e){this._minNode=e,this._header._left=e!=null?e:this.NIL}_setMaxCache(e){this._maxNode=e,this._header._right=e!=null?e:this.NIL}_setKVNode(e,t){var E,y,m,N,K,V,R;let n=this.NIL,r=this._comparator,s=this._header,o=(E=s._left)!=null?E:n;if(o!==n){let k=r(e,o.key);if(k===0)return o.value=t,this._isMapMode&&this._store.set(e,o),{node:o,created:!1};let I=o.left;if(k<0&&(I===n||I===null||I===void 0)){let v=this.createNode(e,t);return this._attachNewNode(o,"left",v),this._isMapMode&&this._store.set(v.key,v),this._size++,this._setMinCache(v),s._right===n&&this._setMaxCache(v),{node:v,created:!0}}if(k>0){let v=(y=s._right)!=null?y:n,ft=r(e,v.key);if(ft===0)return v.value=t,this._isMapMode&&this._store.set(e,v),{node:v,created:!1};let Se=v.right;if(ft>0&&(Se===n||Se===null||Se===void 0)){let te=this.createNode(e,t);return this._attachNewNode(v,"right",te),this._isMapMode&&this._store.set(te.key,te),this._size++,this._setMaxCache(te),s._left===n&&this._setMinCache(te),{node:te,created:!0}}}}let d=r,a=this._isMapMode,l=this._store,f=(m=this._header.parent)!=null?m:n,c,g=0;for(;f!==n;)if(c=f,g=d(e,f.key),g<0)f=(N=f.left)!=null?N:n;else if(g>0)f=(K=f.right)!=null?K:n;else return f.value=t,a&&l.set(e,f),{node:f,created:!1};let p=this.createNode(e,t);if(p.parent=c,c?g<0?c.left=p:c.right=p:this._setRoot(p),p.left=n,p.right=n,p.color="RED",this._insertFixup(p),this.isRealNode(this._root))this._root.color="BLACK";else return;a&&l.set(p.key,p),this._size++;let b=(V=this._header._left)!=null?V:n,T=(R=this._header._right)!=null?R:n;return b===n||T===n?(this._setMinCache(p),this._setMaxCache(p)):c===T&&g>0?this._setMaxCache(p):c===b&&g<0?this._setMinCache(p):(d(p.key,b.key)<0&&this._setMinCache(p),d(p.key,T.key)>0&&this._setMaxCache(p)),{node:p,created:!0}}_setKV(e,t){if(this._isMapMode){let r=this._store.get(e);if(r)return r.value=t,!0}return this._setKVNode(e,t)!==void 0}setWithHintNode(e,t,n){var d,a,l,f,c,g,p,b,T,E,y,m,N;if(!n||!this.isRealNode(n))return(d=this._setKVNode(e,t))==null?void 0:d.node;let r=this._compare.bind(this),s=r(e,n.key);if(s===0)return n.value=t,this._isMapMode&&this._store.set(e,n),n;if(s<0){if(!this.isRealNode(n.left)){let V=this.createNode(e,t);if(!this.isRealNode(V))return;this._attachNewNode(n,"left",V),this._isMapMode&&this._store.set(e,V),this._size++;let R=this.NIL,k=(a=this._header._left)!=null?a:R;(k===R||this._compare(V.key,k.key)<0)&&this._setMinCache(V);let I=(l=this._header._right)!=null?l:R;return(I===R||this._compare(V.key,I.key)>0)&&this._setMaxCache(V),V}let K=this._predecessorOf(n);if(K&&r(K.key,e)>=0)return(f=this._setKVNode(e,t))==null?void 0:f.node;if(K&&!this.isRealNode(K.right)){let V=this.createNode(e,t);if(!this.isRealNode(V))return;this._attachNewNode(K,"right",V),this._isMapMode&&this._store.set(e,V),this._size++;let R=this.NIL,k=(c=this._header._left)!=null?c:R;(k===R||this._compare(V.key,k.key)<0)&&this._setMinCache(V);let I=(g=this._header._right)!=null?g:R;return(I===R||this._compare(V.key,I.key)>0)&&this._setMaxCache(V),V}return(p=this._setKVNode(e,t))==null?void 0:p.node}if(!this.isRealNode(n.right)){let K=this.createNode(e,t);if(!this.isRealNode(K))return;this._attachNewNode(n,"right",K),this._isMapMode&&this._store.set(e,K),this._size++;let V=this.NIL,R=(b=this._header._left)!=null?b:V;(R===V||this._compare(K.key,R.key)<0)&&this._setMinCache(K);let k=(T=this._header._right)!=null?T:V;return(k===V||this._compare(K.key,k.key)>0)&&this._setMaxCache(K),K}let o=this._successorOf(n);if(o&&r(o.key,e)<=0)return(E=this._setKVNode(e,t))==null?void 0:E.node;if(o&&!this.isRealNode(o.left)){let K=this.createNode(e,t);if(!this.isRealNode(K))return;this._attachNewNode(o,"left",K),this._isMapMode&&this._store.set(e,K),this._size++;let V=this.NIL,R=(y=this._header._left)!=null?y:V;(R===V||this._compare(K.key,R.key)<0)&&this._setMinCache(K);let k=(m=this._header._right)!=null?m:V;return(k===V||this._compare(K.key,k.key)>0)&&this._setMaxCache(K),K}return(N=this._setKVNode(e,t))==null?void 0:N.node}setWithHint(e,t,n){return this.setWithHintNode(e,t,n)!==void 0}set(e,t){if(!this.isNode(e)){if(e==null)return!1;if(this.isEntry(e)){let o=e[0];if(o==null)return!1;let d=t!=null?t:e[1];return this._setKV(o,d)}return this._setKV(e,t)}let[n,r]=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;if(this._isMapMode){let o=this.getNode(n.key);this.isRealNode(o)&&(o.value=r,this._store.set(o.key,o))}return this._size++,!0}if(s==="UPDATED"){if(this._isMapMode){let o=this.getNode(n.key);this.isRealNode(o)&&(o.value=r,this._store.set(o.key,o))}return!0}return!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 r=n===this._minNode,s=n===this._maxNode,o=r?this._successorOf(n):void 0,d=s?this._predecessorOf(n):void 0,a=n.color,l;if(!this.isRealNode(n.left))n.right!==null&&(l=n.right,this._transplant(n,n.right));else if(!this.isRealNode(n.right))l=n.left,this._transplant(n,n.left);else{let f=this.getLeftMost(c=>c,n.right);f&&(a=f.color,f.right!==null&&(l=f.right),f.parent===n?this.isRealNode(l)&&(l.parent=f):(f.right!==null&&(this._transplant(f,f.right),f.right=n.right),this.isRealNode(f.right)&&(f.right.parent=f)),this._transplant(n,f),f.left=n.left,this.isRealNode(f.left)&&(f.left.parent=f),f.color=n.color)}return this._isMapMode&&this._store.delete(n.key),this._size--,this._size<=0?(this._setMinCache(void 0),this._setMaxCache(void 0)):(r&&this._setMinCache(o),s&&this._setMaxCache(d),(!this._minNode||!this.isRealNode(this._minNode))&&this._setMinCache(this.isRealNode(this._root)?this.getLeftMost(f=>f,this._root):void 0),(!this._maxNode||!this.isRealNode(this._maxNode))&&this._setMaxCache(this.isRealNode(this._root)?this.getRightMost(f=>f,this._root):void 0)),a==="BLACK"&&this._deleteFixup(l),t.push({deleted:n,needBalanced:void 0}),t}map(e,t,n){let r=this._createLike([],t),s=0;for(let[o,d]of this)r.set(e.call(n,d,o,s++,this));return r}_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){let t=this.NIL;e&&(e.parent=void 0),this._root=e,this._header.parent=e!=null?e:t}_replaceNode(e,t){return t.color=e.color,super._replaceNode(e,t)}_insert(e){var d,a,l;let t=this.NIL,n=this._compare.bind(this),r=(d=this._header.parent)!=null?d:t,s,o=0;for(;r!==t;)if(s=r,o=n(e.key,r.key),o<0)r=(a=r.left)!=null?a:t;else if(o>0)r=(l=r.right)!=null?l:t;else return this._replaceNode(r,e),"UPDATED";return e.parent=s,s?o<0?s.left=e:s.right=e:this._setRoot(e),e.left=t,e.right=t,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){let t=this._leftRotate.bind(this),n=this._rightRotate.bind(this);for(;e;){let r=e.parent;if(!r||r.color!=="RED")break;let s=r.parent;if(!s)break;if(r===s.left){let o=s.right;if((o==null?void 0:o.color)==="RED"){r.color="BLACK",o.color="BLACK",s.color="RED",e=s;continue}e===r.right&&(e=r,t(e));let d=e==null?void 0:e.parent,a=d==null?void 0:d.parent;d&&a&&(d.color="BLACK",a.color="RED",n(a))}else{let o=s.left;if((o==null?void 0:o.color)==="RED"){r.color="BLACK",o.color="BLACK",s.color="RED",e=s;continue}e===r.left&&(e=r,n(e));let d=e==null?void 0:e.parent,a=d==null?void 0:d.parent;d&&a&&(d.color="BLACK",a.color="RED",t(a))}break}this.isRealNode(this._root)&&(this._root.color="BLACK")}_deleteFixup(e){var t,n,r,s;if(!e||e===this.root||e.color==="BLACK"){e&&(e.color="BLACK");return}for(;e&&e!==this.root&&e.color==="BLACK";){let o=e.parent;if(!o)break;if(e===o.left){let d=o.right;(d==null?void 0:d.color)==="RED"&&(d.color="BLACK",o.color="RED",this._leftRotate(o),d=o.right),((n=(t=d==null?void 0:d.left)==null?void 0:t.color)!=null?n:"BLACK")==="BLACK"?(d&&(d.color="RED"),e=o):(d!=null&&d.left&&(d.left.color="BLACK"),d&&(d.color=o.color),o.color="BLACK",this._rightRotate(o),e=this.root)}else{let d=o.left;(d==null?void 0:d.color)==="RED"&&(d.color="BLACK",o&&(o.color="RED"),this._rightRotate(o),o&&(d=o.left)),((s=(r=d==null?void 0:d.right)==null?void 0:r.color)!=null?s:"BLACK")==="BLACK"?(d&&(d.color="RED"),e=o):(d!=null&&d.right&&(d.right.color="BLACK"),d&&(d.color=o.color),o&&(o.color="BLACK"),this._leftRotate(o),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 B,le,ue,ae=class ae{constructor(i=[],e={}){C(this,B);C(this,le);C(this,ue);var r;S(this,ue,e.comparator);let t=e.toElementFn,n=(r=e.comparator)!=null?r:ae.createDefaultComparator();S(this,le,e.comparator===void 0),S(this,B,new A([],{comparator:n,isMapMode:e.isMapMode}));for(let s of i){let o=t?t(s):s;this.add(o)}}static createDefaultComparator(){return(i,e)=>{if(typeof i=="number"&&typeof e=="number"){if(Number.isNaN(i)||Number.isNaN(e))throw new TypeError("TreeSet: NaN is not a valid key");let t=Object.is(i,-0)?0:i,n=Object.is(e,-0)?0:e;return t>n?1:t<n?-1:0}if(typeof i=="string"&&typeof e=="string")return i>e?1:i<e?-1:0;if(i instanceof Date&&e instanceof Date){let t=i.getTime(),n=e.getTime();if(Number.isNaN(t)||Number.isNaN(n))throw new TypeError("TreeSet: invalid Date key");return t>n?1:t<n?-1:0}throw new TypeError("TreeSet: comparator is required for non-number/non-string/non-Date keys")}}get size(){return _(this,B).size}isEmpty(){return this.size===0}_validateKey(i){if(_(this,le)){if(typeof i=="number"){if(Number.isNaN(i))throw new TypeError("TreeSet: NaN is not a valid key");return}if(typeof i!="string"){if(i instanceof Date){if(Number.isNaN(i.getTime()))throw new TypeError("TreeSet: invalid Date key");return}throw new TypeError("TreeSet: comparator is required for non-number/non-string/non-Date keys")}}}add(i){return this._validateKey(i),_(this,B).set(i,void 0),this}has(i){return this._validateKey(i),_(this,B).has(i)}delete(i){var t;this._validateKey(i);let e=_(this,B).delete(i);return Array.isArray(e)&&e.length>0&&!!((t=e[0])!=null&&t.deleted)}clear(){_(this,B).clear()}keys(){return _(this,B).keys()}values(){return this.keys()}*entries(){for(let i of this.keys())yield[i,i]}[Symbol.iterator](){return this.keys()}forEach(i,e){for(let t of this)i.call(e,t,t,this)}map(i,e={},t){let n=new ae([],e),r=0;for(let s of this){let o=t===void 0?i(s,r++,this):i.call(t,s,r++,this);n.add(o)}return n}filter(i,e){let t=new ae([],{comparator:_(this,ue)}),n=0;for(let r of this)(e===void 0?i(r,n++,this):i.call(e,r,n++,this))&&t.add(r);return t}reduce(i,e){let t=e,n=0;for(let r of this)t=i(t,r,n++,this);return t}every(i,e){let t=0;for(let n of this)if(!(e===void 0?i(n,t++,this):i.call(e,n,t++,this)))return!1;return!0}some(i,e){let t=0;for(let n of this)if(e===void 0?i(n,t++,this):i.call(e,n,t++,this))return!0;return!1}find(i,e){let t=0;for(let n of this)if(e===void 0?i(n,t++,this):i.call(e,n,t++,this))return n}toArray(){return[...this]}print(){_(this,B).print()}first(){return _(this,B).getLeftMost()}last(){return _(this,B).getRightMost()}pollFirst(){let i=this.first();if(i!==void 0)return this.delete(i),i}pollLast(){let i=this.last();if(i!==void 0)return this.delete(i),i}ceiling(i){return this._validateKey(i),_(this,B).ceiling(i)}floor(i){return this._validateKey(i),_(this,B).floor(i)}higher(i){return this._validateKey(i),_(this,B).higher(i)}lower(i){return this._validateKey(i),_(this,B).lower(i)}rangeSearch(i,e={}){let{lowInclusive:t=!0,highInclusive:n=!0}=e,[r,s]=i;this._validateKey(r),this._validateKey(s);let o=_(this,B).rangeSearch([r,s]),d=[],a=_(this,B).comparator;for(let l of o)l!==void 0&&(!t&&a(l,r)===0||!n&&a(l,s)===0||d.push(l));return d}clone(){return new ae(this,{comparator:_(this,le)?void 0:_(this,ue),isMapMode:_(this,B).isMapMode})}};B=new WeakMap,le=new WeakMap,ue=new WeakMap;var Y=ae;var nt=class extends G{constructor(i,e=[]){super(i,e)}},M,Ee,Te=class Te{constructor(i=[],e={}){C(this,M);C(this,Ee);var r;let t=(r=e.comparator)!=null?r:Y.createDefaultComparator();S(this,Ee,e.comparator===void 0);let n=e.toEntryFn;S(this,M,new A([],{...e,comparator:t,isMapMode:e.isMapMode}));for(let s of i)if(s!=null){if(n){let[o,d]=n(s);if(o==null)continue;d!==void 0?_(this,M).set(o,Array.isArray(d)?[...d]:[d]):_(this,M).set(o,[]);continue}if(Array.isArray(s)){let[o,d]=s;if(o==null)continue;d!==void 0?_(this,M).set(o,[...d]):_(this,M).set(o,[]);continue}_(this,M).set(s,[])}}_validateKey(i){if(_(this,Ee)){if(typeof i=="number"){if(Number.isNaN(i))throw new TypeError("TreeMultiMap: NaN is not a valid key");return}if(typeof i!="string"){if(i instanceof Date){if(Number.isNaN(i.getTime()))throw new TypeError("TreeMultiMap: invalid Date key");return}throw new TypeError("TreeMultiMap: comparator is required for non-number/non-string/non-Date keys")}}}get size(){return _(this,M).size}isEmpty(){return this.size===0}clear(){_(this,M).clear()}count(i){let e=this.get(i);return Array.isArray(e)?e.length:0}get totalSize(){let i=0;for(let[,e]of this)i+=e.length;return i}has(i){return this._validateKey(i),_(this,M).has(i)}get(i){return this._validateKey(i),_(this,M).get(i)}add(i,e){this._validateKey(i);let t=_(this,M).get(i);return t?(t.push(e),!0):_(this,M).set(i,[e])}set(i,e){if(i==null)return!1;if(Array.isArray(i)){let[t,n]=i;if(t==null)return!1;if(e!==void 0)return this.add(t,e);if(n===void 0)return _(this,M).set(t,[]);let r=_(this,M).get(t);return r?(r.push(...n),!0):_(this,M).set(t,[...n])}return e!==void 0?this.add(i,e):_(this,M).set(i,[])}delete(i){return this._validateKey(i),_(this,M).delete(i).length>0}hasEntry(i,e,t=Object.is){let n=this.get(i);return Array.isArray(n)?n.some(r=>t(r,e)):!1}deleteValue(i,e,t=Object.is){let n=this.get(i);if(!Array.isArray(n))return!1;let r=n.findIndex(s=>t(s,e));return r===-1?!1:(n.splice(r,1),n.length===0&&this.delete(i),!0)}deleteValues(i,e,t=Object.is){let n=this.get(i);if(!Array.isArray(n)||n.length===0)return 0;let r=0;for(let s=n.length-1;s>=0;s--)t(n[s],e)&&(n.splice(s,1),r++);return n.length===0&&r>0&&this.delete(i),r}*[Symbol.iterator](){for(let[i,e]of _(this,M))yield[i,e!=null?e:[]]}*keys(){yield*_(this,M).keys()}*values(){for(let[,i]of this)yield i}*entriesOf(i){let e=this.get(i);if(Array.isArray(e))for(let t of e)yield[i,t]}*valuesOf(i){let e=this.get(i);Array.isArray(e)&&(yield*e)}*flatEntries(){for(let[i,e]of this)for(let t of e)yield[i,t]}first(){let i=_(this,M).getLeftMost();if(i===void 0)return;let e=this.get(i);return e===void 0?void 0:[i,e]}last(){let i=_(this,M).getRightMost();if(i===void 0)return;let e=this.get(i);return e===void 0?void 0:[i,e]}pollFirst(){let i=this.first();if(i)return this.delete(i[0]),i}pollLast(){let i=this.last();if(i)return this.delete(i[0]),i}ceiling(i){this._validateKey(i);let e=_(this,M).ceiling(i);if(e===void 0)return;let t=this.get(e);return t===void 0?void 0:[e,t]}floor(i){this._validateKey(i);let e=_(this,M).floor(i);if(e===void 0)return;let t=this.get(e);return t===void 0?void 0:[e,t]}higher(i){this._validateKey(i);let e=_(this,M).higher(i);if(e===void 0)return;let t=this.get(e);return t===void 0?void 0:[e,t]}lower(i){this._validateKey(i);let e=_(this,M).lower(i);if(e===void 0)return;let t=this.get(e);return t===void 0?void 0:[e,t]}print(){_(this,M).print()}forEach(i){for(let[e,t]of this)i(t,e,this)}filter(i){let e=[];for(let[t,n]of this)i(n,t,this)&&e.push([t,n]);return new Te(e,{comparator:this.comparator})}map(i){let e=[];for(let[t,n]of this)e.push(i(n,t,this));return new Te(e,{comparator:this.comparator})}reduce(i,e){let t=e;for(let[n,r]of this)t=i(t,r,n,this);return t}setMany(i){let e=[];for(let t of i)e.push(this.set(t));return e}rangeSearch(i,e){return _(this,M).rangeSearch(i,e)}clone(){return new Te(this,{comparator:this.comparator,isMapMode:_(this,M).isMapMode})}get comparator(){return _(this,M).comparator}};M=new WeakMap,Ee=new WeakMap;var it=Te;var L,fe,ce,he=class he{constructor(i=[],e={}){C(this,L);C(this,fe);C(this,ce);var r;S(this,ce,e.comparator);let t=e.toEntryFn,n=(r=e.comparator)!=null?r:he.createDefaultComparator();S(this,fe,e.comparator===void 0),S(this,L,new A([],{comparator:n,isMapMode:e.isMapMode}));for(let s of i){let o,d;if(t)[o,d]=t(s);else{if(!Array.isArray(s)||s.length<2)throw new TypeError("TreeMap: each entry must be a [key, value] tuple");o=s[0],d=s[1]}this.set(o,d)}}static createDefaultComparator(){return(i,e)=>{if(typeof i=="number"&&typeof e=="number"){if(Number.isNaN(i)||Number.isNaN(e))throw new TypeError("TreeMap: NaN is not a valid key");let t=Object.is(i,-0)?0:i,n=Object.is(e,-0)?0:e;return t>n?1:t<n?-1:0}if(typeof i=="string"&&typeof e=="string")return i>e?1:i<e?-1:0;if(i instanceof Date&&e instanceof Date){let t=i.getTime(),n=e.getTime();if(Number.isNaN(t)||Number.isNaN(n))throw new TypeError("TreeMap: invalid Date key");return t>n?1:t<n?-1:0}throw new TypeError("TreeMap: comparator is required for non-number/non-string/non-Date keys")}}_validateKey(i){if(_(this,fe)){if(typeof i=="number"){if(Number.isNaN(i))throw new TypeError("TreeMap: NaN is not a valid key");return}if(typeof i!="string"){if(i instanceof Date){if(Number.isNaN(i.getTime()))throw new TypeError("TreeMap: invalid Date key");return}throw new TypeError("TreeMap: comparator is required for non-number/non-string/non-Date keys")}}}get size(){return _(this,L).size}isEmpty(){return this.size===0}set(i,e){return this._validateKey(i),_(this,L).set(i,e),this}get(i){return this._validateKey(i),_(this,L).get(i)}has(i){return this._validateKey(i),_(this,L).has(i)}delete(i){var t;this._validateKey(i);let e=_(this,L).delete(i);return Array.isArray(e)&&e.length>0&&!!((t=e[0])!=null&&t.deleted)}clear(){_(this,L).clear()}keys(){return _(this,L).keys()}_entryFromKey(i){return[i,_(this,L).get(i)]}*values(){for(let i of this.keys())yield this._entryFromKey(i)[1]}*entries(){for(let i of this.keys())yield this._entryFromKey(i)}[Symbol.iterator](){return this.entries()}forEach(i,e){for(let[t,n]of this)i.call(e,n,t,this)}map(i,e={},t){let n=new he([],e),r=0;for(let[s,o]of this){let[d,a]=t===void 0?i(o,s,r++,this):i.call(t,o,s,r++,this);n.set(d,a)}return n}filter(i,e){let t=new he([],{comparator:_(this,ce)}),n=0;for(let[r,s]of this)(e===void 0?i(s,r,n++,this):i.call(e,s,r,n++,this))&&t.set(r,s);return t}reduce(i,e){let t=e,n=0;for(let[r,s]of this)t=i(t,s,r,n++,this);return t}every(i,e){let t=0;for(let[n,r]of this)if(!(e===void 0?i(r,n,t++,this):i.call(e,r,n,t++,this)))return!1;return!0}some(i,e){let t=0;for(let[n,r]of this)if(e===void 0?i(r,n,t++,this):i.call(e,r,n,t++,this))return!0;return!1}find(i,e){let t=0;for(let[n,r]of this)if(e===void 0?i(r,n,t++,this):i.call(e,r,n,t++,this))return[n,r]}toArray(){return[...this]}print(){_(this,L).print()}first(){let i=_(this,L).getLeftMost();return i===void 0?void 0:this._entryFromKey(i)}last(){let i=_(this,L).getRightMost();return i===void 0?void 0:this._entryFromKey(i)}pollFirst(){let i=this.first();if(i)return this.delete(i[0]),i}pollLast(){let i=this.last();if(i)return this.delete(i[0]),i}ceiling(i){this._validateKey(i);let e=_(this,L).ceiling(i);return e===void 0?void 0:this._entryFromKey(e)}floor(i){this._validateKey(i);let e=_(this,L).floor(i);return e===void 0?void 0:this._entryFromKey(e)}higher(i){this._validateKey(i);let e=_(this,L).higher(i);return e===void 0?void 0:this._entryFromKey(e)}lower(i){this._validateKey(i);let e=_(this,L).lower(i);return e===void 0?void 0:this._entryFromKey(e)}rangeSearch(i,e={}){let{lowInclusive:t=!0,highInclusive:n=!0}=e,[r,s]=i;this._validateKey(r),this._validateKey(s);let o=_(this,L).rangeSearch([r,s]),d=[],a=_(this,L).comparator;for(let l of o)l!==void 0&&(!t&&a(l,r)===0||!n&&a(l,s)===0||d.push(this._entryFromKey(l)));return d}clone(){return new he(this,{comparator:_(this,fe)?void 0:_(this,ce),isMapMode:_(this,L).isMapMode})}};L=new WeakMap,fe=new WeakMap,ce=new WeakMap;var rt=he;var x,Z,Ne=class Ne{constructor(i=[],e={}){C(this,x);C(this,Z);u(this,"_size",0);var r;let t=e.toElementFn,n=(r=e.comparator)!=null?r:Y.createDefaultComparator();S(this,Z,e.comparator===void 0),S(this,x,new A([],{comparator:n,isMapMode:e.isMapMode}));for(let s of i){let o=t?t(s):s;this.add(o)}}_validateKey(i){if(_(this,Z)){if(typeof i=="number"){if(Number.isNaN(i))throw new TypeError("TreeMultiSet: NaN is not a valid key");return}if(typeof i!="string"){if(i instanceof Date){if(Number.isNaN(i.getTime()))throw new TypeError("TreeMultiSet: invalid Date key");return}throw new TypeError("TreeMultiSet: comparator is required for non-number/non-string/non-Date keys")}}}_validateCount(i){if(!Number.isSafeInteger(i)||i<0)throw new RangeError("TreeMultiSet: count must be a safe integer >= 0")}get size(){return this._size}get distinctSize(){return _(this,x).size}isEmpty(){return this.size===0}has(i){return this._validateKey(i),this.count(i)>0}count(i){var e;return this._validateKey(i),(e=_(this,x).get(i))!=null?e:0}add(i,e=1){var r;if(this._validateKey(i),this._validateCount(e),e===0)return!1;let n=((r=_(this,x).get(i))!=null?r:0)+e;return _(this,x).set(i,n),this._size+=e,!0}setCount(i,e){var n;this._validateKey(i),this._validateCount(e);let t=(n=_(this,x).get(i))!=null?n:0;return t===e?!1:(e===0?t!==0&&_(this,x).delete(i):_(this,x).set(i,e),this._size+=e-t,!0)}delete(i,e=1){var s;if(this._validateKey(i),this._validateCount(e),e===0)return!1;let t=(s=_(this,x).get(i))!=null?s:0;if(t===0)return!1;let n=Math.min(t,e),r=t-n;return r===0?_(this,x).delete(i):_(this,x).set(i,r),this._size-=n,!0}deleteAll(i){var t;this._validateKey(i);let e=(t=_(this,x).get(i))!=null?t:0;return e===0?!1:(_(this,x).delete(i),this._size-=e,!0)}*keysDistinct(){yield*_(this,x).keys()}*entries(){for(let[i,e]of _(this,x))yield[i,e!=null?e:0]}*[Symbol.iterator](){for(let[i,e]of this.entries())for(let t=0;t<e;t++)yield i}toArray(){return[...this]}toDistinctArray(){return[...this.keysDistinct()]}toEntries(){return[...this.entries()]}get comparator(){return _(this,x)._comparator}clear(){_(this,x).clear(),this._size=0}first(){return _(this,x).getLeftMost()}last(){return _(this,x).getRightMost()}pollFirst(){let i=this.first();if(i!==void 0)return this.deleteAll(i),i}pollLast(){let i=this.last();if(i!==void 0)return this.deleteAll(i),i}ceiling(i){return this._validateKey(i),_(this,x).ceiling(i)}floor(i){return this._validateKey(i),_(this,x).floor(i)}higher(i){return this._validateKey(i),_(this,x).higher(i)}lower(i){return this._validateKey(i),_(this,x).lower(i)}forEach(i){for(let[e,t]of this.entries())i(e,t)}filter(i){let e=new Ne([],{comparator:_(this,Z)?void 0:this.comparator,isMapMode:_(this,x)._isMapMode});for(let[t,n]of this.entries())i(t,n)&&e.add(t,n);return e}reduce(i,e){let t=e;for(let[n,r]of this.entries())t=i(t,n,r);return t}map(i,e){let t=new Ne([],{comparator:e==null?void 0:e.comparator,isMapMode:_(this,x)._isMapMode});for(let[n,r]of this.entries()){let[s,o]=i(n,r);t.add(s,o)}return t}clone(){let i=new Ne([],{comparator:_(this,Z)?void 0:this.comparator,isMapMode:_(this,x)._isMapMode});for(let[e,t]of this.entries())i.add(e,t);return i}rangeSearch(i,e){let t=e!=null?e:(n=>n);return _(this,x).rangeSearch(i,n=>t(n.key))}print(){_(this,x).print()}};x=new WeakMap,Z=new WeakMap;var st=Ne;var ee=class extends D{constructor(i=[],e){super(i,e)}};var ot=class extends ee{constructor(i=[],e){super(i,e)}};var dt=class extends ee{constructor(i=[],e){super(i,{comparator:(t,n)=>{if(typeof t=="object"||typeof n=="object")throw TypeError("When comparing object types, a custom comparator must be defined in the constructor's options parameter.");return t<n?1:t>n?-1:0},...e})}};var at=class h{constructor(i,e){u(this,"_rows",0);u(this,"_cols",0);u(this,"_data");var t,n,r;if(e){let{rows:s,cols:o,addFn:d,subtractFn:a,multiplyFn:l}=e;typeof s=="number"&&s>0?this._rows=s:this._rows=i.length,typeof o=="number"&&o>0?this._cols=o:this._cols=((t=i[0])==null?void 0:t.length)||0,d&&(this._addFn=d),a&&(this._subtractFn=a),l&&(this._multiplyFn=l)}else this._rows=i.length,this._cols=(r=(n=i[0])==null?void 0:n.length)!=null?r:0;if(i.length>0)this._data=i;else{this._data=[];for(let s=0;s<this.rows;s++)this._data[s]=new Array(this.cols).fill(0)}}get rows(){return this._rows}get cols(){return this._cols}get data(){return this._data}get addFn(){return this._addFn}get subtractFn(){return this._subtractFn}get multiplyFn(){return this._multiplyFn}get(i,e){if(this.isValidIndex(i,e))return this.data[i][e]}set(i,e,t){return this.isValidIndex(i,e)?(this.data[i][e]=t,!0):!1}isMatchForCalculate(i){return this.rows===i.rows&&this.cols===i.cols}add(i){if(!this.isMatchForCalculate(i))throw new Error("Matrix dimensions must match for addition.");let e=[];for(let t=0;t<this.rows;t++){e[t]=[];for(let n=0;n<this.cols;n++){let r=this.get(t,n),s=i.get(t,n);if(r!==void 0&&s!==void 0){let o=this._addFn(r,s);o&&(e[t][n]=o)}}}return new h(e,{rows:this.rows,cols:this.cols,addFn:this.addFn,subtractFn:this.subtractFn,multiplyFn:this.multiplyFn})}subtract(i){if(!this.isMatchForCalculate(i))throw new Error("Matrix dimensions must match for subtraction.");let e=[];for(let t=0;t<this.rows;t++){e[t]=[];for(let n=0;n<this.cols;n++){let r=this.get(t,n),s=i.get(t,n);if(r!==void 0&&s!==void 0){let o=this._subtractFn(r,s);o&&(e[t][n]=o)}}}return new h(e,{rows:this.rows,cols:this.cols,addFn:this.addFn,subtractFn:this.subtractFn,multiplyFn:this.multiplyFn})}multiply(i){if(this.cols!==i.rows)throw new Error("Matrix dimensions must be compatible for multiplication (A.cols = B.rows).");let e=[];for(let t=0;t<this.rows;t++){e[t]=[];for(let n=0;n<i.cols;n++){let r;for(let s=0;s<this.cols;s++){let o=this.get(t,s),d=i.get(s,n);if(o!==void 0&&d!==void 0){let a=this.multiplyFn(o,d);a!==void 0&&(r=this.addFn(r,a))}}r!==void 0&&(e[t][n]=r)}}return new h(e,{rows:this.rows,cols:i.cols,addFn:this.addFn,subtractFn:this.subtractFn,multiplyFn:this.multiplyFn})}transpose(){if(this.data.some(e=>e.length!==this.rows))throw new Error("Matrix must be rectangular for transposition.");let i=[];for(let e=0;e<this.cols;e++){i[e]=[];for(let t=0;t<this.rows;t++){let n=this.get(t,e);n!==void 0&&(i[e][t]=n)}}return new h(i,{rows:this.cols,cols:this.rows,addFn:this.addFn,subtractFn:this.subtractFn,multiplyFn:this.multiplyFn})}inverse(){var n;if(this.rows!==this.cols)throw new Error("Matrix must be square for inversion.");let i=[];for(let r=0;r<this.rows;r++){i[r]=this.data[r].slice();for(let s=0;s<this.cols;s++)i[r][this.cols+s]=r===s?1:0}let e=new h(i,{rows:this.rows,cols:this.cols*2,addFn:this.addFn,subtractFn:this.subtractFn,multiplyFn:this.multiplyFn});for(let r=0;r<this.rows;r++){let s=r;for(;s<this.rows&&e.get(s,r)===0;)s++;if(s===this.rows)throw new Error("Matrix is singular, and its inverse does not exist.");e._swapRows(r,s);let o=(n=e.get(r,r))!=null?n:1;if(o===0)throw new Error("Matrix is singular, and its inverse does not exist (division by zero).");e._scaleRow(r,1/o);for(let d=0;d<this.rows;d++)if(d!==r){let a=e.get(d,r);a===void 0&&(a=0),e._addScaledRow(d,r,-a)}}let t=[];for(let r=0;r<this.rows;r++)t[r]=e.data[r].slice(this.cols);return new h(t,{rows:this.rows,cols:this.cols,addFn:this.addFn,subtractFn:this.subtractFn,multiplyFn:this.multiplyFn})}dot(i){if(this.cols!==i.rows)throw new Error("Number of columns in the first matrix must be equal to the number of rows in the second matrix for dot product.");let e=[];for(let t=0;t<this.rows;t++){e[t]=[];for(let n=0;n<i.cols;n++){let r;for(let s=0;s<this.cols;s++){let o=this.get(t,s),d=i.get(s,n);if(o!==void 0&&d!==void 0){let a=this.multiplyFn(o,d);a!==void 0&&(r=this.addFn(r,a))}}r!==void 0&&(e[t][n]=r)}}return new h(e,{rows:this.rows,cols:i.cols,addFn:this.addFn,subtractFn:this.subtractFn,multiplyFn:this.multiplyFn})}isValidIndex(i,e){return i>=0&&i<this.rows&&e>=0&&e<this.cols}clone(){return new h(this.data,{rows:this.rows,cols:this.cols,addFn:this.addFn,subtractFn:this.subtractFn,multiplyFn:this.multiplyFn})}_addFn(i,e){return i===void 0?e:i+e}_subtractFn(i,e){return i-e}_multiplyFn(i,e){return i*e}_swapRows(i,e){let t=this.data[i];this.data[i]=this.data[e],this.data[e]=t}_scaleRow(i,e){for(let t=0;t<this.cols;t++){let n=this.multiplyFn(this.data[i][t],e);n===void 0&&(n=0),this.data[i][t]=n}}_addScaledRow(i,e,t){for(let n=0;n<this.cols;n++){let r=this.multiplyFn(this.data[e][n],t);r===void 0&&(r=0);let s=r,o=this.addFn(this.data[i][n],s);o===void 0&&(o=0),this.data[i][n]=o}}};var Ce=class h{constructor(i,e){u(this,"direction");u(this,"turn");this.direction=i,this.turn=()=>new h(e[i],e)}},lt=class{constructor({matrix:i,turning:e,onMove:t,init:{cur:n,charDir:r,VISITED:s}}){u(this,"onMove");u(this,"_matrix");u(this,"_cur");u(this,"_character");u(this,"_VISITED");this._matrix=i,this._cur=n,this._character=new Ce(r,e),this.onMove=t,this.onMove&&this.onMove(this._cur),this._VISITED=s,this._matrix[this._cur[0]][this._cur[1]]=this._VISITED}start(){for(;this.check(this._character.direction)||this.check(this._character.turn().direction);){let{direction:i}=this._character;this.check(i)?this.move(i):this.check(this._character.turn().direction)&&(this._character=this._character.turn())}}check(i){let e,t,n=this._matrix,[r,s]=this._cur;switch(i){case"up":if(t=n[r-1],!t)return!1;e=t[s];break;case"right":e=n[r][s+1];break;case"down":if(t=n[r+1],!t)return!1;e=t[s];break;case"left":e=n[r][s-1];break}return e!==void 0&&e!==this._VISITED}move(i){switch(i){case"up":this._cur[0]--;break;case"right":this._cur[1]++;break;case"down":this._cur[0]++;break;case"left":this._cur[1]--;break}let[e,t]=this._cur;this._matrix[e][t]=this._VISITED,this.onMove&&this.onMove(this._cur)}};var pe=class{constructor(i){u(this,"_key");u(this,"_children");u(this,"_isEnd");this._key=i,this._isEnd=!1,this._children=new Map}get key(){return this._key}set key(i){this._key=i}get children(){return this._children}set children(i){this._children=i}get isEnd(){return this._isEnd}set isEnd(i){this._isEnd=i}},ut=class extends F{constructor(e=[],t){super(t);u(this,"_size",0);u(this,"_caseSensitive",!0);u(this,"_root",new pe(""));if(t){let{caseSensitive:n}=t;n!==void 0&&(this._caseSensitive=n)}e&&this.addMany(e)}get size(){return this._size}get caseSensitive(){return this._caseSensitive}get root(){return this._root}get _total(){return this._size}add(e){e=this._caseProcess(e);let t=this.root,n=!1;for(let r of e){let s=t.children.get(r);s||(s=new pe(r),t.children.set(r,s)),t=s}return t.isEnd||(n=!0,t.isEnd=!0,this._size++),n}addMany(e){let t=[];for(let n of e)this.toElementFn?t.push(this.add(this.toElementFn(n))):t.push(this.add(n));return t}has(e){e=this._caseProcess(e);let t=this.root;for(let n of e){let r=t.children.get(n);if(!r)return!1;t=r}return t.isEnd}isEmpty(){return this._size===0}clear(){this._size=0,this._root=new pe("")}delete(e){e=this._caseProcess(e);let t=!1,n=(r,s)=>{let o=e[s],d=r.children.get(o);return d?s===e.length-1?d.isEnd?(d.children.size>0?d.isEnd=!1:r.children.delete(o),t=!0,!0):!1:n(d,s+1)&&!r.isEnd&&d.children.size===0?(r.children.delete(o),!0):!1:!1};return n(this.root,0),t&&this._size--,t}getHeight(){let e=this.root,t=0;if(e){let n=(r,s)=>{s>t&&(t=s);let{children:o}=r;if(o)for(let d of o.entries())n(d[1],s+1)};n(e,0)}return t}hasPurePrefix(e){e=this._caseProcess(e);let t=this.root;for(let n of e){let r=t.children.get(n);if(!r)return!1;t=r}return!t.isEnd}hasPrefix(e){e=this._caseProcess(e);let t=this.root;for(let n of e){let r=t.children.get(n);if(!r)return!1;t=r}return!0}hasCommonPrefix(e){e=this._caseProcess(e);let t="",n=r=>{if(t+=r.key,t!==e&&!r.isEnd)if(r&&r.children&&r.children.size===1)n(Array.from(r.children.values())[0]);else return};return n(this.root),t===e}getLongestCommonPrefix(){let e="",t=n=>{if(e+=n.key,!n.isEnd)if(n&&n.children&&n.children.size===1)t(Array.from(n.children.values())[0]);else return};return t(this.root),e}getWords(e="",t=Number.MAX_SAFE_INTEGER,n=!1){e=this._caseProcess(e);let r=[],s=0,o=(a,l)=>{for(let[f,c]of a.children){if(s>=t)return;o(c,l+f)}if(a.isEnd){if(s>=t)return;r.push(l),s++}},d=this.root;if(e)for(let a of e){let l=d.children.get(a);if(l)d=l;else return[]}return(n||d!==this.root)&&o(d,e),r}clone(){let e=this._createInstance();for(let t of this)e.add(t);return e}filter(e,t){let n=this._createInstance(),r=0;for(let s of this)e.call(t,s,r,this)&&n.add(s),r++;return n}map(e,t,n){let r=this._createLike([],t),s=0;for(let o of this){let d=n===void 0?e(o,s++,this):e.call(n,o,s++,this);if(typeof d!="string")throw new TypeError(`Trie.map callback must return string; got ${typeof d}`);r.add(d)}return r}mapSame(e,t){let n=this._createInstance(),r=0;for(let s of this){let o=t===void 0?e(s,r++,this):e.call(t,s,r++,this);n.add(o)}return n}_createInstance(e){let t=this.constructor;return new t([],{toElementFn:this.toElementFn,caseSensitive:this.caseSensitive,...e!=null?e:{}})}_createLike(e=[],t){let n=this.constructor;return new n(e,t)}_spawnLike(e){return this._createLike([],e)}*_getIterator(){function*e(t,n){t.isEnd&&(yield n);for(let[r,s]of t.children)yield*e(s,n+r)}yield*e(this.root,"")}_caseProcess(e){return this._caseSensitive||(e=e.toLowerCase()),e}};var ht=class h{constructor(i,e,t){u(this,"_key");u(this,"_value");u(this,"_children");this._key=i,this._value=e||void 0,t&&(this._children=t)}get key(){return this._key}set key(i){this._key=i}get value(){return this._value}set value(i){this._value=i}get children(){return this._children}set children(i){this._children=i}addChildren(i){this._children||(this._children=[]),i instanceof h?this._children.push(i):this._children=this._children.concat(i)}getHeight(){let i=0;if(this){let e=(t,n)=>{n>i&&(i=n);let{_children:r}=t;if(r)for(let s=0,o=r.length;s<o;s++)e(r[s],n+1)};e(this,0)}return i}};return Nt(Bt);})();
|
|
6
6
|
/**
|
|
7
7
|
* data-structure-typed
|
|
8
8
|
*
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "data-structure-typed",
|
|
3
|
-
"version": "2.4.
|
|
3
|
+
"version": "2.4.3",
|
|
4
4
|
"description": "Standard data structure",
|
|
5
5
|
"browser": "dist/umd/data-structure-typed.min.js",
|
|
6
6
|
"umd:main": "dist/umd/data-structure-typed.min.js",
|
|
@@ -105,7 +105,7 @@
|
|
|
105
105
|
"benchmark": "^2.1.4",
|
|
106
106
|
"binary-tree-typed": "^1.54.3",
|
|
107
107
|
"bst-typed": "^1.54.3",
|
|
108
|
-
"data-structure-typed": "^2.4.
|
|
108
|
+
"data-structure-typed": "^2.4.2",
|
|
109
109
|
"dependency-cruiser": "^16.5.0",
|
|
110
110
|
"doctoc": "^2.2.1",
|
|
111
111
|
"eslint": "^9.13.0",
|
|
@@ -436,4 +436,20 @@ export class TreeMap<K = any, V = any, R = [K, V]> implements Iterable<[K, V | u
|
|
|
436
436
|
|
|
437
437
|
return out;
|
|
438
438
|
}
|
|
439
|
+
|
|
440
|
+
/**
|
|
441
|
+
* Creates a shallow clone of this map.
|
|
442
|
+
* @remarks Time O(n log n), Space O(n)
|
|
443
|
+
* @example
|
|
444
|
+
* const original = new TreeMap([['a', 1], ['b', 2]]);
|
|
445
|
+
* const copy = original.clone();
|
|
446
|
+
* copy.set('c', 3);
|
|
447
|
+
* original.has('c'); // false (original unchanged)
|
|
448
|
+
*/
|
|
449
|
+
clone(): TreeMap<K, V> {
|
|
450
|
+
return new TreeMap<K, V>(this, {
|
|
451
|
+
comparator: this.#isDefaultComparator ? undefined : this.#userComparator,
|
|
452
|
+
isMapMode: this.#core.isMapMode
|
|
453
|
+
});
|
|
454
|
+
}
|
|
439
455
|
}
|
|
@@ -404,4 +404,20 @@ export class TreeSet<K = any, R = K> implements Iterable<K> {
|
|
|
404
404
|
|
|
405
405
|
return out;
|
|
406
406
|
}
|
|
407
|
+
|
|
408
|
+
/**
|
|
409
|
+
* Creates a shallow clone of this set.
|
|
410
|
+
* @remarks Time O(n log n), Space O(n)
|
|
411
|
+
* @example
|
|
412
|
+
* const original = new TreeSet([1, 2, 3]);
|
|
413
|
+
* const copy = original.clone();
|
|
414
|
+
* copy.add(4);
|
|
415
|
+
* original.has(4); // false (original unchanged)
|
|
416
|
+
*/
|
|
417
|
+
clone(): TreeSet<K> {
|
|
418
|
+
return new TreeSet<K>(this, {
|
|
419
|
+
comparator: this.#isDefaultComparator ? undefined : this.#userComparator,
|
|
420
|
+
isMapMode: this.#core.isMapMode
|
|
421
|
+
});
|
|
422
|
+
}
|
|
407
423
|
}
|