Class: DFS

Inherits:
Object
  • Object
show all
Defined in:
lib/rsearch/dfs.rb

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ DFS

Returns a new instance of DFS.



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/rsearch/dfs.rb', line 5

def initialize(options)

  stack = []
  marked = Set.new
  marked << options[:start]

  scheduler = Proc.new do |states|
    states.reverse.each do |state|
      stack << state if !marked.include?(state)
      marked << state
    end
    stack.pop
  end

  @search = Search.new(start: options[:start],
                       generator: options[:generator],
                       scheduler: scheduler)
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(meth, *args, &block) ⇒ Object



24
25
26
# File 'lib/rsearch/dfs.rb', line 24

def method_missing(meth, *args, &block)
  @search.send(meth, *args, &block)
end