How to use the graphlib/lib/alg.isAcyclic function in graphlib

To help you get started, we’ve selected a few graphlib examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github trufflesuite / truffle / packages / truffle-core / lib / profiler.js View on Github external
function() {
      // Check for cycles in the graph, the dependency graph needs to be a tree otherwise there's an error
      if (!isAcyclic(dependsGraph)) {
        var errorMessage = "Found cyclic dependencies. Adjust your import statements to remove cycles.\n\n";
        dependsGraph.edges().forEach(function(o){
          errorMessage += o.v + " -- depends on --> " + o.w + "\n";
        });
        return callback(new CompileError(errorMessage));
      }
      callback(null, dependsGraph)
    });
  },
github uzyn / web3-loader / index.js View on Github external
for (var i = 0; i < contracts.length; i++) {
    var contract = contracts[i];
    var contractName = contract.name;
    if (!g.hasNode(contractName)) {
      g.setNode(contractName);
    }

    var deps = getDependencies(contract);
    for (var j = 0; j < deps.length; j++) {
      var depName = deps[j];
      if (!g.hasNode(depName)) {
        g.setNode(depName);
      }

      g.setEdge(contractName, depName);
      if (!GraphAlgorithms.isAcyclic(g)) {
        throw new Error('Dependency ' + contractName + ' -> ' + depName + ' inroduces cycle');
      }
    }
  }
  return g;
}