Class: Ogr::EdgeBag
- Inherits:
-
Object
- Object
- Ogr::EdgeBag
- Includes:
- Enumerable
- Defined in:
- lib/ogr/graphs/edge_bag.rb
Overview
Bag for Edge objects
Instance Method Summary collapse
- #add(x, weight) ⇒ Object
- #each(&block) ⇒ Object
- #get(x) ⇒ Object
-
#initialize ⇒ EdgeBag
constructor
A new instance of EdgeBag.
- #remove(x) ⇒ Object
- #size ⇒ Object
Constructor Details
#initialize ⇒ EdgeBag
Returns a new instance of EdgeBag.
5 6 7 |
# File 'lib/ogr/graphs/edge_bag.rb', line 5 def initialize @store = [] end |
Instance Method Details
#add(x, weight) ⇒ Object
9 10 11 |
# File 'lib/ogr/graphs/edge_bag.rb', line 9 def add(x, weight) @store.push v: x, weight: weight end |
#each(&block) ⇒ Object
21 22 23 |
# File 'lib/ogr/graphs/edge_bag.rb', line 21 def each(&block) @store.each(&block) end |
#get(x) ⇒ Object
17 18 19 |
# File 'lib/ogr/graphs/edge_bag.rb', line 17 def get(x) @store.find { |edge| edge[:v] == x } end |
#remove(x) ⇒ Object
13 14 15 |
# File 'lib/ogr/graphs/edge_bag.rb', line 13 def remove(x) @store.delete_if { |edge| edge[:v] == x } end |
#size ⇒ Object
25 26 27 |
# File 'lib/ogr/graphs/edge_bag.rb', line 25 def size @store.size end |