Skip to content

Commit

Permalink
Nested arrays can be used to create the digraph
Browse files Browse the repository at this point in the history
  • Loading branch information
forforf committed Apr 15, 2011
1 parent 3e0fdb8 commit f16581b
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
5 changes: 5 additions & 0 deletions lib/rgl/adjacency.rb
Expand Up @@ -27,8 +27,13 @@ class DirectedAdjacencyGraph
#
# RGL::DirectedAdjacencyGraph[1,2, 2,3, 2,4, 4,5].edges.to_a.to_s =>
# "(1-2)(2-3)(2-4)(4-5)"
#
# This fork allows input to be of the form:
# RGL::DirectedAdjacencyGraph[ [1,2], [2,3], [2,4], [4,5] ].edges_to_a.to_s
# #=> "(1-2)(2-3)(2-4)(4-5)"

def self.[] (*a)
a.flatten!
result = new
0.step(a.size-1, 2) { |i| result.add_edge(a[i], a[i+1]) }
result
Expand Down
6 changes: 1 addition & 5 deletions lib/rgl/forforf_rgl_adjacency.rb
Expand Up @@ -51,11 +51,7 @@ def in_degree(v)
rdg.out_degree(v)
end

def out_degree(v)
self.adjacent_vertices(v).size
end

#Find nodes with #in_degree of 0
#Find vertices with in degree of 0
#Although roots isn't strictly a digraph term (it's for trees)
#it has the right connotation
def roots
Expand Down

0 comments on commit f16581b

Please sign in to comment.