Class: Seafoam::BFS
- Inherits:
-
Object
- Object
- Seafoam::BFS
- Defined in:
- lib/seafoam/search.rb
Instance Attribute Summary collapse
-
#root ⇒ Object
readonly
Returns the value of attribute root.
Instance Method Summary collapse
-
#initialize(root) ⇒ BFS
constructor
A new instance of BFS.
- #search(&block) ⇒ Object
Constructor Details
Instance Attribute Details
#root ⇒ Object (readonly)
Returns the value of attribute root.
7 8 9 |
# File 'lib/seafoam/search.rb', line 7 def root @root end |
Instance Method Details
#search(&block) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/seafoam/search.rb', line 13 def search(&block) queue = root.outputs.collect(&:to) visited = Set.new until queue.empty? entry = queue.shift visited << entry result = entry.visit(&block) if result return result else entry.outputs.collect(&:to).each do |child| queue << child unless visited.include?(child) end end end end |