fastqueue
A fast push/shift sync queue
Last updated 12 years ago by creationix .
Original npm · Tarball · package.json
$ npm install fastqueue 
SYNC missed versions from official npm registry.

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

Current Tags

  • 0.1.0                                ...           latest (12 years ago)

1 Versions

  • 0.1.0                                ...           12 years ago
Maintainers (1)
Downloads
Total 1
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 0
Dependencies (0)
None
Dev Dependencies (0)
None
Dependents (3)

© 2010 - cnpmjs.org x YWFE | Home | YWFE