Spaces:
Running
Running
import{y as e,z as t,A as s,B as i,D as r,F as n}from"./index-BiV-b1K2.js";import{a as h,f as o,c as d,i as a,v as u,r as _}from"./_baseUniq-DUj_-ybn.js";import{a8 as l}from"./mermaid-D0MGOvVE.js";var c=e((function(e){return h(t(e,1,s,!0))})),p="\0";class g{constructor(e={}){this._isDirected=!Object.prototype.hasOwnProperty.call(e,"directed")||e.directed,this._isMultigraph=!!Object.prototype.hasOwnProperty.call(e,"multigraph")&&e.multigraph,this._isCompound=!!Object.prototype.hasOwnProperty.call(e,"compound")&&e.compound,this._label=void 0,this._defaultNodeLabelFn=i(void 0),this._defaultEdgeLabelFn=i(void 0),this._nodes={},this._isCompound&&(this._parent={},this._children={},this._children[p]={}),this._in={},this._preds={},this._out={},this._sucs={},this._edgeObjs={},this._edgeLabels={}}isDirected(){return this._isDirected}isMultigraph(){return this._isMultigraph}isCompound(){return this._isCompound}setGraph(e){return this._label=e,this}graph(){return this._label}setDefaultNodeLabel(e){return r(e)||(e=i(e)),this._defaultNodeLabelFn=e,this}nodeCount(){return this._nodeCount}nodes(){return n(this._nodes)}sources(){var e=this;return o(this.nodes(),(function(t){return l(e._in[t])}))}sinks(){var e=this;return o(this.nodes(),(function(t){return l(e._out[t])}))}setNodes(e,t){var s=arguments,i=this;return d(e,(function(e){s.length>1?i.setNode(e,t):i.setNode(e)})),this}setNode(e,t){return Object.prototype.hasOwnProperty.call(this._nodes,e)?(arguments.length>1&&(this._nodes[e]=t),this):(this._nodes[e]=arguments.length>1?t:this._defaultNodeLabelFn(e),this._isCompound&&(this._parent[e]=p,this._children[e]={},this._children[p][e]=!0),this._in[e]={},this._preds[e]={},this._out[e]={},this._sucs[e]={},++this._nodeCount,this)}node(e){return this._nodes[e]}hasNode(e){return Object.prototype.hasOwnProperty.call(this._nodes,e)}removeNode(e){if(Object.prototype.hasOwnProperty.call(this._nodes,e)){var t=e=>this.removeEdge(this._edgeObjs[e]);delete this._nodes[e],this._isCompound&&(this._removeFromParentsChildList(e),delete this._parent[e],d(this.children(e),(e=>{this.setParent(e)})),delete this._children[e]),d(n(this._in[e]),t),delete this._in[e],delete this._preds[e],d(n(this._out[e]),t),delete this._out[e],delete this._sucs[e],--this._nodeCount}return this}setParent(e,t){if(!this._isCompound)throw new Error("Cannot set parent in a non-compound graph");if(a(t))t=p;else{for(var s=t+="";!a(s);s=this.parent(s))if(s===e)throw new Error("Setting "+t+" as parent of "+e+" would create a cycle");this.setNode(t)}return this.setNode(e),this._removeFromParentsChildList(e),this._parent[e]=t,this._children[t][e]=!0,this}_removeFromParentsChildList(e){delete this._children[this._parent[e]][e]}parent(e){if(this._isCompound){var t=this._parent[e];if(t!==p)return t}}children(e){if(a(e)&&(e=p),this._isCompound){var t=this._children[e];if(t)return n(t)}else{if(e===p)return this.nodes();if(this.hasNode(e))return[]}}predecessors(e){var t=this._preds[e];if(t)return n(t)}successors(e){var t=this._sucs[e];if(t)return n(t)}neighbors(e){var t=this.predecessors(e);if(t)return c(t,this.successors(e))}isLeaf(e){return 0===(this.isDirected()?this.successors(e):this.neighbors(e)).length}filterNodes(e){var t=new this.constructor({directed:this._isDirected,multigraph:this._isMultigraph,compound:this._isCompound});t.setGraph(this.graph());var s=this;d(this._nodes,(function(s,i){e(i)&&t.setNode(i,s)})),d(this._edgeObjs,(function(e){t.hasNode(e.v)&&t.hasNode(e.w)&&t.setEdge(e,s.edge(e))}));var i={};function r(e){var n=s.parent(e);return void 0===n||t.hasNode(n)?(i[e]=n,n):n in i?i[n]:r(n)}return this._isCompound&&d(t.nodes(),(function(e){t.setParent(e,r(e))})),t}setDefaultEdgeLabel(e){return r(e)||(e=i(e)),this._defaultEdgeLabelFn=e,this}edgeCount(){return this._edgeCount}edges(){return u(this._edgeObjs)}setPath(e,t){var s=this,i=arguments;return _(e,(function(e,r){return i.length>1?s.setEdge(e,r,t):s.setEdge(e,r),r})),this}setEdge(){var e,t,s,i,r=!1,n=arguments[0];"object"==typeof n&&null!==n&&"v"in n?(e=n.v,t=n.w,s=n.name,2===arguments.length&&(i=arguments[1],r=!0)):(e=n,t=arguments[1],s=arguments[3],arguments.length>2&&(i=arguments[2],r=!0)),e=""+e,t=""+t,a(s)||(s=""+s);var h=m(this._isDirected,e,t,s);if(Object.prototype.hasOwnProperty.call(this._edgeLabels,h))return r&&(this._edgeLabels[h]=i),this;if(!a(s)&&!this._isMultigraph)throw new Error("Cannot set a named edge when isMultigraph = false");this.setNode(e),this.setNode(t),this._edgeLabels[h]=r?i:this._defaultEdgeLabelFn(e,t,s);var o=function(e,t,s,i){var r=""+t,n=""+s;if(!e&&r>n){var h=r;r=n,n=h}var o={v:r,w:n};i&&(o.name=i);return o}(this._isDirected,e,t,s);return e=o.v,t=o.w,Object.freeze(o),this._edgeObjs[h]=o,f(this._preds[t],e),f(this._sucs[e],t),this._in[t][h]=o,this._out[e][h]=o,this._edgeCount++,this}edge(e,t,s){var i=1===arguments.length?b(this._isDirected,arguments[0]):m(this._isDirected,e,t,s);return this._edgeLabels[i]}hasEdge(e,t,s){var i=1===arguments.length?b(this._isDirected,arguments[0]):m(this._isDirected,e,t,s);return Object.prototype.hasOwnProperty.call(this._edgeLabels,i)}removeEdge(e,t,s){var i=1===arguments.length?b(this._isDirected,arguments[0]):m(this._isDirected,e,t,s),r=this._edgeObjs[i];return r&&(e=r.v,t=r.w,delete this._edgeLabels[i],delete this._edgeObjs[i],v(this._preds[t],e),v(this._sucs[e],t),delete this._in[t][i],delete this._out[e][i],this._edgeCount--),this}inEdges(e,t){var s=this._in[e];if(s){var i=u(s);return t?o(i,(function(e){return e.v===t})):i}}outEdges(e,t){var s=this._out[e];if(s){var i=u(s);return t?o(i,(function(e){return e.w===t})):i}}nodeEdges(e,t){var s=this.inEdges(e,t);if(s)return s.concat(this.outEdges(e,t))}}function f(e,t){e[t]?e[t]++:e[t]=1}function v(e,t){--e[t]||delete e[t]}function m(e,t,s,i){var r=""+t,n=""+s;if(!e&&r>n){var h=r;r=n,n=h}return r+""+n+""+(a(i)?"\0":i)}function b(e,t){return m(e,t.v,t.w,t.name)}g.prototype._nodeCount=0,g.prototype._edgeCount=0;export{g as G}; | |