tiny-queue

WebJar for tiny-queue

License

License

Apache 2
GroupId

GroupId

org.webjars.npm
ArtifactId

ArtifactId

tiny-queue
Last Version

Last Version

0.2.0
Release Date

Release Date

Type

Type

jar
Description

Description

tiny-queue
WebJar for tiny-queue
Project URL

Project URL

http://webjars.org
Source Code Management

Source Code Management

https://github.com/nolanlawson/tiny-queue

Download tiny-queue

How to add to project

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

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.

tiny-queue

A simple FIFO queue implementation as a linked list. The main benefit is to avoid doing shift() on an array, which may be slow. It's implemented in the straightforward root -> node1 -> node2 -> etc. architecture that you may have learned in CS 101.

This can typically be used as a drop-in replacement for an array, and it's only 38 lines of code.

See this Wikipedia page for a good explanation of the tradeoffs of a linked list versus other data structures.

Status

browser support

Usage

npm install tiny-queue

Then:

var Queue = require('tiny-queue');
var queue = new Queue();

queue.push('foo');
queue.push('bar');
queue.shift(); // 'foo'
queue.shift(); //'bar'
queue.length; // 0
queue.shift(); // undefined

API

The returned Queue object, once instantiated, only supports four operations:

queue.push()
queue.shift()
queue.slice() // returns a regular Array
queue.length

So it's basically a drop-in replacement for most naïve usages of an array as a queue.

Versions

Version
0.2.0