Bug:Fix file validation issue
[vnfsdk/refrepo.git] / vnfmarket / src / main / webapp / vnfmarket / node_modules / redis / lib / queue.js
1 var to_array = require("./to_array");
2
3 // Queue class adapted from Tim Caswell's pattern library
4 // http://github.com/creationix/pattern/blob/master/lib/pattern/queue.js
5
6 function Queue() {
7     this.tail = [];
8     this.head = [];
9     this.offset = 0;
10 }
11
12 Queue.prototype.shift = function () {
13     if (this.offset === this.head.length) {
14         var tmp = this.head;
15         tmp.length = 0;
16         this.head = this.tail;
17         this.tail = tmp;
18         this.offset = 0;
19         if (this.head.length === 0) {
20             return;
21         }
22     }
23     return this.head[this.offset++]; // sorry, JSLint
24 };
25
26 Queue.prototype.push = function (item) {
27     return this.tail.push(item);
28 };
29
30 Queue.prototype.forEach = function (fn, thisv) {
31     var array = this.head.slice(this.offset), i, il;
32
33     array.push.apply(array, this.tail);
34
35     if (thisv) {
36         for (i = 0, il = array.length; i < il; i += 1) {
37             fn.call(thisv, array[i], i, array);
38         }
39     } else {
40         for (i = 0, il = array.length; i < il; i += 1) {
41             fn(array[i], i, array);
42         }
43     }
44
45     return array;
46 };
47
48 Queue.prototype.getLength = function () {
49     return this.head.length - this.offset + this.tail.length;
50 };
51     
52 Object.defineProperty(Queue.prototype, 'length', {
53     get: function () {
54         return this.getLength();
55     }
56 });
57
58
59 if(typeof module !== 'undefined' && module.exports) {
60   module.exports = Queue;
61 }