tinyqueue

WebJar for tinyqueue

License

License

ISC
GroupId

GroupId

org.webjars.npm
ArtifactId

ArtifactId

tinyqueue
Last Version

Last Version

2.0.3
Release Date

Release Date

Type

Type

jar
Description

Description

tinyqueue
WebJar for tinyqueue
Project URL

Project URL

http://webjars.org
Source Code Management

Source Code Management

https://github.com/mourner/tinyqueue

Download tinyqueue

How to add to project

<!-- https://jarcasting.com/artifacts/org.webjars.npm/tinyqueue/ -->
<dependency>
    <groupId>org.webjars.npm</groupId>
    <artifactId>tinyqueue</artifactId>
    <version>2.0.3</version>
</dependency>
// https://jarcasting.com/artifacts/org.webjars.npm/tinyqueue/
implementation 'org.webjars.npm:tinyqueue:2.0.3'
// https://jarcasting.com/artifacts/org.webjars.npm/tinyqueue/
implementation ("org.webjars.npm:tinyqueue:2.0.3")
'org.webjars.npm:tinyqueue:jar:2.0.3'
<dependency org="org.webjars.npm" name="tinyqueue" rev="2.0.3">
  <artifact name="tinyqueue" type="jar" />
</dependency>
@Grapes(
@Grab(group='org.webjars.npm', module='tinyqueue', version='2.0.3')
)
libraryDependencies += "org.webjars.npm" % "tinyqueue" % "2.0.3"
[org.webjars.npm/tinyqueue "2.0.3"]

Dependencies

There are no dependencies for this project. It is a standalone project that does not depend on any other jars.

Project Modules

There are no modules declared in this project.

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());

For a faster number-based queue, see flatqueue.

Install

Install using NPM (npm install tinyqueue) or Yarn (yarn add tinyqueue), then:

// import as an ES module
import TinyQueue from 'tinyqueue';

// or require in Node / Browserify
const TinyQueue = require('tinyqueue');

Or use a browser build directly:

<script src="https://unpkg.com/[email protected]/tinyqueue.min.js"></script>

Thanks

Inspired by js-priority-queue by Adam Hooper.

Versions

Version
2.0.3
2.0.2
2.0.0
1.2.3
1.1.0