@antv/algorithm
Advanced tools
Comparing version 0.1.8-beta.5 to 0.1.8-beta.6
@@ -1,2 +0,2 @@ | ||
(()=>{"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:()=>re,breadthFirstSearch:()=>f,connectedComponent:()=>h,depthFirstSearch:()=>b,detectCycle:()=>E,dijkstra:()=>k,findAllPath:()=>x,findShortestPath:()=>I,floydWarshall:()=>O,getAdjMatrix:()=>r,getDegree:()=>l,getInDegree:()=>p,getNeighbors:()=>d,getOutDegree:()=>v,labelPropagation:()=>S,louvain:()=>P,minimumSpanningTree:()=>R,pageRank:()=>U});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):""+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){return void 0===e&&(e=0),e+"-"+(""+Math.random()).split(".")[1].substr(0,5)+(""+Math.random()).split(".")[1].substr(0,5)};const f=function(e,t,r){var n=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),o=new a,i=e.edges,s=void 0===i?[]:i;o.enqueue(t);for(var u="",f=function(){var e=o.dequeue();n.enter({current:e,previous:u}),d(e,s,"target").forEach((function(t){n.allowTraversal({previous:u,current:e,next:t})&&o.enqueue(t)})),n.leave({current:e,previous:u}),u=e};!o.isEmpty();)f()};function h(e,t){return t?function(e){for(var t=e.nodes,r=void 0===t?[]:t,n=e.edges,o=void 0===n?[]:n,i=[],a={},s={},u={},f=[],h=0,c=function(e){s[e.id]=h,u[e.id]=h,h+=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&&c(i[0]),u[e.id]=Math.min(u[e.id],u[o])}},l=0;l<t.length;l++)n(l);if(u[e.id]===s[e.id]){for(var p=[];i.length>0;){var v=i.pop();if(a[v.id]=!1,p.push(v),v===e)break}p.length>0&&f.push(p)}},l=0,p=r;l<p.length;l++){var v=p[l];s[v.id]||0===s[v.id]||c(v)}return f}(e):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;i<t.length;++i)n(i)},f=0;f<r.length;f++){var h=r[f];if(!a[h.id]){u(h);for(var c=[];s.length>0;)c.push(s.pop());i.push(c)}}return i}(e)}var c=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 l=c;var p=function(e,t){return c(e)[t]?c(e)[t].inDegree:0},v=function(e,t){return c(e)[t]?c(e)[t].outDegree:0};function g(e,t,r,n){n.enter({current:t,previous:r});var o=e.edges;d(t,void 0===o?[]:o,"target").forEach((function(o){n.allowTraversal({previous:r,current:t,next:o})&&g(e,o,t,n)})),n.leave({current:t,previous:r})}function b(e,t,r){g(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))}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,s=a;s!==r;)t[d]=s,d=s,s=n[s];t[d]=s}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;)b(e,Object.keys(o)[0],d);return t};function m(e,t){for(var r=0,n=t.length,o=e.length;r<n;r++,o++)e[o]=t[r];return e}Object.create,Object.create;var y={}.toString;const L=function(e,t){return y.call(e)==="[object "+t+"]"},N=function(e){return Array.isArray?Array.isArray(e):L(e,"Array")};Object.keys;var M=Array.prototype;M.splice,M.indexOf,Array.prototype.splice,Object.prototype.hasOwnProperty;Number.isInteger&&Number.isInteger,Math.PI,parseInt,Math.PI,Object.values,Object.prototype;const j=function e(t){if("object"!=typeof t||null===t)return t;var r;if(N(t)){r=[];for(var n=0,o=t.length;n<o;n++)"object"==typeof t[n]&&null!=t[n]?r[n]=e(t[n]):r[n]=t[n]}else for(var i in r={},t)"object"==typeof t[i]&&null!=t[i]?r[i]=e(t[i]):r[i]=t[i];return r};Object.prototype.hasOwnProperty,Object.prototype.hasOwnProperty,function(){function e(){this.map={}}e.prototype.has=function(e){return void 0!==this.map[e]},e.prototype.get=function(e,t){var r=this.map[e];return void 0===r?t:r},e.prototype.set=function(e,t){this.map[e]=t},e.prototype.clear=function(){this.map={}},e.prototype.delete=function(e){delete this.map[e]},e.prototype.size=function(){return Object.keys(this.map).length}}();const k=function(e,t,r,n){var o=e.nodes,i=void 0===o?[]:o,a=e.edges,d=void 0===a?[]:a,u=[],f={},h={},c={};i.forEach((function(e,r){var n=e.id;u.push(n),h[n]=1/0,n===t&&(h[n]=0)}));for(var l=i.length,p=function(e){var t=function(e,t,r){for(var n,o=1/0,i=0;i<t.length;i++){var a=t[i].id;!r[a]&&e[a]<=o&&(o=e[a],n=t[i])}return n}(h,i,f),o=t.id;if(f[o]=!0,h[o]===1/0)return"continue";(r?function(e,t){return t.filter((function(t){return t.source===e}))}(o,d):s(o,d)).forEach((function(e){var r=e.target,i=e.source,a=r===o?i:r,d=n&&e[n]?e[n]:1;h[a]>h[t.id]+d?(h[a]=h[t.id]+d,c[a]=[t.id]):h[a]===h[t.id]+d&&c[a].push(t.id)}))},v=0;v<l;v++)p();c[t]=[t];var g={};for(var b in h)h[b]!==1/0&&w(t,b,c,g);var E={};for(var b in g)E[b]=g[b][0];return{length:h,path:E,allPath:g}};function w(e,t,r,n){if(e===t)return[e];if(n[t])return n[t];for(var o=[],i=0,a=r[t];i<a.length;i++){var d=w(e,a[i],r,n);if(!d)return;for(var s=0,u=d;s<u.length;s++){var f=u[s];N(f)?o.push(m(m([],f),[t])):o.push([f,t])}}return n[t]=o,n[t]}var I=function(e,t,r,n,o){var i=k(e,t,n,o),a=i.length,d=i.path,s=i.allPath;return{length:a[r],path:d[r],allPath:s[r]}},x=function(e,t,r,n){var o;if(t===r)return[[t]];var i=e.edges,a=void 0===i?[]:i,s=[t],u=((o={})[t]=!0,o),f=[],h=[],c=n?d(t,a,"target"):d(t,a);for(f.push(c);s.length>0&&f.length>0;){var l=f[f.length-1];if(l.length){var p=l.shift();if(p&&(s.push(p),u[p]=!0,c=n?d(p,a,"target"):d(p,a),f.push(c.filter((function(e){return!u[e]})))),s[s.length-1]===r){var v=s.map((function(e){return e}));h.push(v),g=s.pop(),u[g]=!1,f.pop()}}else{var g=s.pop();u[g]=!1,f.pop()}}return h};const O=function(e,t){for(var n=r(e,t),o=[],i=n.length,a=0;a<i;a+=1){o[a]=[];for(var d=0;d<i;d+=1)a===d?o[a][d]=0:0!==n[a][d]&&n[a][d]?o[a][d]=n[a][d]:o[a][d]=1/0}for(var s=0;s<i;s+=1)for(a=0;a<i;a+=1)for(d=0;d<i;d+=1)o[a][d]>o[a][s]+o[s][d]&&(o[a][d]=o[a][s]+o[s][d]);return o},S=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,f={},h={};a.forEach((function(e,t){var r=u();e.clusterId=r,f[r]={id:r,nodes:[e]},h[e.id]={node:e,idx:t}}));var c=r(e,t),l=[],p={};c.forEach((function(e,t){var r=0,n=a[t].id;p[n]={},e.forEach((function(e,t){if(e){r+=e;var o=a[t].id;p[n][o]=e}})),l.push(r)}));for(var v=0,g=function(){var e=!1;if(a.forEach((function(t){var r={};Object.keys(p[t.id]).forEach((function(e){var n=p[t.id][e],o=h[e].node.clusterId;r[o]||(r[o]=0),r[o]+=n}));var n=-1/0,o=[];if(Object.keys(r).forEach((function(e){n<r[e]?(n=r[e],o=[e]):n===r[e]&&o.push(e)})),1!==o.length||o[0]!==t.clusterId){var i=o.indexOf(t.clusterId);if(i>=0&&o.splice(i,1),o&&o.length){e=!0;var a=f[t.clusterId],d=a.nodes.indexOf(t);a.nodes.splice(d,1);var s=Math.floor(Math.random()*o.length),u=f[o[s]];u.nodes.push(t),t.clusterId=u.id}}})),!e)return"break";v++};v<o&&"break"!==g(););Object.keys(f).forEach((function(e){var t=f[e];t.nodes&&t.nodes.length||delete f[e]}));var b=[],E={};s.forEach((function(e){var t=e.source,r=e.target,o=e[n]||1,i=h[t].node.clusterId,a=h[r].node.clusterId,d=i+"---"+a;if(E[d])E[d].weight+=o,E[d].count++;else{var s={source:i,target:a,weight:o,count:1};E[d]=s,b.push(s)}}));var m=[];return Object.keys(f).forEach((function(e){m.push(f[e])})),{clusters:m,clusterEdges:b}};var C=function(e,t,r,n){for(var o=t.length,i=2*n,a=0,d=0;d<o;d++)for(var s=e[d].clusterId,u=0;u<o;u++)s===e[u].clusterId&&(a+=(t[d][u]||0)-(r[d]||0)*(r[u]||0)/i);return a*(1/i)};const P=function(e,t,n,o){void 0===t&&(t=!1),void 0===n&&(n="weight"),void 0===o&&(o=1e-4);var i=e.nodes,a=void 0===i?[]:i,d=e.edges,s=void 0===d?[]:d,u=1,f={},h={};a.forEach((function(e,t){var r=String(u++);e.clusterId=r,f[r]={id:r,nodes:[e]},h[e.id]={node:e,idx:t}}));var c=r(e,t),l=[],p={},v=0;c.forEach((function(e,t){var r=0,n=a[t].id;p[n]={},e.forEach((function(e,t){if(e){r+=e;var o=a[t].id;p[n][o]=e,v+=e}})),l.push(r)})),v/=2;for(var g=1/0,b=1/0,E=0;g=C(a,c,l,v),!(Math.abs(g-b)<o||E>100);)b=g,E++,Object.keys(f).forEach((function(e){var t=0;s.forEach((function(r){var o=r.source,i=r.target,a=h[o].node.clusterId,d=h[i].node.clusterId;(a===e&&d!==e||d===e&&a!==e)&&(t+=r[n]||1)})),f[e].sumTot=t})),a.forEach((function(e,t){var r,o=f[e.clusterId],i=0,a=l[t]/(2*v),d=0;o.nodes.forEach((function(e){var r=h[e.id].idx;d+=c[t][r]||0}));var u=d-o.sumTot*a,g=p[e.id];if(Object.keys(g).forEach((function(n){var o=h[n].node.clusterId;if(o!==e.clusterId){var d=f[o],s=d.nodes;if(s&&s.length){var l=0;s.forEach((function(e){var r=h[e.id].idx;l+=c[t][r]||0}));var p=l-d.sumTot*a-u;p>i&&(i=p,r=d)}}})),i>0){r.nodes.push(e);var b=e.clusterId;e.clusterId=r.id;var E=o.nodes.indexOf(e);o.nodes.splice(E,1);var m=0,y=0;s.forEach((function(e){var t=e.source,o=e.target,i=h[t].node.clusterId,a=h[o].node.clusterId;(i===r.id&&a!==r.id||a===r.id&&i!==r.id)&&(m+=e[n]||1),(i===b&&a!==b||a===b&&i!==b)&&(y+=e[n]||1)})),r.sumTot=m,o.sumTot=y}}));var m={},y=0;Object.keys(f).forEach((function(e){var t=f[e];if(t.nodes&&t.nodes.length){var r=String(y+1);r!==e&&(t.id=r,t.nodes=t.nodes.map((function(e){return{id:e.id,clusterId:r}})),f[r]=t,m[e]=r,delete f[e],y++)}else delete f[e]})),a.forEach((function(e){e.clusterId&&m[e.clusterId]&&(e.clusterId=m[e.clusterId])}));var L=[],N={};s.forEach((function(e){var t=e.source,r=e.target,o=e[n]||1,i=h[t].node.clusterId,a=h[r].node.clusterId,d=i+"---"+a;if(N[d])N[d].weight+=o,N[d].count++;else{var s={source:i,target:a,weight:o,count:1};N[d]=s,L.push(s)}}));var M=[];return Object.keys(f).forEach((function(e){M.push(f[e])})),{clusters:M,clusterEdges:L}},T=function(){function e(e){this.count=e.length,this.parent={};for(var t=0,r=e;t<r.length;t++){var n=r[t];this.parent[n]=n}}return e.prototype.find=function(e){for(;this.parent[e]!==e;)e=this.parent[e];return e},e.prototype.union=function(e,t){var r=this.find(e),n=this.find(t);r!==n&&(r<n?(this.parent[t]!==t&&this.union(this.parent[t],e),this.parent[t]=this.parent[e]):(this.parent[e]!==e&&this.union(this.parent[e],t),this.parent[e]=this.parent[t]))},e.prototype.connected=function(e,t){return this.find(e)===this.find(t)},e}();var q=function(e,t){return e-t};const F=function(){function e(e){void 0===e&&(e=q),this.compareFn=e,this.list=[]}return e.prototype.getLeft=function(e){return 2*e+1},e.prototype.getRight=function(e){return 2*e+2},e.prototype.getParent=function(e){return 0===e?null:Math.floor((e-1)/2)},e.prototype.isEmpty=function(){return this.list.length<=0},e.prototype.top=function(){return this.isEmpty()?void 0:this.list[0]},e.prototype.delMin=function(){var e=this.top(),t=this.list.pop();return this.list.length>0&&(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&&n<i&&this.compareFn(this.list[r],this.list[n])>0?r=n:null!==o&&o<i&&this.compareFn(this.list[r],this.list[o])>0&&(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 D=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 f=new F((function(e,r){return t?e.weight-r.weight:0}));for(s(d.id,a).forEach((function(e){f.insert(e)}));!f.isEmpty();){var h=f.delMin(),c=h.source,l=h.target;u.has(c)&&u.has(l)||(r.push(h),u.has(c)||(u.add(c),s(c,a).forEach((function(e){f.insert(e)}))),u.has(l)||(u.add(l),s(l,a).forEach((function(e){f.insert(e)}))))}return r},A=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 T(o.map((function(e){return e.id})));d.length>0;){var u=d.shift(),f=u.source,h=u.target;s.connected(f,h)||(r.push(u),s.union(f,h))}return r};const R=function(e,t,r){return r?{prim:D,kruskal:A}[r](e,t):A(e,t)},U=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,f=e.edges,h=void 0===f?[]:f,c=u.length,p={},v={},g=0;g<c;++g)p[E=(M=u[g]).id]=1/c,v[E]=1/c;for(var b=l(e);a>0&&o>t;){for(i=0,g=0;g<c;++g){var E=(M=u[g]).id;if(n=0,0===b[M.id].inDegree)p[E]=0;else{for(var m=d(E,h,"source"),y=0;y<m.length;++y){var L=m[y],N=b[L].outDegree;N>0&&(n+=v[L]/N)}p[E]=r*n,i+=p[E]}}for(i=(1-i)/c,o=0,g=0;g<c;++g){var M;n=p[E=(M=u[g]).id]+i,o+=Math.abs(n-v[E]),v[E]=n}a-=1}return v};var G="-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},B=function(){function e(e,t){void 0===e&&(e=-1),void 0===t&&(t=G),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}(),H=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 B(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}(),_=function(){function e(e,t,r,n,o){this.fromNode=e,this.toNode=t,this.nodeEdgeNodeLabel={nodeLabel1:r||G,edgeLabel:n||"-1",nodeLabel2:o||G}}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}(),K=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<t;r++)if(this.dfsEdgeList[r]!==e[r])return!1;return!0},e.prototype.notEqualTo=function(e){return!this.equalTo(e)},e.prototype.pushBack=function(e,t,r,n,o){return this.dfsEdgeList.push(new _(e,t,r,n,o)),this.dfsEdgeList},e.prototype.toGraph=function(e,t){void 0===e&&(e=-1),void 0===t&&(t=!1);var r=new H(e,!0,t);return this.dfsEdgeList.forEach((function(e){var t=e.fromNode,n=e.toNode,o=e.nodeEdgeNodeLabel,i=o.nodeLabel1,a=o.edgeLabel,d=o.nodeLabel2;i!==G&&r.addNode(t,i),d!==G&&r.addNode(n,d),r.addEdge(void 0,t,n,a)})),r},e.prototype.buildRmpath=function(){this.rmpath=[];for(var e=void 0,t=this.dfsEdgeList.length-1;t>=0;t--){var r=this.dfsEdgeList[t],n=r.fromNode,o=r.toNode;n<o&&(void 0===e||o===e)&&(this.rmpath.push(t),e=n)}return this.rmpath},e.prototype.getNodeNum=function(){var e={};return this.dfsEdgeList.forEach((function(t){e[t.fromNode]||(e[t.fromNode]=!0),e[t.toNode]||(e[t.toNode]=!0)})),Object.keys(e).length},e}(),W=function(){function e(e){if(this.his={},this.nodesUsed={},this.edgesUsed={},this.edges=[],e){for(;e;){var t=e.edge;this.edges.push(t),this.nodesUsed[t.from]=1,this.nodesUsed[t.to]=1,this.edgesUsed[t.id]=1,e=e.preNode}this.edges=this.edges.reverse()}}return e.prototype.hasNode=function(e){return 1===this.nodesUsed[e.id]},e.prototype.hasEdge=function(e){return 1===this.edgesUsed[e.id]},e}(),J=function(){function e(e){var t=e.graphs,r=e.minSupport,n=void 0===r?2:r,o=e.minNodeNum,i=void 0===o?1:o,a=e.maxNodeNum,d=void 0===a?4:a,s=e.top,u=void 0===s?10:s,f=e.directed,h=void 0!==f&&f,c=e.verbose,l=void 0!==c&&c;this.graphs=t,this.dfsCode=new K,this.support=0,this.frequentSize1Subgraphs=[],this.frequentSubgraphs=[],this.minSupport=n,this.top=u,this.directed=h,this.counter=0,this.maxNodeNum=d,this.minNodeNum=i,this.verbose=l,this.maxNodeNum<this.minNodeNum&&(this.maxNodeNum=this.minNodeNum),this.reportDF=[]}return e.prototype.findForwardRootEdges=function(e,t){var r=this,n=[],o=e.nodeMap;return t.edges.forEach((function(e){(r.directed||t.label<=o[e.to].label)&&n.push(e)})),n},e.prototype.findBackwardEdge=function(e,t,r,n){if(!this.directed&&t===r)return null;for(var o=e.nodeMap,i=o[r.to].edges,a=i.length,d=0;d<a;d++){var s=i[d];if(!n.hasEdge(s)&&s.to===t.from)if(this.directed){if(o[t.from].label<o[r.to].label||o[t.from].label===o[r.to].label&&t.label<=s.label)return s}else if(t.label<s.label||t.label===s.label&&o[t.to].label<=o[r.to].label)return s}return null},e.prototype.findForwardPureEdges=function(e,t,r,n){for(var o=[],i=t.to,a=e.nodeMap[i].edges,d=a.length,s=0;s<d;s++){var u=a[s],f=e.nodeMap[u.to];r<=f.label&&!n.hasNode(f)&&o.push(u)}return o},e.prototype.findForwardRmpathEdges=function(e,t,r,n){for(var o=[],i=e.nodeMap,a=i[t.to].label,d=i[t.from].edges,s=d.length,u=0;u<s;u++){var f=d[u],h=i[f.to].label;t.to===f.to||r>h||n.hasNode(i[f.to])||(t.label<f.label||t.label===f.label&&a<=h)&&o.push(f)}return o},e.prototype.getSupport=function(e){var t={};return e.forEach((function(e){t[e.graphId]||(t[e.graphId]=!0)})),Object.keys(t).length},e.prototype.findMinLabel=function(e){var t=void 0;return Object.keys(e).forEach((function(r){var n=e[r],o=n.nodeLabel1,i=n.edgeLabel,a=n.nodeLabel2;t?(o<t.nodeLabel1||o===t.nodeLabel1&&i<t.edgeLabel||o===t.nodeLabel1&&i===t.edgeLabel&&a<t.nodeLabel2)&&(t={nodeLabel1:o,edgeLabel:i,nodeLabel2:a}):t={nodeLabel1:o,edgeLabel:i,nodeLabel2:a}})),t},e.prototype.isMin=function(){var e=this,t=this.dfsCode;if(this.verbose&&console.log("isMin checking",t),1===t.dfsEdgeList.length)return!0;var r=this.directed,n=t.toGraph(-1,r),o=n.nodeMap,i=new K,a={};n.nodes.forEach((function(t){e.findForwardRootEdges(n,t).forEach((function(e){var r=o[e.to],i=t.label+"-"+e.label+"-"+r.label;a[i]||(a[i]={projected:[],nodeLabel1:t.label,edgeLabel:e.label,nodeLabel2:r.label});var d={graphId:n.id,edge:e,preNode:null};a[i].projected.push(d)}))}));var d=this.findMinLabel(a);i.dfsEdgeList.push(new _(0,1,d.nodeLabel1,d.edgeLabel,d.nodeLabel2));var s=function(a){for(var d=i.buildRmpath(),u=i.dfsEdgeList[0].nodeEdgeNodeLabel.nodeLabel1,f=i.dfsEdgeList[d[0]].toNode,h={},c=!1,l=0,p=r?-1:0,v=function(t){if(c)return"break";a.forEach((function(r){var o=new W(r),a=e.findBackwardEdge(n,o.edges[d[t]],o.edges[d[0]],o);a&&(h[a.label]||(h[a.label]={projected:[],edgeLabel:a.label}),h[a.label].projected.push({graphId:n.id,edge:h,preNode:r}),l=i.dfsEdgeList[d[t]].fromNode,c=!0)}))},g=d.length-1;g>p&&"break"!==v(g);g--);if(c){var b=e.findMinLabel(h);i.dfsEdgeList.push(new _(f,l,G,b.edgeLabel,G));var E=i.dfsEdgeList.length-1;return e.dfsCode.dfsEdgeList[E]===i.dfsEdgeList[E]&&s(h[b.edgeLabel].projected)}var m={};c=!1;var y=0;a.forEach((function(t){var r=new W(t),i=e.findForwardPureEdges(n,r.edges[d[0]],u,r);i.length>0&&(c=!0,y=f,i.forEach((function(e){var r=e.label+"-"+o[e.to].label;m[r]||(m[r]={projected:[],edgeLabel:e.label,nodeLabel2:o[e.to].label}),m[r].projected.push({graphId:n.id,edge:e,preNode:t})})))}));var L=d.length,N=function(t){if(c)return"break";var r=d[t];a.forEach((function(t){var a=new W(t),d=e.findForwardRmpathEdges(n,a.edges[r],u,a);d.length>0&&(c=!0,y=i.dfsEdgeList[r].fromNode,d.forEach((function(e){var r=e.label+"-"+o[e.to].label;m[r]||(m[r]={projected:[],edgeLabel:e.label,nodeLabel2:o[e.to].label}),m[r].projected.push({graphId:n.id,edge:e,preNode:t})})))}))};for(g=0;g<L&&"break"!==N(g);g++);if(!c)return!0;var M=e.findMinLabel(m);i.dfsEdgeList.push(new _(y,f+1,G,M.edgeLabel,M.nodeLabel2));var j=i.dfsEdgeList.length-1;return t.dfsEdgeList[j]===i.dfsEdgeList[j]&&s(m[M.edgeLabel+"-"+M.nodeLabel2].projected)},u=d.nodeLabel1+"-"+d.edgeLabel+"-"+d.nodeLabel2;return s(a[u].projected)},e.prototype.report=function(){if(!(this.dfsCode.getNodeNum()<this.minNodeNum)){this.counter++;var e=this.dfsCode.toGraph(this.counter,this.directed);this.frequentSubgraphs.push(j(e))}},e.prototype.subGraphMining=function(e){var t=this;if(!(this.getSupport(e)<this.minSupport)&&this.isMin()){this.report();var r=this.dfsCode.getNodeNum(),n=this.dfsCode.buildRmpath(),o=this.dfsCode.dfsEdgeList[n[0]].toNode,i=this.dfsCode.dfsEdgeList[0].nodeEdgeNodeLabel.nodeLabel1,a={},d={};e.forEach((function(e){for(var s=t.graphs[e.graphId],u=s.nodeMap,f=new W(e),h=n.length-1;h>=0;h--){var c=t.findBackwardEdge(s,f.edges[n[h]],f.edges[n[0]],f);if(c){var l=t.dfsCode.dfsEdgeList[n[h]].fromNode+"-"+c.label;d[l]||(d[l]={projected:[],toNodeId:t.dfsCode.dfsEdgeList[n[h]].fromNode,edgeLabel:c.label}),d[l].projected.push({graphId:e.graphId,edge:c,preNode:e})}}if(!(r>=t.maxNodeNum)){t.findForwardPureEdges(s,f.edges[n[0]],i,f).forEach((function(t){var r=o+"-"+t.label+"-"+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 p=function(r){t.findForwardRmpathEdges(s,f.edges[n[r]],i,f).forEach((function(o){var i=t.dfsCode.dfsEdgeList[n[r]].fromNode+"-"+o.label+"-"+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(h=0;h<n.length;h++)p(h)}})),Object.keys(d).forEach((function(e){var r=d[e],n=r.toNodeId,i=r.edgeLabel;t.dfsCode.dfsEdgeList.push(new _(o,n,"-1",i,"-1")),t.subGraphMining(d[e].projected),t.dfsCode.dfsEdgeList.pop()})),Object.keys(a).forEach((function(e){var r=a[e],n=r.fromNodeId,i=r.edgeLabel,d=r.nodeLabel2;t.dfsCode.dfsEdgeList.push(new _(n,o+1,G,i,d)),t.subGraphMining(a[e].projected),t.dfsCode.dfsEdgeList.pop()}))}},e.prototype.generate1EdgeFrequentSubGraphs=function(){var e=this.graphs,t=this.directed,r=this.minSupport,n=this.frequentSize1Subgraphs,o={},i={},a={},d={};return Object.keys(e).forEach((function(r){var n=e[r],s=n.nodeMap;n.nodes.forEach((function(e,n){var u=e.label,f=r+"-"+u;if(!a[f]){var h=o[u]||0;h++,o[u]=h}a[f]={graphKey:r,label:u},e.edges.forEach((function(e){var n=u,o=s[e.to].label;if(!t&&n>o){var a=o;o=n,n=a}var f=e.label,h=r+"-"+n+"-"+f+"-"+o,c=n+"-"+f+"-"+o;if(!i[c]){var l=i[c]||0;l++,i[c]=l}d[h]={graphId:r,nodeLabel1:n,edgeLabel:f,nodeLabel2:o}}))}))})),Object.keys(o).forEach((function(e){if(!(o[e]<r)){var t={nodes:[],edges:[]};t.nodes.push({id:"0",label:e}),n.push(t)}})),n},e.prototype.run=function(){var e=this;if(this.frequentSize1Subgraphs=this.generate1EdgeFrequentSubGraphs(),!(this.maxNodeNum<2)){var t=this.graphs,r=(this.directed,{});Object.keys(t).forEach((function(n){var o=t[n],i=o.nodeMap;o.nodes.forEach((function(t){e.findForwardRootEdges(o,t).forEach((function(e){var o=i[e.to],a=t.label+"-"+e.label+"-"+o.label;r[a]||(r[a]={projected:[],nodeLabel1:t.label,edgeLabel:e.label,nodeLabel2:o.label});var d={graphId:n,edge:e,preNode:null};r[a].projected.push(d)}))}))})),Object.keys(r).forEach((function(t){var n=r[t],o=n.projected,i=n.nodeLabel1,a=n.edgeLabel,d=n.nodeLabel2;e.dfsCode.dfsEdgeList.push(new _(0,1,i,a,d)),e.subGraphMining(o),e.dfsCode.dfsEdgeList.pop()}))}},e}(),Q="cluster";var V=function(e,t,r,n){void 0===r&&(r="cluster"),void 0===n&&(n=2);var o=[],i=e.nodes;return t.forEach((function(e,t){o.push(X(i,e,t,r,n))})),o},X=function(e,t,r,n,o){var i=[r],a=[],d={};return t.forEach((function(t,s){if(t<=o&&r!==s){i.push(s),a.push(e[s]);var u=e[s][n];d[u]?(d[u].count++,d[u].dists.push(t)):d[u]={count:1,dists:[t]}}})),Object.keys(d).forEach((function(e){d[e].dists=d[e].dists.sort((function(e,t){return e-t}))})),{nodeIdx:r,nodeId:e[r].id,nodeIdxs:i,neighbors:a,neighborNum:i.length-1,nodeLabelCountMap:d}},Y=function(e,t,r,n){var o=r.nodes;return n||(n={}),Object.keys(e).forEach((function(i){var a,d;if(!n||!n[i]){n[i]={nodes:[],edges:[]};var s=e[i],u=null===(a=t[s.start])||void 0===a?void 0:a.nodeIdxs,f=null===(d=t[s.end])||void 0===d?void 0:d.nodeIdxs;if(u&&f){var h=new Set(f),c=u.filter((function(e){return h.has(e)}));if(c&&c.length){for(var l={},p=c.length,v=0;v<p;v++){var g=o[c[v]];n[i].nodes.push(g),l[g.id]=!0}r.edges.forEach((function(e){l[e.source]&&l[e.target]&&n[i].edges.push(e)}))}}}})),n},Z=function(e,t,r,n){var o={};e.nodes.forEach((function(e){o[e.id]=e}));var i=0;return e.edges.forEach((function(e){var a=o[e.source][r],d=o[e.target][r],s=t.nodes[0][r],u=t.nodes[1][r],f=t.edges[0][n];e[n]===f&&(a===s&&d===u||a===u&&d===s)&&i++})),i},$=function(e,t){var r={},n={};return e.forEach((function(e,o){r[e.id]={idx:o,node:e,degree:0};var i=e[t];n[i]||(n[i]=[]),n[i].push(e)})),{nodeMap:r,nodeLabelMap:n}},ee=function(e,t,r){var n={},o={};return e.forEach((function(e,i){n[""+u]={idx:i,edge:e};var a=e[t];o[a]||(o[a]=[]),o[a].push(e);var d=r[e.source];d&&d.degree++;var s=r[e.target];s&&s.degree++})),{edgeMap:n,edgeLabelMap:o}},te=function(e,t,r){var n=t.length,o={};return t.forEach((function(t,i){for(var a=r?0:i+1,d=e[i].id,s=a;s<n;s++)if(i!==s){var u=e[s].id,f=t[s];o[d+"-"+u]=f,r||(o[u+"-"+d]=f)}})),o};const re=function(e,t,r,n,o,i,a){if(void 0===r&&(r=!1),void 0===i&&(i="cluster"),void 0===a&&(a="cluster"),e&&e.nodes){var d=e.nodes.length;if(d){var s=O(e,r),u=O(t,r),f=te(e.nodes,s,r),h=te(t.nodes,u,r),c=$(e.nodes,i),l=c.nodeMap,p=c.nodeLabelMap,v=$(t.nodes,i),g=v.nodeMap,b=v.nodeLabelMap;ee(e.edges,a,l);var E=ee(t.edges,a,g).edgeLabelMap;o||(o=Math.max.apply(Math,m(m([],u[0]),[2]))),n||(n=o);var y=V(e,s,i,n),L=V(t,u,i,n),N=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,f=e.nodeIdxs,h=e.neighborNum-1;s<i;){for(var c=f[1+Math.floor(Math.random()*h)],l=0;(a[n+"-"+c]||a[c+"-"+n])&&(c=Math.floor(Math.random()*t),!(++l>2*t)););if(l<2*t&&(a[n+"-"+c]={start:n,end:c,distance:o[n][c]},s++,++d>=r))return a;if(++u>2*t)break}s<i&&(i=(i+(i-s))/(t-n-1))})),a}(0,d,Math.min(100,d*(d-1)/2),L,s),M=Y(N,y,e),j=function(e){var t=e.graphs,r=e.directed,n=void 0!==r&&r,o=e.nodeLabelProp,i=void 0===o?Q:o,a=e.edgeLabelProp,d=void 0===a?Q:a,s=function(e,t,r,n){var o={};return Object.keys(e).forEach((function(i,a){var d=e[i],s=new H(a,!0,t),u={};d.nodes.forEach((function(e,t){s.addNode(t,e[r]),u[e.id]=t})),d.edges.forEach((function(e,t){var r=u[e.source],o=u[e.target];s.addEdge(-1,r,o,e[n])})),s&&s.getNodeNum()&&(o[s.id]=s)})),o}(t,n,i,d),u=e.minSupport,f=e.maxNodeNum,h=e.minNodeNum,c=e.verbose,l=e.top,p=new J({graphs:s,minSupport:u,maxNodeNum:f,minNodeNum:h,top:l,verbose:c,directed:n});return p.run(),function(e,t,r){var n=[];return e.forEach((function(e){var o={nodes:[],edges:[]};e.nodes.forEach((function(e){var r;o.nodes.push(((r={id:""+e.id})[t]=e.label,r))})),e.edges.forEach((function(e){var t;o.edges.push(((t={source:""+e.from,target:""+e.to})[r]=e.label,t))})),n.push(o)})),n}(p.frequentSubgraphs,i,d)}({graphs:M,nodeLabelProp:i,edgeLabelProp:a,minSupport:1,minNodeNum:1,maxNodeNum:4,directed:r}).slice(0,10),w=j.length,I=[];j.forEach((function(e,t){I[t]={},Object.keys(M).forEach((function(r){var n=M[r],o=Z(n,e,i,a);I[t][r]=o}))}));var x=function(e,t,r){for(var n=1/0,o=0,i=function(t){var r=e[t],i=Object.keys(r).sort((function(e,t){return r[e]-r[t]})),a=[];i.forEach((function(e,t){a[t%10]||(a[t%10]={graphs:[],totalCount:0,aveCount:0}),a[t%10].graphs.push(e),a[t%10].totalCount+=r[e]}));var d=0,s=[];a.forEach((function(e){var t=e.totalCount/e.graphs.length;e.aveCount=t,s.push(t);var n=0,o=e.length;e.graphs.forEach((function(t,o){var i=r[t];e.graphs.forEach((function(e,t){o!==t&&(n+=Math.abs(i-r[e]))}))})),d+=n/=o*(o-1)/2})),d/=a.length;var u=0;s.forEach((function(e,t){s.forEach((function(r,n){t!==n&&(u+=Math.abs(e-r))})),u/=s.length*(s.length-1)/2}));var f=u-d;n<f&&(n=f,o=t)},a=0;a<t;a++)i(a);return{structure:r[o],structureCountMap:e[o]}}(I,w,j),S=x.structure,C=x.structureCountMap,P=t.nodes[0],T=P[i],q=p[T],F={},D={},A={},R={},U={};Object.keys(b).forEach((function(r,n){U[r]=[];var o=-1/0,d=b[r],s={};d.forEach((function(e){var t=h[P.id+"-"+e.id];t&&U[r].push(t),o<t&&(o=t),s[P.id+"-"+e.id]={start:0,end:g[e.id].idx,distance:t}})),U[r]=U[r].sort((function(e,t){return e-t})),D=Y(s,L,t,D);var u=[];if(Object.keys(s).forEach((function(e){if(A[e])u.push(A[e]);else{var t=D[e];A[e]=Z(t,S,i,a),u.push(A[e])}})),u=u.sort((function(e,t){return t-e})),R[P.id+"-"+r]=u,r!==T)for(var c=function(t){var n=q[t],o=y[l[n.id].idx],d=o.nodeLabelCountMap[r],s=b[r].length;if(!d||d.count<s)return q.splice(t,1),"continue";for(var h=!1,c=0;c<s;c++)if(d.dists[c]>U[r][c]){h=!0;break}if(h)return q.splice(t,1),"continue";var p={};o.neighbors.forEach((function(e){var t=f[n.id+"-"+e.id];p[n.id+"-"+e.id]={start:l[n.id].idx,end:l[e.id].idx,distance:t}})),M=Y(p,y,e,M);var v=[];Object.keys(p).forEach((function(e){if(C[e])v.push(C[e]);else{var t=M[e];C[e]=Z(t,S,i,a),v.push(C[e])}})),v=v.sort((function(e,t){return t-e}));var g=!1;for(c=0;c<s;c++)if(v[c]<u[c]){g=!0;break}return g?(q.splice(t,1),"continue"):void 0},p=q.length-1;p>=0;p--)c(p)}));var G=[];q.forEach((function(r){for(var n=l[r.id].idx,d=X(e.nodes,s[n],n,i,o).neighbors,u=d.length,h=!1,c=function(n){if(d.length+1<t.nodes.length)return h=!0,{value:void 0};var o=d[n],s=o[i];if(!b[s]||!b[s].length)return d.splice(n,1),"continue";var u=r.id+"-"+o.id;if(!U[s]||!U[s].length)return d.splice(n,1),"continue";var c=f[u];if(c>U[s][U[s].length-1])return d.splice(n,1),"continue";var p=C[u]?C[u]:function(e,t,r,n,o,i,a,d,s,u,f){var h,c=t.id+"-"+r.id;if(u&&u[c])return u[c];var l=f?f[c]:void 0;if(!l){var p=((h={})[c]={start:n[t.id].idx,end:n[r.id].idx,distance:o},h);l=(f=Y(p,i,e,f))[c]}return Z(l,a,d,s)}(e,r,o,l,c,y,S,i,a,C,M),v=P.id+"-"+s;if(p<R[v][R[v].length-1])return d.splice(n,1),"continue";var E=F[s];return void 0===E&&(E=1/0,b[s].forEach((function(e){var t=g[e.id].degree;E>t&&(E=t)})),F[s]=E),l[o.id].degree<E?(d.splice(n,1),"continue"):void 0},p=u-1;p>=0;p--){var v=c(p);if("object"==typeof v)return v.value}h||G.push({nodes:[r].concat(d)})}));var z=k(t,P.id,!1).length,B={};r?(Object.keys(z).forEach((function(e){var t=g[e].node[i];B[t]?B[t].push(z[e]):B[t]=[z[e]]})),Object.keys(B).forEach((function(e){B[e].sort((function(e,t){return e-t}))}))):B=U;for(var _=function(n){var o=G[n],d=o.nodes[0],s={},u={};o.nodes.forEach((function(e,t){u[e.id]={idx:t,node:e,degree:0};var r=e[i];s[r]?s[r]++:s[r]=1}));var f=[],h={};e.edges.forEach((function(e){u[e.source]&&u[e.target]&&(f.push(e),h[e[a]]?h[e[a]]++:h[e[a]]=1,u[e.source].degree++,u[e.target].degree++)}));for(var c=Object.keys(E).length,p=!1,v=0;v<c;v++){var m=Object.keys(E)[v];if(!h[m]||h[m]<E[m].length){p=!0;break}}if(p)return G.splice(n,1),"continue";var y=f.length;if(y<t.edges.length)return G.splice(n,1),"break";var L=!1,N=function(e){var t=f[e],n=t[a],o=E[n];if(!o||!o.length)return h[n]--,o&&h[n]<o.length?(L=!0,"break"):(f.splice(e,1),u[t.source].degree--,u[t.target].degree--,"continue");var d=u[t.source].node[i],s=u[t.target].node[i],c=!1;return o.forEach((function(e){var t=g[e.source].node,n=g[e.target].node;t[i]===d&&n[i]===s&&(c=!0),r||t[i]!==s||n[i]!==d||(c=!0)})),c?void 0:(h[n]--,o&&h[n]<o.length?(L=!0,"break"):(f.splice(e,1),u[t.source].degree--,u[t.target].degree--,"continue"))};for(v=y-1;v>=0&&"break"!==N(v);v--);if(L)return G.splice(n,1),"continue";o.edges=f;var M=k(o,o.nodes[0].id,!1).length;if(Object.keys(M).reverse().forEach((function(e){if(e!==o.nodes[0].id&&!L){if(M[e]===1/0){var t=u[e].node[i];if(s[t]--,s[t]<b[t].length)return void(L=!0);var r=o.nodes.indexOf(u[e].node);return o.nodes.splice(r,1),void(u[e]=void 0)}var n=l[e].node[i];if(!B[n]||!B[n].length||M[e]>B[n][B[n].length-1]){if(t=u[e].node[i],s[t]--,s[t]<b[t].length)return void(L=!0);r=o.nodes.indexOf(u[e].node),o.nodes.splice(r,1),u[e]=void 0}}})),L)return G.splice(n,1),"continue";for(var j=!0,w=0;j&&!L;){if(j=!1,u[d.id].degree<g[P.id].degree){L=!0;break}if(s[d[i]]<b[d[i]].length){L=!0;break}for(var I=o.nodes.length-1;I>=0;I--){var x=o.nodes[I],O=u[x.id].degree,S=x[i];if(O<F[S]){if(s[x[i]]--,s[x[i]]<b[x[i]].length){L=!0;break}o.nodes.splice(I,1),u[x.id]=void 0,j=!0}}if(L||!j&&0!==w)break;for(var C=(y=f.length)-1;C>=0;C--){var T=f[C];if(!u[T.source]||!u[T.target]){f.splice(C,1);var q=T[a];if(h[q]--,u[T.source]&&u[T.source].degree--,u[T.target]&&u[T.target].degree--,E[q]&&h[q]<E[q].length){L=!0;break}j=!0}}w++}return L||L||o.nodes.length<t.nodes.length||f.length<t.edges.length?(G.splice(n,1),"continue"):void 0},K=G.length-1;K>=0&&"break"!==_(K);K--);var W=G.length,re=function(e){var t=G[e],r={};t.edges.forEach((function(e){var t=e.source+"-"+e.target+"-"+e.label;r[t]?r[t]++:r[t]=1}));for(var n=function(e){var t=G[e],n={};t.edges.forEach((function(e){var t=e.source+"-"+e.target+"-"+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&&G.splice(e,1)},o=W-1;o>e;o--)n(o);W=G.length};for(K=0;K<=W-1;K++)re(K);return G}}};var ne=self;ne.onmessage=function(e){var r=e.data,n=r.type,o=r.data;if("function"!=typeof t[n])ne.postMessage({type:"FAILURE"});else{var i=t[n].apply(t,o);ne.postMessage({type:"SUCCESS",data:i})}}})(); | ||
(()=>{"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:()=>re,breadthFirstSearch:()=>f,connectedComponent:()=>h,depthFirstSearch:()=>b,detectCycle:()=>E,dijkstra:()=>k,findAllPath:()=>x,findShortestPath:()=>I,floydWarshall:()=>O,getAdjMatrix:()=>r,getDegree:()=>l,getInDegree:()=>p,getNeighbors:()=>d,getOutDegree:()=>v,labelPropagation:()=>S,louvain:()=>P,minimumSpanningTree:()=>R,pageRank:()=>U});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):""+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){return void 0===e&&(e=0),e+"-"+(""+Math.random()).split(".")[1].substr(0,5)+(""+Math.random()).split(".")[1].substr(0,5)};const f=function(e,t,r){var n=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),o=new a,i=e.edges,s=void 0===i?[]:i;o.enqueue(t);for(var u="",f=function(){var e=o.dequeue();n.enter({current:e,previous:u}),d(e,s,"target").forEach((function(t){n.allowTraversal({previous:u,current:e,next:t})&&o.enqueue(t)})),n.leave({current:e,previous:u}),u=e};!o.isEmpty();)f()};function h(e,t){return t?function(e){for(var t=e.nodes,r=void 0===t?[]:t,n=e.edges,o=void 0===n?[]:n,i=[],a={},s={},u={},f=[],h=0,c=function(e){s[e.id]=h,u[e.id]=h,h+=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&&c(i[0]),u[e.id]=Math.min(u[e.id],u[o])}},l=0;l<t.length;l++)n(l);if(u[e.id]===s[e.id]){for(var p=[];i.length>0;){var v=i.pop();if(a[v.id]=!1,p.push(v),v===e)break}p.length>0&&f.push(p)}},l=0,p=r;l<p.length;l++){var v=p[l];s[v.id]||0===s[v.id]||c(v)}return f}(e):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;i<t.length;++i)n(i)},f=0;f<r.length;f++){var h=r[f];if(!a[h.id]){u(h);for(var c=[];s.length>0;)c.push(s.pop());i.push(c)}}return i}(e)}var c=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 l=c;var p=function(e,t){return c(e)[t]?c(e)[t].inDegree:0},v=function(e,t){return c(e)[t]?c(e)[t].outDegree:0};function g(e,t,r,n){n.enter({current:t,previous:r});var o=e.edges;d(t,void 0===o?[]:o,"target").forEach((function(o){n.allowTraversal({previous:r,current:t,next:o})&&g(e,o,t,n)})),n.leave({current:t,previous:r})}function b(e,t,r){g(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))}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,s=a;s!==r;)t[d]=s,d=s,s=n[s];t[d]=s}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;)b(e,Object.keys(o)[0],d);return t};function m(e,t){for(var r=0,n=t.length,o=e.length;r<n;r++,o++)e[o]=t[r];return e}Object.create,Object.create;var y={}.toString;const L=function(e,t){return y.call(e)==="[object "+t+"]"},N=function(e){return Array.isArray?Array.isArray(e):L(e,"Array")};Object.keys;var M=Array.prototype;M.splice,M.indexOf,Array.prototype.splice,Object.prototype.hasOwnProperty;Number.isInteger&&Number.isInteger,Math.PI,parseInt,Math.PI,Object.values,Object.prototype;const j=function e(t){if("object"!=typeof t||null===t)return t;var r;if(N(t)){r=[];for(var n=0,o=t.length;n<o;n++)"object"==typeof t[n]&&null!=t[n]?r[n]=e(t[n]):r[n]=t[n]}else for(var i in r={},t)"object"==typeof t[i]&&null!=t[i]?r[i]=e(t[i]):r[i]=t[i];return r};Object.prototype.hasOwnProperty,Object.prototype.hasOwnProperty,function(){function e(){this.map={}}e.prototype.has=function(e){return void 0!==this.map[e]},e.prototype.get=function(e,t){var r=this.map[e];return void 0===r?t:r},e.prototype.set=function(e,t){this.map[e]=t},e.prototype.clear=function(){this.map={}},e.prototype.delete=function(e){delete this.map[e]},e.prototype.size=function(){return Object.keys(this.map).length}}();const k=function(e,t,r,n){var o=e.nodes,i=void 0===o?[]:o,a=e.edges,d=void 0===a?[]:a,u=[],f={},h={},c={};i.forEach((function(e,r){var n=e.id;u.push(n),h[n]=1/0,n===t&&(h[n]=0)}));for(var l=i.length,p=function(e){var t=function(e,t,r){for(var n,o=1/0,i=0;i<t.length;i++){var a=t[i].id;!r[a]&&e[a]<=o&&(o=e[a],n=t[i])}return n}(h,i,f),o=t.id;if(f[o]=!0,h[o]===1/0)return"continue";(r?function(e,t){return t.filter((function(t){return t.source===e}))}(o,d):s(o,d)).forEach((function(e){var r=e.target,i=e.source,a=r===o?i:r,d=n&&e[n]?e[n]:1;h[a]>h[t.id]+d?(h[a]=h[t.id]+d,c[a]=[t.id]):h[a]===h[t.id]+d&&c[a].push(t.id)}))},v=0;v<l;v++)p();c[t]=[t];var g={};for(var b in h)h[b]!==1/0&&w(t,b,c,g);var E={};for(var b in g)E[b]=g[b][0];return{length:h,path:E,allPath:g}};function w(e,t,r,n){if(e===t)return[e];if(n[t])return n[t];for(var o=[],i=0,a=r[t];i<a.length;i++){var d=w(e,a[i],r,n);if(!d)return;for(var s=0,u=d;s<u.length;s++){var f=u[s];N(f)?o.push(m(m([],f),[t])):o.push([f,t])}}return n[t]=o,n[t]}var I=function(e,t,r,n,o){var i=k(e,t,n,o),a=i.length,d=i.path,s=i.allPath;return{length:a[r],path:d[r],allPath:s[r]}},x=function(e,t,r,n){var o;if(t===r)return[[t]];var i=e.edges,a=void 0===i?[]:i,s=[t],u=((o={})[t]=!0,o),f=[],h=[],c=n?d(t,a,"target"):d(t,a);for(f.push(c);s.length>0&&f.length>0;){var l=f[f.length-1];if(l.length){var p=l.shift();if(p&&(s.push(p),u[p]=!0,c=n?d(p,a,"target"):d(p,a),f.push(c.filter((function(e){return!u[e]})))),s[s.length-1]===r){var v=s.map((function(e){return e}));h.push(v),g=s.pop(),u[g]=!1,f.pop()}}else{var g=s.pop();u[g]=!1,f.pop()}}return h};const O=function(e,t){for(var n=r(e,t),o=[],i=n.length,a=0;a<i;a+=1){o[a]=[];for(var d=0;d<i;d+=1)a===d?o[a][d]=0:0!==n[a][d]&&n[a][d]?o[a][d]=n[a][d]:o[a][d]=1/0}for(var s=0;s<i;s+=1)for(a=0;a<i;a+=1)for(d=0;d<i;d+=1)o[a][d]>o[a][s]+o[s][d]&&(o[a][d]=o[a][s]+o[s][d]);return o},S=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,f={},h={};a.forEach((function(e,t){var r=u();e.clusterId=r,f[r]={id:r,nodes:[e]},h[e.id]={node:e,idx:t}}));var c=r(e,t),l=[],p={};c.forEach((function(e,t){var r=0,n=a[t].id;p[n]={},e.forEach((function(e,t){if(e){r+=e;var o=a[t].id;p[n][o]=e}})),l.push(r)}));for(var v=0,g=function(){var e=!1;if(a.forEach((function(t){var r={};Object.keys(p[t.id]).forEach((function(e){var n=p[t.id][e],o=h[e].node.clusterId;r[o]||(r[o]=0),r[o]+=n}));var n=-1/0,o=[];if(Object.keys(r).forEach((function(e){n<r[e]?(n=r[e],o=[e]):n===r[e]&&o.push(e)})),1!==o.length||o[0]!==t.clusterId){var i=o.indexOf(t.clusterId);if(i>=0&&o.splice(i,1),o&&o.length){e=!0;var a=f[t.clusterId],d=a.nodes.indexOf(t);a.nodes.splice(d,1);var s=Math.floor(Math.random()*o.length),u=f[o[s]];u.nodes.push(t),t.clusterId=u.id}}})),!e)return"break";v++};v<o&&"break"!==g(););Object.keys(f).forEach((function(e){var t=f[e];t.nodes&&t.nodes.length||delete f[e]}));var b=[],E={};s.forEach((function(e){var t=e.source,r=e.target,o=e[n]||1,i=h[t].node.clusterId,a=h[r].node.clusterId,d=i+"---"+a;if(E[d])E[d].weight+=o,E[d].count++;else{var s={source:i,target:a,weight:o,count:1};E[d]=s,b.push(s)}}));var m=[];return Object.keys(f).forEach((function(e){m.push(f[e])})),{clusters:m,clusterEdges:b}};var C=function(e,t,r,n){for(var o=t.length,i=2*n,a=0,d=0;d<o;d++)for(var s=e[d].clusterId,u=0;u<o;u++)s===e[u].clusterId&&(a+=(t[d][u]||0)-(r[d]||0)*(r[u]||0)/i);return a*(1/i)};const P=function(e,t,n,o){void 0===t&&(t=!1),void 0===n&&(n="weight"),void 0===o&&(o=1e-4);var i=e.nodes,a=void 0===i?[]:i,d=e.edges,s=void 0===d?[]:d,u=1,f={},h={};a.forEach((function(e,t){var r=String(u++);e.clusterId=r,f[r]={id:r,nodes:[e]},h[e.id]={node:e,idx:t}}));var c=r(e,t),l=[],p={},v=0;c.forEach((function(e,t){var r=0,n=a[t].id;p[n]={},e.forEach((function(e,t){if(e){r+=e;var o=a[t].id;p[n][o]=e,v+=e}})),l.push(r)})),v/=2;for(var g=1/0,b=1/0,E=0;g=C(a,c,l,v),!(Math.abs(g-b)<o||E>100);)b=g,E++,Object.keys(f).forEach((function(e){var t=0;s.forEach((function(r){var o=r.source,i=r.target,a=h[o].node.clusterId,d=h[i].node.clusterId;(a===e&&d!==e||d===e&&a!==e)&&(t+=r[n]||1)})),f[e].sumTot=t})),a.forEach((function(e,t){var r,o=f[e.clusterId],i=0,a=l[t]/(2*v),d=0;o.nodes.forEach((function(e){var r=h[e.id].idx;d+=c[t][r]||0}));var u=d-o.sumTot*a,g=p[e.id];if(Object.keys(g).forEach((function(n){var o=h[n].node.clusterId;if(o!==e.clusterId){var d=f[o],s=d.nodes;if(s&&s.length){var l=0;s.forEach((function(e){var r=h[e.id].idx;l+=c[t][r]||0}));var p=l-d.sumTot*a-u;p>i&&(i=p,r=d)}}})),i>0){r.nodes.push(e);var b=e.clusterId;e.clusterId=r.id;var E=o.nodes.indexOf(e);o.nodes.splice(E,1);var m=0,y=0;s.forEach((function(e){var t=e.source,o=e.target,i=h[t].node.clusterId,a=h[o].node.clusterId;(i===r.id&&a!==r.id||a===r.id&&i!==r.id)&&(m+=e[n]||1),(i===b&&a!==b||a===b&&i!==b)&&(y+=e[n]||1)})),r.sumTot=m,o.sumTot=y}}));var m={},y=0;Object.keys(f).forEach((function(e){var t=f[e];if(t.nodes&&t.nodes.length){var r=String(y+1);r!==e&&(t.id=r,t.nodes=t.nodes.map((function(e){return{id:e.id,clusterId:r}})),f[r]=t,m[e]=r,delete f[e],y++)}else delete f[e]})),a.forEach((function(e){e.clusterId&&m[e.clusterId]&&(e.clusterId=m[e.clusterId])}));var L=[],N={};s.forEach((function(e){var t=e.source,r=e.target,o=e[n]||1,i=h[t].node.clusterId,a=h[r].node.clusterId,d=i+"---"+a;if(N[d])N[d].weight+=o,N[d].count++;else{var s={source:i,target:a,weight:o,count:1};N[d]=s,L.push(s)}}));var M=[];return Object.keys(f).forEach((function(e){M.push(f[e])})),{clusters:M,clusterEdges:L}},T=function(){function e(e){this.count=e.length,this.parent={};for(var t=0,r=e;t<r.length;t++){var n=r[t];this.parent[n]=n}}return e.prototype.find=function(e){for(;this.parent[e]!==e;)e=this.parent[e];return e},e.prototype.union=function(e,t){var r=this.find(e),n=this.find(t);r!==n&&(r<n?(this.parent[t]!==t&&this.union(this.parent[t],e),this.parent[t]=this.parent[e]):(this.parent[e]!==e&&this.union(this.parent[e],t),this.parent[e]=this.parent[t]))},e.prototype.connected=function(e,t){return this.find(e)===this.find(t)},e}();var q=function(e,t){return e-t};const F=function(){function e(e){void 0===e&&(e=q),this.compareFn=e,this.list=[]}return e.prototype.getLeft=function(e){return 2*e+1},e.prototype.getRight=function(e){return 2*e+2},e.prototype.getParent=function(e){return 0===e?null:Math.floor((e-1)/2)},e.prototype.isEmpty=function(){return this.list.length<=0},e.prototype.top=function(){return this.isEmpty()?void 0:this.list[0]},e.prototype.delMin=function(){var e=this.top(),t=this.list.pop();return this.list.length>0&&(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&&n<i&&this.compareFn(this.list[r],this.list[n])>0?r=n:null!==o&&o<i&&this.compareFn(this.list[r],this.list[o])>0&&(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 D=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 f=new F((function(e,r){return t?e.weight-r.weight:0}));for(s(d.id,a).forEach((function(e){f.insert(e)}));!f.isEmpty();){var h=f.delMin(),c=h.source,l=h.target;u.has(c)&&u.has(l)||(r.push(h),u.has(c)||(u.add(c),s(c,a).forEach((function(e){f.insert(e)}))),u.has(l)||(u.add(l),s(l,a).forEach((function(e){f.insert(e)}))))}return r},A=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 T(o.map((function(e){return e.id})));d.length>0;){var u=d.shift(),f=u.source,h=u.target;s.connected(f,h)||(r.push(u),s.union(f,h))}return r};const R=function(e,t,r){return r?{prim:D,kruskal:A}[r](e,t):A(e,t)},U=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,f=e.edges,h=void 0===f?[]:f,c=u.length,p={},v={},g=0;g<c;++g)p[E=(M=u[g]).id]=1/c,v[E]=1/c;for(var b=l(e);a>0&&o>t;){for(i=0,g=0;g<c;++g){var E=(M=u[g]).id;if(n=0,0===b[M.id].inDegree)p[E]=0;else{for(var m=d(E,h,"source"),y=0;y<m.length;++y){var L=m[y],N=b[L].outDegree;N>0&&(n+=v[L]/N)}p[E]=r*n,i+=p[E]}}for(i=(1-i)/c,o=0,g=0;g<c;++g){var M;n=p[E=(M=u[g]).id]+i,o+=Math.abs(n-v[E]),v[E]=n}a-=1}return v};var G="-1",_=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},z=function(){function e(e,t){void 0===e&&(e=-1),void 0===t&&(t=G),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}(),B=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 z(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 _(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 _(e,r,t,n);this.nodeMap[r].addEdge(i),this.edgeLabelMap[n].push(i)}}},e}(),H=function(){function e(e,t,r,n,o){this.fromNode=e,this.toNode=t,this.nodeEdgeNodeLabel={nodeLabel1:r||G,edgeLabel:n||"-1",nodeLabel2:o||G}}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}(),K=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<t;r++)if(this.dfsEdgeList[r]!==e[r])return!1;return!0},e.prototype.notEqualTo=function(e){return!this.equalTo(e)},e.prototype.pushBack=function(e,t,r,n,o){return this.dfsEdgeList.push(new H(e,t,r,n,o)),this.dfsEdgeList},e.prototype.toGraph=function(e,t){void 0===e&&(e=-1),void 0===t&&(t=!1);var r=new B(e,!0,t);return this.dfsEdgeList.forEach((function(e){var t=e.fromNode,n=e.toNode,o=e.nodeEdgeNodeLabel,i=o.nodeLabel1,a=o.edgeLabel,d=o.nodeLabel2;i!==G&&r.addNode(t,i),d!==G&&r.addNode(n,d),r.addEdge(void 0,t,n,a)})),r},e.prototype.buildRmpath=function(){this.rmpath=[];for(var e=void 0,t=this.dfsEdgeList.length-1;t>=0;t--){var r=this.dfsEdgeList[t],n=r.fromNode,o=r.toNode;n<o&&(void 0===e||o===e)&&(this.rmpath.push(t),e=n)}return this.rmpath},e.prototype.getNodeNum=function(){var e={};return this.dfsEdgeList.forEach((function(t){e[t.fromNode]||(e[t.fromNode]=!0),e[t.toNode]||(e[t.toNode]=!0)})),Object.keys(e).length},e}(),W=function(){function e(e){if(this.his={},this.nodesUsed={},this.edgesUsed={},this.edges=[],e){for(;e;){var t=e.edge;this.edges.push(t),this.nodesUsed[t.from]=1,this.nodesUsed[t.to]=1,this.edgesUsed[t.id]=1,e=e.preNode}this.edges=this.edges.reverse()}}return e.prototype.hasNode=function(e){return 1===this.nodesUsed[e.id]},e.prototype.hasEdge=function(e){return 1===this.edgesUsed[e.id]},e}(),J=function(){function e(e){var t=e.graphs,r=e.minSupport,n=void 0===r?2:r,o=e.minNodeNum,i=void 0===o?1:o,a=e.maxNodeNum,d=void 0===a?4:a,s=e.top,u=void 0===s?10:s,f=e.directed,h=void 0!==f&&f,c=e.verbose,l=void 0!==c&&c;this.graphs=t,this.dfsCode=new K,this.support=0,this.frequentSize1Subgraphs=[],this.frequentSubgraphs=[],this.minSupport=n,this.top=u,this.directed=h,this.counter=0,this.maxNodeNum=d,this.minNodeNum=i,this.verbose=l,this.maxNodeNum<this.minNodeNum&&(this.maxNodeNum=this.minNodeNum),this.reportDF=[]}return e.prototype.findForwardRootEdges=function(e,t){var r=this,n=[],o=e.nodeMap;return t.edges.forEach((function(e){(r.directed||t.label<=o[e.to].label)&&n.push(e)})),n},e.prototype.findBackwardEdge=function(e,t,r,n){if(!this.directed&&t===r)return null;for(var o=e.nodeMap,i=o[r.to].edges,a=i.length,d=0;d<a;d++){var s=i[d];if(!n.hasEdge(s)&&s.to===t.from)if(this.directed){if(o[t.from].label<o[r.to].label||o[t.from].label===o[r.to].label&&t.label<=s.label)return s}else if(t.label<s.label||t.label===s.label&&o[t.to].label<=o[r.to].label)return s}return null},e.prototype.findForwardPureEdges=function(e,t,r,n){for(var o=[],i=t.to,a=e.nodeMap[i].edges,d=a.length,s=0;s<d;s++){var u=a[s],f=e.nodeMap[u.to];r<=f.label&&!n.hasNode(f)&&o.push(u)}return o},e.prototype.findForwardRmpathEdges=function(e,t,r,n){for(var o=[],i=e.nodeMap,a=i[t.to].label,d=i[t.from].edges,s=d.length,u=0;u<s;u++){var f=d[u],h=i[f.to].label;t.to===f.to||r>h||n.hasNode(i[f.to])||(t.label<f.label||t.label===f.label&&a<=h)&&o.push(f)}return o},e.prototype.getSupport=function(e){var t={};return e.forEach((function(e){t[e.graphId]||(t[e.graphId]=!0)})),Object.keys(t).length},e.prototype.findMinLabel=function(e){var t=void 0;return Object.keys(e).forEach((function(r){var n=e[r],o=n.nodeLabel1,i=n.edgeLabel,a=n.nodeLabel2;t?(o<t.nodeLabel1||o===t.nodeLabel1&&i<t.edgeLabel||o===t.nodeLabel1&&i===t.edgeLabel&&a<t.nodeLabel2)&&(t={nodeLabel1:o,edgeLabel:i,nodeLabel2:a}):t={nodeLabel1:o,edgeLabel:i,nodeLabel2:a}})),t},e.prototype.isMin=function(){var e=this,t=this.dfsCode;if(this.verbose&&console.log("isMin checking",t),1===t.dfsEdgeList.length)return!0;var r=this.directed,n=t.toGraph(-1,r),o=n.nodeMap,i=new K,a={};n.nodes.forEach((function(t){e.findForwardRootEdges(n,t).forEach((function(e){var r=o[e.to],i=t.label+"-"+e.label+"-"+r.label;a[i]||(a[i]={projected:[],nodeLabel1:t.label,edgeLabel:e.label,nodeLabel2:r.label});var d={graphId:n.id,edge:e,preNode:null};a[i].projected.push(d)}))}));var d=this.findMinLabel(a);i.dfsEdgeList.push(new H(0,1,d.nodeLabel1,d.edgeLabel,d.nodeLabel2));var s=function(a){for(var d=i.buildRmpath(),u=i.dfsEdgeList[0].nodeEdgeNodeLabel.nodeLabel1,f=i.dfsEdgeList[d[0]].toNode,h={},c=!1,l=0,p=r?-1:0,v=function(t){if(c)return"break";a.forEach((function(r){var o=new W(r),a=e.findBackwardEdge(n,o.edges[d[t]],o.edges[d[0]],o);a&&(h[a.label]||(h[a.label]={projected:[],edgeLabel:a.label}),h[a.label].projected.push({graphId:n.id,edge:h,preNode:r}),l=i.dfsEdgeList[d[t]].fromNode,c=!0)}))},g=d.length-1;g>p&&"break"!==v(g);g--);if(c){var b=e.findMinLabel(h);i.dfsEdgeList.push(new H(f,l,G,b.edgeLabel,G));var E=i.dfsEdgeList.length-1;return e.dfsCode.dfsEdgeList[E]===i.dfsEdgeList[E]&&s(h[b.edgeLabel].projected)}var m={};c=!1;var y=0;a.forEach((function(t){var r=new W(t),i=e.findForwardPureEdges(n,r.edges[d[0]],u,r);i.length>0&&(c=!0,y=f,i.forEach((function(e){var r=e.label+"-"+o[e.to].label;m[r]||(m[r]={projected:[],edgeLabel:e.label,nodeLabel2:o[e.to].label}),m[r].projected.push({graphId:n.id,edge:e,preNode:t})})))}));var L=d.length,N=function(t){if(c)return"break";var r=d[t];a.forEach((function(t){var a=new W(t),d=e.findForwardRmpathEdges(n,a.edges[r],u,a);d.length>0&&(c=!0,y=i.dfsEdgeList[r].fromNode,d.forEach((function(e){var r=e.label+"-"+o[e.to].label;m[r]||(m[r]={projected:[],edgeLabel:e.label,nodeLabel2:o[e.to].label}),m[r].projected.push({graphId:n.id,edge:e,preNode:t})})))}))};for(g=0;g<L&&"break"!==N(g);g++);if(!c)return!0;var M=e.findMinLabel(m);i.dfsEdgeList.push(new H(y,f+1,G,M.edgeLabel,M.nodeLabel2));var j=i.dfsEdgeList.length-1;return t.dfsEdgeList[j]===i.dfsEdgeList[j]&&s(m[M.edgeLabel+"-"+M.nodeLabel2].projected)},u=d.nodeLabel1+"-"+d.edgeLabel+"-"+d.nodeLabel2;return s(a[u].projected)},e.prototype.report=function(){if(!(this.dfsCode.getNodeNum()<this.minNodeNum)){this.counter++;var e=this.dfsCode.toGraph(this.counter,this.directed);this.frequentSubgraphs.push(j(e))}},e.prototype.subGraphMining=function(e){var t=this;if(!(this.getSupport(e)<this.minSupport)&&this.isMin()){this.report();var r=this.dfsCode.getNodeNum(),n=this.dfsCode.buildRmpath(),o=this.dfsCode.dfsEdgeList[n[0]].toNode,i=this.dfsCode.dfsEdgeList[0].nodeEdgeNodeLabel.nodeLabel1,a={},d={};e.forEach((function(e){for(var s=t.graphs[e.graphId],u=s.nodeMap,f=new W(e),h=n.length-1;h>=0;h--){var c=t.findBackwardEdge(s,f.edges[n[h]],f.edges[n[0]],f);if(c){var l=t.dfsCode.dfsEdgeList[n[h]].fromNode+"-"+c.label;d[l]||(d[l]={projected:[],toNodeId:t.dfsCode.dfsEdgeList[n[h]].fromNode,edgeLabel:c.label}),d[l].projected.push({graphId:e.graphId,edge:c,preNode:e})}}if(!(r>=t.maxNodeNum)){t.findForwardPureEdges(s,f.edges[n[0]],i,f).forEach((function(t){var r=o+"-"+t.label+"-"+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 p=function(r){t.findForwardRmpathEdges(s,f.edges[n[r]],i,f).forEach((function(o){var i=t.dfsCode.dfsEdgeList[n[r]].fromNode+"-"+o.label+"-"+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(h=0;h<n.length;h++)p(h)}})),Object.keys(d).forEach((function(e){var r=d[e],n=r.toNodeId,i=r.edgeLabel;t.dfsCode.dfsEdgeList.push(new H(o,n,"-1",i,"-1")),t.subGraphMining(d[e].projected),t.dfsCode.dfsEdgeList.pop()})),Object.keys(a).forEach((function(e){var r=a[e],n=r.fromNodeId,i=r.edgeLabel,d=r.nodeLabel2;t.dfsCode.dfsEdgeList.push(new H(n,o+1,G,i,d)),t.subGraphMining(a[e].projected),t.dfsCode.dfsEdgeList.pop()}))}},e.prototype.generate1EdgeFrequentSubGraphs=function(){var e=this.graphs,t=this.directed,r=this.minSupport,n=this.frequentSize1Subgraphs,o={},i={},a={},d={};return Object.keys(e).forEach((function(r){var n=e[r],s=n.nodeMap;n.nodes.forEach((function(e,n){var u=e.label,f=r+"-"+u;if(!a[f]){var h=o[u]||0;h++,o[u]=h}a[f]={graphKey:r,label:u},e.edges.forEach((function(e){var n=u,o=s[e.to].label;if(!t&&n>o){var a=o;o=n,n=a}var f=e.label,h=r+"-"+n+"-"+f+"-"+o,c=n+"-"+f+"-"+o;if(!i[c]){var l=i[c]||0;l++,i[c]=l}d[h]={graphId:r,nodeLabel1:n,edgeLabel:f,nodeLabel2:o}}))}))})),Object.keys(o).forEach((function(e){if(!(o[e]<r)){var t={nodes:[],edges:[]};t.nodes.push({id:"0",label:e}),n.push(t)}})),n},e.prototype.run=function(){var e=this;if(this.frequentSize1Subgraphs=this.generate1EdgeFrequentSubGraphs(),!(this.maxNodeNum<2)){var t=this.graphs,r=(this.directed,{});Object.keys(t).forEach((function(n){var o=t[n],i=o.nodeMap;o.nodes.forEach((function(t){e.findForwardRootEdges(o,t).forEach((function(e){var o=i[e.to],a=t.label+"-"+e.label+"-"+o.label;r[a]||(r[a]={projected:[],nodeLabel1:t.label,edgeLabel:e.label,nodeLabel2:o.label});var d={graphId:n,edge:e,preNode:null};r[a].projected.push(d)}))}))})),Object.keys(r).forEach((function(t){var n=r[t],o=n.projected,i=n.nodeLabel1,a=n.edgeLabel,d=n.nodeLabel2;e.dfsCode.dfsEdgeList.push(new H(0,1,i,a,d)),e.subGraphMining(o),e.dfsCode.dfsEdgeList.pop()}))}},e}(),Q="cluster";var V=function(e,t,r,n){void 0===r&&(r="cluster"),void 0===n&&(n=2);var o=[],i=e.nodes;return t.forEach((function(e,t){o.push(X(i,e,t,r,n))})),o},X=function(e,t,r,n,o){var i=[r],a=[],d={};return t.forEach((function(t,s){if(t<=o&&r!==s){i.push(s),a.push(e[s]);var u=e[s][n];d[u]?(d[u].count++,d[u].dists.push(t)):d[u]={count:1,dists:[t]}}})),Object.keys(d).forEach((function(e){d[e].dists=d[e].dists.sort((function(e,t){return e-t}))})),{nodeIdx:r,nodeId:e[r].id,nodeIdxs:i,neighbors:a,neighborNum:i.length-1,nodeLabelCountMap:d}},Y=function(e,t,r,n){var o=r.nodes;return n||(n={}),Object.keys(e).forEach((function(i){var a,d;if(!n||!n[i]){n[i]={nodes:[],edges:[]};var s=e[i],u=null===(a=t[s.start])||void 0===a?void 0:a.nodeIdxs,f=null===(d=t[s.end])||void 0===d?void 0:d.nodeIdxs;if(u&&f){var h=new Set(f),c=u.filter((function(e){return h.has(e)}));if(c&&c.length){for(var l={},p=c.length,v=0;v<p;v++){var g=o[c[v]];n[i].nodes.push(g),l[g.id]=!0}r.edges.forEach((function(e){l[e.source]&&l[e.target]&&n[i].edges.push(e)}))}}}})),n},Z=function(e,t,r,n){var o={};e.nodes.forEach((function(e){o[e.id]=e}));var i=0;return e.edges.forEach((function(e){var a=o[e.source][r],d=o[e.target][r],s=t.nodes[0][r],u=t.nodes[1][r],f=t.edges[0][n];e[n]===f&&(a===s&&d===u||a===u&&d===s)&&i++})),i},$=function(e,t){var r={},n={};return e.forEach((function(e,o){r[e.id]={idx:o,node:e,degree:0};var i=e[t];n[i]||(n[i]=[]),n[i].push(e)})),{nodeMap:r,nodeLabelMap:n}},ee=function(e,t,r){var n={},o={};return e.forEach((function(e,i){n[""+u]={idx:i,edge:e};var a=e[t];o[a]||(o[a]=[]),o[a].push(e);var d=r[e.source];d&&d.degree++;var s=r[e.target];s&&s.degree++})),{edgeMap:n,edgeLabelMap:o}},te=function(e,t,r){var n=t.length,o={};return t.forEach((function(t,i){for(var a=r?0:i+1,d=e[i].id,s=a;s<n;s++)if(i!==s){var u=e[s].id,f=t[s];o[d+"-"+u]=f,r||(o[u+"-"+d]=f)}})),o};const re=function(e,t,r,n,o,i,a){if(void 0===r&&(r=!1),void 0===i&&(i="cluster"),void 0===a&&(a="cluster"),e&&e.nodes){var d=e.nodes.length;if(d){var s=O(e,r),u=O(t,r),f=te(e.nodes,s,r),h=te(t.nodes,u,r),c=$(e.nodes,i),l=c.nodeMap,p=c.nodeLabelMap,v=$(t.nodes,i),g=v.nodeMap,b=v.nodeLabelMap;ee(e.edges,a,l);var E=ee(t.edges,a,g).edgeLabelMap;o||(o=Math.max.apply(Math,m(m([],u[0]),[2]))),n||(n=o);var y=V(e,s,i,n),L=V(t,u,i,n),N=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,f=e.nodeIdxs,h=e.neighborNum-1;s<i;){for(var c=f[1+Math.floor(Math.random()*h)],l=0;(a[n+"-"+c]||a[c+"-"+n])&&(c=Math.floor(Math.random()*t),!(++l>2*t)););if(l<2*t&&(a[n+"-"+c]={start:n,end:c,distance:o[n][c]},s++,++d>=r))return a;if(++u>2*t)break}s<i&&(i=(i+(i-s))/(t-n-1))})),a}(0,d,Math.min(100,d*(d-1)/2),L,s),M=Y(N,y,e),j=function(e){var t=e.graphs,r=e.directed,n=void 0!==r&&r,o=e.nodeLabelProp,i=void 0===o?Q:o,a=e.edgeLabelProp,d=void 0===a?Q:a,s=function(e,t,r,n){var o={};return Object.keys(e).forEach((function(i,a){var d=e[i],s=new B(a,!0,t),u={};d.nodes.forEach((function(e,t){s.addNode(t,e[r]),u[e.id]=t})),d.edges.forEach((function(e,t){var r=u[e.source],o=u[e.target];s.addEdge(-1,r,o,e[n])})),s&&s.getNodeNum()&&(o[s.id]=s)})),o}(t,n,i,d),u=e.minSupport,f=e.maxNodeNum,h=e.minNodeNum,c=e.verbose,l=e.top,p=new J({graphs:s,minSupport:u,maxNodeNum:f,minNodeNum:h,top:l,verbose:c,directed:n});return p.run(),function(e,t,r){var n=[];return e.forEach((function(e){var o={nodes:[],edges:[]};e.nodes.forEach((function(e){var r;o.nodes.push(((r={id:""+e.id})[t]=e.label,r))})),e.edges.forEach((function(e){var t;o.edges.push(((t={source:""+e.from,target:""+e.to})[r]=e.label,t))})),n.push(o)})),n}(p.frequentSubgraphs,i,d)}({graphs:M,nodeLabelProp:i,edgeLabelProp:a,minSupport:1,minNodeNum:1,maxNodeNum:4,directed:r}).slice(0,10),w=j.length,I=[];j.forEach((function(e,t){I[t]={},Object.keys(M).forEach((function(r){var n=M[r],o=Z(n,e,i,a);I[t][r]=o}))}));var x=function(e,t,r){for(var n=1/0,o=0,i=function(t){var r=e[t],i=Object.keys(r).sort((function(e,t){return r[e]-r[t]})),a=[];i.forEach((function(e,t){a[t%10]||(a[t%10]={graphs:[],totalCount:0,aveCount:0}),a[t%10].graphs.push(e),a[t%10].totalCount+=r[e]}));var d=0,s=[];a.forEach((function(e){var t=e.totalCount/e.graphs.length;e.aveCount=t,s.push(t);var n=0,o=e.length;e.graphs.forEach((function(t,o){var i=r[t];e.graphs.forEach((function(e,t){o!==t&&(n+=Math.abs(i-r[e]))}))})),d+=n/=o*(o-1)/2})),d/=a.length;var u=0;s.forEach((function(e,t){s.forEach((function(r,n){t!==n&&(u+=Math.abs(e-r))})),u/=s.length*(s.length-1)/2}));var f=u-d;n<f&&(n=f,o=t)},a=0;a<t;a++)i(a);return{structure:r[o],structureCountMap:e[o]}}(I,w,j),S=x.structure,C=x.structureCountMap,P=t.nodes[0],T=P[i],q=p[T],F={},D={},A={},R={},U={};Object.keys(b).forEach((function(r,n){U[r]=[];var o=-1/0,d=b[r],s={};d.forEach((function(e){var t=h[P.id+"-"+e.id];t&&U[r].push(t),o<t&&(o=t),s[P.id+"-"+e.id]={start:0,end:g[e.id].idx,distance:t}})),U[r]=U[r].sort((function(e,t){return e-t})),D=Y(s,L,t,D);var u=[];if(Object.keys(s).forEach((function(e){if(A[e])u.push(A[e]);else{var t=D[e];A[e]=Z(t,S,i,a),u.push(A[e])}})),u=u.sort((function(e,t){return t-e})),R[P.id+"-"+r]=u,r!==T)for(var c=function(t){var n=q[t],o=y[l[n.id].idx],d=o.nodeLabelCountMap[r],s=b[r].length;if(!d||d.count<s)return q.splice(t,1),"continue";for(var h=!1,c=0;c<s;c++)if(d.dists[c]>U[r][c]){h=!0;break}if(h)return q.splice(t,1),"continue";var p={};o.neighbors.forEach((function(e){var t=f[n.id+"-"+e.id];p[n.id+"-"+e.id]={start:l[n.id].idx,end:l[e.id].idx,distance:t}})),M=Y(p,y,e,M);var v=[];Object.keys(p).forEach((function(e){if(C[e])v.push(C[e]);else{var t=M[e];C[e]=Z(t,S,i,a),v.push(C[e])}})),v=v.sort((function(e,t){return t-e}));var g=!1;for(c=0;c<s;c++)if(v[c]<u[c]){g=!0;break}return g?(q.splice(t,1),"continue"):void 0},p=q.length-1;p>=0;p--)c(p)}));var G=[];q.forEach((function(r){for(var n=l[r.id].idx,d=X(e.nodes,s[n],n,i,o).neighbors,u=d.length,h=!1,c=function(n){if(d.length+1<t.nodes.length)return h=!0,{value:void 0};var o=d[n],s=o[i];if(!b[s]||!b[s].length)return d.splice(n,1),"continue";var u=r.id+"-"+o.id;if(!U[s]||!U[s].length)return d.splice(n,1),"continue";var c=f[u];if(c>U[s][U[s].length-1])return d.splice(n,1),"continue";var p=C[u]?C[u]:function(e,t,r,n,o,i,a,d,s,u,f){var h,c=t.id+"-"+r.id;if(u&&u[c])return u[c];var l=f?f[c]:void 0;if(!l){var p=((h={})[c]={start:n[t.id].idx,end:n[r.id].idx,distance:o},h);l=(f=Y(p,i,e,f))[c]}return Z(l,a,d,s)}(e,r,o,l,c,y,S,i,a,C,M),v=P.id+"-"+s;if(p<R[v][R[v].length-1])return d.splice(n,1),"continue";var E=F[s];return void 0===E&&(E=1/0,b[s].forEach((function(e){var t=g[e.id].degree;E>t&&(E=t)})),F[s]=E),l[o.id].degree<E?(d.splice(n,1),"continue"):void 0},p=u-1;p>=0;p--){var v=c(p);if("object"==typeof v)return v.value}h||G.push({nodes:[r].concat(d)})}));var _=k(t,P.id,!1).length,z={};r?(Object.keys(_).forEach((function(e){var t=g[e].node[i];z[t]?z[t].push(_[e]):z[t]=[_[e]]})),Object.keys(z).forEach((function(e){z[e].sort((function(e,t){return e-t}))}))):z=U;for(var H=function(n){var o=G[n],d=o.nodes[0],s={},u={};o.nodes.forEach((function(e,t){u[e.id]={idx:t,node:e,degree:0};var r=e[i];s[r]?s[r]++:s[r]=1}));var f=[],h={};e.edges.forEach((function(e){u[e.source]&&u[e.target]&&(f.push(e),h[e[a]]?h[e[a]]++:h[e[a]]=1,u[e.source].degree++,u[e.target].degree++)}));for(var c=Object.keys(E).length,p=!1,v=0;v<c;v++){var m=Object.keys(E)[v];if(!h[m]||h[m]<E[m].length){p=!0;break}}if(p)return G.splice(n,1),"continue";var y=f.length;if(y<t.edges.length)return G.splice(n,1),"break";var L=!1,N=function(e){var t=f[e],n=t[a],o=E[n];if(!o||!o.length)return h[n]--,o&&h[n]<o.length?(L=!0,"break"):(f.splice(e,1),u[t.source].degree--,u[t.target].degree--,"continue");var d=u[t.source].node[i],s=u[t.target].node[i],c=!1;return o.forEach((function(e){var t=g[e.source].node,n=g[e.target].node;t[i]===d&&n[i]===s&&(c=!0),r||t[i]!==s||n[i]!==d||(c=!0)})),c?void 0:(h[n]--,o&&h[n]<o.length?(L=!0,"break"):(f.splice(e,1),u[t.source].degree--,u[t.target].degree--,"continue"))};for(v=y-1;v>=0&&"break"!==N(v);v--);if(L)return G.splice(n,1),"continue";o.edges=f;var M=k(o,o.nodes[0].id,!1).length;if(Object.keys(M).reverse().forEach((function(e){if(e!==o.nodes[0].id&&!L){if(M[e]===1/0){var t=u[e].node[i];if(s[t]--,s[t]<b[t].length)return void(L=!0);var r=o.nodes.indexOf(u[e].node);return o.nodes.splice(r,1),void(u[e]=void 0)}var n=l[e].node[i];if(!z[n]||!z[n].length||M[e]>z[n][z[n].length-1]){if(t=u[e].node[i],s[t]--,s[t]<b[t].length)return void(L=!0);r=o.nodes.indexOf(u[e].node),o.nodes.splice(r,1),u[e]=void 0}}})),L)return G.splice(n,1),"continue";for(var j=!0,w=0;j&&!L;){if(j=!1,u[d.id].degree<g[P.id].degree){L=!0;break}if(s[d[i]]<b[d[i]].length){L=!0;break}for(var I=o.nodes.length-1;I>=0;I--){var x=o.nodes[I],O=u[x.id].degree,S=x[i];if(O<F[S]){if(s[x[i]]--,s[x[i]]<b[x[i]].length){L=!0;break}o.nodes.splice(I,1),u[x.id]=void 0,j=!0}}if(L||!j&&0!==w)break;for(var C=(y=f.length)-1;C>=0;C--){var T=f[C];if(!u[T.source]||!u[T.target]){f.splice(C,1);var q=T[a];if(h[q]--,u[T.source]&&u[T.source].degree--,u[T.target]&&u[T.target].degree--,E[q]&&h[q]<E[q].length){L=!0;break}j=!0}}w++}return L||L||o.nodes.length<t.nodes.length||f.length<t.edges.length?(G.splice(n,1),"continue"):void 0},K=G.length-1;K>=0&&"break"!==H(K);K--);var W=G.length,re=function(e){var t=G[e],r={};t.edges.forEach((function(e){var t=e.source+"-"+e.target+"-"+e.label;r[t]?r[t]++:r[t]=1}));for(var n=function(e){var t=G[e],n={};t.edges.forEach((function(e){var t=e.source+"-"+e.target+"-"+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&&G.splice(e,1)},o=W-1;o>e;o--)n(o);W=G.length};for(K=0;K<=W-1;K++)re(K);return G}}};var ne=self;ne.onmessage=function(e){var r=e.data,n=r._algorithmType,o=r.data;if(n)if("function"!=typeof t[n])ne.postMessage({_algorithmType:"FAILURE"});else{var i=t[n].apply(t,o);ne.postMessage({_algorithmType:"SUCCESS",data:i})}}})(); | ||
//# sourceMappingURL=index.worker.js.map |
@@ -19,3 +19,3 @@ import { MESSAGE } from './constant'; | ||
worker.postMessage({ | ||
type: type, | ||
_algorithmType: type, | ||
data: data | ||
@@ -27,5 +27,5 @@ }); | ||
data = _a.data, | ||
type = _a.type; | ||
_algorithmType = _a._algorithmType; | ||
if (MESSAGE.SUCCESS === type) { | ||
if (MESSAGE.SUCCESS === _algorithmType) { | ||
resolve(data); | ||
@@ -32,0 +32,0 @@ } else { |
@@ -7,9 +7,15 @@ import * as algorithm from './algorithm'; | ||
var _a = event.data, | ||
type = _a.type, | ||
data = _a.data; | ||
_algorithmType = _a._algorithmType, | ||
data = _a.data; // 如果发送内容没有私有类型。说明不是自己发的。不管 | ||
// fix: https://github.com/antvis/algorithm/issues/25 | ||
if (typeof algorithm[type] === 'function') { | ||
var result = algorithm[type].apply(algorithm, data); | ||
if (!_algorithmType) { | ||
return; | ||
} | ||
if (typeof algorithm[_algorithmType] === 'function') { | ||
var result = algorithm[_algorithmType].apply(algorithm, data); | ||
ctx.postMessage({ | ||
type: MESSAGE.SUCCESS, | ||
_algorithmType: MESSAGE.SUCCESS, | ||
data: result | ||
@@ -21,3 +27,3 @@ }); | ||
ctx.postMessage({ | ||
type: MESSAGE.FAILURE | ||
_algorithmType: MESSAGE.FAILURE | ||
}); | ||
@@ -24,0 +30,0 @@ }; // https://stackoverflow.com/questions/50210416/webpack-worker-loader-fails-to-compile-typescript-worker |
@@ -29,3 +29,3 @@ "use strict"; | ||
worker.postMessage({ | ||
type: type, | ||
_algorithmType: type, | ||
data: data | ||
@@ -37,5 +37,5 @@ }); | ||
data = _a.data, | ||
type = _a.type; | ||
_algorithmType = _a._algorithmType; | ||
if (_constant.MESSAGE.SUCCESS === type) { | ||
if (_constant.MESSAGE.SUCCESS === _algorithmType) { | ||
resolve(data); | ||
@@ -42,0 +42,0 @@ } else { |
@@ -22,9 +22,15 @@ "use strict"; | ||
var _a = event.data, | ||
type = _a.type, | ||
data = _a.data; | ||
_algorithmType = _a._algorithmType, | ||
data = _a.data; // 如果发送内容没有私有类型。说明不是自己发的。不管 | ||
// fix: https://github.com/antvis/algorithm/issues/25 | ||
if (typeof algorithm[type] === 'function') { | ||
var result = algorithm[type].apply(algorithm, data); | ||
if (!_algorithmType) { | ||
return; | ||
} | ||
if (typeof algorithm[_algorithmType] === 'function') { | ||
var result = algorithm[_algorithmType].apply(algorithm, data); | ||
ctx.postMessage({ | ||
type: _constant.MESSAGE.SUCCESS, | ||
_algorithmType: _constant.MESSAGE.SUCCESS, | ||
data: result | ||
@@ -36,3 +42,3 @@ }); | ||
ctx.postMessage({ | ||
type: _constant.MESSAGE.FAILURE | ||
_algorithmType: _constant.MESSAGE.FAILURE | ||
}); | ||
@@ -39,0 +45,0 @@ }; // https://stackoverflow.com/questions/50210416/webpack-worker-loader-fails-to-compile-typescript-worker |
{ | ||
"name": "@antv/algorithm", | ||
"version": "0.1.8-beta.5", | ||
"version": "0.1.8-beta.6", | ||
"description": "graph algorithm", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
974180
9903