0
33%
MIT
BuckleScript/ReasonML bindings for [tinyqueue](https://github.com/mourner/tinyqueue), a priority queue/heap implementation.

bs-priority-queue

BuckleScript/ReasonML bindings for tinyqueue, a priority queue/heap implementation.

Installation

npm install --save bs-priority-queue

Then, add the dependency in your bsconfig.json:

{
  "bs-dependencies": ["bs-priority-queue"]
}

Usage

  • RE
  • ML
/* Create an empty priority queue */
let minQueue = PriorityQueue.make(Pervasives.compare);

/* Add some items */
minQueue->PriorityQueue.push(7);
minQueue->PriorityQueue.push(5);
minQueue->PriorityQueue.push(10);

/* Remove the top item */
Js.log(minQueue->PriorityQueue.pop); /* Returns Some(5) */

/* Return the top item (without removing it) */
Js.log(minQueue->PriorityQueue.peek); /* Returns Some(7) */

/* Remove the top item, throwing Not_found if the queue is empty */
Js.log(minQueue->PriorityQueue.popExn); /* Returns 7 */

/* Return the top item, throwing Not_found if the queue is empty */
Js.log(minQueue->PriorityQueue.peekExn); /* Returns 10 */

/* Get the size of the queue */
Js.log(minQueue->PriorityQueue.size); /* Returns 1 */

/* Populate a priority queue with an existing array */
let minQueue = PriorityQueue.fromArray([|7, 5, 10|], Pervasives.compare);

/* Set the top to be the max element */
let maxQueue = PriorityQueue.make((a, b) => b - a);
2310: syntax error, consider adding a `;' before