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.
- package/dist/cjs/index.cjs +422 -14
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs-legacy/index.cjs +422 -14
- package/dist/cjs-legacy/index.cjs.map +1 -1
- package/dist/esm/index.mjs +422 -14
- package/dist/esm/index.mjs.map +1 -1
- package/dist/esm-legacy/index.mjs +422 -14
- package/dist/esm-legacy/index.mjs.map +1 -1
- package/dist/types/data-structures/base/iterable-element-base.d.ts +17 -0
- package/dist/types/data-structures/base/linear-base.d.ts +6 -0
- package/dist/types/data-structures/binary-tree/avl-tree.d.ts +86 -2
- package/dist/types/data-structures/binary-tree/binary-indexed-tree.d.ts +98 -0
- package/dist/types/data-structures/binary-tree/binary-tree.d.ts +191 -15
- package/dist/types/data-structures/binary-tree/bst.d.ts +171 -3
- package/dist/types/data-structures/binary-tree/red-black-tree.d.ts +136 -8
- package/dist/types/data-structures/binary-tree/segment-tree.d.ts +42 -0
- package/dist/types/data-structures/binary-tree/tree-map.d.ts +1061 -167
- package/dist/types/data-structures/binary-tree/tree-multi-map.d.ts +1232 -355
- package/dist/types/data-structures/binary-tree/tree-multi-set.d.ts +916 -194
- package/dist/types/data-structures/binary-tree/tree-set.d.ts +1078 -141
- package/dist/types/data-structures/graph/directed-graph.d.ts +70 -0
- package/dist/types/data-structures/graph/undirected-graph.d.ts +63 -0
- package/dist/types/data-structures/hash/hash-map.d.ts +84 -6
- package/dist/types/data-structures/heap/heap.d.ts +140 -12
- package/dist/types/data-structures/linked-list/doubly-linked-list.d.ts +150 -2
- package/dist/types/data-structures/linked-list/singly-linked-list.d.ts +106 -1
- package/dist/types/data-structures/linked-list/skip-linked-list.d.ts +126 -0
- package/dist/types/data-structures/matrix/matrix.d.ts +56 -0
- package/dist/types/data-structures/queue/deque.d.ts +171 -0
- package/dist/types/data-structures/queue/queue.d.ts +97 -0
- package/dist/types/data-structures/stack/stack.d.ts +72 -2
- package/dist/types/data-structures/trie/trie.d.ts +84 -0
- package/dist/types/interfaces/binary-tree.d.ts +2 -3
- package/dist/umd/graph-typed.js +422 -14
- package/dist/umd/graph-typed.js.map +1 -1
- package/dist/umd/graph-typed.min.js +2 -2
- package/dist/umd/graph-typed.min.js.map +1 -1
- package/package.json +2 -2
- package/src/data-structures/base/iterable-element-base.ts +32 -0
- package/src/data-structures/base/linear-base.ts +11 -0
- package/src/data-structures/binary-tree/avl-tree.ts +88 -5
- package/src/data-structures/binary-tree/binary-indexed-tree.ts +98 -0
- package/src/data-structures/binary-tree/binary-tree.ts +242 -81
- package/src/data-structures/binary-tree/bst.ts +173 -7
- package/src/data-structures/binary-tree/red-black-tree.ts +139 -15
- package/src/data-structures/binary-tree/segment-tree.ts +42 -0
- package/src/data-structures/binary-tree/tree-map.ts +948 -36
- package/src/data-structures/binary-tree/tree-multi-map.ts +893 -13
- package/src/data-structures/binary-tree/tree-multi-set.ts +761 -33
- package/src/data-structures/binary-tree/tree-set.ts +1260 -251
- package/src/data-structures/graph/directed-graph.ts +71 -1
- package/src/data-structures/graph/undirected-graph.ts +64 -1
- package/src/data-structures/hash/hash-map.ts +100 -12
- package/src/data-structures/heap/heap.ts +149 -19
- package/src/data-structures/linked-list/doubly-linked-list.ts +178 -2
- package/src/data-structures/linked-list/singly-linked-list.ts +106 -1
- package/src/data-structures/linked-list/skip-linked-list.ts +126 -0
- package/src/data-structures/matrix/matrix.ts +56 -0
- package/src/data-structures/queue/deque.ts +187 -0
- package/src/data-structures/queue/queue.ts +109 -0
- package/src/data-structures/stack/stack.ts +75 -5
- package/src/data-structures/trie/trie.ts +84 -0
- package/src/interfaces/binary-tree.ts +1 -9
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
"use strict";var graphTyped=(()=>{var F=Object.defineProperty;var J=Object.getOwnPropertyDescriptor;var Y=Object.getOwnPropertyNames;var Z=Object.prototype.hasOwnProperty;var ee=(l,a,e)=>a in l?F(l,a,{enumerable:!0,configurable:!0,writable:!0,value:e}):l[a]=e;var te=(l,a)=>{for(var e in a)F(l,e,{get:a[e],enumerable:!0})},ne=(l,a,e,t)=>{if(a&&typeof a=="object"||typeof a=="function")for(let n of Y(a))!Z.call(l,n)&&n!==e&&F(l,n,{get:()=>a[n],enumerable:!(t=J(a,n))||t.enumerable});return l};var re=l=>ne(F({},"__esModule",{value:!0}),l);var g=(l,a,e)=>ee(l,typeof a!="symbol"?a+"":a,e);var se={};te(se,{AbstractEdge:()=>K,AbstractGraph:()=>I,AbstractVertex:()=>_,DFSOperation:()=>X,DirectedEdge:()=>A,DirectedGraph:()=>L,DirectedVertex:()=>N,ERR:()=>C,MapEdge:()=>P,MapGraph:()=>q,MapVertex:()=>z,Range:()=>B,UndirectedEdge:()=>j,UndirectedGraph:()=>W,UndirectedVertex:()=>H,raise:()=>w});var Q=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)})},v=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 w(l,a){throw new l(a)}var C={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 X=(e=>(e[e.VISIT=0]="VISIT",e[e.PROCESS=1]="PROCESS",e))(X||{}),B=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 D=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,i]=r;t=a(t,i,s,n++,this)}return t}toArray(){return[...this]}toVisual(){return[...this]}print(){console.log(this.toVisual())}};var T=class{constructor(a){g(this,"_toElementFn");if(a){let{toElementFn:e}=a;typeof e=="function"?this._toElementFn=e:e&&w(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&&w(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 U=class l extends T{constructor(e){super(e);g(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 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 $=class l extends T{constructor(e=[],t){super(t);g(this,"_equals",Object.is);g(this,"_elements",[]);g(this,"_DEFAULT_COMPARATOR",(e,t)=>((typeof e=="object"||typeof t=="object")&&w(TypeError,C.comparatorRequired("Heap")),e>t?1:e<t?-1:0));g(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,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||w(TypeError,C.comparatorRequired("Heap.map"));let o=this._createLike([],{...i,comparator:r,toElementFn:s}),u=0;for(let f of this){let h=n===void 0?e(f,u++,this):e.call(n,f,u++,this);o.add(h)}return o}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 G=class l extends U{constructor(e=[],t){super(t);g(this,"_elements",[]);g(this,"_offset",0);g(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 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,o;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:(o=t==null?void 0:t.autoCompactRatio)!=null?o: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 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 o of this){let u=t===void 0?e(o,s++,this):e.call(t,o,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 _=class{constructor(a,e){g(this,"key");g(this,"value");this.key=a,this.value=e}},K=class{constructor(a,e){g(this,"value");g(this,"weight");g(this,"_hashCode");this.weight=a!==void 0?a:1,this.value=e,this._hashCode=Q()}get hashCode(){return this._hashCode}},I=class extends D{constructor(e){super();g(this,"_options",{defaultEdgeWeight:1});g(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 K)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 w(TypeError,C.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 o=[];for(o.push({vertex:s,path:[s]});o.length>0;){let{vertex:u,path:f}=o.pop();if(u===i&&(r.push(f),r.length>=n))return r;let h=this.getNeighbors(u);for(let d of h)if(!f.includes(d)){let p=[...f,d];o.push({vertex:d,path:p})}}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,o=new G([s]);i.set(s,!0);let u=0;for(;o.length>0;){for(let f=0,h=o.length;f<h;f++){let d=o.shift();if(d===r)return u;if(d!==void 0){let p=this.getNeighbors(d);for(let x of p)i.has(x)||(i.set(x,!0),o.push(x))}}u++}return}}getMinPathBetween(e,t,n,r=!1){var s,i;if(n===void 0&&(n=!1),n)if(r){let o=this.getAllPathsBetween(e,t,1e4),u=Number.MAX_SAFE_INTEGER,f=-1,h=0;for(let d of o){let p=this.getPathSumWeight(d);p<u&&(u=p,f=h),h++}return o[f]||void 0}else return(i=(s=this.dijkstra(e,t,!0,!0))==null?void 0:s.minPath)!=null?i:[];else{let o=[],u=this._getVertex(e),f=this._getVertex(t);if(!(u&&f))return[];let h=(d,p,x,b)=>{if(x.add(d),d===p){o=[u,...b];return}let R=this.getNeighbors(d);for(let k of R)x.has(k)||(b.push(k),h(k,p,x,b),b.pop());x.delete(d)};return h(u,f,new Set,[]),o}}dijkstraWithoutHeap(e,t=void 0,n=!1,r=!1){let s=Number.MAX_SAFE_INTEGER,i,o=[],u=[],f=this._vertexMap,h=new Map,d=new Set,p=new Map,x=this._getVertex(e),b=t?this._getVertex(t):void 0;if(!x)return;for(let V of f){let c=V[1];c instanceof _&&h.set(c,Number.MAX_SAFE_INTEGER)}h.set(x,0),p.set(x,void 0);let R=()=>{let V=Number.MAX_SAFE_INTEGER,c;for(let[E,m]of h)d.has(E)||m<V&&(V=m,c=E);return c},k=V=>{for(let c of f){let E=c[1];if(E instanceof _){let m=[E],O=p.get(E);for(;O;)m.push(O),O=p.get(O);let y=m.reverse();c[1]===V&&(o=y),u.push(y)}}};for(let V=1;V<f.size;V++){let c=R();if(c){if(d.add(c),b&&b===c)return n&&(s=h.get(b)||Number.MAX_SAFE_INTEGER),r&&k(b),{distMap:h,preMap:p,seen:d,paths:u,minDist:s,minPath:o};let E=this.getNeighbors(c);for(let m of E)if(!d.has(m)){let O=this.getEdge(c,m);if(O){let y=h.get(c),M=h.get(m);y!==void 0&&M!==void 0&&O.weight+y<M&&(h.set(m,O.weight+y),p.set(m,c))}}}}return n&&h.forEach((V,c)=>{c!==x&&V<s&&(s=V,r&&(i=c))}),r&&k(i),{distMap:h,preMap:p,seen:d,paths:u,minDist:s,minPath:o}}dijkstra(e,t=void 0,n=!1,r=!1){var V;let s=Number.MAX_SAFE_INTEGER,i,o=[],u=[],f=this._vertexMap,h=new Map,d=new Set,p=new Map,x=this._getVertex(e),b=t?this._getVertex(t):void 0;if(!x)return;for(let c of f){let E=c[1];E instanceof _&&h.set(E,Number.MAX_SAFE_INTEGER)}let R=new $([],{comparator:(c,E)=>c.key-E.key});R.add({key:0,value:x}),h.set(x,0),p.set(x,void 0);let k=c=>{for(let E of f){let m=E[1];if(m instanceof _){let O=[m],y=p.get(m);for(;y;)O.push(y),y=p.get(y);let M=O.reverse();E[1]===c&&(o=M),u.push(M)}}};for(;R.size>0;){let c=R.poll(),E=c==null?void 0:c.key,m=c==null?void 0:c.value;if(E!==void 0&&m){if(d.add(m),b&&b===m)return n&&(s=h.get(b)||Number.MAX_SAFE_INTEGER),r&&k(b),{distMap:h,preMap:p,seen:d,paths:u,minDist:s,minPath:o};let O=this.getNeighbors(m);for(let y of O)if(!d.has(y)){let M=(V=this.getEdge(m,y))==null?void 0:V.weight;if(typeof M=="number"){let S=h.get(y);S!==void 0&&E+M<S&&(R.add({key:E+M,value:y}),p.set(y,m),h.set(y,E+M))}}}}return n&&h.forEach((c,E)=>{E!==x&&c<s&&(s=c,r&&(i=E))}),r&&k(i),{distMap:h,preMap:p,seen:d,paths:u,minDist:s,minPath:o}}bellmanFord(e,t,n,r){n===void 0&&(n=!1),r===void 0&&(r=!1);let s=this._getVertex(e),i=[],o=new Map,u=new Map,f=Number.MAX_SAFE_INTEGER,h=[],d;if(t&&(d=!1),!s)return{hasNegativeCycle:d,distMap:o,preMap:u,paths:i,min:f,minPath:h};let p=this._vertexMap,x=p.size,b=this.edgeSet(),R=b.length;this._vertexMap.forEach(V=>{o.set(V,Number.MAX_SAFE_INTEGER)}),o.set(s,0);for(let V=1;V<x;++V)for(let c=0;c<R;++c){let E=this.getEndsOfEdge(b[c]);if(E){let[m,O]=E,y=b[c].weight,M=o.get(m),S=o.get(O);M!==void 0&&S!==void 0&&o.get(m)!==Number.MAX_SAFE_INTEGER&&M+y<S&&(o.set(O,M+y),r&&u.set(O,m))}}let k;if(n&&o.forEach((V,c)=>{c!==s&&V<f&&(f=V,r&&(k=c))}),r)for(let V of p){let c=V[1];if(c instanceof _){let E=[c],m=u.get(c);for(;m!==void 0;)E.push(m),m=u.get(m);let O=E.reverse();V[1]===k&&(h=O),i.push(O)}}for(let V=0;V<R;++V){let c=this.getEndsOfEdge(b[V]);if(c){let[E]=c,m=b[V].weight,O=o.get(E);O&&O!==Number.MAX_SAFE_INTEGER&&O+m<O&&(d=!0)}}return{hasNegativeCycle:d,distMap:o,preMap:u,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 o=0;o<t;o++)r[i][o]=void 0}for(let i=0;i<t;i++)for(let o=0;o<t;o++)n[i][o]=((s=this.getEdge(e[i][1],e[o][1]))==null?void 0:s.weight)||Number.MAX_SAFE_INTEGER;for(let i=0;i<t;i++)for(let o=0;o<t;o++)for(let u=0;u<t;u++)n[o][u]>n[o][i]+n[i][u]&&(n[o][u]=n[o][i]+n[i][u],r[o][u]=e[i][1]);return{costs:n,predecessor:r}}getCycles(e=!1){let t=[],n=new Set,r=(i,o,u)=>{if(u.has(i)){(!e&&o.length>2||e&&o.length>=2)&&o[0]===i.key&&t.push([...o]);return}u.add(i),o.push(i.key);for(let f of this.getNeighbors(i))f&&r(f,o,u);u.delete(i),o.pop()};for(let i of this.vertexMap.values())r(i,[],n);let s=new Map;for(let i of t){let o=[...i].sort().toString();s.has(o)||s.set(o,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[o,u]=i,f=o.key,h=u.key,d=typeof n.hasVertex=="function"?n.hasVertex(f):!1,p=typeof n.hasVertex=="function"?n.hasVertex(h):!1;if(d&&p){let x=n.createEdge(f,h,s.weight,s.value);n._addEdge(x)}}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 o;let t=(o=e==null?void 0:e.showWeight)!=null?o:!0,n=[...this._vertexMap.values()],r=n.length,s=this.edgeSet().length,i=[`Graph (${r} vertices, ${s} edges):`];for(let u of n){let f=this.getNeighbors(u);if(f.length===0)i.push(` ${u.key} (isolated)`);else{let h=f.map(d=>{let p=this.getEdge(u,d);return p&&t&&p.weight!==void 0&&p.weight!==1?`${d.key} (${p.weight})`:`${d.key}`});i.push(` ${u.key} ${this._edgeConnector} ${h.join(", ")}`)}}return i.join(`
|
|
1
|
+
"use strict";var graphTyped=(()=>{var F=Object.defineProperty;var J=Object.getOwnPropertyDescriptor;var Y=Object.getOwnPropertyNames;var Z=Object.prototype.hasOwnProperty;var ee=(l,a,e)=>a in l?F(l,a,{enumerable:!0,configurable:!0,writable:!0,value:e}):l[a]=e;var te=(l,a)=>{for(var e in a)F(l,e,{get:a[e],enumerable:!0})},ne=(l,a,e,t)=>{if(a&&typeof a=="object"||typeof a=="function")for(let n of Y(a))!Z.call(l,n)&&n!==e&&F(l,n,{get:()=>a[n],enumerable:!(t=J(a,n))||t.enumerable});return l};var re=l=>ne(F({},"__esModule",{value:!0}),l);var g=(l,a,e)=>ee(l,typeof a!="symbol"?a+"":a,e);var se={};te(se,{AbstractEdge:()=>K,AbstractGraph:()=>I,AbstractVertex:()=>_,DFSOperation:()=>X,DirectedEdge:()=>A,DirectedGraph:()=>L,DirectedVertex:()=>N,ERR:()=>C,MapEdge:()=>P,MapGraph:()=>q,MapVertex:()=>z,Range:()=>W,UndirectedEdge:()=>j,UndirectedGraph:()=>B,UndirectedVertex:()=>H,raise:()=>w});var Q=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)})},v=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 w(l,a){throw new l(a)}var C={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 X=(e=>(e[e.VISIT=0]="VISIT",e[e.PROCESS=1]="PROCESS",e))(X||{}),W=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 D=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,i]=r;t=a(t,i,s,n++,this)}return t}toArray(){return[...this]}toVisual(){return[...this]}print(){console.log(this.toVisual())}};var T=class{constructor(a){g(this,"_toElementFn");if(a){let{toElementFn:e}=a;typeof e=="function"?this._toElementFn=e:e&&w(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&&w(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 U=class l extends T{constructor(e){super(e);g(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 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}toReversed(){let e=this.clone();return e.reverse(),e}};var $=class l extends T{constructor(e=[],t){super(t);g(this,"_equals",Object.is);g(this,"_elements",[]);g(this,"_DEFAULT_COMPARATOR",(e,t)=>((typeof e=="object"||typeof t=="object")&&w(TypeError,C.comparatorRequired("Heap")),e>t?1:e<t?-1:0));g(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,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||w(TypeError,C.comparatorRequired("Heap.map"));let o=this._createLike([],{...i,comparator:r,toElementFn:s}),u=0;for(let f of this){let h=n===void 0?e(f,u++,this):e.call(n,f,u++,this);o.add(h)}return o}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 G=class l extends U{constructor(e=[],t){super(t);g(this,"_elements",[]);g(this,"_offset",0);g(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 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,o;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:(o=t==null?void 0:t.autoCompactRatio)!=null?o: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 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 o of this){let u=t===void 0?e(o,s++,this):e.call(t,o,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 _=class{constructor(a,e){g(this,"key");g(this,"value");this.key=a,this.value=e}},K=class{constructor(a,e){g(this,"value");g(this,"weight");g(this,"_hashCode");this.weight=a!==void 0?a:1,this.value=e,this._hashCode=Q()}get hashCode(){return this._hashCode}},I=class extends D{constructor(e){super();g(this,"_options",{defaultEdgeWeight:1});g(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 K)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 w(TypeError,C.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 o=[];for(o.push({vertex:s,path:[s]});o.length>0;){let{vertex:u,path:f}=o.pop();if(u===i&&(r.push(f),r.length>=n))return r;let h=this.getNeighbors(u);for(let d of h)if(!f.includes(d)){let p=[...f,d];o.push({vertex:d,path:p})}}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,o=new G([s]);i.set(s,!0);let u=0;for(;o.length>0;){for(let f=0,h=o.length;f<h;f++){let d=o.shift();if(d===r)return u;if(d!==void 0){let p=this.getNeighbors(d);for(let x of p)i.has(x)||(i.set(x,!0),o.push(x))}}u++}return}}getMinPathBetween(e,t,n,r=!1){var s,i;if(n===void 0&&(n=!1),n)if(r){let o=this.getAllPathsBetween(e,t,1e4),u=Number.MAX_SAFE_INTEGER,f=-1,h=0;for(let d of o){let p=this.getPathSumWeight(d);p<u&&(u=p,f=h),h++}return o[f]||void 0}else return(i=(s=this.dijkstra(e,t,!0,!0))==null?void 0:s.minPath)!=null?i:[];else{let o=[],u=this._getVertex(e),f=this._getVertex(t);if(!(u&&f))return[];let h=(d,p,x,b)=>{if(x.add(d),d===p){o=[u,...b];return}let R=this.getNeighbors(d);for(let k of R)x.has(k)||(b.push(k),h(k,p,x,b),b.pop());x.delete(d)};return h(u,f,new Set,[]),o}}dijkstraWithoutHeap(e,t=void 0,n=!1,r=!1){let s=Number.MAX_SAFE_INTEGER,i,o=[],u=[],f=this._vertexMap,h=new Map,d=new Set,p=new Map,x=this._getVertex(e),b=t?this._getVertex(t):void 0;if(!x)return;for(let V of f){let c=V[1];c instanceof _&&h.set(c,Number.MAX_SAFE_INTEGER)}h.set(x,0),p.set(x,void 0);let R=()=>{let V=Number.MAX_SAFE_INTEGER,c;for(let[E,m]of h)d.has(E)||m<V&&(V=m,c=E);return c},k=V=>{for(let c of f){let E=c[1];if(E instanceof _){let m=[E],O=p.get(E);for(;O;)m.push(O),O=p.get(O);let y=m.reverse();c[1]===V&&(o=y),u.push(y)}}};for(let V=1;V<f.size;V++){let c=R();if(c){if(d.add(c),b&&b===c)return n&&(s=h.get(b)||Number.MAX_SAFE_INTEGER),r&&k(b),{distMap:h,preMap:p,seen:d,paths:u,minDist:s,minPath:o};let E=this.getNeighbors(c);for(let m of E)if(!d.has(m)){let O=this.getEdge(c,m);if(O){let y=h.get(c),M=h.get(m);y!==void 0&&M!==void 0&&O.weight+y<M&&(h.set(m,O.weight+y),p.set(m,c))}}}}return n&&h.forEach((V,c)=>{c!==x&&V<s&&(s=V,r&&(i=c))}),r&&k(i),{distMap:h,preMap:p,seen:d,paths:u,minDist:s,minPath:o}}dijkstra(e,t=void 0,n=!1,r=!1){var V;let s=Number.MAX_SAFE_INTEGER,i,o=[],u=[],f=this._vertexMap,h=new Map,d=new Set,p=new Map,x=this._getVertex(e),b=t?this._getVertex(t):void 0;if(!x)return;for(let c of f){let E=c[1];E instanceof _&&h.set(E,Number.MAX_SAFE_INTEGER)}let R=new $([],{comparator:(c,E)=>c.key-E.key});R.add({key:0,value:x}),h.set(x,0),p.set(x,void 0);let k=c=>{for(let E of f){let m=E[1];if(m instanceof _){let O=[m],y=p.get(m);for(;y;)O.push(y),y=p.get(y);let M=O.reverse();E[1]===c&&(o=M),u.push(M)}}};for(;R.size>0;){let c=R.poll(),E=c==null?void 0:c.key,m=c==null?void 0:c.value;if(E!==void 0&&m){if(d.add(m),b&&b===m)return n&&(s=h.get(b)||Number.MAX_SAFE_INTEGER),r&&k(b),{distMap:h,preMap:p,seen:d,paths:u,minDist:s,minPath:o};let O=this.getNeighbors(m);for(let y of O)if(!d.has(y)){let M=(V=this.getEdge(m,y))==null?void 0:V.weight;if(typeof M=="number"){let S=h.get(y);S!==void 0&&E+M<S&&(R.add({key:E+M,value:y}),p.set(y,m),h.set(y,E+M))}}}}return n&&h.forEach((c,E)=>{E!==x&&c<s&&(s=c,r&&(i=E))}),r&&k(i),{distMap:h,preMap:p,seen:d,paths:u,minDist:s,minPath:o}}bellmanFord(e,t,n,r){n===void 0&&(n=!1),r===void 0&&(r=!1);let s=this._getVertex(e),i=[],o=new Map,u=new Map,f=Number.MAX_SAFE_INTEGER,h=[],d;if(t&&(d=!1),!s)return{hasNegativeCycle:d,distMap:o,preMap:u,paths:i,min:f,minPath:h};let p=this._vertexMap,x=p.size,b=this.edgeSet(),R=b.length;this._vertexMap.forEach(V=>{o.set(V,Number.MAX_SAFE_INTEGER)}),o.set(s,0);for(let V=1;V<x;++V)for(let c=0;c<R;++c){let E=this.getEndsOfEdge(b[c]);if(E){let[m,O]=E,y=b[c].weight,M=o.get(m),S=o.get(O);M!==void 0&&S!==void 0&&o.get(m)!==Number.MAX_SAFE_INTEGER&&M+y<S&&(o.set(O,M+y),r&&u.set(O,m))}}let k;if(n&&o.forEach((V,c)=>{c!==s&&V<f&&(f=V,r&&(k=c))}),r)for(let V of p){let c=V[1];if(c instanceof _){let E=[c],m=u.get(c);for(;m!==void 0;)E.push(m),m=u.get(m);let O=E.reverse();V[1]===k&&(h=O),i.push(O)}}for(let V=0;V<R;++V){let c=this.getEndsOfEdge(b[V]);if(c){let[E]=c,m=b[V].weight,O=o.get(E);O&&O!==Number.MAX_SAFE_INTEGER&&O+m<O&&(d=!0)}}return{hasNegativeCycle:d,distMap:o,preMap:u,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 o=0;o<t;o++)r[i][o]=void 0}for(let i=0;i<t;i++)for(let o=0;o<t;o++)n[i][o]=((s=this.getEdge(e[i][1],e[o][1]))==null?void 0:s.weight)||Number.MAX_SAFE_INTEGER;for(let i=0;i<t;i++)for(let o=0;o<t;o++)for(let u=0;u<t;u++)n[o][u]>n[o][i]+n[i][u]&&(n[o][u]=n[o][i]+n[i][u],r[o][u]=e[i][1]);return{costs:n,predecessor:r}}getCycles(e=!1){let t=[],n=new Set,r=(i,o,u)=>{if(u.has(i)){(!e&&o.length>2||e&&o.length>=2)&&o[0]===i.key&&t.push([...o]);return}u.add(i),o.push(i.key);for(let f of this.getNeighbors(i))f&&r(f,o,u);u.delete(i),o.pop()};for(let i of this.vertexMap.values())r(i,[],n);let s=new Map;for(let i of t){let o=[...i].sort().toString();s.has(o)||s.set(o,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[o,u]=i,f=o.key,h=u.key,d=typeof n.hasVertex=="function"?n.hasVertex(f):!1,p=typeof n.hasVertex=="function"?n.hasVertex(h):!1;if(d&&p){let x=n.createEdge(f,h,s.weight,s.value);n._addEdge(x)}}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 o;let t=(o=e==null?void 0:e.showWeight)!=null?o:!0,n=[...this._vertexMap.values()],r=n.length,s=this.edgeSet().length,i=[`Graph (${r} vertices, ${s} edges):`];for(let u of n){let f=this.getNeighbors(u);if(f.length===0)i.push(` ${u.key} (isolated)`);else{let h=f.map(d=>{let p=this.getEdge(u,d);return p&&t&&p.weight!==void 0&&p.weight!==1?`${d.key} (${p.weight})`:`${d.key}`});i.push(` ${u.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?"->":"--",o=[`${s} ${t} {`];for(let d of this._vertexMap.values())o.push(` "${d.key}";`);let u=new Set;for(let d of this._vertexMap.values())for(let p of this.getNeighbors(d)){let x=r?`${d.key}->${p.key}`:[d.key,p.key].sort().join("--");if(u.has(x))continue;u.add(x);let b=this.getEdge(d,p),R=b&&n&&b.weight!==void 0&&b.weight!==1?` [label="${b.weight}"]`:"";o.push(` "${d.key}" ${i} "${p.key}"${R};`)}return o.push("}"),o.join(`
|
|
3
|
-
`)}print(e){console.log(this.toVisual(e))}};var N=class extends _{constructor(a,e){super(a,e)}},A=class extends K{constructor(e,t,n,r){super(n,r);g(this,"src");g(this,"dest");this.src=e,this.dest=t}},L=class l extends I{constructor(e){super(e);g(this,"_outEdgeMap",new Map);g(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 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 N(e,t)}createEdge(e,t,n,r){var s;return new A(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(o=>o.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&&v(i,u=>u.dest===r.key);let o=this._inEdgeMap.get(r);return o&&(s=v(o,u=>u.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&&v(i,u=>u.src===r.key&&u.dest===(s==null?void 0:s.key));let o=this._inEdgeMap.get(s);o&&o.length>0&&(n=v(o,u=>u.src===r.key&&u.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 o=this.getDestinations(i);for(let u of o){let f=t.get(u);f===0?s(u):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 N?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,o=u=>{e.set(u,r),t.set(u,r),r++,s.push(u),i.add(u);let f=this.getNeighbors(u);for(let h of f)e.has(h)?i.has(h)&&t.set(u,Math.min(t.get(u),e.get(h))):(o(h),t.set(u,Math.min(t.get(u),t.get(h))));if(e.get(u)===t.get(u)){let h=[],d;do d=s.pop(),i.delete(d),h.push(d);while(d!==u);n.set(n.size,h)}};for(let u of this.vertexMap.values())e.has(u)||o(u);return{dfnMap:e,lowMap:t,SCCs:n}}getDFNMap(){return this.tarjan().dfnMap}getLowMap(){return this.tarjan().lowMap}getSCCs(){return this.tarjan().SCCs}_addEdge(e){if(!(this.hasVertex(e.src)&&this.hasVertex(e.dest)))return!1;let t=this._getVertex(e.src),n=this._getVertex(e.dest);if(t&&n){let r=this._outEdgeMap.get(t);r?r.push(e):this._outEdgeMap.set(t,[e]);let s=this._inEdgeMap.get(n);return s?s.push(e):this._inEdgeMap.set(n,[e]),!0}else return!1}};var H=class extends _{constructor(a,e){super(a,e)}},j=class extends K{constructor(e,t,n,r){super(n,r);g(this,"endpoints");this.endpoints=[e,t]}},
|
|
3
|
+
`)}print(e){console.log(this.toVisual(e))}};var N=class extends _{constructor(a,e){super(a,e)}},A=class extends K{constructor(e,t,n,r){super(n,r);g(this,"src");g(this,"dest");this.src=e,this.dest=t}},L=class l extends I{constructor(e){super(e);g(this,"_outEdgeMap",new Map);g(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 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 N(e,t)}createEdge(e,t,n,r){var s;return new A(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(o=>o.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&&v(i,u=>u.dest===r.key);let o=this._inEdgeMap.get(r);return o&&(s=v(o,u=>u.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&&v(i,u=>u.src===r.key&&u.dest===(s==null?void 0:s.key));let o=this._inEdgeMap.get(s);o&&o.length>0&&(n=v(o,u=>u.src===r.key&&u.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 o=this.getDestinations(i);for(let u of o){let f=t.get(u);f===0?s(u):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 N?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,o=u=>{e.set(u,r),t.set(u,r),r++,s.push(u),i.add(u);let f=this.getNeighbors(u);for(let h of f)e.has(h)?i.has(h)&&t.set(u,Math.min(t.get(u),e.get(h))):(o(h),t.set(u,Math.min(t.get(u),t.get(h))));if(e.get(u)===t.get(u)){let h=[],d;do d=s.pop(),i.delete(d),h.push(d);while(d!==u);n.set(n.size,h)}};for(let u of this.vertexMap.values())e.has(u)||o(u);return{dfnMap:e,lowMap:t,SCCs:n}}getDFNMap(){return this.tarjan().dfnMap}getLowMap(){return this.tarjan().lowMap}getSCCs(){return this.tarjan().SCCs}_addEdge(e){if(!(this.hasVertex(e.src)&&this.hasVertex(e.dest)))return!1;let t=this._getVertex(e.src),n=this._getVertex(e.dest);if(t&&n){let r=this._outEdgeMap.get(t);r?r.push(e):this._outEdgeMap.set(t,[e]);let s=this._inEdgeMap.get(n);return s?s.push(e):this._inEdgeMap.set(n,[e]),!0}else return!1}};var H=class extends _{constructor(a,e){super(a,e)}},j=class extends K{constructor(e,t,n,r){super(n,r);g(this,"endpoints");this.endpoints=[e,t]}},B=class l extends I{constructor(e){super(e);g(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 H(e,t)}createEdge(e,t,n,r){var s;return new j(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),i=this._getVertex(t);s&&i&&(n=(r=this._edgeMap.get(s))==null?void 0:r.filter(o=>o.endpoints.includes(i.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),i;s&&(i=v(s,u=>u.endpoints.includes(r.key))[0]||void 0);let o=this._edgeMap.get(r);return o&&v(o,u=>u.endpoints.includes(n.key)),i}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 i=this._edgeMap.get(s);if(i){let o=i.filter(u=>!u.endpoints.includes(t));this._edgeMap.set(s,o)}}),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 i=this._getVertex(s.endpoints.filter(o=>o!==n.key)[0]);i&&t.push(i)}}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,i=(o,u)=>{e.set(o,s),t.set(o,s),s++;let f=this.getNeighbors(o),h=0;for(let d of f)if(e.has(d))d!==u&&t.set(o,Math.min(t.get(o),e.get(d)));else{if(h++,i(d,o),t.set(o,Math.min(t.get(o),t.get(d))),t.get(d)>e.get(o)){let p=this.getEdge(o,d);p&&n.push(p)}u!==void 0&&t.get(d)>=e.get(o)&&r.push(o)}u===void 0&&h>1&&r.push(o)};for(let o of this.vertexMap.values())e.has(o)||i(o,void 0);return{dfnMap:e,lowMap:t,bridges:n,cutVertices:r}}getBiconnectedComponents(){let e=new Map,t=new Map,n=[],r=[],s=0,i=(o,u)=>{e.set(o,s),t.set(o,s),s++;let f=this.getNeighbors(o),h=0;for(let d of f){let p=this.getEdge(o,d);if(p){if(e.has(d))d!==u&&e.get(d)<e.get(o)&&(n.push(p),t.set(o,Math.min(t.get(o),e.get(d))));else if(h++,n.push(p),i(d,o),t.set(o,Math.min(t.get(o),t.get(d))),u===void 0&&h>1||u!==void 0&&t.get(d)>=e.get(o)){let x=[],b;do b=n.pop(),b&&x.push(b);while(b&&b!==p);x.length>0&&r.push(x)}}}};for(let o of this.vertexMap.values())e.has(o)||(i(o,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}};var z=class extends N{constructor(e,t,n,r){super(e,t);g(this,"lat");g(this,"long");this.lat=n,this.long=r}},P=class extends A{constructor(a,e,t,n){super(a,e,t,n)}},q=class l extends L{constructor(e,t){super();g(this,"_originCoord",[0,0]);g(this,"_bottomRight");this._originCoord=e,this._bottomRight=t}get originCoord(){return this._originCoord}get bottomRight(){return this._bottomRight}createVertex(e,t,n=this.originCoord[0],r=this.originCoord[1]){return new z(e,t,n,r)}createEdge(e,t,n,r){return new P(e,t,n,r)}clone(){return super.clone()}_snapshotOptions(){return{...super._snapshotOptions(),originCoord:this.originCoord,bottomRight:this.bottomRight}}_createInstance(e){let{originCoord:t,bottomRight:n}=e||{},r=t!=null?t:this.originCoord,s=n!=null?n:this.bottomRight;return new l(r,s)}};return re(se);})();
|
|
4
4
|
/**
|
|
5
5
|
* data-structure-typed
|
|
6
6
|
*
|