Class: BipartiteGraph::EdgeSet
- Inherits:
-
Object
- Object
- BipartiteGraph::EdgeSet
- Includes:
- Enumerable
- Defined in:
- lib/bipartite_graph/edge_set.rb
Instance Attribute Summary collapse
-
#edges ⇒ Object
readonly
Returns the value of attribute edges.
-
#filter ⇒ Object
readonly
Returns the value of attribute filter.
Instance Method Summary collapse
- #<<(edge) ⇒ Object
- #add(edge) ⇒ Object
- #delete(edge) ⇒ Object
- #each ⇒ Object
- #from(node_or_nodes) ⇒ Object
-
#initialize(edges = Set.new, filter = {}) ⇒ EdgeSet
constructor
A new instance of EdgeSet.
- #length ⇒ Object
- #not_to(node_or_nodes) ⇒ Object
Constructor Details
#initialize(edges = Set.new, filter = {}) ⇒ EdgeSet
Returns a new instance of EdgeSet.
6 7 8 9 |
# File 'lib/bipartite_graph/edge_set.rb', line 6 def initialize(edges = Set.new, filter = {}) @edges = edges @filter = filter end |
Instance Attribute Details
#edges ⇒ Object (readonly)
Returns the value of attribute edges.
4 5 6 |
# File 'lib/bipartite_graph/edge_set.rb', line 4 def edges @edges end |
#filter ⇒ Object (readonly)
Returns the value of attribute filter.
4 5 6 |
# File 'lib/bipartite_graph/edge_set.rb', line 4 def filter @filter end |
Instance Method Details
#<<(edge) ⇒ Object
11 12 13 |
# File 'lib/bipartite_graph/edge_set.rb', line 11 def <<(edge) add(edge) end |
#add(edge) ⇒ Object
15 16 17 |
# File 'lib/bipartite_graph/edge_set.rb', line 15 def add(edge) edges.add(edge) end |
#delete(edge) ⇒ Object
19 20 21 |
# File 'lib/bipartite_graph/edge_set.rb', line 19 def delete(edge) edges.delete(edge) end |
#each ⇒ Object
37 38 39 40 41 42 43 44 45 46 |
# File 'lib/bipartite_graph/edge_set.rb', line 37 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 |
#from(node_or_nodes) ⇒ Object
27 28 29 30 |
# File 'lib/bipartite_graph/edge_set.rb', line 27 def from(node_or_nodes) from_set = Set.new(Array(node_or_nodes)) self.class.new(edges, filter.merge({ from: from_set })) end |
#length ⇒ Object
23 24 25 |
# File 'lib/bipartite_graph/edge_set.rb', line 23 def length to_a.length end |
#not_to(node_or_nodes) ⇒ Object
32 33 34 35 |
# File 'lib/bipartite_graph/edge_set.rb', line 32 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 |