Adds a circular flag to the load object of cyclic dependencies

MUTATES THE GRAPH

@param {Object} graph - The graph to check
494235
function flagCircularDependencies(graph) {
	var includes = require("lodash/includes");
	var nodes = Array.isArray(graph) ? graph : require("lodash/values")(graph);

	for (var i = 0; i < nodes.length; i += 1) {
		var curr = nodes[i];

		for (var j = i + 1; j < nodes.length; j += 1) {
			var next = nodes[j];

			if (
				includes(curr.dependencies, next.load.name) &&
				includes(next.dependencies, curr.load.name)
			) {
				curr.load.circular = true;
				next.load.circular = true;
			}
		}
	}

	return graph;
}
619780
function visit( node, predecessors ) {
                //check if a node is dependent of itself
                if( predecessors.length !== 0 && predecessors.indexOf( node ) !== -1 ) {
                    throw new Error( "Cyclic dependency found. " + node + " is dependent of itself.\nDependency chain: "
                                     + predecessors.join( " -> " ) + " => " + node );
                }

                var index = nodes.indexOf( node );

                //if the node still exists, traverse its dependencies
                if( index !== -1 ) {
                    var copy = false;

                    //mark the node as false to exclude it from future iterations
                    nodes[index] = false;

                    //loop through all edges and follow dependencies of the current node
                    for( var _iterator4 = _this.edges, _isArray4 = Array.isArray( _iterator4 ), _i4 = 0, _iterator4 = _isArray4 ?
                                                                                                                      _iterator4 :
                                                                                                                      _iterator4[Symbol.iterator](); ; ) {
                        var _ref4;

                        if( _isArray4 ) {
                            if( _i4 >= _iterator4.length ) {
                                break;
                            }
                            _ref4 = _iterator4[_i4++];
                        } else {
                            _i4 = _iterator4.next();
                            if( _i4.done ) {
                                break;
                            }
                            _ref4 = _i4.value;
                        }

                        var edge = _ref4;

                        if( edge[0] === node ) {
                            //lazily create a copy of predecessors with the current node concatenated onto it
                            copy = copy || predecessors.concat( [node] );

                            //recurse to node dependencies
                            visit( edge[1], copy );
                        }
                    }

                    //add the node to the next place in the sorted array
                    sorted[--place] = node;
                }
            }
1028715
function(obj) { 
   if(!this.nodes[obj.id]) {  
     var edges = this.edges[obj.id] = {};
     this.nodes[obj.id] = new Graph.Node($.extend({
        'id': obj.id,
        'name': obj.name,
        'data': obj.data || {},
        'adjacencies': edges 
      }, this.opt.Node), 
      this.opt.complex, 
      this.Node, 
      this.Edge,
      this.Label);
    }
    return this.nodes[obj.id];
  }
1332323
function Rug( graph ) {

	// INSTANCE ATTRIBUTES //

	this._parent = graph;
	this._root = undefined;
	this._children = {};
	this._config = {
		"type": "rug",
		"size": 6,
		"labels": []
	};

	// DATA //

	this._data = graph._data;

	// TRANSFORMS //

	this._transforms = {
		'x': function X( d ) {
			return graph._xScale( d[ 0 ] );
		},
		'y': function Y( d ) {
			return d[ 1 ];
		}
	};

	// GENERATOR //

	this._path = this.path()
		.x( this._transforms.x )
		.y( this._transforms.y );

	// REGISTER //
	if ( graph._config.hasOwnProperty( 'marks' ) ) {
		graph._config.marks.push( this._config );
	} else {
		graph._config.marks = [ this._config ];
	}
	if ( graph._children.hasOwnProperty( 'marks' ) ) {
		graph._children.marks.push( this );
	} else {
		graph._children.marks = [ this ];
	}

	return this;
}
687213
def topological_sort(dependencies, start_nodes):
    
    retval = []
    def edges(node): return dependencies[node][1]
    def in_degree(node): return dependencies[node][0]
    def remove_incoming(node): dependencies[node][0] = in_degree(node) - 1
    while start_nodes:
        node = start_nodes.pop()
        retval.append(node)
        for child in edges(node):
            remove_incoming(child)
            if not in_degree(child):
                start_nodes.append(child)
    leftover_nodes = [node for node in list(dependencies.keys())
                      if in_degree(node) > 0]
    if leftover_nodes:
        raise CyclicDependency(leftover_nodes)
    else:
        return retval
