graph-data-structure
Advanced tools
Comparing version 3.5.0 to 4.0.0
@@ -1,2 +0,1 @@ | ||
!function(t,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports):"function"==typeof define&&define.amd?define(["exports"],n):n((t||self).graphDataStructure={})}(this,function(t){function n(t){return n=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(t){return t.__proto__||Object.getPrototypeOf(t)},n(t)}function e(t,n){return e=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,n){return t.__proto__=n,t},e(t,n)}function r(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){})),!0}catch(t){return!1}}function o(t,n,i){return o=r()?Reflect.construct.bind():function(t,n,r){var o=[null];o.push.apply(o,n);var i=new(Function.bind.apply(t,o));return r&&e(i,r.prototype),i},o.apply(null,arguments)}function i(t){var r="function"==typeof Map?new Map:void 0;return i=function(t){if(null===t||-1===Function.toString.call(t).indexOf("[native code]"))return t;if("function"!=typeof t)throw new TypeError("Super expression must either be null or a function");if(void 0!==r){if(r.has(t))return r.get(t);r.set(t,i)}function i(){return o(t,arguments,n(this).constructor)}return i.prototype=Object.create(t.prototype,{constructor:{value:i,enumerable:!1,writable:!0,configurable:!0}}),e(i,t)},i(t)}var u=/*#__PURE__*/function(t){var n,r;function o(n){var e;return e=t.call(this,n)||this,Object.setPrototypeOf(function(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}(e),o.prototype),e}return r=t,(n=o).prototype=Object.create(r.prototype),n.prototype.constructor=n,e(n,r),o}(/*#__PURE__*/i(Error));function c(t){var n={addNode:o,removeNode:function(t){return Object.keys(e).forEach(function(n){e[n].forEach(function(e){e===t&&p(n,e)})}),delete e[t],n},nodes:i,adjacent:c,addEdge:s,removeEdge:p,hasEdge:l,setEdgeWeight:a,getEdgeWeight:h,indegree:function(t){var n=0;function r(e){e===t&&n++}return Object.keys(e).forEach(function(t){e[t].forEach(r)}),n},outdegree:function(t){return t in e?e[t].length:0},depthFirstSearch:d,hasCycle:function(){try{return d(void 0,!0,!0),!1}catch(t){if(t instanceof u)return!0;throw t}},lowestCommonAncestors:function(t,n){var e=[],r=[];return function t(o,i){return!!o[i]||(o[i]=!0,e.push(i),i==n?(r.push(i),!1):c(i).every(function(n){return t(o,n)}))}({},t)&&function t(n,o){n[o]||(n[o]=!0,e.indexOf(o)>=0?r.push(o):0==r.length&&c(o).forEach(function(e){t(n,e)}))}({},n),r},topologicalSort:function(t,n){return void 0===n&&(n=!0),d(t,n,!0).reverse()},shortestPath:v,shortestPaths:function(t,n){for(var e=v(t,n),r=[e],o=[],i=e.weight;i;){var u=e[0],c=e[1];l(u,c)&&(o.push({u:u,v:c,weight:h(u,c)}),p(u,c)),l(c,u)&&(o.push({u:c,v:u,weight:h(c,u)}),p(c,u));try{if(!(e=v(t,n)).weight||i<e.weight)break;r.push(e)}catch(t){break}}for(var f=0,a=o;f<a.length;f++){var d=a[f];s(d.u,d.v,d.weight)}return r},serialize:function(){var t={nodes:i().map(function(t){return{id:t}}),links:[]};return t.nodes.forEach(function(n){var e=n.id;c(e).forEach(function(n){t.links.push({source:e,target:n,weight:h(e,n)})})}),t},deserialize:y},e={},r={};function o(t){return e[t]=c(t),n}function i(){var t={};return Object.keys(e).forEach(function(n){t[n]=!0,e[n].forEach(function(n){t[n]=!0})}),Object.keys(t)}function c(t){return e[t]||[]}function f(t,n){return t+"|"+n}function a(t,e,o){return r[f(t,e)]=o,n}function h(t,n){var e=r[f(t,n)];return void 0===e?1:e}function s(t,e,r){return o(t),o(e),c(t).push(e),void 0!==r&&a(t,e,r),n}function p(t,r){return e[t]&&(e[t]=c(t).filter(function(t){return t!==r})),n}function l(t,n){return c(t).includes(n)}function d(t,n,e){void 0===n&&(n=!0),void 0===e&&(e=!1),t||(t=i()),"boolean"!=typeof n&&(n=!0);var r={},o={},f=[];function a(t){if(o[t]&&e)throw new u("Cycle found");r[t]||(r[t]=!0,o[t]=!0,c(t).forEach(a),o[t]=!1,f.push(t))}return n?t.forEach(a):(t.forEach(function(t){r[t]=!0}),t.forEach(function(t){c(t).forEach(a)})),f}function v(t,n){var e={},r={},o={};return function(){!function(){if(i().forEach(function(t){e[t]=Infinity}),Infinity!==e[t])throw new Error("Source node is not in the graph");if(Infinity!==e[n])throw new Error("Destination node is not in the graph");e[t]=0}(),i().forEach(function(t){o[t]=!0});for(var u=function(){var t,n,i=(n=Infinity,Object.keys(o).forEach(function(r){e[r]<n&&(n=e[r],t=r)}),void 0===t?(o={},null):(delete o[t],t));if(null===i)return{v:void 0};c(i).forEach(function(t){!function(t,n){var o=h(t,n);e[n]>e[t]+o&&(e[n]=e[t]+o,r[n]=t)}(i,t)})};0!==Object.keys(o).length;){var f=u();if("object"==typeof f)return f.v}}(),function(){for(var e=[],o=0,i=n;r[i];)e.push(i),o+=h(r[i],i),i=r[i];if(i!==t)throw new Error("No path found");return e.push(i),e.reverse(),e.weight=o,e}()}function y(t){return t.nodes.forEach(function(t){o(t.id)}),t.links.forEach(function(t){s(t.source,t.target,t.weight)}),n}return t&&y(t),n}t.CycleError=u,t.Graph=c,t.default=c}); | ||
//# sourceMappingURL=index.umd.js.map | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).graphDataStructure={})}(this,(function(e){"use strict";function t(e,t){if(!1===e||null==e)throw console.warn("Test invariant failed:",t),new Error(t)}class o{nodes=new Set;edges=new Map;edgeWeights=new Map;edgeProperties=new Map;addNode(e){return this.nodes.has(e)||this.nodes.add(e),this.edges.has(e)||this.edges.set(e,new Set),this}removeNode(e){this.edges.delete(e),this.nodes.delete(e);for(const t of this.edges.values())t.delete(e);return this}adjacent(e){return this.edges.get(e)}setEdgeWeight(e,o,r){this.edgeWeights.has(e)||this.edgeWeights.set(e,new Map);const n=this.edgeWeights.get(e);return t(n),n.set(o,r),this}getEdgeWeight(e,t){return this.edgeWeights.get(e)?.get(t)??1}setEdgeProperties(e,o,r){this.edgeProperties.has(e)||this.edgeProperties.set(e,new Map);const n=this.edgeProperties.get(e);return t(n),n.set(o,r),this}getEdgeProperties(e,t){return this.edgeProperties.get(e)?.get(t)}addEdge(e,o,...r){let n,s;const d=r[0];"number"==typeof d&&(n=d),"object"==typeof d&&(n=d.weight,d&&(s=Object.prototype.hasOwnProperty.call(d,"props")?d.props:void 0)),this.addNode(e),this.addNode(o);const i=this.adjacent(e);return t(i),i.add(o),void 0!==n&&this.setEdgeWeight(e,o,n),void 0!==s&&this.setEdgeProperties(e,o,s),this}removeEdge(e,t){return this.edges.get(e)?.delete(t),this.edgeProperties.get(e)?.delete(t),this}hasEdge(e,t){return this.edges.get(e)?.has(t)??!1}}class r extends Error{constructor(e){super(e),Object.setPrototypeOf(this,r.prototype)}}function n(e,t,o,s,d,i){const{errorOnCycle:h=!1,shouldFollow:g}=i;if(s.has(d)&&h)throw new r("Cycle found");o.has(d)||(o.add(d),s.add(d),e.adjacent(d)?.forEach((r=>{(void 0===g||g({source:d,target:r,graph:e}))&&n(e,t,o,s,r,i)})),s.delete(d),t.push(d))}function s(e,t={}){const{sourceNodes:o=Array.from(e.nodes),includeSourceNodes:r=!0}=t,s=new Set,d=new Set,i=[];if(r){for(let r=0;r<o.length;r++){const h=o[r];h&&n(e,i,s,d,h,t)}return i}for(let e=0;e<o.length;e++){const t=o[e];t&&s.add(t)}for(let r=0;r<o.length;r++){const h=o[r];h&&e.adjacent(h)?.forEach((o=>n(e,i,s,d,o,t)))}return i}function d(e){let t,o=1/0;const{d:r,q:n}=e;return n.forEach((e=>{const n=r.get(e)??1/0;n<o&&(o=n,t=e)})),void 0===t?(n.clear(),null):(n.delete(t),t)}function i(e,o,r,n){const{d:s,p:d}=o,i=e.getEdgeWeight(r,n),h=s.get(r),g=s.get(n);t(h,"Missing source distance"),t(g,"Missing target distance"),g>h+i&&(s.set(n,h+i),d.set(n,r))}function h(e,t,o,r){const n=e.nodes,{q:s}=t;for(!function(e,{d:t},o,r){if(e.forEach((e=>{t.set(e,1/0)})),t.get(o)!==1/0)throw new Error("Source node is not in the graph");if(t.get(r)!==1/0)throw new Error("Destination node is not in the graph");t.set(o,0)}(n,t,o,r),function(e,{q:t}){e.forEach((e=>{t.add(e)}))}(n,t);0!==s.size;){const o=d(t);if(null===o)return;e.adjacent(o)?.forEach((r=>{i(e,t,o,r)}))}}function g(e,t,o){const r={d:new Map,p:new Map,q:new Set};return h(e,r,t,o),function(e,t,o,r){const{p:n}=t,s=[];let d=0,i=r;for(;n.has(i);){const t=n.get(i);s.push(i),d+=e.getEdgeWeight(t,i),i=t}if(i!==o)throw new Error("No path found");return s.push(i),s.reverse(),{nodes:s,weight:d}}(e,r,t,o)}function c(e,t,o,r,n,s){return!!r.has(n)||(r.add(n),t.push(n),n==s?(o.push(n),!1):Array.from(e.adjacent(n)??[]).every((n=>c(e,t,o,r,n,s))))}function a(e,t,o,r,n){r.has(n)||(r.add(n),t.indexOf(n)>=0?o.push(n):0==o.length&&e.adjacent(n)?.forEach((n=>{a(e,t,o,r,n)})))}e.CycleError=r,e.Graph=o,e.cloneGraph=function(e){const t=new o;for(let[o,r]of e.edges.entries())r.forEach((r=>{t.addEdge.apply(t,[o,r]);const n=e.edgeWeights.get(o)?.get(r);n&&t.setEdgeWeight(o,r,n);const s=e.getEdgeProperties(o,r);s&&t.setEdgeProperties(o,r,s)}));return t},e.depthFirstSearch=s,e.deserializeGraph=function(...e){const[t,r]=e,n=new o,s=new Map;return t.nodes.forEach((e=>{n.addNode(e),r&&s.set(r(e),e)})),t.links.forEach((e=>{if(!r)return void n.addEdge.apply(n,[e.source,e.target,e.weight,e.props]);const t=s.get(r(e.source))??e.source,o=s.get(r(e.target))??e.target;n.addEdge.apply(n,[t,o,e.weight,e.props])})),n},e.findNodes=function(e,t){const o=[];return e.nodes.forEach((e=>{t(e)&&o.push(e)})),o},e.getFirstNode=function(e,t){for(const o of e.nodes)if(t(o))return o;throw new Error("Node not found.")},e.getNode=function(e,t){const o=[];for(const r of e.nodes)t(r)&&o.push(r);if(0===o.length)throw new Error("Node not found.");if(o.length>1)throw new Error("More than one node found.");return o[0]},e.hasCycle=function(e,t){try{return s(e,{...t,includeSourceNodes:!0,errorOnCycle:!0}),!1}catch(e){if(e instanceof r)return!0;throw e}},e.indegree=function(e,t){let o=0;for(const r of e.edges.values())for(let e of r)e===t&&o++;return o},e.lowestCommonAncestors=function(e,t,o){const r=[],n=[];return c(e,r,n,new Set,t,o)&&a(e,r,n,new Set,o),n},e.outdegree=function(e,t){return e.edges.get(t)?.size??0},e.serializeGraph=function(e,t={}){const{includeDefaultWeight:o=!1}=t,r={nodes:Array.from(e.nodes),links:[]};return r.nodes.forEach((t=>{const n=t;e.adjacent(n)?.forEach((t=>{const s=e.getEdgeWeight(n,t),d=e.getEdgeProperties(n,t),i={source:n,target:t};(1!=s||o)&&(i.weight=s),d&&(i.props=d),r.links.push(i)}))})),r},e.shortestPath=g,e.shortestPaths=function(e,t,o){let r=g(e,t,o);const n=[r],s=r.weight,d=[];for(;r.weight;){const i=r.nodes[0],h=r.nodes[1];e.hasEdge(i,h)&&(d.push({u:i,v:h,weight:e.getEdgeWeight(i,h),props:e.getEdgeProperties(i,h)}),e.removeEdge(i,h)),e.hasEdge(h,i)&&(d.push({u:h,v:i,weight:e.getEdgeWeight(h,i),props:e.getEdgeProperties(i,h)}),e.removeEdge(h,i));try{if(r=g(e,t,o),!r.weight||s<r.weight)break;n.push(r)}catch(e){break}}for(const{u:t,v:o,weight:r,props:n}of d)e.addEdge(t,o,r,n);return n},e.topologicalSort=function(e,t={}){return s(e,{...t,errorOnCycle:!0}).reverse()}})); |
105
package.json
{ | ||
"name": "graph-data-structure", | ||
"version": "3.5.0", | ||
"version": "4.0.0", | ||
"description": "A graph data structure with topological sort.", | ||
"files": [ | ||
"./dist" | ||
"author": "Curran Kelleher", | ||
"contributors": [ | ||
{ | ||
"name": "Jonathan MASSUCHETTI", | ||
"email": "jonathan.massuchetti@dappit.fr", | ||
"url": "https://github.com/JesusTheHun" | ||
} | ||
], | ||
"license": "MIT", | ||
"bugs": { | ||
"url": "https://github.com/datavis-tech/graph-data-structure/issues" | ||
}, | ||
"homepage": "https://github.com/datavis-tech/graph-data-structure#readme", | ||
"type": "module", | ||
"source": "src/index.ts", | ||
"main": "./dist/index.cjs", | ||
"module": "./dist/index.mjs", | ||
"types": "dist/index.d.ts", | ||
"type": "module", | ||
"unpkg": "./dist/index.umd.js", | ||
"exports": { | ||
"require": "./dist/index.cjs", | ||
"types": "./dist/index.d.ts", | ||
"default": "./dist/index.modern.js" | ||
".": { | ||
"import": { | ||
"types": "./dist/index.d.mts", | ||
"default": "./dist/index.mjs" | ||
}, | ||
"require": { | ||
"types": "./dist/index.d.cts", | ||
"default": "./dist/index.cjs" | ||
}, | ||
"umd": { | ||
"types": "./dist/index.umd.d.ts", | ||
"default": "./dist/index.umd.js" | ||
} | ||
} | ||
}, | ||
"main": "./dist/index.cjs", | ||
"module": "./dist/index.module.js", | ||
"unpkg": "./dist/index.umd.js", | ||
"scripts": { | ||
"build": "rm -rf dist && microbundle src/index.ts", | ||
"test": "npm run build -f modern && mocha", | ||
"build": "rm -rf dist && rollup -c", | ||
"test": "vitest --run", | ||
"prepublishOnly": "npm run build", | ||
"lint": "prettier --write .", | ||
"type-check": "tsc", | ||
"prettier": "prettier --write .", | ||
"tsc": "tsc --noEmit --noEmitOnError", | ||
"release": "release-it" | ||
}, | ||
"release-it": { | ||
"git": { | ||
"commitMessage": "${version}" | ||
}, | ||
"github": { | ||
"release": true | ||
}, | ||
"npm": { | ||
"publish": false | ||
} | ||
"devDependencies": { | ||
"@rollup/plugin-node-resolve": "15.2.3", | ||
"@rollup/plugin-terser": "0.4.4", | ||
"@types/node": "22.5.4", | ||
"microbundle": "0.15.1", | ||
"prettier": "3.3.3", | ||
"release-it": "17.6.0", | ||
"rollup": "4.21.3", | ||
"rollup-plugin-ts": "3.4.5", | ||
"typescript": "5.6.2", | ||
"vitest": "2.0.5" | ||
}, | ||
"files": [ | ||
"./dist" | ||
], | ||
"repository": { | ||
@@ -48,17 +73,23 @@ "type": "git", | ||
], | ||
"author": "Curran Kelleher", | ||
"license": "MIT", | ||
"bugs": { | ||
"url": "https://github.com/datavis-tech/graph-data-structure/issues" | ||
"release-it": { | ||
"git": { | ||
"commitMessage": "${version}" | ||
}, | ||
"github": { | ||
"release": true | ||
}, | ||
"npm": { | ||
"publish": false | ||
} | ||
}, | ||
"homepage": "https://github.com/datavis-tech/graph-data-structure#readme", | ||
"devDependencies": { | ||
"@types/node": "20.10.3", | ||
"graph-diagrams": "0.5.0", | ||
"microbundle": "0.15.1", | ||
"mocha": "10.2.0", | ||
"prettier": "3.1.0", | ||
"release-it": "17.0.0", | ||
"typescript": "5.3.2" | ||
"prettier": { | ||
"arrowParens": "always", | ||
"bracketSameLine": false, | ||
"bracketSpacing": true, | ||
"printWidth": 90, | ||
"quoteProps": "consistent", | ||
"singleAttributePerLine": false, | ||
"singleQuote": true, | ||
"tabWidth": 2 | ||
} | ||
} |
@@ -26,3 +26,3 @@ # graph-data-structure | ||
```javascript | ||
var Graph = require("graph-data-structure"); | ||
const { Graph } = require('graph-data-structure'); | ||
``` | ||
@@ -43,5 +43,5 @@ | ||
```javascript | ||
graph.addNode("a"); | ||
graph.addNode("b"); | ||
graph.addEdge("a", "b"); | ||
graph.addNode('a'); | ||
graph.addNode('b'); | ||
graph.addEdge('a', 'b'); | ||
``` | ||
@@ -52,3 +52,3 @@ | ||
```javascript | ||
graph.addEdge("b", "c"); | ||
graph.addEdge('b', 'c'); | ||
``` | ||
@@ -74,10 +74,10 @@ | ||
var graph = Graph() | ||
.addEdge("socks", "shoes") | ||
.addEdge("shirt", "belt") | ||
.addEdge("shirt", "tie") | ||
.addEdge("tie", "jacket") | ||
.addEdge("belt", "jacket") | ||
.addEdge("pants", "shoes") | ||
.addEdge("underpants", "pants") | ||
.addEdge("pants", "belt"); | ||
.addEdge('socks', 'shoes') | ||
.addEdge('shirt', 'belt') | ||
.addEdge('shirt', 'tie') | ||
.addEdge('tie', 'jacket') | ||
.addEdge('belt', 'jacket') | ||
.addEdge('pants', 'shoes') | ||
.addEdge('underpants', 'pants') | ||
.addEdge('pants', 'belt'); | ||
@@ -179,4 +179,4 @@ // prints [ "underpants", "pants", "shirt", "tie", "belt", "jacket", "socks", "shoes" ] | ||
var graph = Graph(); | ||
graph.addEdge("a", "b"); | ||
graph.addEdge("b", "c"); | ||
graph.addEdge('a', 'b'); | ||
graph.addEdge('b', 'c'); | ||
var serialized = graph.serialize(); | ||
@@ -183,0 +183,0 @@ ``` |
Sorry, the diff of this file is not supported yet
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
312
58604
10
9
1