Class: RubyAi::Search::Core::PriorityQueue
- Defined in:
- lib/ruby_ai/search/core/frontier.rb
Instance Method Summary collapse
- #append(element:, priority:) ⇒ Object
- #empty? ⇒ Boolean
- #include?(element:) ⇒ Boolean
-
#initialize(order: nil) ⇒ PriorityQueue
constructor
A new instance of PriorityQueue.
- #pop ⇒ Object
- #size ⇒ Object
- #store ⇒ Object
Constructor Details
#initialize(order: nil) ⇒ PriorityQueue
Returns a new instance of PriorityQueue.
59 60 61 62 |
# 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 |
Instance Method Details
#append(element:, priority:) ⇒ Object
64 65 66 67 |
# File 'lib/ruby_ai/search/core/frontier.rb', line 64 def append(element:, priority:) @store[priority].push(element) self end |
#empty? ⇒ Boolean
73 74 75 |
# File 'lib/ruby_ai/search/core/frontier.rb', line 73 def empty? clean_store && super end |
#include?(element:) ⇒ Boolean
81 82 83 |
# File 'lib/ruby_ai/search/core/frontier.rb', line 81 def include?(element:) @store.values.flatten.include?(element) end |
#pop ⇒ Object
69 70 71 |
# File 'lib/ruby_ai/search/core/frontier.rb', line 69 def pop clean_store && @store[max_priority].pop end |
#size ⇒ Object
77 78 79 |
# File 'lib/ruby_ai/search/core/frontier.rb', line 77 def size @store.values.flatten.size end |
#store ⇒ Object
85 86 87 88 |
# File 'lib/ruby_ai/search/core/frontier.rb', line 85 def store clean_store super end |