Inefficient and poorly tested substitute for priority_queue gem.
The underlying data structure is a sorted list. Make it a min-heap, and this implementation is unobjectionable.
Make an empty queue.
# File hack_priority_queue.rb, line 42 def initialize @q = [] end
Return a new Entry in the queue, with only priority set.
# File hack_priority_queue.rb, line 47 def [](priority) entry = Entry.new(priority) i = @q.find_index {|e| e.priority >= priority} @q.insert(i == nil ? -1 : i, entry) return entry end
Return highest-priority item, removing its entry from queue.
# File hack_priority_queue.rb, line 55 def shift @q.shift.item end
The number of entries in the queue.
# File hack_priority_queue.rb, line 60 def size @q.length end