undirected-graph-typed 2.5.2 → 2.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (63) hide show
  1. package/dist/cjs/index.cjs +352 -14
  2. package/dist/cjs/index.cjs.map +1 -1
  3. package/dist/cjs-legacy/index.cjs +352 -14
  4. package/dist/cjs-legacy/index.cjs.map +1 -1
  5. package/dist/esm/index.mjs +352 -14
  6. package/dist/esm/index.mjs.map +1 -1
  7. package/dist/esm-legacy/index.mjs +352 -14
  8. package/dist/esm-legacy/index.mjs.map +1 -1
  9. package/dist/types/data-structures/base/iterable-element-base.d.ts +17 -0
  10. package/dist/types/data-structures/base/linear-base.d.ts +6 -0
  11. package/dist/types/data-structures/binary-tree/avl-tree.d.ts +86 -2
  12. package/dist/types/data-structures/binary-tree/binary-indexed-tree.d.ts +98 -0
  13. package/dist/types/data-structures/binary-tree/binary-tree.d.ts +191 -15
  14. package/dist/types/data-structures/binary-tree/bst.d.ts +171 -3
  15. package/dist/types/data-structures/binary-tree/red-black-tree.d.ts +136 -8
  16. package/dist/types/data-structures/binary-tree/segment-tree.d.ts +42 -0
  17. package/dist/types/data-structures/binary-tree/tree-map.d.ts +1061 -167
  18. package/dist/types/data-structures/binary-tree/tree-multi-map.d.ts +1232 -355
  19. package/dist/types/data-structures/binary-tree/tree-multi-set.d.ts +916 -194
  20. package/dist/types/data-structures/binary-tree/tree-set.d.ts +1078 -141
  21. package/dist/types/data-structures/graph/directed-graph.d.ts +70 -0
  22. package/dist/types/data-structures/graph/undirected-graph.d.ts +63 -0
  23. package/dist/types/data-structures/hash/hash-map.d.ts +84 -6
  24. package/dist/types/data-structures/heap/heap.d.ts +140 -12
  25. package/dist/types/data-structures/linked-list/doubly-linked-list.d.ts +150 -2
  26. package/dist/types/data-structures/linked-list/singly-linked-list.d.ts +106 -1
  27. package/dist/types/data-structures/linked-list/skip-linked-list.d.ts +126 -0
  28. package/dist/types/data-structures/matrix/matrix.d.ts +56 -0
  29. package/dist/types/data-structures/queue/deque.d.ts +171 -0
  30. package/dist/types/data-structures/queue/queue.d.ts +97 -0
  31. package/dist/types/data-structures/stack/stack.d.ts +72 -2
  32. package/dist/types/data-structures/trie/trie.d.ts +84 -0
  33. package/dist/types/interfaces/binary-tree.d.ts +2 -3
  34. package/dist/umd/undirected-graph-typed.js +352 -14
  35. package/dist/umd/undirected-graph-typed.js.map +1 -1
  36. package/dist/umd/undirected-graph-typed.min.js +1 -1
  37. package/dist/umd/undirected-graph-typed.min.js.map +1 -1
  38. package/package.json +2 -2
  39. package/src/data-structures/base/iterable-element-base.ts +32 -0
  40. package/src/data-structures/base/linear-base.ts +11 -0
  41. package/src/data-structures/binary-tree/avl-tree.ts +88 -5
  42. package/src/data-structures/binary-tree/binary-indexed-tree.ts +98 -0
  43. package/src/data-structures/binary-tree/binary-tree.ts +242 -81
  44. package/src/data-structures/binary-tree/bst.ts +173 -7
  45. package/src/data-structures/binary-tree/red-black-tree.ts +139 -15
  46. package/src/data-structures/binary-tree/segment-tree.ts +42 -0
  47. package/src/data-structures/binary-tree/tree-map.ts +948 -36
  48. package/src/data-structures/binary-tree/tree-multi-map.ts +893 -13
  49. package/src/data-structures/binary-tree/tree-multi-set.ts +761 -33
  50. package/src/data-structures/binary-tree/tree-set.ts +1260 -251
  51. package/src/data-structures/graph/directed-graph.ts +71 -1
  52. package/src/data-structures/graph/undirected-graph.ts +64 -1
  53. package/src/data-structures/hash/hash-map.ts +100 -12
  54. package/src/data-structures/heap/heap.ts +149 -19
  55. package/src/data-structures/linked-list/doubly-linked-list.ts +178 -2
  56. package/src/data-structures/linked-list/singly-linked-list.ts +106 -1
  57. package/src/data-structures/linked-list/skip-linked-list.ts +126 -0
  58. package/src/data-structures/matrix/matrix.ts +56 -0
  59. package/src/data-structures/queue/deque.ts +187 -0
  60. package/src/data-structures/queue/queue.ts +109 -0
  61. package/src/data-structures/stack/stack.ts +75 -5
  62. package/src/data-structures/trie/trie.ts +84 -0
  63. package/src/interfaces/binary-tree.ts +1 -9
