|
| 1 | +# PQueue |
| 2 | + |
| 3 | +[](http://badge.fury.io/rb/pqueue) |
| 4 | +[](http://travis-ci.org/rubyworks/pqueue) |
| 5 | +[](http://flattr.com/thing/324911/Rubyworks-Ruby-Development-Fund) |
| 6 | + |
| 7 | +[Website](http://rubyworks.github.com/pqueue) · |
| 8 | +[API](http://rubydoc.info/gems/pqueue) · |
| 9 | +[User Guide](http://wiki.github.com/rubyworks/pqueue) · |
| 10 | +[Report Issue](http://github.com/rubyworks/pqueue/issues) · |
| 11 | +[Source Code](http://github.com/rubyworks/pqueue) |
| 12 | + |
| 13 | + |
| 14 | +## DESCRIPTION |
| 15 | + |
| 16 | +Priority queue with array based heap. |
| 17 | + |
| 18 | +A priority queue is like a standard queue, except that each inserted |
| 19 | +elements is given a certain priority, based on the result of the |
| 20 | +comparison block given at instantiation time. Also, retrieving an element |
| 21 | +from the queue will always return the one with the highest priority |
| 22 | +(see #pop and #top). |
| 23 | + |
| 24 | +The default is to compare the elements in respect to their #<=> method. |
| 25 | +For example, Numeric elements with higher values will have higher |
| 26 | +priorities. |
| 27 | + |
| 28 | +This library is a rewrite of the original PQueue.rb by K. Kodama and |
| 29 | +Heap.rb by Ronald Butler. The two libraries were later merged |
| 30 | +and generally improved by Olivier Renaud. Then the whole library |
| 31 | +rewritten by Trans using the original as a functional reference. |
| 32 | + |
| 33 | + |
| 34 | +## USAGE |
| 35 | + |
| 36 | +Usage is simple enough. Think of it as an array that takes a block, where |
| 37 | +the block decides which element of the array goes first. |
| 38 | + |
| 39 | + require 'pqueue' |
| 40 | + |
| 41 | + pq = PQueue.new([2,3,1]){ |a,b| a > b } |
| 42 | + |
| 43 | + pq.pop #=> 3 |
| 44 | + |
| 45 | + |
| 46 | +## ACKNOWLEDGMENTS |
| 47 | + |
| 48 | +Although the library has been completely rewritten since, we still would |
| 49 | +like to acknowledge the efforts of the original PQueue authors and |
| 50 | +contributors. |
| 51 | + |
| 52 | +* Olivier Renaud (2007) |
| 53 | +* Rick Bradley (2003) |
| 54 | +* Ronald Butler (2002) |
| 55 | +* K Kodama (2001, original library) |
| 56 | + |
| 57 | + |
| 58 | +## COPYRIGHTS |
| 59 | + |
| 60 | +Copyright (c) 2011 Rubyworks |
| 61 | + |
| 62 | +PQueue is distributable in accordance with the *BSD-2-Clause* license. |
| 63 | + |
| 64 | +PQueue is based on the original PQueue library (c) 2001 by K. Kodama. |
| 65 | + |
| 66 | +See the LICENSE.txt file for details. |
0 commit comments