https://github.com/rubyworks/pqueue
Priority Queue in pure Ruby
https://github.com/rubyworks/pqueue
Last synced: 5 months ago
JSON representation
Priority Queue in pure Ruby
- Host: GitHub
- URL: https://github.com/rubyworks/pqueue
- Owner: rubyworks
- License: other
- Created: 2009-09-09T00:57:30.000Z (over 16 years ago)
- Default Branch: master
- Last Pushed: 2015-03-03T02:51:50.000Z (almost 11 years ago)
- Last Synced: 2025-08-13T17:57:23.559Z (6 months ago)
- Language: Ruby
- Homepage:
- Size: 291 KB
- Stars: 69
- Watchers: 4
- Forks: 7
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Changelog: History.md
- Contributing: Contributing.md
- License: License.txt
Awesome Lists containing this project
README
# PQueue
[](http://badge.fury.io/rb/pqueue)
[](http://travis-ci.org/rubyworks/pqueue)
[](http://flattr.com/thing/324911/Rubyworks-Ruby-Development-Fund)
[Website](http://rubyworks.github.com/pqueue) ·
[YARD API](http://rubydoc.info/gems/pqueue) ·
[Report Issue](http://github.com/rubyworks/pqueue/issues) ·
[Source Code](http://github.com/rubyworks/pqueue)
## About
PQueue is a priority queue with array based heap.
A priority queue is like a standard queue, except that each inserted
element 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 respect to their #<=> method.
For example, Numeric elements with higher values will have higher
priorities.
This library is a rewrite of the original PQueue.rb by K. Kodama and
Heap.rb by Ronald Butler. The two libraries were later merged
and generally improved by Olivier Renaud. Then the whole library
rewritten by Trans using the original as a functional reference.
## Usage
Usage is simple enough. Think of it as an array that takes a block, where
the block decides which element of the array goes first.
require 'pqueue'
pq = PQueue.new([2,3,1]){ |a,b| a > b }
pq.pop #=> 3
## Install
Using RubyGems:
gem install pqueue
## Acknowledgements
Although the library has been completely rewritten since, we still would
like to acknowledge the efforts of the original PQueue authors and
contributors.
* Olivier Renaud (2007)
* Rick Bradley (2003)
* Ronald Butler (2002)
* K Kodama (2001, original library)
## License & Copyrights
Copyright (c) 2011 Rubyworks
PQueue is distributable in accordance with the *BSD-2-Clause* license.
PQueue is based on the original PQueue library (c) 2001 by K. Kodama.
See the LICENSE.txt file for details.