Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/nolanlawson/tiny-queue
Simple JavaScript FIFO queue implementation to avoid having to do shift()
https://github.com/nolanlawson/tiny-queue
Last synced: 1 day ago
JSON representation
Simple JavaScript FIFO queue implementation to avoid having to do shift()
- Host: GitHub
- URL: https://github.com/nolanlawson/tiny-queue
- Owner: nolanlawson
- License: apache-2.0
- Created: 2014-05-23T02:18:07.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2017-11-23T16:47:53.000Z (about 7 years ago)
- Last Synced: 2025-01-08T09:51:31.764Z (7 days ago)
- Language: JavaScript
- Size: 8.79 KB
- Stars: 21
- Watchers: 4
- Forks: 8
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-nodejs-pure-js - tiny-queue
README
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](https://en.wikipedia.org/wiki/Linked_list#Tradeoffs) for a good explanation of the tradeoffs of a linked list versus other data structures.
### Status
[![browser support](https://ci.testling.com/nolanlawson/tiny-queue.png)](https://ci.testling.com/nolanlawson/tiny-queue)
### Usage
```
npm install tiny-queue
```Then:
```js
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:```js
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.