|
@@ -16,7 +16,34 @@
|
|
|
}(this, function () {
|
|
|
|
|
|
function Queue() {
|
|
|
+ this.tail = [];
|
|
|
+ this.head = [].slice.call(arguments);
|
|
|
+ this.offset = 0;
|
|
|
}
|
|
|
|
|
|
+ Queue.prototype.shift = function () {
|
|
|
+ if (this.offset === this.head.length) {
|
|
|
+ var tmp = this.head;
|
|
|
+ tmp.length = 0;
|
|
|
+ this.head = this.tail;
|
|
|
+ this.tail = tmp;
|
|
|
+ this.offset = 0;
|
|
|
+ if (this.head.length === 0) return;
|
|
|
+ }
|
|
|
+ return this.head[this.offset++];
|
|
|
+ };
|
|
|
+
|
|
|
+ Queue.prototype.push = function () {
|
|
|
+ return [].push.apply(this.tail, arguments);
|
|
|
+ };
|
|
|
+
|
|
|
+ Object.defineProperty(Queue.prototype, "length", {
|
|
|
+ get: function () {
|
|
|
+ return this.head.length - this.offset + this.tail.length;
|
|
|
+ },
|
|
|
+ enumerable: false,
|
|
|
+ configurable: true
|
|
|
+ });
|
|
|
+
|
|
|
return Queue;
|
|
|
}));
|