Permalink
Browse files

Documentation for directed graph

  • Loading branch information...
1 parent c4d092b commit 8abfce5a6901f77959c54a9c581c9a86cd975fe3 @retiman committed Jun 9, 2010
Showing with 5 additions and 0 deletions.
  1. +5 −0 lib/jsdm/directed_graph.rb
@@ -1,4 +1,7 @@
class JSDM
+ # Very simple class to represent a directed graph using adjacency lists.
+ # See http://en.wikipedia.org/wiki/Digraph_(mathematics)
+ # See http://en.wikipedia.org/wiki/Adjacency_list
class DirectedGraph
attr_accessor :nodes, :arcs
private :nodes=, :arcs=
@@ -8,6 +11,8 @@ def initialize(nodes, arcs)
self.arcs = arcs
end
+ # Returns a list of nodes that are in the tail of an arc whose head
+ # is the given node.
def successors(node)
arcs.select { |a| a.first == node }.map { |a| a.last }
end

0 comments on commit 8abfce5

Please sign in to comment.