Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

The smallest and simplest priority queue in JavaScript.

License

NotificationsYou must be signed in to change notification settings

mourner/tinyqueue

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

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';

Thanks

Inspired byjs-priority-queuebyAdam Hooper.

About

The smallest and simplest priority queue in JavaScript.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors10


[8]ページ先頭

©2009-2025 Movatter.jp