1015684
def add_load(self, lv_load):
        
        if lv_load not in self._loads and isinstance(lv_load,
                                                     MVLoadDing0):
            self._loads.append(lv_load)
            self.graph_add_node(lv_load)
860723
function init(app) {
    var keys = Object.keys(DependenciesMap);
    var allDeps = _.uniq(_.flatten(_.values(DependenciesMap)));

    allDeps.forEach(function (d) {
        if (!_.contains(keys, d)) {
            throw new Error("Unresolved dependency: " + d)
        }
    });


    keys.forEach(function (k) {
        var dep = DependenciesMap[k];
        if (_.contains(dep, k)) {
            throw new Error('Circular dependency: key: ' + k);
        }

        if (dep.length == 0) {
            HandlerArray.push(getHandler(app, k, PluginsData[k]));
        }
    });

    async.series(HandlerArray, function (err, end) {
        if (err)
            throw err;

        saveSchemas(app);
    });
}
651920
def add_node(self, graph_node):
        

        if not isinstance(graph_node, Node):
            raise TypeError(
                'add_node() received ' +
                'a non node class object: ' + str(graph_node))


        node = self.get_node(graph_node.get_name())

        if not node:

            self.obj_dict['nodes'][graph_node.get_name()] = [
                graph_node.obj_dict ]

            #self.node_dict[graph_node.get_name()] = graph_node.attributes
            graph_node.set_parent_graph(self.get_parent_graph())

        else:

            self.obj_dict['nodes'][graph_node.get_name()].append(
                graph_node.obj_dict )

        graph_node.set_sequence(self.get_next_sequence_number())
868378
private void throwCircularDependenciesException()
            throws CircularDependenciesException {
        String msg = "Circular dependencies found. Check the circular graph below:\n";
        boolean firstNode = true;
        String tab = "  ";
        for (String visit : visitedInjectNodes) {
            if (!firstNode) {
                msg += tab + "->";
                tab += tab;
            }
            msg += visit + "\n";
            firstNode = false;
        }
        msg += tab.substring(2) + "->" + revisitedNode + "\n";
        throw new CircularDependenciesException(msg);
    }
1136624
public void addNode(RNode newNode) {
        graph.add(newNode);
        graphBitSet.set(graph.size() - 1);
    }
1005615
public void addDependency(final ProcessorGraphNode node) {
        Assert.isTrue(node != this, "A processor can't depends on himself");

        this.dependencies.add(node);
        node.addRequirement(this);
    }
150322
function addNodeToGraph(node){

    gNodesDisplayed.push(node);
    g.addNode(node._id, node);


    if (contains(childrenNodes, node._id)){
        var parentNode = getNodeFromId(nodesToBeLinked[node._id].from);
        if (contains(gNodesDisplayed, parentNode)){
            addLinkToParent(node._id, parentNode._id);
        }
    }
}
1025708
def _detect_circle(nodes=None, dependencies=None, traveled=None, path=None):
    
    # Verify nodes and traveled types
    if nodes is None:
        nodes = {}
    elif not isinstance(nodes, dict):
        raise TypeError('"nodes" must be a dictionary')
    if dependencies is None:
        return
    elif not isinstance(dependencies, set):
        raise TypeError('"dependencies" must be a set')
    if traveled is None:
        traveled = []
    elif not isinstance(traveled, list):
        raise TypeError('"traveled" must be a list')
    if path is None:
        path = []

    if not dependencies:
        # We're at the end of a dependency path.
        return []

    # Recursively iterate over nodes,
    # and gather dependency children nodes.
    children = []
    for name in dependencies:
        # Path is used for circular dependency exceptions
        # to display to the user the circular path.
        new_path = list(path)
        new_path.append(name)

        # Check if we've traveled to this node before.
        if name in traveled:
            raise CircularDependencyException(new_path)

        # Make recursive call
        node_children = _detect_circle(nodes=nodes,
                                       dependencies=nodes[name],
                                       traveled=traveled + list(name),
                                       path=new_path)

        # Create node for this dependency with children.
        node = DependencyNode(name)
        for child in node_children:
            child.parent = node
            node.add_child(child)
        children.append(node)

    return children
