summit/frontend/node_modules/martinez-polygon-clipping/node_modules/tinyqueue
mula.liu eb63677c25 0.0.9 2025-12-09 00:31:30 +08:00
..
.travis.yml 0.0.9 2025-12-09 00:31:30 +08:00
LICENSE 0.0.9 2025-12-09 00:31:30 +08:00
README.md 0.0.9 2025-12-09 00:31:30 +08:00
bench.js 0.0.9 2025-12-09 00:31:30 +08:00
bench2.js 0.0.9 2025-12-09 00:31:30 +08:00
bench3.js 0.0.9 2025-12-09 00:31:30 +08:00
index.js 0.0.9 2025-12-09 00:31:30 +08:00
package.json 0.0.9 2025-12-09 00:31:30 +08:00
test.js 0.0.9 2025-12-09 00:31:30 +08:00
yarn.lock 0.0.9 2025-12-09 00:31:30 +08:00

README.md

tinyqueue

The smallest and simplest binary heap priority queue in JavaScript.

// create an empty priority queue
var queue = new TinyQueue();

// add some items
queue.push(7);
queue.push(5);
queue.push(10);

// remove the top item
var top = queue.pop(); // returns 5

// return the top item (without removal)
top = queue.peek(); // returns 7

// get queue length
queue.length; // returns 2

// create a priority queue from an existing array (modifies the array)
queue = new TinyQueue([7, 5, 10]);

// pass a custom item comparator as a second argument
queue = new TinyQueue([{value: 5}, {value: 7}], function (a, b) {
	return a.value - b.value;
});

// turn a queue into a sorted array
var array = [];
while (queue.length) array.push(queue.pop());

Install as an NPM module:

$ npm install tinyqueue

Make a browser build using Browserify:

$ npm install -g browserify
$ browserify index.js -s TinyQueue > tinyqueue.js

Inspired by js-priority-queue by Adam Hooper.