directed-graph-typed 2.5.2 → 2.5.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.
Files changed (59) hide show
  1. package/dist/cjs/index.cjs +212 -14
  2. package/dist/cjs/index.cjs.map +1 -1
  3. package/dist/cjs-legacy/index.cjs +212 -14
  4. package/dist/cjs-legacy/index.cjs.map +1 -1
  5. package/dist/esm/index.mjs +212 -14
  6. package/dist/esm/index.mjs.map +1 -1
  7. package/dist/esm-legacy/index.mjs +212 -14
  8. package/dist/esm-legacy/index.mjs.map +1 -1
  9. package/dist/types/data-structures/binary-tree/avl-tree.d.ts +50 -2
  10. package/dist/types/data-structures/binary-tree/binary-indexed-tree.d.ts +56 -0
  11. package/dist/types/data-structures/binary-tree/binary-tree.d.ts +116 -15
  12. package/dist/types/data-structures/binary-tree/bst.d.ts +99 -3
  13. package/dist/types/data-structures/binary-tree/red-black-tree.d.ts +79 -8
  14. package/dist/types/data-structures/binary-tree/segment-tree.d.ts +24 -0
  15. package/dist/types/data-structures/binary-tree/tree-map.d.ts +520 -1
  16. package/dist/types/data-structures/binary-tree/tree-multi-map.d.ts +489 -1
  17. package/dist/types/data-structures/binary-tree/tree-multi-set.d.ts +393 -1
  18. package/dist/types/data-structures/binary-tree/tree-set.d.ts +500 -1
  19. package/dist/types/data-structures/graph/directed-graph.d.ts +40 -0
  20. package/dist/types/data-structures/graph/undirected-graph.d.ts +36 -0
  21. package/dist/types/data-structures/hash/hash-map.d.ts +51 -6
  22. package/dist/types/data-structures/heap/heap.d.ts +98 -12
  23. package/dist/types/data-structures/linked-list/doubly-linked-list.d.ts +75 -0
  24. package/dist/types/data-structures/linked-list/singly-linked-list.d.ts +61 -1
  25. package/dist/types/data-structures/linked-list/skip-linked-list.d.ts +72 -0
  26. package/dist/types/data-structures/matrix/matrix.d.ts +32 -0
  27. package/dist/types/data-structures/queue/deque.d.ts +82 -0
  28. package/dist/types/data-structures/queue/queue.d.ts +61 -0
  29. package/dist/types/data-structures/stack/stack.d.ts +42 -2
  30. package/dist/types/data-structures/trie/trie.d.ts +48 -0
  31. package/dist/types/interfaces/binary-tree.d.ts +2 -3
  32. package/dist/umd/directed-graph-typed.js +212 -14
  33. package/dist/umd/directed-graph-typed.js.map +1 -1
  34. package/dist/umd/directed-graph-typed.min.js +1 -1
  35. package/dist/umd/directed-graph-typed.min.js.map +1 -1
  36. package/package.json +2 -2
  37. package/src/data-structures/binary-tree/avl-tree.ts +52 -5
  38. package/src/data-structures/binary-tree/binary-indexed-tree.ts +56 -0
  39. package/src/data-structures/binary-tree/binary-tree.ts +167 -81
  40. package/src/data-structures/binary-tree/bst.ts +101 -7
  41. package/src/data-structures/binary-tree/red-black-tree.ts +82 -15
  42. package/src/data-structures/binary-tree/segment-tree.ts +24 -0
  43. package/src/data-structures/binary-tree/tree-map.ts +540 -3
  44. package/src/data-structures/binary-tree/tree-multi-map.ts +490 -2
  45. package/src/data-structures/binary-tree/tree-multi-set.ts +393 -1
  46. package/src/data-structures/binary-tree/tree-set.ts +520 -3
  47. package/src/data-structures/graph/directed-graph.ts +41 -1
  48. package/src/data-structures/graph/undirected-graph.ts +37 -1
  49. package/src/data-structures/hash/hash-map.ts +67 -12
  50. package/src/data-structures/heap/heap.ts +107 -19
  51. package/src/data-structures/linked-list/doubly-linked-list.ts +88 -0
  52. package/src/data-structures/linked-list/singly-linked-list.ts +61 -1
  53. package/src/data-structures/linked-list/skip-linked-list.ts +72 -0
  54. package/src/data-structures/matrix/matrix.ts +32 -0
  55. package/src/data-structures/queue/deque.ts +85 -0
  56. package/src/data-structures/queue/queue.ts +73 -0
  57. package/src/data-structures/stack/stack.ts +45 -5
  58. package/src/data-structures/trie/trie.ts +48 -0
  59. package/src/interfaces/binary-tree.ts +1 -9
