priority-queue

Version, currently 1.1.24 versions

github.com/spider-gazelle/priority-queue

Priority Queue and Heap implementation for Crystal Lang

12 stars
7 dependents
License: MIT

Installation

# Add this to your shard.yml
dependencies:
  priority-queue:
    github: spider-gazelle/priority-queue
    version: ~> 1.1.2

Then run:

shards install

shard.yml

Crystal
>= 0.36.1

Dependencies

Runtime Dependencies

  • bisect*github: spider-gazelle/bisect

Development Dependencies

  • ameba*github: veelenga/amebadev

README

Crystal Lang Priority Queue

CI

Usage

Simple priority queue.

  • Higher numbers pop first
  • lower numbers shift first
  • always insert using push or << to maintain validity

require 'priority-queue'

queue = Priority::Queue(String).new
queue.push 10, "Insert 1"
queue.push 20, "Insert 2"

queue.pop.value # => "Insert 2"
queue.pop.value # => "Insert 1"

A named priority queue where newer items with the same name replace existing items. The highest of the two priorities is inherited by the new item.


require 'priority-queue'

queue = Priority::NamedQueue(String).new
queue.push 20, "Insert 1", :named
queue.push 20, "Insert 2"
queue.push 10, "Insert 3", :named

queue.size # => 2

queue.pop.value # => "Insert 3"
queue.pop.value # => "Insert 2"