GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - mourner/tinyqueue: The smallest and simplest priority queue in JavaScript.

BranchesTags
Open more actions menu

Latest commit

 

History

55 Commits
55 Commits

Folders and files

NameName
Last commit message
Last commit date
.github/workflows
.github/workflows
 
 
.gitignore
.gitignore
 
 
LICENSE
LICENSE
 
 
README.md
README.md
 
 
bench.js
bench.js
 
 
eslint.config.js
eslint.config.js
 
 
index.d.ts
index.d.ts
 
 
index.js
index.js
 
 
package-lock.json
package-lock.json
 
 
package.json
package.json
 
 
test.js
test.js
 
 

Repository files navigation

tinyqueue

The smallest and simplest binary heap priority queue in JavaScript.

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

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

// remove the top item
let 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
const array = [];
while (queue.length) array.push(queue.pop());

For a faster number-based queue, see flatqueue.

Install

Install using NPM (npm install tinyqueue), then import as a module:

import TinyQueue from 'tinyqueue';

Or use a browser build from a CDN:

<script type="module">
	import TinyQueue from 'https://cdn.jsdelivr.net/npm/tinyqueue/+esm';

Thanks

Inspired by js-priority-queue by Adam Hooper.

About

The smallest and simplest priority queue in JavaScript.

Topics

algorithmbinary-heapdata-structurejavascriptpriority-queue

Resources

Readme
ISC license
Activity

Stars

471 stars

Watchers

12 watching

Forks

47 forks
Report repository

Releases

Packages

Used by

Contributors

Languages

You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.