!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.Algorithm=t():e.Algorithm=t()}(this,(()=>(()=>{"use strict";var e={d:(t,r)=>{for(var n in r)e.o(r,n)&&!e.o(t,n)&&Object.defineProperty(t,n,{enumerable:!0,get:r[n]})},o:(e,t)=>Object.prototype.hasOwnProperty.call(e,t)},t={};e.d(t,{default:()=>pe});const r=function(e,t){var r=e.nodes,n=e.edges,o=[],i={};if(!r)throw new Error("invalid nodes data!");return r&&r.forEach((function(e,t){i[e.id]=t,o.push([])})),n&&n.forEach((function(e){var r=e.source,n=e.target,a=i[r],d=i[n];!a&&0!==a||!d&&0!==d||(o[a][d]=1,t||(o[d][a]=1))})),o};var n=function(e,t){return e===t},o=function(){function e(e,t){void 0===t&&(t=null),this.value=e,this.next=t}return e.prototype.toString=function(e){return e?e(this.value):"".concat(this.value)},e}();const i=function(){function e(e){void 0===e&&(e=n),this.head=null,this.tail=null,this.compare=e}return e.prototype.prepend=function(e){var t=new o(e,this.head);return this.head=t,this.tail||(this.tail=t),this},e.prototype.append=function(e){var t=new o(e);return this.head?(this.tail.next=t,this.tail=t,this):(this.head=t,this.tail=t,this)},e.prototype.delete=function(e){if(!this.head)return null;for(var t=null;this.head&&this.compare(this.head.value,e);)t=this.head,this.head=this.head.next;var r=this.head;if(null!==r)for(;r.next;)this.compare(r.next.value,e)?(t=r.next,r.next=r.next.next):r=r.next;return this.compare(this.tail.value,e)&&(this.tail=r),t},e.prototype.find=function(e){var t=e.value,r=void 0===t?void 0:t,n=e.callback,o=void 0===n?void 0:n;if(!this.head)return null;for(var i=this.head;i;){if(o&&o(i.value))return i;if(void 0!==r&&this.compare(i.value,r))return i;i=i.next}return null},e.prototype.deleteTail=function(){var e=this.tail;if(this.head===this.tail)return this.head=null,this.tail=null,e;for(var t=this.head;t.next;)t.next.next?t=t.next:t.next=null;return this.tail=t,e},e.prototype.deleteHead=function(){if(!this.head)return null;var e=this.head;return this.head.next?this.head=this.head.next:(this.head=null,this.tail=null),e},e.prototype.fromArray=function(e){var t=this;return e.forEach((function(e){return t.append(e)})),this},e.prototype.toArray=function(){for(var e=[],t=this.head;t;)e.push(t),t=t.next;return e},e.prototype.reverse=function(){for(var e=this.head,t=null,r=null;e;)r=e.next,e.next=t,t=e,e=r;this.tail=this.head,this.head=t},e.prototype.toString=function(e){return void 0===e&&(e=void 0),this.toArray().map((function(t){return t.toString(e)})).toString()},e}(),a=function(){function e(){this.linkedList=new i}return e.prototype.isEmpty=function(){return!this.linkedList.head},e.prototype.peek=function(){return this.linkedList.head?this.linkedList.head.value:null},e.prototype.enqueue=function(e){this.linkedList.append(e)},e.prototype.dequeue=function(){var e=this.linkedList.deleteHead();return e?e.value:null},e.prototype.toString=function(e){return this.linkedList.toString(e)},e}();var d=function(e,t,r){void 0===t&&(t=[]);var n=t.filter((function(t){return t.source===e||t.target===e}));return"target"===r?n.filter((function(t){return t.source===e})).map((function(e){return e.target})):"source"===r?n.filter((function(t){return t.target===e})).map((function(e){return e.source})):n.map((function(t){return t.source===e?t.target:t.source}))},u=function(e,t){return t.filter((function(t){return t.source===e||t.target===e}))},s=function(e){void 0===e&&(e=0);var t="".concat(Math.random()).split(".")[1].substr(0,5),r="".concat(Math.random()).split(".")[1].substr(0,5);return"".concat(e,"-").concat(t).concat(r)};var c=function(e){for(var t=e.nodes,r=void 0===t?[]:t,n=e.edges,o=void 0===n?[]:n,i=[],a={},u={},s={},c=[],f=0,l=function(e){u[e.id]=f,s[e.id]=f,f+=1,i.push(e),a[e.id]=!0;for(var t=d(e.id,o,"target").filter((function(e){return r.map((function(e){return e.id})).indexOf(e)>-1})),n=function(n){var o=t[n];if(u[o]||0===u[o])a[o]&&(s[e.id]=Math.min(s[e.id],u[o]));else{var i=r.filter((function(e){return e.id===o}));i.length>0&&l(i[0]),s[e.id]=Math.min(s[e.id],s[o])}},h=0;h0;){var p=i.pop();if(a[p.id]=!1,v.push(p),p===e)break}v.length>0&&c.push(v)}},h=0,v=r;h0&&s(o[0])}},i=0;i0;)l.push(u.pop());i.push(l)}}return i}(e)}var l=function(e){var t={},r=e.nodes,n=void 0===r?[]:r,o=e.edges,i=void 0===o?[]:o;return n.forEach((function(e){t[e.id]={degree:0,inDegree:0,outDegree:0}})),i.forEach((function(e){t[e.source].degree++,t[e.source].outDegree++,t[e.target].degree++,t[e.target].inDegree++})),t};const h=l;function v(e,t,r,n,o){void 0===o&&(o=!0),n.enter({current:t,previous:r});var i=e.edges;d(t,void 0===i?[]:i,o?"target":void 0).forEach((function(i){n.allowTraversal({previous:r,current:t,next:i})&&v(e,i,t,n,o)})),n.leave({current:t,previous:r})}function p(e,t,r,n){void 0===n&&(n=!0),v(e,t,"",function(e){void 0===e&&(e={});var t,r=e,n=function(){},o=(t={},function(e){var r=e.next;return!t[r]&&(t[r]=!0,!0)});return r.allowTraversal=e.allowTraversal||o,r.enter=e.enter||n,r.leave=e.leave||n,r}(r),n)}var g=function(e,t,r){var n,o;void 0===r&&(r=!0);for(var i=[],a=0,u=f(e,!1);a0;)for(var g=h.pop(),b=g.id,E=d(b,e.edges),y=function(n){var o,a=E[n],d=e.nodes.find((function(e){return e.id===a}));if(a===b)i.push(((o={})[a]=g,o));else if(a in p){if(!p[b].has(d)){for(var u=!0,s=[d,g],c=v[b];p[a].size&&!p[a].has(c)&&(s.push(c),c!==v[c.id]);)c=v[c.id];if(s.push(c),t&&r?(u=!1,s.findIndex((function(e){return t.indexOf(e.id)>-1}))>-1&&(u=!0)):t&&!r&&s.findIndex((function(e){return t.indexOf(e.id)>-1}))>-1&&(u=!1),u){for(var f={},l=1;l-1)return c;n.push(e),o.add(e);for(var l=s[e.id],h=0;h0;){var r=t.pop();o.has(r)&&(o.delete(r),i[r.id].forEach((function(e){t.push(e)})),i[r.id].clear())}}(e);else for(h=0;h-1}));b-1?p[g.id].push(s[y]):a.push(((o={})[g.id]=g,o))}}return{component:v,adjList:p,minIdx:u}},y=0;y=y})),L=c({nodes:m,edges:e.edges}).filter((function(e){return e.length>1}));if(0===L.length)break;var N=E(L),w=N.minIdx,k=N.adjList,I=N.component;if(!(I.length>1))break;I.forEach((function(e){i[e.id]=new Set}));var x=u[w];if(t&&r&&-1===t.indexOf(x.id))return a;f(x,x,k),y=w+1}return a};const E=function(e){var t=null,r=e.nodes,n={},o={},i={},a={};(void 0===r?[]:r).forEach((function(e){o[e.id]=e}));for(var d={enter:function(e){var r=e.current,a=e.previous;if(i[r]){t={};for(var d=r,u=a;u!==r;)t[d]=u,d=u,u=n[u];t[d]=u}else i[r]=r,delete o[r],n[r]=a},leave:function(e){var t=e.current;a[t]=t,delete i[t]},allowTraversal:function(e){var r=e.next;return!t&&!a[r]}};Object.keys(o).length;)p(e,Object.keys(o)[0],d);return t};function y(e,t,r){if(r||2===arguments.length)for(var n,o=0,i=t.length;of[t.id]+d?(f[a]=f[t.id]+d,l[a]=[t.id]):f[a]===f[t.id]+d&&l[a].push(t.id)}))},p=0;po[a][u]+o[u][d]&&(o[a][d]=o[a][u]+o[u][d]);return o};const T=function(){function e(e){this.arr=e}return e.prototype.getArr=function(){return this.arr||[]},e.prototype.add=function(t){var r,n=t.arr;if(!(null===(r=this.arr)||void 0===r?void 0:r.length))return new e(n);if(!(null==n?void 0:n.length))return new e(this.arr);if(this.arr.length===n.length){var o=[];for(var i in this.arr)o[i]=this.arr[i]+n[i];return new e(o)}},e.prototype.subtract=function(t){var r,n=t.arr;if(!(null===(r=this.arr)||void 0===r?void 0:r.length))return new e(n);if(!(null==n?void 0:n.length))return new e(this.arr);if(this.arr.length===n.length){var o=[];for(var i in this.arr)o[i]=this.arr[i]-n[i];return new e(o)}},e.prototype.avg=function(t){var r=[];if(0!==t)for(var n in this.arr)r[n]=this.arr[n]/t;return new e(r)},e.prototype.negate=function(){var t=[];for(var r in this.arr)t[r]=-this.arr[r];return new e(t)},e.prototype.squareEuclideanDistance=function(e){var t,r=e.arr;if(!(null===(t=this.arr)||void 0===t?void 0:t.length)||!(null==r?void 0:r.length))return 0;if(this.arr.length===r.length){var n=0;for(var o in this.arr)n+=Math.pow(this.arr[o]-e.arr[o],2);return n}},e.prototype.euclideanDistance=function(e){var t,r=e.arr;if(!(null===(t=this.arr)||void 0===t?void 0:t.length)||!(null==r?void 0:r.length))return 0;if(this.arr.length===r.length){var n=0;for(var o in this.arr)n+=Math.pow(this.arr[o]-e.arr[o],2);return Math.sqrt(n)}console.error("The two vectors are unequal in length.")},e.prototype.normalize=function(){var t=[],r=M(this.arr);r.sort((function(e,t){return e-t}));var n=r[r.length-1],o=r[0];for(var i in this.arr)t[i]=(this.arr[i]-o)/(n-o);return new e(t)},e.prototype.norm2=function(){var e;if(!(null===(e=this.arr)||void 0===e?void 0:e.length))return 0;var t=0;for(var r in this.arr)t+=Math.pow(this.arr[r],2);return Math.sqrt(t)},e.prototype.dot=function(e){var t,r=e.arr;if(!(null===(t=this.arr)||void 0===t?void 0:t.length)||!(null==r?void 0:r.length))return 0;if(this.arr.length===r.length){var n=0;for(var o in this.arr)n+=this.arr[o]*e.arr[o];return n}console.error("The two vectors are unequal in length.")},e.prototype.equal=function(e){var t,r=e.arr;if((null===(t=this.arr)||void 0===t?void 0:t.length)!==(null==r?void 0:r.length))return!1;for(var n in this.arr)if(this.arr[n]!==r[n])return!1;return!0},e}();var q,F=function(e,t){void 0===t&&(t=void 0);var r=[];return e.forEach((function(e){void 0===t&&r.push(e),void 0!==e[t]&&r.push(e[t])})),r};!function(e){e.EuclideanDistance="euclideanDistance"}(q||(q={}));var R=function(e,t,r){var n=function(e,t,r){var n=[];(null==t?void 0:t.length)?n=t:(e.forEach((function(e){n=n.concat(Object.keys(e))})),n=x(n));var o={};return n.forEach((function(t){var n=[];e.forEach((function(e){void 0!==e[t]&&""!==e[t]&&n.push(e[t])})),n.length&&!(null==r?void 0:r.includes(t))&&(o[t]=x(n))})),o}(e,t,r),o=[];if(!Object.keys(n).length)return o;var i=Object.values(n).every((function(e){return e.every((function(e){return"number"==typeof e}))}));return e.forEach((function(e,t){var r=[];Object.keys(n).forEach((function(t){var o=e[t],a=n[t],d=a.findIndex((function(e){return o===e})),u=[];if(i)u.push(o);else for(var s=0;s0&&k>I&&k-II&&(j=f.map((function(e){return{node:e,clusterId:e.clusterId}})),O=M(E),I=k),D||x>100)break;x++,Object.keys(E).forEach((function(e){var t=0;h.forEach((function(r){var o=r.source,i=r.target,a=y[o].node.clusterId,d=y[i].node.clusterId;(a===e&&d!==e||d===e&&a!==e)&&(t+=r[n]||1)})),E[e].sumTot=t})),f.forEach((function(e,t){var r,o=E[e.clusterId],a=0,d=L[t]/(2*w),u=0,c=o.nodes;c.forEach((function(e){var r=y[e.id].idx;u+=m[t][r]||0}));var f=u-o.sumTot*d,l=c.filter((function(t){return t.id!==e.id})),p=[];l.forEach((function(e,t){p[t]=v[e.originIndex]}));var g=z(l,v)*s,b=N[e.id];if(Object.keys(b).forEach((function(n){var o=y[n].node.clusterId;if(o!==e.clusterId){var u=E[o],c=u.nodes;if(c&&c.length){var l=0;c.forEach((function(e){var r=y[e.id].idx;l+=m[t][r]||0}));var h=l-u.sumTot*d,p=c.concat([e]),b=[];p.forEach((function(e,t){b[t]=v[e.originIndex]}));var L=z(p,v)*s,N=h-f;i&&(N=h+L-(f+g)),N>a&&(a=N,r=u)}}})),a>0){r.nodes.push(e);var k=e.clusterId;e.clusterId=r.id;var I=o.nodes.indexOf(e);o.nodes.splice(I,1);var x=0,M=0;h.forEach((function(e){var t=e.source,o=e.target,i=y[t].node.clusterId,a=y[o].node.clusterId;(i===r.id&&a!==r.id||a===r.id&&i!==r.id)&&(x+=e[n]||1),(i===k&&a!==k||a===k&&i!==k)&&(M+=e[n]||1)})),r.sumTot=x,o.sumTot=M}}))}var S={},C=0;Object.keys(O).forEach((function(e){var t=O[e];if(t.nodes&&t.nodes.length){var r=String(C+1);r!==e&&(t.id=r,t.nodes=t.nodes.map((function(e){return{id:e.id,clusterId:r}})),O[r]=t,S[e]=r,delete O[e],C++)}else delete O[e]})),j.forEach((function(e){var t=e.node,r=e.clusterId;t&&(t.clusterId=r,t.clusterId&&S[t.clusterId]&&(t.clusterId=S[t.clusterId]))}));var P=[],A={};h.forEach((function(e){var t=e.source,r=e.target,o=e[n]||1,i=y[t].node.clusterId,a=y[r].node.clusterId;if(i&&a){var d="".concat(i,"---").concat(a);if(A[d])A[d].weight+=o,A[d].count++;else{var u={source:i,target:a,weight:o,count:1};A[d]=u,P.push(u)}}}));var T=[];return Object.keys(O).forEach((function(e){T.push(O[e])})),{clusters:T,clusterEdges:P}};var H=function(e,t,r){return e===q.EuclideanDistance?t[r]:[]};const W=function(e,t){var r=new T(t),n=r.norm2(),o=new T(e),i=o.norm2(),a=r.dot(o),d=n*i;return d?a/d:0},K=function(){function e(e){this.count=e.length,this.parent={};for(var t=0,r=e;t0&&(this.list[0]=t,this.moveDown(0)),e},e.prototype.insert=function(e){if(null!==e){this.list.push(e);var t=this.list.length-1;return this.moveUp(t),!0}return!1},e.prototype.moveUp=function(e){for(var t=this.getParent(e);e&&e>0&&this.compareFn(this.list[t],this.list[e])>0;){var r=this.list[t];this.list[t]=this.list[e],this.list[e]=r,e=t,t=this.getParent(e)}},e.prototype.moveDown=function(e){var t,r=e,n=this.getLeft(e),o=this.getRight(e),i=this.list.length;null!==n&&n0?r=n:null!==o&&o0&&(r=o),e!==r&&(t=[this.list[r],this.list[e]],this.list[e]=t[0],this.list[r]=t[1],this.moveDown(r))},e}();var Q=function(e,t){var r=[],n=e.nodes,o=void 0===n?[]:n,i=e.edges,a=void 0===i?[]:i;if(0===o.length)return r;var d=o[0],s=new Set;s.add(d);var c=new J((function(e,r){return t?e.weight-r.weight:0}));for(u(d.id,a).forEach((function(e){c.insert(e)}));!c.isEmpty();){var f=c.delMin(),l=f.source,h=f.target;s.has(l)&&s.has(h)||(r.push(f),s.has(l)||(s.add(l),u(l,a).forEach((function(e){c.insert(e)}))),s.has(h)||(s.add(h),u(h,a).forEach((function(e){c.insert(e)}))))}return r},X=function(e,t){var r=[],n=e.nodes,o=void 0===n?[]:n,i=e.edges,a=void 0===i?[]:i;if(0===o.length)return r;var d=a.map((function(e){return e}));t&&d.sort((function(e,t){return e.weight-t.weight}));for(var u=new K(o.map((function(e){return e.id})));d.length>0;){var s=d.shift(),c=s.source,f=s.target;u.connected(c,f)||(r.push(s),u.union(c,f))}return r};var Y="-1",Z=function(e,t,r,n){void 0===e&&(e=-1),void 0===t&&(t=-1),void 0===r&&(r=-1),void 0===n&&(n="-1"),this.id=e,this.from=t,this.to=r,this.label=n},$=function(){function e(e,t){void 0===e&&(e=-1),void 0===t&&(t=Y),this.id=e,this.label=t,this.edges=[],this.edgeMap={}}return e.prototype.addEdge=function(e){this.edges.push(e),this.edgeMap[e.id]=e},e}(),_=function(){function e(e,t,r){void 0===e&&(e=-1),void 0===t&&(t=!0),void 0===r&&(r=!1),this.id=e,this.edgeIdAutoIncrease=t,this.edges=[],this.nodes=[],this.nodeMap={},this.edgeMap={},this.nodeLabelMap={},this.edgeLabelMap={},this.counter=0,this.directed=r}return e.prototype.getNodeNum=function(){return this.nodes.length},e.prototype.addNode=function(e,t){if(!this.nodeMap[e]){var r=new $(e,t);this.nodes.push(r),this.nodeMap[e]=r,this.nodeLabelMap[t]||(this.nodeLabelMap[t]=[]),this.nodeLabelMap[t].push(e)}},e.prototype.addEdge=function(e,t,r,n){if((this.edgeIdAutoIncrease||void 0===e)&&(e=this.counter++),!(this.nodeMap[t]&&this.nodeMap[r]&&this.nodeMap[r].edgeMap[e])){var o=new Z(e,t,r,n);if(this.edges.push(o),this.edgeMap[e]=o,this.nodeMap[t].addEdge(o),this.edgeLabelMap[n]||(this.edgeLabelMap[n]=[]),this.edgeLabelMap[n].push(o),!this.directed){var i=new Z(e,r,t,n);this.nodeMap[r].addEdge(i),this.edgeLabelMap[n].push(i)}}},e}(),ee=function(){function e(e,t,r,n,o){this.fromNode=e,this.toNode=t,this.nodeEdgeNodeLabel={nodeLabel1:r||Y,edgeLabel:n||"-1",nodeLabel2:o||Y}}return e.prototype.equalTo=function(e){return this.fromNode===e.formNode&&this.toNode===e.toNode&&this.nodeEdgeNodeLabel===e.nodeEdgeNodeLabel},e.prototype.notEqualTo=function(e){return!this.equalTo(e)},e}(),te=function(){function e(){this.rmpath=[],this.dfsEdgeList=[]}return e.prototype.equalTo=function(e){var t=this.dfsEdgeList.length;if(t!==e.length)return!1;for(var r=0;r=0;t--){var r=this.dfsEdgeList[t],n=r.fromNode,o=r.toNode;nf||n.hasNode(i[c.to])||(t.labelv&&"break"!==p(g);g--);if(l){var b=e.findMinLabel(f);i.dfsEdgeList.push(new ee(c,h,Y,b.edgeLabel,Y));var E=i.dfsEdgeList.length-1;return e.dfsCode.dfsEdgeList[E]===i.dfsEdgeList[E]&&u(f[b.edgeLabel].projected)}var y={};l=!1;var m=0;a.forEach((function(t){var r=new re(t),i=e.findForwardPureEdges(n,r.edges[d[0]],s,r);i.length>0&&(l=!0,m=c,i.forEach((function(e){var r="".concat(e.label,"-").concat(o[e.to].label);y[r]||(y[r]={projected:[],edgeLabel:e.label,nodeLabel2:o[e.to].label}),y[r].projected.push({graphId:n.id,edge:e,preNode:t})})))}));var L=d.length,N=function(t){if(l)return"break";var r=d[t];a.forEach((function(t){var a=new re(t),d=e.findForwardRmpathEdges(n,a.edges[r],s,a);d.length>0&&(l=!0,m=i.dfsEdgeList[r].fromNode,d.forEach((function(e){var r="".concat(e.label,"-").concat(o[e.to].label);y[r]||(y[r]={projected:[],edgeLabel:e.label,nodeLabel2:o[e.to].label}),y[r].projected.push({graphId:n.id,edge:e,preNode:t})})))}))};for(g=0;g=0;f--){var l=t.findBackwardEdge(u,c.edges[n[f]],c.edges[n[0]],c);if(l){var h="".concat(t.dfsCode.dfsEdgeList[n[f]].fromNode,"-").concat(l.label);d[h]||(d[h]={projected:[],toNodeId:t.dfsCode.dfsEdgeList[n[f]].fromNode,edgeLabel:l.label}),d[h].projected.push({graphId:e.graphId,edge:l,preNode:e})}}if(!(r>=t.maxNodeNum)){t.findForwardPureEdges(u,c.edges[n[0]],i,c).forEach((function(t){var r="".concat(o,"-").concat(t.label,"-").concat(s[t.to].label);a[r]||(a[r]={projected:[],fromNodeId:o,edgeLabel:t.label,nodeLabel2:s[t.to].label}),a[r].projected.push({graphId:e.graphId,edge:t,preNode:e})}));var v=function(r){t.findForwardRmpathEdges(u,c.edges[n[r]],i,c).forEach((function(o){var i="".concat(t.dfsCode.dfsEdgeList[n[r]].fromNode,"-").concat(o.label,"-").concat(s[o.to].label);a[i]||(a[i]={projected:[],fromNodeId:t.dfsCode.dfsEdgeList[n[r]].fromNode,edgeLabel:o.label,nodeLabel2:s[o.to].label}),a[i].projected.push({graphId:e.graphId,edge:o,preNode:e})}))};for(f=0;fo){var a=o;o=n,n=a}var c=e.label,f="".concat(r,"-").concat(n,"-").concat(c,"-").concat(o),l="".concat(n,"-").concat(c,"-").concat(o);if(!i[l]){var h=i[l]||0;h++,i[l]=h}d[f]={graphId:r,nodeLabel1:n,edgeLabel:c,nodeLabel2:o}}))}))})),Object.keys(o).forEach((function(e){if(!(o[e]t&&(d=t);var n=r[e.id].inDegree;u>n&&(u=n);var o=r[e.id].outDegree;s>o&&(s=o)})),e[t]={degree:d,inDegree:u,outDegree:s}),{minPatternNodeLabelDegree:d,minPatternNodeLabelInDegree:u,minPatternNodeLabelOutDegree:s}};var ve=function(){function e(e){void 0===e&&(e=10),this.linkedList=new i,this.maxStep=e}return Object.defineProperty(e.prototype,"length",{get:function(){return this.linkedList.toArray().length},enumerable:!1,configurable:!0}),e.prototype.isEmpty=function(){return!this.linkedList.head},e.prototype.isMaxStack=function(){return this.toArray().length>=this.maxStep},e.prototype.peek=function(){return this.isEmpty()?null:this.linkedList.head.value},e.prototype.push=function(e){this.linkedList.prepend(e),this.length>this.maxStep&&this.linkedList.deleteTail()},e.prototype.pop=function(){var e=this.linkedList.deleteHead();return e?e.value:null},e.prototype.toArray=function(){return this.linkedList.toArray().map((function(e){return e.value}))},e.prototype.clear=function(){for(;!this.isEmpty();)this.pop()},e}();const pe={getAdjMatrix:r,breadthFirstSearch:function(e,t,r,n){void 0===n&&(n=!0);var o=function(e){void 0===e&&(e={});var t,r=e,n=function(){},o=(t={},function(e){var r=e.next;return!t[r]&&(t[r]=!0,!0)});return r.allowTraversal=e.allowTraversal||o,r.enter=e.enter||n,r.leave=e.leave||n,r}(r),i=new a,u=e.edges,s=void 0===u?[]:u;i.enqueue(t);for(var c="",f=function(){var e=i.dequeue();o.enter({current:e,previous:c}),d(e,s,n?"target":void 0).forEach((function(t){o.allowTraversal({previous:c,current:e,next:t})&&i.enqueue(t)})),o.leave({current:e,previous:c}),c=e};!i.isEmpty();)f()},connectedComponent:f,getDegree:h,getInDegree:function(e,t){return l(e)[t]?l(e)[t].inDegree:0},getOutDegree:function(e,t){return l(e)[t]?l(e)[t].outDegree:0},detectCycle:E,detectDirectedCycle:E,detectAllCycles:function(e,t,r,n){return void 0===n&&(n=!0),t?b(e,r,n):g(e,r,n)},detectAllDirectedCycle:b,detectAllUndirectedCycle:g,depthFirstSearch:p,dijkstra:C,findAllPath:function(e,t,r,n){var o;if(t===r)return[[t]];var i=e.edges,a=void 0===i?[]:i,u=[t],s=((o={})[t]=!0,o),c=[],f=[],l=n?d(t,a,"target"):d(t,a);for(c.push(l);u.length>0&&c.length>0;){var h=c[c.length-1];if(h.length){var v=h.shift();if(v&&(u.push(v),s[v]=!0,l=n?d(v,a,"target"):d(v,a),c.push(l.filter((function(e){return!s[e]})))),u[u.length-1]===r){var p=u.map((function(e){return e}));f.push(p),g=u.pop(),s[g]=!1,c.pop()}}else{var g=u.pop();s[g]=!1,c.pop()}}return f},findShortestPath:function(e,t,r,n,o){var i=C(e,t,n,o),a=i.length,d=i.path,u=i.allPath;return{length:a[r],path:d[r],allPath:u[r]}},floydWarshall:A,labelPropagation:function(e,t,n,o){void 0===t&&(t=!1),void 0===n&&(n="weight"),void 0===o&&(o=1e3);var i=e.nodes,a=void 0===i?[]:i,d=e.edges,u=void 0===d?[]:d,c={},f={};a.forEach((function(e,t){var r=s();e.clusterId=r,c[r]={id:r,nodes:[e]},f[e.id]={node:e,idx:t}}));var l=r(e,t),h=[],v={};l.forEach((function(e,t){var r=0,n=a[t].id;v[n]={},e.forEach((function(e,t){if(e){r+=e;var o=a[t].id;v[n][o]=e}})),h.push(r)}));for(var p=0,g=function(){var e=!1;if(a.forEach((function(t){var r={};Object.keys(v[t.id]).forEach((function(e){var n=v[t.id][e],o=f[e].node.clusterId;r[o]||(r[o]=0),r[o]+=n}));var n=-1/0,o=[];if(Object.keys(r).forEach((function(e){n=0&&o.splice(i,1),o&&o.length){e=!0;var a=c[t.clusterId],d=a.nodes.indexOf(t);a.nodes.splice(d,1);var u=Math.floor(Math.random()*o.length),s=c[o[u]];s.nodes.push(t),t.clusterId=s.id}}})),!e)return"break";p++};p=t)return"break";var a=i.findIndex((function(e){return e.id===o}));i.splice(a,1),d=d.filter((function(e){return!(e.source===o||e.target===o)}))};"break"!==u(););return{nodes:i,edges:d}},kMeans:function(e,t,r,n,o,i){void 0===t&&(t=3),void 0===r&&(r=void 0),void 0===n&&(n=[]),void 0===o&&(o=["id"]),void 0===i&&(i=q.EuclideanDistance);var a=e.nodes,d=void 0===a?[]:a,u=e.edges,s=void 0===u?[]:u,c={clusters:[{id:"0",nodes:d}],clusterEdges:[]};if(i===q.EuclideanDistance&&!d.every((function(e){return e.hasOwnProperty(r)})))return c;var f=[],l=[];if(i===q.EuclideanDistance&&(f=F(d,r),l=R(f,n,o)),!l.length)return c;for(var h=x(l.map((function(e){return e.join("")}))),v=Math.min(t,d.length,h.length),p=0;pm&&!g.find((function(t){return D(t,H(i,l,d[e].originIndex))}))&&(m=o,L=e)}},w=0;w=0;S--)E[Number(d[p].clusterId)][S].id===d[p].id&&E[Number(d[p].clusterId)].splice(S,1);d[p].clusterId=String(I),E[I].push(d[p])}}var C=!1;for(p=0;p=1e3)break}var z=[],B={};return s.forEach((function(e){var t,r,n=e.source,o=e.target,i=null===(t=d.find((function(e){return e.id===n})))||void 0===t?void 0:t.clusterId,a=null===(r=d.find((function(e){return e.id===o})))||void 0===r?void 0:r.clusterId,u="".concat(i,"---").concat(a);if(B[u])B[u].count++;else{var s={source:i,target:a,count:1};B[u]=s,z.push(s)}})),{clusters:E,clusterEdges:z}},cosineSimilarity:W,nodesCosineSimilarity:function(e,t,r,n,o){void 0===e&&(e=[]),void 0===r&&(r=void 0),void 0===n&&(n=[]),void 0===o&&(o=[]);var i=M(e.filter((function(e){return e.id!==t.id}))),a=e.findIndex((function(e){return e.id===t.id})),d=F(e,r),u=R(d,n,o),s=u[a],c=[];return i.forEach((function(e,r){if(e.id!==t.id){var n=u[r],o=W(n,s);c.push(o),e.cosineSimilarity=o}})),i.sort((function(e,t){return t.cosineSimilarity-e.cosineSimilarity})),{allCosineSimilarity:c,similarNodes:i}},minimumSpanningTree:function(e,t,r){return r?{prim:Q,kruskal:X}[r](e,t):X(e,t)},pageRank:function(e,t,r){"number"!=typeof t&&(t=1e-6),"number"!=typeof r&&(r=.85);for(var n,o=1,i=0,a=1e3,u=e.nodes,s=void 0===u?[]:u,c=e.edges,f=void 0===c?[]:c,l=s.length,v={},p={},g=0;g0&&o>t;){for(i=0,g=0;g0&&(n+=p[L]/N)}v[E]=r*n,i+=v[E]}}for(i=(1-i)/l,o=0,g=0;g2*t)););if(h<2*t&&(a["".concat(n,"-").concat(l)]={start:n,end:l,distance:o[n][l]},u++,++d>=r))return a;if(++s>2*t)break}uF&&(F=r.length,T=r,q=t,P=e)}));var R={},G={},U={},z={},B={},H={};Object.keys(E).forEach((function(n,o){B[n]=[],r&&(H[n]=[]);var d=-1/0,u=E[n],s={};u.forEach((function(e){var t=l["".concat(P.id,"-").concat(e.id)];if(t&&B[n].push(t),dB[n][l]){s=!0;break}if(s)return T.splice(t,1),"continue";var h={};o.neighbors.forEach((function(e){var t=f["".concat(r.id,"-").concat(e.id)];h["".concat(r.id,"-").concat(e.id)]={start:v[r.id].idx,end:v[e.id].idx,distance:t}})),I=de(h,N,e,I);var p=[];Object.keys(h).forEach((function(e){if(S[e])p.push(S[e]);else{var t=I[e];S[e]=ue(t,D,i,a),p.push(S[e])}})),p=p.sort((function(e,t){return t-e}));var g=!1;for(l=0;l=0;p--)h(p)}));var W=[];null==T||T.forEach((function(n){for(var d=v[n.id].idx,u=ae(e.nodes,s[d],d,i,o).neighbors,c=!1,l=u.length-1;l>=0;l--){if(u.length+1B[p][m])u.splice(l,1);else{if(r){var L="".concat(h.id,"-").concat(n.id),w=f[L];if(m=H[p].length-1,w>H[p][m]){u.splice(l,1);continue}}var k=S[g]?S[g]:le(e,n,h,v,y,N,D,i,a,S,I),x="".concat(P.id,"-").concat(p);if(k=0&&"break"!==N(p);p--);if(L)return W.splice(n,1),"continue";o.edges=c;var w=C(o,o.nodes[0].id,!1).length;if(Object.keys(w).reverse().forEach((function(e){if(e!==o.nodes[0].id&&!L){if(w[e]===1/0){var t=s[e].node[i];if(u[t]--,u[t]V[n][V[n].length-1]){if(t=s[e].node[i],u[t]--,u[t]=0;x--){var M=o.nodes[x],j=s[M.id].degree,O=s[M.id].inDegree,D=s[M.id].outDegree,S=M[i],A=he(R,S,b,E),T=A.minPatternNodeLabelDegree,q=A.minPatternNodeLabelInDegree,F=A.minPatternNodeLabelOutDegree;if(r?j=0;G--){var U=c[G];if(!s[U.source]||!s[U.target]){c.splice(G,1);var z=U[a];if(f[z]--,s[U.source]&&(s[U.source].degree--,s[U.source].outDegree--),s[U.target]&&(s[U.target].degree--,s[U.target].inDegree--),m[z]&&f[z]=0&&"break"!==J(Q);Q--);var X=W.length,Y=function(e){var t=W[e],r={};t.edges.forEach((function(e){var t="".concat(e.source,"-").concat(e.target,"-").concat(e.label);r[t]?r[t]++:r[t]=1}));for(var n=function(e){var t=W[e],n={};t.edges.forEach((function(e){var t="".concat(e.source,"-").concat(e.target,"-").concat(e.label);n[t]?n[t]++:n[t]=1}));var o=!0;Object.keys(n).length!==Object.keys(r).length?o=!1:Object.keys(r).forEach((function(e){n[e]!==r[e]&&(o=!1)})),o&&W.splice(e,1)},o=X-1;o>e;o--)n(o);X=W.length};for(Q=0;Q<=X-1;Q++)Y(Q);return W}}}};return t.default})())); //# sourceMappingURL=index.min.js.map