data-structure-typed 1.42.9 → 1.43.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.
@@ -3,26 +3,26 @@
3
3
  "benchmarks": [
4
4
  {
5
5
  "test name": "10,000 add randomly",
6
- "time taken (ms)": "33.60",
7
- "executions per sec": "29.76",
6
+ "time taken (ms)": "35.38",
7
+ "executions per sec": "28.26",
8
8
  "sample deviation": "0.00"
9
9
  },
10
10
  {
11
11
  "test name": "10,000 add & delete randomly",
12
- "time taken (ms)": "72.39",
13
- "executions per sec": "13.81",
12
+ "time taken (ms)": "80.65",
13
+ "executions per sec": "12.40",
14
14
  "sample deviation": "0.01"
15
15
  },
16
16
  {
17
17
  "test name": "10,000 addMany",
18
- "time taken (ms)": "41.06",
19
- "executions per sec": "24.35",
20
- "sample deviation": "0.00"
18
+ "time taken (ms)": "46.45",
19
+ "executions per sec": "21.53",
20
+ "sample deviation": "9.97e-4"
21
21
  },
22
22
  {
23
23
  "test name": "10,000 get",
24
- "time taken (ms)": "28.01",
25
- "executions per sec": "35.71",
24
+ "time taken (ms)": "31.59",
25
+ "executions per sec": "31.66",
26
26
  "sample deviation": "0.00"
27
27
  }
28
28
  ],
@@ -32,44 +32,44 @@
32
32
  "benchmarks": [
33
33
  {
34
34
  "test name": "1,000 add randomly",
35
- "time taken (ms)": "12.64",
36
- "executions per sec": "79.09",
37
- "sample deviation": "6.90e-4"
35
+ "time taken (ms)": "13.01",
36
+ "executions per sec": "76.84",
37
+ "sample deviation": "7.71e-4"
38
38
  },
39
39
  {
40
40
  "test name": "1,000 add & delete randomly",
41
- "time taken (ms)": "16.03",
42
- "executions per sec": "62.38",
43
- "sample deviation": "5.30e-4"
41
+ "time taken (ms)": "16.82",
42
+ "executions per sec": "59.46",
43
+ "sample deviation": "0.00"
44
44
  },
45
45
  {
46
46
  "test name": "1,000 addMany",
47
- "time taken (ms)": "10.44",
48
- "executions per sec": "95.78",
49
- "sample deviation": "0.00"
47
+ "time taken (ms)": "10.46",
48
+ "executions per sec": "95.62",
49
+ "sample deviation": "2.13e-4"
50
50
  },
51
51
  {
52
52
  "test name": "1,000 get",
53
- "time taken (ms)": "18.19",
54
- "executions per sec": "54.98",
55
- "sample deviation": "3.11e-4"
53
+ "time taken (ms)": "18.44",
54
+ "executions per sec": "54.22",
55
+ "sample deviation": "2.49e-4"
56
56
  },
57
57
  {
58
58
  "test name": "1,000 dfs",
59
- "time taken (ms)": "154.71",
60
- "executions per sec": "6.46",
61
- "sample deviation": "0.00"
59
+ "time taken (ms)": "163.31",
60
+ "executions per sec": "6.12",
61
+ "sample deviation": "0.01"
62
62
  },
63
63
  {
64
64
  "test name": "1,000 bfs",
65
- "time taken (ms)": "56.97",
66
- "executions per sec": "17.55",
67
- "sample deviation": "8.92e-4"
65
+ "time taken (ms)": "58.07",
66
+ "executions per sec": "17.22",
67
+ "sample deviation": "0.00"
68
68
  },
69
69
  {
70
70
  "test name": "1,000 morris",
71
- "time taken (ms)": "260.71",
72
- "executions per sec": "3.84",
71
+ "time taken (ms)": "273.11",
72
+ "executions per sec": "3.66",
73
73
  "sample deviation": "0.00"
74
74
  }
75
75
  ],