1153717
function Graph(directed) {
  this.directed = (directed === undefined ? true : !!directed);
  this.adjList = Object.create(null);
  this.vertices = new HashSet();
}
546209
def add(object)
      key, id = to_key_and_id(object)

      @graph[key] ? @graph[key] << id : @graph[key] = [id]
    end
719366
def _AddEdge(self, start_node, end_node):
    

    self.graph[start_node].outgoing.append(end_node)

    # This check is necessary because an artifact can provide attributes that
    # are not covered by the graph because they are not relevant for the
    # requested artifacts.
    if end_node in self.graph:
      self.graph[end_node].incoming.append(start_node)
30451
protected function addComponent(BaseGraph $graph, $componentId, Node $parentNode = null)
    {
        $component          = $this->graphComponents[$componentId];
        $origComponentClass = $component['class'];

        // If this is a variant: Redirect to the master component
        if ($component['master']) {
            $component      = $component['master'];
            $componentId    = $component['class'];
            $componentLabel = htmlspecialchars($component['label']);

            // Else: This is a master component
        } else {
            $componentLabel = '<b>'.htmlspecialchars($component['label']).'</b>';
        }

        $componentLabel  .= '<br align="left"/>';
        $escaped         = false;
        $dependencyNodes = [];

        if (count($component['variants'])) {
            uasort(
                $component['variants'],
                function(array $variant1, array $variant2) {
                    return strnatcasecmp($variant1['label'], $variant2['label']);
                }
            );

            // Run through all variants
            $variantCount = count($component['variants']);
            foreach (array_values($component['variants']) as $index => $variant) {
                $variantLabel = '• '.htmlspecialchars($variant['label']);
                if ($variant['class'] === $origComponentClass) {
                    $variantLabel = "<b>$variantLabel</b>";
                }
                $componentLabel .= $variantLabel.'<br align="left"/>';
                foreach ($variant['dependencies'] as $dependency) {
                    $dependencyNodes[$dependency['class']] = true;
                }
            }
        }

        $isCurrent = $this->rootComponent === $origComponentClass;

        // Add the component node
        $graph->node(
            $this->getComponentTitle($componentId),
            [
                'label'     => "<$componentLabel>",
                '_escaped'  => $escaped,
                'margin'    => '.15,.15',
                'fillcolor' => self::$colors[$component['type']],
                'penwidth'  => $isCurrent ? 1.5 : .5,
            ]
        );

        // Add an edge from the parent node
        if ($parentNode instanceof Node) {
            $graph->edge(
                [$parentNode->getId(), $this->getComponentTitle($componentId)],
                ['arrowhead' => 'none', 'color' => 'darkgrey', 'penwidth' => .5]
            );
        }

        // Add dependency edges
        foreach ($component['dependencies'] as $dependency) {
            $dependencyNodes[$dependency['master'] ? $dependency['master']['class'] : $dependency['class']] = true;
        }
        foreach (array_keys($dependencyNodes) as $dependencyNode) {
            $graph->edge([$this->getComponentTitle($componentId), $this->getComponentTitle($dependencyNode)]);
        }

        return $graph;
    }