0.1.6 • Published 9 years ago

rapid-queue v0.1.6

Weekly downloads
4
License
-
Repository
github
Last release
9 years ago

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

	npm install rapid-queue

##Usage

Before using it, require the module

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

###Creating queue

  var queue = RapidQueue.createQueue();

##Queue operation

###Inserting element to the end of queue

  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

  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

  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

  var length = queue.length()

It will return the number of element inside queue;

###Check if queue is empty

  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.

0.1.6

9 years ago

0.1.5

9 years ago

0.1.4

9 years ago

0.1.3

9 years ago

0.1.2

9 years ago

0.1.1

9 years ago

0.1.0

9 years ago