- Notifications
You must be signed in to change notification settings - Fork45
The smallest and simplest priority queue in JavaScript.
License
NotificationsYou must be signed in to change notification settings
mourner/tinyqueue
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
The smallest and simplest binary heap priority queue in JavaScript.
// create an empty priority queueletqueue=newTinyQueue();// add some itemsqueue.push(7);queue.push(5);queue.push(10);// remove the top itemlettop=queue.pop();// returns 5// return the top item (without removal)top=queue.peek();// returns 7// get queue lengthqueue.length;// returns 2// create a priority queue from an existing array (modifies the array)queue=newTinyQueue([7,5,10]);// pass a custom item comparator as a second argumentqueue=newTinyQueue([{value:5},{value:7}],function(a,b){returna.value-b.value;});// turn a queue into a sorted arrayconstarray=[];while(queue.length)array.push(queue.pop());
For a faster number-based queue, seeflatqueue.
Install using NPM (npm install tinyqueue), then import as a module:
importTinyQueuefrom'tinyqueue';
Or use a browser build from a CDN:
<scripttype="module">import TinyQueue from 'https://cdn.jsdelivr.net/npm/tinyqueue/+esm';
Inspired byjs-priority-queuebyAdam Hooper.
About
The smallest and simplest priority queue in JavaScript.
Topics
Resources
License
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Packages0
No packages published
Contributors10
Uh oh!
There was an error while loading.Please reload this page.