Crystal implementation of Lindén and Jonsson's lock-free priority queue.
- Add the dependency to your
shard.yml:
dependencies:
pqueue:
github: beta-ziliani/pqueue.cr- Run
shards install
require "pqueue"
# The queue retains a number of deleted nodes before restructuring the internal structure.
# The number in the initializer is the count of such nodes.
queue = PQueue::PQueue(Int32, String).new 10
# Insert some elements
queue.insert 10, "low prio"
queue.insert 5, "mid prio"
# It also works with the indexing operator
queue[0] = "high priority"
# Inserting also updates if the key exists
queue.insert 5, "mid priority"
# Which of course can be done with the indexing operator too
queue[10] = "low priority"
a = [] of {Int32, String}?
(1..4).each do
a << queue.delete_min
end
puts a # => [{0, "high priority}, {5, "mid priority"}, {10, "low priority"}, nil]- Fork it (https://github.com/your-github-user/pqueue/fork)
- Create your feature branch (
git checkout -b my-new-feature) - Commit your changes (
git commit -am 'Add some feature') - Push to the branch (
git push origin my-new-feature) - Create a new Pull Request
- Beta Ziliani - creator and maintainer