@@ -79,27 +79,27 @@
79
79
  "benchmarks": [
80
80
  {
81
81
  "test name": "10,000 add randomly",
82
- "time taken (ms)": "29.57",
83
- "executions per sec": "33.81",
84
- "sample deviation": "2.75e-4"
82
+ "time taken (ms)": "33.44",
83
+ "executions per sec": "29.91",
84
+ "sample deviation": "5.09e-4"
85
85
  },
86
86
  {
87
87
  "test name": "10,000 add & delete randomly",
88
- "time taken (ms)": "70.78",
89
- "executions per sec": "14.13",
88
+ "time taken (ms)": "76.03",
89
+ "executions per sec": "13.15",
90
90
  "sample deviation": "0.00"
91
91
  },
92
92
  {
93
93
  "test name": "10,000 addMany",
94
- "time taken (ms)": "29.10",
95
- "executions per sec": "34.36",
96
- "sample deviation": "6.84e-4"
94
+ "time taken (ms)": "32.26",
95
+ "executions per sec": "31.00",
96
+ "sample deviation": "0.00"
97
97
  },
98
98
  {
99
99
  "test name": "10,000 get",
100
- "time taken (ms)": "28.75",
101
- "executions per sec": "34.78",
102
- "sample deviation": "6.05e-4"
100
+ "time taken (ms)": "32.75",
101
+ "executions per sec": "30.53",
102
+ "sample deviation": "0.01"
103
103
  }
104
104
  ],
105
105
  "testName": "bst"
@@ -107,22 +107,22 @@
107
107
  "rb-tree": {
108
108
  "benchmarks": [
109
109
  {
110
- "test name": "100,000 add randomly",
111
- "time taken (ms)": "88.55",
112
- "executions per sec": "11.29",
110
+ "test name": "100,000 add",
111
+ "time taken (ms)": "99.27",
112
+ "executions per sec": "10.07",
113
113
  "sample deviation": "0.01"
114
114
  },
115
115
  {
116
116
  "test name": "100,000 add & delete randomly",
117
- "time taken (ms)": "220.41",
118
- "executions per sec": "4.54",
117
+ "time taken (ms)": "233.22",
118
+ "executions per sec": "4.29",
119
119
  "sample deviation": "0.01"
120
120
  },
121
121
  {
122
122
  "test name": "100,000 getNode",
123
- "time taken (ms)": "37.52",
124
- "executions per sec": "26.65",
125
- "sample deviation": "2.68e-4"
123
+ "time taken (ms)": "148.41",
124
+ "executions per sec": "6.74",
125
+ "sample deviation": "0.00"
126
126
  }
127
127
  ],
128
128
  "testName": "rb-tree"
@@ -131,62 +131,79 @@
131
131
  "benchmarks": [
132
132
  {
133
133
  "test name": "1,000 addVertex",
134
- "time taken (ms)": "0.10",
135
- "executions per sec": "9804.12",
136
- "sample deviation": "1.07e-6"
134
+ "time taken (ms)": "0.11",
135
+ "executions per sec": "9381.52",
136
+ "sample deviation": "3.21e-6"
137
137
  },
138
138
  {
139
139
  "test name": "1,000 addEdge",
140
- "time taken (ms)": "6.06",
141
- "executions per sec": "165.11",
142
- "sample deviation": "1.66e-4"
140
+ "time taken (ms)": "6.36",
141
+ "executions per sec": "157.14",
142
+ "sample deviation": "7.19e-4"
143
143
  },
144
144
  {
145
145
  "test name": "1,000 getVertex",
146
146
  "time taken (ms)": "0.05",
147
- "executions per sec": "2.17e+4",
148
- "sample deviation": "3.48e-7"
147
+ "executions per sec": "2.09e+4",
148
+ "sample deviation": "2.72e-6"
149
149
  },
150
150
  {
151
151
  "test name": "1,000 getEdge",
152
- "time taken (ms)": "23.26",
153
- "executions per sec": "43.00",
152
+ "time taken (ms)": "24.66",
153
+ "executions per sec": "40.55",
154
154
  "sample deviation": "0.00"
155
155
  },
156
156
  {
157
157
  "test name": "tarjan",
158
- "time taken (ms)": "223.27",
159
- "executions per sec": "4.48",
158
+ "time taken (ms)": "219.65",
159
+ "executions per sec": "4.55",
160
160
  "sample deviation": "0.01"
161
161
  },
162
162
  {
163
163
  "test name": "tarjan all",
164
- "time taken (ms)": "224.27",
165
- "executions per sec": "4.46",
166
- "sample deviation": "0.00"
164
+ "time taken (ms)": "239.68",
165
+ "executions per sec": "4.17",
166
+ "sample deviation": "0.04"
167
167
  },
168
168
  {
169
169
  "test name": "topologicalSort",
170
- "time taken (ms)": "179.19",
171
- "executions per sec": "5.58",
172
- "sample deviation": "0.00"
170
+ "time taken (ms)": "216.14",
171
+ "executions per sec": "4.63",
172
+ "sample deviation": "0.07"
173
173
  }
174
174
  ],
175
175
  "testName": "directed-graph"
176
176
  },
