public void MergeVertex(TVertex v, EdgeFactory <TVertex, TEdge> edgeFactory) { Contract.Requires(GraphContract.InVertexSet(this, v)); Contract.Requires(edgeFactory != null); // storing edges in local array var inedges = this.vertexInEdges[v]; var outedges = this.vertexOutEdges[v]; // remove vertex this.RemoveVertex(v); // add edges from each source to each target foreach (var source in inedges) { //is it a self edge if (source.Source.Equals(v)) { continue; } foreach (var target in outedges) { if (v.Equals(target.Target)) { continue; } // we add an new edge this.AddEdge(edgeFactory(source.Source, target.Target)); } } }