Class: Mementus::BreadthFirstSearch
- Inherits:
-
Object
- Object
- Mementus::BreadthFirstSearch
- Defined in:
- lib/mementus/breadth_first_search.rb
Instance Method Summary collapse
- #each(&block) ⇒ Object
-
#initialize(graph, start_id, method = :out) ⇒ BreadthFirstSearch
constructor
A new instance of BreadthFirstSearch.
Constructor Details
#initialize(graph, start_id, method = :out) ⇒ BreadthFirstSearch
Returns a new instance of BreadthFirstSearch.
3 4 5 6 7 8 9 |
# File 'lib/mementus/breadth_first_search.rb', line 3 def initialize(graph, start_id, method=:out) @graph = graph @start_id = start_id @method = method @visited = { @start_id => true } @queue = [] end |
Instance Method Details
#each(&block) ⇒ Object
11 12 13 |
# File 'lib/mementus/breadth_first_search.rb', line 11 def each(&block) visit(@start_id, &block) end |