You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
89 lines
2.1 KiB
89 lines
2.1 KiB
7 years ago
|
|
||
8 years ago
|
!(function () {
|
||
|
BI.Queue = function (capacity) {
|
||
|
this.capacity = capacity;
|
||
|
this.array = [];
|
||
|
};
|
||
|
BI.Queue.prototype = {
|
||
|
constructor: BI.Queue,
|
||
|
|
||
|
contains: function (v) {
|
||
7 years ago
|
return BI.contains(this.array, v);
|
||
8 years ago
|
},
|
||
|
|
||
|
indexOf: function (v) {
|
||
7 years ago
|
return BI.contains(this.array, v);
|
||
8 years ago
|
},
|
||
|
|
||
7 years ago
|
getElementByIndex: function (index) {
|
||
8 years ago
|
return this.array[index];
|
||
|
},
|
||
|
|
||
|
push: function (v) {
|
||
|
this.array.push(v);
|
||
|
if (this.capacity && this.array.length > this.capacity) {
|
||
|
this.array.shift();
|
||
|
}
|
||
|
},
|
||
|
|
||
|
pop: function () {
|
||
|
this.array.pop();
|
||
|
},
|
||
|
|
||
|
shift: function () {
|
||
|
this.array.shift();
|
||
|
},
|
||
|
|
||
|
unshift: function (v) {
|
||
|
this.array.unshift(v);
|
||
|
if (this.capacity && this.array.length > this.capacity) {
|
||
|
this.array.pop();
|
||
|
}
|
||
|
},
|
||
|
|
||
|
remove: function (v) {
|
||
7 years ago
|
BI.remove(this.array, v);
|
||
8 years ago
|
},
|
||
7 years ago
|
|
||
7 years ago
|
splice: function () {
|
||
|
this.array.splice.apply(this.array, arguments);
|
||
8 years ago
|
},
|
||
7 years ago
|
|
||
7 years ago
|
slice: function () {
|
||
|
this.array.slice.apply(this.array, arguments);
|
||
8 years ago
|
},
|
||
7 years ago
|
|
||
8 years ago
|
size: function () {
|
||
|
return this.array.length;
|
||
|
},
|
||
|
|
||
|
each: function (fn, scope) {
|
||
|
var scope = scope || window;
|
||
|
var fn = fn || null;
|
||
7 years ago
|
if (fn == null || typeof (fn) !== "function") {
|
||
8 years ago
|
return;
|
||
|
}
|
||
|
for (var i = 0; i < this.array.length; i++) {
|
||
|
var re = fn.call(scope, i, this.array[i], this.array);
|
||
|
if (re == false) {
|
||
|
break;
|
||
|
}
|
||
|
}
|
||
|
},
|
||
|
|
||
|
toArray: function () {
|
||
|
return this.array;
|
||
|
},
|
||
|
|
||
|
fromArray: function (array) {
|
||
|
var self = this;
|
||
|
BI.each(array, function (i, v) {
|
||
|
self.push(v);
|
||
7 years ago
|
});
|
||
8 years ago
|
},
|
||
|
|
||
|
clear: function () {
|
||
7 years ago
|
this.array.length = 0;
|
||
8 years ago
|
}
|
||
7 years ago
|
};
|
||
8 years ago
|
})();
|