177
+ "hash-map": {
178
+ "benchmarks": [
179
+ {
180
+ "test name": "10,000 set",
181
+ "time taken (ms)": "19.50",
182
+ "executions per sec": "51.27",
183
+ "sample deviation": "0.01"
184
+ },
185
+ {
186
+ "test name": "10,000 set & get",
187
+ "time taken (ms)": "38.20",
188
+ "executions per sec": "26.18",
189
+ "sample deviation": "0.01"
190
+ }
191
+ ],
192
+ "testName": "hash-map"
193
+ },
177
194
  "heap": {
178
195
  "benchmarks": [
179
196
  {
180
197
  "test name": "10,000 add & pop",
181
- "time taken (ms)": "4.62",
182
- "executions per sec": "216.39",
183
- "sample deviation": "3.75e-5"
198
+ "time taken (ms)": "4.86",
199
+ "executions per sec": "205.69",
200
+ "sample deviation": "7.04e-4"
184
201
  },
185
202
  {
186
203
  "test name": "10,000 fib add & pop",
187
- "time taken (ms)": "354.57",
188
- "executions per sec": "2.82",
189
- "sample deviation": "0.00"
204
+ "time taken (ms)": "386.50",
205
+ "executions per sec": "2.59",
206
+ "sample deviation": "0.03"
190
207
  }
191
208
  ],
192
209
  "testName": "heap"
@@ -195,21 +212,21 @@
195
212
  "benchmarks": [
196
213
  {
197
214
  "test name": "1,000,000 unshift",
198
- "time taken (ms)": "225.57",
199
- "executions per sec": "4.43",
200
- "sample deviation": "0.02"
215
+ "time taken (ms)": "243.46",
216
+ "executions per sec": "4.11",
217
+ "sample deviation": "0.05"
201
218
  },
202
219
  {
203
220
  "test name": "1,000,000 unshift & shift",
204
- "time taken (ms)": "164.91",
205
- "executions per sec": "6.06",
221
+ "time taken (ms)": "178.49",
222
+ "executions per sec": "5.60",
206
223
  "sample deviation": "0.02"
207
224
  },
208
225
  {
209
226
  "test name": "1,000,000 insertBefore",
210
- "time taken (ms)": "342.06",
211
- "executions per sec": "2.92",
212
- "sample deviation": "0.09"
227
+ "time taken (ms)": "326.38",
228
+ "executions per sec": "3.06",
229
+ "sample deviation": "0.07"
213
230
  }
214
231
  ],
215
232
  "testName": "doubly-linked-list"
@@ -218,15 +235,15 @@
218
235
  "benchmarks": [
219
236
  {
220
237
  "test name": "10,000 push & pop",
221
- "time taken (ms)": "224.20",
222
- "executions per sec": "4.46",
223
- "sample deviation": "0.02"
238
+ "time taken (ms)": "232.85",
239
+ "executions per sec": "4.29",
240
+ "sample deviation": "0.01"
224
241
  },
225
242
  {
226
243
  "test name": "10,000 insertBefore",
227
- "time taken (ms)": "244.96",
228
- "executions per sec": "4.08",
229
- "sample deviation": "0.00"
244
+ "time taken (ms)": "255.90",
245
+ "executions per sec": "3.91",
246
+ "sample deviation": "0.01"
230
247
  }
231
248
  ],
232
249
  "testName": "singly-linked-list"
@@ -235,25 +252,36 @@
235
252
  "benchmarks": [
236
253
  {
237
254
  "test name": "10,000 refill & poll",
238
- "time taken (ms)": "11.45",
239
- "executions per sec": "87.32",
240
- "sample deviation": "1.74e-4"
255
+ "time taken (ms)": "11.88",
256
+ "executions per sec": "84.15",
257
+ "sample deviation": "0.00"
241
258
  }
242
259
  ],
243
260
  "testName": "max-priority-queue"
244
261
  },
