class EmailGraph::UndirectedGraph
Public Class Methods
new()
click to toggle source
# File lib/email_graph/undirected_graph.rb, line 5 def initialize @store = {} end
Public Instance Methods
add_edge(e)
click to toggle source
Adds an edge and associated vertices if they don’t already exist and returns the edge
# File lib/email_graph/undirected_graph.rb, line 36 def add_edge(e) v, w = *e.vertices edge(v, w) || e.vertices.each{ |v| add_vertex(v); @store[v].add(e)} end
add_vertex(v)
click to toggle source
Adds a vertex if it doesn’t already exist and returns it
# File lib/email_graph/undirected_graph.rb, line 30 def add_vertex(v) @store[v] ||= Set.new end
edge(v, w)
click to toggle source
A specific edge from v
to w
# File lib/email_graph/undirected_graph.rb, line 20 def edge(v, w) (@store[v] || []).find{ |e| e.vertices.include?(w) } end
edges()
click to toggle source
All edges
# File lib/email_graph/undirected_graph.rb, line 15 def edges @store.values.to_set.flatten end
edges_with(v)
click to toggle source
Edges involving a vertex v
# File lib/email_graph/undirected_graph.rb, line 25 def edges_with(v) @store[v] end
vertices()
click to toggle source
All vertices
# File lib/email_graph/undirected_graph.rb, line 10 def vertices @store.keys end