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

graphs-all

Package Overview
Dependencies
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

graphs-all - npm Package Compare versions

Comparing version 0.0.1 to 0.1.0

2

package.json
{
"name": "graphs-all",
"version": "0.0.1",
"version": "0.1.0",
"description": "Graph Data Structure Library",

@@ -5,0 +5,0 @@ "main": "src/index.js",

@@ -1,14 +0,66 @@

function Graph() {
var counterId = 0;
var keyToIdTable = {};
this.nodes = [];
function Node(key, value) {
this.key = key;
this.value = value;
}
function Graph(isDirected, isWeighted) {
isDirected = isDirected || false;
isWeighted = isWeighted || false;
var counterId = 0,
keyToIdTable = {};
this.nodes = {};
this.links = {};
this.addNode = function(key, value) {
if (keyToIdTable[key] === undefined) {
var id = counterId++;
keyToIdTable[key] = id;
this.nodes[id] = new Node(key, value);
this.links[id] = {};
return true;
}
return false;
};
this.addLink = function(key1, key2, weight) {
if (!isWeighted || weight === undefined) {
weight = 1;
}
if (isNaN(weight)) {
throw "Weight must be a number";
}
var id1 = keyToIdTable[key1],
id2 = keyToIdTable[key2];
if (id1 === undefined) {
throw "'" + key1 + "' is not found."
}
if (id2 === undefined) {
throw "'" + key2 + "' is not found."
}
this.links[id1][id2] = weight;
if (!isDirected) {
this.links[id2][id1] = weight;
}
};
this.hasNode = function(key) {
return keyToIdTable[key] !== undefined;
};
this.hasLink = function(key1, key2) {
return this.hasNode(key1) && this.hasNode(key2) && this.links[key1][key2] !== undefined;
}
}
function emptyGraph() {
return new Graph();
function createGraph(isDirected, isWeighted) {
return function(){
return new Graph(isDirected, isWeighted);
};
}
module.exports = {
emptyGraph: emptyGraph
Graph: Graph,
createGraph: createGraph
};

@@ -6,3 +6,6 @@ "use strict";

module.exports = {
emptyGraph: graph.emptyGraph
UndirectedUnweightedGraph: graph.createGraph(false, false),
DirectedUnweightedGraph: graph.createGraph(true, false),
DirectedWeightedGraph: graph.createGraph(true, true),
UndirectedWeightedGraph: graph.createGraph(false, true)
};

Sorry, the diff of this file is not supported yet

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