heap-typed 1.52.4 → 1.52.6

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.
Files changed (74) hide show
  1. package/dist/data-structures/base/iterable-element-base.d.ts +1 -37
  2. package/dist/data-structures/base/iterable-element-base.js +1 -37
  3. package/dist/data-structures/base/iterable-entry-base.d.ts +2 -54
  4. package/dist/data-structures/base/iterable-entry-base.js +1 -49
  5. package/dist/data-structures/binary-tree/avl-tree-multi-map.d.ts +0 -32
  6. package/dist/data-structures/binary-tree/avl-tree-multi-map.js +9 -41
  7. package/dist/data-structures/binary-tree/avl-tree.d.ts +0 -46
  8. package/dist/data-structures/binary-tree/avl-tree.js +0 -46
  9. package/dist/data-structures/binary-tree/binary-tree.d.ts +82 -147
  10. package/dist/data-structures/binary-tree/binary-tree.js +300 -332
  11. package/dist/data-structures/binary-tree/bst.d.ts +1 -40
  12. package/dist/data-structures/binary-tree/bst.js +12 -44
  13. package/dist/data-structures/binary-tree/rb-tree.d.ts +0 -48
  14. package/dist/data-structures/binary-tree/rb-tree.js +2 -50
  15. package/dist/data-structures/binary-tree/tree-multi-map.d.ts +0 -32
  16. package/dist/data-structures/binary-tree/tree-multi-map.js +9 -41
  17. package/dist/data-structures/graph/abstract-graph.d.ts +0 -75
  18. package/dist/data-structures/graph/abstract-graph.js +0 -75
  19. package/dist/data-structures/graph/directed-graph.d.ts +0 -98
  20. package/dist/data-structures/graph/directed-graph.js +0 -98
  21. package/dist/data-structures/graph/undirected-graph.d.ts +0 -50
  22. package/dist/data-structures/graph/undirected-graph.js +0 -50
  23. package/dist/data-structures/hash/hash-map.d.ts +5 -92
  24. package/dist/data-structures/hash/hash-map.js +27 -111
  25. package/dist/data-structures/heap/heap.d.ts +0 -32
  26. package/dist/data-structures/heap/heap.js +0 -32
  27. package/dist/data-structures/linked-list/doubly-linked-list.d.ts +5 -88
  28. package/dist/data-structures/linked-list/doubly-linked-list.js +5 -88
  29. package/dist/data-structures/linked-list/singly-linked-list.d.ts +1 -83
  30. package/dist/data-structures/linked-list/singly-linked-list.js +2 -84
  31. package/dist/data-structures/linked-list/skip-linked-list.d.ts +1 -35
  32. package/dist/data-structures/linked-list/skip-linked-list.js +1 -35
  33. package/dist/data-structures/queue/deque.d.ts +1 -98
  34. package/dist/data-structures/queue/deque.js +3 -99
  35. package/dist/data-structures/queue/queue.d.ts +1 -54
  36. package/dist/data-structures/queue/queue.js +0 -53
  37. package/dist/data-structures/stack/stack.d.ts +1 -34
  38. package/dist/data-structures/stack/stack.js +1 -34
  39. package/dist/data-structures/tree/tree.js +2 -1
  40. package/dist/data-structures/trie/trie.d.ts +0 -64
  41. package/dist/data-structures/trie/trie.js +0 -64
  42. package/dist/types/data-structures/binary-tree/binary-tree.d.ts +8 -0
  43. package/dist/types/data-structures/binary-tree/binary-tree.js +6 -0
  44. package/dist/types/utils/utils.d.ts +13 -12
  45. package/dist/utils/number.d.ts +13 -0
  46. package/dist/utils/number.js +13 -0
  47. package/dist/utils/utils.d.ts +125 -3
  48. package/dist/utils/utils.js +177 -21
  49. package/package.json +2 -2
  50. package/src/data-structures/base/iterable-element-base.ts +2 -42
  51. package/src/data-structures/base/iterable-entry-base.ts +3 -62
  52. package/src/data-structures/binary-tree/avl-tree-multi-map.ts +8 -48
  53. package/src/data-structures/binary-tree/avl-tree.ts +0 -57
  54. package/src/data-structures/binary-tree/binary-tree.ts +330 -359
  55. package/src/data-structures/binary-tree/bst.ts +11 -54
  56. package/src/data-structures/binary-tree/rb-tree.ts +2 -62
  57. package/src/data-structures/binary-tree/tree-multi-map.ts +8 -48
  58. package/src/data-structures/graph/abstract-graph.ts +0 -92
  59. package/src/data-structures/graph/directed-graph.ts +0 -122
  60. package/src/data-structures/graph/undirected-graph.ts +0 -62
  61. package/src/data-structures/hash/hash-map.ts +29 -133
  62. package/src/data-structures/heap/heap.ts +0 -40
  63. package/src/data-structures/linked-list/doubly-linked-list.ts +5 -112
  64. package/src/data-structures/linked-list/singly-linked-list.ts +2 -104
  65. package/src/data-structures/linked-list/skip-linked-list.ts +1 -44
  66. package/src/data-structures/queue/deque.ts +2 -125
  67. package/src/data-structures/queue/queue.ts +1 -68
  68. package/src/data-structures/stack/stack.ts +1 -43
  69. package/src/data-structures/tree/tree.ts +1 -1
  70. package/src/data-structures/trie/trie.ts +0 -80
  71. package/src/types/data-structures/binary-tree/binary-tree.ts +8 -1
  72. package/src/types/utils/utils.ts +17 -15
  73. package/src/utils/number.ts +13 -0
  74. package/src/utils/utils.ts +174 -18
