Class: MiniGraph::Core::Search::Base
- Inherits:
-
Object
- Object
- MiniGraph::Core::Search::Base
- Includes:
- Enumerable
- Defined in:
- lib/mini_graph/core/search.rb
Overview
Base Search Implementation
Instance Attribute Summary collapse
-
#graph ⇒ Object
readonly
Returns the value of attribute graph.
-
#vertex_index ⇒ Object
readonly
Returns the value of attribute vertex_index.
Instance Method Summary collapse
- #each ⇒ Object
-
#initialize(graph, vertex_index) ⇒ Base
constructor
A new instance of Base.
- #visit(index, visited = Array.new(graph.size, false), &block) ⇒ Object
Constructor Details
#initialize(graph, vertex_index) ⇒ Base
Returns a new instance of Base.
14 15 16 17 |
# File 'lib/mini_graph/core/search.rb', line 14 def initialize(graph, vertex_index) @graph = graph @vertex_index = vertex_index end |
Instance Attribute Details
#graph ⇒ Object (readonly)
Returns the value of attribute graph.
12 13 14 |
# File 'lib/mini_graph/core/search.rb', line 12 def graph @graph end |
#vertex_index ⇒ Object (readonly)
Returns the value of attribute vertex_index.
12 13 14 |
# File 'lib/mini_graph/core/search.rb', line 12 def vertex_index @vertex_index end |
Instance Method Details
#each ⇒ Object
19 20 21 22 23 24 25 |
# File 'lib/mini_graph/core/search.rb', line 19 def each return enum_for(:each) unless block_given? visit(vertex_index) do |vi| yield graph[vi] end end |
#visit(index, visited = Array.new(graph.size, false), &block) ⇒ Object
27 28 29 |
# File 'lib/mini_graph/core/search.rb', line 27 def visit(index, visited=Array.new(graph.size, false), &block) raise NotImplementedError, "#visit must be implemented" end |