forked from fanruan/fineui
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
|
|
!(function () { |
|
BI.Queue = function (capacity) { |
|
this.capacity = capacity; |
|
this.array = []; |
|
}; |
|
BI.Queue.prototype = { |
|
constructor: BI.Queue, |
|
|
|
contains: function (v) { |
|
return BI.contains(this.array, v); |
|
}, |
|
|
|
indexOf: function (v) { |
|
return BI.contains(this.array, v); |
|
}, |
|
|
|
getElementByIndex: function (index) { |
|
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) { |
|
BI.remove(this.array, v); |
|
}, |
|
|
|
splice: function () { |
|
this.array.splice.apply(this.array, arguments); |
|
}, |
|
|
|
slice: function () { |
|
this.array.slice.apply(this.array, arguments); |
|
}, |
|
|
|
size: function () { |
|
return this.array.length; |
|
}, |
|
|
|
each: function (fn, scope) { |
|
var scope = scope || window; |
|
var fn = fn || null; |
|
if (fn == null || typeof (fn) !== "function") { |
|
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); |
|
}); |
|
}, |
|
|
|
clear: function () { |
|
this.array.length = 0; |
|
} |
|
}; |
|
})(); |