@@ -1,4 +1,4 @@
1
- "use strict";var directedGraphTyped=(()=>{var S=Object.defineProperty;var P=Object.getOwnPropertyDescriptor;var W=Object.getOwnPropertyNames;var B=Object.prototype.hasOwnProperty;var q=(u,o,e)=>o in u?S(u,o,{enumerable:!0,configurable:!0,writable:!0,value:e}):u[o]=e;var Q=(u,o)=>{for(var e in o)S(u,e,{get:o[e],enumerable:!0})},X=(u,o,e,t)=>{if(o&&typeof o=="object"||typeof o=="function")for(let n of W(o))!B.call(u,n)&&n!==e&&S(u,n,{get:()=>o[n],enumerable:!(t=P(o,n))||t.enumerable});return u};var J=u=>X(S({},"__esModule",{value:!0}),u);var V=(u,o,e)=>q(u,typeof o!="symbol"?o+"":o,e);var Y={};Q(Y,{AbstractEdge:()=>I,AbstractGraph:()=>T,AbstractVertex:()=>_,DFSOperation:()=>z,DirectedEdge:()=>H,DirectedGraph:()=>G,DirectedVertex:()=>A,ERR:()=>w,Range:()=>U,raise:()=>v});var j=function(){return"xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx".replace(/[x]/g,function(u){let o=Math.random()*16|0;return(u=="x"?o:o&3|8).toString(16)})},N=function(u,o){let e=-1,t=u?u.length:0,n=[];for(;++e<t;){let r=u[e];o(r,e,u)&&(n.push(r),Array.prototype.splice.call(u,e--,1),t--)}return n};function v(u,o){throw new u(o)}var w={indexOutOfRange:(u,o,e,t)=>`${t?t+": ":""}Index ${u} is out of range [${o}, ${e}].`,invalidIndex:u=>`${u?u+": ":""}Index must be an integer.`,invalidArgument:(u,o)=>`${o?o+": ":""}${u}`,comparatorRequired:u=>`${u?u+": ":""}Comparator is required for non-number/non-string/non-Date keys.`,invalidKey:(u,o)=>`${o?o+": ":""}${u}`,notAFunction:(u,o)=>`${o?o+": ":""}${u} must be a function.`,invalidEntry:u=>`${u?u+": ":""}Each entry must be a [key, value] tuple.`,invalidNaN:u=>`${u?u+": ":""}NaN is not a valid key.`,invalidDate:u=>`${u?u+": ":""}Invalid Date key.`,reduceEmpty:u=>`${u?u+": ":""}Reduce of empty structure with no initial value.`,callbackReturnType:(u,o,e)=>`${e?e+": ":""}Callback must return ${u}; got ${o}.`,invalidOperation:(u,o)=>`${o?o+": ":""}${u}`,matrixDimensionMismatch:u=>`Matrix: Dimensions must be compatible for ${u}.`,matrixSingular:()=>"Matrix: Singular matrix, inverse does not exist.",matrixNotSquare:()=>"Matrix: Must be square for inversion.",matrixNotRectangular:()=>"Matrix: Must be rectangular for transposition.",matrixRowMismatch:(u,o)=>`Matrix: Expected row length ${u}, but got ${o}.`,orderStatisticNotEnabled:(u,o)=>`${o?o+": ":""}${u}() requires enableOrderStatistic: true.`};var z=(e=>(e[e.VISIT=0]="VISIT",e[e.PROCESS=1]="PROCESS",e))(z||{}),U=class{constructor(o,e,t=!0,n=!0){this.low=o;this.high=e;this.includeLow=t;this.includeHigh=n}isInRange(o,e){let t=this.includeLow?e(o,this.low)>=0:e(o,this.low)>0,n=this.includeHigh?e(o,this.high)<=0:e(o,this.high)<0;return t&&n}};var L=class{*[Symbol.iterator](...o){yield*this._getIterator(...o)}*entries(){for(let o of this)yield o}*keys(){for(let o of this)yield o[0]}*values(){for(let o of this)yield o[1]}every(o,e){let t=0;for(let n of this)if(!o.call(e,n[1],n[0],t++,this))return!1;return!0}some(o,e){let t=0;for(let n of this)if(o.call(e,n[1],n[0],t++,this))return!0;return!1}forEach(o,e){let t=0;for(let n of this){let[r,s]=n;o.call(e,s,r,t++,this)}}find(o,e){let t=0;for(let n of this){let[r,s]=n;if(o.call(e,s,r,t++,this))return n}}has(o){for(let e of this){let[t]=e;if(t===o)return!0}return!1}hasValue(o){for(let[,e]of this)if(e===o)return!0;return!1}get(o){for(let e of this){let[t,n]=e;if(t===o)return n}}reduce(o,e){let t=e,n=0;for(let r of this){let[s,i]=r;t=o(t,i,s,n++,this)}return t}toArray(){return[...this]}toVisual(){return[...this]}print(){console.log(this.toVisual())}};var K=class{constructor(o){V(this,"_toElementFn");if(o){let{toElementFn:e}=o;typeof e=="function"?this._toElementFn=e:e&&v(TypeError,"toElementFn must be a function type")}}get toElementFn(){return this._toElementFn}*[Symbol.iterator](...o){yield*this._getIterator(...o)}*values(){for(let o of this)yield o}every(o,e){let t=0;for(let n of this)if(e===void 0){if(!o(n,t++,this))return!1}else if(!o.call(e,n,t++,this))return!1;return!0}some(o,e){let t=0;for(let n of this)if(e===void 0){if(o(n,t++,this))return!0}else if(o.call(e,n,t++,this))return!0;return!1}forEach(o,e){let t=0;for(let n of this)e===void 0?o(n,t++,this):o.call(e,n,t++,this)}find(o,e){let t=0;for(let n of this)if(e===void 0){if(o(n,t++,this))return n}else if(o.call(e,n,t++,this))return n}has(o){for(let e of this)if(e===o)return!0;return!1}reduce(o,e){let t=0,n=this[Symbol.iterator](),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=o(r,s,t++,this);return r}toArray(){return[...this]}toVisual(){return[...this]}print(){console.log(this.toVisual())}};var F=class u extends K{constructor(e){super(e);V(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 u?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 i=this.deleteAt(e);i!==void 0&&r.push(i)}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 D=class u extends K{constructor(e=[],t){super(t);V(this,"_equals",Object.is);V(this,"_elements",[]);V(this,"_DEFAULT_COMPARATOR",(e,t)=>((typeof e=="object"||typeof t=="object")&&v(TypeError,w.comparatorRequired("Heap")),e>t?1:e<t?-1:0));V(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 u(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,i=s+1;r<this.size&&(e==="IN"?(n(s),t.push(this.elements[r]),n(i)):e==="PRE"?(t.push(this.elements[r]),n(s),n(i)):e==="POST"&&(n(s),n(i),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,...i}=t!=null?t:{};r||v(TypeError,w.comparatorRequired("Heap.map"));let a=this._createLike([],{...i,comparator:r,toElementFn:s}),l=0;for(let f of this){let h=n===void 0?e(f,l++,this):e.call(n,f,l++,this);a.add(h)}return a}mapSame(e,t){let n=this._createInstance(),r=0;for(let s of this){let i=t===void 0?e(s,r++,this):e.call(t,s,r++,this);n.add(i)}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,i=this.elements[r];if(s<this.elements.length&&this.comparator(i,this.elements[s])>0&&(r=s,i=this.elements[s]),this.comparator(i,n)>=0)break;this.elements[e]=i,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 $=class u extends F{constructor(e=[],t){super(t);V(this,"_elements",[]);V(this,"_offset",0);V(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 u(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 i=this._createInstance({toElementFn:this.toElementFn,maxLen:this._maxLen});return i._setAutoCompactRatio(this._autoCompactRatio),i.pushMany(s),i}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 i,a;let r=new this.constructor([],{toElementFn:t==null?void 0:t.toElementFn,maxLen:(i=t==null?void 0:t.maxLen)!=null?i:this._maxLen,autoCompactRatio:(a=t==null?void 0:t.autoCompactRatio)!=null?a:this._autoCompactRatio}),s=0;for(let l of this)r.push(n===void 0?e(l,s++,this):e.call(n,l,s++,this));return r}mapSame(e,t){var i;let n=this.constructor,r=new n([],{toElementFn:this.toElementFn,maxLen:this._maxLen,autoCompactRatio:this._autoCompactRatio});(i=r._setAutoCompactRatio)==null||i.call(r,this._autoCompactRatio);let s=0;for(let a of this){let l=t===void 0?e(a,s++,this):e.call(t,a,s++,this);r.push(l)}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 _=class{constructor(o,e){V(this,"key");V(this,"value");this.key=o,this.value=e}},I=class{constructor(o,e){V(this,"value");V(this,"weight");V(this,"_hashCode");this.weight=o!==void 0?o:1,this.value=e,this._hashCode=j()}get hashCode(){return this._hashCode}},T=class extends L{constructor(e){super();V(this,"_options",{defaultEdgeWeight:1});V(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 _)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 I)return this._addEdge(e);if(t instanceof _||typeof t=="string"||typeof t=="number"){if(!(this.hasVertex(e)&&this.hasVertex(t)))return!1;e instanceof _&&(e=e.key),t instanceof _&&(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),i=this._getVertex(t);if(!(s&&i))return[];let a=[];for(a.push({vertex:s,path:[s]});a.length>0;){let{vertex:l,path:f}=a.pop();if(l===i&&(r.push(f),r.length>=n))return r;let h=this.getNeighbors(l);for(let d of h)if(!f.includes(d)){let m=[...f,d];a.push({vertex:d,path:m})}}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 i of r)s=Math.min(this.getPathSumWeight(i),s);return s}else{let r=this._getVertex(t),s=this._getVertex(e);if(!(s&&r))return;let i=new Map,a=new $([s]);i.set(s,!0);let l=0;for(;a.length>0;){for(let f=0,h=a.length;f<h;f++){let d=a.shift();if(d===r)return l;if(d!==void 0){let m=this.getNeighbors(d);for(let b of m)i.has(b)||(i.set(b,!0),a.push(b))}}l++}return}}getMinPathBetween(e,t,n,r=!1){var s,i;if(n===void 0&&(n=!1),n)if(r){let a=this.getAllPathsBetween(e,t,1e4),l=Number.MAX_SAFE_INTEGER,f=-1,h=0;for(let d of a){let m=this.getPathSumWeight(d);m<l&&(l=m,f=h),h++}return a[f]||void 0}else return(i=(s=this.dijkstra(e,t,!0,!0))==null?void 0:s.minPath)!=null?i:[];else{let a=[],l=this._getVertex(e),f=this._getVertex(t);if(!(l&&f))return[];let h=(d,m,b,x)=>{if(b.add(d),d===m){a=[l,...x];return}let M=this.getNeighbors(d);for(let k of M)b.has(k)||(x.push(k),h(k,m,b,x),x.pop());b.delete(d)};return h(l,f,new Set,[]),a}}dijkstraWithoutHeap(e,t=void 0,n=!1,r=!1){let s=Number.MAX_SAFE_INTEGER,i,a=[],l=[],f=this._vertexMap,h=new Map,d=new Set,m=new Map,b=this._getVertex(e),x=t?this._getVertex(t):void 0;if(!b)return;for(let g of f){let c=g[1];c instanceof _&&h.set(c,Number.MAX_SAFE_INTEGER)}h.set(b,0),m.set(b,void 0);let M=()=>{let g=Number.MAX_SAFE_INTEGER,c;for(let[E,p]of h)d.has(E)||p<g&&(g=p,c=E);return c},k=g=>{for(let c of f){let E=c[1];if(E instanceof _){let p=[E],O=m.get(E);for(;O;)p.push(O),O=m.get(O);let y=p.reverse();c[1]===g&&(a=y),l.push(y)}}};for(let g=1;g<f.size;g++){let c=M();if(c){if(d.add(c),x&&x===c)return n&&(s=h.get(x)||Number.MAX_SAFE_INTEGER),r&&k(x),{distMap:h,preMap:m,seen:d,paths:l,minDist:s,minPath:a};let E=this.getNeighbors(c);for(let p of E)if(!d.has(p)){let O=this.getEdge(c,p);if(O){let y=h.get(c),R=h.get(p);y!==void 0&&R!==void 0&&O.weight+y<R&&(h.set(p,O.weight+y),m.set(p,c))}}}}return n&&h.forEach((g,c)=>{c!==b&&g<s&&(s=g,r&&(i=c))}),r&&k(i),{distMap:h,preMap:m,seen:d,paths:l,minDist:s,minPath:a}}dijkstra(e,t=void 0,n=!1,r=!1){var g;let s=Number.MAX_SAFE_INTEGER,i,a=[],l=[],f=this._vertexMap,h=new Map,d=new Set,m=new Map,b=this._getVertex(e),x=t?this._getVertex(t):void 0;if(!b)return;for(let c of f){let E=c[1];E instanceof _&&h.set(E,Number.MAX_SAFE_INTEGER)}let M=new D([],{comparator:(c,E)=>c.key-E.key});M.add({key:0,value:b}),h.set(b,0),m.set(b,void 0);let k=c=>{for(let E of f){let p=E[1];if(p instanceof _){let O=[p],y=m.get(p);for(;y;)O.push(y),y=m.get(y);let R=O.reverse();E[1]===c&&(a=R),l.push(R)}}};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(d.add(p),x&&x===p)return n&&(s=h.get(x)||Number.MAX_SAFE_INTEGER),r&&k(x),{distMap:h,preMap:m,seen:d,paths:l,minDist:s,minPath:a};let O=this.getNeighbors(p);for(let y of O)if(!d.has(y)){let R=(g=this.getEdge(p,y))==null?void 0:g.weight;if(typeof R=="number"){let C=h.get(y);C!==void 0&&E+R<C&&(M.add({key:E+R,value:y}),m.set(y,p),h.set(y,E+R))}}}}return n&&h.forEach((c,E)=>{E!==b&&c<s&&(s=c,r&&(i=E))}),r&&k(i),{distMap:h,preMap:m,seen:d,paths:l,minDist:s,minPath:a}}bellmanFord(e,t,n,r){n===void 0&&(n=!1),r===void 0&&(r=!1);let s=this._getVertex(e),i=[],a=new Map,l=new Map,f=Number.MAX_SAFE_INTEGER,h=[],d;if(t&&(d=!1),!s)return{hasNegativeCycle:d,distMap:a,preMap:l,paths:i,min:f,minPath:h};let m=this._vertexMap,b=m.size,x=this.edgeSet(),M=x.length;this._vertexMap.forEach(g=>{a.set(g,Number.MAX_SAFE_INTEGER)}),a.set(s,0);for(let g=1;g<b;++g)for(let c=0;c<M;++c){let E=this.getEndsOfEdge(x[c]);if(E){let[p,O]=E,y=x[c].weight,R=a.get(p),C=a.get(O);R!==void 0&&C!==void 0&&a.get(p)!==Number.MAX_SAFE_INTEGER&&R+y<C&&(a.set(O,R+y),r&&l.set(O,p))}}let k;if(n&&a.forEach((g,c)=>{c!==s&&g<f&&(f=g,r&&(k=c))}),r)for(let g of m){let c=g[1];if(c instanceof _){let E=[c],p=l.get(c);for(;p!==void 0;)E.push(p),p=l.get(p);let O=E.reverse();g[1]===k&&(h=O),i.push(O)}}for(let g=0;g<M;++g){let c=this.getEndsOfEdge(x[g]);if(c){let[E]=c,p=x[g].weight,O=a.get(E);O&&O!==Number.MAX_SAFE_INTEGER&&O+p<O&&(d=!0)}}return{hasNegativeCycle:d,distMap:a,preMap:l,paths:i,min:f,minPath:h}}floydWarshall(){var s;let e=[...this._vertexMap],t=e.length,n=[],r=[];for(let i=0;i<t;i++){n[i]=[],r[i]=[];for(let a=0;a<t;a++)r[i][a]=void 0}for(let i=0;i<t;i++)for(let a=0;a<t;a++)n[i][a]=((s=this.getEdge(e[i][1],e[a][1]))==null?void 0:s.weight)||Number.MAX_SAFE_INTEGER;for(let i=0;i<t;i++)for(let a=0;a<t;a++)for(let l=0;l<t;l++)n[a][l]>n[a][i]+n[i][l]&&(n[a][l]=n[a][i]+n[i][l],r[a][l]=e[i][1]);return{costs:n,predecessor:r}}getCycles(e=!1){let t=[],n=new Set,r=(i,a,l)=>{if(l.has(i)){(!e&&a.length>2||e&&a.length>=2)&&a[0]===i.key&&t.push([...a]);return}l.add(i),a.push(i.key);for(let f of this.getNeighbors(i))f&&r(f,a,l);l.delete(i),a.pop()};for(let i of this.vertexMap.values())r(i,[],n);let s=new Map;for(let i of t){let a=[...i].sort().toString();s.has(a)||s.set(a,i)}return[...s].map(i=>i[1])}filter(e,t){let n=[],r=0;for(let[s,i]of this)e.call(t,i,s,r,this)&&n.push([s,i]),r++;return this._createLike(n,this._snapshotOptions())}filterEntries(e,t){let n=[],r=0;for(let[s,i]of this)e.call(t,i,s,r,this)&&n.push([s,i]),r++;return n}map(e,t){let n=[],r=0;for(let[s,i]of this)n.push(e.call(t,i,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,i]of e)n.addVertex(s,i);else for(let[s,i]of this)n.addVertex(s,i);let r=this.edgeSet();for(let s of r){let i=this.getEndsOfEdge(s);if(!i)continue;let[a,l]=i,f=a.key,h=l.key,d=typeof n.hasVertex=="function"?n.hasVertex(f):!1,m=typeof n.hasVertex=="function"?n.hasVertex(h):!1;if(d&&m){let b=n.createEdge(f,h,s.weight,s.value);n._addEdge(b)}}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 _?e.key:e}get _edgeConnector(){return"--"}toVisual(e){var a;let t=(a=e==null?void 0:e.showWeight)!=null?a:!0,n=[...this._vertexMap.values()],r=n.length,s=this.edgeSet().length,i=[`Graph (${r} vertices, ${s} edges):`];for(let l of n){let f=this.getNeighbors(l);if(f.length===0)i.push(` ${l.key} (isolated)`);else{let h=f.map(d=>{let m=this.getEdge(l,d);return m&&t&&m.weight!==void 0&&m.weight!==1?`${d.key} (${m.weight})`:`${d.key}`});i.push(` ${l.key} ${this._edgeConnector} ${h.join(", ")}`)}}return i.join(`
1
+ "use strict";var directedGraphTyped=(()=>{var S=Object.defineProperty;var P=Object.getOwnPropertyDescriptor;var W=Object.getOwnPropertyNames;var B=Object.prototype.hasOwnProperty;var q=(u,o,e)=>o in u?S(u,o,{enumerable:!0,configurable:!0,writable:!0,value:e}):u[o]=e;var Q=(u,o)=>{for(var e in o)S(u,e,{get:o[e],enumerable:!0})},X=(u,o,e,t)=>{if(o&&typeof o=="object"||typeof o=="function")for(let n of W(o))!B.call(u,n)&&n!==e&&S(u,n,{get:()=>o[n],enumerable:!(t=P(o,n))||t.enumerable});return u};var J=u=>X(S({},"__esModule",{value:!0}),u);var V=(u,o,e)=>q(u,typeof o!="symbol"?o+"":o,e);var Y={};Q(Y,{AbstractEdge:()=>I,AbstractGraph:()=>T,AbstractVertex:()=>_,DFSOperation:()=>z,DirectedEdge:()=>H,DirectedGraph:()=>G,DirectedVertex:()=>A,ERR:()=>w,Range:()=>U,raise:()=>v});var j=function(){return"xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx".replace(/[x]/g,function(u){let o=Math.random()*16|0;return(u=="x"?o:o&3|8).toString(16)})},N=function(u,o){let e=-1,t=u?u.length:0,n=[];for(;++e<t;){let r=u[e];o(r,e,u)&&(n.push(r),Array.prototype.splice.call(u,e--,1),t--)}return n};function v(u,o){throw new u(o)}var w={indexOutOfRange:(u,o,e,t)=>`${t?t+": ":""}Index ${u} is out of range [${o}, ${e}].`,invalidIndex:u=>`${u?u+": ":""}Index must be an integer.`,invalidArgument:(u,o)=>`${o?o+": ":""}${u}`,comparatorRequired:u=>`${u?u+": ":""}Comparator is required for non-number/non-string/non-Date keys.`,invalidKey:(u,o)=>`${o?o+": ":""}${u}`,notAFunction:(u,o)=>`${o?o+": ":""}${u} must be a function.`,invalidEntry:u=>`${u?u+": ":""}Each entry must be a [key, value] tuple.`,invalidNaN:u=>`${u?u+": ":""}NaN is not a valid key.`,invalidDate:u=>`${u?u+": ":""}Invalid Date key.`,reduceEmpty:u=>`${u?u+": ":""}Reduce of empty structure with no initial value.`,callbackReturnType:(u,o,e)=>`${e?e+": ":""}Callback must return ${u}; got ${o}.`,invalidOperation:(u,o)=>`${o?o+": ":""}${u}`,matrixDimensionMismatch:u=>`Matrix: Dimensions must be compatible for ${u}.`,matrixSingular:()=>"Matrix: Singular matrix, inverse does not exist.",matrixNotSquare:()=>"Matrix: Must be square for inversion.",matrixNotRectangular:()=>"Matrix: Must be rectangular for transposition.",matrixRowMismatch:(u,o)=>`Matrix: Expected row length ${u}, but got ${o}.`,orderStatisticNotEnabled:(u,o)=>`${o?o+": ":""}${u}() requires enableOrderStatistic: true.`};var z=(e=>(e[e.VISIT=0]="VISIT",e[e.PROCESS=1]="PROCESS",e))(z||{}),U=class{constructor(o,e,t=!0,n=!0){this.low=o;this.high=e;this.includeLow=t;this.includeHigh=n}isInRange(o,e){let t=this.includeLow?e(o,this.low)>=0:e(o,this.low)>0,n=this.includeHigh?e(o,this.high)<=0:e(o,this.high)<0;return t&&n}};var L=class{*[Symbol.iterator](...o){yield*this._getIterator(...o)}*entries(){for(let o of this)yield o}*keys(){for(let o of this)yield o[0]}*values(){for(let o of this)yield o[1]}every(o,e){let t=0;for(let n of this)if(!o.call(e,n[1],n[0],t++,this))return!1;return!0}some(o,e){let t=0;for(let n of this)if(o.call(e,n[1],n[0],t++,this))return!0;return!1}forEach(o,e){let t=0;for(let n of this){let[r,s]=n;o.call(e,s,r,t++,this)}}find(o,e){let t=0;for(let n of this){let[r,s]=n;if(o.call(e,s,r,t++,this))return n}}has(o){for(let e of this){let[t]=e;if(t===o)return!0}return!1}hasValue(o){for(let[,e]of this)if(e===o)return!0;return!1}get(o){for(let e of this){let[t,n]=e;if(t===o)return n}}reduce(o,e){let t=e,n=0;for(let r of this){let[s,i]=r;t=o(t,i,s,n++,this)}return t}toArray(){return[...this]}toVisual(){return[...this]}print(){console.log(this.toVisual())}};var K=class{constructor(o){V(this,"_toElementFn");if(o){let{toElementFn:e}=o;typeof e=="function"?this._toElementFn=e:e&&v(TypeError,"toElementFn must be a function type")}}get toElementFn(){return this._toElementFn}*[Symbol.iterator](...o){yield*this._getIterator(...o)}*values(){for(let o of this)yield o}every(o,e){let t=0;for(let n of this)if(e===void 0){if(!o(n,t++,this))return!1}else if(!o.call(e,n,t++,this))return!1;return!0}some(o,e){let t=0;for(let n of this)if(e===void 0){if(o(n,t++,this))return!0}else if(o.call(e,n,t++,this))return!0;return!1}forEach(o,e){let t=0;for(let n of this)e===void 0?o(n,t++,this):o.call(e,n,t++,this)}find(o,e){let t=0;for(let n of this)if(e===void 0){if(o(n,t++,this))return n}else if(o.call(e,n,t++,this))return n}has(o){for(let e of this)if(e===o)return!0;return!1}reduce(o,e){let t=0,n=this[Symbol.iterator](),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=o(r,s,t++,this);return r}toArray(){return[...this]}toVisual(){return[...this]}print(){console.log(this.toVisual())}};var F=class u extends K{constructor(e){super(e);V(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 u?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 i=this.deleteAt(e);i!==void 0&&r.push(i)}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 D=class u extends K{constructor(e=[],t){super(t);V(this,"_equals",Object.is);V(this,"_elements",[]);V(this,"_DEFAULT_COMPARATOR",(e,t)=>((typeof e=="object"||typeof t=="object")&&v(TypeError,w.comparatorRequired("Heap")),e>t?1:e<t?-1:0));V(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 u(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,i=s+1;r<this.size&&(e==="IN"?(n(s),t.push(this.elements[r]),n(i)):e==="PRE"?(t.push(this.elements[r]),n(s),n(i)):e==="POST"&&(n(s),n(i),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,...i}=t!=null?t:{};r||v(TypeError,w.comparatorRequired("Heap.map"));let a=this._createLike([],{...i,comparator:r,toElementFn:s}),l=0;for(let f of this){let h=n===void 0?e(f,l++,this):e.call(n,f,l++,this);a.add(h)}return a}mapSame(e,t){let n=this._createInstance(),r=0;for(let s of this){let i=t===void 0?e(s,r++,this):e.call(t,s,r++,this);n.add(i)}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,i=this.elements[r];if(s<this.elements.length&&this.comparator(i,this.elements[s])>0&&(r=s,i=this.elements[s]),this.comparator(i,n)>=0)break;this.elements[e]=i,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 $=class u extends F{constructor(e=[],t){super(t);V(this,"_elements",[]);V(this,"_offset",0);V(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 u(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 i=this._createInstance({toElementFn:this.toElementFn,maxLen:this._maxLen});return i._setAutoCompactRatio(this._autoCompactRatio),i.pushMany(s),i}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 i,a;let r=new this.constructor([],{toElementFn:t==null?void 0:t.toElementFn,maxLen:(i=t==null?void 0:t.maxLen)!=null?i:this._maxLen,autoCompactRatio:(a=t==null?void 0:t.autoCompactRatio)!=null?a:this._autoCompactRatio}),s=0;for(let l of this)r.push(n===void 0?e(l,s++,this):e.call(n,l,s++,this));return r}mapSame(e,t){var i;let n=this.constructor,r=new n([],{toElementFn:this.toElementFn,maxLen:this._maxLen,autoCompactRatio:this._autoCompactRatio});(i=r._setAutoCompactRatio)==null||i.call(r,this._autoCompactRatio);let s=0;for(let a of this){let l=t===void 0?e(a,s++,this):e.call(t,a,s++,this);r.push(l)}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 _=class{constructor(o,e){V(this,"key");V(this,"value");this.key=o,this.value=e}},I=class{constructor(o,e){V(this,"value");V(this,"weight");V(this,"_hashCode");this.weight=o!==void 0?o:1,this.value=e,this._hashCode=j()}get hashCode(){return this._hashCode}},T=class extends L{constructor(e){super();V(this,"_options",{defaultEdgeWeight:1});V(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 _)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 I)return this._addEdge(e);if(t instanceof _||typeof t=="string"||typeof t=="number"){if(!(this.hasVertex(e)&&this.hasVertex(t)))return!1;e instanceof _&&(e=e.key),t instanceof _&&(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),i=this._getVertex(t);if(!(s&&i))return[];let a=[];for(a.push({vertex:s,path:[s]});a.length>0;){let{vertex:l,path:f}=a.pop();if(l===i&&(r.push(f),r.length>=n))return r;let h=this.getNeighbors(l);for(let d of h)if(!f.includes(d)){let m=[...f,d];a.push({vertex:d,path:m})}}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 i of r)s=Math.min(this.getPathSumWeight(i),s);return s}else{let r=this._getVertex(t),s=this._getVertex(e);if(!(s&&r))return;let i=new Map,a=new $([s]);i.set(s,!0);let l=0;for(;a.length>0;){for(let f=0,h=a.length;f<h;f++){let d=a.shift();if(d===r)return l;if(d!==void 0){let m=this.getNeighbors(d);for(let b of m)i.has(b)||(i.set(b,!0),a.push(b))}}l++}return}}getMinPathBetween(e,t,n,r=!1){var s,i;if(n===void 0&&(n=!1),n)if(r){let a=this.getAllPathsBetween(e,t,1e4),l=Number.MAX_SAFE_INTEGER,f=-1,h=0;for(let d of a){let m=this.getPathSumWeight(d);m<l&&(l=m,f=h),h++}return a[f]||void 0}else return(i=(s=this.dijkstra(e,t,!0,!0))==null?void 0:s.minPath)!=null?i:[];else{let a=[],l=this._getVertex(e),f=this._getVertex(t);if(!(l&&f))return[];let h=(d,m,b,x)=>{if(b.add(d),d===m){a=[l,...x];return}let M=this.getNeighbors(d);for(let k of M)b.has(k)||(x.push(k),h(k,m,b,x),x.pop());b.delete(d)};return h(l,f,new Set,[]),a}}dijkstraWithoutHeap(e,t=void 0,n=!1,r=!1){let s=Number.MAX_SAFE_INTEGER,i,a=[],l=[],f=this._vertexMap,h=new Map,d=new Set,m=new Map,b=this._getVertex(e),x=t?this._getVertex(t):void 0;if(!b)return;for(let g of f){let c=g[1];c instanceof _&&h.set(c,Number.MAX_SAFE_INTEGER)}h.set(b,0),m.set(b,void 0);let M=()=>{let g=Number.MAX_SAFE_INTEGER,c;for(let[E,p]of h)d.has(E)||p<g&&(g=p,c=E);return c},k=g=>{for(let c of f){let E=c[1];if(E instanceof _){let p=[E],O=m.get(E);for(;O;)p.push(O),O=m.get(O);let y=p.reverse();c[1]===g&&(a=y),l.push(y)}}};for(let g=1;g<f.size;g++){let c=M();if(c){if(d.add(c),x&&x===c)return n&&(s=h.get(x)||Number.MAX_SAFE_INTEGER),r&&k(x),{distMap:h,preMap:m,seen:d,paths:l,minDist:s,minPath:a};let E=this.getNeighbors(c);for(let p of E)if(!d.has(p)){let O=this.getEdge(c,p);if(O){let y=h.get(c),R=h.get(p);y!==void 0&&R!==void 0&&O.weight+y<R&&(h.set(p,O.weight+y),m.set(p,c))}}}}return n&&h.forEach((g,c)=>{c!==b&&g<s&&(s=g,r&&(i=c))}),r&&k(i),{distMap:h,preMap:m,seen:d,paths:l,minDist:s,minPath:a}}dijkstra(e,t=void 0,n=!1,r=!1){var g;let s=Number.MAX_SAFE_INTEGER,i,a=[],l=[],f=this._vertexMap,h=new Map,d=new Set,m=new Map,b=this._getVertex(e),x=t?this._getVertex(t):void 0;if(!b)return;for(let c of f){let E=c[1];E instanceof _&&h.set(E,Number.MAX_SAFE_INTEGER)}let M=new D([],{comparator:(c,E)=>c.key-E.key});M.add({key:0,value:b}),h.set(b,0),m.set(b,void 0);let k=c=>{for(let E of f){let p=E[1];if(p instanceof _){let O=[p],y=m.get(p);for(;y;)O.push(y),y=m.get(y);let R=O.reverse();E[1]===c&&(a=R),l.push(R)}}};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(d.add(p),x&&x===p)return n&&(s=h.get(x)||Number.MAX_SAFE_INTEGER),r&&k(x),{distMap:h,preMap:m,seen:d,paths:l,minDist:s,minPath:a};let O=this.getNeighbors(p);for(let y of O)if(!d.has(y)){let R=(g=this.getEdge(p,y))==null?void 0:g.weight;if(typeof R=="number"){let C=h.get(y);C!==void 0&&E+R<C&&(M.add({key:E+R,value:y}),m.set(y,p),h.set(y,E+R))}}}}return n&&h.forEach((c,E)=>{E!==b&&c<s&&(s=c,r&&(i=E))}),r&&k(i),{distMap:h,preMap:m,seen:d,paths:l,minDist:s,minPath:a}}bellmanFord(e,t,n,r){n===void 0&&(n=!1),r===void 0&&(r=!1);let s=this._getVertex(e),i=[],a=new Map,l=new Map,f=Number.MAX_SAFE_INTEGER,h=[],d;if(t&&(d=!1),!s)return{hasNegativeCycle:d,distMap:a,preMap:l,paths:i,min:f,minPath:h};let m=this._vertexMap,b=m.size,x=this.edgeSet(),M=x.length;this._vertexMap.forEach(g=>{a.set(g,Number.MAX_SAFE_INTEGER)}),a.set(s,0);for(let g=1;g<b;++g)for(let c=0;c<M;++c){let E=this.getEndsOfEdge(x[c]);if(E){let[p,O]=E,y=x[c].weight,R=a.get(p),C=a.get(O);R!==void 0&&C!==void 0&&a.get(p)!==Number.MAX_SAFE_INTEGER&&R+y<C&&(a.set(O,R+y),r&&l.set(O,p))}}let k;if(n&&a.forEach((g,c)=>{c!==s&&g<f&&(f=g,r&&(k=c))}),r)for(let g of m){let c=g[1];if(c instanceof _){let E=[c],p=l.get(c);for(;p!==void 0;)E.push(p),p=l.get(p);let O=E.reverse();g[1]===k&&(h=O),i.push(O)}}for(let g=0;g<M;++g){let c=this.getEndsOfEdge(x[g]);if(c){let[E]=c,p=x[g].weight,O=a.get(E);O&&O!==Number.MAX_SAFE_INTEGER&&O+p<O&&(d=!0)}}return{hasNegativeCycle:d,distMap:a,preMap:l,paths:i,min:f,minPath:h}}floydWarshall(){var s;let e=[...this._vertexMap],t=e.length,n=[],r=[];for(let i=0;i<t;i++){n[i]=[],r[i]=[];for(let a=0;a<t;a++)r[i][a]=void 0}for(let i=0;i<t;i++)for(let a=0;a<t;a++)n[i][a]=((s=this.getEdge(e[i][1],e[a][1]))==null?void 0:s.weight)||Number.MAX_SAFE_INTEGER;for(let i=0;i<t;i++)for(let a=0;a<t;a++)for(let l=0;l<t;l++)n[a][l]>n[a][i]+n[i][l]&&(n[a][l]=n[a][i]+n[i][l],r[a][l]=e[i][1]);return{costs:n,predecessor:r}}getCycles(e=!1){let t=[],n=new Set,r=(i,a,l)=>{if(l.has(i)){(!e&&a.length>2||e&&a.length>=2)&&a[0]===i.key&&t.push([...a]);return}l.add(i),a.push(i.key);for(let f of this.getNeighbors(i))f&&r(f,a,l);l.delete(i),a.pop()};for(let i of this.vertexMap.values())r(i,[],n);let s=new Map;for(let i of t){let a=[...i].sort().toString();s.has(a)||s.set(a,i)}return[...s].map(i=>i[1])}filter(e,t){let n=[],r=0;for(let[s,i]of this)e.call(t,i,s,r,this)&&n.push([s,i]),r++;return this._createLike(n,this._snapshotOptions())}filterEntries(e,t){let n=[],r=0;for(let[s,i]of this)e.call(t,i,s,r,this)&&n.push([s,i]),r++;return n}map(e,t){let n=[],r=0;for(let[s,i]of this)n.push(e.call(t,i,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,i]of e)n.addVertex(s,i);else for(let[s,i]of this)n.addVertex(s,i);let r=this.edgeSet();for(let s of r){let i=this.getEndsOfEdge(s);if(!i)continue;let[a,l]=i,f=a.key,h=l.key,d=typeof n.hasVertex=="function"?n.hasVertex(f):!1,m=typeof n.hasVertex=="function"?n.hasVertex(h):!1;if(d&&m){let b=n.createEdge(f,h,s.weight,s.value);n._addEdge(b)}}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 _?e.key:e}get _edgeConnector(){return"--"}toVisual(e){var a;let t=(a=e==null?void 0:e.showWeight)!=null?a:!0,n=[...this._vertexMap.values()],r=n.length,s=this.edgeSet().length,i=[`Graph (${r} vertices, ${s} edges):`];for(let l of n){let f=this.getNeighbors(l);if(f.length===0)i.push(` ${l.key} (isolated)`);else{let h=f.map(d=>{let m=this.getEdge(l,d);return m&&t&&m.weight!==void 0&&m.weight!==1?`${d.key} (${m.weight})`:`${d.key}`});i.push(` ${l.key} ${this._edgeConnector} ${h.join(", ")}`)}}return i.join(`
2
2
  `)}toDot(e){var f,h;let t=(f=e==null?void 0:e.name)!=null?f:"G",n=(h=e==null?void 0:e.showWeight)!=null?h:!0,r=this._edgeConnector==="->",s=r?"digraph":"graph",i=r?"->":"--",a=[`${s} ${t} {`];for(let d of this._vertexMap.values())a.push(` "${d.key}";`);let l=new Set;for(let d of this._vertexMap.values())for(let m of this.getNeighbors(d)){let b=r?`${d.key}->${m.key}`:[d.key,m.key].sort().join("--");if(l.has(b))continue;l.add(b);let x=this.getEdge(d,m),M=x&&n&&x.weight!==void 0&&x.weight!==1?` [label="${x.weight}"]`:"";a.push(` "${d.key}" ${i} "${m.key}"${M};`)}return a.push("}"),a.join(`
3
3
  `)}print(e){console.log(this.toVisual(e))}};var A=class extends _{constructor(o,e){super(o,e)}},H=class extends I{constructor(e,t,n,r){super(n,r);V(this,"src");V(this,"dest");this.src=e,this.dest=t}},G=class u extends T{constructor(e){super(e);V(this,"_outEdgeMap",new Map);V(this,"_inEdgeMap",new Map)}get _edgeConnector(){return"->"}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 u({vertexValueInitializer:n=>n});for(let n of e)t.addVertex(n);return t}static fromEntries(e){let t=new u;for(let[n,r]of e)t.addVertex(n,r);return t}createVertex(e,t){return new A(e,t)}createEdge(e,t,n,r){var s;return new H(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 i=this._outEdgeMap.get(r);i&&(n=i.filter(a=>a.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 i=this._outEdgeMap.get(n);i&&N(i,l=>l.dest===r.key);let a=this._inEdgeMap.get(r);return a&&(s=N(a,l=>l.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 i=this._outEdgeMap.get(r);i&&i.length>0&&N(i,l=>l.src===r.key&&l.dest===(s==null?void 0:s.key));let a=this._inEdgeMap.get(s);a&&a.length>0&&(n=N(a,l=>l.src===r.key&&l.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 i of this.vertexMap)t.set(i[1],0);let n=[],r=!1,s=i=>{t.set(i,1);let a=this.getDestinations(i);for(let l of a){let f=t.get(l);f===0?s(l):f===1&&(r=!0)}t.set(i,2),n.push(i)};for(let i of this.vertexMap)t.get(i[1])===0&&s(i[1]);if(!r)return e==="key"&&(n=n.map(i=>i instanceof A?i.key:i)),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 i=this._getVertex(s.dest);i&&t.push(i)}}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=[],i=new Set,a=l=>{e.set(l,r),t.set(l,r),r++,s.push(l),i.add(l);let f=this.getNeighbors(l);for(let h of f)e.has(h)?i.has(h)&&t.set(l,Math.min(t.get(l),e.get(h))):(a(h),t.set(l,Math.min(t.get(l),t.get(h))));if(e.get(l)===t.get(l)){let h=[],d;do d=s.pop(),i.delete(d),h.push(d);while(d!==l);n.set(n.size,h)}};for(let l of this.vertexMap.values())e.has(l)||a(l);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}};return J(Y);})();
4
4
  /**