@@ -1,4 +1,4 @@
1
- "use strict";var undirectedGraphTyped=(()=>{var C=Object.defineProperty;var P=Object.getOwnPropertyDescriptor;var B=Object.getOwnPropertyNames;var W=Object.prototype.hasOwnProperty;var q=(l,a,e)=>a in l?C(l,a,{enumerable:!0,configurable:!0,writable:!0,value:e}):l[a]=e;var Q=(l,a)=>{for(var e in a)C(l,e,{get:a[e],enumerable:!0})},X=(l,a,e,t)=>{if(a&&typeof a=="object"||typeof a=="function")for(let n of B(a))!W.call(l,n)&&n!==e&&C(l,n,{get:()=>a[n],enumerable:!(t=P(a,n))||t.enumerable});return l};var J=l=>X(C({},"__esModule",{value:!0}),l);var y=(l,a,e)=>q(l,typeof a!="symbol"?a+"":a,e);var Y={};Q(Y,{DFSOperation:()=>z,ERR:()=>w,Range:()=>D,UndirectedEdge:()=>$,UndirectedGraph:()=>j,UndirectedVertex:()=>U,raise:()=>v});var G=function(){return"xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx".replace(/[x]/g,function(l){let a=Math.random()*16|0;return(l=="x"?a:a&3|8).toString(16)})},H=function(l,a){let e=-1,t=l?l.length:0,n=[];for(;++e<t;){let r=l[e];a(r,e,l)&&(n.push(r),Array.prototype.splice.call(l,e--,1),t--)}return n};function v(l,a){throw new l(a)}var w={indexOutOfRange:(l,a,e,t)=>`${t?t+": ":""}Index ${l} is out of range [${a}, ${e}].`,invalidIndex:l=>`${l?l+": ":""}Index must be an integer.`,invalidArgument:(l,a)=>`${a?a+": ":""}${l}`,comparatorRequired:l=>`${l?l+": ":""}Comparator is required for non-number/non-string/non-Date keys.`,invalidKey:(l,a)=>`${a?a+": ":""}${l}`,notAFunction:(l,a)=>`${a?a+": ":""}${l} must be a function.`,invalidEntry:l=>`${l?l+": ":""}Each entry must be a [key, value] tuple.`,invalidNaN:l=>`${l?l+": ":""}NaN is not a valid key.`,invalidDate:l=>`${l?l+": ":""}Invalid Date key.`,reduceEmpty:l=>`${l?l+": ":""}Reduce of empty structure with no initial value.`,callbackReturnType:(l,a,e)=>`${e?e+": ":""}Callback must return ${l}; got ${a}.`,invalidOperation:(l,a)=>`${a?a+": ":""}${l}`,matrixDimensionMismatch:l=>`Matrix: Dimensions must be compatible for ${l}.`,matrixSingular:()=>"Matrix: Singular matrix, inverse does not exist.",matrixNotSquare:()=>"Matrix: Must be square for inversion.",matrixNotRectangular:()=>"Matrix: Must be rectangular for transposition.",matrixRowMismatch:(l,a)=>`Matrix: Expected row length ${l}, but got ${a}.`,orderStatisticNotEnabled:(l,a)=>`${a?a+": ":""}${l}() requires enableOrderStatistic: true.`};var z=(e=>(e[e.VISIT=0]="VISIT",e[e.PROCESS=1]="PROCESS",e))(z||{}),D=class{constructor(a,e,t=!0,n=!0){this.low=a;this.high=e;this.includeLow=t;this.includeHigh=n}isInRange(a,e){let t=this.includeLow?e(a,this.low)>=0:e(a,this.low)>0,n=this.includeHigh?e(a,this.high)<=0:e(a,this.high)<0;return t&&n}};var A=class{*[Symbol.iterator](...a){yield*this._getIterator(...a)}*entries(){for(let a of this)yield a}*keys(){for(let a of this)yield a[0]}*values(){for(let a of this)yield a[1]}every(a,e){let t=0;for(let n of this)if(!a.call(e,n[1],n[0],t++,this))return!1;return!0}some(a,e){let t=0;for(let n of this)if(a.call(e,n[1],n[0],t++,this))return!0;return!1}forEach(a,e){let t=0;for(let n of this){let[r,s]=n;a.call(e,s,r,t++,this)}}find(a,e){let t=0;for(let n of this){let[r,s]=n;if(a.call(e,s,r,t++,this))return n}}has(a){for(let e of this){let[t]=e;if(t===a)return!0}return!1}hasValue(a){for(let[,e]of this)if(e===a)return!0;return!1}get(a){for(let e of this){let[t,n]=e;if(t===a)return n}}reduce(a,e){let t=e,n=0;for(let r of this){let[s,o]=r;t=a(t,o,s,n++,this)}return t}toArray(){return[...this]}toVisual(){return[...this]}print(){console.log(this.toVisual())}};var K=class{constructor(a){y(this,"_toElementFn");if(a){let{toElementFn:e}=a;typeof e=="function"?this._toElementFn=e:e&&v(TypeError,"toElementFn must be a function type")}}get toElementFn(){return this._toElementFn}*[Symbol.iterator](...a){yield*this._getIterator(...a)}*values(){for(let a of this)yield a}every(a,e){let t=0;for(let n of this)if(e===void 0){if(!a(n,t++,this))return!1}else if(!a.call(e,n,t++,this))return!1;return!0}some(a,e){let t=0;for(let n of this)if(e===void 0){if(a(n,t++,this))return!0}else if(a.call(e,n,t++,this))return!0;return!1}forEach(a,e){let t=0;for(let n of this)e===void 0?a(n,t++,this):a.call(e,n,t++,this)}find(a,e){let t=0;for(let n of this)if(e===void 0){if(a(n,t++,this))return n}else if(a.call(e,n,t++,this))return n}has(a){for(let e of this)if(e===a)return!0;return!1}reduce(a,e){let t=0,n=this[Symbol.iterator](),r;if(arguments.length>=2)r=e;else{let s=n.next();s.done&&v(TypeError,"Reduce of empty structure with no initial value"),r=s.value,t=1}for(let s of n)r=a(r,s,t++,this);return r}toArray(){return[...this]}toVisual(){return[...this]}print(){console.log(this.toVisual())}};var T=class l extends K{constructor(e){super(e);y(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 l?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}};var L=class l extends K{constructor(e=[],t){super(t);y(this,"_equals",Object.is);y(this,"_elements",[]);y(this,"_DEFAULT_COMPARATOR",(e,t)=>((typeof e=="object"||typeof t=="object")&&v(TypeError,w.comparatorRequired("Heap")),e>t?1:e<t?-1:0));y(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 l(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:{};r||v(TypeError,w.comparatorRequired("Heap.map"));let i=this._createLike([],{...o,comparator:r,toElementFn:s}),u=0;for(let m of this){let d=n===void 0?e(m,u++,this):e.call(n,m,u++,this);i.add(d)}return i}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)}};var F=class l extends T{constructor(e=[],t){super(t);y(this,"_elements",[]);y(this,"_offset",0);y(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 l(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,i;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:(i=t==null?void 0:t.autoCompactRatio)!=null?i:this._autoCompactRatio}),s=0;for(let u of this)r.push(n===void 0?e(u,s++,this):e.call(n,u,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 i of this){let u=t===void 0?e(i,s++,this):e.call(t,i,s++,this);r.push(u)}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)}};var R=class{constructor(a,e){y(this,"key");y(this,"value");this.key=a,this.value=e}},N=class{constructor(a,e){y(this,"value");y(this,"weight");y(this,"_hashCode");this.weight=a!==void 0?a:1,this.value=e,this._hashCode=G()}get hashCode(){return this._hashCode}},S=class extends A{constructor(e){super();y(this,"_options",{defaultEdgeWeight:1});y(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 R)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 N)return this._addEdge(e);if(t instanceof R||typeof t=="string"||typeof t=="number"){if(!(this.hasVertex(e)&&this.hasVertex(t)))return!1;e instanceof R&&(e=e.key),t instanceof R&&(t=t.key);let s=this.createEdge(e,t,n,r);return this._addEdge(s)}else v(TypeError,w.invalidArgument("dest must be a Vertex or vertex key when srcOrEdge is an Edge.","Graph"))}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 i=[];for(i.push({vertex:s,path:[s]});i.length>0;){let{vertex:u,path:m}=i.pop();if(u===o&&(r.push(m),r.length>=n))return r;let d=this.getNeighbors(u);for(let h of d)if(!m.includes(h)){let f=[...m,h];i.push({vertex:h,path:f})}}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,i=new F([s]);o.set(s,!0);let u=0;for(;i.length>0;){for(let m=0,d=i.length;m<d;m++){let h=i.shift();if(h===r)return u;if(h!==void 0){let f=this.getNeighbors(h);for(let V of f)o.has(V)||(o.set(V,!0),i.push(V))}}u++}return}}getMinPathBetween(e,t,n,r=!1){var s,o;if(n===void 0&&(n=!1),n)if(r){let i=this.getAllPathsBetween(e,t,1e4),u=Number.MAX_SAFE_INTEGER,m=-1,d=0;for(let h of i){let f=this.getPathSumWeight(h);f<u&&(u=f,m=d),d++}return i[m]||void 0}else return(o=(s=this.dijkstra(e,t,!0,!0))==null?void 0:s.minPath)!=null?o:[];else{let i=[],u=this._getVertex(e),m=this._getVertex(t);if(!(u&&m))return[];let d=(h,f,V,g)=>{if(V.add(h),h===f){i=[u,...g];return}let M=this.getNeighbors(h);for(let k of M)V.has(k)||(g.push(k),d(k,f,V,g),g.pop());V.delete(h)};return d(u,m,new Set,[]),i}}dijkstraWithoutHeap(e,t=void 0,n=!1,r=!1){let s=Number.MAX_SAFE_INTEGER,o,i=[],u=[],m=this._vertexMap,d=new Map,h=new Set,f=new Map,V=this._getVertex(e),g=t?this._getVertex(t):void 0;if(!V)return;for(let b of m){let c=b[1];c instanceof R&&d.set(c,Number.MAX_SAFE_INTEGER)}d.set(V,0),f.set(V,void 0);let M=()=>{let b=Number.MAX_SAFE_INTEGER,c;for(let[E,p]of d)h.has(E)||p<b&&(b=p,c=E);return c},k=b=>{for(let c of m){let E=c[1];if(E instanceof R){let p=[E],x=f.get(E);for(;x;)p.push(x),x=f.get(x);let _=p.reverse();c[1]===b&&(i=_),u.push(_)}}};for(let b=1;b<m.size;b++){let c=M();if(c){if(h.add(c),g&&g===c)return n&&(s=d.get(g)||Number.MAX_SAFE_INTEGER),r&&k(g),{distMap:d,preMap:f,seen:h,paths:u,minDist:s,minPath:i};let E=this.getNeighbors(c);for(let p of E)if(!h.has(p)){let x=this.getEdge(c,p);if(x){let _=d.get(c),O=d.get(p);_!==void 0&&O!==void 0&&x.weight+_<O&&(d.set(p,x.weight+_),f.set(p,c))}}}}return n&&d.forEach((b,c)=>{c!==V&&b<s&&(s=b,r&&(o=c))}),r&&k(o),{distMap:d,preMap:f,seen:h,paths:u,minDist:s,minPath:i}}dijkstra(e,t=void 0,n=!1,r=!1){var b;let s=Number.MAX_SAFE_INTEGER,o,i=[],u=[],m=this._vertexMap,d=new Map,h=new Set,f=new Map,V=this._getVertex(e),g=t?this._getVertex(t):void 0;if(!V)return;for(let c of m){let E=c[1];E instanceof R&&d.set(E,Number.MAX_SAFE_INTEGER)}let M=new L([],{comparator:(c,E)=>c.key-E.key});M.add({key:0,value:V}),d.set(V,0),f.set(V,void 0);let k=c=>{for(let E of m){let p=E[1];if(p instanceof R){let x=[p],_=f.get(p);for(;_;)x.push(_),_=f.get(_);let O=x.reverse();E[1]===c&&(i=O),u.push(O)}}};for(;M.size>0;){let c=M.poll(),E=c==null?void 0:c.key,p=c==null?void 0:c.value;if(E!==void 0&&p){if(h.add(p),g&&g===p)return n&&(s=d.get(g)||Number.MAX_SAFE_INTEGER),r&&k(g),{distMap:d,preMap:f,seen:h,paths:u,minDist:s,minPath:i};let x=this.getNeighbors(p);for(let _ of x)if(!h.has(_)){let O=(b=this.getEdge(p,_))==null?void 0:b.weight;if(typeof O=="number"){let I=d.get(_);I!==void 0&&E+O<I&&(M.add({key:E+O,value:_}),f.set(_,p),d.set(_,E+O))}}}}return n&&d.forEach((c,E)=>{E!==V&&c<s&&(s=c,r&&(o=E))}),r&&k(o),{distMap:d,preMap:f,seen:h,paths:u,minDist:s,minPath:i}}bellmanFord(e,t,n,r){n===void 0&&(n=!1),r===void 0&&(r=!1);let s=this._getVertex(e),o=[],i=new Map,u=new Map,m=Number.MAX_SAFE_INTEGER,d=[],h;if(t&&(h=!1),!s)return{hasNegativeCycle:h,distMap:i,preMap:u,paths:o,min:m,minPath:d};let f=this._vertexMap,V=f.size,g=this.edgeSet(),M=g.length;this._vertexMap.forEach(b=>{i.set(b,Number.MAX_SAFE_INTEGER)}),i.set(s,0);for(let b=1;b<V;++b)for(let c=0;c<M;++c){let E=this.getEndsOfEdge(g[c]);if(E){let[p,x]=E,_=g[c].weight,O=i.get(p),I=i.get(x);O!==void 0&&I!==void 0&&i.get(p)!==Number.MAX_SAFE_INTEGER&&O+_<I&&(i.set(x,O+_),r&&u.set(x,p))}}let k;if(n&&i.forEach((b,c)=>{c!==s&&b<m&&(m=b,r&&(k=c))}),r)for(let b of f){let c=b[1];if(c instanceof R){let E=[c],p=u.get(c);for(;p!==void 0;)E.push(p),p=u.get(p);let x=E.reverse();b[1]===k&&(d=x),o.push(x)}}for(let b=0;b<M;++b){let c=this.getEndsOfEdge(g[b]);if(c){let[E]=c,p=g[b].weight,x=i.get(E);x&&x!==Number.MAX_SAFE_INTEGER&&x+p<x&&(h=!0)}}return{hasNegativeCycle:h,distMap:i,preMap:u,paths:o,min:m,minPath:d}}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 i=0;i<t;i++)r[o][i]=void 0}for(let o=0;o<t;o++)for(let i=0;i<t;i++)n[o][i]=((s=this.getEdge(e[o][1],e[i][1]))==null?void 0:s.weight)||Number.MAX_SAFE_INTEGER;for(let o=0;o<t;o++)for(let i=0;i<t;i++)for(let u=0;u<t;u++)n[i][u]>n[i][o]+n[o][u]&&(n[i][u]=n[i][o]+n[o][u],r[i][u]=e[o][1]);return{costs:n,predecessor:r}}getCycles(e=!1){let t=[],n=new Set,r=(o,i,u)=>{if(u.has(o)){(!e&&i.length>2||e&&i.length>=2)&&i[0]===o.key&&t.push([...i]);return}u.add(o),i.push(o.key);for(let m of this.getNeighbors(o))m&&r(m,i,u);u.delete(o),i.pop()};for(let o of this.vertexMap.values())r(o,[],n);let s=new Map;for(let o of t){let i=[...o].sort().toString();s.has(i)||s.set(i,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[i,u]=o,m=i.key,d=u.key,h=typeof n.hasVertex=="function"?n.hasVertex(m):!1,f=typeof n.hasVertex=="function"?n.hasVertex(d):!1;if(h&&f){let V=n.createEdge(m,d,s.weight,s.value);n._addEdge(V)}}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 R?e.key:e}get _edgeConnector(){return"--"}toVisual(e){var i;let t=(i=e==null?void 0:e.showWeight)!=null?i:!0,n=[...this._vertexMap.values()],r=n.length,s=this.edgeSet().length,o=[`Graph (${r} vertices, ${s} edges):`];for(let u of n){let m=this.getNeighbors(u);if(m.length===0)o.push(` ${u.key} (isolated)`);else{let d=m.map(h=>{let f=this.getEdge(u,h);return f&&t&&f.weight!==void 0&&f.weight!==1?`${h.key} (${f.weight})`:`${h.key}`});o.push(` ${u.key} ${this._edgeConnector} ${d.join(", ")}`)}}return o.join(`
1
+ "use strict";var undirectedGraphTyped=(()=>{var C=Object.defineProperty;var P=Object.getOwnPropertyDescriptor;var W=Object.getOwnPropertyNames;var B=Object.prototype.hasOwnProperty;var q=(l,a,e)=>a in l?C(l,a,{enumerable:!0,configurable:!0,writable:!0,value:e}):l[a]=e;var Q=(l,a)=>{for(var e in a)C(l,e,{get:a[e],enumerable:!0})},X=(l,a,e,t)=>{if(a&&typeof a=="object"||typeof a=="function")for(let n of W(a))!B.call(l,n)&&n!==e&&C(l,n,{get:()=>a[n],enumerable:!(t=P(a,n))||t.enumerable});return l};var J=l=>X(C({},"__esModule",{value:!0}),l);var y=(l,a,e)=>q(l,typeof a!="symbol"?a+"":a,e);var Y={};Q(Y,{DFSOperation:()=>z,ERR:()=>w,Range:()=>D,UndirectedEdge:()=>$,UndirectedGraph:()=>j,UndirectedVertex:()=>U,raise:()=>v});var G=function(){return"xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx".replace(/[x]/g,function(l){let a=Math.random()*16|0;return(l=="x"?a:a&3|8).toString(16)})},H=function(l,a){let e=-1,t=l?l.length:0,n=[];for(;++e<t;){let r=l[e];a(r,e,l)&&(n.push(r),Array.prototype.splice.call(l,e--,1),t--)}return n};function v(l,a){throw new l(a)}var w={indexOutOfRange:(l,a,e,t)=>`${t?t+": ":""}Index ${l} is out of range [${a}, ${e}].`,invalidIndex:l=>`${l?l+": ":""}Index must be an integer.`,invalidArgument:(l,a)=>`${a?a+": ":""}${l}`,comparatorRequired:l=>`${l?l+": ":""}Comparator is required for non-number/non-string/non-Date keys.`,invalidKey:(l,a)=>`${a?a+": ":""}${l}`,notAFunction:(l,a)=>`${a?a+": ":""}${l} must be a function.`,invalidEntry:l=>`${l?l+": ":""}Each entry must be a [key, value] tuple.`,invalidNaN:l=>`${l?l+": ":""}NaN is not a valid key.`,invalidDate:l=>`${l?l+": ":""}Invalid Date key.`,reduceEmpty:l=>`${l?l+": ":""}Reduce of empty structure with no initial value.`,callbackReturnType:(l,a,e)=>`${e?e+": ":""}Callback must return ${l}; got ${a}.`,invalidOperation:(l,a)=>`${a?a+": ":""}${l}`,matrixDimensionMismatch:l=>`Matrix: Dimensions must be compatible for ${l}.`,matrixSingular:()=>"Matrix: Singular matrix, inverse does not exist.",matrixNotSquare:()=>"Matrix: Must be square for inversion.",matrixNotRectangular:()=>"Matrix: Must be rectangular for transposition.",matrixRowMismatch:(l,a)=>`Matrix: Expected row length ${l}, but got ${a}.`,orderStatisticNotEnabled:(l,a)=>`${a?a+": ":""}${l}() requires enableOrderStatistic: true.`};var z=(e=>(e[e.VISIT=0]="VISIT",e[e.PROCESS=1]="PROCESS",e))(z||{}),D=class{constructor(a,e,t=!0,n=!0){this.low=a;this.high=e;this.includeLow=t;this.includeHigh=n}isInRange(a,e){let t=this.includeLow?e(a,this.low)>=0:e(a,this.low)>0,n=this.includeHigh?e(a,this.high)<=0:e(a,this.high)<0;return t&&n}};var A=class{*[Symbol.iterator](...a){yield*this._getIterator(...a)}*entries(){for(let a of this)yield a}*keys(){for(let a of this)yield a[0]}*values(){for(let a of this)yield a[1]}every(a,e){let t=0;for(let n of this)if(!a.call(e,n[1],n[0],t++,this))return!1;return!0}some(a,e){let t=0;for(let n of this)if(a.call(e,n[1],n[0],t++,this))return!0;return!1}forEach(a,e){let t=0;for(let n of this){let[r,s]=n;a.call(e,s,r,t++,this)}}find(a,e){let t=0;for(let n of this){let[r,s]=n;if(a.call(e,s,r,t++,this))return n}}has(a){for(let e of this){let[t]=e;if(t===a)return!0}return!1}hasValue(a){for(let[,e]of this)if(e===a)return!0;return!1}get(a){for(let e of this){let[t,n]=e;if(t===a)return n}}reduce(a,e){let t=e,n=0;for(let r of this){let[s,o]=r;t=a(t,o,s,n++,this)}return t}toArray(){return[...this]}toVisual(){return[...this]}print(){console.log(this.toVisual())}};var I=class{constructor(a){y(this,"_toElementFn");if(a){let{toElementFn:e}=a;typeof e=="function"?this._toElementFn=e:e&&v(TypeError,"toElementFn must be a function type")}}get toElementFn(){return this._toElementFn}*[Symbol.iterator](...a){yield*this._getIterator(...a)}*values(){for(let a of this)yield a}every(a,e){let t=0;for(let n of this)if(e===void 0){if(!a(n,t++,this))return!1}else if(!a.call(e,n,t++,this))return!1;return!0}some(a,e){let t=0;for(let n of this)if(e===void 0){if(a(n,t++,this))return!0}else if(a.call(e,n,t++,this))return!0;return!1}forEach(a,e){let t=0;for(let n of this)e===void 0?a(n,t++,this):a.call(e,n,t++,this)}find(a,e){let t=0;for(let n of this)if(e===void 0){if(a(n,t++,this))return n}else if(a.call(e,n,t++,this))return n}has(a){for(let e of this)if(e===a)return!0;return!1}includes(a){return this.has(a)}*entries(){let a=0;for(let e of this)yield[a++,e]}*keys(){let a=0;for(let e of this)yield a++}reduce(a,e){let t=0,n=this[Symbol.iterator](),r;if(arguments.length>=2)r=e;else{let s=n.next();s.done&&v(TypeError,"Reduce of empty structure with no initial value"),r=s.value,t=1}for(let s of n)r=a(r,s,t++,this);return r}toArray(){return[...this]}toVisual(){return[...this]}print(){console.log(this.toVisual())}};var T=class l extends I{constructor(e){super(e);y(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 l?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}toReversed(){let e=this.clone();return e.reverse(),e}};var L=class l extends I{constructor(e=[],t){super(t);y(this,"_equals",Object.is);y(this,"_elements",[]);y(this,"_DEFAULT_COMPARATOR",(e,t)=>((typeof e=="object"||typeof t=="object")&&v(TypeError,w.comparatorRequired("Heap")),e>t?1:e<t?-1:0));y(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 l(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(){return this.pop()}pop(){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=[]}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.pop():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){return this.deleteWhere(e)}deleteWhere(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.pop():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:{};r||v(TypeError,w.comparatorRequired("Heap.map"));let i=this._createLike([],{...o,comparator:r,toElementFn:s}),u=0;for(let m of this){let d=n===void 0?e(m,u++,this):e.call(n,m,u++,this);i.add(d)}return i}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)}};var F=class l extends T{constructor(e=[],t){super(t);y(this,"_elements",[]);y(this,"_offset",0);y(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}peek(){return this.first}get last(){return this.length>0?this.elements[this.elements.length-1]:void 0}static fromArray(e){return new l(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)}deleteWhere(e){for(let t=0;t<this.length;t++)if(e(this._elements[this._offset+t],t,this))return this.deleteAt(t),!0;return!1}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,i;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:(i=t==null?void 0:t.autoCompactRatio)!=null?i:this._autoCompactRatio}),s=0;for(let u of this)r.push(n===void 0?e(u,s++,this):e.call(n,u,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 i of this){let u=t===void 0?e(i,s++,this):e.call(t,i,s++,this);r.push(u)}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)}};var R=class{constructor(a,e){y(this,"key");y(this,"value");this.key=a,this.value=e}},N=class{constructor(a,e){y(this,"value");y(this,"weight");y(this,"_hashCode");this.weight=a!==void 0?a:1,this.value=e,this._hashCode=G()}get hashCode(){return this._hashCode}},S=class extends A{constructor(e){super();y(this,"_options",{defaultEdgeWeight:1});y(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 R)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 N)return this._addEdge(e);if(t instanceof R||typeof t=="string"||typeof t=="number"){if(!(this.hasVertex(e)&&this.hasVertex(t)))return!1;e instanceof R&&(e=e.key),t instanceof R&&(t=t.key);let s=this.createEdge(e,t,n,r);return this._addEdge(s)}else v(TypeError,w.invalidArgument("dest must be a Vertex or vertex key when srcOrEdge is an Edge.","Graph"))}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 i=[];for(i.push({vertex:s,path:[s]});i.length>0;){let{vertex:u,path:m}=i.pop();if(u===o&&(r.push(m),r.length>=n))return r;let d=this.getNeighbors(u);for(let h of d)if(!m.includes(h)){let f=[...m,h];i.push({vertex:h,path:f})}}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,i=new F([s]);o.set(s,!0);let u=0;for(;i.length>0;){for(let m=0,d=i.length;m<d;m++){let h=i.shift();if(h===r)return u;if(h!==void 0){let f=this.getNeighbors(h);for(let V of f)o.has(V)||(o.set(V,!0),i.push(V))}}u++}return}}getMinPathBetween(e,t,n,r=!1){var s,o;if(n===void 0&&(n=!1),n)if(r){let i=this.getAllPathsBetween(e,t,1e4),u=Number.MAX_SAFE_INTEGER,m=-1,d=0;for(let h of i){let f=this.getPathSumWeight(h);f<u&&(u=f,m=d),d++}return i[m]||void 0}else return(o=(s=this.dijkstra(e,t,!0,!0))==null?void 0:s.minPath)!=null?o:[];else{let i=[],u=this._getVertex(e),m=this._getVertex(t);if(!(u&&m))return[];let d=(h,f,V,g)=>{if(V.add(h),h===f){i=[u,...g];return}let M=this.getNeighbors(h);for(let k of M)V.has(k)||(g.push(k),d(k,f,V,g),g.pop());V.delete(h)};return d(u,m,new Set,[]),i}}dijkstraWithoutHeap(e,t=void 0,n=!1,r=!1){let s=Number.MAX_SAFE_INTEGER,o,i=[],u=[],m=this._vertexMap,d=new Map,h=new Set,f=new Map,V=this._getVertex(e),g=t?this._getVertex(t):void 0;if(!V)return;for(let b of m){let c=b[1];c instanceof R&&d.set(c,Number.MAX_SAFE_INTEGER)}d.set(V,0),f.set(V,void 0);let M=()=>{let b=Number.MAX_SAFE_INTEGER,c;for(let[E,p]of d)h.has(E)||p<b&&(b=p,c=E);return c},k=b=>{for(let c of m){let E=c[1];if(E instanceof R){let p=[E],x=f.get(E);for(;x;)p.push(x),x=f.get(x);let _=p.reverse();c[1]===b&&(i=_),u.push(_)}}};for(let b=1;b<m.size;b++){let c=M();if(c){if(h.add(c),g&&g===c)return n&&(s=d.get(g)||Number.MAX_SAFE_INTEGER),r&&k(g),{distMap:d,preMap:f,seen:h,paths:u,minDist:s,minPath:i};let E=this.getNeighbors(c);for(let p of E)if(!h.has(p)){let x=this.getEdge(c,p);if(x){let _=d.get(c),O=d.get(p);_!==void 0&&O!==void 0&&x.weight+_<O&&(d.set(p,x.weight+_),f.set(p,c))}}}}return n&&d.forEach((b,c)=>{c!==V&&b<s&&(s=b,r&&(o=c))}),r&&k(o),{distMap:d,preMap:f,seen:h,paths:u,minDist:s,minPath:i}}dijkstra(e,t=void 0,n=!1,r=!1){var b;let s=Number.MAX_SAFE_INTEGER,o,i=[],u=[],m=this._vertexMap,d=new Map,h=new Set,f=new Map,V=this._getVertex(e),g=t?this._getVertex(t):void 0;if(!V)return;for(let c of m){let E=c[1];E instanceof R&&d.set(E,Number.MAX_SAFE_INTEGER)}let M=new L([],{comparator:(c,E)=>c.key-E.key});M.add({key:0,value:V}),d.set(V,0),f.set(V,void 0);let k=c=>{for(let E of m){let p=E[1];if(p instanceof R){let x=[p],_=f.get(p);for(;_;)x.push(_),_=f.get(_);let O=x.reverse();E[1]===c&&(i=O),u.push(O)}}};for(;M.size>0;){let c=M.poll(),E=c==null?void 0:c.key,p=c==null?void 0:c.value;if(E!==void 0&&p){if(h.add(p),g&&g===p)return n&&(s=d.get(g)||Number.MAX_SAFE_INTEGER),r&&k(g),{distMap:d,preMap:f,seen:h,paths:u,minDist:s,minPath:i};let x=this.getNeighbors(p);for(let _ of x)if(!h.has(_)){let O=(b=this.getEdge(p,_))==null?void 0:b.weight;if(typeof O=="number"){let K=d.get(_);K!==void 0&&E+O<K&&(M.add({key:E+O,value:_}),f.set(_,p),d.set(_,E+O))}}}}return n&&d.forEach((c,E)=>{E!==V&&c<s&&(s=c,r&&(o=E))}),r&&k(o),{distMap:d,preMap:f,seen:h,paths:u,minDist:s,minPath:i}}bellmanFord(e,t,n,r){n===void 0&&(n=!1),r===void 0&&(r=!1);let s=this._getVertex(e),o=[],i=new Map,u=new Map,m=Number.MAX_SAFE_INTEGER,d=[],h;if(t&&(h=!1),!s)return{hasNegativeCycle:h,distMap:i,preMap:u,paths:o,min:m,minPath:d};let f=this._vertexMap,V=f.size,g=this.edgeSet(),M=g.length;this._vertexMap.forEach(b=>{i.set(b,Number.MAX_SAFE_INTEGER)}),i.set(s,0);for(let b=1;b<V;++b)for(let c=0;c<M;++c){let E=this.getEndsOfEdge(g[c]);if(E){let[p,x]=E,_=g[c].weight,O=i.get(p),K=i.get(x);O!==void 0&&K!==void 0&&i.get(p)!==Number.MAX_SAFE_INTEGER&&O+_<K&&(i.set(x,O+_),r&&u.set(x,p))}}let k;if(n&&i.forEach((b,c)=>{c!==s&&b<m&&(m=b,r&&(k=c))}),r)for(let b of f){let c=b[1];if(c instanceof R){let E=[c],p=u.get(c);for(;p!==void 0;)E.push(p),p=u.get(p);let x=E.reverse();b[1]===k&&(d=x),o.push(x)}}for(let b=0;b<M;++b){let c=this.getEndsOfEdge(g[b]);if(c){let[E]=c,p=g[b].weight,x=i.get(E);x&&x!==Number.MAX_SAFE_INTEGER&&x+p<x&&(h=!0)}}return{hasNegativeCycle:h,distMap:i,preMap:u,paths:o,min:m,minPath:d}}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 i=0;i<t;i++)r[o][i]=void 0}for(let o=0;o<t;o++)for(let i=0;i<t;i++)n[o][i]=((s=this.getEdge(e[o][1],e[i][1]))==null?void 0:s.weight)||Number.MAX_SAFE_INTEGER;for(let o=0;o<t;o++)for(let i=0;i<t;i++)for(let u=0;u<t;u++)n[i][u]>n[i][o]+n[o][u]&&(n[i][u]=n[i][o]+n[o][u],r[i][u]=e[o][1]);return{costs:n,predecessor:r}}getCycles(e=!1){let t=[],n=new Set,r=(o,i,u)=>{if(u.has(o)){(!e&&i.length>2||e&&i.length>=2)&&i[0]===o.key&&t.push([...i]);return}u.add(o),i.push(o.key);for(let m of this.getNeighbors(o))m&&r(m,i,u);u.delete(o),i.pop()};for(let o of this.vertexMap.values())r(o,[],n);let s=new Map;for(let o of t){let i=[...o].sort().toString();s.has(i)||s.set(i,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[i,u]=o,m=i.key,d=u.key,h=typeof n.hasVertex=="function"?n.hasVertex(m):!1,f=typeof n.hasVertex=="function"?n.hasVertex(d):!1;if(h&&f){let V=n.createEdge(m,d,s.weight,s.value);n._addEdge(V)}}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 R?e.key:e}get _edgeConnector(){return"--"}toVisual(e){var i;let t=(i=e==null?void 0:e.showWeight)!=null?i:!0,n=[...this._vertexMap.values()],r=n.length,s=this.edgeSet().length,o=[`Graph (${r} vertices, ${s} edges):`];for(let u of n){let m=this.getNeighbors(u);if(m.length===0)o.push(` ${u.key} (isolated)`);else{let d=m.map(h=>{let f=this.getEdge(u,h);return f&&t&&f.weight!==void 0&&f.weight!==1?`${h.key} (${f.weight})`:`${h.key}`});o.push(` ${u.key} ${this._edgeConnector} ${d.join(", ")}`)}}return o.join(`
2
2
  `)}toDot(e){var m,d;let t=(m=e==null?void 0:e.name)!=null?m:"G",n=(d=e==null?void 0:e.showWeight)!=null?d:!0,r=this._edgeConnector==="->",s=r?"digraph":"graph",o=r?"->":"--",i=[`${s} ${t} {`];for(let h of this._vertexMap.values())i.push(` "${h.key}";`);let u=new Set;for(let h of this._vertexMap.values())for(let f of this.getNeighbors(h)){let V=r?`${h.key}->${f.key}`:[h.key,f.key].sort().join("--");if(u.has(V))continue;u.add(V);let g=this.getEdge(h,f),M=g&&n&&g.weight!==void 0&&g.weight!==1?` [label="${g.weight}"]`:"";i.push(` "${h.key}" ${o} "${f.key}"${M};`)}return i.push("}"),i.join(`
3
3
  `)}print(e){console.log(this.toVisual(e))}};var U=class extends R{constructor(a,e){super(a,e)}},$=class extends N{constructor(e,t,n,r){super(n,r);y(this,"endpoints");this.endpoints=[e,t]}},j=class l extends S{constructor(e){super(e);y(this,"_edgeMap");this._edgeMap=new Map}get edgeMap(){return this._edgeMap}set edgeMap(e){this._edgeMap=e}static fromKeys(e){let t=new l({vertexValueInitializer:n=>n});for(let n of e)t.addVertex(n);return t}static fromEntries(e){let t=new l;for(let[n,r]of e)t.addVertex(n,r);return t}createVertex(e,t){return new U(e,t)}createEdge(e,t,n,r){var s;return new $(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(i=>i.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=H(s,u=>u.endpoints.includes(r.key))[0]||void 0);let i=this._edgeMap.get(r);return i&&H(i,u=>u.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 i=o.filter(u=>!u.endpoints.includes(t));this._edgeMap.set(s,i)}}),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(i=>i!==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=(i,u)=>{e.set(i,s),t.set(i,s),s++;let m=this.getNeighbors(i),d=0;for(let h of m)if(e.has(h))h!==u&&t.set(i,Math.min(t.get(i),e.get(h)));else{if(d++,o(h,i),t.set(i,Math.min(t.get(i),t.get(h))),t.get(h)>e.get(i)){let f=this.getEdge(i,h);f&&n.push(f)}u!==void 0&&t.get(h)>=e.get(i)&&r.push(i)}u===void 0&&d>1&&r.push(i)};for(let i of this.vertexMap.values())e.has(i)||o(i,void 0);return{dfnMap:e,lowMap:t,bridges:n,cutVertices:r}}getBiconnectedComponents(){let e=new Map,t=new Map,n=[],r=[],s=0,o=(i,u)=>{e.set(i,s),t.set(i,s),s++;let m=this.getNeighbors(i),d=0;for(let h of m){let f=this.getEdge(i,h);if(f){if(e.has(h))h!==u&&e.get(h)<e.get(i)&&(n.push(f),t.set(i,Math.min(t.get(i),e.get(h))));else if(d++,n.push(f),o(h,i),t.set(i,Math.min(t.get(i),t.get(h))),u===void 0&&d>1||u!==void 0&&t.get(h)>=e.get(i)){let V=[],g;do g=n.pop(),g&&V.push(g);while(g&&g!==f);V.length>0&&r.push(V)}}}};for(let i of this.vertexMap.values())e.has(i)||(o(i,void 0),n.length>0&&(r.push([...n]),n.length=0));return r}hasCycle(){let e=new Set,t=(n,r)=>{e.add(n);for(let s of this.getNeighbors(n))if(e.has(s)){if(s!==r)return!0}else if(t(s,n))return!0;return!1};for(let n of this.vertexMap.values())if(!e.has(n)&&t(n,void 0))return!0;return!1}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}};return J(Y);})();
4
4
  /**