redis 3.1.0 → 3.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/heroku/index.js +14 -0
- package/heroku/node_modules/.package-lock.json +57 -0
- package/heroku/node_modules/denque/CHANGELOG.md +4 -0
- package/heroku/node_modules/denque/LICENSE +13 -0
- package/heroku/node_modules/denque/README.md +362 -0
- package/heroku/node_modules/denque/index.d.ts +31 -0
- package/heroku/node_modules/denque/index.js +443 -0
- package/heroku/node_modules/denque/package.json +55 -0
- package/heroku/node_modules/redis/.deepsource.toml +9 -0
- package/heroku/node_modules/redis/CHANGELOG.md +880 -0
- package/heroku/node_modules/redis/LICENSE +24 -0
- package/heroku/node_modules/redis/README.md +1009 -0
- package/{a.js → heroku/node_modules/redis/a.js} +0 -0
- package/heroku/node_modules/redis/index.js +1039 -0
- package/heroku/node_modules/redis/lib/command.js +16 -0
- package/heroku/node_modules/redis/lib/commands.js +105 -0
- package/heroku/node_modules/redis/lib/createClient.js +88 -0
- package/heroku/node_modules/redis/lib/customErrors.js +58 -0
- package/heroku/node_modules/redis/lib/debug.js +13 -0
- package/heroku/node_modules/redis/lib/extendedApi.js +113 -0
- package/heroku/node_modules/redis/lib/individualCommands.js +629 -0
- package/heroku/node_modules/redis/lib/multi.js +187 -0
- package/heroku/node_modules/redis/lib/utils.js +134 -0
- package/{npm → heroku/node_modules/redis/npm} +0 -0
- package/heroku/node_modules/redis/package.json +77 -0
- package/heroku/node_modules/redis-commands/LICENSE +22 -0
- package/heroku/node_modules/redis-commands/README.md +51 -0
- package/heroku/node_modules/redis-commands/changelog.md +83 -0
- package/heroku/node_modules/redis-commands/commands.json +2334 -0
- package/heroku/node_modules/redis-commands/index.js +168 -0
- package/heroku/node_modules/redis-commands/package.json +41 -0
- package/heroku/node_modules/redis-commands/tools/build.js +62 -0
- package/heroku/node_modules/redis-errors/LICENSE +22 -0
- package/heroku/node_modules/redis-errors/README.md +116 -0
- package/heroku/node_modules/redis-errors/index.js +7 -0
- package/heroku/node_modules/redis-errors/lib/modern.js +59 -0
- package/heroku/node_modules/redis-errors/lib/old.js +119 -0
- package/heroku/node_modules/redis-errors/package.json +41 -0
- package/heroku/node_modules/redis-parser/LICENSE +22 -0
- package/heroku/node_modules/redis-parser/README.md +166 -0
- package/heroku/node_modules/redis-parser/changelog.md +156 -0
- package/heroku/node_modules/redis-parser/index.js +3 -0
- package/heroku/node_modules/redis-parser/lib/parser.js +552 -0
- package/heroku/node_modules/redis-parser/package.json +53 -0
- package/heroku/package.json +9 -0
- package/lib/utils.js +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -14,9 +14,9 @@
|
|
|
14
14
|
<a href="https://github.com/NodeRedis/node-redis/actions?query=workflow%3ATests"><img src="https://github.com/NodeRedis/node-redis/workflows/Tests/badge.svg" alt="Build Status" /></a>
|
|
15
15
|
<a href="https://github.com/NodeRedis/node-redis/actions?query=workflow%3A%22Tests+Windows%22"><img src="https://github.com/NodeRedis/node-redis/workflows/Tests%20Windows/badge.svg" alt="Windows Build Status" /></a>
|
|
16
16
|
<a href="https://coveralls.io/r/NodeRedis/node-redis?branch="><img src="https://coveralls.io/repos/NodeRedis/node-redis/badge.svg?branch=master" alt="Coverage Status" /></a>
|
|
17
|
-
<a href="https://twitter.com/NodeRedis"><img src="https://img.shields.io/twitter/follow/NodeRedis.svg?style=flat-square&colorA=1da1f2&colorB=&label=Follow%20on%20Twitter" alt="Follow on Twitter"></a>
|
|
18
17
|
<a href="https://codeclimate.com/github/NodeRedis/node-redis/maintainability"><img src="https://api.codeclimate.com/v1/badges/f6d7063243c234237e73/maintainability" /></a>
|
|
19
18
|
<a href="https://lgtm.com/projects/g/NodeRedis/node-redis/context:javascript"><img src="https://img.shields.io/lgtm/grade/javascript/g/NodeRedis/node-redis.svg?logo=lgtm&logoWidth=18" alt="Coverage Status" /></a>
|
|
19
|
+
<a href="https://discord.gg/XMMVgxUm"><img src="https://img.shields.io/discord/697882427875393627?style=flat-square" /></a>
|
|
20
20
|
</p>
|
|
21
21
|
|
|
22
22
|
---
|
package/heroku/index.js
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
const redis = require("redis");
|
|
2
|
+
const client = redis.createClient(process.env.REDISCLOUD_URL);
|
|
3
|
+
|
|
4
|
+
console.log(process.env.REDISCLOUD_URL);
|
|
5
|
+
|
|
6
|
+
setInterval(() => {
|
|
7
|
+
client.get('a', (err, result) => {
|
|
8
|
+
if (err) {
|
|
9
|
+
return console.error(err);
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
console.log(result);
|
|
13
|
+
})
|
|
14
|
+
}, 3000);
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "heroku",
|
|
3
|
+
"lockfileVersion": 2,
|
|
4
|
+
"requires": true,
|
|
5
|
+
"packages": {
|
|
6
|
+
"node_modules/denque": {
|
|
7
|
+
"version": "1.5.0",
|
|
8
|
+
"resolved": "https://registry.npmjs.org/denque/-/denque-1.5.0.tgz",
|
|
9
|
+
"integrity": "sha512-CYiCSgIF1p6EUByQPlGkKnP1M9g0ZV3qMIrqMqZqdwazygIA/YP2vrbcyl1h/WppKJTdl1F85cXIle+394iDAQ==",
|
|
10
|
+
"engines": {
|
|
11
|
+
"node": ">=0.10"
|
|
12
|
+
}
|
|
13
|
+
},
|
|
14
|
+
"node_modules/redis": {
|
|
15
|
+
"version": "3.1.0",
|
|
16
|
+
"resolved": "https://registry.npmjs.org/redis/-/redis-3.1.0.tgz",
|
|
17
|
+
"integrity": "sha512-//lAOcEtNIKk2ekZibes5oyWKYUVWMvMB71lyD/hS9KRePNkB7AU3nXGkArX6uDKEb2N23EyJBthAv6pagD0uw==",
|
|
18
|
+
"dependencies": {
|
|
19
|
+
"denque": "^1.5.0",
|
|
20
|
+
"redis-commands": "^1.7.0",
|
|
21
|
+
"redis-errors": "^1.2.0",
|
|
22
|
+
"redis-parser": "^3.0.0"
|
|
23
|
+
},
|
|
24
|
+
"engines": {
|
|
25
|
+
"node": ">=10"
|
|
26
|
+
},
|
|
27
|
+
"funding": {
|
|
28
|
+
"type": "opencollective",
|
|
29
|
+
"url": "https://opencollective.com/node-redis"
|
|
30
|
+
}
|
|
31
|
+
},
|
|
32
|
+
"node_modules/redis-commands": {
|
|
33
|
+
"version": "1.7.0",
|
|
34
|
+
"resolved": "https://registry.npmjs.org/redis-commands/-/redis-commands-1.7.0.tgz",
|
|
35
|
+
"integrity": "sha512-nJWqw3bTFy21hX/CPKHth6sfhZbdiHP6bTawSgQBlKOVRG7EZkfHbbHwQJnrE4vsQf0CMNE+3gJ4Fmm16vdVlQ=="
|
|
36
|
+
},
|
|
37
|
+
"node_modules/redis-errors": {
|
|
38
|
+
"version": "1.2.0",
|
|
39
|
+
"resolved": "https://registry.npmjs.org/redis-errors/-/redis-errors-1.2.0.tgz",
|
|
40
|
+
"integrity": "sha1-62LSrbFeTq9GEMBK/hUpOEJQq60=",
|
|
41
|
+
"engines": {
|
|
42
|
+
"node": ">=4"
|
|
43
|
+
}
|
|
44
|
+
},
|
|
45
|
+
"node_modules/redis-parser": {
|
|
46
|
+
"version": "3.0.0",
|
|
47
|
+
"resolved": "https://registry.npmjs.org/redis-parser/-/redis-parser-3.0.0.tgz",
|
|
48
|
+
"integrity": "sha1-tm2CjNyv5rS4pCin3vTGvKwxyLQ=",
|
|
49
|
+
"dependencies": {
|
|
50
|
+
"redis-errors": "^1.0.0"
|
|
51
|
+
},
|
|
52
|
+
"engines": {
|
|
53
|
+
"node": ">=4"
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
Copyright (c) 2018 Mike Diarmid (Salakar) <mike.diarmid@gmail.com>
|
|
2
|
+
|
|
3
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
you may not use this library except in compliance with the License.
|
|
5
|
+
You may obtain a copy of the License at
|
|
6
|
+
|
|
7
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
|
|
9
|
+
Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
See the License for the specific language governing permissions and
|
|
13
|
+
limitations under the License.
|
|
@@ -0,0 +1,362 @@
|
|
|
1
|
+
<p align="center">
|
|
2
|
+
<a href="https://invertase.io">
|
|
3
|
+
<img src="https://static.invertase.io/assets/invertase-logo-small.png"><br/>
|
|
4
|
+
</a>
|
|
5
|
+
<h2 align="center">Denque</h2>
|
|
6
|
+
</p>
|
|
7
|
+
|
|
8
|
+
<p align="center">
|
|
9
|
+
<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>
|
|
10
|
+
<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>
|
|
11
|
+
<a href="https://travis-ci.org/Salakar/denque"><img src="https://travis-ci.org/invertase/denque.svg" alt="Build version"></a>
|
|
12
|
+
<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>
|
|
13
|
+
<a href="/LICENSE"><img src="https://img.shields.io/npm/l/denque.svg?style=flat-square" alt="License"></a>
|
|
14
|
+
<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>
|
|
15
|
+
<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>
|
|
16
|
+
</p>
|
|
17
|
+
|
|
18
|
+
Extremely fast and lightweight [double-ended queue](http://en.wikipedia.org/wiki/Double-ended_queue) implementation with zero dependencies.
|
|
19
|
+
|
|
20
|
+
Double-ended queues can also be used as a:
|
|
21
|
+
|
|
22
|
+
- [Stack](http://en.wikipedia.org/wiki/Stack_\(abstract_data_type\))
|
|
23
|
+
- [Queue](http://en.wikipedia.org/wiki/Queue_\(data_structure\))
|
|
24
|
+
|
|
25
|
+
This implementation is currently the fastest available, even faster than `double-ended-queue`, see the [benchmarks](#benchmarks)
|
|
26
|
+
|
|
27
|
+
Every queue operation is done at a constant `O(1)` - including random access from `.peekAt(index)`.
|
|
28
|
+
|
|
29
|
+
**Works on all node versions >= v0.10**
|
|
30
|
+
|
|
31
|
+
# Quick Start
|
|
32
|
+
|
|
33
|
+
npm install denque
|
|
34
|
+
|
|
35
|
+
```js
|
|
36
|
+
const Denque = require("denque");
|
|
37
|
+
|
|
38
|
+
const denque = new Denque([1,2,3,4]);
|
|
39
|
+
denque.shift(); // 1
|
|
40
|
+
denque.pop(); // 4
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
# API
|
|
45
|
+
|
|
46
|
+
- [`new Denque()`](#new-denque---denque)
|
|
47
|
+
- [`new Denque(Array items)`](#new-denquearray-items---denque)
|
|
48
|
+
- [`push(item)`](#pushitem---int)
|
|
49
|
+
- [`unshift(item)`](#unshiftitem---int)
|
|
50
|
+
- [`pop()`](#pop---dynamic)
|
|
51
|
+
- [`shift()`](#shift---dynamic)
|
|
52
|
+
- [`toArray()`](#toarray---array)
|
|
53
|
+
- [`peekBack()`](#peekback---dynamic)
|
|
54
|
+
- [`peekFront()`](#peekfront---dynamic)
|
|
55
|
+
- [`peekAt(int index)`](#peekAtint-index---dynamic)
|
|
56
|
+
- [`remove(int index, int count)`](#remove)
|
|
57
|
+
- [`removeOne(int index)`](#removeOne)
|
|
58
|
+
- [`splice(int index, int count, item1, item2, ...)`](#splice)
|
|
59
|
+
- [`isEmpty()`](#isempty---boolean)
|
|
60
|
+
- [`clear()`](#clear---void)
|
|
61
|
+
|
|
62
|
+
#### `new Denque()` -> `Denque`
|
|
63
|
+
|
|
64
|
+
Creates an empty double-ended queue with initial capacity of 4.
|
|
65
|
+
|
|
66
|
+
```js
|
|
67
|
+
var denque = new Denque();
|
|
68
|
+
denque.push(1);
|
|
69
|
+
denque.push(2);
|
|
70
|
+
denque.push(3);
|
|
71
|
+
denque.shift(); //1
|
|
72
|
+
denque.pop(); //3
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
<hr>
|
|
76
|
+
|
|
77
|
+
#### `new Denque(Array items)` -> `Denque`
|
|
78
|
+
|
|
79
|
+
Creates a double-ended queue from `items`.
|
|
80
|
+
|
|
81
|
+
```js
|
|
82
|
+
var denque = new Denque([1,2,3,4]);
|
|
83
|
+
denque.shift(); // 1
|
|
84
|
+
denque.pop(); // 4
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
<hr>
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
#### `push(item)` -> `int`
|
|
91
|
+
|
|
92
|
+
Push an item to the back of this queue. Returns the amount of items currently in the queue after the operation.
|
|
93
|
+
|
|
94
|
+
```js
|
|
95
|
+
var denque = new Denque();
|
|
96
|
+
denque.push(1);
|
|
97
|
+
denque.pop(); // 1
|
|
98
|
+
denque.push(2);
|
|
99
|
+
denque.push(3);
|
|
100
|
+
denque.shift(); // 2
|
|
101
|
+
denque.shift(); // 3
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
<hr>
|
|
105
|
+
|
|
106
|
+
#### `unshift(item)` -> `int`
|
|
107
|
+
|
|
108
|
+
Unshift an item to the front of this queue. Returns the amount of items currently in the queue after the operation.
|
|
109
|
+
|
|
110
|
+
```js
|
|
111
|
+
var denque = new Denque([2,3]);
|
|
112
|
+
denque.unshift(1);
|
|
113
|
+
denque.toString(); // "1,2,3"
|
|
114
|
+
denque.unshift(-2);
|
|
115
|
+
denque.toString(); // "-2,-1,0,1,2,3"
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
<hr>
|
|
119
|
+
|
|
120
|
+
|
|
121
|
+
#### `pop()` -> `dynamic`
|
|
122
|
+
|
|
123
|
+
Pop off the item at the back of this queue.
|
|
124
|
+
|
|
125
|
+
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).
|
|
126
|
+
|
|
127
|
+
If the queue is empty, `undefined` is returned. If you need to differentiate between `undefined` values in the queue and `pop()` return value -
|
|
128
|
+
check the queue `.length` before popping.
|
|
129
|
+
|
|
130
|
+
```js
|
|
131
|
+
var denque = new Denque([1,2,3]);
|
|
132
|
+
denque.pop(); // 3
|
|
133
|
+
denque.pop(); // 2
|
|
134
|
+
denque.pop(); // 1
|
|
135
|
+
denque.pop(); // undefined
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
**Aliases:** `removeBack`
|
|
139
|
+
|
|
140
|
+
<hr>
|
|
141
|
+
|
|
142
|
+
#### `shift()` -> `dynamic`
|
|
143
|
+
|
|
144
|
+
Shifts off the item at the front of this queue.
|
|
145
|
+
|
|
146
|
+
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).
|
|
147
|
+
|
|
148
|
+
If the queue is empty, `undefined` is returned. If you need to differentiate between `undefined` values in the queue and `shift()` return value -
|
|
149
|
+
check the queue `.length` before shifting.
|
|
150
|
+
|
|
151
|
+
```js
|
|
152
|
+
var denque = new Denque([1,2,3]);
|
|
153
|
+
denque.shift(); // 1
|
|
154
|
+
denque.shift(); // 2
|
|
155
|
+
denque.shift(); // 3
|
|
156
|
+
denque.shift(); // undefined
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
<hr>
|
|
160
|
+
|
|
161
|
+
#### `toArray()` -> `Array`
|
|
162
|
+
|
|
163
|
+
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.
|
|
164
|
+
|
|
165
|
+
```js
|
|
166
|
+
var denque = new Denque([1,2,3]);
|
|
167
|
+
denque.push(4);
|
|
168
|
+
denque.unshift(0);
|
|
169
|
+
denque.toArray(); // [0,1,2,3,4]
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
<hr>
|
|
173
|
+
|
|
174
|
+
#### `peekBack()` -> `dynamic`
|
|
175
|
+
|
|
176
|
+
Returns the item that is at the back of this queue without removing it.
|
|
177
|
+
|
|
178
|
+
If the queue is empty, `undefined` is returned.
|
|
179
|
+
|
|
180
|
+
```js
|
|
181
|
+
var denque = new Denque([1,2,3]);
|
|
182
|
+
denque.push(4);
|
|
183
|
+
denque.peekBack(); // 4
|
|
184
|
+
```
|
|
185
|
+
|
|
186
|
+
<hr>
|
|
187
|
+
|
|
188
|
+
#### `peekFront()` -> `dynamic`
|
|
189
|
+
|
|
190
|
+
Returns the item that is at the front of this queue without removing it.
|
|
191
|
+
|
|
192
|
+
If the queue is empty, `undefined` is returned.
|
|
193
|
+
|
|
194
|
+
```js
|
|
195
|
+
var denque = new Denque([1,2,3]);
|
|
196
|
+
denque.push(4);
|
|
197
|
+
denque.peekFront(); // 1
|
|
198
|
+
```
|
|
199
|
+
|
|
200
|
+
<hr>
|
|
201
|
+
|
|
202
|
+
#### `peekAt(int index)` -> `dynamic`
|
|
203
|
+
|
|
204
|
+
Returns the item that is at the given `index` of this queue without removing it.
|
|
205
|
+
|
|
206
|
+
The index is zero-based, so `.peekAt(0)` will return the item that is at the front, `.peekAt(1)` will return
|
|
207
|
+
the item that comes after and so on.
|
|
208
|
+
|
|
209
|
+
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,
|
|
210
|
+
`.peekAt(-2)` will return the item that comes before and so on.
|
|
211
|
+
|
|
212
|
+
Returns `undefined` if `index` is not a valid index into the queue.
|
|
213
|
+
|
|
214
|
+
```js
|
|
215
|
+
var denque = new Denque([1,2,3]);
|
|
216
|
+
denque.peekAt(0); //1
|
|
217
|
+
denque.peekAt(1); //2
|
|
218
|
+
denque.peekAt(2); //3
|
|
219
|
+
|
|
220
|
+
denque.peekAt(-1); // 3
|
|
221
|
+
denque.peekAt(-2); // 2
|
|
222
|
+
denque.peekAt(-3); // 1
|
|
223
|
+
```
|
|
224
|
+
|
|
225
|
+
**Note**: The implementation has O(1) random access using `.peekAt()`.
|
|
226
|
+
|
|
227
|
+
**Aliases:** `get`
|
|
228
|
+
|
|
229
|
+
<hr>
|
|
230
|
+
|
|
231
|
+
#### `remove(int index, int count)` -> `array`
|
|
232
|
+
|
|
233
|
+
Remove number of items from the specified index from the list.
|
|
234
|
+
|
|
235
|
+
Returns array of removed items.
|
|
236
|
+
|
|
237
|
+
Returns undefined if the list is empty.
|
|
238
|
+
|
|
239
|
+
```js
|
|
240
|
+
var denque = new Denque([1,2,3,4,5,6,7]);
|
|
241
|
+
denque.remove(0,3); //[1,2,3]
|
|
242
|
+
denque.remove(1,2); //[5,6]
|
|
243
|
+
var denque1 = new Denque([1,2,3,4,5,6,7]);
|
|
244
|
+
denque1.remove(4, 100); //[5,6,7]
|
|
245
|
+
```
|
|
246
|
+
|
|
247
|
+
<hr>
|
|
248
|
+
|
|
249
|
+
#### `removeOne(int index)` -> `dynamic`
|
|
250
|
+
|
|
251
|
+
Remove and return the item at the specified index from the list.
|
|
252
|
+
|
|
253
|
+
Returns undefined if the list is empty.
|
|
254
|
+
|
|
255
|
+
```js
|
|
256
|
+
var denque = new Denque([1,2,3,4,5,6,7]);
|
|
257
|
+
denque.removeOne(4); // 5
|
|
258
|
+
denque.removeOne(3); // 4
|
|
259
|
+
denque1.removeOne(1); // 2
|
|
260
|
+
```
|
|
261
|
+
|
|
262
|
+
<hr>
|
|
263
|
+
|
|
264
|
+
#### `splice(int index, int count, item1, item2, ...)` -> `array`
|
|
265
|
+
|
|
266
|
+
Native splice implementation.
|
|
267
|
+
|
|
268
|
+
Remove number of items from the specified index from the list and/or add new elements.
|
|
269
|
+
|
|
270
|
+
Returns array of removed items or empty array if count == 0.
|
|
271
|
+
|
|
272
|
+
Returns undefined if the list is empty.
|
|
273
|
+
|
|
274
|
+
```js
|
|
275
|
+
var denque = new Denque([1,2,3,4,5,6,7]);
|
|
276
|
+
denque.splice(denque.length, 0, 8, 9, 10); // []
|
|
277
|
+
denque.toArray() // [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 ]
|
|
278
|
+
denque.splice(3, 3, 44, 55, 66); // [4,5,6]
|
|
279
|
+
denque.splice(5,4, 666,667,668,669); // [ 66, 7, 8, 9 ]
|
|
280
|
+
denque.toArray() // [ 1, 2, 3, 44, 55, 666, 667, 668, 669, 10 ]
|
|
281
|
+
```
|
|
282
|
+
|
|
283
|
+
<hr>
|
|
284
|
+
|
|
285
|
+
#### `isEmpty()` -> `boolean`
|
|
286
|
+
|
|
287
|
+
Return `true` if this queue is empty, `false` otherwise.
|
|
288
|
+
|
|
289
|
+
```js
|
|
290
|
+
var denque = new Denque();
|
|
291
|
+
denque.isEmpty(); // true
|
|
292
|
+
denque.push(1);
|
|
293
|
+
denque.isEmpty(); // false
|
|
294
|
+
```
|
|
295
|
+
|
|
296
|
+
<hr>
|
|
297
|
+
|
|
298
|
+
#### `clear()` -> `void`
|
|
299
|
+
|
|
300
|
+
Remove all items from this queue. Does not change the queue's capacity.
|
|
301
|
+
|
|
302
|
+
```js
|
|
303
|
+
var denque = new Denque([1,2,3]);
|
|
304
|
+
denque.toString(); // "1,2,3"
|
|
305
|
+
denque.clear();
|
|
306
|
+
denque.toString(); // ""
|
|
307
|
+
```
|
|
308
|
+
<hr>
|
|
309
|
+
|
|
310
|
+
|
|
311
|
+
## Benchmarks
|
|
312
|
+
|
|
313
|
+
#### Platform info:
|
|
314
|
+
```
|
|
315
|
+
Darwin 17.0.0 x64
|
|
316
|
+
Node.JS 9.4.0
|
|
317
|
+
V8 6.2.414.46-node.17
|
|
318
|
+
Intel(R) Core(TM) i7-7700K CPU @ 4.20GHz × 8
|
|
319
|
+
```
|
|
320
|
+
|
|
321
|
+
#### 1000 items in queue
|
|
322
|
+
|
|
323
|
+
(3 x shift + 3 x push ops per 'op')
|
|
324
|
+
|
|
325
|
+
denque x 64,365,425 ops/sec ±0.69% (92 runs sampled)
|
|
326
|
+
double-ended-queue x 26,646,882 ops/sec ±0.47% (94 runs sampled)
|
|
327
|
+
|
|
328
|
+
#### 2 million items in queue
|
|
329
|
+
|
|
330
|
+
(3 x shift + 3 x push ops per 'op')
|
|
331
|
+
|
|
332
|
+
denque x 61,994,249 ops/sec ±0.26% (95 runs sampled)
|
|
333
|
+
double-ended-queue x 26,363,500 ops/sec ±0.42% (91 runs sampled)
|
|
334
|
+
|
|
335
|
+
#### Splice
|
|
336
|
+
|
|
337
|
+
(1 x splice per 'op') - initial size of 100,000 items
|
|
338
|
+
|
|
339
|
+
denque.splice x 925,749 ops/sec ±22.29% (77 runs sampled)
|
|
340
|
+
native array splice x 7,777 ops/sec ±8.35% (50 runs sampled)
|
|
341
|
+
|
|
342
|
+
#### Remove
|
|
343
|
+
|
|
344
|
+
(1 x remove + 10 x push per 'op') - initial size of 100,000 items
|
|
345
|
+
|
|
346
|
+
denque.remove x 2,635,275 ops/sec ±0.37% (95 runs sampled)
|
|
347
|
+
native array splice - Fails to complete: "JavaScript heap out of memory"
|
|
348
|
+
|
|
349
|
+
#### Remove One
|
|
350
|
+
|
|
351
|
+
(1 x removeOne + 10 x push per 'op') - initial size of 100,000 items
|
|
352
|
+
|
|
353
|
+
denque.removeOne x 1,088,240 ops/sec ±0.21% (93 runs sampled)
|
|
354
|
+
native array splice x 5,300 ops/sec ±0.41% (96 runs sampled)
|
|
355
|
+
|
|
356
|
+
---
|
|
357
|
+
|
|
358
|
+
Built and maintained with 💛 by [Invertase](https://invertase.io).
|
|
359
|
+
|
|
360
|
+
- [💼 Hire Us](https://invertase.io/hire-us)
|
|
361
|
+
- [☕️ Sponsor Us](https://opencollective.com/react-native-firebase)
|
|
362
|
+
- [👩💻 Work With Us](https://invertase.io/jobs)
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
declare class Denque<T = any> {
|
|
2
|
+
constructor();
|
|
3
|
+
constructor(array: T[]);
|
|
4
|
+
constructor(array: T[], options: IDenqueOptions);
|
|
5
|
+
|
|
6
|
+
push(item: T): number;
|
|
7
|
+
unshift(item: T): number;
|
|
8
|
+
pop(): T | undefined;
|
|
9
|
+
removeBack(): T | undefined;
|
|
10
|
+
shift(): T | undefined;
|
|
11
|
+
peekBack(): T | undefined;
|
|
12
|
+
peekFront(): T | undefined;
|
|
13
|
+
peekAt(index: number): T | undefined;
|
|
14
|
+
get(index: number): T | undefined;
|
|
15
|
+
remove(index: number, count: number): T[];
|
|
16
|
+
removeOne(index: number): T | undefined;
|
|
17
|
+
splice(index: number, count: number, ...item: T[]): T[] | undefined;
|
|
18
|
+
isEmpty(): boolean;
|
|
19
|
+
clear(): void;
|
|
20
|
+
|
|
21
|
+
toString(): string;
|
|
22
|
+
toArray(): T[];
|
|
23
|
+
|
|
24
|
+
length: number;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
interface IDenqueOptions {
|
|
28
|
+
capacity?: number
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export = Denque;
|