Method: RGL::Graph#edges_filtered_by

Defined in:
lib/rgl/implicit.rb

#edges_filtered_by(&filter) ⇒ ImplicitGraph

Returns a new ImplicitGraph which has as edges all edges of the receiver which satisfy the predicate filter (a block with two parameters).

Examples:


g = complete(7).edges_filtered_by { |u,v| u+v == 7 }
g.to_s     => "(1=6)(2=5)(3=4)"
g.vertices => [1, 2, 3, 4, 5, 6, 7]

Returns:



146
147
148
149
150
151
152
153
154
155
156
157
158
# File 'lib/rgl/implicit.rb', line 146

def edges_filtered_by(&filter)
  implicit_graph do |g|
    g.adjacent_iterator do |v, b|
      self.each_adjacent(v) do |u|
        b.call(u) if filter.call(v, u)
      end
    end

    g.edge_iterator do |b|
      self.each_edge { |u, v| b.call(u, v) if filter.call(u, v) }
    end
  end
end