Cleanup
This commit is contained in:
367
node_modules/denque/README.md
generated
vendored
367
node_modules/denque/README.md
generated
vendored
@@ -1,36 +1,39 @@
|
||||
<p align="center">
|
||||
<a href="https://invertase.io">
|
||||
<img src="https://static.invertase.io/assets/invertase-logo-small.png"><br/>
|
||||
</a>
|
||||
<h2 align="center">Denque</h2>
|
||||
<h1 align="center">Denque</h1>
|
||||
</p>
|
||||
|
||||
<p align="center">
|
||||
<a href="https://www.npmjs.com/package/denque"><img src="https://img.shields.io/npm/dm/denque.svg?style=flat-square" alt="NPM downloads"></a>
|
||||
<a href="https://www.npmjs.com/package/denque"><img src="https://img.shields.io/npm/v/denque.svg?style=flat-square" alt="NPM version"></a>
|
||||
<a href="https://travis-ci.org/Salakar/denque"><img src="https://travis-ci.org/invertase/denque.svg" alt="Build version"></a>
|
||||
<a href="https://coveralls.io/github/invertase/denque?branch=master"><img src="https://coveralls.io/repos/github/invertase/denque/badge.svg?branch=master" alt="Build version"></a>
|
||||
<a href="https://github.com/invertase/denque/actions/workflows/testing.yam"><img src="https://github.com/invertase/denque/actions/workflows/testing.yaml/badge.svg" alt="Tests status"></a>
|
||||
<a href="https://codecov.io/gh/invertase/denque"><img src="https://codecov.io/gh/invertase/denque/branch/master/graph/badge.svg?token=rn91iI4bSe" alt="Coverage"></a>
|
||||
<a href="/LICENSE"><img src="https://img.shields.io/npm/l/denque.svg?style=flat-square" alt="License"></a>
|
||||
<a href="https://discord.gg/C9aK28N"><img src="https://img.shields.io/discord/295953187817521152.svg?logo=discord&style=flat-square&colorA=7289da&label=discord" alt="Chat"></a>
|
||||
<a href="https://twitter.com/invertaseio"><img src="https://img.shields.io/twitter/follow/invertaseio.svg?style=social&label=Follow" alt="Follow on Twitter"></a>
|
||||
</p>
|
||||
|
||||
Extremely fast and lightweight [double-ended queue](http://en.wikipedia.org/wiki/Double-ended_queue) implementation with zero dependencies.
|
||||
Denque is a well tested, extremely fast and lightweight [double-ended queue](http://en.wikipedia.org/wiki/Double-ended_queue)
|
||||
implementation with zero dependencies and includes TypeScript types.
|
||||
|
||||
Double-ended queues can also be used as a:
|
||||
|
||||
- [Stack](http://en.wikipedia.org/wiki/Stack_\(abstract_data_type\))
|
||||
- [Queue](http://en.wikipedia.org/wiki/Queue_\(data_structure\))
|
||||
|
||||
This implementation is currently the fastest available, even faster than `double-ended-queue`, see the [benchmarks](#benchmarks)
|
||||
This implementation is currently the fastest available, even faster than `double-ended-queue`, see the [benchmarks](https://docs.page/invertase/denque/benchmarks).
|
||||
|
||||
Every queue operation is done at a constant `O(1)` - including random access from `.peekAt(index)`.
|
||||
|
||||
**Works on all node versions >= v0.10**
|
||||
|
||||
# Quick Start
|
||||
## Quick Start
|
||||
|
||||
npm install denque
|
||||
Install the package:
|
||||
|
||||
```bash
|
||||
npm install denque
|
||||
```
|
||||
|
||||
Create and consume a queue:
|
||||
|
||||
```js
|
||||
const Denque = require("denque");
|
||||
@@ -41,322 +44,34 @@ denque.pop(); // 4
|
||||
```
|
||||
|
||||
|
||||
# API
|
||||
See the [API reference documentation](https://docs.page/invertase/denque/api) for more examples.
|
||||
|
||||
- [`new Denque()`](#new-denque---denque)
|
||||
- [`new Denque(Array items)`](#new-denquearray-items---denque)
|
||||
- [`push(item)`](#pushitem---int)
|
||||
- [`unshift(item)`](#unshiftitem---int)
|
||||
- [`pop()`](#pop---dynamic)
|
||||
- [`shift()`](#shift---dynamic)
|
||||
- [`toArray()`](#toarray---array)
|
||||
- [`peekBack()`](#peekback---dynamic)
|
||||
- [`peekFront()`](#peekfront---dynamic)
|
||||
- [`peekAt(int index)`](#peekAtint-index---dynamic)
|
||||
- [`remove(int index, int count)`](#remove)
|
||||
- [`removeOne(int index)`](#removeOne)
|
||||
- [`splice(int index, int count, item1, item2, ...)`](#splice)
|
||||
- [`isEmpty()`](#isempty---boolean)
|
||||
- [`clear()`](#clear---void)
|
||||
|
||||
#### `new Denque()` -> `Denque`
|
||||
|
||||
Creates an empty double-ended queue with initial capacity of 4.
|
||||
|
||||
```js
|
||||
var denque = new Denque();
|
||||
denque.push(1);
|
||||
denque.push(2);
|
||||
denque.push(3);
|
||||
denque.shift(); //1
|
||||
denque.pop(); //3
|
||||
```
|
||||
|
||||
<hr>
|
||||
|
||||
#### `new Denque(Array items)` -> `Denque`
|
||||
|
||||
Creates a double-ended queue from `items`.
|
||||
|
||||
```js
|
||||
var denque = new Denque([1,2,3,4]);
|
||||
denque.shift(); // 1
|
||||
denque.pop(); // 4
|
||||
```
|
||||
|
||||
<hr>
|
||||
|
||||
|
||||
#### `push(item)` -> `int`
|
||||
|
||||
Push an item to the back of this queue. Returns the amount of items currently in the queue after the operation.
|
||||
|
||||
```js
|
||||
var denque = new Denque();
|
||||
denque.push(1);
|
||||
denque.pop(); // 1
|
||||
denque.push(2);
|
||||
denque.push(3);
|
||||
denque.shift(); // 2
|
||||
denque.shift(); // 3
|
||||
```
|
||||
|
||||
<hr>
|
||||
|
||||
#### `unshift(item)` -> `int`
|
||||
|
||||
Unshift an item to the front of this queue. Returns the amount of items currently in the queue after the operation.
|
||||
|
||||
```js
|
||||
var denque = new Denque([2,3]);
|
||||
denque.unshift(1);
|
||||
denque.toString(); // "1,2,3"
|
||||
denque.unshift(-2);
|
||||
denque.toString(); // "-2,-1,0,1,2,3"
|
||||
```
|
||||
|
||||
<hr>
|
||||
|
||||
|
||||
#### `pop()` -> `dynamic`
|
||||
|
||||
Pop off the item at the back of this queue.
|
||||
|
||||
Note: The item will be removed from the queue. If you simply want to see what's at the back of the queue use [`peekBack()`](#peekback---dynamic) or [`.peekAt(-1)`](#peekAtint-index---dynamic).
|
||||
|
||||
If the queue is empty, `undefined` is returned. If you need to differentiate between `undefined` values in the queue and `pop()` return value -
|
||||
check the queue `.length` before popping.
|
||||
|
||||
```js
|
||||
var denque = new Denque([1,2,3]);
|
||||
denque.pop(); // 3
|
||||
denque.pop(); // 2
|
||||
denque.pop(); // 1
|
||||
denque.pop(); // undefined
|
||||
```
|
||||
|
||||
**Aliases:** `removeBack`
|
||||
|
||||
<hr>
|
||||
|
||||
#### `shift()` -> `dynamic`
|
||||
|
||||
Shifts off the item at the front of this queue.
|
||||
|
||||
Note: The item will be removed from the queue. If you simply want to see what's at the front of the queue use [`peekFront()`](#peekfront---dynamic) or [`.peekAt(0)`](#peekAtint-index---dynamic).
|
||||
|
||||
If the queue is empty, `undefined` is returned. If you need to differentiate between `undefined` values in the queue and `shift()` return value -
|
||||
check the queue `.length` before shifting.
|
||||
|
||||
```js
|
||||
var denque = new Denque([1,2,3]);
|
||||
denque.shift(); // 1
|
||||
denque.shift(); // 2
|
||||
denque.shift(); // 3
|
||||
denque.shift(); // undefined
|
||||
```
|
||||
|
||||
<hr>
|
||||
|
||||
#### `toArray()` -> `Array`
|
||||
|
||||
Returns the items in the queue as an array. Starting from the item in the front of the queue and ending to the item at the back of the queue.
|
||||
|
||||
```js
|
||||
var denque = new Denque([1,2,3]);
|
||||
denque.push(4);
|
||||
denque.unshift(0);
|
||||
denque.toArray(); // [0,1,2,3,4]
|
||||
```
|
||||
|
||||
<hr>
|
||||
|
||||
#### `peekBack()` -> `dynamic`
|
||||
|
||||
Returns the item that is at the back of this queue without removing it.
|
||||
|
||||
If the queue is empty, `undefined` is returned.
|
||||
|
||||
```js
|
||||
var denque = new Denque([1,2,3]);
|
||||
denque.push(4);
|
||||
denque.peekBack(); // 4
|
||||
```
|
||||
|
||||
<hr>
|
||||
|
||||
#### `peekFront()` -> `dynamic`
|
||||
|
||||
Returns the item that is at the front of this queue without removing it.
|
||||
|
||||
If the queue is empty, `undefined` is returned.
|
||||
|
||||
```js
|
||||
var denque = new Denque([1,2,3]);
|
||||
denque.push(4);
|
||||
denque.peekFront(); // 1
|
||||
```
|
||||
|
||||
<hr>
|
||||
|
||||
#### `peekAt(int index)` -> `dynamic`
|
||||
|
||||
Returns the item that is at the given `index` of this queue without removing it.
|
||||
|
||||
The index is zero-based, so `.peekAt(0)` will return the item that is at the front, `.peekAt(1)` will return
|
||||
the item that comes after and so on.
|
||||
|
||||
The index can be negative to read items at the back of the queue. `.peekAt(-1)` returns the item that is at the back of the queue,
|
||||
`.peekAt(-2)` will return the item that comes before and so on.
|
||||
|
||||
Returns `undefined` if `index` is not a valid index into the queue.
|
||||
|
||||
```js
|
||||
var denque = new Denque([1,2,3]);
|
||||
denque.peekAt(0); //1
|
||||
denque.peekAt(1); //2
|
||||
denque.peekAt(2); //3
|
||||
|
||||
denque.peekAt(-1); // 3
|
||||
denque.peekAt(-2); // 2
|
||||
denque.peekAt(-3); // 1
|
||||
```
|
||||
|
||||
**Note**: The implementation has O(1) random access using `.peekAt()`.
|
||||
|
||||
**Aliases:** `get`
|
||||
|
||||
<hr>
|
||||
|
||||
#### `remove(int index, int count)` -> `array`
|
||||
|
||||
Remove number of items from the specified index from the list.
|
||||
|
||||
Returns array of removed items.
|
||||
|
||||
Returns undefined if the list is empty.
|
||||
|
||||
```js
|
||||
var denque = new Denque([1,2,3,4,5,6,7]);
|
||||
denque.remove(0,3); //[1,2,3]
|
||||
denque.remove(1,2); //[5,6]
|
||||
var denque1 = new Denque([1,2,3,4,5,6,7]);
|
||||
denque1.remove(4, 100); //[5,6,7]
|
||||
```
|
||||
|
||||
<hr>
|
||||
|
||||
#### `removeOne(int index)` -> `dynamic`
|
||||
|
||||
Remove and return the item at the specified index from the list.
|
||||
|
||||
Returns undefined if the list is empty.
|
||||
|
||||
```js
|
||||
var denque = new Denque([1,2,3,4,5,6,7]);
|
||||
denque.removeOne(4); // 5
|
||||
denque.removeOne(3); // 4
|
||||
denque1.removeOne(1); // 2
|
||||
```
|
||||
|
||||
<hr>
|
||||
|
||||
#### `splice(int index, int count, item1, item2, ...)` -> `array`
|
||||
|
||||
Native splice implementation.
|
||||
|
||||
Remove number of items from the specified index from the list and/or add new elements.
|
||||
|
||||
Returns array of removed items or empty array if count == 0.
|
||||
|
||||
Returns undefined if the list is empty.
|
||||
|
||||
```js
|
||||
var denque = new Denque([1,2,3,4,5,6,7]);
|
||||
denque.splice(denque.length, 0, 8, 9, 10); // []
|
||||
denque.toArray() // [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 ]
|
||||
denque.splice(3, 3, 44, 55, 66); // [4,5,6]
|
||||
denque.splice(5,4, 666,667,668,669); // [ 66, 7, 8, 9 ]
|
||||
denque.toArray() // [ 1, 2, 3, 44, 55, 666, 667, 668, 669, 10 ]
|
||||
```
|
||||
|
||||
<hr>
|
||||
|
||||
#### `isEmpty()` -> `boolean`
|
||||
|
||||
Return `true` if this queue is empty, `false` otherwise.
|
||||
|
||||
```js
|
||||
var denque = new Denque();
|
||||
denque.isEmpty(); // true
|
||||
denque.push(1);
|
||||
denque.isEmpty(); // false
|
||||
```
|
||||
|
||||
<hr>
|
||||
|
||||
#### `clear()` -> `void`
|
||||
|
||||
Remove all items from this queue. Does not change the queue's capacity.
|
||||
|
||||
```js
|
||||
var denque = new Denque([1,2,3]);
|
||||
denque.toString(); // "1,2,3"
|
||||
denque.clear();
|
||||
denque.toString(); // ""
|
||||
```
|
||||
<hr>
|
||||
|
||||
|
||||
## Benchmarks
|
||||
|
||||
#### Platform info:
|
||||
```
|
||||
Darwin 17.0.0 x64
|
||||
Node.JS 9.4.0
|
||||
V8 6.2.414.46-node.17
|
||||
Intel(R) Core(TM) i7-7700K CPU @ 4.20GHz × 8
|
||||
```
|
||||
|
||||
#### 1000 items in queue
|
||||
|
||||
(3 x shift + 3 x push ops per 'op')
|
||||
|
||||
denque x 64,365,425 ops/sec ±0.69% (92 runs sampled)
|
||||
double-ended-queue x 26,646,882 ops/sec ±0.47% (94 runs sampled)
|
||||
|
||||
#### 2 million items in queue
|
||||
|
||||
(3 x shift + 3 x push ops per 'op')
|
||||
|
||||
denque x 61,994,249 ops/sec ±0.26% (95 runs sampled)
|
||||
double-ended-queue x 26,363,500 ops/sec ±0.42% (91 runs sampled)
|
||||
|
||||
#### Splice
|
||||
|
||||
(1 x splice per 'op') - initial size of 100,000 items
|
||||
|
||||
denque.splice x 925,749 ops/sec ±22.29% (77 runs sampled)
|
||||
native array splice x 7,777 ops/sec ±8.35% (50 runs sampled)
|
||||
|
||||
#### Remove
|
||||
|
||||
(1 x remove + 10 x push per 'op') - initial size of 100,000 items
|
||||
|
||||
denque.remove x 2,635,275 ops/sec ±0.37% (95 runs sampled)
|
||||
native array splice - Fails to complete: "JavaScript heap out of memory"
|
||||
|
||||
#### Remove One
|
||||
|
||||
(1 x removeOne + 10 x push per 'op') - initial size of 100,000 items
|
||||
|
||||
denque.removeOne x 1,088,240 ops/sec ±0.21% (93 runs sampled)
|
||||
native array splice x 5,300 ops/sec ±0.41% (96 runs sampled)
|
||||
|
||||
---
|
||||
|
||||
Built and maintained with 💛 by [Invertase](https://invertase.io).
|
||||
## Who's using it?
|
||||
|
||||
- [💼 Hire Us](https://invertase.io/hire-us)
|
||||
- [☕️ Sponsor Us](https://opencollective.com/react-native-firebase)
|
||||
- [👩💻 Work With Us](https://invertase.io/jobs)
|
||||
- [Kafka Node.js client](https://www.npmjs.com/package/kafka-node)
|
||||
- [MariaDB Node.js client](https://www.npmjs.com/package/mariadb)
|
||||
- [MongoDB Node.js client](https://www.npmjs.com/package/mongodb)
|
||||
- [MySQL Node.js client](https://www.npmjs.com/package/mysql2)
|
||||
- [Redis Node.js clients](https://www.npmjs.com/package/redis)
|
||||
|
||||
... and [many more](https://www.npmjs.com/browse/depended/denque).
|
||||
|
||||
|
||||
---
|
||||
|
||||
## License
|
||||
|
||||
- See [LICENSE](/LICENSE)
|
||||
|
||||
---
|
||||
|
||||
<p align="center">
|
||||
<a href="https://invertase.io/?utm_source=readme&utm_medium=footer&utm_campaign=docs.page">
|
||||
<img width="75px" src="https://static.invertase.io/assets/invertase/invertase-rounded-avatar.png">
|
||||
</a>
|
||||
<p align="center">
|
||||
Built and maintained by <a href="https://invertase.io/?utm_source=readme&utm_medium=footer&utm_campaign=denque">Invertase</a>.
|
||||
</p>
|
||||
</p>
|
||||
|
||||
5
node_modules/denque/index.d.ts
generated
vendored
5
node_modules/denque/index.d.ts
generated
vendored
@@ -1,6 +1,7 @@
|
||||
declare class Denque<T = any> {
|
||||
constructor();
|
||||
constructor(array: T[]);
|
||||
constructor(array: T[], options: IDenqueOptions);
|
||||
|
||||
push(item: T): number;
|
||||
unshift(item: T): number;
|
||||
@@ -23,4 +24,8 @@ declare class Denque<T = any> {
|
||||
length: number;
|
||||
}
|
||||
|
||||
interface IDenqueOptions {
|
||||
capacity?: number
|
||||
}
|
||||
|
||||
export = Denque;
|
||||
|
||||
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;
|
||||
};
|
||||
|
||||
|
||||
14
node_modules/denque/package.json
generated
vendored
14
node_modules/denque/package.json
generated
vendored
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "denque",
|
||||
"version": "1.4.1",
|
||||
"description": "The fastest javascript implementation of a double-ended queue. Maintains compatability with deque.",
|
||||
"version": "1.5.1",
|
||||
"description": "The fastest javascript implementation of a double-ended queue. Used by the official Redis, MongoDB, MariaDB & MySQL libraries for Node.js and many other libraries. Maintains compatability with deque.",
|
||||
"main": "index.js",
|
||||
"engines": {
|
||||
"node": ">=0.10"
|
||||
@@ -43,17 +43,13 @@
|
||||
"bugs": {
|
||||
"url": "https://github.com/invertase/denque/issues"
|
||||
},
|
||||
"homepage": "https://github.com/invertase/denque#readme",
|
||||
"homepage": "https://docs.page/invertase/denque",
|
||||
"devDependencies": {
|
||||
"benchmark": "^2.1.4",
|
||||
"coveralls": "^2.13.3",
|
||||
"codecov": "^3.8.3",
|
||||
"double-ended-queue": "^2.1.0-0",
|
||||
"istanbul": "^0.4.5",
|
||||
"mocha": "^3.5.3",
|
||||
"typescript": "^3.4.1"
|
||||
}
|
||||
|
||||
,"_resolved": "https://registry.npmjs.org/denque/-/denque-1.4.1.tgz"
|
||||
,"_integrity": "sha512-OfzPuSZKGcgr96rf1oODnfjqBFmr1DVoc/TrItj3Ohe0Ah1C5WX5Baquw/9U9KovnQ88EqmJbD66rKYUQYN1tQ=="
|
||||
,"_from": "denque@1.4.1"
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user