1 var to_array = require("./to_array");
3 // Queue class adapted from Tim Caswell's pattern library
4 // http://github.com/creationix/pattern/blob/master/lib/pattern/queue.js
12 Queue.prototype.shift = function () {
13 if (this.offset === this.head.length) {
16 this.head = this.tail;
19 if (this.head.length === 0) {
23 return this.head[this.offset++]; // sorry, JSLint
26 Queue.prototype.push = function (item) {
27 return this.tail.push(item);
30 Queue.prototype.forEach = function (fn, thisv) {
31 var array = this.head.slice(this.offset), i, il;
33 array.push.apply(array, this.tail);
36 for (i = 0, il = array.length; i < il; i += 1) {
37 fn.call(thisv, array[i], i, array);
40 for (i = 0, il = array.length; i < il; i += 1) {
41 fn(array[i], i, array);
48 Queue.prototype.getLength = function () {
49 return this.head.length - this.offset + this.tail.length;
52 Object.defineProperty(Queue.prototype, 'length', {
54 return this.getLength();
59 if(typeof module !== 'undefined' && module.exports) {
60 module.exports = Queue;