graph-typed 1.52.3 → 1.52.5

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 +299 -331
  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 +29 -115
  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 +5 -58
  36. package/dist/data-structures/queue/queue.js +4 -57
  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 +329 -358
  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 +31 -139
  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 +5 -72
  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
@@ -81,11 +81,6 @@ export class DirectedGraph<
81
81
  this._inEdgeMap = v;
82
82
  }
83
83
 
84
- /**
85
- * In TypeScript, a subclass inherits the interface implementation of its parent class, without needing to implement the same interface again in the subclass. This behavior differs from Java's approach. In Java, if a parent class implements an interface, the subclass needs to explicitly implement the same interface, even if the parent class has already implemented it.
86
- * This means that using abstract methods in the parent class cannot constrain the grandchild classes. Defining methods within an interface also cannot constrain the descendant classes. When inheriting from this class, developers need to be aware that this method needs to be overridden.
87
- */
88
-
89
84
  /**
90
85
  * The function creates a new vertex with an optional value and returns it.
91
86
  * @param {VertexKey} key - The `key` parameter is the unique identifier for the vertex. It is of type `VertexKey`, which
@@ -99,11 +94,6 @@ export class DirectedGraph<
99
94
  return new DirectedVertex(key, value) as VO;
100
95
  }
101
96
 
102
- /**
103
- * In TypeScript, a subclass inherits the interface implementation of its parent class, without needing to implement the same interface again in the subclass. This behavior differs from Java's approach. In Java, if a parent class implements an interface, the subclass needs to explicitly implement the same interface, even if the parent class has already implemented it.
104
- * This means that using abstract methods in the parent class cannot constrain the grandchild classes. Defining methods within an interface also cannot constrain the descendant classes. When inheriting from this class, developers need to be aware that this method needs to be overridden.
105
- */
106
-
107
97
  /**
108
98
  * The function creates a directed edge between two vertexMap with an optional weight and value.
109
99
  * @param {VertexKey} src - The source vertex ID of the edge. It represents the starting point of the edge.
@@ -118,11 +108,6 @@ export class DirectedGraph<
118
108
  return new DirectedEdge(src, dest, weight ?? 1, value) as EO;
119
109
  }
120
110
 
121
- /**
122
- * Time Complexity: O(|V|) where |V| is the number of vertexMap
123
- * Space Complexity: O(1)
124
- */
125
-
126
111
  /**
127
112
  * Time Complexity: O(|V|) where |V| is the number of vertexMap
128
113
  * Space Complexity: O(1)
@@ -152,11 +137,6 @@ export class DirectedGraph<
152
137
  return edgeMap[0] || undefined;
153
138
  }
154
139
 
155
- /**
156
- * Time Complexity: O(|E|) where |E| is the number of edgeMap
157
- * Space Complexity: O(1)
158
- */
159
-
160
140
  /**
161
141
  * Time Complexity: O(|E|) where |E| is the number of edgeMap
162
142
  * Space Complexity: O(1)
@@ -186,11 +166,6 @@ export class DirectedGraph<
186
166
  return removed;
187
167
  }
188
168
 
189
- /**
190
- * Time Complexity: O(E) where E is the number of edgeMap
191
- * Space Complexity: O(1)
192
- */
193
-
194
169
  /**
195
170
  * Time Complexity: O(E) where E is the number of edgeMap
196
171
  * Space Complexity: O(1)
@@ -234,11 +209,6 @@ export class DirectedGraph<
234
209
  return removed;
235
210
  }
236
211
 
237
- /**
238
- * Time Complexity: O(1) - Constant time for Map operations.
239
- * Space Complexity: O(1) - Constant space, as it creates only a few variables.
240
- */
241
-
242
212
  /**
243
213
  * Time Complexity: O(1) - Constant time for Map operations.
244
214
  * Space Complexity: O(1) - Constant space, as it creates only a few variables.
@@ -272,11 +242,6 @@ export class DirectedGraph<
272
242
  return this._vertexMap.delete(vertexKey);
273
243
  }
274
244
 
275
- /**
276
- * Time Complexity: O(|E|) where |E| is the number of edgeMap
277
- * Space Complexity: O(1)
278
- */
279
-
280
245
  /**
281
246
  * Time Complexity: O(|E|) where |E| is the number of edgeMap
282
247
  * Space Complexity: O(1)
@@ -302,11 +267,6 @@ export class DirectedGraph<
302
267
  return removed;
303
268
  }
304
269
 
305
- /**
306
- * Time Complexity: O(1)
307
- * Space Complexity: O(1)
308
- */
309
-
310
270
  /**
311
271
  * Time Complexity: O(1)
312
272
  * Space Complexity: O(1)
@@ -324,11 +284,6 @@ export class DirectedGraph<
324
284
  return [];
325
285
  }
326
286
 
327
- /**
328
- * Time Complexity: O(1)
329
- * Space Complexity: O(1)
330
- */
331
-
332
287
  /**
333
288
  * Time Complexity: O(1)
334
289
  * Space Complexity: O(1)
@@ -346,11 +301,6 @@ export class DirectedGraph<
346
301
  return [];
347
302
  }
348
303
 
349
- /**
350
- * Time Complexity: O(1)
351
- * Space Complexity: O(1)
352
- */
353
-
354
304
  /**
355
305
  * Time Complexity: O(1)
356
306
  * Space Complexity: O(1)
@@ -363,11 +313,6 @@ export class DirectedGraph<
363
313
  return this.outDegreeOf(vertexOrKey) + this.inDegreeOf(vertexOrKey);
364
314
  }
365
315
 
366
- /**
367
- * Time Complexity: O(1)
368
- * Space Complexity: O(1)
369
- */
370
-
371
316
  /**
372
317
  * Time Complexity: O(1)
373
318
  * Space Complexity: O(1)
@@ -380,11 +325,6 @@ export class DirectedGraph<
380
325
  return this.incomingEdgesOf(vertexOrKey).length;
381
326
  }
382
327
 
383
- /**
384
- * Time Complexity: O(1)
385
- * Space Complexity: O(1)
386
- */
387
-
388
328
  /**
389
329
  * Time Complexity: O(1)
390
330
  * Space Complexity: O(1)
@@ -397,11 +337,6 @@ export class DirectedGraph<
397
337
  return this.outgoingEdgesOf(vertexOrKey).length;
398
338
  }
399
339
 
400
- /**
401
- * Time Complexity: O(1)
402
- * Space Complexity: O(1)
403
- */
404
-
405
340
  /**
406
341
  * Time Complexity: O(1)
407
342
  * Space Complexity: O(1)
@@ -414,11 +349,6 @@ export class DirectedGraph<
414
349
  return [...this.outgoingEdgesOf(vertexOrKey), ...this.incomingEdgesOf(vertexOrKey)];
415
350
  }
416
351
 
417
- /**
418
- * Time Complexity: O(1)
419
- * Space Complexity: O(1)
420
- */
421
-
422
352
  /**
423
353
  * Time Complexity: O(1)
424
354
  * Space Complexity: O(1)
@@ -431,11 +361,6 @@ export class DirectedGraph<
431
361
  return this._getVertex(e.src);
432
362
  }
433
363
 
434
- /**
435
- * Time Complexity: O(1)
436
- * Space Complexity: O(1)
437
- */
438
-
439
364
  /**
440
365
  * Time Complexity: O(1)
441
366
  * Space Complexity: O(1)
@@ -448,11 +373,6 @@ export class DirectedGraph<
448
373
  return this._getVertex(e.dest);
449
374
  }
450
375
 
451
- /**
452
- * Time Complexity: O(|E|) where |E| is the number of edgeMap
453
- * Space Complexity: O(1)
454
- */
455
-
456
376
  /**
457
377
  * Time Complexity: O(|E|) where |E| is the number of edgeMap
458
378
  * Space Complexity: O(1)
@@ -477,11 +397,6 @@ export class DirectedGraph<
477
397
  return destinations;
478
398
  }
479
399
 
480
- /**
481
- * Time Complexity: O(|V| + |E|) where |V| is the number of vertexMap and |E| is the number of edgeMap
482
- * Space Complexity: O(|V|)
483
- */
484
-
485
400
  /**
486
401
  * Time Complexity: O(|V| + |E|) where |V| is the number of vertexMap and |E| is the number of edgeMap
487
402
  * Space Complexity: O(|V|)
@@ -531,11 +446,6 @@ export class DirectedGraph<
531
446
  return sorted.reverse();
532
447
  }
533
448
 
534
- /**
535
- * Time Complexity: O(|E|) where |E| is the number of edgeMap
536
- * Space Complexity: O(|E|)
537
- */
538
-
539
449
  /**
540
450
  * Time Complexity: O(|E|) where |E| is the number of edgeMap
541
451
  * Space Complexity: O(|E|)
@@ -551,11 +461,6 @@ export class DirectedGraph<
551
461
  return edgeMap;
552
462
  }
553
463
 
554
- /**
555
- * Time Complexity: O(|E|) where |E| is the number of edgeMap
556
- * Space Complexity: O(1)
557
- */
558
-
559
464
  /**
560
465
  * Time Complexity: O(|E|) where |E| is the number of edgeMap
561
466
  * Space Complexity: O(1)
@@ -581,11 +486,6 @@ export class DirectedGraph<
581
486
  return neighbors;
582
487
  }
583
488
 
584
- /**
585
- * Time Complexity: O(1)
586
- * Space Complexity: O(1)
587
- */
588
-
589
489
  /**
590
490
  * Time Complexity: O(1)
591
491
  * Space Complexity: O(1)
@@ -618,11 +518,6 @@ export class DirectedGraph<
618
518
  return this.vertexMap.size === 0 && this.inEdgeMap.size === 0 && this.outEdgeMap.size === 0;
619
519
  }
620
520
 
621
- /**
622
- * Time Complexity: O(1)
623
- * Space Complexity: O(1)
624
- */
625
-
626
521
  /**
627
522
  * Time Complexity: O(1)
628
523
  * Space Complexity: O(1)
@@ -648,13 +543,6 @@ export class DirectedGraph<
648
543
  return cloned;
649
544
  }
650
545
 
651
- /**
652
- * Time Complexity: O(V + E)
653
- * Space Complexity: O(V)
654
- * Tarjan is an algorithm based on dfs,which is used to solve the connectivity problem of graphs.
655
- * Tarjan can find the SSC(strongly connected components), articulation points, and bridges of directed graphs.
656
- */
657
-
658
546
  /**
659
547
  * Time Complexity: O(V + E)
660
548
  * Space Complexity: O(V)
@@ -717,11 +605,6 @@ export class DirectedGraph<
717
605
  return { dfnMap, lowMap, SCCs };
718
606
  }
719
607
 
720
- /**
721
- * Time Complexity: O(V + E) - Depends on the implementation (Tarjan's algorithm).
722
- * Space Complexity: O(V) - Depends on the implementation (Tarjan's algorithm).
723
- */
724
-
725
608
  /**
726
609
  * Time Complexity: O(V + E) - Depends on the implementation (Tarjan's algorithm).
727
610
  * Space Complexity: O(V) - Depends on the implementation (Tarjan's algorithm).
@@ -753,11 +636,6 @@ export class DirectedGraph<
753
636
  return this.tarjan().SCCs;
754
637
  }
755
638
 
756
- /**
757
- * Time Complexity: O(1)
758
- * Space Complexity: O(1)
759
- */
760
-
761
639
  /**
762
640
  * Time Complexity: O(1)
763
641
  * Space Complexity: O(1)
@@ -96,11 +96,6 @@ export class UndirectedGraph<
96
96
  return new UndirectedEdge(v1, v2, weight ?? 1, value) as EO;
97
97
  }
98
98
 
99
- /**
100
- * Time Complexity: O(|E|), where |E| is the number of edgeMap incident to the given vertex.
101
- * Space Complexity: O(1)
102
- */
103
-
104
99
  /**
105
100
  * Time Complexity: O(|E|), where |E| is the number of edgeMap incident to the given vertex.
106
101
  * Space Complexity: O(1)
@@ -127,11 +122,6 @@ export class UndirectedGraph<
127
122
  return edgeMap ? edgeMap[0] || undefined : undefined;
128
123
  }
129
124
 
130
- /**
131
- * Time Complexity: O(|E|), where |E| is the number of edgeMap incident to the given vertex.
132
- * Space Complexity: O(1)
133
- */
134
-
135
125
  /**
136
126
  * Time Complexity: O(|E|), where |E| is the number of edgeMap incident to the given vertex.
137
127
  * Space Complexity: O(1)
@@ -162,11 +152,6 @@ export class UndirectedGraph<
162
152
  return removed;
163
153
  }
164
154
 
165
- /**
166
- * Time Complexity: O(E), where E is the number of edgeMap incident to the given vertex.
167
- * Space Complexity: O(1)
168
- */
169
-
170
155
  /**
171
156
  * Time Complexity: O(E), where E is the number of edgeMap incident to the given vertex.
172
157
  * Space Complexity: O(1)
@@ -201,11 +186,6 @@ export class UndirectedGraph<
201
186
  }
202
187
  }
203
188
 
204
- /**
205
- * Time Complexity: O(1) - Constant time for Map operations.
206
- * Space Complexity: O(1) - Constant space, as it creates only a few variables.
207
- */
208
-
209
189
  /**
210
190
  * Time Complexity: O(1) - Constant time for Map operations.
211
191
  * Space Complexity: O(1) - Constant space, as it creates only a few variables.
@@ -244,11 +224,6 @@ export class UndirectedGraph<
244
224
  return this._vertexMap.delete(vertexKey);
245
225
  }
246
226
 
247
- /**
248
- * Time Complexity: O(1)
249
- * Space Complexity: O(1)
250
- */
251
-
252
227
  /**
253
228
  * Time Complexity: O(1)
254
229
  * Space Complexity: O(1)
@@ -268,11 +243,6 @@ export class UndirectedGraph<
268
243
  }
269
244
  }
270
245
 
271
- /**
272
- * Time Complexity: O(1)
273
- * Space Complexity: O(1)
274
- */
275
-
276
246
  /**
277
247
  * Time Complexity: O(1)
278
248
  * Space Complexity: O(1)
@@ -291,11 +261,6 @@ export class UndirectedGraph<
291
261
  }
292
262
  }
293
263
 
294
- /**
295
- * Time Complexity: O(|V| + |E|), where |V| is the number of vertexMap and |E| is the number of edgeMap.
296
- * Space Complexity: O(|E|)
297
- */
298
-
299
264
  /**
300
265
  * Time Complexity: O(|V| + |E|), where |V| is the number of vertexMap and |E| is the number of edgeMap.
301
266
  * Space Complexity: O(|E|)
@@ -313,11 +278,6 @@ export class UndirectedGraph<
313
278
  return [...edgeSet];
314
279
  }
315
280
 
316
- /**
317
- * Time Complexity: O(|V| + |E|), where |V| is the number of vertexMap and |E| is the number of edgeMap.
318
- * Space Complexity: O(|E|)
319
- */
320
-
321
281
  /**
322
282
  * Time Complexity: O(|V| + |E|), where |V| is the number of vertexMap and |E| is the number of edgeMap.
323
283
  * Space Complexity: O(|E|)
@@ -342,11 +302,6 @@ export class UndirectedGraph<
342
302
  return neighbors;
343
303
  }
344
304
 
345
- /**
346
- * Time Complexity: O(1)
347
- * Space Complexity: O(1)
348
- */
349
-
350
305
  /**
351
306
  * Time Complexity: O(1)
352
307
  * Space Complexity: O(1)
@@ -378,11 +333,6 @@ export class UndirectedGraph<
378
333
  return this.vertexMap.size === 0 && this.edgeMap.size === 0;
379
334
  }
380
335
 
381
- /**
382
- * Time Complexity: O(1)
383
- * Space Complexity: O(1)
384
- */
385
-
386
336
  /**
387
337
  * Time Complexity: O(1)
388
338
  * Space Complexity: O(1)
@@ -410,11 +360,6 @@ export class UndirectedGraph<
410
360
  return cloned;
411
361
  }
412
362
 
413
- /**
414
- * Time Complexity: O(1)
415
- * Space Complexity: O(1)
416
- */
417
-
418
363
  /**
419
364
  * Time Complexity: O(V + E)
420
365
  * Space Complexity: O(V)
@@ -484,13 +429,6 @@ export class UndirectedGraph<
484
429
  };
485
430
  }
486
431
 
487
- /**
488
- * Time Complexity: O(V + E)
489
- * Space Complexity: O(V)
490
- * Tarjan is an algorithm based on dfs,which is used to solve the connectivity problem of graphs.
491
- * 1. Tarjan can find the articulation points and bridges(critical edgeMap) of undirected graphs in linear time
492
- */
493
-
494
432
  /**
495
433
  * The function "getBridges" returns an array of bridges in a graph using the Tarjan's algorithm.
496
434
  * @returns The function `getBridges()` is returning the bridges found using the Tarjan's algorithm.