Penguin Queue

Ruby priority-queue library
10000.times { array << rand; array.delete(array.min) }
10000.times { pq << rand; pq.deq }
Install
gem install penguin_queue
gem 'penguin_queue'
Usage
require 'penguin_queue'
pq = PenguinQueue.new
10.times.to_a.shuffle.each { |i| pq << i }
10.times.map { pq.deq }
pq.enq 'hello', priority: 0
pq.first
pq.first_with_priority
pq.deq_with_priority
nodes = 10.times.to_a.shuffle.map { |i| pq << i }
nodes.each { |n| n.priority = -n.priority }
nodes.each_with_index{ |n| n.remove if n.value.odd? }
pq.size.times.map { pq.deq }
Methods
PenguinQueue.new
PenguinQueue.new(order)
PenguinQueue.new(&calc_priority_from_element_proc)
<<(e) enq(e) push(e) unshift(e)
enq(e, priority: p) push(e, priority: p) unshift(e, priority: e)
deq shift pop poll deq_with_priority
deq(n) shift(n) pop(n) poll(n)
first peek top first_with_priority first_node
remove(node) delete(node)
to_s inspect clear size empty? min? max?
remove delete value value= priority priority= to_s inspect