262
+ "priority-queue": {
263
+ "benchmarks": [
264
+ {
265
+ "test name": "10,000 add & pop",
266
+ "time taken (ms)": "12.60",
267
+ "executions per sec": "79.35",
268
+ "sample deviation": "1.40e-4"
269
+ }
270
+ ],
271
+ "testName": "priority-queue"
272
+ },
245
273
  "deque": {
246
274
  "benchmarks": [
247
275
  {
248
276
  "test name": "1,000,000 push",
249
- "time taken (ms)": "222.74",
250
- "executions per sec": "4.49",
251
- "sample deviation": "0.08"
277
+ "time taken (ms)": "226.32",
278
+ "executions per sec": "4.42",
279
+ "sample deviation": "0.03"
252
280
  },
253
281
  {
254
282
  "test name": "1,000,000 shift",
255
- "time taken (ms)": "26.48",
256
- "executions per sec": "37.77",
283
+ "time taken (ms)": "26.09",
284
+ "executions per sec": "38.33",
257
285
  "sample deviation": "0.00"
258
286
  }
259
287
  ],
@@ -263,31 +291,48 @@
263
291
  "benchmarks": [
264
292
  {
265
293
  "test name": "1,000,000 push",
266
- "time taken (ms)": "45.50",
267
- "executions per sec": "21.98",
294
+ "time taken (ms)": "45.45",
295
+ "executions per sec": "22.00",
268
296
  "sample deviation": "0.01"
269
297
  },
270
298
  {
271
299
  "test name": "1,000,000 push & shift",
272
- "time taken (ms)": "80.10",
273
- "executions per sec": "12.48",
300
+ "time taken (ms)": "82.87",
301
+ "executions per sec": "12.07",
274
302
  "sample deviation": "0.00"
275
303
  }
276
304
  ],
277
305
  "testName": "queue"
278
306
  },