@@ -9,11 +9,6 @@ export abstract class IterableEntryBase<K = any, V = any> {
9
9
  // }
10
10
  // }
11
11
 
12
- /**
13
- * Time Complexity: O(n)
14
- * Space Complexity: O(1)
15
- */
16
-
17
12
  abstract get size(): number;
18
13
 
19
14
  // protected _toEntryFn?: (rawElement: R) => BTNEntry<K, V>;
@@ -39,10 +34,6 @@ export abstract class IterableEntryBase<K = any, V = any> {
39
34
  yield* this._getIterator(...args);
40
35
  }
41
36
 
42
- /**
43
- * Time Complexity: O(n)
44
- * Space Complexity: O(n)
45
- */
46
37
  /**
47
38
  * Time Complexity: O(n)
48
39
  * Space Complexity: O(n)
@@ -56,10 +47,6 @@ export abstract class IterableEntryBase<K = any, V = any> {
56
47
  }
57
48
  }
58
49
 
59
- /**
60
- * Time Complexity: O(n)
61
- * Space Complexity: O(n)
62
- */
63
50
  /**
64
51
  * Time Complexity: O(n)
65
52
  * Space Complexity: O(n)
@@ -72,10 +59,6 @@ export abstract class IterableEntryBase<K = any, V = any> {
72
59
  }
73
60
  }
74
61
 
75
- /**
76
- * Time Complexity: O(n)
77
- * Space Complexity: O(n)
78
- */
79
62
  /**
80
63
  * Time Complexity: O(n)
81
64
  * Space Complexity: O(n)
@@ -88,10 +71,6 @@ export abstract class IterableEntryBase<K = any, V = any> {
88
71
  }
89
72
  }
90
73
 
91
- /**
92
- * Time Complexity: O(n)
93
- * Space Complexity: O(1)
94
- */
95
74
  /**
96
75
  * Time Complexity: O(n)
97
76
  * Space Complexity: O(1)
@@ -116,10 +95,6 @@ export abstract class IterableEntryBase<K = any, V = any> {
116
95
  return true;
117
96
  }
118
97
 
119
- /**
120
- * Time Complexity: O(n)
121
- * Space Complexity: O(1)
122
- */
123
98
  /**
124
99
  * Time Complexity: O(n)
125
100
  * Space Complexity: O(1)
@@ -145,15 +120,6 @@ export abstract class IterableEntryBase<K = any, V = any> {
145
120
  return false;
146
121
  }
147
122
 
148
- /**
149
- * Time Complexity: O(n)
150
- * Space Complexity: O(1)
151
- */
152
-
153
- /**
154
- * Time Complexity: O(n)
155
- * Space Complexity: O(1)
156
- */
157
123
  /**
158
124
  * Time Complexity: O(n)
159
125
  * Space Complexity: O(1)
@@ -175,11 +141,6 @@ export abstract class IterableEntryBase<K = any, V = any> {
175
141
  }
176
142
  }
177
143
 
178
- /**
179
- * Time Complexity: O(n)
180
- * Space Complexity: O(1)
181
- */
182
-
183
144
  /**
184
145
  * Time Complexity: O(n)
185
146
  * Space Complexity: O(1)
@@ -197,7 +158,7 @@ export abstract class IterableEntryBase<K = any, V = any> {
197
158
  * the provided callback function. If no element satisfies the callback function, `undefined` is
198
159
  * returned.
199
160
  */
200
- find(callbackfn: EntryCallback<K, V, [K, V]>, thisArg?: any): [K, V] | undefined {
161
+ find(callbackfn: EntryCallback<K, V, boolean>, thisArg?: any): [K, V] | undefined {
201
162
  let index = 0;
202
163
  for (const item of this) {
203
164
  const [key, value] = item;
@@ -206,11 +167,6 @@ export abstract class IterableEntryBase<K = any, V = any> {
206
167
  return;
207
168
  }
208
169
 
209
- /**
210
- * Time Complexity: O(n)
211
- * Space Complexity: O(1)
212
- */
213
-
214
170
  /**
215
171
  * Time Complexity: O(n)
216
172
  * Space Complexity: O(1)
@@ -229,11 +185,6 @@ export abstract class IterableEntryBase<K = any, V = any> {
229
185
  return false;
230
186
  }
231
187
 
232
- /**
233
- * Time Complexity: O(n)
234
- * Space Complexity: O(1)
235
- */
236
-
237
188
  /**
238
189
  * Time Complexity: O(n)
239
190
  * Space Complexity: O(1)
@@ -250,11 +201,6 @@ export abstract class IterableEntryBase<K = any, V = any> {
250
201
  return false;
251
202
  }
252
203
 
253
- /**
254
- * Time Complexity: O(n)
255
- * Space Complexity: O(1)
256
- */
257
-
258
204
  /**
259
205
  * Time Complexity: O(n)
260
206
  * Space Complexity: O(1)
@@ -299,19 +245,14 @@ export abstract class IterableEntryBase<K = any, V = any> {
299
245
  return accumulator;
300
246
  }
301
247
 
302
- /**
303
- * Time Complexity: O(n)
304
- * Space Complexity: O(n)
305
- */
306
-
307
248
  /**
308
249
  * Time Complexity: O(n)
309
250
  * Space Complexity: O(n)
310
251
  *
311
252
  * The print function logs the elements of an array to the console.
312
253
  */
313
- print(): void {
314
- console.log([...this]);
254
+ print(): [K, V][] | string {
255
+ return [...this];
315
256
  }
316
257
 
317
258
  abstract isEmpty(): boolean;
@@ -105,11 +105,6 @@ export class AVLTreeMultiMap<
105
105
  return this._count;
106
106
  }
107
107
 
108
- /**
109
- * Time Complexity: O(n)
110
- * Space Complexity: O(1)
111
- */
112
-
113
108
  /**
114
109
  * Time Complexity: O(n)
115
110
  * Space Complexity: O(1)
@@ -187,15 +182,15 @@ export class AVLTreeMultiMap<
187
182
  if (keyOrNodeOrEntryOrRawElement === undefined || keyOrNodeOrEntryOrRawElement === null) return;
188
183
  if (this.isNode(keyOrNodeOrEntryOrRawElement)) return keyOrNodeOrEntryOrRawElement;
189
184
 
190
- if (this.toEntryFn) {
191
- const [key, entryValue] = this.toEntryFn(keyOrNodeOrEntryOrRawElement as R);
192
- if (key) return this.createNode(key, entryValue ?? value, count);
193
- }
194
-
195
185
  if (this.isEntry(keyOrNodeOrEntryOrRawElement)) {
196
- const [key, value] = keyOrNodeOrEntryOrRawElement;
186
+ const [key, entryValue] = keyOrNodeOrEntryOrRawElement;
197
187
  if (key === undefined || key === null) return;
198
- else return this.createNode(key, value, count);
188
+ if (this.isKey(key)) return this.createNode(key, value ?? entryValue, count);
189
+ }
190
+
191
+ if (this.toEntryFn) {
192
+ const [key, entryValue] = this.toEntryFn(keyOrNodeOrEntryOrRawElement as R);
193
+ if (this.isKey(key)) return this.createNode(key, value ?? entryValue, count);
199
194
  }
200
195
 
201
196
  if (this.isKey(keyOrNodeOrEntryOrRawElement)) return this.createNode(keyOrNodeOrEntryOrRawElement, value, count);
@@ -203,11 +198,6 @@ export class AVLTreeMultiMap<
203
198
  return;
204
199
  }
205
200
 
206
- /**
207
- * Time Complexity: O(log n)
208
- * Space Complexity: O(1)
209
- */
210
-
211
201
  /**
212
202
  * Time Complexity: O(log n)
213
203
  * Space Complexity: O(1)
@@ -237,11 +227,6 @@ export class AVLTreeMultiMap<
237
227
  return true;
238
228
  }
239
229
 
240
- /**
241
- * Time Complexity: O(log n)
242
- * Space Complexity: O(1)
243
- */
244
-
245
230
  /**
246
231
  * Time Complexity: O(log n)
247
232
  * Space Complexity: O(1)
@@ -294,7 +279,7 @@ export class AVLTreeMultiMap<
294
279
  needBalanced = parent;
295
280
  }
296
281
  } else {
297
- const leftSubTreeRightMost = curr.left ? this.getRightMost(curr.left) : undefined;
282
+ const leftSubTreeRightMost = curr.left ? this.getRightMost(node => node, curr.left) : undefined;
298
283
  if (leftSubTreeRightMost) {
299
284
  const parentOfLeftSubTreeMax = leftSubTreeRightMost.parent;
300
285
  orgCurrent = this._swapProperties(curr, leftSubTreeRightMost);
@@ -322,11 +307,6 @@ export class AVLTreeMultiMap<
322
307
  return deletedResult;
323
308
  }
324
309
 
325
- /**
326
- * Time Complexity: O(1)
327
- * Space Complexity: O(1)
328
- */
329
-
330
310
  /**
331
311
  * Time Complexity: O(1)
332
312
  * Space Complexity: O(1)
@@ -339,11 +319,6 @@ export class AVLTreeMultiMap<
339
319
  this._count = 0;
340
320
  }
341
321
 
342
- /**
343
- * Time Complexity: O(n log n)
344
- * Space Complexity: O(log n)
345
- */
346
-
347
322
  /**
348
323
  * Time Complexity: O(n log n)
349
324
  * Space Complexity: O(log n)
@@ -394,11 +369,6 @@ export class AVLTreeMultiMap<
394
369
  }
395
370
  }
396
371
 
397
- /**
398
- * Time complexity: O(n)
399
- * Space complexity: O(n)
400
- */
401
-
402
372
  /**
403
373
  * Time complexity: O(n)
404
374
  * Space complexity: O(n)
@@ -412,11 +382,6 @@ export class AVLTreeMultiMap<
412
382
  return cloned;
413
383
  }
414
384
 
415
- /**
416
- * Time Complexity: O(1)
417
- * Space Complexity: O(1)
418
- */
419
-
420
385
  /**
421
386
  * Time Complexity: O(1)
422
387
  * Space Complexity: O(1)
@@ -458,11 +423,6 @@ export class AVLTreeMultiMap<
458
423
  return undefined;
459
424
  }
460
425
 
461
- /**
462
- * Time Complexity: O(1)
463
- * Space Complexity: O(1)
464
- */
465
-
466
426
  /**
467
427
  * Time Complexity: O(1)
468
428
  * Space Complexity: O(1)
@@ -135,12 +135,6 @@ export class AVLTree<
135
135
  return keyOrNodeOrEntryOrRawElement instanceof AVLTreeNode;
136
136
  }
137
137
 
138
- /**
139
- * Time Complexity: O(log n)
140
- * Space Complexity: O(1)
141
- * logarithmic time, where "n" is the number of nodes in the tree. The add method of the superclass (BST) has logarithmic time complexity. constant space, as it doesn't use additional data structures that scale with input size.
142
- */
143
-
144
138
  /**
145
139
  * Time Complexity: O(log n)
146
140
  * Space Complexity: O(1)
@@ -161,11 +155,6 @@ export class AVLTree<
161
155
  return inserted;
162
156
  }
163
157
 
164
- /**
165
- * Time Complexity: O(log n)
166
- * Space Complexity: O(1)
167
- */
168
-
169
158
  /**
170
159
  * Time Complexity: O(log n)
171
160
  * Space Complexity: O(1)
@@ -192,11 +181,6 @@ export class AVLTree<
192
181
  return deletedResults;
193
182
  }
194
183
 
195
- /**
196
- * Time Complexity: O(1)
197
- * Space Complexity: O(1)
198
- */
199
-
200
184
  /**
201
185
  * Time Complexity: O(1)
202
186
  * Space Complexity: O(1)
@@ -238,11 +222,6 @@ export class AVLTree<
238
222
  return undefined;
239
223
  }
240
224
 
241
- /**
242
- * Time Complexity: O(1)
243
- * Space Complexity: O(1)
244
- */
245
-
246
225
  /**
247
226
  * Time Complexity: O(1)
248
227
  * Space Complexity: O(1)
@@ -263,11 +242,6 @@ export class AVLTree<
263
242
  else return node.right.height - node.left.height;
264
243
  }
265
244
 
266
- /**
267
- * Time Complexity: O(1)
268
- * Space Complexity: O(1)
269
- */
270
-
271
245
  /**
272
246
  * Time Complexity: O(1)
273
247
  * Space Complexity: O(1)
@@ -285,11 +259,6 @@ export class AVLTree<
285
259
  else node.height = 1 + Math.max(node.right.height, node.left.height);
286
260
  }
287
261
 
288
- /**
289
- * Time Complexity: O(1)
290
- * Space Complexity: O(1)
291
- */
292
-
293
262
  /**
294
263
  * Time Complexity: O(1)
295
264
  * Space Complexity: O(1)
@@ -323,11 +292,6 @@ export class AVLTree<
323
292
  if (B) this._updateHeight(B);
324
293
  }
325
294
 
326
- /**
327
- * Time Complexity: O(1)
328
- * Space Complexity: O(1)
329
- */
330
-
331
295
  /**
332
296
  * Time Complexity: O(1)
333
297
  * Space Complexity: O(1)
@@ -379,11 +343,6 @@ export class AVLTree<
379
343
  C && this._updateHeight(C);
380
344
  }
381
345
 
382
- /**
383
- * Time Complexity: O(1)
384
- * Space Complexity: O(1)
385
- */
386
-
387
346
  /**
388
347
  * Time Complexity: O(1)
389
348
  * Space Complexity: O(1)
@@ -422,11 +381,6 @@ export class AVLTree<
422
381
  B && this._updateHeight(B);
423
382
  }
424
383
 
425
- /**
426
- * Time Complexity: O(1)
427
- * Space Complexity: O(1)
428
- */
429
-
430
384
  /**
431
385
  * Time Complexity: O(1)
432
386
  * Space Complexity: O(1)
@@ -477,12 +431,6 @@ export class AVLTree<
477
431
  C && this._updateHeight(C);
478
432
  }
479
433
 
480
- /**
481
- * Time Complexity: O(log n)
482
- * Space Complexity: O(1)
483
- * logarithmic time, where "n" is the number of nodes in the tree. The method traverses the path from the inserted node to the root. constant space, as it doesn't use additional data structures that scale with input size.
484
- */
485
-
486
434
  /**
487
435
  * Time Complexity: O(log n)
488
436
  * Space Complexity: O(1)
@@ -532,11 +480,6 @@ export class AVLTree<
532
480
  }
533
481
  }
534
482
 
535
- /**
536
- * Time Complexity: O(1)
537
- * Space Complexity: O(1)
538
- */
539
-
540
483
  /**
541
484
  * Time Complexity: O(1)
542
485
  * Space Complexity: O(1)