Socket
Socket
Sign inDemoInstall

fastqueue

Package Overview
Dependencies
0
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    fastqueue

A fast push/shift sync queue


Version published
Weekly downloads
2.3K
decreased by-15.06%
Maintainers
1
Install size
2.88 kB
Created
Weekly downloads
 

Readme

Source

Fast Queue

While normal JavaScript arrays can be used as FIFO queues, the .shift() call is very slow if the queue gets large because it has to reindex all the remaining items on every shift.

This library is a fast queue that only implements .push(item), .shift(), .unshift(item) and .length from the Array interface.

Internally it uses two arrays and cycles them and uses counters so that the .shift() calls are still fast.

Usage

var Queue = require('fastqueue');

var q = new Queue;
q.push(1);
q.push(2);
q.push(3);
var i = 4;
while (q.length > 0) {
  console.log(q.length, q.shift());
  q.unshift(i++);
  console.log(q.length, q.shift());
  q.push(i++);
  console.log(q.length, q.shift());
}

FAQs

Last updated on 02 Apr 2013

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc