Class | PQueue |
In: |
lib/facets/more/pqueue.rb
|
Parent: | Object |
Priority queue with array based heap.
A priority queue is like a standard queue, except that each inserted elements is given a certain priority, based on the result of the comparison block given at instantiation time. Also, retrieving an element from the queue will always return the one with the highest priority (see pop and top).
The default is to compare the elements in repect to their #> method. For example, Numeric elements with higher values will have higher priorities.
gt | [R] | compare Proc |
size | [R] | number of elements |
Returns a new priority queue.
If elements are given, build the priority queue with these initial values. The elements object must respond to to_a.
If a block is given, it will be used to determine the priority between the elements.
By default, the priority queue retrieves maximum elements first (using the #> method).
Return the element with the highest priority and remove it from the queue.
The highest priority is determined by the block given at instanciation time.
The deletion time is O(log n), with n the size of the queue.
Return nil if the queue is empty.