graph-data-structure
Advanced tools
Comparing version 3.3.0 to 3.5.0
@@ -36,2 +36,5 @@ export type NodeId = string; | ||
}; | ||
shortestPaths: (source: NodeId, destination: NodeId) => (string[] & { | ||
weight?: number | undefined; | ||
})[]; | ||
serialize: () => Serialized; | ||
@@ -38,0 +41,0 @@ deserialize: (serialized: Serialized) => any; |
@@ -1,2 +0,2 @@ | ||
class n extends Error{constructor(t){super(t),Object.setPrototypeOf(this,n.prototype)}}function t(t){const o={addNode:c,removeNode:function(n){return Object.keys(e).forEach(function(t){e[t].forEach(function(o){o===n&&d(t,o)})}),delete e[n],o},nodes:i,adjacent:u,addEdge:a,removeEdge:d,hasEdge:function(n,t){return u(n).includes(t)},setEdgeWeight:s,getEdgeWeight:h,indegree:function(n){let t=0;function o(o){o===n&&t++}return Object.keys(e).forEach(function(n){e[n].forEach(o)}),t},outdegree:function(n){return n in e?e[n].length:0},depthFirstSearch:E,hasCycle:function(){try{return E(void 0,!0,!0),!1}catch(t){if(t instanceof n)return!0;throw t}},lowestCommonAncestors:function(n,t){const o=[],e=[];return function n(r,c){return!!r[c]||(r[c]=!0,o.push(c),c==t?(e.push(c),!1):u(c).every(t=>n(r,t)))}({},n)&&function n(t,r){t[r]||(t[r]=!0,o.indexOf(r)>=0?e.push(r):0==e.length&&u(r).forEach(o=>{n(t,o)}))}({},t),e},topologicalSort:function(n,t=!0){return E(n,t,!0).reverse()},shortestPath:function(n,t){const o={},e={};let r={};function c(){let n,t=Infinity;return Object.keys(r).forEach(function(e){o[e]<t&&(t=o[e],n=e)}),void 0===n?(r={},null):(delete r[n],n)}function f(n,t){const r=h(n,t);o[t]>o[n]+r&&(o[t]=o[n]+r,e[t]=n)}return function(){for(function(){if(i().forEach(function(n){o[n]=Infinity}),Infinity!==o[n])throw new Error("Source node is not in the graph");if(Infinity!==o[t])throw new Error("Destination node is not in the graph");o[n]=0}(),i().forEach(function(n){r[n]=!0});0!==Object.keys(r).length;){const n=c();if(null===n)return;u(n).forEach(function(t){f(n,t)})}}(),function(){const o=[];let r=0,c=t;for(;e[c];)o.push(c),r+=h(e[c],c),c=e[c];if(c!==n)throw new Error("No path found");return o.push(c),o.reverse(),o.weight=r,o}()},serialize:function(){const n={nodes:i().map(function(n){return{id:n}}),links:[]};return n.nodes.forEach(function(t){const o=t.id;u(o).forEach(function(t){n.links.push({source:o,target:t,weight:h(o,t)})})}),n},deserialize:l},e={},r={};function c(n){return e[n]=u(n),o}function i(){const n={};return Object.keys(e).forEach(function(t){n[t]=!0,e[t].forEach(function(t){n[t]=!0})}),Object.keys(n)}function u(n){return e[n]||[]}function f(n,t){return n+"|"+t}function s(n,t,e){return r[f(n,t)]=e,o}function h(n,t){const o=r[f(n,t)];return void 0===o?1:o}function a(n,t,e){return c(n),c(t),u(n).push(t),void 0!==e&&s(n,t,e),o}function d(n,t){return e[n]&&(e[n]=u(n).filter(function(n){return n!==t})),o}function E(t,o=!0,e=!1){t||(t=i()),"boolean"!=typeof o&&(o=!0);const r={},c={},f=[];function s(t){if(c[t]&&e)throw new n("Cycle found");r[t]||(r[t]=!0,c[t]=!0,u(t).forEach(s),c[t]=!1,f.push(t))}return o?t.forEach(s):(t.forEach(function(n){r[n]=!0}),t.forEach(function(n){u(n).forEach(s)})),f}function l(n){return n.nodes.forEach(function(n){c(n.id)}),n.links.forEach(function(n){a(n.source,n.target,n.weight)}),o}return t&&l(t),o}export{n as CycleError,t as Graph,t as default}; | ||
class n extends Error{constructor(t){super(t),Object.setPrototypeOf(this,n.prototype)}}function t(t){const e={addNode:c,removeNode:function(n){return Object.keys(o).forEach(function(t){o[t].forEach(function(e){e===n&&d(t,e)})}),delete o[n],e},nodes:i,adjacent:u,addEdge:a,removeEdge:d,hasEdge:l,setEdgeWeight:s,getEdgeWeight:h,indegree:function(n){let t=0;function e(e){e===n&&t++}return Object.keys(o).forEach(function(n){o[n].forEach(e)}),t},outdegree:function(n){return n in o?o[n].length:0},depthFirstSearch:E,hasCycle:function(){try{return E(void 0,!0,!0),!1}catch(t){if(t instanceof n)return!0;throw t}},lowestCommonAncestors:function(n,t){const e=[],o=[];return function n(r,c){return!!r[c]||(r[c]=!0,e.push(c),c==t?(o.push(c),!1):u(c).every(t=>n(r,t)))}({},n)&&function n(t,r){t[r]||(t[r]=!0,e.indexOf(r)>=0?o.push(r):0==o.length&&u(r).forEach(e=>{n(t,e)}))}({},t),o},topologicalSort:function(n,t=!0){return E(n,t,!0).reverse()},shortestPath:g,shortestPaths:function(n,t){let e=g(n,t);const o=[e],r=[],c=e.weight;for(;c;){const i=e[0],u=e[1];l(i,u)&&(r.push({u:i,v:u,weight:h(i,u)}),d(i,u)),l(u,i)&&(r.push({u,v:i,weight:h(u,i)}),d(u,i));try{if(e=g(n,t),!e.weight||c<e.weight)break;o.push(e)}catch(n){break}}for(const{u:n,v:t,weight:e}of r)a(n,t,e);return o},serialize:function(){const n={nodes:i().map(function(n){return{id:n}}),links:[]};return n.nodes.forEach(function(t){const e=t.id;u(e).forEach(function(t){n.links.push({source:e,target:t,weight:h(e,t)})})}),n},deserialize:p},o={},r={};function c(n){return o[n]=u(n),e}function i(){const n={};return Object.keys(o).forEach(function(t){n[t]=!0,o[t].forEach(function(t){n[t]=!0})}),Object.keys(n)}function u(n){return o[n]||[]}function f(n,t){return n+"|"+t}function s(n,t,o){return r[f(n,t)]=o,e}function h(n,t){const e=r[f(n,t)];return void 0===e?1:e}function a(n,t,o){return c(n),c(t),u(n).push(t),void 0!==o&&s(n,t,o),e}function d(n,t){return o[n]&&(o[n]=u(n).filter(function(n){return n!==t})),e}function l(n,t){return u(n).includes(t)}function E(t,e=!0,o=!1){t||(t=i()),"boolean"!=typeof e&&(e=!0);const r={},c={},f=[];function s(t){if(c[t]&&o)throw new n("Cycle found");r[t]||(r[t]=!0,c[t]=!0,u(t).forEach(s),c[t]=!1,f.push(t))}return e?t.forEach(s):(t.forEach(function(n){r[n]=!0}),t.forEach(function(n){u(n).forEach(s)})),f}function g(n,t){const e={},o={};let r={};function c(){let n,t=Infinity;return Object.keys(r).forEach(function(o){e[o]<t&&(t=e[o],n=o)}),void 0===n?(r={},null):(delete r[n],n)}function f(n,t){const r=h(n,t);e[t]>e[n]+r&&(e[t]=e[n]+r,o[t]=n)}return function(){for(function(){if(i().forEach(function(n){e[n]=Infinity}),Infinity!==e[n])throw new Error("Source node is not in the graph");if(Infinity!==e[t])throw new Error("Destination node is not in the graph");e[n]=0}(),i().forEach(function(n){r[n]=!0});0!==Object.keys(r).length;){const n=c();if(null===n)return;u(n).forEach(function(t){f(n,t)})}}(),function(){const e=[];let r=0,c=t;for(;o[c];)e.push(c),r+=h(o[c],c),c=o[c];if(c!==n)throw new Error("No path found");return e.push(c),e.reverse(),e.weight=r,e}()}function p(n){return n.nodes.forEach(function(n){c(n.id)}),n.links.forEach(function(n){a(n.source,n.target,n.weight)}),e}return t&&p(t),e}export{n as CycleError,t as Graph,t as default}; | ||
//# sourceMappingURL=index.modern.js.map |
@@ -1,2 +0,2 @@ | ||
function n(t){return n=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(n){return n.__proto__||Object.getPrototypeOf(n)},n(t)}function t(n,r){return t=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(n,t){return n.__proto__=t,n},t(n,r)}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(n){return!1}}function e(n,o,u){return e=r()?Reflect.construct.bind():function(n,r,e){var o=[null];o.push.apply(o,r);var u=new(Function.bind.apply(n,o));return e&&t(u,e.prototype),u},e.apply(null,arguments)}function o(r){var u="function"==typeof Map?new Map:void 0;return o=function(r){if(null===r||-1===Function.toString.call(r).indexOf("[native code]"))return r;if("function"!=typeof r)throw new TypeError("Super expression must either be null or a function");if(void 0!==u){if(u.has(r))return u.get(r);u.set(r,o)}function o(){return e(r,arguments,n(this).constructor)}return o.prototype=Object.create(r.prototype,{constructor:{value:o,enumerable:!1,writable:!0,configurable:!0}}),t(o,r)},o(r)}var u=/*#__PURE__*/function(n){var r,e;function o(t){var r;return r=n.call(this,t)||this,Object.setPrototypeOf(function(n){if(void 0===n)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return n}(r),o.prototype),r}return e=n,(r=o).prototype=Object.create(e.prototype),r.prototype.constructor=r,t(r,e),o}(/*#__PURE__*/o(Error));function i(n){var t={addNode:o,removeNode:function(n){return Object.keys(r).forEach(function(t){r[t].forEach(function(r){r===n&&p(t,r)})}),delete r[n],t},nodes:i,adjacent:c,addEdge:h,removeEdge:p,hasEdge:function(n,t){return c(n).includes(t)},setEdgeWeight:a,getEdgeWeight:s,indegree:function(n){var t=0;function e(r){r===n&&t++}return Object.keys(r).forEach(function(n){r[n].forEach(e)}),t},outdegree:function(n){return n in r?r[n].length:0},depthFirstSearch:l,hasCycle:function(){try{return l(void 0,!0,!0),!1}catch(n){if(n instanceof u)return!0;throw n}},lowestCommonAncestors:function(n,t){var r=[],e=[];return function n(o,u){return!!o[u]||(o[u]=!0,r.push(u),u==t?(e.push(u),!1):c(u).every(function(t){return n(o,t)}))}({},n)&&function n(t,o){t[o]||(t[o]=!0,r.indexOf(o)>=0?e.push(o):0==e.length&&c(o).forEach(function(r){n(t,r)}))}({},t),e},topologicalSort:function(n,t){return void 0===t&&(t=!0),l(n,t,!0).reverse()},shortestPath:function(n,t){var r={},e={},o={};return function(){(function(){if(i().forEach(function(n){r[n]=Infinity}),Infinity!==r[n])throw new Error("Source node is not in the graph");if(Infinity!==r[t])throw new Error("Destination node is not in the graph");r[n]=0})(),i().forEach(function(n){o[n]=!0});for(var u=function(){var n,t,u=(t=Infinity,Object.keys(o).forEach(function(e){r[e]<t&&(t=r[e],n=e)}),void 0===n?(o={},null):(delete o[n],n));if(null===u)return{v:void 0};c(u).forEach(function(n){!function(n,t){var o=s(n,t);r[t]>r[n]+o&&(r[t]=r[n]+o,e[t]=n)}(u,n)})};0!==Object.keys(o).length;){var f=u();if("object"==typeof f)return f.v}}(),function(){for(var r=[],o=0,u=t;e[u];)r.push(u),o+=s(e[u],u),u=e[u];if(u!==n)throw new Error("No path found");return r.push(u),r.reverse(),r.weight=o,r}()},serialize:function(){var n={nodes:i().map(function(n){return{id:n}}),links:[]};return n.nodes.forEach(function(t){var r=t.id;c(r).forEach(function(t){n.links.push({source:r,target:t,weight:s(r,t)})})}),n},deserialize:d},r={},e={};function o(n){return r[n]=c(n),t}function i(){var n={};return Object.keys(r).forEach(function(t){n[t]=!0,r[t].forEach(function(t){n[t]=!0})}),Object.keys(n)}function c(n){return r[n]||[]}function f(n,t){return n+"|"+t}function a(n,r,o){return e[f(n,r)]=o,t}function s(n,t){var r=e[f(n,t)];return void 0===r?1:r}function h(n,r,e){return o(n),o(r),c(n).push(r),void 0!==e&&a(n,r,e),t}function p(n,e){return r[n]&&(r[n]=c(n).filter(function(n){return n!==e})),t}function l(n,t,r){void 0===t&&(t=!0),void 0===r&&(r=!1),n||(n=i()),"boolean"!=typeof t&&(t=!0);var e={},o={},f=[];function a(n){if(o[n]&&r)throw new u("Cycle found");e[n]||(e[n]=!0,o[n]=!0,c(n).forEach(a),o[n]=!1,f.push(n))}return t?n.forEach(a):(n.forEach(function(n){e[n]=!0}),n.forEach(function(n){c(n).forEach(a)})),f}function d(n){return n.nodes.forEach(function(n){o(n.id)}),n.links.forEach(function(n){h(n.source,n.target,n.weight)}),t}return n&&d(n),t}export{u as CycleError,i as Graph,i as default}; | ||
function t(n){return t=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(t){return t.__proto__||Object.getPrototypeOf(t)},t(n)}function n(t,r){return n=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,n){return t.__proto__=n,t},n(t,r)}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 e(t,o,u){return e=r()?Reflect.construct.bind():function(t,r,e){var o=[null];o.push.apply(o,r);var u=new(Function.bind.apply(t,o));return e&&n(u,e.prototype),u},e.apply(null,arguments)}function o(r){var u="function"==typeof Map?new Map:void 0;return o=function(r){if(null===r||-1===Function.toString.call(r).indexOf("[native code]"))return r;if("function"!=typeof r)throw new TypeError("Super expression must either be null or a function");if(void 0!==u){if(u.has(r))return u.get(r);u.set(r,o)}function o(){return e(r,arguments,t(this).constructor)}return o.prototype=Object.create(r.prototype,{constructor:{value:o,enumerable:!1,writable:!0,configurable:!0}}),n(o,r)},o(r)}var u=/*#__PURE__*/function(t){var r,e;function o(n){var r;return r=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}(r),o.prototype),r}return e=t,(r=o).prototype=Object.create(e.prototype),r.prototype.constructor=r,n(r,e),o}(/*#__PURE__*/o(Error));function i(t){var n={addNode:o,removeNode:function(t){return Object.keys(r).forEach(function(n){r[n].forEach(function(r){r===t&&p(n,r)})}),delete r[t],n},nodes:i,adjacent:c,addEdge:s,removeEdge:p,hasEdge:l,setEdgeWeight:a,getEdgeWeight:h,indegree:function(t){var n=0;function e(r){r===t&&n++}return Object.keys(r).forEach(function(t){r[t].forEach(e)}),n},outdegree:function(t){return t in r?r[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 r=[],e=[];return function t(o,u){return!!o[u]||(o[u]=!0,r.push(u),u==n?(e.push(u),!1):c(u).every(function(n){return t(o,n)}))}({},t)&&function t(n,o){n[o]||(n[o]=!0,r.indexOf(o)>=0?e.push(o):0==e.length&&c(o).forEach(function(r){t(n,r)}))}({},n),e},topologicalSort:function(t,n){return void 0===n&&(n=!0),d(t,n,!0).reverse()},shortestPath:v,shortestPaths:function(t,n){for(var r=v(t,n),e=[r],o=[],u=r.weight;u;){var i=r[0],c=r[1];l(i,c)&&(o.push({u:i,v:c,weight:h(i,c)}),p(i,c)),l(c,i)&&(o.push({u:c,v:i,weight:h(c,i)}),p(c,i));try{if(!(r=v(t,n)).weight||u<r.weight)break;e.push(r)}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 e},serialize:function(){var t={nodes:i().map(function(t){return{id:t}}),links:[]};return t.nodes.forEach(function(n){var r=n.id;c(r).forEach(function(n){t.links.push({source:r,target:n,weight:h(r,n)})})}),t},deserialize:y},r={},e={};function o(t){return r[t]=c(t),n}function i(){var t={};return Object.keys(r).forEach(function(n){t[n]=!0,r[n].forEach(function(n){t[n]=!0})}),Object.keys(t)}function c(t){return r[t]||[]}function f(t,n){return t+"|"+n}function a(t,r,o){return e[f(t,r)]=o,n}function h(t,n){var r=e[f(t,n)];return void 0===r?1:r}function s(t,r,e){return o(t),o(r),c(t).push(r),void 0!==e&&a(t,r,e),n}function p(t,e){return r[t]&&(r[t]=c(t).filter(function(t){return t!==e})),n}function l(t,n){return c(t).includes(n)}function d(t,n,r){void 0===n&&(n=!0),void 0===r&&(r=!1),t||(t=i()),"boolean"!=typeof n&&(n=!0);var e={},o={},f=[];function a(t){if(o[t]&&r)throw new u("Cycle found");e[t]||(e[t]=!0,o[t]=!0,c(t).forEach(a),o[t]=!1,f.push(t))}return n?t.forEach(a):(t.forEach(function(t){e[t]=!0}),t.forEach(function(t){c(t).forEach(a)})),f}function v(t,n){var r={},e={},o={};return function(){!function(){if(i().forEach(function(t){r[t]=Infinity}),Infinity!==r[t])throw new Error("Source node is not in the graph");if(Infinity!==r[n])throw new Error("Destination node is not in the graph");r[t]=0}(),i().forEach(function(t){o[t]=!0});for(var u=function(){var t,n,u=(n=Infinity,Object.keys(o).forEach(function(e){r[e]<n&&(n=r[e],t=e)}),void 0===t?(o={},null):(delete o[t],t));if(null===u)return{v:void 0};c(u).forEach(function(t){!function(t,n){var o=h(t,n);r[n]>r[t]+o&&(r[n]=r[t]+o,e[n]=t)}(u,t)})};0!==Object.keys(o).length;){var f=u();if("object"==typeof f)return f.v}}(),function(){for(var r=[],o=0,u=n;e[u];)r.push(u),o+=h(e[u],u),u=e[u];if(u!==t)throw new Error("No path found");return r.push(u),r.reverse(),r.weight=o,r}()}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}export{u as CycleError,i as Graph,i as default}; | ||
//# sourceMappingURL=index.module.js.map |
@@ -1,2 +0,2 @@ | ||
!function(n,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((n||self).graphDataStructure={})}(this,function(n){function t(n){return t=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(n){return n.__proto__||Object.getPrototypeOf(n)},t(n)}function e(n,t){return e=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(n,t){return n.__proto__=t,n},e(n,t)}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(n){return!1}}function o(n,t,i){return o=r()?Reflect.construct.bind():function(n,t,r){var o=[null];o.push.apply(o,t);var i=new(Function.bind.apply(n,o));return r&&e(i,r.prototype),i},o.apply(null,arguments)}function i(n){var r="function"==typeof Map?new Map:void 0;return i=function(n){if(null===n||-1===Function.toString.call(n).indexOf("[native code]"))return n;if("function"!=typeof n)throw new TypeError("Super expression must either be null or a function");if(void 0!==r){if(r.has(n))return r.get(n);r.set(n,i)}function i(){return o(n,arguments,t(this).constructor)}return i.prototype=Object.create(n.prototype,{constructor:{value:i,enumerable:!1,writable:!0,configurable:!0}}),e(i,n)},i(n)}var u=/*#__PURE__*/function(n){var t,r;function o(t){var e;return e=n.call(this,t)||this,Object.setPrototypeOf(function(n){if(void 0===n)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return n}(e),o.prototype),e}return r=n,(t=o).prototype=Object.create(r.prototype),t.prototype.constructor=t,e(t,r),o}(/*#__PURE__*/i(Error));function c(n){var t={addNode:o,removeNode:function(n){return Object.keys(e).forEach(function(t){e[t].forEach(function(e){e===n&&p(t,e)})}),delete e[n],t},nodes:i,adjacent:c,addEdge:h,removeEdge:p,hasEdge:function(n,t){return c(n).includes(t)},setEdgeWeight:a,getEdgeWeight:s,indegree:function(n){var t=0;function r(e){e===n&&t++}return Object.keys(e).forEach(function(n){e[n].forEach(r)}),t},outdegree:function(n){return n in e?e[n].length:0},depthFirstSearch:d,hasCycle:function(){try{return d(void 0,!0,!0),!1}catch(n){if(n instanceof u)return!0;throw n}},lowestCommonAncestors:function(n,t){var e=[],r=[];return function n(o,i){return!!o[i]||(o[i]=!0,e.push(i),i==t?(r.push(i),!1):c(i).every(function(t){return n(o,t)}))}({},n)&&function n(t,o){t[o]||(t[o]=!0,e.indexOf(o)>=0?r.push(o):0==r.length&&c(o).forEach(function(e){n(t,e)}))}({},t),r},topologicalSort:function(n,t){return void 0===t&&(t=!0),d(n,t,!0).reverse()},shortestPath:function(n,t){var e={},r={},o={};return function(){(function(){if(i().forEach(function(n){e[n]=Infinity}),Infinity!==e[n])throw new Error("Source node is not in the graph");if(Infinity!==e[t])throw new Error("Destination node is not in the graph");e[n]=0})(),i().forEach(function(n){o[n]=!0});for(var u=function(){var n,t,i=(t=Infinity,Object.keys(o).forEach(function(r){e[r]<t&&(t=e[r],n=r)}),void 0===n?(o={},null):(delete o[n],n));if(null===i)return{v:void 0};c(i).forEach(function(n){!function(n,t){var o=s(n,t);e[t]>e[n]+o&&(e[t]=e[n]+o,r[t]=n)}(i,n)})};0!==Object.keys(o).length;){var f=u();if("object"==typeof f)return f.v}}(),function(){for(var e=[],o=0,i=t;r[i];)e.push(i),o+=s(r[i],i),i=r[i];if(i!==n)throw new Error("No path found");return e.push(i),e.reverse(),e.weight=o,e}()},serialize:function(){var n={nodes:i().map(function(n){return{id:n}}),links:[]};return n.nodes.forEach(function(t){var e=t.id;c(e).forEach(function(t){n.links.push({source:e,target:t,weight:s(e,t)})})}),n},deserialize:l},e={},r={};function o(n){return e[n]=c(n),t}function i(){var n={};return Object.keys(e).forEach(function(t){n[t]=!0,e[t].forEach(function(t){n[t]=!0})}),Object.keys(n)}function c(n){return e[n]||[]}function f(n,t){return n+"|"+t}function a(n,e,o){return r[f(n,e)]=o,t}function s(n,t){var e=r[f(n,t)];return void 0===e?1:e}function h(n,e,r){return o(n),o(e),c(n).push(e),void 0!==r&&a(n,e,r),t}function p(n,r){return e[n]&&(e[n]=c(n).filter(function(n){return n!==r})),t}function d(n,t,e){void 0===t&&(t=!0),void 0===e&&(e=!1),n||(n=i()),"boolean"!=typeof t&&(t=!0);var r={},o={},f=[];function a(n){if(o[n]&&e)throw new u("Cycle found");r[n]||(r[n]=!0,o[n]=!0,c(n).forEach(a),o[n]=!1,f.push(n))}return t?n.forEach(a):(n.forEach(function(n){r[n]=!0}),n.forEach(function(n){c(n).forEach(a)})),f}function l(n){return n.nodes.forEach(function(n){o(n.id)}),n.links.forEach(function(n){h(n.source,n.target,n.weight)}),t}return n&&l(n),t}n.CycleError=u,n.Graph=c,n.default=c}); | ||
!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 |
{ | ||
"name": "graph-data-structure", | ||
"version": "3.3.0", | ||
"version": "3.5.0", | ||
"description": "A graph data structure with topological sort.", | ||
@@ -55,10 +55,10 @@ "files": [ | ||
"devDependencies": { | ||
"@types/node": "18.15.11", | ||
"@types/node": "20.10.3", | ||
"graph-diagrams": "0.5.0", | ||
"microbundle": "0.15.1", | ||
"mocha": "10.2.0", | ||
"prettier": "2.8.7", | ||
"release-it": "15.10.0", | ||
"typescript": "5.0.3" | ||
"prettier": "3.1.0", | ||
"release-it": "17.0.0", | ||
"typescript": "5.3.2" | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
109683
116