Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

js-graph

Package Overview
Dependencies
Maintainers
1
Versions
19
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

js-graph - npm Package Compare versions

Comparing version 0.4.0 to 0.4.1

2

bower.json
{
"name": "js-graph",
"version": "0.4.0",
"version": "0.4.1",
"description": "a javascript library for storing arbitrary data in mathematical (di)graphs, as well as traversing and analyzing them in various ways",

@@ -5,0 +5,0 @@ "ignore": [

@@ -1,3 +0,3 @@

/* js-graph - v0.3.0 - 2014-10-18 */
/* js-graph - v0.4.0 - 2014-12-27 */
"use strict";!function(a,b,c){"function"==typeof define&&define.amd?define([],c):"object"==typeof exports?module.exports=c():a[b]=c()}(this,"JsGraph",function(){function a(){var b=this,d={},e={},f={},g=0,h=0,i=new c,j=new c;b.onAddVertex=i.add,b.onRemoveVertex=j.add,b.addNewVertex=function(c,h){if(b.hasVertex(c))throw new a.VertexExistsError(c,d[c]);d[c]=h,e[c]={},f[c]={},g+=1,i.fire(c,h)},b.setVertex=function(c,e){if(!b.hasVertex(c))throw new a.VertexNotExistsError(c);d[c]=e},b.ensureVertex=function(a,c){b.hasVertex(a)||b.addNewVertex(a,c)},b.addVertex=function(a,c){b.hasVertex(a)?b.setVertex(a,c):b.addNewVertex(a,c)},b.removeExistingVertex=function(c){if(!b.hasVertex(c))throw new a.VertexNotExistsError(c);if(Object.keys(e[c]).length)throw new a.HasConnectedEdgesError(c);if(Object.keys(f[c]).length)throw new a.HasConnectedEdgesError(c);var h=d[c];delete d[c],g-=1,j.fire(c,h)},b.destroyExistingVertex=function(c){if(!b.hasVertex(c))throw new a.VertexNotExistsError(c);b.eachVertexFrom(c,function(a){b.removeEdge(c,a)}),b.eachVertexTo(c,function(a){b.removeEdge(a,c)}),b.removeExistingVertex(c)},b.removeVertex=function(a){b.hasVertex(a)&&b.removeExistingVertex(a)},b.destroyVertex=function(a){b.hasVertex(a)&&b.destroyExistingVertex(a)};var k=new c,l=new c;b.onAddEdge=k.add,b.onRemoveEdge=l.add,b.addNewEdge=function(c,d,g){if(b.hasEdge(c,d))throw new a.EdgeExistsError(c,d,b.edgeValue(c,d));if(!b.hasVertex(c))throw b.hasVertex(d)?new a.VertexNotExistsError(c):new a.VertexNotExistsError(c).v(d);if(!b.hasVertex(d))throw new a.VertexNotExistsError(d);e[c][d]=g,f[d][c]=null,h+=1,k.fire(c,d,g)},b.createNewEdge=function(c,d,e){if(b.hasEdge(c,d))throw new a.EdgeExistsError(c,d,b.edgeValue(c,d));b.ensureVertex(c),b.ensureVertex(d),b.addNewEdge(c,d,e)},b.setEdge=function(c,d,f){if(!b.hasEdge(c,d))throw new a.EdgeNotExistsError(c,d);e[c][d]=f},b.spanEdge=function(c,d,e){if(!b.hasVertex(c))throw b.hasVertex(d)?new a.VertexNotExistsError(c):new a.VertexNotExistsError(c).v(d);if(!b.hasVertex(d))throw new a.VertexNotExistsError(d);b.hasEdge(c,d)||b.addNewEdge(c,d,e)},b.addEdge=function(a,c,d){b.hasEdge(a,c)?b.setEdge(a,c,d):b.addNewEdge(a,c,d)},b.ensureEdge=function(a,c,d){b.hasEdge(a,c)||b.createNewEdge(a,c,d)},b.createEdge=function(a,c,d){b.hasEdge(a,c)?b.setEdge(a,c,d):b.createNewEdge(a,c,d)},b.removeExistingEdge=function(c,d){if(!b.hasEdge(c,d))throw new a.EdgeNotExistsError(c,d);var g=e[c][d];delete e[c][d],delete f[d][c],h-=1,l.fire(c,d,g)},b.removeEdge=function(a,c){b.hasEdge(a,c)&&b.removeExistingEdge(a,c)},b.vertexCount=function(){return g},b.hasVertex=function(a){return a in d},b.vertexValue=function(a){return d[a]},b.edgeCount=function(){return h},b.hasEdge=function(a,c){return b.hasVertex(a)&&b.hasVertex(c)&&a in e&&c in e[a]},b.edgeValue=function(a,c){return b.hasEdge(a,c)?e[a][c]:void 0},b.successors=function(c){if(!b.hasVertex(c))throw new a.VertexNotExistsError(c);return Object.keys(e[c])},b.predecessors=function(c){if(!b.hasVertex(c))throw new a.VertexNotExistsError(c);return Object.keys(f[c])},b.eachVertex=function(a){Object.keys(d).every(function(b){var c=a(b,d[b]);return c!==!1})},b.eachVertexFrom=function(c,d){if(!b.hasVertex(c))throw new a.VertexNotExistsError(c);Object.keys(e[c]).every(function(a){var e=d(a,b.vertexValue(a),b.edgeValue(c,a));return e!==!1})},b.eachVertexTo=function(c,d){if(!b.hasVertex(c))throw new a.VertexNotExistsError(c);Object.keys(f[c]).every(function(a){var e=d(a,b.vertexValue(a),b.edgeValue(a,c));return e!==!1})},b.eachEdge=function(a){Object.keys(e).every(function(b){return Object.keys(e[b]).every(function(c){var d=a(b,c,e[b][c]);return d!==!1})})},b.clearEdges=function(){b.eachEdge(b.removeEdge)},b.clear=function(){b.eachVertex(b.destroyVertex)},b.hasCycle=function(){function a(f){return c[f]?void(e=!0):void(d[f]||(d[f]=!0,c[f]=!0,b.eachVertexFrom(f,function(b){return a(b),e?!1:void 0}),c[f]=!1))}var c={},d={},e=!1;return b.eachVertex(function(b){return a(b),e?!1:void 0}),e},b.hasPath=function(a,c){function d(a){if(b.hasEdge(a,c))return!0;e[a]=!0;var f=!1;return b.eachVertexFrom(a,function(a){f||e[a]||!d(a)||(f=!0)}),delete e[a],f}if(!b.hasVertex(a)||!b.hasVertex(c))return!1;var e={};return d(a)},b.topologically=function(c){function d(g){e.push(g);var h=e.indexOf(g);if(h!==e.length-1){var i=e.slice(h+1).reverse();throw new a.CycleError(i)}f[g]||(b.eachVertexTo(g,d),f[g]={returned:c(g,b.vertexValue(g))}),e.pop()}var e=[],f={};b.eachVertex(function(a){f[a]||d(a)})},b.transitiveReduction=function(){var c=new a;return b.eachVertex(function(a,b){c.addVertex(a,b)}),b.eachEdge(function(a,b,d){c.addEdge(a,b,d)}),c.eachVertex(function(a){c.eachVertex(function(b){c.hasEdge(a,b)&&c.eachVertex(function(d){c.hasPath(b,d)&&c.removeEdge(a,d)})})}),c}}function b(a,b,c,d){"undefined"==typeof a[b]&&(a[b]={}),a[b][c]=d}function c(){var a=[];this.add=function(b){return-1===a.indexOf(b)&&a.push(b),function(){var c=a.indexOf(b);-1!==c&&a.splice(c,1)}},this.fire=function(){var b=arguments;a.forEach(function(a){a.apply(null,b)})}}function d(a,b){return b.prototype.__proto__=Error.prototype,b.prototype.constructor=b,b.prototype.name=a,b}return a.VertexExistsError=d("VertexExistsError",function(a,b){function c(){d.message="This graph has "+(1===d.vertices?"a vertex":"vertices")+" '"+Object.keys(d.vertices).join("', '")+"'"}var d=this;d.v=function(a,b){return d.vertices[a]=b,c(),d},d.vertices={},d.v(a,b),c()}),a.VertexNotExistsError=d("VertexNotExistError",function(a){function b(){c.message="This graph does not have "+(1===c.vertices?"a vertex":"vertices")+" '"+Object.keys(c.vertices).join("', '")+"'"}var c=this;c.v=function(a){return c.vertices[a]=void 0,b(),c},c.vertices={},c.v(a),b()}),a.EdgeExistsError=d("EdgeExistsError",function(a,c,d){function e(){var a=[];Object.keys(f.edges).forEach(function(b){Object.keys(f.edges[b]).forEach(function(c){a.push("('"+b+"', '"+c+"')")})}),f.message="This graph has "+(1===a.length?"an edge ":"edges ")+a.join(", ")}var f=this;f.e=function(a,c,d){return b(f.edges,a,c,d),e(),f},f.edges={},f.e(a,c,d),e()}),a.EdgeNotExistsError=d("EdgeNotExistError",function(a,c){function d(){var a=[];Object.keys(e.edges).forEach(function(b){Object.keys(e.edges[b]).forEach(function(c){a.push("('"+b+"', '"+c+"')")})}),e.message="This graph does not have "+(1===a.length?"an edge ":"edges ")+a.join(", ")}var e=this;e.e=function(a,c){return b(e.edges,a,c,void 0),d(),e},e.edges={},e.e(a,c),d()}),a.HasConnectedEdgesError=d("HasConnectedEdgesError",function(a){this.message="The '"+a+"' vertex has connected edges",this.key=a}),a.CycleError=d("CycleError",function(a){this.message="This graph contains a cycle: "+a,this.cycle=a}),a});
//# sourceMappingURL=js-graph.min.js.map
{
"name": "js-graph",
"version": "0.4.0",
"version": "0.4.1",
"title": "Javascript Graph Datastructure",

@@ -5,0 +5,0 @@ "homepage": "https://github.com/mhelvens/js-graph",

@@ -1550,4 +1550,6 @@ 'use strict';

it("returns a new graph with the same reachability as the original", function () {
graph.eachEdge(function (from, to) {
expect(newGraph.hasPath(from, to)).toBeTruthy();
graph.eachVertex(function (from) {
graph.eachVertex(function (to) {
expect(graph.hasPath(from, to)).toEqual(newGraph.hasPath(from, to));
});
});

@@ -1554,0 +1556,0 @@ });

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc