(()=>{"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),r:e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})}},t={};e.r(t),e.d(t,{GADDI:()=>le,breadthFirstSearch:()=>c,connectedComponent:()=>l,depthFirstSearch:()=>y,detectCycle:()=>m,dijkstra:()=>D,findAllPath:()=>C,findShortestPath:()=>P,floydWarshall:()=>T,getAdjMatrix:()=>r,getDegree:()=>p,getInDegree:()=>g,getNeighbors:()=>d,getOutDegree:()=>b,labelPropagation:()=>q,louvain:()=>z,minimumSpanningTree:()=>V,pageRank:()=>J});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}))},s=function(e,t){return t.filter((function(t){return t.source===e||t.target===e}))},u=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)};const c=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,s=e.edges,u=void 0===s?[]:s;i.enqueue(t);for(var c="",f=function(){var e=i.dequeue();o.enter({current:e,previous:c}),d(e,u,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()};var f=function(e){for(var t=e.nodes,r=void 0===t?[]:t,n=e.edges,o=void 0===n?[]:n,i=[],a={},s=[],u=function(e){s.push(e),a[e.id]=!0;for(var t=d(e.id,o),n=function(e){var n=t[e];if(!a[n]){var o=r.filter((function(e){return e.id===n}));o.length>0&&u(o[0])}},i=0;i0;)h.push(s.pop());i.push(h)}}return i},h=function(e){for(var t=e.nodes,r=void 0===t?[]:t,n=e.edges,o=void 0===n?[]:n,i=[],a={},s={},u={},c=[],f=0,h=function(e){s[e.id]=f,u[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(s[o]||0===s[o])a[o]&&(u[e.id]=Math.min(u[e.id],s[o]));else{var i=r.filter((function(e){return e.id===o}));i.length>0&&h(i[0]),u[e.id]=Math.min(u[e.id],u[o])}},l=0;l0;){var p=i.pop();if(a[p.id]=!1,v.push(p),p===e)break}v.length>0&&c.push(v)}},l=0,v=r;lf[t.id]+d?(f[a]=f[t.id]+d,h[a]=[t.id]):f[a]===f[t.id]+d&&h[a].push(t.id)}))},p=0;p0&&c.length>0;){var l=c[c.length-1];if(l.length){var v=l.shift();if(v&&(s.push(v),u[v]=!0,h=n?d(v,a,"target"):d(v,a),c.push(h.filter((function(e){return!u[e]})))),s[s.length-1]===r){var p=s.map((function(e){return e}));f.push(p),g=s.pop(),u[g]=!1,c.pop()}}else{var g=s.pop();u[g]=!1,c.pop()}}return f};const T=function(e,t){for(var n=r(e,t),o=[],i=n.length,a=0;ao[a][s]+o[s][d]&&(o[a][d]=o[a][s]+o[s][d]);return o},q=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,s=void 0===d?[]:d,c={},f={};a.forEach((function(e,t){var r=u();e.clusterId=r,c[r]={id:r,nodes:[e]},f[e.id]={node:e,idx:t}}));var h=r(e,t),l=[],v={};h.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}})),l.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 s=Math.floor(Math.random()*o.length),u=c[o[s]];u.nodes.push(t),t.clusterId=u.id}}})),!e)return"break";p++};p0&&M>I&&M-II&&(k=f.map((function(e){return{node:e,clusterId:e.clusterId}})),O=x(E),I=M),D||j>100)break;j++,Object.keys(E).forEach((function(e){var t=0;l.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),s=0,c=o.nodes;c.forEach((function(e){var r=y[e.id].idx;s+=m[t][r]||0}));var f=s-o.sumTot*d,h=c.filter((function(t){return t.id!==e.id})),p=[];h.forEach((function(e,t){p[t]=v[e.originIndex]}));var g=G(h,v)*u,b=N[e.id];if(Object.keys(b).forEach((function(n){var o=y[n].node.clusterId;if(o!==e.clusterId){var s=E[o],c=s.nodes;if(c&&c.length){var h=0;c.forEach((function(e){var r=y[e.id].idx;h+=m[t][r]||0}));var l=h-s.sumTot*d,p=c.concat([e]),b=[];p.forEach((function(e,t){b[t]=v[e.originIndex]}));var L=G(p,v)*u,N=l-f;i&&(N=l+L-(f+g)),N>a&&(a=N,r=s)}}})),a>0){r.nodes.push(e);var M=e.clusterId;e.clusterId=r.id;var I=o.nodes.indexOf(e);o.nodes.splice(I,1);var j=0,k=0;l.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)&&(j+=e[n]||1),(i===M&&a!==M||a===M&&i!==M)&&(k+=e[n]||1)})),r.sumTot=j,o.sumTot=k}}))}var S={},P=0;Object.keys(O).forEach((function(e){var t=O[e];if(t.nodes&&t.nodes.length){var r=String(P+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],P++)}else delete O[e]})),k.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 C=[],T={};l.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(T[d])T[d].weight+=o,T[d].count++;else{var s={source:i,target:a,weight:o,count:1};T[d]=s,C.push(s)}}}));var q=[];return Object.keys(O).forEach((function(e){q.push(O[e])})),{clusters:q,clusterEdges:C}},_=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 W=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],u=new Set;u.add(d);var c=new H((function(e,r){return t?e.weight-r.weight:0}));for(s(d.id,a).forEach((function(e){c.insert(e)}));!c.isEmpty();){var f=c.delMin(),h=f.source,l=f.target;u.has(h)&&u.has(l)||(r.push(f),u.has(h)||(u.add(h),s(h,a).forEach((function(e){c.insert(e)}))),u.has(l)||(u.add(l),s(l,a).forEach((function(e){c.insert(e)}))))}return r},K=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 s=new _(o.map((function(e){return e.id})));d.length>0;){var u=d.shift(),c=u.source,f=u.target;s.connected(c,f)||(r.push(u),s.union(c,f))}return r};const V=function(e,t,r){return r?{prim:W,kruskal:K}[r](e,t):K(e,t)},J=function(e,t,r){"number"!=typeof t&&(t=1e-6),"number"!=typeof r&&(r=.85);for(var n,o=1,i=0,a=1e3,s=e.nodes,u=void 0===s?[]:s,c=e.edges,f=void 0===c?[]:c,h=u.length,l={},v={},g=0;g0&&o>t;){for(i=0,g=0;g0&&(n+=v[L]/N)}l[E]=r*n,i+=l[E]}}for(i=(1-i)/h,o=0,g=0;g=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(h){var b=e.findMinLabel(f);i.dfsEdgeList.push(new $(c,l,Q,b.edgeLabel,Q));var E=i.dfsEdgeList.length-1;return e.dfsCode.dfsEdgeList[E]===i.dfsEdgeList[E]&&s(f[b.edgeLabel].projected)}var y={};h=!1;var m=0;a.forEach((function(t){var r=new te(t),i=e.findForwardPureEdges(n,r.edges[d[0]],u,r);i.length>0&&(h=!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(h)return"break";var r=d[t];a.forEach((function(t){var a=new te(t),d=e.findForwardRmpathEdges(n,a.edges[r],u,a);d.length>0&&(h=!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 h=t.findBackwardEdge(s,c.edges[n[f]],c.edges[n[0]],c);if(h){var l="".concat(t.dfsCode.dfsEdgeList[n[f]].fromNode,"-").concat(h.label);d[l]||(d[l]={projected:[],toNodeId:t.dfsCode.dfsEdgeList[n[f]].fromNode,edgeLabel:h.label}),d[l].projected.push({graphId:e.graphId,edge:h,preNode:e})}}if(!(r>=t.maxNodeNum)){t.findForwardPureEdges(s,c.edges[n[0]],i,c).forEach((function(t){var r="".concat(o,"-").concat(t.label,"-").concat(u[t.to].label);a[r]||(a[r]={projected:[],fromNodeId:o,edgeLabel:t.label,nodeLabel2:u[t.to].label}),a[r].projected.push({graphId:e.graphId,edge:t,preNode:e})}));var v=function(r){t.findForwardRmpathEdges(s,c.edges[n[r]],i,c).forEach((function(o){var i="".concat(t.dfsCode.dfsEdgeList[n[r]].fromNode,"-").concat(o.label,"-").concat(u[o.to].label);a[i]||(a[i]={projected:[],fromNodeId:t.dfsCode.dfsEdgeList[n[r]].fromNode,edgeLabel:o.label,nodeLabel2:u[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),h="".concat(n,"-").concat(c,"-").concat(o);if(!i[h]){var l=i[h]||0;l++,i[h]=l}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;s>n&&(s=n);var o=r[e.id].outDegree;u>o&&(u=o)})),e[t]={degree:d,inDegree:s,outDegree:u}),{minPatternNodeLabelDegree:d,minPatternNodeLabelInDegree:s,minPatternNodeLabelOutDegree:u}};const le=function(e,t,r,n,o,i,a){var d;if(void 0===r&&(r=!1),void 0===i&&(i="cluster"),void 0===a&&(a="cluster"),e&&e.nodes){var s=e.nodes.length;if(s){var u=T(e,r),c=T(t,r),f=ce(e.nodes,u,r),h=ce(t.nodes,c,r),l=se(e.nodes,i),v=l.nodeMap,p=l.nodeLabelMap,g=se(t.nodes,i),b=g.nodeMap,E=g.nodeLabelMap;ue(e.edges,a,v);var y=ue(t.edges,a,b).edgeLabelMap,m=[];null==c||c.forEach((function(e){m=m.concat(e)})),o||(o=Math.max.apply(Math,L(L([],m,!1),[2],!1))),n||(n=o);var N=oe(e,u,i,n),w=oe(t,c,i,n),M=function(e,t,r,n,o){var i=Math.ceil(r/t),a={},d=0;return n.forEach((function(e,n){for(var s=0,u=0,c=e.nodeIdxs,f=e.neighborNum-1;s2*t)););if(l<2*t&&(a["".concat(n,"-").concat(h)]={start:n,end:h,distance:o[n][h]},s++,++d>=r))return a;if(++u>2*t)break}sF&&(F=r.length,q=r,A=t,C=e)}));var R={},U={},G={},z={},_={},B={};Object.keys(E).forEach((function(n,o){_[n]=[],r&&(B[n]=[]);var d=-1/0,s=E[n],u={};s.forEach((function(e){var t=h["".concat(C.id,"-").concat(e.id)];if(t&&_[n].push(t),d_[n][h]){u=!0;break}if(u)return q.splice(t,1),"continue";var l={};o.neighbors.forEach((function(e){var t=f["".concat(r.id,"-").concat(e.id)];l["".concat(r.id,"-").concat(e.id)]={start:v[r.id].idx,end:v[e.id].idx,distance:t}})),I=ae(l,N,e,I);var p=[];Object.keys(l).forEach((function(e){if(P[e])p.push(P[e]);else{var t=I[e];P[e]=de(t,S,i,a),p.push(P[e])}})),p=p.sort((function(e,t){return t-e}));var g=!1;for(h=0;h=0;p--)l(p)}));var H=[];null==q||q.forEach((function(n){for(var d=v[n.id].idx,s=ie(e.nodes,u[d],d,i,o).neighbors,c=!1,h=s.length-1;h>=0;h--){if(s.length+1_[p][m])s.splice(h,1);else{if(r){var L="".concat(l.id,"-").concat(n.id),w=f[L];if(m=B[p].length-1,w>B[p][m]){s.splice(h,1);continue}}var M=P[g]?P[g]:fe(e,n,l,v,y,N,S,i,a,P,I),j="".concat(C.id,"-").concat(p);if(M=0&&"break"!==N(p);p--);if(L)return H.splice(n,1),"continue";o.edges=c;var w=D(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=u[e].node[i];if(s[t]--,s[t]K[n][K[n].length-1]){if(t=u[e].node[i],s[t]--,s[t]=0;j--){var k=o.nodes[j],x=u[k.id].degree,O=u[k.id].inDegree,S=u[k.id].outDegree,P=k[i],T=he(R,P,b,E),q=T.minPatternNodeLabelDegree,A=T.minPatternNodeLabelInDegree,F=T.minPatternNodeLabelOutDegree;if(r?x=0;U--){var G=c[U];if(!u[G.source]||!u[G.target]){c.splice(U,1);var z=G[a];if(f[z]--,u[G.source]&&(u[G.source].degree--,u[G.source].outDegree--),u[G.target]&&(u[G.target].degree--,u[G.target].inDegree--),y[z]&&f[z]=0&&"break"!==V(J);J--);var Q=H.length,X=function(e){var t=H[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=H[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&&H.splice(e,1)},o=Q-1;o>e;o--)n(o);Q=H.length};for(J=0;J<=Q-1;J++)X(J);return H}}};var ve="undefined"!=typeof self?self:{};ve.onmessage=function(e){var r=e.data,n=r._algorithmType,o=r.data;if(n)if("function"!=typeof t[n])ve.postMessage({_algorithmType:"FAILURE"});else{var i=t[n].apply(t,o);ve.postMessage({_algorithmType:"SUCCESS",data:i})}}})(); //# sourceMappingURL=index.worker.js.map