class BipartiteGraph::EdgeSet
Attributes
edges[R]
filter[R]
Public Class Methods
new(edges = Set.new, filter = {})
click to toggle source
# File lib/bipartite_graph/edge_set.rb, line 6 def initialize(edges = Set.new, filter = {}) @edges = edges @filter = filter end
Public Instance Methods
<<(edge)
click to toggle source
# File lib/bipartite_graph/edge_set.rb, line 11 def <<(edge) add(edge) end
add(edge)
click to toggle source
# File lib/bipartite_graph/edge_set.rb, line 15 def add(edge) edges.add(edge) end
delete(edge)
click to toggle source
# File lib/bipartite_graph/edge_set.rb, line 19 def delete(edge) edges.delete(edge) end
each() { |edge| ... }
click to toggle source
# File lib/bipartite_graph/edge_set.rb, line 40 def each from_set = filter[:from] not_to_set = filter[:not_to] edges.each do |edge| from_cond = !from_set || from_set.include?(edge.from) not_to_cond = !not_to_set || !not_to_set.include?(edge.to) yield edge if from_cond && not_to_cond end end
empty?()
click to toggle source
# File lib/bipartite_graph/edge_set.rb, line 26 def empty? to_a.empty? end
from(node_or_nodes)
click to toggle source
# File lib/bipartite_graph/edge_set.rb, line 30 def from(node_or_nodes) from_set = Set.new(Array(node_or_nodes)) self.class.new(edges, filter.merge({ from: from_set })) end
length()
click to toggle source
# File lib/bipartite_graph/edge_set.rb, line 23 def length to_a.length end
not_to(node_or_nodes)
click to toggle source
# File lib/bipartite_graph/edge_set.rb, line 35 def not_to(node_or_nodes) not_to_set = Set.new(Array(node_or_nodes)) self.class.new(edges, filter.merge({ not_to: not_to_set })) end