tinyqueue
The smallest and simplest binary heap priority queue in JavaScript.
var queue = new TinyQueue();
queue.push(7);
queue.push(5);
queue.push(10);
var top = queue.pop();
top = queue.peek();
queue.length;
queue = new TinyQueue([7, 5, 10]);
queue = new TinyQueue([{value: 5}, {value: 7}], function (a, b) {
return a.value - b.value;
});
var array = [];
while (queue.length) array.push(queue.pop());
For a faster number-based queue, see flatqueue.
Install
Install using NPM (npm install tinyqueue
) or Yarn (yarn add tinyqueue
), then:
import TinyQueue from 'tinyqueue';
const TinyQueue = require('tinyqueue');
Or use a browser build directly:
<script src="https://unpkg.com/tinyqueue@2.0.0/tinyqueue.min.js"></script>
Thanks
Inspired by js-priority-queue
by Adam Hooper.