lib/rgl/adjacency.rb in rgl-0.3.1 vs lib/rgl/adjacency.rb in rgl-0.4.0

- old
+ new

@@ -1,8 +1,8 @@ # adjacency.rb # -# $Id: adjacency.rb,v 1.11 2008/03/02 13:45:43 monora Exp $ +# $Id: adjacency.rb,v 1.12 2008/08/23 05:37:05 javanthropus Exp $ # # The DirectedAdjacencyGraph class implements a generalized adjacency list # graph structure. An AdjacencyGraph is basically a two-dimensional structure # (ie, a list of lists). Each element of the first dimension represents a # vertex. Each of the vertices contains a one-dimensional structure that is @@ -171,9 +171,10 @@ # Convert a general graph to an AdjacencyGraph. If the graph is directed, # returns a DirectedAdjacencyGraph; otherwise, returns an AdjacencyGraph. def to_adjacency result = (directed? ? DirectedAdjacencyGraph : AdjacencyGraph).new + each_vertex { |v| result.add_vertex(v) } each_edge { |u,v| result.add_edge(u, v) } result end # Return a new DirectedAdjacencyGraph which has the same set of vertices.