class RubyAi::Search::Core::PriorityQueue
Public Class Methods
new(order: nil)
click to toggle source
# File lib/ruby_ai/search/core/frontier.rb, line 59 def initialize(order: nil) @order = Proc.new { |priorities| priorities.min } @store = Hash.new { |hash, key| hash[key] = [] } end
Public Instance Methods
append(element:, priority:)
click to toggle source
# File lib/ruby_ai/search/core/frontier.rb, line 64 def append(element:, priority:) @store[priority].push(element) self end
empty?()
click to toggle source
Calls superclass method
RubyAi::Search::Core::Frontier#empty?
# File lib/ruby_ai/search/core/frontier.rb, line 73 def empty? clean_store && super end
include?(element:)
click to toggle source
# File lib/ruby_ai/search/core/frontier.rb, line 81 def include?(element:) @store.values.flatten.include?(element) end
pop()
click to toggle source
# File lib/ruby_ai/search/core/frontier.rb, line 69 def pop clean_store && @store[max_priority].pop end
size()
click to toggle source
# File lib/ruby_ai/search/core/frontier.rb, line 77 def size @store.values.flatten.size end
store()
click to toggle source
Calls superclass method
# File lib/ruby_ai/search/core/frontier.rb, line 85 def store clean_store super end
Private Instance Methods
clean_store()
click to toggle source
# File lib/ruby_ai/search/core/frontier.rb, line 96 def clean_store @store.delete_if { |priority, elements| elements.empty? } end
max_priority()
click to toggle source
# File lib/ruby_ai/search/core/frontier.rb, line 92 def max_priority @order.call(@store.keys) end