Class: GraphMatching::DirectedEdgeSet

Inherits:
Object
  • Object
show all
Defined in:
lib/graph_matching/directed_edge_set.rb

Overview

A ‘DirectedEdgeSet` is simply a set of directed edges in a graph. Whether the graph is actually directed or not is irrelevant, we can still discuss directed edges in an undirected graph.

The naive implementation would be to use ruby’s ‘Set` and RGL’s ‘DirectedEdge`. This class is optimized to use a 2D array instead. The sub-array at index i represents a set (or subset) of vertexes adjacent to i.

Instance Method Summary collapse

Constructor Details

#initialize(graph_size) ⇒ DirectedEdgeSet

Returns a new instance of DirectedEdgeSet.



15
16
17
# File 'lib/graph_matching/directed_edge_set.rb', line 15

def initialize(graph_size)
  @edges = Array.new(graph_size + 1) { [] }
end

Instance Method Details

#add(v, w) ⇒ Object



19
20
21
# File 'lib/graph_matching/directed_edge_set.rb', line 19

def add(v, w)
  edges[v] << w
end

#adjacent_vertices(v) ⇒ Object



23
24
25
# File 'lib/graph_matching/directed_edge_set.rb', line 23

def adjacent_vertices(v)
  edges[v]
end