307
+ "stack": {
308
+ "benchmarks": [
309
+ {
310
+ "test name": "1,000,000 push",
311
+ "time taken (ms)": "43.95",
312
+ "executions per sec": "22.75",
313
+ "sample deviation": "0.01"
314
+ },
315
+ {
316
+ "test name": "1,000,000 push & pop",
317
+ "time taken (ms)": "50.91",
318
+ "executions per sec": "19.64",
319
+ "sample deviation": "0.00"
320
+ }
321
+ ],
322
+ "testName": "stack"
323
+ },
279
324
  "trie": {
280
325
  "benchmarks": [
281
326
  {
282
327
  "test name": "100,000 push",
283
- "time taken (ms)": "56.99",
284
- "executions per sec": "17.55",
285
- "sample deviation": "0.01"
328
+ "time taken (ms)": "50.20",
329
+ "executions per sec": "19.92",
330
+ "sample deviation": "0.00"
286
331
  },
287
332
  {
288
333
  "test name": "100,000 getWords",
289
- "time taken (ms)": "98.43",
290
- "executions per sec": "10.16",
334
+ "time taken (ms)": "110.08",
335
+ "executions per sec": "9.08",
291
336
  "sample deviation": "0.01"
292
337
  }
293
338
  ],
@@ -139,23 +139,18 @@ class BinaryTree {
139
139
  const queue = new queue_1.Queue([root]);
140
140
  while (queue.size > 0) {
141
141
  const cur = queue.shift();
142
- if (cur) {
143
- if (newNode && cur.key === newNode.key) {
144
- cur.value = newNode.value;
145
- return;
146
- }
147
- const inserted = this._addTo(newNode, cur);
148
- if (inserted !== undefined)
149
- return inserted;
150
- if (cur.left)
151
- queue.push(cur.left);
152
- if (cur.right)
153
- queue.push(cur.right);
154
- }
155
- else
142
+ if (newNode && cur.key === newNode.key) {
143
+ cur.value = newNode.value;
156
144
  return;
145
+ }
146
+ const inserted = this._addTo(newNode, cur);
147
+ if (inserted !== undefined)
148
+ return inserted;
149
+ if (cur.left)
150
+ queue.push(cur.left);
151
+ if (cur.right)
152
+ queue.push(cur.right);
157
153
  }
158
- return;
159
154
  };
160
155
  let inserted, needInsert;
161
156
  if (keyOrNode === null) {
@@ -259,7 +254,7 @@ class BinaryTree {
259
254
  const deletedResult = [];
260
255
  if (!this.root)
261
256
  return deletedResult;
262
- if (identifier instanceof BinaryTreeNode)
257
+ if ((!callback || callback === this._defaultOneParamCallback) && identifier instanceof BinaryTreeNode)
263
258
  callback = (node => node);
264
259
  const curr = this.getNode(identifier, callback);
265
260
  if (!curr)
@@ -284,16 +279,18 @@ class BinaryTree {
284
279
  }
285
280
  }
286
281
  else {
287
- const leftSubTreeRightMost = curr.left ? this.getRightMost(curr.left) : null;
288
- if (leftSubTreeRightMost) {
289
- const parentOfLeftSubTreeMax = leftSubTreeRightMost.parent;
290
- orgCurrent = this._swap(curr, leftSubTreeRightMost);
291
- if (parentOfLeftSubTreeMax) {
292
- if (parentOfLeftSubTreeMax.right === leftSubTreeRightMost)
293
- parentOfLeftSubTreeMax.right = leftSubTreeRightMost.left;
294
- else
295
- parentOfLeftSubTreeMax.left = leftSubTreeRightMost.left;
296
- needBalanced = parentOfLeftSubTreeMax;
282
+ if (curr.left) {
283
+ const leftSubTreeRightMost = this.getRightMost(curr.left);
284
+ if (leftSubTreeRightMost) {
285
+ const parentOfLeftSubTreeMax = leftSubTreeRightMost.parent;
286
+ orgCurrent = this._swap(curr, leftSubTreeRightMost);
287
+ if (parentOfLeftSubTreeMax) {
288
+ if (parentOfLeftSubTreeMax.right === leftSubTreeRightMost)
289
+ parentOfLeftSubTreeMax.right = leftSubTreeRightMost.left;
290
+ else
291
+ parentOfLeftSubTreeMax.left = leftSubTreeRightMost.left;
292
+ needBalanced = parentOfLeftSubTreeMax;
293
+ }
297
294
  }
298
295
  }
299
296
  }
@@ -365,9 +362,6 @@ class BinaryTree {
365
362
  return _getMaxHeight(beginRoot);
366
363
  }
367
364
  else {
368
- if (!beginRoot) {
369
- return -1;
370
- }
371
365
  const stack = [{ node: beginRoot, depth: 0 }];
372
366
  let maxHeight = 0;
373
367
  while (stack.length > 0) {
@@ -492,9 +486,7 @@ class BinaryTree {
492
486
  * @returns an array of nodes of type `N`.
493
487
  */
494
488
  getNodes(identifier, callback = this._defaultOneParamCallback, onlyOne = false, beginRoot = this.root, iterationType = this.iterationType) {
495
- if (!beginRoot)
496
- return [];
497
- if (identifier instanceof BinaryTreeNode)
489
+ if ((!callback || callback === this._defaultOneParamCallback) && identifier instanceof BinaryTreeNode)
498
490
  callback = (node => node);
499
491
  beginRoot = this.ensureNotKey(beginRoot);
500
492
  if (!beginRoot)
@@ -556,7 +548,7 @@ class BinaryTree {
556
548
  * @returns a boolean value.
557
549
  */
558
550
  has(identifier, callback = this._defaultOneParamCallback, beginRoot = this.root, iterationType = this.iterationType) {
559
- if (identifier instanceof BinaryTreeNode)
551
+ if ((!callback || callback === this._defaultOneParamCallback) && identifier instanceof BinaryTreeNode)
560
552
  callback = (node => node);
561
553
  return this.getNodes(identifier, callback, true, beginRoot, iterationType).length > 0;
562
554
  }
@@ -587,7 +579,7 @@ class BinaryTree {
587
579
  */
588
580
  getNode(identifier, callback = this._defaultOneParamCallback, beginRoot = this.root, iterationType = this.iterationType) {
589
581
  var _a;
590
- if (identifier instanceof BinaryTreeNode)
582
+ if ((!callback || callback === this._defaultOneParamCallback) && identifier instanceof BinaryTreeNode)
591
583
  callback = (node => node);
592
584
  return (_a = this.getNodes(identifier, callback, true, beginRoot, iterationType)[0]) !== null && _a !== void 0 ? _a : null;
593
585
  }
@@ -680,7 +672,7 @@ class BinaryTree {
680
672
  */
681
673
  get(identifier, callback = this._defaultOneParamCallback, beginRoot = this.root, iterationType = this.iterationType) {
682
674
  var _a, _b;
683
- if (identifier instanceof BinaryTreeNode)
675
+ if ((!callback || callback === this._defaultOneParamCallback) && identifier instanceof BinaryTreeNode)
684
676
  callback = (node => node);
685
677
  return (_b = (_a = this.getNode(identifier, callback, beginRoot, iterationType)) === null || _a === void 0 ? void 0 : _a.value) !== null && _b !== void 0 ? _b : undefined;
686
678
  }
@@ -882,9 +874,9 @@ class BinaryTree {
882
874
  return this.isSubtreeBST(this.root, iterationType);
883
875
  }
884
876
  /**
885
- * Time complexity: O(n)
886
- * Space complexity: O(log n)
887
- */
877
+ * Time complexity: O(n)
878
+ * Space complexity: O(log n)
879
+ */
888
880
  /**
889
881
  * Time complexity: O(n)
890
882
  * Space complexity: O(log n)