A fast and compact priority queue with low integer keys
  • OCaml 86.3%
  • Makefile 12.4%
  • Dune 1.3%
Find a file
2025-11-17 10:35:55 +01:00
src Documentation: note that this data structure is not thread-safe. 2025-11-17 10:35:55 +01:00
test Implement [iter] (untested). 2025-09-26 09:21:01 +02:00
.gitattributes Creation. 2025-09-19 21:23:44 +02:00
.gitignore Creation. 2025-09-19 21:23:44 +02:00
AUTHORS.md Creation. 2025-09-19 21:23:44 +02:00
CHANGES.md CHANGES. 2025-09-26 09:21:41 +02:00
dune-project Add [maintenance_intent] field in dune-project. 2025-09-25 17:31:36 +02:00
headache.config Creation. 2025-09-19 21:23:44 +02:00
header.txt Header. 2025-09-22 21:51:25 +02:00
LICENSE.txt Creation. 2025-09-19 21:23:44 +02:00
Makefile Update [make vendor]. 2025-11-17 10:34:52 +01:00
README.md README. 2025-09-24 11:19:35 +02:00
TODO.md TODO. 2025-09-26 09:21:09 +02:00

IntPQueue

This OCaml library offers a fast and compact priority queue whose keys are nonnegative integers.

The priorities must be low integers, because the space occupied by the priority queue is O(n+p), where n is the number of elements in the queue and p is the greatest priority that is ever used.

Furthermore, this priority queue is most efficient under the assumption that the priorities that are passed to add and update are at least as high as the priority of the last element that was returned by extract. This is the case, for example, in Dijkstra's single-source shortest paths algorithm. In this scenario, the time complexity of inserting and extracting n elements is O(n+p). In Dijkstra's algorithm, for example, if the cost of every edge in the graph is 1 then p is O(n) so the time complexity of inserting and extracting n elements is O(n). In other words, every priority queue operation has amortized time complexity O(1).

The library offers two variants of the priority queue: IntPQueue.Plain is simpler, faster, and more compact; IntPQueue.Boxed is slower (by a constant factor) but supports more operations, namely remove and update.

Installation and Usage

Type opam install intPQueue.

In your dune file, add (libraries intPQueue) to the description of your library or executable.

Documentation

For more information, please see the documentation of the latest released version.