Cleanup
This commit is contained in:
14
node_modules/denque/index.js
generated
vendored
14
node_modules/denque/index.js
generated
vendored
@@ -3,9 +3,12 @@
|
||||
/**
|
||||
* Custom implementation of a double ended queue.
|
||||
*/
|
||||
function Denque(array) {
|
||||
function Denque(array, options) {
|
||||
var options = options || {};
|
||||
|
||||
this._head = 0;
|
||||
this._tail = 0;
|
||||
this._capacity = options.capacity;
|
||||
this._capacityMask = 0x3;
|
||||
this._list = new Array(4);
|
||||
if (Array.isArray(array)) {
|
||||
@@ -41,7 +44,7 @@ Denque.prototype.peekAt = function peekAt(index) {
|
||||
};
|
||||
|
||||
/**
|
||||
* Alias for peakAt()
|
||||
* Alias for peekAt()
|
||||
* @param i
|
||||
* @returns {*}
|
||||
*/
|
||||
@@ -104,6 +107,7 @@ Denque.prototype.unshift = function unshift(item) {
|
||||
this._head = (this._head - 1 + len) & this._capacityMask;
|
||||
this._list[this._head] = item;
|
||||
if (this._tail === this._head) this._growArray();
|
||||
if (this._capacity && this.size() > this._capacity) this.pop();
|
||||
if (this._head < this._tail) return this._tail - this._head;
|
||||
else return this._capacityMask + 1 - (this._head - this._tail);
|
||||
};
|
||||
@@ -135,7 +139,9 @@ Denque.prototype.push = function push(item) {
|
||||
if (this._tail === this._head) {
|
||||
this._growArray();
|
||||
}
|
||||
|
||||
if (this._capacity && this.size() > this._capacity) {
|
||||
this.shift();
|
||||
}
|
||||
if (this._head < this._tail) return this._tail - this._head;
|
||||
else return this._capacityMask + 1 - (this._head - this._tail);
|
||||
};
|
||||
@@ -420,7 +426,7 @@ Denque.prototype._growArray = function _growArray() {
|
||||
// head is at 0 and array is now full, safe to extend
|
||||
this._tail = this._list.length;
|
||||
|
||||
this._list.length *= 2;
|
||||
this._list.length <<= 1;
|
||||
this._capacityMask = (this._capacityMask << 1) | 1;
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user