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

ngraph.coarsen

Package Overview
Dependencies
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ngraph.coarsen - npm Package Compare versions

Comparing version 1.0.2 to 1.1.0

26

index.js

@@ -33,2 +33,28 @@ var createGraph = require('ngraph.graph');

var isolateNodes = new Set();
var isolateCommunityId;
srcGraph.forEachNode(function(node) {
// if node is islate the forEachLink will never visit it, which means
// its community class is never added to the graph:
var nodeCommunity = community.getClass(node.id);
if (graph.getNode(nodeCommunity)) {
// this was not an isolate. Ignore;
return;
}
if (isolateCommunityId === undefined) {
// we don't care which node will represent isolated community.
isolateCommunityId = node.id;
}
isolateNodes.add(node.id);
});
if (isolateNodes.size > 0) {
// Each node in the isolated noes has no links. So they all belong to the
// same community. We take arbitrary node from this class and assign them
// all to the same community:
graph.addNode(isolateCommunityId, isolateNodes);
}
return graph;

@@ -35,0 +61,0 @@

2

package.json
{
"name": "ngraph.coarsen",
"version": "1.0.2",
"version": "1.1.0",
"description": "Given a community structure creates a coarse graph",

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

@@ -62,3 +62,3 @@ var coarsen = require('../');

t.equals(newGraph.getLinksCount(), 3, 'There should be two links');
t.equals(newGraph.getLinksCount(), 3, 'There should be three links');
t.equals(newGraph.getNodesCount(), 2, 'There are two nodes: even and odd');

@@ -86,1 +86,27 @@

});
test('it can handle isolate nodes', function(t) {
var srcGraph = createGraph();
srcGraph.addLink(1, 2);
srcGraph.addNode(3);
srcGraph.addNode(4);
var fakeCommunity = {
getClass: function getClass(nodeId) {
// now we pretend that if nodes are odd - they belong to the same community:
return (nodeId < 3) ? 1 : 2;
}
}
var newGraph = coarsen(srcGraph, fakeCommunity);
var selfLink = newGraph.getLink(1, 1);
t.equals(newGraph.getLinksCount(), 1, 'There should be one link');
t.ok(selfLink, 'and that is self link');
// the isolate nodes are assigned at random:
var node = newGraph.getNode(3) || newGraph.getNode(4);
t.equals(newGraph.getNodesCount(), 2, 'There are two nodes');
t.ok(node.data.has(3) && node.data.has(4), 'The isolate community lits all nodes');
t.end();
});
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