denque
Advanced tools
Comparing version 1.4.1 to 1.5.0
declare class Denque<T = any> { | ||
constructor(); | ||
constructor(array: T[]); | ||
constructor(array: T[], options: IDenqueOptions); | ||
@@ -26,2 +27,6 @@ push(item: T): number; | ||
interface IDenqueOptions { | ||
capacity?: number | ||
} | ||
export = Denque; |
12
index.js
@@ -6,5 +6,8 @@ 'use strict'; | ||
*/ | ||
function Denque(array) { | ||
function Denque(array, options) { | ||
var options = options || {}; | ||
this._head = 0; | ||
this._tail = 0; | ||
this._capacity = options.capacity; | ||
this._capacityMask = 0x3; | ||
@@ -45,3 +48,3 @@ this._list = new Array(4); | ||
/** | ||
* Alias for peakAt() | ||
* Alias for peekAt() | ||
* @param i | ||
@@ -109,2 +112,3 @@ * @returns {*} | ||
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; | ||
@@ -141,3 +145,5 @@ else return this._capacityMask + 1 - (this._head - this._tail); | ||
} | ||
if (this._capacity && this.size() > this._capacity) { | ||
this.shift(); | ||
} | ||
if (this._head < this._tail) return this._tail - this._head; | ||
@@ -144,0 +150,0 @@ else return this._capacityMask + 1 - (this._head - this._tail); |
{ | ||
"name": "denque", | ||
"version": "1.4.1", | ||
"version": "1.5.0", | ||
"description": "The fastest javascript implementation of a double-ended queue. Maintains compatability with deque.", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
24035
6
440