graphology
Advanced tools
Comparing version 0.9.1 to 0.10.0
@@ -1,1 +0,1 @@ | ||
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.graphology=t():e.graphology=t()}(this,function(){return function(e){function t(n){if(r[n])return r[n].exports;var o=r[n]={i:n,l:!1,exports:{}};return e[n].call(o.exports,o,o.exports,t),o.l=!0,o.exports}var r={};return t.m=e,t.c=r,t.i=function(e){return e},t.d=function(e,r,n){t.o(e,r)||Object.defineProperty(e,r,{configurable:!1,enumerable:!0,get:n})},t.n=function(e){var r=e&&e.__esModule?function(){return e.default}:function(){return e};return t.d(r,"a",r),r},t.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},t.p="",t(t.s=5)}([function(e,t,r){"use strict";function n(e){e=e||{};for(var t=arguments.length,r=Array(t>1?t-1:0),n=1;n<t;n++)r[n-1]=arguments[n];for(var o=0,i=r.length;o<i;o++)if(r[o])for(var a in r[o])e[a]=r[o][a];return e}function o(e,t){for(var r=new Array(e),n=0,o=void 0;o=t.next(),!o.done;)r[n++]=o.value;return r}function i(e,t,r,n){var o=e._nodes.get(t);return"mixed"===n?o.out&&o.out[r]||o.undirected&&o.undirected[r]:"directed"===n?o.out&&o.out[r]:o.undirected&&o.undirected[r]}function a(e){return!!e&&"object"===(void 0===e?"undefined":g(e))&&(Array.isArray(e)||"function"==typeof Map&&e instanceof Map||"function"==typeof Set&&e instanceof Set||!(e instanceof Date)&&!(e instanceof RegExp))}function d(e){return null!==e&&"object"===(void 0===e?"undefined":g(e))&&"function"==typeof e.addUndirectedEdgeWithKey&&"function"==typeof e.dropNode}function s(e){return"object"===(void 0===e?"undefined":g(e))&&null!==e&&e.constructor===Object}function u(e,t){if(Array.isArray(e))for(var r=0,n=e.length;r<n;r++)t(e[r],null);else if("function"==typeof e.forEach)for(var o=e.entries(),i=void 0;i=o.next();){var a=i,d=a.value,s=a.done;if(s)break;var u=d[0],h=d[1];h===u?t(h,null):t(u,h)}else for(var p in e){var c=e[p];t(p,c)}}function h(e){for(var t=""+e,r="",n=0,o=t.length;n<o;n++){r=t[o-n-1]+r,(n-2)%3||n===o-1||(r=","+r)}return r}function p(e,t,r){Object.defineProperty(e,t,{enumerable:!1,configurable:!1,writable:!0,value:r})}function c(e,t,r){var n={enumerable:!0,configurable:!0};"function"==typeof r?n.get=r:(n.value=r,n.writable=!1),Object.defineProperty(e,t,n)}function f(){var e=0;return function(){return"_geid"+e+++"_"}}Object.defineProperty(t,"__esModule",{value:!0});var g="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e};t.assign=n,t.consumeIterator=o,t.getMatchingEdge=i,t.isBunch=a,t.isGraph=d,t.isPlainObject=s,t.overBunch=u,t.prettyPrint=h,t.privateProperty=p,t.readOnlyProperty=c,t.incrementalId=f},function(e,t,r){"use strict";function n(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function o(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t}function i(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}Object.defineProperty(t,"__esModule",{value:!0});var a=t.GraphError=function(e){function t(r,i){n(this,t);var a=o(this,e.call(this));return a.name="GraphError",a.message=r||"",a.data=i||{},a}return i(t,e),t}(Error);t.InvalidArgumentsGraphError=function(e){function t(r,i){n(this,t);var a=o(this,e.call(this,r,i));return a.name="InvalidArgumentsGraphError","function"==typeof Error.captureStackTrace&&Error.captureStackTrace(a,t.prototype.constructor),a}return i(t,e),t}(a),t.NotFoundGraphError=function(e){function t(r,i){n(this,t);var a=o(this,e.call(this,r,i));return a.name="NotFoundGraphError","function"==typeof Error.captureStackTrace&&Error.captureStackTrace(a,t.prototype.constructor),a}return i(t,e),t}(a),t.UsageGraphError=function(e){function t(r,i){n(this,t);var a=o(this,e.call(this,r,i));return a.name="UsageGraphError","function"==typeof Error.captureStackTrace&&Error.captureStackTrace(a,t.prototype.constructor),a}return i(t,e),t}(a)},function(e,t,r){"use strict";function n(e){this.attributes=e,this.inDegree=0,this.outDegree=0,this.undirectedDegree=0,this.directedSelfLoops=0,this.undirectedSelfLoops=0,this.in={},this.out={},this.undirected={}}function o(e){this.attributes=e||{},this.inDegree=0,this.outDegree=0,this.directedSelfLoops=0,this.in={},this.out={}}function i(e){this.attributes=e||{},this.undirectedDegree=0,this.undirectedSelfLoops=0,this.undirected={}}function a(e,t,r,n){this.attributes=n,this.source=t,this.target=r,this.generatedKey=e}function d(e,t,r,n){this.attributes=n,this.source=t,this.target=r,this.generatedKey=e}Object.defineProperty(t,"__esModule",{value:!0}),t.MixedNodeData=n,t.DirectedNodeData=o,t.UndirectedNodeData=i,t.DirectedEdgeData=a,t.UndirectedEdgeData=d,o.prototype.upgradeToMixed=function(){this.undirectedDegree=0,this.undirectedSelfLoops=0,this.undirected={}},i.prototype.upgradeToMixed=function(){this.inDegree=0,this.outDegree=0,this.directedSelfLoops=0,this.in={},this.out={}}},function(e,t,r){"use strict";function n(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function o(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t}function i(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}function a(e,t,r,n,o,i,a,d){if(!n&&"undirected"===e.type)throw new h.UsageGraphError("Graph."+t+": you cannot add a directed edge to an undirected graph. Use the #.addEdge or #.addUndirectedEdge instead.");if(n&&"directed"===e.type)throw new h.UsageGraphError("Graph."+t+": you cannot add an undirected edge to a directed graph. Use the #.addEdge or #.addDirectedEdge instead.");if(!e.allowSelfLoops&&i===a)throw new h.UsageGraphError("Graph."+t+': source & target are the same ("'+i+"\"), thus creating a loop explicitly forbidden by this graph 'allowSelfLoops' option set to false.");if(d&&!(0,v.isPlainObject)(d))throw new h.InvalidArgumentsGraphError("Graph."+t+': invalid attributes. Expecting an object but got "'+d+'"');i=""+i,a=""+a;var s=e._nodes.get(i),u=e._nodes.get(a);if(!s)throw new h.NotFoundGraphError("Graph."+t+': source node "'+i+'" not found.');if(!u)throw new h.NotFoundGraphError("Graph."+t+': target node "'+a+'" not found.');if(d=(0,v.assign)({},e._options.defaultEdgeAttributes,d),r&&(o=e._edgeKeyGenerator({undirected:n,source:i,target:a,attributes:d})),o=""+o,e._edges.has(o))throw new h.UsageGraphError("Graph."+t+': the "'+o+'" edge already exists in the graph.');if(!e.multi&&(n?e.hasUndirectedEdge(i,a):e.hasDirectedEdge(i,a)))throw new h.UsageGraphError("Graph."+t+': an edge linking "'+i+'" to "'+a+"\" already exists. If you really want to add multiple edges linking those nodes, you should create a multi graph by using the 'multi' option.");var c=n?p.UndirectedEdgeData:p.DirectedEdgeData,g=new c(r,i,a,d);return e._edges.set(o,g),i===a?n?s.undirectedSelfLoops++:s.directedSelfLoops++:n?(s.undirectedDegree++,u.undirectedDegree++):(s.outDegree++,u.inDegree++),(0,f.updateStructureIndex)(e,n,o,i,a,s,u),e.emit("edgeAdded",{key:o,source:i,target:a,attributes:d,undirected:n}),o}function d(e,t,r,n,o,i,a,d){if(!n&&"undirected"===e.type)throw new h.UsageGraphError("Graph."+t+": you cannot add a directed edge to an undirected graph. Use the #.addEdge or #.addUndirectedEdge instead.");if(n&&"directed"===e.type)throw new h.UsageGraphError("Graph."+t+": you cannot add an undirected edge to a directed graph. Use the #.addEdge or #.addDirectedEdge instead.");if(!e.allowSelfLoops&&i===a)throw new h.UsageGraphError("Graph."+t+': source & target are the same ("'+i+"\"), thus creating a loop explicitly forbidden by this graph 'allowSelfLoops' option set to false.");if(d&&!(0,v.isPlainObject)(d))throw new h.InvalidArgumentsGraphError("Graph."+t+': invalid attributes. Expecting an object but got "'+d+'"');i=""+i,a=""+a;var s=e._nodes.get(i),u=e._nodes.get(a),c=null;if(!e.multi&&(n?e.hasUndirectedEdge(i,a):e.hasDirectedEdge(i,a))&&(c=(0,v.getMatchingEdge)(e,i,a,n?"undirected":"directed")),c){var g=e._edges.get(c);if(g.source!==i||g.target!==a)throw new h.UsageGraphError("Graph."+t+': inconsistency detected when attempting to merge the "'+o+'" edge with "'+i+'" source & "'+a+'" target vs. ('+g.source+", "+g.target+").");return(0,v.assign)(g.attributes,d),c}if(d=(0,v.assign)({},e._options.defaultEdgeAttributes,d),r&&(o=e._edgeKeyGenerator({undirected:n,source:i,target:a,attributes:d})),o=""+o,e._edges.has(o))throw new h.UsageGraphError("Graph."+t+': the "'+o+'" edge already exists in the graph.');s||(e.addNode(i),s=e._nodes.get(i)),u||(e.addNode(a),u=e._nodes.get(a));var l=n?p.UndirectedEdgeData:p.DirectedEdgeData,y=new l(r,i,a,d);return e._edges.set(o,y),i===a?n?s.undirectedSelfLoops++:s.directedSelfLoops++:n?(s.undirectedDegree++,u.undirectedDegree++):(s.outDegree++,u.inDegree++),(0,f.updateStructureIndex)(e,n,o,i,a,s,u),e.emit("edgeAdded",{key:o,source:i,target:a,attributes:d,undirected:n}),o}function s(e,t,r,n){var o=[];if(n){if(!(0,v.isBunch)(n))throw new h.InvalidArgumentsGraphError("Graph."+t+": invalid bunch.");(0,v.overBunch)(n,function(n){if(!e.hasEdge(n))throw new h.NotFoundGraphError("Graph."+t+': could not find the "'+n+'" edge from the bunch in the graph.');r&&!r(n)||o.push(n)})}else o="exportEdges"===t?e.edges():"exportDirectedEdges"===t?e.directedEdges():e.undirectedEdges();for(var i=new Array(o.length),a=0,d=o.length;a<d;a++)i[a]=e.exportEdge(o[a]);return i}Object.defineProperty(t,"__esModule",{value:!0});var u=r(11),h=r(1),p=r(2),c=r(8),f=r(6),g=r(4),l=r(7),y=r(9),b=r(10),v=r(0),w=new Set(["directed","undirected","mixed"]),m=new Set(["domain","_events","_eventsCount","_maxListeners"]),E=[{name:function(e){return e+"Edge"},generateKey:!0},{name:function(e){return e+"DirectedEdge"},generateKey:!0,type:"directed"},{name:function(e){return e+"UndirectedEdge"},generateKey:!0,type:"undirected"},{name:function(e){return e+"EdgeWithKey"}},{name:function(e){return e+"DirectedEdgeWithKey"},type:"directed"},{name:function(e){return e+"UndirectedEdgeWithKey"},type:"undirected"}],G={allowSelfLoops:!0,defaultEdgeAttributes:{},defaultNodeAttributes:{},edgeKeyGenerator:null,multi:!1,type:"mixed"},_=function(e){function t(r){n(this,t);var i=o(this,e.call(this));if(r=(0,v.assign)({},G,r),r.edgeKeyGenerator&&"function"!=typeof r.edgeKeyGenerator)throw new h.InvalidArgumentsGraphError("Graph.constructor: invalid 'edgeKeyGenerator' option. Expecting a function but got \""+r.edgeKeyGenerator+'".');if("boolean"!=typeof r.multi)throw new h.InvalidArgumentsGraphError("Graph.constructor: invalid 'multi' option. Expecting a boolean but got \""+r.multi+'".');if(!w.has(r.type))throw new h.InvalidArgumentsGraphError('Graph.constructor: invalid \'type\' option. Should be one of "mixed", "directed" or "undirected" but got "'+r.type+'".');if("boolean"!=typeof r.allowSelfLoops)throw new h.InvalidArgumentsGraphError("Graph.constructor: invalid 'allowSelfLoops' option. Expecting a boolean but got \""+r.allowSelfLoops+'".');if(!(0,v.isPlainObject)(r.defaultEdgeAttributes))throw new h.InvalidArgumentsGraphError("Graph.constructor: invalid 'defaultEdgeAttributes' option. Expecting a plain object but got \""+r.defaultEdgeAttributes+'".');if(!(0,v.isPlainObject)(r.defaultNodeAttributes))throw new h.InvalidArgumentsGraphError("Graph.constructor: invalid 'defaultNodeAttributes' option. Expecting a plain object but got \""+r.defaultNodeAttributes+'".');return(0,v.privateProperty)(i,"_attributes",{}),(0,v.privateProperty)(i,"_nodes",new Map),(0,v.privateProperty)(i,"_edges",new Map),(0,v.privateProperty)(i,"_edgeKeyGenerator",r.edgeKeyGenerator||(0,v.incrementalId)()),(0,v.privateProperty)(i,"_options",r),m.forEach(function(e){return(0,v.privateProperty)(i,e,i[e])}),(0,v.readOnlyProperty)(i,"order",function(){return i._nodes.size}),(0,v.readOnlyProperty)(i,"size",function(){return i._edges.size}),(0,v.readOnlyProperty)(i,"multi",i._options.multi),(0,v.readOnlyProperty)(i,"type",i._options.type),(0,v.readOnlyProperty)(i,"allowSelfLoops",i._options.allowSelfLoops),i}return i(t,e),t.prototype.hasNode=function(e){return this._nodes.has(""+e)},t.prototype.hasDirectedEdge=function(e,t){if("undirected"===this.type)return!1;if(1===arguments.length){var r=""+e,n=this._edges.get(r);return!!n&&n instanceof p.DirectedEdgeData}if(2===arguments.length){e=""+e,t=""+t;var o=this._nodes.get(e);if(!o)return!1;var i=o.out[t];return!!i&&(!this.multi||!!i.size)}throw new h.InvalidArgumentsGraphError("Graph.hasDirectedEdge: invalid arity ("+arguments.length+", instead of 1 or 2). You can either ask for an edge id or for the existence of an edge between a source & a target.")},t.prototype.hasUndirectedEdge=function(e,t){if("directed"===this.type)return!1;if(1===arguments.length){var r=""+e,n=this._edges.get(r);return!!n&&n instanceof p.UndirectedEdgeData}if(2===arguments.length){e=""+e,t=""+t;var o=this._nodes.get(e);if(!o)return!1;var i=o.undirected[t];return!!i&&(!this.multi||!!i.size)}throw new h.InvalidArgumentsGraphError("Graph.hasDirectedEdge: invalid arity ("+arguments.length+", instead of 1 or 2). You can either ask for an edge id or for the existence of an edge between a source & a target.")},t.prototype.hasEdge=function(e,t){if(1===arguments.length){var r=""+e;return this._edges.has(r)}if(2===arguments.length){e=""+e,t=""+t;var n=this._nodes.get(e);if(!n)return!1;var o=void 0!==n.out&&n.out[t];return o||(o=void 0!==n.undirected&&n.undirected[t]),!!o&&(!this.multi||!!o.size)}throw new h.InvalidArgumentsGraphError("Graph.hasEdge: invalid arity ("+arguments.length+", instead of 1 or 2). You can either ask for an edge id or for the existence of an edge between a source & a target.")},t.prototype.directedEdge=function(e,t){if("undirected"!==this.type){if(e=""+e,t=""+t,this.multi)throw new h.UsageGraphError("Graph.directedEdge: this method is irrelevant with multigraphs since there might be multiple edges between source & target. See #.directedEdges instead.");var r=this._nodes.get(e);if(!r)throw new h.NotFoundGraphError('Graph.directedEdge: could not find the "'+e+'" source node in the graph.');if(!this._nodes.has(t))throw new h.NotFoundGraphError('Graph.directedEdge: could not find the "'+t+'" target node in the graph.');return r.out&&r.out[t]||void 0}},t.prototype.undirectedEdge=function(e,t){if("directed"!==this.type){if(e=""+e,t=""+t,this.multi)throw new h.UsageGraphError("Graph.undirectedEdge: this method is irrelevant with multigraphs since there might be multiple edges between source & target. See #.undirectedEdges instead.");var r=this._nodes.get(e);if(!r)throw new h.NotFoundGraphError('Graph.undirectedEdge: could not find the "'+e+'" source node in the graph.');if(!this._nodes.has(t))throw new h.NotFoundGraphError('Graph.undirectedEdge: could not find the "'+t+'" target node in the graph.');return r.undirected&&r.undirected[t]||void 0}},t.prototype.edge=function(e,t){if(this.multi)throw new h.UsageGraphError("Graph.edge: this method is irrelevant with multigraphs since there might be multiple edges between source & target. See #.edges instead.");e=""+e,t=""+t;var r=this._nodes.get(e);if(!r)throw new h.NotFoundGraphError('Graph.edge: could not find the "'+e+'" source node in the graph.');if(!this._nodes.has(t))throw new h.NotFoundGraphError('Graph.edge: could not find the "'+t+'" target node in the graph.');return r.out&&r.out[t]||r.undirected&&r.undirected[t]||void 0},t.prototype.inDegree=function(e){var t=!(arguments.length>1&&void 0!==arguments[1])||arguments[1];if("boolean"!=typeof t)throw new h.InvalidArgumentsGraphError('Graph.inDegree: Expecting a boolean but got "'+t+'" for the second parameter (allowing self-loops to be counted).');e=""+e;var r=this._nodes.get(e);if(!r)throw new h.NotFoundGraphError('Graph.inDegree: could not find the "'+e+'" node in the graph.');if("undirected"===this.type)return 0;var n=t?r.directedSelfLoops:0;return r.inDegree+n},t.prototype.outDegree=function(e){var t=!(arguments.length>1&&void 0!==arguments[1])||arguments[1];if("boolean"!=typeof t)throw new h.InvalidArgumentsGraphError('Graph.outDegree: Expecting a boolean but got "'+t+'" for the second parameter (allowing self-loops to be counted).');e=""+e;var r=this._nodes.get(e);if(!r)throw new h.NotFoundGraphError('Graph.outDegree: could not find the "'+e+'" node in the graph.');if("undirected"===this.type)return 0;var n=t?r.directedSelfLoops:0;return r.outDegree+n},t.prototype.directedDegree=function(e){var t=!(arguments.length>1&&void 0!==arguments[1])||arguments[1];if("boolean"!=typeof t)throw new h.InvalidArgumentsGraphError('Graph.directedDegree: Expecting a boolean but got "'+t+'" for the second parameter (allowing self-loops to be counted).');if(e=""+e,!this.hasNode(e))throw new h.NotFoundGraphError('Graph.directedDegree: could not find the "'+e+'" node in the graph.');return"undirected"===this.type?0:this.inDegree(e,t)+this.outDegree(e,t)},t.prototype.undirectedDegree=function(e){var t=!(arguments.length>1&&void 0!==arguments[1])||arguments[1];if("boolean"!=typeof t)throw new h.InvalidArgumentsGraphError('Graph.undirectedDegree: Expecting a boolean but got "'+t+'" for the second parameter (allowing self-loops to be counted).');if(e=""+e,!this.hasNode(e))throw new h.NotFoundGraphError('Graph.undirectedDegree: could not find the "'+e+'" node in the graph.');if("directed"===this.type)return 0;var r=this._nodes.get(e),n=t?2*r.undirectedSelfLoops:0;return r.undirectedDegree+n},t.prototype.degree=function(e){var t=!(arguments.length>1&&void 0!==arguments[1])||arguments[1];if("boolean"!=typeof t)throw new h.InvalidArgumentsGraphError('Graph.degree: Expecting a boolean but got "'+t+'" for the second parameter (allowing self-loops to be counted).');if(e=""+e,!this.hasNode(e))throw new h.NotFoundGraphError('Graph.degree: could not find the "'+e+'" node in the graph.');var r=0;return"undirected"!==this.type&&(r+=this.directedDegree(e,t)),"directed"!==this.type&&(r+=this.undirectedDegree(e,t)),r},t.prototype.source=function(e){if(e=""+e,!this.hasEdge(e))throw new h.NotFoundGraphError('Graph.source: could not find the "'+e+'" edge in the graph.');return this._edges.get(e).source},t.prototype.target=function(e){if(e=""+e,!this.hasEdge(e))throw new h.NotFoundGraphError('Graph.target: could not find the "'+e+'" edge in the graph.');return this._edges.get(e).target},t.prototype.extremities=function(e){e=""+e;var t=this._edges.get(e);if(!t)throw new h.NotFoundGraphError('Graph.extremities: could not find the "'+e+'" edge in the graph.');return[t.source,t.target]},t.prototype.opposite=function(e,t){if(e=""+e,t=""+t,!this._nodes.has(e))throw new h.NotFoundGraphError('Graph.opposite: could not find the "'+e+'" node in the graph.');var r=this._edges.get(t);if(!r)throw new h.NotFoundGraphError('Graph.opposite: could not find the "'+t+'" edge in the graph.');var n=r.source,o=r.target;if(e!==n&&e!==o)throw new h.NotFoundGraphError('Graph.opposite: the "'+e+'" node is not attached to the "'+t+'" edge ('+n+", "+o+").");return e===n?o:n},t.prototype.undirected=function(e){e=""+e;var t=this._edges.get(e);if(!t)throw new h.NotFoundGraphError('Graph.undirected: could not find the "'+e+'" edge in the graph.');return t instanceof p.UndirectedEdgeData},t.prototype.directed=function(e){e=""+e;var t=this._edges.get(e);if(!t)throw new h.NotFoundGraphError('Graph.directed: could not find the "'+e+'" edge in the graph.');return t instanceof p.DirectedEdgeData},t.prototype.selfLoop=function(e){e=""+e;var t=this._edges.get(e);if(!t)throw new h.NotFoundGraphError('Graph.selfLoop: could not find the "'+e+'" edge in the graph.');return t.source===t.target},t.prototype.addNode=function(e,t){if(t&&!(0,v.isPlainObject)(t))throw new h.InvalidArgumentsGraphError('Graph.addNode: invalid attributes. Expecting an object but got "'+t+'"');if(e=""+e,this._nodes.has(e))throw new h.UsageGraphError('Graph.addNode: the "'+e+'" node already exist in the graph.');t=(0,v.assign)({},this._options.defaultNodeAttributes,t);var r="mixed"===this.type?p.MixedNodeData:"directed"===this.type?p.DirectedNodeData:p.UndirectedNodeData,n=new r(t);return this._nodes.set(e,n),this.emit("nodeAdded",{key:e,attributes:t}),e},t.prototype.mergeNode=function(e,t){var r=this._nodes.get(e);return r?(t&&(0,v.assign)(r.attributes,t),e):this.addNode(e,t)},t.prototype.addNodesFrom=function(e){var t=this;if(!(0,v.isBunch)(e))throw new h.InvalidArgumentsGraphError('Graph.addNodesFrom: invalid bunch provided ("'+e+'").');return(0,v.overBunch)(e,function(e,r){t.addNode(e,r)}),this},t.prototype.dropNode=function(e){if(e=""+e,!this.hasNode(e))throw new h.NotFoundGraphError('Graph.dropNode: could not find the "'+e+'" node in the graph.');for(var t=this.edges(e),r=0,n=t.length;r<n;r++)this.dropEdge(t[r]);var o=this._nodes.get(e);this._nodes.delete(e),this.emit("nodeDropped",{key:e,attributes:o.attributes})},t.prototype.dropEdge=function(e){if(arguments.length>1){var t=""+arguments[0],r=""+arguments[1];if(!this.hasNode(t))throw new h.NotFoundGraphError('Graph.dropEdge: could not find the "'+t+'" source node in the graph.');if(!this.hasNode(r))throw new h.NotFoundGraphError('Graph.dropEdge: could not find the "'+r+'" target node in the graph.');if(!this.hasEdge(t,r))throw new h.NotFoundGraphError('Graph.dropEdge: could not find the "'+t+'" -> "'+r+'" edge in the graph.');e=(0,v.getMatchingEdge)(this,t,r,this.type)}else if(e=""+e,!this.hasEdge(e))throw new h.NotFoundGraphError('Graph.dropEdge: could not find the "'+e+'" edge in the graph.');var n=this._edges.get(e);this._edges.delete(e);var o=n.source,i=n.target,a=n.attributes,d=n instanceof p.UndirectedEdgeData,s=this._nodes.get(o),u=this._nodes.get(i);return o===i?s.selfLoops--:d?(s.undirectedDegree--,u.undirectedDegree--):(s.outDegree--,u.inDegree--),(0,f.clearEdgeFromStructureIndex)(this,d,e,n),this.emit("edgeDropped",{key:e,attributes:a,source:o,target:i,undirected:d}),this},t.prototype.dropNodes=function(e){var t=this;if(!arguments.length)return this.clear();if(!(0,v.isBunch)(e))throw new h.InvalidArgumentsGraphError("Graph.dropNodes: invalid bunch.");return(0,v.overBunch)(e,function(e){t.dropNode(e)}),this},t.prototype.dropEdges=function(e){var t=this;if(!arguments.length)return this._edges.clear(),this.clearIndex(),this;if(2===arguments.length){var r=arguments[0],n=arguments[1];e=this.edges(r,n)}if(!(0,v.isBunch)(e))throw new h.InvalidArgumentsGraphError("Graph.dropEdges: invalid bunch.");return(0,v.overBunch)(e,function(e){t.dropEdge(e)}),this},t.prototype.clear=function(){this._edges.clear(),this._nodes.clear();for(var e in this._indices){var t=this._indices[e];t.lazy&&(t.computed=!1)}this.emit("cleared")},t.prototype.getAttribute=function(e){return this._attributes[e]},t.prototype.getAttributes=function(){return this._attributes},t.prototype.hasAttribute=function(e){return this._attributes.hasOwnProperty(e)},t.prototype.setAttribute=function(e,t){return this._attributes[e]=t,this.emit("attributesUpdated",{type:"set",meta:{name:e,value:t}}),this},t.prototype.updateAttribute=function(e,t){if("function"!=typeof t)throw new h.InvalidArgumentsGraphError("Graph.updateAttribute: updater should be a function.");return this._attributes[e]=t(this._attributes[e]),this.emit("attributesUpdated",{type:"set",meta:{name:e,value:this._attributes[e]}}),this},t.prototype.removeAttribute=function(e){return delete this._attributes[e],this.emit("attributesUpdated",{type:"remove",meta:{name:e}}),this},t.prototype.replaceAttributes=function(e){if(!(0,v.isPlainObject)(e))throw new h.InvalidArgumentsGraphError("Graph.replaceAttributes: provided attributes are not a plain object.");var t=this._attributes;return this._attributes=e,this.emit("attributesUpdated",{type:"replace",meta:{before:t,after:e}}),this},t.prototype.mergeAttributes=function(e){if(!(0,v.isPlainObject)(e))throw new h.InvalidArgumentsGraphError("Graph.mergeAttributes: provided attributes are not a plain object.");return this._attributes=(0,v.assign)(this._attributes,e),this.emit("attributesUpdated",{type:"merge",meta:{data:this._attributes}}),this},t.prototype.getNodeAttribute=function(e,t){if(e=""+e,!this.hasNode(e))throw new h.NotFoundGraphError('Graph.getNodeAttribute: could not find the "'+e+'" node in the graph.');return this._nodes.get(e).attributes[t]},t.prototype.getNodeAttributes=function(e){if(e=""+e,!this.hasNode(e))throw new h.NotFoundGraphError('Graph.getNodeAttributes: could not find the "'+e+'" node in the graph.');return this._nodes.get(e).attributes},t.prototype.hasNodeAttribute=function(e,t){if(e=""+e,!this.hasNode(e))throw new h.NotFoundGraphError('Graph.hasNodeAttribute: could not find the "'+e+'" node in the graph.');return this._nodes.get(e).attributes.hasOwnProperty(t)},t.prototype.setNodeAttribute=function(e,t,r){if(e=""+e,!this.hasNode(e))throw new h.NotFoundGraphError('Graph.setNodeAttribute: could not find the "'+e+'" node in the graph.');if(arguments.length<3)throw new h.InvalidArgumentsGraphError("Graph.setNodeAttribute: not enough arguments. Either you forgot to pass the attribute's name or value, or you meant to use #.replaceNodeAttributes / #.mergeNodeAttributes instead.");return this._nodes.get(e).attributes[t]=r,this.emit("nodeAttributesUpdated",{key:e,type:"set",meta:{name:t,value:r}}),this},t.prototype.updateNodeAttribute=function(e,t,r){if(e=""+e,!this.hasNode(e))throw new h.NotFoundGraphError('Graph.updateNodeAttribute: could not find the "'+e+'" node in the graph.');if(arguments.length<3)throw new h.InvalidArgumentsGraphError("Graph.updateNodeAttribute: not enough arguments. Either you forgot to pass the attribute's name or updater, or you meant to use #.replaceNodeAttributes / #.mergeNodeAttributes instead.");if("function"!=typeof r)throw new h.InvalidArgumentsGraphError("Graph.updateAttribute: updater should be a function.");var n=this._nodes.get(e).attributes;return n[t]=r(n[t]),this.emit("nodeAttributesUpdated",{key:e,type:"set",meta:{name:t,value:n[t]}}),this},t.prototype.removeNodeAttribute=function(e,t){if(e=""+e,!this.hasNode(e))throw new h.NotFoundGraphError('Graph.hasNodeAttribute: could not find the "'+e+'" node in the graph.');return delete this._nodes.get(e).attributes[t],this.emit("nodeAttributesUpdated",{key:e,type:"remove",meta:{name:t}}),this},t.prototype.replaceNodeAttributes=function(e,t){if(e=""+e,!this.hasNode(e))throw new h.NotFoundGraphError('Graph.replaceNodeAttributes: could not find the "'+e+'" node in the graph.');if(!(0,v.isPlainObject)(t))throw new h.InvalidArgumentsGraphError("Graph.replaceNodeAttributes: provided attributes are not a plain object.");var r=this._nodes.get(e),n=r.attributes;return r.attributes=t,this.emit("nodeAttributesUpdated",{key:e,type:"replace",meta:{before:n,after:t}}),this},t.prototype.mergeNodeAttributes=function(e,t){if(e=""+e,!this.hasNode(e))throw new h.NotFoundGraphError('Graph.mergeNodeAttributes: could not find the "'+e+'" node in the graph.');if(!(0,v.isPlainObject)(t))throw new h.InvalidArgumentsGraphError("Graph.mergeNodeAttributes: provided attributes are not a plain object.");var r=this._nodes.get(e);return(0,v.assign)(r.attributes,t),this.emit("nodeAttributesUpdated",{key:e,type:"merge",meta:{data:t}}),this},t.prototype.nodes=function(){return(0,v.consumeIterator)(this._nodes.size,this._nodes.keys())},t.prototype.nodesIterator=function(){var e=this._nodes.keys();return new c.NodesIterator(function(){return e.next()})},t.prototype.exportNode=function(e){e=""+e;var t=this._nodes.get(e);if(!t)throw new h.NotFoundGraphError('Graph.exportNode: could not find the "'+e+'" node in the graph.');return(0,b.serializeNode)(e,t)},t.prototype.exportEdge=function(e){e=""+e;var t=this._edges.get(e);if(!t)throw new h.NotFoundGraphError('Graph.exportEdge: could not find the "'+e+'" edge in the graph.');return(0,b.serializeEdge)(e,t)},t.prototype.exportNodes=function(e){var t=this,r=[];if(arguments.length){if(!(0,v.isBunch)(e))throw new h.InvalidArgumentsGraphError("Graph.exportNodes: invalid bunch.");(0,v.overBunch)(e,function(e){if(!t.hasNode(e))throw new h.NotFoundGraphError('Graph.exportNodes: could not find the "'+e+'" node from the bunch in the graph.');r.push(e)})}else r=this.nodes();for(var n=new Array(r.length),o=0,i=r.length;o<i;o++)n[o]=this.exportNode(r[o]);return n},t.prototype.exportEdges=function(e){return s(this,"exportEdges",null,e)},t.prototype.exportDirectedEdges=function(e){var t=this;return s(this,"exportDirectedEdges",function(e){return t.directed(e)},e)},t.prototype.exportUndirectedEdges=function(e){var t=this;return s(this,"exportUndirectedEdges",function(e){return t.undirected(e)},e)},t.prototype.export=function(){return{attributes:this.getAttributes(),nodes:this.exportNodes(),edges:this.exportEdges()}},t.prototype.importNode=function(e){var t=arguments.length>1&&void 0!==arguments[1]&&arguments[1],r=(0,b.validateSerializedNode)(e);if(r){if("not-object"===r)throw new h.InvalidArgumentsGraphError('Graph.importNode: invalid serialized node. A serialized node should be a plain object with at least a "key" property.');if("no-key"===r)throw new h.InvalidArgumentsGraphError("Graph.importNode: no key provided.");if("invalid-attributes"===r)throw new h.InvalidArgumentsGraphError("Graph.importNode: invalid attributes. Attributes should be a plain object, null or omitted.")}var n=e.key,o=e.attributes,i=void 0===o?{}:o;return t?this.mergeNode(n,i):this.addNode(n,i),this},t.prototype.importEdge=function(e){var t=arguments.length>1&&void 0!==arguments[1]&&arguments[1],r=(0,b.validateSerializedEdge)(e);if(r){if("not-object"===r)throw new h.InvalidArgumentsGraphError('Graph.importEdge: invalid serialized edge. A serialized edge should be a plain object with at least a "source" & "target" property.');if("no-source"===r)throw new h.InvalidArgumentsGraphError("Graph.importEdge: missing souce.");if("no-target"===r)throw new h.InvalidArgumentsGraphError("Graph.importEdge: missing target.");if("invalid-attributes"===r)throw new h.InvalidArgumentsGraphError("Graph.importEdge: invalid attributes. Attributes should be a plain object, null or omitted.");if("invalid-undirected"===r)throw new h.InvalidArgumentsGraphError("Graph.importEdge: invalid undirected. Undirected should be boolean or omitted.")}var n=e.source,o=e.target,i=e.attributes,a=void 0===i?{}:i,d=e.undirected,s=void 0!==d&&d,u=void 0;return"key"in e?(u=t?s?this.mergeUndirectedEdgeWithKey:this.mergeDirectedEdgeWithKey:s?this.addUndirectedEdgeWithKey:this.addDirectedEdgeWithKey,u.call(this,e.key,n,o,a)):(u=t?s?this.mergeUndirectedEdge:this.mergeDirectedEdge:s?this.addUndirectedEdge:this.addDirectedEdge,u.call(this,n,o,a)),this},t.prototype.importNodes=function(e){var t=arguments.length>1&&void 0!==arguments[1]&&arguments[1];if(!Array.isArray(e))throw new h.InvalidArgumentsGraphError("Graph.importNodes: invalid argument. Expecting an array.");for(var r=0,n=e.length;r<n;r++)this.importNode(e[r],t);return this},t.prototype.importEdges=function(e){var t=arguments.length>1&&void 0!==arguments[1]&&arguments[1];if(!Array.isArray(e))throw new h.InvalidArgumentsGraphError("Graph.importEdges: invalid argument. Expecting an array.");for(var r=0,n=e.length;r<n;r++)this.importEdge(e[r],t);return this},t.prototype.import=function(e){var t=arguments.length>1&&void 0!==arguments[1]&&arguments[1];if((0,v.isGraph)(e))return this.import(e.export(),t),this;if(!(0,v.isPlainObject)(e))throw new h.InvalidArgumentsGraphError("Graph.import: invalid argument. Expecting a serialized graph or, alternatively, a Graph instance.");if(e.attributes){if(!(0,v.isPlainObject)(e.attributes))throw new h.InvalidArgumentsGraphError("Graph.import: invalid attributes. Expecting a plain object.");t?this.mergeAttributes(e.attributes):this.replaceAttributes(e.attributes)}return e.nodes&&this.importNodes(e.nodes,t),e.edges&&this.importEdges(e.edges,t),this},t.prototype.emptyCopy=function(){return new t(this._options)},t.prototype.copy=function(){var e=new t(this._options);return e.import(this),e},t.prototype.upgradeToMixed=function(){return"mixed"===this.type?this:(this._nodes.forEach(function(e){return e.upgradeToMixed()}),this._options.type="mixed",(0,v.readOnlyProperty)(this,"type",this._options.type),this)},t.prototype.upgradeToMulti=function(){return this.multi?this:(this._options.multi=!0,(0,v.readOnlyProperty)(this,"multi",!0),(0,f.upgradeStructureIndexToMulti)(this),this)},t.prototype.clearIndex=function(){return(0,f.clearStructureIndex)(this),this},t.prototype.toJSON=function(){return this.export()},t.prototype.toString=function(){var e=this.order>1||0===this.order,t=this.size>1||0===this.size;return"Graph<"+(0,v.prettyPrint)(this.order)+" node"+(e?"s":"")+", "+(0,v.prettyPrint)(this.size)+" edge"+(t?"s":"")+">"},t.prototype.inspect=function(){var e={};this._nodes.forEach(function(t,r){e[r]=t.attributes});var t={};this._edges.forEach(function(e,r){var n=e.undirected?"<->":"->",o="";e.generatedKey||(o+="["+r+"]: "),o+="("+e.source+")"+n+"("+e.target+")",t[o]=e.attributes});var r={};for(var n in this)this.hasOwnProperty(n)&&!m.has(n)&&"function"!=typeof this[n]&&(r[n]=this[n]);return r.attributes=this._attributes,r.nodes=e,r.edges=t,(0,v.privateProperty)(r,"constructor",this.constructor),r},t}(u.EventEmitter);t.default=_,E.forEach(function(e){["add","merge"].forEach(function(t){var r=e.name(t),n="add"===t?a:d;e.generateKey?_.prototype[r]=function(t,o,i){return n(this,r,e.generateKey,"undirected"===(e.type||this.type),null,t,o,i)}:_.prototype[r]=function(t,o,i,a){return n(this,r,e.generateKey,"undirected"===(e.type||this.type),t,o,i,a)}})}),(0,g.attachAttributesMethods)(_),(0,l.attachEdgeIterationMethods)(_),(0,y.attachNeighborIterationMethods)(_)},function(e,t,r){"use strict";function n(e,t,r,n){e.prototype[t]=function(e,o){if(arguments.length>2){if(this.multi)throw new f.UsageGraphError("Graph."+t+": cannot use a {source,target} combo when asking about an edge's attributes in a MultiGraph since we cannot infer the one you want information about.");var i=""+e,a=""+o;if(o=arguments[2],!this[r](i,a))throw new f.NotFoundGraphError("Graph."+t+': could not find an edge for the given path ("'+i+'" - "'+a+'").');e=(0,c.getMatchingEdge)(this,i,a,n)}else e=""+e;if(!this[r](e))throw new f.NotFoundGraphError("Graph."+t+': could not find the "'+e+'" edge in the graph.');return this._edges.get(e).attributes[o]}}function o(e,t,r,n){e.prototype[t]=function(e){if(arguments.length>1){if(this.multi)throw new f.UsageGraphError("Graph."+t+": cannot use a {source,target} combo when asking about an edge's attributes in a MultiGraph since we cannot infer the one you want information about.");var o=""+e,i=""+arguments[1];if(!this[r](o,i))throw new f.NotFoundGraphError("Graph."+t+': could not find an edge for the given path ("'+o+'" - "'+i+'").');e=(0,c.getMatchingEdge)(this,o,i,n)}else e=""+e;if(!this[r](e))throw new f.NotFoundGraphError("Graph."+t+': could not find the "'+e+'" edge in the graph.');return this._edges.get(e).attributes}}function i(e,t,r,n){e.prototype[t]=function(e,o){if(arguments.length>2){if(this.multi)throw new f.UsageGraphError("Graph."+t+": cannot use a {source,target} combo when asking about an edge's attributes in a MultiGraph since we cannot infer the one you want information about.");var i=""+e,a=""+o;if(o=arguments[2],!this[r](i,a))throw new f.NotFoundGraphError("Graph."+t+': could not find an edge for the given path ("'+i+'" - "'+a+'").');e=(0,c.getMatchingEdge)(this,i,a,n)}else e=""+e;if(!this[r](e))throw new f.NotFoundGraphError("Graph."+t+': could not find the "'+e+'" edge in the graph.');return this._edges.get(e).attributes.hasOwnProperty(o)}}function a(e,t,r,n){e.prototype[t]=function(e,o,i){if(arguments.length>3){if(this.multi)throw new f.UsageGraphError("Graph."+t+": cannot use a {source,target} combo when asking about an edge's attributes in a MultiGraph since we cannot infer the one you want information about.");var a=""+e,d=""+o;if(o=arguments[2],i=arguments[3],!this[r](a,d))throw new f.NotFoundGraphError("Graph."+t+': could not find an edge for the given path ("'+a+'" - "'+d+'").');e=(0,c.getMatchingEdge)(this,a,d,n)}else e=""+e;if(!this[r](e))throw new f.NotFoundGraphError("Graph."+t+': could not find the "'+e+'" edge in the graph.');return this._edges.get(e).attributes[o]=i,this.emit("edgeAttributesUpdated",{key:e,type:"set",meta:{name:o,value:i}}),this}}function d(e,t,r,n){e.prototype[t]=function(e,o,i){if(arguments.length>3){if(this.multi)throw new f.UsageGraphError("Graph."+t+": cannot use a {source,target} combo when asking about an edge's attributes in a MultiGraph since we cannot infer the one you want information about.");var a=""+e,d=""+o;if(o=arguments[2],i=arguments[3],!this[r](a,d))throw new f.NotFoundGraphError("Graph."+t+': could not find an edge for the given path ("'+a+'" - "'+d+'").');e=(0,c.getMatchingEdge)(this,a,d,n)}else e=""+e;if(!this[r](e))throw new f.NotFoundGraphError("Graph."+t+': could not find the "'+e+'" edge in the graph.');if("function"!=typeof i)throw new f.InvalidArgumentsGraphError("Graph."+t+": updater should be a function.");var s=this._edges.get(e);return s.attributes[o]=i(s.attributes[o]),this.emit("edgeAttributesUpdated",{key:e,type:"set",meta:{name:o,value:s.attributes[o]}}),this}}function s(e,t,r,n){e.prototype[t]=function(e,o){if(arguments.length>2){if(this.multi)throw new f.UsageGraphError("Graph."+t+": cannot use a {source,target} combo when asking about an edge's attributes in a MultiGraph since we cannot infer the one you want information about.");var i=""+e,a=""+o;if(o=arguments[2],!this[r](i,a))throw new f.NotFoundGraphError("Graph."+t+': could not find an edge for the given path ("'+i+'" - "'+a+'").');e=(0,c.getMatchingEdge)(this,i,a,n)}else e=""+e;if(!this[r](e))throw new f.NotFoundGraphError("Graph."+t+': could not find the "'+e+'" edge in the graph.');return delete this._edges.get(e).attributes[o],this.emit("edgeAttributesUpdated",{key:e,type:"remove",meta:{name:o}}),this}}function u(e,t,r,n){e.prototype[t]=function(e,o){if(arguments.length>2){if(this.multi)throw new f.UsageGraphError("Graph."+t+": cannot use a {source,target} combo when asking about an edge's attributes in a MultiGraph since we cannot infer the one you want information about.");var i=""+e,a=""+o;if(o=arguments[2],!this[r](i,a))throw new f.NotFoundGraphError("Graph."+t+': could not find an edge for the given path ("'+i+'" - "'+a+'").');e=(0,c.getMatchingEdge)(this,i,a,n)}else e=""+e;if(!this[r](e))throw new f.NotFoundGraphError("Graph."+t+': could not find the "'+e+'" edge in the graph.');if(!(0,c.isPlainObject)(o))throw new f.InvalidArgumentsGraphError("Graph."+t+": provided attributes are not a plain object.");var d=this._edges.get(e),s=d.attributes;return d.attributes=o,this.emit("edgeAttributesUpdated",{key:e,type:"replace",meta:{before:s,after:o}}),this}}function h(e,t,r,n){e.prototype[t]=function(e,o){if(arguments.length>2){if(this.multi)throw new f.UsageGraphError("Graph."+t+": cannot use a {source,target} combo when asking about an edge's attributes in a MultiGraph since we cannot infer the one you want information about.");var i=""+e,a=""+o;if(o=arguments[2],!this[r](i,a))throw new f.NotFoundGraphError("Graph."+t+': could not find an edge for the given path ("'+i+'" - "'+a+'").');e=(0,c.getMatchingEdge)(this,i,a,n)}else e=""+e;if(!this[r](e))throw new f.NotFoundGraphError("Graph."+t+': could not find the "'+e+'" edge in the graph.');if(!(0,c.isPlainObject)(o))throw new f.InvalidArgumentsGraphError("Graph."+t+": provided attributes are not a plain object.");var d=this._edges.get(e);return(0,c.assign)(d.attributes,o),this.emit("edgeAttributesUpdated",{key:e,type:"merge",meta:{data:o}}),this}}function p(e){g.forEach(function(t){var r=t.name,n=t.attacher;n(e,r("Edge"),"hasEdge","mixed"),n(e,r("DirectedEdge"),"hasDirectedEdge","directed"),n(e,r("UndirectedEdge"),"hasUndirectedEdge","undirected")})}Object.defineProperty(t,"__esModule",{value:!0}),t.attachAttributesMethods=p;var c=r(0),f=r(1),g=[{name:function(e){return"get"+e+"Attribute"},attacher:n},{name:function(e){return"get"+e+"Attributes"},attacher:o},{name:function(e){return"has"+e+"Attribute"},attacher:i},{name:function(e){return"set"+e+"Attribute"},attacher:a},{name:function(e){return"update"+e+"Attribute"},attacher:d},{name:function(e){return"remove"+e+"Attribute"},attacher:s},{name:function(e){return"replace"+e+"Attributes"},attacher:u},{name:function(e){return"merge"+e+"Attributes"},attacher:h}]},function(e,t,r){"use strict";function n(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function o(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t}function i(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}function a(e){e.from=function(t,r){var n=new e(r);return n.import(t),n}}var d=r(0),s=r(3),u=function(e){return e&&e.__esModule?e:{default:e}}(s),h=r(1),p=function(e){function t(r){return n(this,t),o(this,e.call(this,(0,d.assign)({type:"directed"},r)))}return i(t,e),t}(u.default),c=function(e){function t(r){return n(this,t),o(this,e.call(this,(0,d.assign)({type:"undirected"},r)))}return i(t,e),t}(u.default),f=function(e){function t(r){return n(this,t),o(this,e.call(this,(0,d.assign)({multi:!0,type:"directed"},r)))}return i(t,e),t}(u.default),g=function(e){function t(r){return n(this,t),o(this,e.call(this,(0,d.assign)({multi:!0,type:"undirected"},r)))}return i(t,e),t}(u.default);a(u.default),a(p),a(c),a(f),a(g),u.default.Graph=u.default,u.default.DirectedGraph=p,u.default.UndirectedGraph=c,u.default.MultiDirectedGraph=f,u.default.MultiUndirectedGraph=g,u.default.InvalidArgumentsGraphError=h.InvalidArgumentsGraphError,u.default.NotFoundGraphError=h.NotFoundGraphError,u.default.UsageGraphError=h.UsageGraphError,e.exports=u.default},function(e,t,r){"use strict";function n(e,t,r,n,o,i,a){var d=e.multi,s=t?"undirected":"out",u=t?"undirected":"in";void 0===i[s][o]&&(i[s][o]=d?new Set:r),d&&i[s][o].add(r),n!==o&&void 0===a[u][n]&&(a[u][n]=i[s][o])}function o(e,t,r,n){var o=e.multi,i=n.source,a=n.target,d=e._nodes.get(i),s=t?"undirected":"out",u=d[s];if(a in u&&(o?u[a].delete(r):delete u[a]),!o){delete e._nodes.get(a)[t?"undirected":"in"][i]}}function i(e){e._nodes.forEach(function(e){e.in={},e.out={},e.undirected={}})}function a(e){e._nodes.forEach(function(t,r){if(t.out)for(var n in t.out){var o=new Set;o.add(t.out[n]),t.out[n]=o,e._nodes.get(n).in[r]=o}if(t.undirected)for(var i in t.undirected)if(!(i>r)){var a=new Set;a.add(t.undirected[i]),t.undirected[i]=a,e._nodes.get(i).undirected[r]=a}})}Object.defineProperty(t,"__esModule",{value:!0}),t.updateStructureIndex=n,t.clearEdgeFromStructureIndex=o,t.clearStructureIndex=i,t.upgradeStructureIndexToMulti=a},function(e,t,r){"use strict";function n(e,t){for(var r in t)t[r]instanceof Set?e.push.apply(e,(0,c.consumeIterator)(t[r].size,t[r].values())):e.push(t[r])}function o(e,t,r){r in t&&(t[r]instanceof Set?e.push.apply(e,(0,c.consumeIterator)(t[r].size,t[r].values())):e.push(t[r]))}function i(e,t){if("mixed"===t)return(0,c.consumeIterator)(e._edges.size,e._edges.keys());var r=[];return e._edges.forEach(function(e,n){e instanceof p.UndirectedEdgeData==("undirected"===t)&&r.push(n)}),r}function a(e,t,r,o){var i=[],a=e._nodes.get(o);return"undirected"!==t&&("out"!==r&&n(i,a.in),"in"!==r&&n(i,a.out)),"directed"!==t&&n(i,a.undirected),i}function d(e,t,r,n){var i=[],a=e._nodes.get(r);return"undirected"!==t&&(o(i,a.in,n),o(i,a.out,n)),"directed"!==t&&o(i,a.undirected,n),i}function s(e,t){var r=t.name,n=t.type,o=t.direction;e.prototype[r]=function(e,t){if("mixed"!==n&&"mixed"!==this.type&&n!==this.type)return[];if(!arguments.length)return i(this,n);if(1===arguments.length){if(e=""+e,!this._nodes.has(e))throw new h.NotFoundGraphError("Graph."+r+': could not find the "'+e+'" node in the graph.');return a(this,n,o,e)}if(2===arguments.length){if(e=""+e,t=""+t,!this._nodes.has(e))throw new h.NotFoundGraphError("Graph."+r+': could not find the "'+e+'" source node in the graph.');if(!this._nodes.has(t))throw new h.NotFoundGraphError("Graph."+r+': could not find the "'+t+'" target node in the graph.');var s=void 0;return s="undirected"!==n?this.hasDirectedEdge(e,t):this.hasUndirectedEdge(e,t),s?d(this,n,e,t):[]}throw new h.InvalidArgumentsGraphError("Graph."+r+": too many arguments (expecting 0, 1 or 2 and got "+arguments.length+").")}}function u(e){f.forEach(function(t){s(e,t)})}Object.defineProperty(t,"__esModule",{value:!0}),t.attachEdgeIterationMethods=u;var h=r(1),p=r(2),c=r(0),f=[{name:"edges",type:"mixed"},{name:"inEdges",type:"directed",direction:"in"},{name:"outEdges",type:"directed",direction:"out"},{name:"directedEdges",type:"directed"},{name:"undirectedEdges",type:"undirected"}]},function(e,t,r){"use strict";function n(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t}function o(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}function i(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}Object.defineProperty(t,"__esModule",{value:!0});var a=function e(t){i(this,e),this.next=t};t.NodesIterator=function(e){function t(){return i(this,t),n(this,e.apply(this,arguments))}return o(t,e),t}(a)},function(e,t,r){"use strict";function n(e,t){if(t)for(var r in t)e.add(r)}function o(e,t,r,o){var i=new Set,a=e._nodes.get(o);return"undirected"!==t&&("out"!==r&&n(i,a.in),"in"!==r&&n(i,a.out)),"directed"!==t&&n(i,a.undirected),i}function i(e,t){var r=t.name,n=t.type,i=t.direction;e.prototype[r]=function(e){if("mixed"!==n&&"mixed"!==this.type&&n!==this.type)return[];if(2===arguments.length){var t=""+arguments[0],a=""+arguments[1];if(!this._nodes.has(t))throw new d.NotFoundGraphError("Graph."+r+': could not find the "'+t+'" node in the graph.');if(!this._nodes.has(a))throw new d.NotFoundGraphError("Graph."+r+': could not find the "'+a+'" node in the graph.');return o(this,n,i,t).has(a)}if(1===arguments.length){if(e=""+e,!this._nodes.has(e))throw new d.NotFoundGraphError("Graph."+r+': could not find the "'+e+'" node in the graph.');var u=o(this,n,i,e);return(0,s.consumeIterator)(u.size,u.values())}throw new d.InvalidArgumentsGraphError("Graph."+r+": invalid number of arguments (expecting 1 or 2 and got "+arguments.length+").")}}function a(e){u.forEach(function(t){i(e,t)})}Object.defineProperty(t,"__esModule",{value:!0}),t.attachNeighborIterationMethods=a;var d=r(1),s=r(0),u=[{name:"neighbors",type:"mixed"},{name:"inNeighbors",type:"directed",direction:"in"},{name:"outNeighbors",type:"directed",direction:"out"},{name:"directedNeighbors",type:"directed"},{name:"undirectedNeighbors",type:"undirected"}]},function(e,t,r){"use strict";function n(e,t){var r={key:e};return Object.keys(t.attributes).length&&(r.attributes=t.attributes),r}function o(e,t){var r={source:t.source,target:t.target};return t.generatedKey||(r.key=e),Object.keys(t.attributes).length&&(r.attributes=t.attributes),t instanceof d.UndirectedEdgeData&&(r.undirected=!0),r}function i(e){return(0,s.isPlainObject)(e)?"key"in e?"attributes"in e&&(!(0,s.isPlainObject)(e.attributes)||null===e.attributes)?"invalid-attributes":null:"no-key":"not-object"}function a(e){return(0,s.isPlainObject)(e)?"source"in e?"target"in e?"attributes"in e&&(!(0,s.isPlainObject)(e.attributes)||null===e.attributes)?"invalid-attributes":"undirected"in e&&"boolean"!=typeof e.undirected?"invalid-undirected":null:"no-target":"no-source":"not-object"}Object.defineProperty(t,"__esModule",{value:!0}),t.serializeNode=n,t.serializeEdge=o,t.validateSerializedNode=i,t.validateSerializedEdge=a;var d=r(2),s=r(0)},function(e,t){function r(){this._events=this._events||{},this._maxListeners=this._maxListeners||void 0}function n(e){return"function"==typeof e}function o(e){return"number"==typeof e}function i(e){return"object"==typeof e&&null!==e}function a(e){return void 0===e}e.exports=r,r.EventEmitter=r,r.prototype._events=void 0,r.prototype._maxListeners=void 0,r.defaultMaxListeners=10,r.prototype.setMaxListeners=function(e){if(!o(e)||e<0||isNaN(e))throw TypeError("n must be a positive number");return this._maxListeners=e,this},r.prototype.emit=function(e){var t,r,o,d,s,u;if(this._events||(this._events={}),"error"===e&&(!this._events.error||i(this._events.error)&&!this._events.error.length)){if((t=arguments[1])instanceof Error)throw t;var h=new Error('Uncaught, unspecified "error" event. ('+t+")");throw h.context=t,h}if(r=this._events[e],a(r))return!1;if(n(r))switch(arguments.length){case 1:r.call(this);break;case 2:r.call(this,arguments[1]);break;case 3:r.call(this,arguments[1],arguments[2]);break;default:d=Array.prototype.slice.call(arguments,1),r.apply(this,d)}else if(i(r))for(d=Array.prototype.slice.call(arguments,1),u=r.slice(),o=u.length,s=0;s<o;s++)u[s].apply(this,d);return!0},r.prototype.addListener=function(e,t){var o;if(!n(t))throw TypeError("listener must be a function");return this._events||(this._events={}),this._events.newListener&&this.emit("newListener",e,n(t.listener)?t.listener:t),this._events[e]?i(this._events[e])?this._events[e].push(t):this._events[e]=[this._events[e],t]:this._events[e]=t,i(this._events[e])&&!this._events[e].warned&&(o=a(this._maxListeners)?r.defaultMaxListeners:this._maxListeners)&&o>0&&this._events[e].length>o&&(this._events[e].warned=!0,console.error("(node) warning: possible EventEmitter memory leak detected. %d listeners added. Use emitter.setMaxListeners() to increase limit.",this._events[e].length),"function"==typeof console.trace&&console.trace()),this},r.prototype.on=r.prototype.addListener,r.prototype.once=function(e,t){function r(){this.removeListener(e,r),o||(o=!0,t.apply(this,arguments))}if(!n(t))throw TypeError("listener must be a function");var o=!1;return r.listener=t,this.on(e,r),this},r.prototype.removeListener=function(e,t){var r,o,a,d;if(!n(t))throw TypeError("listener must be a function");if(!this._events||!this._events[e])return this;if(r=this._events[e],a=r.length,o=-1,r===t||n(r.listener)&&r.listener===t)delete this._events[e],this._events.removeListener&&this.emit("removeListener",e,t);else if(i(r)){for(d=a;d-- >0;)if(r[d]===t||r[d].listener&&r[d].listener===t){o=d;break}if(o<0)return this;1===r.length?(r.length=0,delete this._events[e]):r.splice(o,1),this._events.removeListener&&this.emit("removeListener",e,t)}return this},r.prototype.removeAllListeners=function(e){var t,r;if(!this._events)return this;if(!this._events.removeListener)return 0===arguments.length?this._events={}:this._events[e]&&delete this._events[e],this;if(0===arguments.length){for(t in this._events)"removeListener"!==t&&this.removeAllListeners(t);return this.removeAllListeners("removeListener"),this._events={},this}if(r=this._events[e],n(r))this.removeListener(e,r);else if(r)for(;r.length;)this.removeListener(e,r[r.length-1]);return delete this._events[e],this},r.prototype.listeners=function(e){return this._events&&this._events[e]?n(this._events[e])?[this._events[e]]:this._events[e].slice():[]},r.prototype.listenerCount=function(e){if(this._events){var t=this._events[e];if(n(t))return 1;if(t)return t.length}return 0},r.listenerCount=function(e,t){return e.listenerCount(t)}}])}); | ||
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.graphology=t():e.graphology=t()}(this,function(){return function(e){function t(n){if(r[n])return r[n].exports;var i=r[n]={i:n,l:!1,exports:{}};return e[n].call(i.exports,i,i.exports,t),i.l=!0,i.exports}var r={};return t.m=e,t.c=r,t.i=function(e){return e},t.d=function(e,r,n){t.o(e,r)||Object.defineProperty(e,r,{configurable:!1,enumerable:!0,get:n})},t.n=function(e){var r=e&&e.__esModule?function(){return e.default}:function(){return e};return t.d(r,"a",r),r},t.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},t.p="",t(t.s=7)}([function(e,t,r){"use strict";function n(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function i(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t}function o(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}Object.defineProperty(t,"__esModule",{value:!0});var a=t.GraphError=function(e){function t(r,o){n(this,t);var a=i(this,e.call(this));return a.name="GraphError",a.message=r||"",a.data=o||{},a}return o(t,e),t}(Error);t.InvalidArgumentsGraphError=function(e){function t(r,o){n(this,t);var a=i(this,e.call(this,r,o));return a.name="InvalidArgumentsGraphError","function"==typeof Error.captureStackTrace&&Error.captureStackTrace(a,t.prototype.constructor),a}return o(t,e),t}(a),t.NotFoundGraphError=function(e){function t(r,o){n(this,t);var a=i(this,e.call(this,r,o));return a.name="NotFoundGraphError","function"==typeof Error.captureStackTrace&&Error.captureStackTrace(a,t.prototype.constructor),a}return o(t,e),t}(a),t.UsageGraphError=function(e){function t(r,o){n(this,t);var a=i(this,e.call(this,r,o));return a.name="UsageGraphError","function"==typeof Error.captureStackTrace&&Error.captureStackTrace(a,t.prototype.constructor),a}return o(t,e),t}(a)},function(e,t,r){"use strict";function n(){for(var e=arguments[0]||{},t=1,r=arguments.length;t<r;t++)if(arguments[t])for(var n in arguments[t])e[n]=arguments[t][n];return e}function i(e,t,r,n){var i=e._nodes.get(t);return"mixed"===n?i.out&&i.out[r]||i.undirected&&i.undirected[r]:"directed"===n?i.out&&i.out[r]:i.undirected&&i.undirected[r]}function o(e){return!!e&&"object"===(void 0===e?"undefined":f(e))&&(Array.isArray(e)||"function"==typeof Map&&e instanceof Map||"function"==typeof Set&&e instanceof Set||!(e instanceof Date)&&!(e instanceof RegExp))}function a(e){return null!==e&&"object"===(void 0===e?"undefined":f(e))&&"function"==typeof e.addUndirectedEdgeWithKey&&"function"==typeof e.dropNode}function d(e){return"object"===(void 0===e?"undefined":f(e))&&null!==e&&e.constructor===Object}function s(e,t){if(Array.isArray(e))for(var r=0,n=e.length;r<n;r++)t(e[r],null);else if("function"==typeof e.forEach)for(var i=e.entries(),o=void 0;o=i.next();){var a=o,d=a.value,s=a.done;if(s)break;var u=d[0],h=d[1];h===u?t(h,null):t(u,h)}else for(var p in e){var c=e[p];t(p,c)}}function u(e){for(var t=""+e,r="",n=0,i=t.length;n<i;n++){r=t[i-n-1]+r,(n-2)%3||n===i-1||(r=","+r)}return r}function h(e,t,r){Object.defineProperty(e,t,{enumerable:!1,configurable:!1,writable:!0,value:r})}function p(e,t,r){var n={enumerable:!0,configurable:!0};"function"==typeof r?n.get=r:(n.value=r,n.writable=!1),Object.defineProperty(e,t,n)}function c(){var e=0;return function(){return"_geid"+e+++"_"}}Object.defineProperty(t,"__esModule",{value:!0});var f="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e};t.assign=n,t.getMatchingEdge=i,t.isBunch=o,t.isGraph=a,t.isPlainObject=d,t.overBunch=s,t.prettyPrint=u,t.privateProperty=h,t.readOnlyProperty=p,t.incrementalId=c},function(e,t,r){"use strict";function n(e){this.attributes=e,this.inDegree=0,this.outDegree=0,this.undirectedDegree=0,this.directedSelfLoops=0,this.undirectedSelfLoops=0,this.in={},this.out={},this.undirected={}}function i(e){this.attributes=e||{},this.inDegree=0,this.outDegree=0,this.directedSelfLoops=0,this.in={},this.out={}}function o(e){this.attributes=e||{},this.undirectedDegree=0,this.undirectedSelfLoops=0,this.undirected={}}function a(e,t,r,n){this.attributes=n,this.source=t,this.target=r,this.generatedKey=e}function d(e,t,r,n){this.attributes=n,this.source=t,this.target=r,this.generatedKey=e}Object.defineProperty(t,"__esModule",{value:!0}),t.MixedNodeData=n,t.DirectedNodeData=i,t.UndirectedNodeData=o,t.DirectedEdgeData=a,t.UndirectedEdgeData=d,i.prototype.upgradeToMixed=function(){this.undirectedDegree=0,this.undirectedSelfLoops=0,this.undirected={}},o.prototype.upgradeToMixed=function(){this.inDegree=0,this.outDegree=0,this.directedSelfLoops=0,this.in={},this.out={}}},function(e,t){e.exports=function(e,t){for(var r,n=arguments.length>1?new Array(t):[],i=0;r=e.next(),!r.done;)n[i++]=r.value;return n}},function(e,t){function r(e){Object.defineProperty(this,"_next",{writable:!1,enumerable:!1,value:e}),this.done=!1}r.prototype.next=function(){if(this.done)return{done:!0};var e=this._next();return e.done&&(this.done=!0),e},"undefined"!=typeof Symbol&&(r.prototype[Symbol.iterator]=function(){return this}),r.of=function(e){var t=!1;return new r(function(){return t?{done:!0}:(t=!0,{value:e})})},r.empty=function(){var e=new r(null);return e.done=!0,e},r.is=function(e){return e instanceof r||"object"==typeof e&&null!==e&&"function"==typeof e.next},e.exports=r},function(e,t,r){"use strict";function n(e){return e&&e.__esModule?e:{default:e}}function i(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function o(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t}function a(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}function d(e,t,r,n,i,o,a,d){if(!n&&"undirected"===e.type)throw new l.UsageGraphError("Graph."+t+": you cannot add a directed edge to an undirected graph. Use the #.addEdge or #.addUndirectedEdge instead.");if(n&&"directed"===e.type)throw new l.UsageGraphError("Graph."+t+": you cannot add an undirected edge to a directed graph. Use the #.addEdge or #.addDirectedEdge instead.");if(d&&!(0,G.isPlainObject)(d))throw new l.InvalidArgumentsGraphError("Graph."+t+': invalid attributes. Expecting an object but got "'+d+'"');if(o=""+o,a=""+a,!e.allowSelfLoops&&o===a)throw new l.UsageGraphError("Graph."+t+': source & target are the same ("'+o+"\"), thus creating a loop explicitly forbidden by this graph 'allowSelfLoops' option set to false.");var s=e._nodes.get(o),u=e._nodes.get(a);if(!s)throw new l.NotFoundGraphError("Graph."+t+': source node "'+o+'" not found.');if(!u)throw new l.NotFoundGraphError("Graph."+t+': target node "'+a+'" not found.');if(d=(0,G.assign)({},e._options.defaultEdgeAttributes,d),r&&(i=e._edgeKeyGenerator({undirected:n,source:o,target:a,attributes:d})),i=""+i,e._edges.has(i))throw new l.UsageGraphError("Graph."+t+': the "'+i+'" edge already exists in the graph.');if(!e.multi&&(n?void 0!==s.undirected[a]:void 0!==s.out[a]))throw new l.UsageGraphError("Graph."+t+': an edge linking "'+o+'" to "'+a+"\" already exists. If you really want to add multiple edges linking those nodes, you should create a multi graph by using the 'multi' option.");var h=n?y.UndirectedEdgeData:y.DirectedEdgeData,p=new h(r,o,a,d);return e._edges.set(i,p),o===a?n?s.undirectedSelfLoops++:s.directedSelfLoops++:n?(s.undirectedDegree++,u.undirectedDegree++):(s.outDegree++,u.inDegree++),(0,v.updateStructureIndex)(e,n,i,o,a,s,u),e.emit("edgeAdded",{key:i,source:o,target:a,attributes:d,undirected:n}),i}function s(e,t,r,n,i,o,a,d){if(!n&&"undirected"===e.type)throw new l.UsageGraphError("Graph."+t+": you cannot add a directed edge to an undirected graph. Use the #.addEdge or #.addUndirectedEdge instead.");if(n&&"directed"===e.type)throw new l.UsageGraphError("Graph."+t+": you cannot add an undirected edge to a directed graph. Use the #.addEdge or #.addDirectedEdge instead.");if(d&&!(0,G.isPlainObject)(d))throw new l.InvalidArgumentsGraphError("Graph."+t+': invalid attributes. Expecting an object but got "'+d+'"');if(o=""+o,a=""+a,!e.allowSelfLoops&&o===a)throw new l.UsageGraphError("Graph."+t+': source & target are the same ("'+o+"\"), thus creating a loop explicitly forbidden by this graph 'allowSelfLoops' option set to false.");var s=e._nodes.get(o),u=e._nodes.get(a),h=null;if(!e.multi&&s&&(n?void 0!==s.undirected[a]:void 0!==s.out[a])&&(h=(0,G.getMatchingEdge)(e,o,a,n?"undirected":"directed")),h){var p=e._edges.get(h);if(p.source!==o||p.target!==a)throw new l.UsageGraphError("Graph."+t+': inconsistency detected when attempting to merge the "'+i+'" edge with "'+o+'" source & "'+a+'" target vs. ('+p.source+", "+p.target+").");return(0,G.assign)(p.attributes,d),h}if(d=(0,G.assign)({},e._options.defaultEdgeAttributes,d),r&&(i=e._edgeKeyGenerator({undirected:n,source:o,target:a,attributes:d})),i=""+i,e._edges.has(i))throw new l.UsageGraphError("Graph."+t+': the "'+i+'" edge already exists in the graph.');s||(e.addNode(o),s=e._nodes.get(o)),u||(e.addNode(a),u=e._nodes.get(a));var c=n?y.UndirectedEdgeData:y.DirectedEdgeData,f=new c(r,o,a,d);return e._edges.set(i,f),o===a?n?s.undirectedSelfLoops++:s.directedSelfLoops++:n?(s.undirectedDegree++,u.undirectedDegree++):(s.outDegree++,u.inDegree++),(0,v.updateStructureIndex)(e,n,i,o,a,s,u),e.emit("edgeAdded",{key:i,source:o,target:a,attributes:d,undirected:n}),i}function u(e,t,r,n){var i=[];if(n){if(!(0,G.isBunch)(n))throw new l.InvalidArgumentsGraphError("Graph."+t+": invalid bunch.");(0,G.overBunch)(n,function(n){if(!e.hasEdge(n))throw new l.NotFoundGraphError("Graph."+t+': could not find the "'+n+'" edge from the bunch in the graph.');r&&!r(n)||i.push(n)})}else i="exportEdges"===t?e.edges():"exportDirectedEdges"===t?e.directedEdges():e.undirectedEdges();for(var o=new Array(i.length),a=0,d=i.length;a<d;a++)o[a]=e.exportEdge(i[a]);return o}Object.defineProperty(t,"__esModule",{value:!0});var h=r(12),p=r(4),c=n(p),f=r(3),g=n(f),l=r(0),y=r(2),v=r(8),b=r(6),w=r(9),m=r(10),E=r(11),G=r(1),_=new Set(["directed","undirected","mixed"]),N=new Set(["domain","_events","_eventsCount","_maxListeners"]),A=[{name:function(e){return e+"Edge"},generateKey:!0},{name:function(e){return e+"DirectedEdge"},generateKey:!0,type:"directed"},{name:function(e){return e+"UndirectedEdge"},generateKey:!0,type:"undirected"},{name:function(e){return e+"EdgeWithKey"}},{name:function(e){return e+"DirectedEdgeWithKey"},type:"directed"},{name:function(e){return e+"UndirectedEdgeWithKey"},type:"undirected"}],x={allowSelfLoops:!0,defaultEdgeAttributes:{},defaultNodeAttributes:{},edgeKeyGenerator:null,multi:!1,type:"mixed"},D=function(e){function t(){return i(this,t),o(this,e.apply(this,arguments))}return a(t,e),t}(c.default),U=function(e){function t(r){i(this,t);var n=o(this,e.call(this));if(r=(0,G.assign)({},x,r),r.edgeKeyGenerator&&"function"!=typeof r.edgeKeyGenerator)throw new l.InvalidArgumentsGraphError("Graph.constructor: invalid 'edgeKeyGenerator' option. Expecting a function but got \""+r.edgeKeyGenerator+'".');if("boolean"!=typeof r.multi)throw new l.InvalidArgumentsGraphError("Graph.constructor: invalid 'multi' option. Expecting a boolean but got \""+r.multi+'".');if(!_.has(r.type))throw new l.InvalidArgumentsGraphError('Graph.constructor: invalid \'type\' option. Should be one of "mixed", "directed" or "undirected" but got "'+r.type+'".');if("boolean"!=typeof r.allowSelfLoops)throw new l.InvalidArgumentsGraphError("Graph.constructor: invalid 'allowSelfLoops' option. Expecting a boolean but got \""+r.allowSelfLoops+'".');if(!(0,G.isPlainObject)(r.defaultEdgeAttributes))throw new l.InvalidArgumentsGraphError("Graph.constructor: invalid 'defaultEdgeAttributes' option. Expecting a plain object but got \""+r.defaultEdgeAttributes+'".');if(!(0,G.isPlainObject)(r.defaultNodeAttributes))throw new l.InvalidArgumentsGraphError("Graph.constructor: invalid 'defaultNodeAttributes' option. Expecting a plain object but got \""+r.defaultNodeAttributes+'".');return(0,G.privateProperty)(n,"_attributes",{}),(0,G.privateProperty)(n,"_nodes",new Map),(0,G.privateProperty)(n,"_edges",new Map),(0,G.privateProperty)(n,"_edgeKeyGenerator",r.edgeKeyGenerator||(0,G.incrementalId)()),(0,G.privateProperty)(n,"_options",r),N.forEach(function(e){return(0,G.privateProperty)(n,e,n[e])}),(0,G.readOnlyProperty)(n,"order",function(){return n._nodes.size}),(0,G.readOnlyProperty)(n,"size",function(){return n._edges.size}),(0,G.readOnlyProperty)(n,"multi",n._options.multi),(0,G.readOnlyProperty)(n,"type",n._options.type),(0,G.readOnlyProperty)(n,"allowSelfLoops",n._options.allowSelfLoops),n}return a(t,e),t.prototype.hasNode=function(e){return this._nodes.has(""+e)},t.prototype.hasDirectedEdge=function(e,t){if("undirected"===this.type)return!1;if(1===arguments.length){var r=""+e,n=this._edges.get(r);return!!n&&n instanceof y.DirectedEdgeData}if(2===arguments.length){e=""+e,t=""+t;var i=this._nodes.get(e);if(!i)return!1;var o=i.out[t];return!!o&&(!this.multi||!!o.size)}throw new l.InvalidArgumentsGraphError("Graph.hasDirectedEdge: invalid arity ("+arguments.length+", instead of 1 or 2). You can either ask for an edge id or for the existence of an edge between a source & a target.")},t.prototype.hasUndirectedEdge=function(e,t){if("directed"===this.type)return!1;if(1===arguments.length){var r=""+e,n=this._edges.get(r);return!!n&&n instanceof y.UndirectedEdgeData}if(2===arguments.length){e=""+e,t=""+t;var i=this._nodes.get(e);if(!i)return!1;var o=i.undirected[t];return!!o&&(!this.multi||!!o.size)}throw new l.InvalidArgumentsGraphError("Graph.hasDirectedEdge: invalid arity ("+arguments.length+", instead of 1 or 2). You can either ask for an edge id or for the existence of an edge between a source & a target.")},t.prototype.hasEdge=function(e,t){if(1===arguments.length){var r=""+e;return this._edges.has(r)}if(2===arguments.length){e=""+e,t=""+t;var n=this._nodes.get(e);if(!n)return!1;var i=void 0!==n.out&&n.out[t];return i||(i=void 0!==n.undirected&&n.undirected[t]),!!i&&(!this.multi||!!i.size)}throw new l.InvalidArgumentsGraphError("Graph.hasEdge: invalid arity ("+arguments.length+", instead of 1 or 2). You can either ask for an edge id or for the existence of an edge between a source & a target.")},t.prototype.directedEdge=function(e,t){if("undirected"!==this.type){if(e=""+e,t=""+t,this.multi)throw new l.UsageGraphError("Graph.directedEdge: this method is irrelevant with multigraphs since there might be multiple edges between source & target. See #.directedEdges instead.");var r=this._nodes.get(e);if(!r)throw new l.NotFoundGraphError('Graph.directedEdge: could not find the "'+e+'" source node in the graph.');if(!this._nodes.has(t))throw new l.NotFoundGraphError('Graph.directedEdge: could not find the "'+t+'" target node in the graph.');return r.out&&r.out[t]||void 0}},t.prototype.undirectedEdge=function(e,t){if("directed"!==this.type){if(e=""+e,t=""+t,this.multi)throw new l.UsageGraphError("Graph.undirectedEdge: this method is irrelevant with multigraphs since there might be multiple edges between source & target. See #.undirectedEdges instead.");var r=this._nodes.get(e);if(!r)throw new l.NotFoundGraphError('Graph.undirectedEdge: could not find the "'+e+'" source node in the graph.');if(!this._nodes.has(t))throw new l.NotFoundGraphError('Graph.undirectedEdge: could not find the "'+t+'" target node in the graph.');return r.undirected&&r.undirected[t]||void 0}},t.prototype.edge=function(e,t){if(this.multi)throw new l.UsageGraphError("Graph.edge: this method is irrelevant with multigraphs since there might be multiple edges between source & target. See #.edges instead.");e=""+e,t=""+t;var r=this._nodes.get(e);if(!r)throw new l.NotFoundGraphError('Graph.edge: could not find the "'+e+'" source node in the graph.');if(!this._nodes.has(t))throw new l.NotFoundGraphError('Graph.edge: could not find the "'+t+'" target node in the graph.');return r.out&&r.out[t]||r.undirected&&r.undirected[t]||void 0},t.prototype.inDegree=function(e){var t=!(arguments.length>1&&void 0!==arguments[1])||arguments[1];if("boolean"!=typeof t)throw new l.InvalidArgumentsGraphError('Graph.inDegree: Expecting a boolean but got "'+t+'" for the second parameter (allowing self-loops to be counted).');e=""+e;var r=this._nodes.get(e);if(!r)throw new l.NotFoundGraphError('Graph.inDegree: could not find the "'+e+'" node in the graph.');if("undirected"===this.type)return 0;var n=t?r.directedSelfLoops:0;return r.inDegree+n},t.prototype.outDegree=function(e){var t=!(arguments.length>1&&void 0!==arguments[1])||arguments[1];if("boolean"!=typeof t)throw new l.InvalidArgumentsGraphError('Graph.outDegree: Expecting a boolean but got "'+t+'" for the second parameter (allowing self-loops to be counted).');e=""+e;var r=this._nodes.get(e);if(!r)throw new l.NotFoundGraphError('Graph.outDegree: could not find the "'+e+'" node in the graph.');if("undirected"===this.type)return 0;var n=t?r.directedSelfLoops:0;return r.outDegree+n},t.prototype.directedDegree=function(e){var t=!(arguments.length>1&&void 0!==arguments[1])||arguments[1];if("boolean"!=typeof t)throw new l.InvalidArgumentsGraphError('Graph.directedDegree: Expecting a boolean but got "'+t+'" for the second parameter (allowing self-loops to be counted).');if(e=""+e,!this.hasNode(e))throw new l.NotFoundGraphError('Graph.directedDegree: could not find the "'+e+'" node in the graph.');return"undirected"===this.type?0:this.inDegree(e,t)+this.outDegree(e,t)},t.prototype.undirectedDegree=function(e){var t=!(arguments.length>1&&void 0!==arguments[1])||arguments[1];if("boolean"!=typeof t)throw new l.InvalidArgumentsGraphError('Graph.undirectedDegree: Expecting a boolean but got "'+t+'" for the second parameter (allowing self-loops to be counted).');if(e=""+e,!this.hasNode(e))throw new l.NotFoundGraphError('Graph.undirectedDegree: could not find the "'+e+'" node in the graph.');if("directed"===this.type)return 0;var r=this._nodes.get(e),n=t?2*r.undirectedSelfLoops:0;return r.undirectedDegree+n},t.prototype.degree=function(e){var t=!(arguments.length>1&&void 0!==arguments[1])||arguments[1];if("boolean"!=typeof t)throw new l.InvalidArgumentsGraphError('Graph.degree: Expecting a boolean but got "'+t+'" for the second parameter (allowing self-loops to be counted).');if(e=""+e,!this.hasNode(e))throw new l.NotFoundGraphError('Graph.degree: could not find the "'+e+'" node in the graph.');var r=0;return"undirected"!==this.type&&(r+=this.directedDegree(e,t)),"directed"!==this.type&&(r+=this.undirectedDegree(e,t)),r},t.prototype.source=function(e){e=""+e;var t=this._edges.get(e);if(!t)throw new l.NotFoundGraphError('Graph.source: could not find the "'+e+'" edge in the graph.');return t.source},t.prototype.target=function(e){e=""+e;var t=this._edges.get(e);if(!t)throw new l.NotFoundGraphError('Graph.target: could not find the "'+e+'" edge in the graph.');return t.target},t.prototype.extremities=function(e){e=""+e;var t=this._edges.get(e);if(!t)throw new l.NotFoundGraphError('Graph.extremities: could not find the "'+e+'" edge in the graph.');return[t.source,t.target]},t.prototype.opposite=function(e,t){if(e=""+e,t=""+t,!this._nodes.has(e))throw new l.NotFoundGraphError('Graph.opposite: could not find the "'+e+'" node in the graph.');var r=this._edges.get(t);if(!r)throw new l.NotFoundGraphError('Graph.opposite: could not find the "'+t+'" edge in the graph.');var n=r.source,i=r.target;if(e!==n&&e!==i)throw new l.NotFoundGraphError('Graph.opposite: the "'+e+'" node is not attached to the "'+t+'" edge ('+n+", "+i+").");return e===n?i:n},t.prototype.undirected=function(e){e=""+e;var t=this._edges.get(e);if(!t)throw new l.NotFoundGraphError('Graph.undirected: could not find the "'+e+'" edge in the graph.');return t instanceof y.UndirectedEdgeData},t.prototype.directed=function(e){e=""+e;var t=this._edges.get(e);if(!t)throw new l.NotFoundGraphError('Graph.directed: could not find the "'+e+'" edge in the graph.');return t instanceof y.DirectedEdgeData},t.prototype.selfLoop=function(e){e=""+e;var t=this._edges.get(e);if(!t)throw new l.NotFoundGraphError('Graph.selfLoop: could not find the "'+e+'" edge in the graph.');return t.source===t.target},t.prototype.addNode=function(e,t){if(t&&!(0,G.isPlainObject)(t))throw new l.InvalidArgumentsGraphError('Graph.addNode: invalid attributes. Expecting an object but got "'+t+'"');if(e=""+e,this._nodes.has(e))throw new l.UsageGraphError('Graph.addNode: the "'+e+'" node already exist in the graph.');t=(0,G.assign)({},this._options.defaultNodeAttributes,t);var r="mixed"===this.type?y.MixedNodeData:"directed"===this.type?y.DirectedNodeData:y.UndirectedNodeData,n=new r(t);return this._nodes.set(e,n),this.emit("nodeAdded",{key:e,attributes:t}),e},t.prototype.mergeNode=function(e,t){var r=this._nodes.get(e);return r?(t&&(0,G.assign)(r.attributes,t),e):this.addNode(e,t)},t.prototype.addNodesFrom=function(e){var t=this;if(!(0,G.isBunch)(e))throw new l.InvalidArgumentsGraphError('Graph.addNodesFrom: invalid bunch provided ("'+e+'").');return(0,G.overBunch)(e,function(e,r){t.addNode(e,r)}),this},t.prototype.dropNode=function(e){if(e=""+e,!this.hasNode(e))throw new l.NotFoundGraphError('Graph.dropNode: could not find the "'+e+'" node in the graph.');for(var t=this.edges(e),r=0,n=t.length;r<n;r++)this.dropEdge(t[r]);var i=this._nodes.get(e);this._nodes.delete(e),this.emit("nodeDropped",{key:e,attributes:i.attributes})},t.prototype.dropEdge=function(e){if(arguments.length>1){var t=""+arguments[0],r=""+arguments[1];if(!this.hasNode(t))throw new l.NotFoundGraphError('Graph.dropEdge: could not find the "'+t+'" source node in the graph.');if(!this.hasNode(r))throw new l.NotFoundGraphError('Graph.dropEdge: could not find the "'+r+'" target node in the graph.');if(!this.hasEdge(t,r))throw new l.NotFoundGraphError('Graph.dropEdge: could not find the "'+t+'" -> "'+r+'" edge in the graph.');e=(0,G.getMatchingEdge)(this,t,r,this.type)}else if(e=""+e,!this.hasEdge(e))throw new l.NotFoundGraphError('Graph.dropEdge: could not find the "'+e+'" edge in the graph.');var n=this._edges.get(e);this._edges.delete(e);var i=n.source,o=n.target,a=n.attributes,d=n instanceof y.UndirectedEdgeData,s=this._nodes.get(i),u=this._nodes.get(o);return i===o?s.selfLoops--:d?(s.undirectedDegree--,u.undirectedDegree--):(s.outDegree--,u.inDegree--),(0,v.clearEdgeFromStructureIndex)(this,d,e,n),this.emit("edgeDropped",{key:e,attributes:a,source:i,target:o,undirected:d}),this},t.prototype.dropNodes=function(e){var t=this;if(!arguments.length)return this.clear();if(!(0,G.isBunch)(e))throw new l.InvalidArgumentsGraphError("Graph.dropNodes: invalid bunch.");return(0,G.overBunch)(e,function(e){t.dropNode(e)}),this},t.prototype.dropEdges=function(e){var t=this;if(!arguments.length)return this._edges.clear(),this.clearIndex(),this;if(2===arguments.length){var r=arguments[0],n=arguments[1];e=this.edges(r,n)}if(!(0,G.isBunch)(e))throw new l.InvalidArgumentsGraphError("Graph.dropEdges: invalid bunch.");return(0,G.overBunch)(e,function(e){t.dropEdge(e)}),this},t.prototype.clear=function(){this._edges.clear(),this._nodes.clear();for(var e in this._indices){var t=this._indices[e];t.lazy&&(t.computed=!1)}this.emit("cleared")},t.prototype.getAttribute=function(e){return this._attributes[e]},t.prototype.getAttributes=function(){return this._attributes},t.prototype.hasAttribute=function(e){return this._attributes.hasOwnProperty(e)},t.prototype.setAttribute=function(e,t){return this._attributes[e]=t,this.emit("attributesUpdated",{type:"set",meta:{name:e,value:t}}),this},t.prototype.updateAttribute=function(e,t){if("function"!=typeof t)throw new l.InvalidArgumentsGraphError("Graph.updateAttribute: updater should be a function.");return this._attributes[e]=t(this._attributes[e]),this.emit("attributesUpdated",{type:"set",meta:{name:e,value:this._attributes[e]}}),this},t.prototype.removeAttribute=function(e){return delete this._attributes[e],this.emit("attributesUpdated",{type:"remove",meta:{name:e}}),this},t.prototype.replaceAttributes=function(e){if(!(0,G.isPlainObject)(e))throw new l.InvalidArgumentsGraphError("Graph.replaceAttributes: provided attributes are not a plain object.");var t=this._attributes;return this._attributes=e,this.emit("attributesUpdated",{type:"replace",meta:{before:t,after:e}}),this},t.prototype.mergeAttributes=function(e){if(!(0,G.isPlainObject)(e))throw new l.InvalidArgumentsGraphError("Graph.mergeAttributes: provided attributes are not a plain object.");return this._attributes=(0,G.assign)(this._attributes,e),this.emit("attributesUpdated",{type:"merge",meta:{data:this._attributes}}),this},t.prototype.getNodeAttribute=function(e,t){if(e=""+e,!this.hasNode(e))throw new l.NotFoundGraphError('Graph.getNodeAttribute: could not find the "'+e+'" node in the graph.');return this._nodes.get(e).attributes[t]},t.prototype.getNodeAttributes=function(e){if(e=""+e,!this.hasNode(e))throw new l.NotFoundGraphError('Graph.getNodeAttributes: could not find the "'+e+'" node in the graph.');return this._nodes.get(e).attributes},t.prototype.hasNodeAttribute=function(e,t){if(e=""+e,!this.hasNode(e))throw new l.NotFoundGraphError('Graph.hasNodeAttribute: could not find the "'+e+'" node in the graph.');return this._nodes.get(e).attributes.hasOwnProperty(t)},t.prototype.setNodeAttribute=function(e,t,r){if(e=""+e,!this.hasNode(e))throw new l.NotFoundGraphError('Graph.setNodeAttribute: could not find the "'+e+'" node in the graph.');if(arguments.length<3)throw new l.InvalidArgumentsGraphError("Graph.setNodeAttribute: not enough arguments. Either you forgot to pass the attribute's name or value, or you meant to use #.replaceNodeAttributes / #.mergeNodeAttributes instead.");return this._nodes.get(e).attributes[t]=r,this.emit("nodeAttributesUpdated",{key:e,type:"set",meta:{name:t,value:r}}),this},t.prototype.updateNodeAttribute=function(e,t,r){if(e=""+e,!this.hasNode(e))throw new l.NotFoundGraphError('Graph.updateNodeAttribute: could not find the "'+e+'" node in the graph.');if(arguments.length<3)throw new l.InvalidArgumentsGraphError("Graph.updateNodeAttribute: not enough arguments. Either you forgot to pass the attribute's name or updater, or you meant to use #.replaceNodeAttributes / #.mergeNodeAttributes instead.");if("function"!=typeof r)throw new l.InvalidArgumentsGraphError("Graph.updateAttribute: updater should be a function.");var n=this._nodes.get(e).attributes;return n[t]=r(n[t]),this.emit("nodeAttributesUpdated",{key:e,type:"set",meta:{name:t,value:n[t]}}),this},t.prototype.removeNodeAttribute=function(e,t){if(e=""+e,!this.hasNode(e))throw new l.NotFoundGraphError('Graph.hasNodeAttribute: could not find the "'+e+'" node in the graph.');return delete this._nodes.get(e).attributes[t],this.emit("nodeAttributesUpdated",{key:e,type:"remove",meta:{name:t}}),this},t.prototype.replaceNodeAttributes=function(e,t){if(e=""+e,!this.hasNode(e))throw new l.NotFoundGraphError('Graph.replaceNodeAttributes: could not find the "'+e+'" node in the graph.');if(!(0,G.isPlainObject)(t))throw new l.InvalidArgumentsGraphError("Graph.replaceNodeAttributes: provided attributes are not a plain object.");var r=this._nodes.get(e),n=r.attributes;return r.attributes=t,this.emit("nodeAttributesUpdated",{key:e,type:"replace",meta:{before:n,after:t}}),this},t.prototype.mergeNodeAttributes=function(e,t){if(e=""+e,!this.hasNode(e))throw new l.NotFoundGraphError('Graph.mergeNodeAttributes: could not find the "'+e+'" node in the graph.');if(!(0,G.isPlainObject)(t))throw new l.InvalidArgumentsGraphError("Graph.mergeNodeAttributes: provided attributes are not a plain object.");var r=this._nodes.get(e);return(0,G.assign)(r.attributes,t),this.emit("nodeAttributesUpdated",{key:e,type:"merge",meta:{data:t}}),this},t.prototype.nodes=function(){return(0,g.default)(this._nodes.keys(),this._nodes.size)},t.prototype.nodesIterator=function(){var e=this._nodes.keys();return new D(e.next.bind(e))},t.prototype.exportNode=function(e){e=""+e;var t=this._nodes.get(e);if(!t)throw new l.NotFoundGraphError('Graph.exportNode: could not find the "'+e+'" node in the graph.');return(0,E.serializeNode)(e,t)},t.prototype.exportEdge=function(e){e=""+e;var t=this._edges.get(e);if(!t)throw new l.NotFoundGraphError('Graph.exportEdge: could not find the "'+e+'" edge in the graph.');return(0,E.serializeEdge)(e,t)},t.prototype.exportNodes=function(e){var t=this,r=[];if(arguments.length){if(!(0,G.isBunch)(e))throw new l.InvalidArgumentsGraphError("Graph.exportNodes: invalid bunch.");(0,G.overBunch)(e,function(e){if(!t.hasNode(e))throw new l.NotFoundGraphError('Graph.exportNodes: could not find the "'+e+'" node from the bunch in the graph.');r.push(e)})}else r=this.nodes();for(var n=new Array(r.length),i=0,o=r.length;i<o;i++)n[i]=this.exportNode(r[i]);return n},t.prototype.exportEdges=function(e){return u(this,"exportEdges",null,e)},t.prototype.exportDirectedEdges=function(e){var t=this;return u(this,"exportDirectedEdges",function(e){return t.directed(e)},e)},t.prototype.exportUndirectedEdges=function(e){var t=this;return u(this,"exportUndirectedEdges",function(e){return t.undirected(e)},e)},t.prototype.export=function(){return{attributes:this.getAttributes(),nodes:this.exportNodes(),edges:this.exportEdges()}},t.prototype.importNode=function(e){var t=arguments.length>1&&void 0!==arguments[1]&&arguments[1],r=(0,E.validateSerializedNode)(e);if(r){if("not-object"===r)throw new l.InvalidArgumentsGraphError('Graph.importNode: invalid serialized node. A serialized node should be a plain object with at least a "key" property.');if("no-key"===r)throw new l.InvalidArgumentsGraphError("Graph.importNode: no key provided.");if("invalid-attributes"===r)throw new l.InvalidArgumentsGraphError("Graph.importNode: invalid attributes. Attributes should be a plain object, null or omitted.")}var n=e.key,i=e.attributes,o=void 0===i?{}:i;return t?this.mergeNode(n,o):this.addNode(n,o),this},t.prototype.importEdge=function(e){var t=arguments.length>1&&void 0!==arguments[1]&&arguments[1],r=(0,E.validateSerializedEdge)(e);if(r){if("not-object"===r)throw new l.InvalidArgumentsGraphError('Graph.importEdge: invalid serialized edge. A serialized edge should be a plain object with at least a "source" & "target" property.');if("no-source"===r)throw new l.InvalidArgumentsGraphError("Graph.importEdge: missing souce.");if("no-target"===r)throw new l.InvalidArgumentsGraphError("Graph.importEdge: missing target.");if("invalid-attributes"===r)throw new l.InvalidArgumentsGraphError("Graph.importEdge: invalid attributes. Attributes should be a plain object, null or omitted.");if("invalid-undirected"===r)throw new l.InvalidArgumentsGraphError("Graph.importEdge: invalid undirected. Undirected should be boolean or omitted.")}var n=e.source,i=e.target,o=e.attributes,a=void 0===o?{}:o,d=e.undirected,s=void 0!==d&&d,u=void 0;return"key"in e?(u=t?s?this.mergeUndirectedEdgeWithKey:this.mergeDirectedEdgeWithKey:s?this.addUndirectedEdgeWithKey:this.addDirectedEdgeWithKey,u.call(this,e.key,n,i,a)):(u=t?s?this.mergeUndirectedEdge:this.mergeDirectedEdge:s?this.addUndirectedEdge:this.addDirectedEdge,u.call(this,n,i,a)),this},t.prototype.importNodes=function(e){var t=arguments.length>1&&void 0!==arguments[1]&&arguments[1];if(!Array.isArray(e))throw new l.InvalidArgumentsGraphError("Graph.importNodes: invalid argument. Expecting an array.");for(var r=0,n=e.length;r<n;r++)this.importNode(e[r],t);return this},t.prototype.importEdges=function(e){var t=arguments.length>1&&void 0!==arguments[1]&&arguments[1];if(!Array.isArray(e))throw new l.InvalidArgumentsGraphError("Graph.importEdges: invalid argument. Expecting an array.");for(var r=0,n=e.length;r<n;r++)this.importEdge(e[r],t);return this},t.prototype.import=function(e){var t=arguments.length>1&&void 0!==arguments[1]&&arguments[1];if((0,G.isGraph)(e))return this.import(e.export(),t),this;if(!(0,G.isPlainObject)(e))throw new l.InvalidArgumentsGraphError("Graph.import: invalid argument. Expecting a serialized graph or, alternatively, a Graph instance.");if(e.attributes){if(!(0,G.isPlainObject)(e.attributes))throw new l.InvalidArgumentsGraphError("Graph.import: invalid attributes. Expecting a plain object.");t?this.mergeAttributes(e.attributes):this.replaceAttributes(e.attributes)}return e.nodes&&this.importNodes(e.nodes,t),e.edges&&this.importEdges(e.edges,t),this},t.prototype.emptyCopy=function(){return new t(this._options)},t.prototype.copy=function(){var e=new t(this._options);return e.import(this),e},t.prototype.upgradeToMixed=function(){return"mixed"===this.type?this:(this._nodes.forEach(function(e){return e.upgradeToMixed()}),this._options.type="mixed",(0,G.readOnlyProperty)(this,"type",this._options.type),this)},t.prototype.upgradeToMulti=function(){return this.multi?this:(this._options.multi=!0,(0,G.readOnlyProperty)(this,"multi",!0),(0,v.upgradeStructureIndexToMulti)(this),this)},t.prototype.clearIndex=function(){return(0,v.clearStructureIndex)(this),this},t.prototype.toJSON=function(){return this.export()},t.prototype.toString=function(){var e=this.order>1||0===this.order,t=this.size>1||0===this.size;return"Graph<"+(0,G.prettyPrint)(this.order)+" node"+(e?"s":"")+", "+(0,G.prettyPrint)(this.size)+" edge"+(t?"s":"")+">"},t.prototype.inspect=function(){var e={};this._nodes.forEach(function(t,r){e[r]=t.attributes});var t={};this._edges.forEach(function(e,r){var n=e instanceof y.UndirectedEdgeData?"--":"->",i="";e.generatedKey||(i+="["+r+"]: "),i+="("+e.source+")"+n+"("+e.target+")",t[i]=e.attributes});var r={};for(var n in this)this.hasOwnProperty(n)&&!N.has(n)&&"function"!=typeof this[n]&&(r[n]=this[n]);return r.attributes=this._attributes,r.nodes=e,r.edges=t,(0,G.privateProperty)(r,"constructor",this.constructor),r},t}(h.EventEmitter);t.default=U,A.forEach(function(e){["add","merge"].forEach(function(t){var r=e.name(t),n="add"===t?d:s;e.generateKey?U.prototype[r]=function(t,i,o){return n(this,r,e.generateKey,"undirected"===(e.type||this.type),null,t,i,o)}:U.prototype[r]=function(t,i,o,a){return n(this,r,e.generateKey,"undirected"===(e.type||this.type),t,i,o,a)}})}),(0,b.attachAttributesMethods)(U),(0,w.attachEdgeIterationMethods)(U),(0,m.attachNeighborIterationMethods)(U)},function(e,t,r){"use strict";function n(e,t,r,n){e.prototype[t]=function(e,i){if(arguments.length>2){if(this.multi)throw new f.UsageGraphError("Graph."+t+": cannot use a {source,target} combo when asking about an edge's attributes in a MultiGraph since we cannot infer the one you want information about.");var o=""+e,a=""+i;if(i=arguments[2],!this[r](o,a))throw new f.NotFoundGraphError("Graph."+t+': could not find an edge for the given path ("'+o+'" - "'+a+'").');e=(0,c.getMatchingEdge)(this,o,a,n)}else e=""+e;if(!this[r](e))throw new f.NotFoundGraphError("Graph."+t+': could not find the "'+e+'" edge in the graph.');return this._edges.get(e).attributes[i]}}function i(e,t,r,n){e.prototype[t]=function(e){if(arguments.length>1){if(this.multi)throw new f.UsageGraphError("Graph."+t+": cannot use a {source,target} combo when asking about an edge's attributes in a MultiGraph since we cannot infer the one you want information about.");var i=""+e,o=""+arguments[1];if(!this[r](i,o))throw new f.NotFoundGraphError("Graph."+t+': could not find an edge for the given path ("'+i+'" - "'+o+'").');e=(0,c.getMatchingEdge)(this,i,o,n)}else e=""+e;if(!this[r](e))throw new f.NotFoundGraphError("Graph."+t+': could not find the "'+e+'" edge in the graph.');return this._edges.get(e).attributes}}function o(e,t,r,n){e.prototype[t]=function(e,i){if(arguments.length>2){if(this.multi)throw new f.UsageGraphError("Graph."+t+": cannot use a {source,target} combo when asking about an edge's attributes in a MultiGraph since we cannot infer the one you want information about.");var o=""+e,a=""+i;if(i=arguments[2],!this[r](o,a))throw new f.NotFoundGraphError("Graph."+t+': could not find an edge for the given path ("'+o+'" - "'+a+'").');e=(0,c.getMatchingEdge)(this,o,a,n)}else e=""+e;if(!this[r](e))throw new f.NotFoundGraphError("Graph."+t+': could not find the "'+e+'" edge in the graph.');return this._edges.get(e).attributes.hasOwnProperty(i)}}function a(e,t,r,n){e.prototype[t]=function(e,i,o){if(arguments.length>3){if(this.multi)throw new f.UsageGraphError("Graph."+t+": cannot use a {source,target} combo when asking about an edge's attributes in a MultiGraph since we cannot infer the one you want information about.");var a=""+e,d=""+i;if(i=arguments[2],o=arguments[3],!this[r](a,d))throw new f.NotFoundGraphError("Graph."+t+': could not find an edge for the given path ("'+a+'" - "'+d+'").');e=(0,c.getMatchingEdge)(this,a,d,n)}else e=""+e;if(!this[r](e))throw new f.NotFoundGraphError("Graph."+t+': could not find the "'+e+'" edge in the graph.');return this._edges.get(e).attributes[i]=o,this.emit("edgeAttributesUpdated",{key:e,type:"set",meta:{name:i,value:o}}),this}}function d(e,t,r,n){e.prototype[t]=function(e,i,o){if(arguments.length>3){if(this.multi)throw new f.UsageGraphError("Graph."+t+": cannot use a {source,target} combo when asking about an edge's attributes in a MultiGraph since we cannot infer the one you want information about.");var a=""+e,d=""+i;if(i=arguments[2],o=arguments[3],!this[r](a,d))throw new f.NotFoundGraphError("Graph."+t+': could not find an edge for the given path ("'+a+'" - "'+d+'").');e=(0,c.getMatchingEdge)(this,a,d,n)}else e=""+e;if(!this[r](e))throw new f.NotFoundGraphError("Graph."+t+': could not find the "'+e+'" edge in the graph.');if("function"!=typeof o)throw new f.InvalidArgumentsGraphError("Graph."+t+": updater should be a function.");var s=this._edges.get(e);return s.attributes[i]=o(s.attributes[i]),this.emit("edgeAttributesUpdated",{key:e,type:"set",meta:{name:i,value:s.attributes[i]}}),this}}function s(e,t,r,n){e.prototype[t]=function(e,i){if(arguments.length>2){if(this.multi)throw new f.UsageGraphError("Graph."+t+": cannot use a {source,target} combo when asking about an edge's attributes in a MultiGraph since we cannot infer the one you want information about.");var o=""+e,a=""+i;if(i=arguments[2],!this[r](o,a))throw new f.NotFoundGraphError("Graph."+t+': could not find an edge for the given path ("'+o+'" - "'+a+'").');e=(0,c.getMatchingEdge)(this,o,a,n)}else e=""+e;if(!this[r](e))throw new f.NotFoundGraphError("Graph."+t+': could not find the "'+e+'" edge in the graph.');return delete this._edges.get(e).attributes[i],this.emit("edgeAttributesUpdated",{key:e,type:"remove",meta:{name:i}}),this}}function u(e,t,r,n){e.prototype[t]=function(e,i){if(arguments.length>2){if(this.multi)throw new f.UsageGraphError("Graph."+t+": cannot use a {source,target} combo when asking about an edge's attributes in a MultiGraph since we cannot infer the one you want information about.");var o=""+e,a=""+i;if(i=arguments[2],!this[r](o,a))throw new f.NotFoundGraphError("Graph."+t+': could not find an edge for the given path ("'+o+'" - "'+a+'").');e=(0,c.getMatchingEdge)(this,o,a,n)}else e=""+e;if(!this[r](e))throw new f.NotFoundGraphError("Graph."+t+': could not find the "'+e+'" edge in the graph.');if(!(0,c.isPlainObject)(i))throw new f.InvalidArgumentsGraphError("Graph."+t+": provided attributes are not a plain object.");var d=this._edges.get(e),s=d.attributes;return d.attributes=i,this.emit("edgeAttributesUpdated",{key:e,type:"replace",meta:{before:s,after:i}}),this}}function h(e,t,r,n){e.prototype[t]=function(e,i){if(arguments.length>2){if(this.multi)throw new f.UsageGraphError("Graph."+t+": cannot use a {source,target} combo when asking about an edge's attributes in a MultiGraph since we cannot infer the one you want information about.");var o=""+e,a=""+i;if(i=arguments[2],!this[r](o,a))throw new f.NotFoundGraphError("Graph."+t+': could not find an edge for the given path ("'+o+'" - "'+a+'").');e=(0,c.getMatchingEdge)(this,o,a,n)}else e=""+e;if(!this[r](e))throw new f.NotFoundGraphError("Graph."+t+': could not find the "'+e+'" edge in the graph.');if(!(0,c.isPlainObject)(i))throw new f.InvalidArgumentsGraphError("Graph."+t+": provided attributes are not a plain object.");var d=this._edges.get(e);return(0,c.assign)(d.attributes,i),this.emit("edgeAttributesUpdated",{key:e,type:"merge",meta:{data:i}}),this}}function p(e){g.forEach(function(t){var r=t.name,n=t.attacher;n(e,r("Edge"),"hasEdge","mixed"),n(e,r("DirectedEdge"),"hasDirectedEdge","directed"),n(e,r("UndirectedEdge"),"hasUndirectedEdge","undirected")})}Object.defineProperty(t,"__esModule",{value:!0}),t.attachAttributesMethods=p;var c=r(1),f=r(0),g=[{name:function(e){return"get"+e+"Attribute"},attacher:n},{name:function(e){return"get"+e+"Attributes"},attacher:i},{name:function(e){return"has"+e+"Attribute"},attacher:o},{name:function(e){return"set"+e+"Attribute"},attacher:a},{name:function(e){return"update"+e+"Attribute"},attacher:d},{name:function(e){return"remove"+e+"Attribute"},attacher:s},{name:function(e){return"replace"+e+"Attributes"},attacher:u},{name:function(e){return"merge"+e+"Attributes"},attacher:h}]},function(e,t,r){"use strict";function n(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function i(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t}function o(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}function a(e){e.from=function(t,r){var n=new e(r);return n.import(t),n}}var d=r(1),s=r(5),u=function(e){return e&&e.__esModule?e:{default:e}}(s),h=r(0),p=function(e){function t(r){return n(this,t),i(this,e.call(this,(0,d.assign)({type:"directed"},r)))}return o(t,e),t}(u.default),c=function(e){function t(r){return n(this,t),i(this,e.call(this,(0,d.assign)({type:"undirected"},r)))}return o(t,e),t}(u.default),f=function(e){function t(r){return n(this,t),i(this,e.call(this,(0,d.assign)({multi:!0,type:"directed"},r)))}return o(t,e),t}(u.default),g=function(e){function t(r){return n(this,t),i(this,e.call(this,(0,d.assign)({multi:!0,type:"undirected"},r)))}return o(t,e),t}(u.default);a(u.default),a(p),a(c),a(f),a(g),u.default.Graph=u.default,u.default.DirectedGraph=p,u.default.UndirectedGraph=c,u.default.MultiDirectedGraph=f,u.default.MultiUndirectedGraph=g,u.default.InvalidArgumentsGraphError=h.InvalidArgumentsGraphError,u.default.NotFoundGraphError=h.NotFoundGraphError,u.default.UsageGraphError=h.UsageGraphError,e.exports=u.default},function(e,t,r){"use strict";function n(e,t,r,n,i,o,a){var d=e.multi,s=t?"undirected":"out",u=t?"undirected":"in";void 0===o[s][i]&&(o[s][i]=d?new Set:r),d&&o[s][i].add(r),n!==i&&void 0===a[u][n]&&(a[u][n]=o[s][i])}function i(e,t,r,n){var i=e.multi,o=n.source,a=n.target,d=e._nodes.get(o),s=t?"undirected":"out",u=d[s];if(a in u&&(i?u[a].delete(r):delete u[a]),!i){delete e._nodes.get(a)[t?"undirected":"in"][o]}}function o(e){e._nodes.forEach(function(e){e.in={},e.out={},e.undirected={}})}function a(e){e._nodes.forEach(function(t,r){if(t.out)for(var n in t.out){var i=new Set;i.add(t.out[n]),t.out[n]=i,e._nodes.get(n).in[r]=i}if(t.undirected)for(var o in t.undirected)if(!(o>r)){var a=new Set;a.add(t.undirected[o]),t.undirected[o]=a,e._nodes.get(o).undirected[r]=a}})}Object.defineProperty(t,"__esModule",{value:!0}),t.updateStructureIndex=n,t.clearEdgeFromStructureIndex=i,t.clearStructureIndex=o,t.upgradeStructureIndexToMulti=a},function(e,t,r){"use strict";function n(e){return e&&e.__esModule?e:{default:e}}function i(e,t){for(var r in t)t[r]instanceof Set?e.push.apply(e,(0,y.default)(t[r].values(),t[r].size)):e.push(t[r])}function o(e,t,r){r in t&&(t[r]instanceof Set?e.push.apply(e,(0,y.default)(t[r].values(),t[r].size)):e.push(t[r]))}function a(e,t){if(0===e.size)return[];if("mixed"===t)return(0,y.default)(e._edges.keys(),e._edges.size);var r=[];return e._edges.forEach(function(e,n){e instanceof b.UndirectedEdgeData==("undirected"===t)&&r.push(n)}),r}function d(e,t){if(0===e.size)return g.default.empty();var r=void 0;return"mixed"===t?(r=e._edges.keys(),new g.default(r.next.bind(r))):(r=e._edges.entries(),new g.default(function e(){var n=r.next();return n.done?n:n.value[1]instanceof b.UndirectedEdgeData==("undirected"===t)?{value:n.value[0]}:e()}))}function s(e,t,r,n){var o=[],a=e._nodes.get(n);return"undirected"!==t&&("out"!==r&&i(o,a.in),"in"!==r&&i(o,a.out)),"directed"!==t&&i(o,a.undirected),o}function u(e,t,r,n){var i=[],a=e._nodes.get(r);return"undirected"!==t&&(o(i,a.in,n),o(i,a.out,n)),"directed"!==t&&o(i,a.undirected,n),i}function h(e,t){var r=t.name,n=t.type,i=t.direction;e.prototype[r]=function(e,t){if("mixed"!==n&&"mixed"!==this.type&&n!==this.type)return[];if(!arguments.length)return a(this,n);if(1===arguments.length){if(e=""+e,!this._nodes.has(e))throw new v.NotFoundGraphError("Graph."+r+': could not find the "'+e+'" node in the graph.');return s(this,n,i,e)}if(2===arguments.length){if(e=""+e,t=""+t,!this._nodes.has(e))throw new v.NotFoundGraphError("Graph."+r+': could not find the "'+e+'" source node in the graph.');if(!this._nodes.has(t))throw new v.NotFoundGraphError("Graph."+r+': could not find the "'+t+'" target node in the graph.');var o=void 0;return o="undirected"!==n?this.hasDirectedEdge(e,t):this.hasUndirectedEdge(e,t),o?u(this,n,e,t):[]}throw new v.InvalidArgumentsGraphError("Graph."+r+": too many arguments (expecting 0, 1 or 2 and got "+arguments.length+").")}}function p(e,t){var r=t.name,n=t.type,i=r+"Iterator";e.prototype[i]=function(){return"mixed"!==n&&"mixed"!==this.type&&n!==this.type?g.default.empty():arguments.length?void 0:d(this,n)}}function c(e){w.forEach(function(t){h(e,t),p(e,t)})}Object.defineProperty(t,"__esModule",{value:!0}),t.attachEdgeIteratorCreator=p,t.attachEdgeIterationMethods=c;var f=r(4),g=n(f),l=r(3),y=n(l),v=r(0),b=r(2),w=[{name:"edges",type:"mixed"},{name:"inEdges",type:"directed",direction:"in"},{name:"outEdges",type:"directed",direction:"out"},{name:"directedEdges",type:"directed"},{name:"undirectedEdges",type:"undirected"}]},function(e,t,r){"use strict";function n(e,t){if(t)for(var r in t)e.add(r)}function i(e,t,r,i){var o=new Set,a=e._nodes.get(i);return"undirected"!==t&&("out"!==r&&n(o,a.in),"in"!==r&&n(o,a.out)),"directed"!==t&&n(o,a.undirected),o}function o(e,t){var r=t.name,n=t.type,o=t.direction;e.prototype[r]=function(e){if("mixed"!==n&&"mixed"!==this.type&&n!==this.type)return[];if(2===arguments.length){var t=""+arguments[0],a=""+arguments[1];if(!this._nodes.has(t))throw new u.NotFoundGraphError("Graph."+r+': could not find the "'+t+'" node in the graph.');if(!this._nodes.has(a))throw new u.NotFoundGraphError("Graph."+r+': could not find the "'+a+'" node in the graph.');return i(this,n,o,t).has(a)}if(1===arguments.length){if(e=""+e,!this._nodes.has(e))throw new u.NotFoundGraphError("Graph."+r+': could not find the "'+e+'" node in the graph.');var d=i(this,n,o,e);return(0,s.default)(d.values(),d.size)}throw new u.InvalidArgumentsGraphError("Graph."+r+": invalid number of arguments (expecting 1 or 2 and got "+arguments.length+").")}}function a(e){h.forEach(function(t){o(e,t)})}Object.defineProperty(t,"__esModule",{value:!0}),t.attachNeighborIterationMethods=a;var d=r(3),s=function(e){return e&&e.__esModule?e:{default:e}}(d),u=r(0),h=[{name:"neighbors",type:"mixed"},{name:"inNeighbors",type:"directed",direction:"in"},{name:"outNeighbors",type:"directed",direction:"out"},{name:"directedNeighbors",type:"directed"},{name:"undirectedNeighbors",type:"undirected"}]},function(e,t,r){"use strict";function n(e,t){var r={key:e};return Object.keys(t.attributes).length&&(r.attributes=t.attributes),r}function i(e,t){var r={source:t.source,target:t.target};return t.generatedKey||(r.key=e),Object.keys(t.attributes).length&&(r.attributes=t.attributes),t instanceof d.UndirectedEdgeData&&(r.undirected=!0),r}function o(e){return(0,s.isPlainObject)(e)?"key"in e?"attributes"in e&&(!(0,s.isPlainObject)(e.attributes)||null===e.attributes)?"invalid-attributes":null:"no-key":"not-object"}function a(e){return(0,s.isPlainObject)(e)?"source"in e?"target"in e?"attributes"in e&&(!(0,s.isPlainObject)(e.attributes)||null===e.attributes)?"invalid-attributes":"undirected"in e&&"boolean"!=typeof e.undirected?"invalid-undirected":null:"no-target":"no-source":"not-object"}Object.defineProperty(t,"__esModule",{value:!0}),t.serializeNode=n,t.serializeEdge=i,t.validateSerializedNode=o,t.validateSerializedEdge=a;var d=r(2),s=r(1)},function(e,t){function r(){this._events=this._events||{},this._maxListeners=this._maxListeners||void 0}function n(e){return"function"==typeof e}function i(e){return"number"==typeof e}function o(e){return"object"==typeof e&&null!==e}function a(e){return void 0===e}e.exports=r,r.EventEmitter=r,r.prototype._events=void 0,r.prototype._maxListeners=void 0,r.defaultMaxListeners=10,r.prototype.setMaxListeners=function(e){if(!i(e)||e<0||isNaN(e))throw TypeError("n must be a positive number");return this._maxListeners=e,this},r.prototype.emit=function(e){var t,r,i,d,s,u;if(this._events||(this._events={}),"error"===e&&(!this._events.error||o(this._events.error)&&!this._events.error.length)){if((t=arguments[1])instanceof Error)throw t;var h=new Error('Uncaught, unspecified "error" event. ('+t+")");throw h.context=t,h}if(r=this._events[e],a(r))return!1;if(n(r))switch(arguments.length){case 1:r.call(this);break;case 2:r.call(this,arguments[1]);break;case 3:r.call(this,arguments[1],arguments[2]);break;default:d=Array.prototype.slice.call(arguments,1),r.apply(this,d)}else if(o(r))for(d=Array.prototype.slice.call(arguments,1),u=r.slice(),i=u.length,s=0;s<i;s++)u[s].apply(this,d);return!0},r.prototype.addListener=function(e,t){var i;if(!n(t))throw TypeError("listener must be a function");return this._events||(this._events={}),this._events.newListener&&this.emit("newListener",e,n(t.listener)?t.listener:t),this._events[e]?o(this._events[e])?this._events[e].push(t):this._events[e]=[this._events[e],t]:this._events[e]=t,o(this._events[e])&&!this._events[e].warned&&(i=a(this._maxListeners)?r.defaultMaxListeners:this._maxListeners)&&i>0&&this._events[e].length>i&&(this._events[e].warned=!0,console.error("(node) warning: possible EventEmitter memory leak detected. %d listeners added. Use emitter.setMaxListeners() to increase limit.",this._events[e].length),"function"==typeof console.trace&&console.trace()),this},r.prototype.on=r.prototype.addListener,r.prototype.once=function(e,t){function r(){this.removeListener(e,r),i||(i=!0,t.apply(this,arguments))}if(!n(t))throw TypeError("listener must be a function");var i=!1;return r.listener=t,this.on(e,r),this},r.prototype.removeListener=function(e,t){var r,i,a,d;if(!n(t))throw TypeError("listener must be a function");if(!this._events||!this._events[e])return this;if(r=this._events[e],a=r.length,i=-1,r===t||n(r.listener)&&r.listener===t)delete this._events[e],this._events.removeListener&&this.emit("removeListener",e,t);else if(o(r)){for(d=a;d-- >0;)if(r[d]===t||r[d].listener&&r[d].listener===t){i=d;break}if(i<0)return this;1===r.length?(r.length=0,delete this._events[e]):r.splice(i,1),this._events.removeListener&&this.emit("removeListener",e,t)}return this},r.prototype.removeAllListeners=function(e){var t,r;if(!this._events)return this;if(!this._events.removeListener)return 0===arguments.length?this._events={}:this._events[e]&&delete this._events[e],this;if(0===arguments.length){for(t in this._events)"removeListener"!==t&&this.removeAllListeners(t);return this.removeAllListeners("removeListener"),this._events={},this}if(r=this._events[e],n(r))this.removeListener(e,r);else if(r)for(;r.length;)this.removeListener(e,r[r.length-1]);return delete this._events[e],this},r.prototype.listeners=function(e){return this._events&&this._events[e]?n(this._events[e])?[this._events[e]]:this._events[e].slice():[]},r.prototype.listenerCount=function(e){if(this._events){var t=this._events[e];if(n(t))return 1;if(t)return t.length}return 0},r.listenerCount=function(e,t){return e.listenerCount(t)}}])}); |
# Changelog | ||
## 0.10.0 | ||
* Adding basic edges iterators. | ||
* Fixing `#.inspect`. | ||
## 0.9.1 | ||
@@ -4,0 +9,0 @@ |
@@ -6,4 +6,13 @@ 'use strict'; | ||
}); | ||
exports.attachEdgeIteratorCreator = attachEdgeIteratorCreator; | ||
exports.attachEdgeIterationMethods = attachEdgeIterationMethods; | ||
var _iterator = require('obliterator/iterator'); | ||
var _iterator2 = _interopRequireDefault(_iterator); | ||
var _consume = require('obliterator/consume'); | ||
var _consume2 = _interopRequireDefault(_consume); | ||
var _errors = require('../errors'); | ||
@@ -13,3 +22,3 @@ | ||
var _utils = require('../utils'); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
@@ -19,2 +28,9 @@ /** | ||
*/ | ||
/** | ||
* Graphology Edge Iteration | ||
* ========================== | ||
* | ||
* Attaching some methods to the Graph class to be able to iterate over a | ||
* graph's edges. | ||
*/ | ||
var EDGES_ITERATION = [{ | ||
@@ -46,12 +62,5 @@ name: 'edges', | ||
*/ | ||
/** | ||
* Graphology Edge Iteration | ||
* ========================== | ||
* | ||
* Attaching some methods to the Graph class to be able to iterate over a | ||
* graph's edges. | ||
*/ | ||
function collect(edges, object) { | ||
for (var k in object) { | ||
if (object[k] instanceof Set) edges.push.apply(edges, (0, _utils.consumeIterator)(object[k].size, object[k].values()));else edges.push(object[k]); | ||
if (object[k] instanceof Set) edges.push.apply(edges, (0, _consume2.default)(object[k].values(), object[k].size));else edges.push(object[k]); | ||
} | ||
@@ -72,3 +81,3 @@ } | ||
if (object[key] instanceof Set) edges.push.apply(edges, (0, _utils.consumeIterator)(object[key].size, object[key].values()));else edges.push(object[key]); | ||
if (object[key] instanceof Set) edges.push.apply(edges, (0, _consume2.default)(object[key].values(), object[key].size));else edges.push(object[key]); | ||
@@ -79,3 +88,3 @@ return; | ||
/** | ||
* Function creating an array of edge for the given type. | ||
* Function creating an array of edges for the given type. | ||
* | ||
@@ -87,4 +96,6 @@ * @param {Graph} graph - Target Graph instance. | ||
function createEdgeArray(graph, type) { | ||
if (type === 'mixed') return (0, _utils.consumeIterator)(graph._edges.size, graph._edges.keys()); | ||
if (graph.size === 0) return []; | ||
if (type === 'mixed') return (0, _consume2.default)(graph._edges.keys(), graph._edges.size); | ||
var list = []; | ||
@@ -101,4 +112,36 @@ | ||
/** | ||
* Function creating an array of edge for the given type & the given node. | ||
* Function creating an iterator of edges for the given type. | ||
* | ||
* @param {Graph} graph - Target Graph instance. | ||
* @param {string} type - Type of edges to retrieve. | ||
* @return {Iterator} - Edge iterator. | ||
*/ | ||
function createEdgeIterator(graph, type) { | ||
if (graph.size === 0) return _iterator2.default.empty(); | ||
var inner = void 0; | ||
if (type === 'mixed') { | ||
inner = graph._edges.keys(); | ||
return new _iterator2.default(inner.next.bind(inner)); | ||
} | ||
inner = graph._edges.entries(); | ||
return new _iterator2.default(function next() { | ||
var step = inner.next(); | ||
if (step.done) return step; | ||
var data = step.value[1]; | ||
if (data instanceof _data.UndirectedEdgeData === (type === 'undirected')) return { value: step.value[0] }; | ||
return next(); | ||
}); | ||
} | ||
/** | ||
* Function creating an array of edges for the given type & the given node. | ||
* | ||
* @param {Graph} graph - Target Graph instance. | ||
@@ -129,3 +172,3 @@ * @param {string} type - Type of edges to retrieve. | ||
/** | ||
* Function creating an array of edge for the given path. | ||
* Function creating an array of edges for the given path. | ||
* | ||
@@ -167,3 +210,3 @@ * @param {Graph} graph - Target Graph instance. | ||
/** | ||
* Function returning an array or the count of certain edges. | ||
* Function returning an array of certain edges. | ||
* | ||
@@ -227,2 +270,81 @@ * Arity 0: Return all the relevant edges. | ||
/** | ||
* Function attaching an edge array iterator method to the Graph prototype. | ||
* | ||
* @param {function} Class - Target class. | ||
* @param {object} description - Method description. | ||
*/ | ||
function attachEdgeIteratorCreator(Class, description) { | ||
var originalName = description.name, | ||
type = description.type; | ||
var name = originalName + 'Iterator'; | ||
/** | ||
* Function returning an iterator over the graph's edges. | ||
* | ||
* Arity 0: Return all the relevant edges. | ||
* | ||
* Arity 1a: Return all of a node's relevant edges. | ||
* @param {any} node - Target node. | ||
* | ||
* Arity 1b: Return the union of the relevant edges of the given bunch of nodes. | ||
* @param {bunch} bunch - Bunch of nodes. | ||
* | ||
* Arity 2: Return the relevant edges across the given path. | ||
* @param {any} source - Source node. | ||
* @param {any} target - Target node. | ||
* | ||
* @return {array|number} - The edges or the number of edges. | ||
* | ||
* @throws {Error} - Will throw if there are too many arguments. | ||
*/ | ||
Class.prototype[name] = function () { | ||
// Early termination | ||
if (type !== 'mixed' && this.type !== 'mixed' && type !== this.type) return _iterator2.default.empty(); | ||
if (!arguments.length) return createEdgeIterator(this, type); | ||
// TODO: complete here... | ||
// if (arguments.length === 1) { | ||
// source = '' + source; | ||
// if (!this._nodes.has(source)) | ||
// throw new NotFoundGraphError(`Graph.${name}: could not find the "${source}" node in the graph.`); | ||
// // Iterating over a node's edges | ||
// return createEdgeArrayForNode(this, type, direction, source); | ||
// } | ||
// if (arguments.length === 2) { | ||
// source = '' + source; | ||
// target = '' + target; | ||
// if (!this._nodes.has(source)) | ||
// throw new NotFoundGraphError(`Graph.${name}: could not find the "${source}" source node in the graph.`); | ||
// if (!this._nodes.has(target)) | ||
// throw new NotFoundGraphError(`Graph.${name}: could not find the "${target}" target node in the graph.`); | ||
// // Iterating over the edges between source & target | ||
// let hasEdge; | ||
// if (type !== 'undirected') | ||
// hasEdge = this.hasDirectedEdge(source, target); | ||
// else | ||
// hasEdge = this.hasUndirectedEdge(source, target); | ||
// // If no such edge exist, we'll stop right there. | ||
// if (!hasEdge) | ||
// return []; | ||
// return createEdgeArrayForPath(this, type, source, target); | ||
// } | ||
// throw new InvalidArgumentsGraphError(`Graph.${name}: too many arguments (expecting 0, 1 or 2 and got ${arguments.length}).`); | ||
}; | ||
} | ||
/** | ||
* Function attaching every edge iteration method to the Graph class. | ||
@@ -235,3 +357,4 @@ * | ||
attachEdgeArrayCreator(Graph, description); | ||
attachEdgeIteratorCreator(Graph, description); | ||
}); | ||
} |
@@ -8,5 +8,9 @@ 'use strict'; | ||
var _consume = require('obliterator/consume'); | ||
var _consume2 = _interopRequireDefault(_consume); | ||
var _errors = require('../errors'); | ||
var _utils = require('../utils'); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
@@ -141,3 +145,3 @@ /** | ||
return (0, _utils.consumeIterator)(_neighbors.size, _neighbors.values()); | ||
return (0, _consume2.default)(_neighbors.values(), _neighbors.size); | ||
} | ||
@@ -144,0 +148,0 @@ |
@@ -10,3 +10,2 @@ 'use strict'; | ||
exports.assign = assign; | ||
exports.consumeIterator = consumeIterator; | ||
exports.getMatchingEdge = getMatchingEdge; | ||
@@ -35,14 +34,10 @@ exports.isBunch = isBunch; | ||
*/ | ||
function assign(target) { | ||
target = target || {}; | ||
function assign() { | ||
var target = arguments[0] || {}; | ||
for (var _len = arguments.length, objects = Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) { | ||
objects[_key - 1] = arguments[_key]; | ||
} | ||
for (var i = 1, l = arguments.length; i < l; i++) { | ||
if (!arguments[i]) continue; | ||
for (var i = 0, l = objects.length; i < l; i++) { | ||
if (!objects[i]) continue; | ||
for (var k in objects[i]) { | ||
target[k] = objects[i][k]; | ||
for (var k in arguments[i]) { | ||
target[k] = arguments[i][k]; | ||
} | ||
@@ -55,20 +50,2 @@ } | ||
/** | ||
* Function consuming the given iterator. | ||
* | ||
* @param {number} size - Size of the target. | ||
* @param {Iterator} iterator - Target iterator. | ||
* @return {Array} | ||
*/ | ||
function consumeIterator(size, iterator) { | ||
var array = new Array(size); | ||
var i = 0, | ||
step = void 0; | ||
while (step = iterator.next(), !step.done) { | ||
array[i++] = step.value; | ||
}return array; | ||
} | ||
/** | ||
* Function returning the first matching edge for given path. | ||
@@ -75,0 +52,0 @@ * Note: this function does not check the existence of source & target. This |
{ | ||
"name": "graphology", | ||
"version": "0.9.1", | ||
"version": "0.10.0", | ||
"description": "A robust and multipurpose Graph object for JavaScript.", | ||
@@ -51,3 +51,4 @@ "main": "dist/index.js", | ||
"dependencies": { | ||
"events": "^1.1.1" | ||
"events": "^1.1.1", | ||
"obliterator": "^1.2.0" | ||
}, | ||
@@ -54,0 +55,0 @@ "devDependencies": { |
@@ -12,2 +12,6 @@ 'use strict'; | ||
var _consume = require('obliterator/consume'); | ||
var _consume2 = _interopRequireDefault(_consume); | ||
var _helpers = require('../helpers'); | ||
@@ -152,2 +156,8 @@ | ||
'it should be possible to return an iterator over the relevant edges.': function itShouldBePossibleToReturnAnIteratorOverTheRelevantEdges() { | ||
var iterator = graph[name + 'Iterator'](); | ||
_assert2.default.deepEqual((0, _consume2.default)(iterator), data.all); | ||
}, | ||
'it should return a node\'s relevant edges.': function itShouldReturnANodeSRelevantEdges() { | ||
@@ -154,0 +164,0 @@ var edges = graph[name](data.node.key); |
@@ -371,2 +371,10 @@ 'use strict'; | ||
}, usage()); | ||
}, | ||
'it should distinguish between typed edges.': function itShouldDistinguishBetweenTypedEdges() { | ||
var graph = new Graph(); | ||
graph.mergeEdge('John', 'Martha', { type: 'LIKES' }); | ||
graph.mergeUndirectedEdge('John', 'Martha', { weight: 34 }); | ||
_assert2.default.strictEqual(graph.size, 2); | ||
} | ||
@@ -373,0 +381,0 @@ }, |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
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
467131
9685
2
32
+ Addedobliterator@^1.2.0
+ Addedobliterator@1.6.1(transitive)