Method: RGL::Graph#vertices_filtered_by
- Defined in:
- lib/rgl/implicit.rb
#vertices_filtered_by(&filter) ⇒ ImplicitGraph
Returns a new ImplicitGraph which has as vertices all vertices of the receiver which satisfy the predicate filter.
The methods provides similar functionality as BGLs Filtered Graph
125 126 127 128 129 130 131 132 133 134 135 |
# File 'lib/rgl/implicit.rb', line 125 def vertices_filtered_by(&filter) implicit_graph do |g| g.vertex_iterator do |b| self.each_vertex { |v| b.call(v) if filter.call(v) } end g.adjacent_iterator do |v, b| self.each_adjacent(v) { |u| b.call(u) if filter.call(u) } end end end |