Skip to content

Commit

Permalink
Performance improvement
Browse files Browse the repository at this point in the history
while connecting components (use merge function instead of union)
  • Loading branch information
hasanbalci committed Sep 30, 2019
1 parent e103493 commit 7b77a3e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
10 changes: 6 additions & 4 deletions cytoscape-fcose.js
Original file line number Diff line number Diff line change
Expand Up @@ -721,7 +721,8 @@ var spectralLayout = function spectralLayout(options) {

var _loop = function _loop() {
var currentNode = topMostNodes[0];
var childrenOfCurrentNode = currentNode.union(currentNode.descendants());
var childrenOfCurrentNode = cy.collection();
childrenOfCurrentNode.merge(currentNode).merge(currentNode.descendants());
visitedTopMostNodes.push(currentNode);

childrenOfCurrentNode.forEach(function (node) {
Expand All @@ -736,7 +737,7 @@ var spectralLayout = function spectralLayout(options) {
var neighborNodes = cy.collection();
currentNode.neighborhood().nodes().forEach(function (node) {
if (eles.contains(currentNode.edgesWith(node))) {
neighborNodes = neighborNodes.union(node);
neighborNodes.merge(node);
}
});

Expand Down Expand Up @@ -776,9 +777,10 @@ var spectralLayout = function spectralLayout(options) {
});
nodesConnectedToDummy.push(minDegreeNode.id());
// TO DO: Check efficiency of this part
var temp = visitedTopMostNodes[0];
var temp = cy.collection();
temp.merge(visitedTopMostNodes[0]);
visitedTopMostNodes.forEach(function (node) {
temp = temp.union(node);
temp.merge(node);
});
visitedTopMostNodes = [];
topMostNodes = topMostNodes.difference(temp);
Expand Down
10 changes: 6 additions & 4 deletions src/fcose/spectral.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,8 @@ let spectralLayout = function(options){

do{
let currentNode = topMostNodes[0];
let childrenOfCurrentNode = currentNode.union(currentNode.descendants());
let childrenOfCurrentNode = cy.collection();
childrenOfCurrentNode.merge(currentNode).merge(currentNode.descendants());
visitedTopMostNodes.push(currentNode);

childrenOfCurrentNode.forEach(function(node) {
Expand All @@ -93,7 +94,7 @@ let spectralLayout = function(options){
let neighborNodes = cy.collection();
currentNode.neighborhood().nodes().forEach(function(node){
if(eles.contains(currentNode.edgesWith(node))){
neighborNodes = neighborNodes.union(node);
neighborNodes.merge(node);
}
});

Expand Down Expand Up @@ -130,9 +131,10 @@ let spectralLayout = function(options){
});
nodesConnectedToDummy.push(minDegreeNode.id());
// TO DO: Check efficiency of this part
let temp = visitedTopMostNodes[0];
let temp = cy.collection();
temp.merge(visitedTopMostNodes[0]);
visitedTopMostNodes.forEach(function(node){
temp = temp.union(node);
temp.merge(node);
});
visitedTopMostNodes = [];
topMostNodes = topMostNodes.difference(temp);
Expand Down

0 comments on commit 7b77a3e

Please sign in to comment.