# rapid-queue

> Queue with table doubling and circular buffer

Latest version **0.1.6** (published 2015-05-04) · 0 weekly downloads

## Install

```sh
npm install rapid-queue
pnpm add rapid-queue
yarn add rapid-queue
bun add rapid-queue
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.1.6 |
| Published | 2015-05-04 |
| First published | 2015-05-03 |
| Weekly downloads | 0 |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 2 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 13 |
| Author | Kevin Yudi Utama |
| Maintainers | kevinyu |
| Keywords | queue, shift, array, javascript, node |

## Links

- npm: https://www.npmjs.com/package/rapid-queue
- Repository: https://github.com/kevyuu/rapid-queue
- Issues: https://github.com/kevyuu/rapid-queue/issues
- npm.io page: https://npm.io/package/rapid-queue

## Dependencies (2)

- [chai](https://npm.io/package/chai.md) ^2.3.0
- [mocha](https://npm.io/package/mocha.md) ^2.2.4

## Alternatives

- [cron](https://npm.io/package/cron.md) — 4.9M weekly downloads
- [@vercel/queue](https://npm.io/package/@vercel/queue.md) — 731.6K weekly downloads
- [create-sonicjs](https://npm.io/package/create-sonicjs.md) — 1.6K weekly downloads
- [@exellix/jobs-api](https://npm.io/package/@exellix/jobs-api.md) — 941 weekly downloads
- [@forwardimpact/libskill](https://npm.io/package/@forwardimpact/libskill.md) — 575 weekly downloads

## Recent versions

- 0.1.6 (latest) — 2015-05-04
- 0.1.5 — 2015-05-04
- 0.1.4 — 2015-05-03
- 0.1.3 — 2015-05-03
- 0.1.2 — 2015-05-03
- 0.1.1 — 2015-05-03
- 0.1.0 — 2015-05-03

## README

rapid-queue
=============
Javascript array.shift() is slow. This is an implementation using circular buffer and two stack. Circular queue use circular buffer and Double Stack Queue use two stack to implement the queue. This implementation of shift is up to 100x faster than javascript array.shift().

##Installation

```shell
	npm install rapid-queue
```

##Usage

Before using it, require the module

```js
	var RapidQueue = require('rapid-queue');
```

###Creating queue

```js
  var queue = RapidQueue.createQueue();
```

##Queue operation


###Inserting element to the end of queue

```js
  queue.push(5);`
```

push will insert 5 to the back of the queue, it will automatically grow the array if the capacity is not enough.

###Get front element

```js
  var front = queue.front();
```

It will return the front element without removing it from the queue. It will return null if queue is empty.

###Remove front element

```js
  var front = queue.shift();
```

It will return and remove front element from the queue. It will return null if queue is empty.

###Get queue length

```js
  var length = queue.length()
```

It will return the number of element inside queue;

###Check if queue is empty

```js
  var isEmpty = queue.isEmpty()
```

##Performance

This is comparison using RapidQueue shift() and Array shift()

http://jsperf.com/rapidqueue-shift-vs-array-shift

As you can see, it is significantly faster

This is comparison using RapidQueue push() and Array push()

http://jsperf.com/rapidqueue-push-vs-array-push

RapidQueue.push() is faster on chrome but can be 2-3 times slower in another browser. This slowdown is not as significant as Array.shift() vs RapidQueue.shift(). This slowdown is due to having additional internal state for circular buffer implementation.

---
_Source: https://npm.io/package/rapid-queue · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
