binary-tree-typed 2.4.5 → 2.5.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.
Files changed (94) hide show
  1. package/README.md +0 -84
  2. package/dist/cjs/index.cjs +1476 -404
  3. package/dist/cjs/index.cjs.map +1 -1
  4. package/dist/cjs-legacy/index.cjs +1473 -401
  5. package/dist/cjs-legacy/index.cjs.map +1 -1
  6. package/dist/esm/index.mjs +1476 -404
  7. package/dist/esm/index.mjs.map +1 -1
  8. package/dist/esm-legacy/index.mjs +1473 -401
  9. package/dist/esm-legacy/index.mjs.map +1 -1
  10. package/dist/types/data-structures/base/index.d.ts +1 -0
  11. package/dist/types/data-structures/base/iterable-element-base.d.ts +1 -1
  12. package/dist/types/data-structures/base/iterable-entry-base.d.ts +8 -8
  13. package/dist/types/data-structures/base/linear-base.d.ts +3 -3
  14. package/dist/types/data-structures/binary-tree/avl-tree.d.ts +380 -51
  15. package/dist/types/data-structures/binary-tree/binary-indexed-tree.d.ts +487 -147
  16. package/dist/types/data-structures/binary-tree/binary-tree.d.ts +956 -80
  17. package/dist/types/data-structures/binary-tree/bst.d.ts +816 -29
  18. package/dist/types/data-structures/binary-tree/red-black-tree.d.ts +610 -31
  19. package/dist/types/data-structures/binary-tree/segment-tree.d.ts +326 -135
  20. package/dist/types/data-structures/binary-tree/tree-map.d.ts +3781 -6
  21. package/dist/types/data-structures/binary-tree/tree-multi-map.d.ts +3607 -201
  22. package/dist/types/data-structures/binary-tree/tree-multi-set.d.ts +2874 -65
  23. package/dist/types/data-structures/binary-tree/tree-set.d.ts +3528 -6
  24. package/dist/types/data-structures/graph/abstract-graph.d.ts +4 -4
  25. package/dist/types/data-structures/graph/directed-graph.d.ts +429 -47
  26. package/dist/types/data-structures/graph/map-graph.d.ts +59 -1
  27. package/dist/types/data-structures/graph/undirected-graph.d.ts +393 -59
  28. package/dist/types/data-structures/hash/hash-map.d.ts +473 -89
  29. package/dist/types/data-structures/heap/heap.d.ts +581 -99
  30. package/dist/types/data-structures/heap/max-heap.d.ts +46 -0
  31. package/dist/types/data-structures/heap/min-heap.d.ts +59 -0
  32. package/dist/types/data-structures/linked-list/doubly-linked-list.d.ts +646 -47
  33. package/dist/types/data-structures/linked-list/singly-linked-list.d.ts +596 -68
  34. package/dist/types/data-structures/linked-list/skip-linked-list.d.ts +793 -12
  35. package/dist/types/data-structures/matrix/matrix.d.ts +499 -0
  36. package/dist/types/data-structures/priority-queue/max-priority-queue.d.ts +57 -0
  37. package/dist/types/data-structures/priority-queue/min-priority-queue.d.ts +60 -0
  38. package/dist/types/data-structures/priority-queue/priority-queue.d.ts +60 -0
  39. package/dist/types/data-structures/queue/deque.d.ts +593 -71
  40. package/dist/types/data-structures/queue/queue.d.ts +463 -42
  41. package/dist/types/data-structures/stack/stack.d.ts +384 -32
  42. package/dist/types/data-structures/trie/trie.d.ts +470 -48
  43. package/dist/types/interfaces/graph.d.ts +1 -1
  44. package/dist/types/types/common.d.ts +2 -2
  45. package/dist/types/types/data-structures/binary-tree/segment-tree.d.ts +1 -1
  46. package/dist/types/types/data-structures/heap/heap.d.ts +1 -0
  47. package/dist/types/types/data-structures/linked-list/skip-linked-list.d.ts +1 -4
  48. package/dist/types/types/data-structures/priority-queue/priority-queue.d.ts +1 -0
  49. package/dist/types/types/utils/validate-type.d.ts +4 -4
  50. package/dist/umd/binary-tree-typed.js +1469 -397
  51. package/dist/umd/binary-tree-typed.js.map +1 -1
  52. package/dist/umd/binary-tree-typed.min.js +5 -5
  53. package/dist/umd/binary-tree-typed.min.js.map +1 -1
  54. package/package.json +2 -2
  55. package/src/data-structures/base/index.ts +1 -0
  56. package/src/data-structures/base/iterable-element-base.ts +4 -5
  57. package/src/data-structures/base/iterable-entry-base.ts +8 -8
  58. package/src/data-structures/base/linear-base.ts +3 -3
  59. package/src/data-structures/binary-tree/avl-tree.ts +386 -51
  60. package/src/data-structures/binary-tree/binary-indexed-tree.ts +596 -247
  61. package/src/data-structures/binary-tree/binary-tree.ts +956 -81
  62. package/src/data-structures/binary-tree/bst.ts +840 -35
  63. package/src/data-structures/binary-tree/red-black-tree.ts +689 -97
  64. package/src/data-structures/binary-tree/segment-tree.ts +498 -249
  65. package/src/data-structures/binary-tree/tree-map.ts +3784 -7
  66. package/src/data-structures/binary-tree/tree-multi-map.ts +3614 -211
  67. package/src/data-structures/binary-tree/tree-multi-set.ts +2874 -65
  68. package/src/data-structures/binary-tree/tree-set.ts +3531 -10
  69. package/src/data-structures/graph/abstract-graph.ts +4 -4
  70. package/src/data-structures/graph/directed-graph.ts +429 -47
  71. package/src/data-structures/graph/map-graph.ts +59 -1
  72. package/src/data-structures/graph/undirected-graph.ts +393 -59
  73. package/src/data-structures/hash/hash-map.ts +476 -92
  74. package/src/data-structures/heap/heap.ts +581 -99
  75. package/src/data-structures/heap/max-heap.ts +46 -0
  76. package/src/data-structures/heap/min-heap.ts +59 -0
  77. package/src/data-structures/linked-list/doubly-linked-list.ts +646 -47
  78. package/src/data-structures/linked-list/singly-linked-list.ts +596 -68
  79. package/src/data-structures/linked-list/skip-linked-list.ts +1067 -90
  80. package/src/data-structures/matrix/matrix.ts +584 -12
  81. package/src/data-structures/priority-queue/max-priority-queue.ts +57 -0
  82. package/src/data-structures/priority-queue/min-priority-queue.ts +60 -0
  83. package/src/data-structures/priority-queue/priority-queue.ts +60 -0
  84. package/src/data-structures/queue/deque.ts +592 -70
  85. package/src/data-structures/queue/queue.ts +463 -42
  86. package/src/data-structures/stack/stack.ts +384 -32
  87. package/src/data-structures/trie/trie.ts +470 -48
  88. package/src/interfaces/graph.ts +1 -1
  89. package/src/types/common.ts +2 -2
  90. package/src/types/data-structures/binary-tree/segment-tree.ts +1 -1
  91. package/src/types/data-structures/heap/heap.ts +1 -0
  92. package/src/types/data-structures/linked-list/skip-linked-list.ts +2 -1
  93. package/src/types/data-structures/priority-queue/priority-queue.ts +1 -0
  94. package/src/types/utils/validate-type.ts +4 -4
@@ -66,65 +66,6 @@ export declare class UndirectedEdge<E = number> extends AbstractEdge<E> {
66
66
  * console.log(neighborsA[0].key); // 'B';
67
67
  * console.log(neighborsA[1].key); // 'C';
68
68
  * @example
69
- * // UndirectedGraph deleteEdge and vertex operations
70
- * const graph = new UndirectedGraph<string>();
71
- *
72
- * // Build a simple undirected graph
73
- * graph.addVertex('X');
74
- * graph.addVertex('Y');
75
- * graph.addVertex('Z');
76
- * graph.addEdge('X', 'Y', 1);
77
- * graph.addEdge('Y', 'Z', 2);
78
- * graph.addEdge('X', 'Z', 3);
79
- *
80
- * // Delete an edge
81
- * graph.deleteEdge('X', 'Y');
82
- * console.log(graph.hasEdge('X', 'Y')); // false;
83
- *
84
- * // Bidirectional deletion confirmed
85
- * console.log(graph.hasEdge('Y', 'X')); // false;
86
- *
87
- * // Other edges should remain
88
- * console.log(graph.hasEdge('Y', 'Z')); // true;
89
- * console.log(graph.hasEdge('Z', 'Y')); // true;
90
- *
91
- * // Delete a vertex
92
- * graph.deleteVertex('Y');
93
- * console.log(graph.hasVertex('Y')); // false;
94
- * console.log(graph.size); // 2;
95
- * @example
96
- * // UndirectedGraph connectivity and neighbors
97
- * const graph = new UndirectedGraph<string>();
98
- *
99
- * // Build a friendship network
100
- * const people = ['Alice', 'Bob', 'Charlie', 'Diana', 'Eve'];
101
- * for (const person of people) {
102
- * graph.addVertex(person);
103
- * }
104
- *
105
- * // Add friendships (undirected edges)
106
- * graph.addEdge('Alice', 'Bob', 1);
107
- * graph.addEdge('Alice', 'Charlie', 1);
108
- * graph.addEdge('Bob', 'Diana', 1);
109
- * graph.addEdge('Charlie', 'Eve', 1);
110
- * graph.addEdge('Diana', 'Eve', 1);
111
- *
112
- * // Get friends of each person
113
- * const aliceFriends = graph.getNeighbors('Alice');
114
- * console.log(aliceFriends[0].key); // 'Bob';
115
- * console.log(aliceFriends[1].key); // 'Charlie';
116
- * console.log(aliceFriends.length); // 2;
117
- *
118
- * const dianaFriends = graph.getNeighbors('Diana');
119
- * console.log(dianaFriends[0].key); // 'Bob';
120
- * console.log(dianaFriends[1].key); // 'Eve';
121
- * console.log(dianaFriends.length); // 2;
122
- *
123
- * // Verify bidirectional friendship
124
- * const bobFriends = graph.getNeighbors('Bob');
125
- * console.log(bobFriends[0].key); // 'Alice'; // Alice -> Bob -> Alice ✓
126
- * console.log(bobFriends[1].key); // 'Diana';
127
- * @example
128
69
  * // UndirectedGraph for social network connectivity analysis
129
70
  * interface Person {
130
71
  * id: number;
@@ -233,6 +174,42 @@ export declare class UndirectedGraph<V = any, E = any, VO extends UndirectedVert
233
174
  * @param v2 - The other vertex or key.
234
175
  * @returns Edge instance or `undefined`.
235
176
  * @remarks Time O(1) avg, Space O(1)
177
+
178
+
179
+
180
+
181
+
182
+
183
+
184
+
185
+
186
+
187
+
188
+
189
+
190
+
191
+
192
+
193
+
194
+
195
+
196
+
197
+
198
+
199
+
200
+
201
+
202
+
203
+
204
+
205
+
206
+ * @example
207
+ * // Get edge between vertices
208
+ * const g = new UndirectedGraph();
209
+ * g.addVertex('A');
210
+ * g.addVertex('B');
211
+ * g.addEdge('A', 'B', 7);
212
+ * console.log(g.getEdge('A', 'B')?.weight); // 7;
236
213
  */
237
214
  getEdge(v1: VO | VertexKey | undefined, v2: VO | VertexKey | undefined): EO | undefined;
238
215
  /**
@@ -249,6 +226,65 @@ export declare class UndirectedGraph<V = any, E = any, VO extends UndirectedVert
249
226
  * @param otherSideVertexKey - Required second endpoint when deleting by pair.
250
227
  * @returns Removed edge or `undefined`.
251
228
  * @remarks Time O(1) avg, Space O(1)
229
+
230
+
231
+
232
+
233
+
234
+
235
+
236
+
237
+
238
+
239
+
240
+
241
+
242
+
243
+
244
+
245
+
246
+
247
+
248
+
249
+
250
+
251
+
252
+
253
+
254
+
255
+
256
+
257
+
258
+
259
+
260
+
261
+ * @example
262
+ * // UndirectedGraph deleteEdge and vertex operations
263
+ * const graph = new UndirectedGraph<string>();
264
+ *
265
+ * // Build a simple undirected graph
266
+ * graph.addVertex('X');
267
+ * graph.addVertex('Y');
268
+ * graph.addVertex('Z');
269
+ * graph.addEdge('X', 'Y', 1);
270
+ * graph.addEdge('Y', 'Z', 2);
271
+ * graph.addEdge('X', 'Z', 3);
272
+ *
273
+ * // Delete an edge
274
+ * graph.deleteEdge('X', 'Y');
275
+ * console.log(graph.hasEdge('X', 'Y')); // false;
276
+ *
277
+ * // Bidirectional deletion confirmed
278
+ * console.log(graph.hasEdge('Y', 'X')); // false;
279
+ *
280
+ * // Other edges should remain
281
+ * console.log(graph.hasEdge('Y', 'Z')); // true;
282
+ * console.log(graph.hasEdge('Z', 'Y')); // true;
283
+ *
284
+ * // Delete a vertex
285
+ * graph.deleteVertex('Y');
286
+ * console.log(graph.hasVertex('Y')); // false;
287
+ * console.log(graph.size); // 2;
252
288
  */
253
289
  deleteEdge(edgeOrOneSideVertexKey: EO | VertexKey, otherSideVertexKey?: VertexKey): EO | undefined;
254
290
  /**
@@ -256,6 +292,43 @@ export declare class UndirectedGraph<V = any, E = any, VO extends UndirectedVert
256
292
  * @param vertexOrKey - Vertex or key.
257
293
  * @returns `true` if removed; otherwise `false`.
258
294
  * @remarks Time O(deg), Space O(1)
295
+
296
+
297
+
298
+
299
+
300
+
301
+
302
+
303
+
304
+
305
+
306
+
307
+
308
+
309
+
310
+
311
+
312
+
313
+
314
+
315
+
316
+
317
+
318
+
319
+
320
+
321
+
322
+
323
+
324
+ * @example
325
+ * // Remove vertex and edges
326
+ * const g = new UndirectedGraph();
327
+ * g.addVertex('A');
328
+ * g.addVertex('B');
329
+ * g.addEdge('A', 'B');
330
+ * g.deleteVertex('A');
331
+ * console.log(g.hasVertex('A')); // false;
259
332
  */
260
333
  deleteVertex(vertexOrKey: VO | VertexKey): boolean;
261
334
  /**
@@ -276,8 +349,111 @@ export declare class UndirectedGraph<V = any, E = any, VO extends UndirectedVert
276
349
  * Unique set of undirected edges across endpoints.
277
350
  * @returns Array of edges.
278
351
  * @remarks Time O(E), Space O(E)
352
+
353
+
354
+
355
+
356
+
357
+
358
+
359
+
360
+
361
+
362
+
363
+
364
+
365
+
366
+
367
+
368
+
369
+
370
+
371
+
372
+
373
+
374
+
375
+
376
+
377
+
378
+
379
+
380
+
381
+ * @example
382
+ * // Get all edges
383
+ * const g = new UndirectedGraph();
384
+ * g.addVertex('A');
385
+ * g.addVertex('B');
386
+ * g.addEdge('A', 'B');
387
+ * console.log(g.edgeSet().length); // 1;
279
388
  */
280
389
  edgeSet(): EO[];
390
+ /**
391
+ * UndirectedGraph connectivity and neighbors
392
+
393
+
394
+
395
+
396
+
397
+
398
+
399
+
400
+
401
+
402
+
403
+
404
+
405
+
406
+
407
+
408
+
409
+
410
+
411
+
412
+
413
+
414
+
415
+
416
+
417
+
418
+
419
+
420
+
421
+
422
+
423
+
424
+ * @example
425
+ * // UndirectedGraph connectivity and neighbors
426
+ * const graph = new UndirectedGraph<string>();
427
+ *
428
+ * // Build a friendship network
429
+ * const people = ['Alice', 'Bob', 'Charlie', 'Diana', 'Eve'];
430
+ * for (const person of people) {
431
+ * graph.addVertex(person);
432
+ * }
433
+ *
434
+ * // Add friendships (undirected edges)
435
+ * graph.addEdge('Alice', 'Bob', 1);
436
+ * graph.addEdge('Alice', 'Charlie', 1);
437
+ * graph.addEdge('Bob', 'Diana', 1);
438
+ * graph.addEdge('Charlie', 'Eve', 1);
439
+ * graph.addEdge('Diana', 'Eve', 1);
440
+ *
441
+ * // Get friends of each person
442
+ * const aliceFriends = graph.getNeighbors('Alice');
443
+ * console.log(aliceFriends[0].key); // 'Bob';
444
+ * console.log(aliceFriends[1].key); // 'Charlie';
445
+ * console.log(aliceFriends.length); // 2;
446
+ *
447
+ * const dianaFriends = graph.getNeighbors('Diana');
448
+ * console.log(dianaFriends[0].key); // 'Bob';
449
+ * console.log(dianaFriends[1].key); // 'Eve';
450
+ * console.log(dianaFriends.length); // 2;
451
+ *
452
+ * // Verify bidirectional friendship
453
+ * const bobFriends = graph.getNeighbors('Bob');
454
+ * console.log(bobFriends[0].key); // 'Alice'; // Alice -> Bob -> Alice ✓
455
+ * console.log(bobFriends[1].key); // 'Diana';
456
+ */
281
457
  getNeighbors(vertexOrKey: VO | VertexKey): VO[];
282
458
  /**
283
459
  * Resolve an edge's two endpoints to vertex instances.
@@ -306,6 +482,45 @@ export declare class UndirectedGraph<V = any, E = any, VO extends UndirectedVert
306
482
  * Tarjan-based bridge and articulation point detection.
307
483
  * @returns `{ dfnMap, lowMap, bridges, cutVertices }`.
308
484
  * @remarks Time O(V + E), Space O(V + E)
485
+
486
+
487
+
488
+
489
+
490
+
491
+
492
+
493
+
494
+
495
+
496
+
497
+
498
+
499
+
500
+
501
+
502
+
503
+
504
+
505
+
506
+
507
+
508
+
509
+
510
+
511
+
512
+
513
+
514
+ * @example
515
+ * // Find articulation points and bridges
516
+ * const g = new UndirectedGraph();
517
+ * g.addVertex('A');
518
+ * g.addVertex('B');
519
+ * g.addVertex('C');
520
+ * g.addEdge('A', 'B');
521
+ * g.addEdge('B', 'C');
522
+ * const result = g.tarjan();
523
+ * console.log(result); // defined;
309
524
  */
310
525
  tarjan(): {
311
526
  dfnMap: Map<VO, number>;
@@ -325,18 +540,137 @@ export declare class UndirectedGraph<V = any, E = any, VO extends UndirectedVert
325
540
  * Uses DFS with parent tracking.
326
541
  * @returns `true` if a cycle exists, `false` otherwise.
327
542
  * @remarks Time O(V + E), Space O(V)
543
+
544
+
545
+
546
+
547
+
548
+
549
+
550
+
551
+
552
+
553
+
554
+
555
+
556
+
557
+
558
+
559
+
560
+
561
+
562
+
563
+
564
+
565
+
566
+
567
+
568
+
569
+
570
+
571
+
572
+ * @example
573
+ * // Detect cycle
574
+ * const g = new UndirectedGraph();
575
+ * g.addVertex('A');
576
+ * g.addVertex('B');
577
+ * g.addVertex('C');
578
+ * g.addEdge('A', 'B');
579
+ * g.addEdge('B', 'C');
580
+ * console.log(g.hasCycle()); // false;
581
+ * g.addEdge('C', 'A');
582
+ * console.log(g.hasCycle()); // true;
328
583
  */
329
584
  hasCycle(): boolean;
330
585
  /**
331
586
  * Get bridges discovered by `tarjan()`.
332
587
  * @returns Array of edges that are bridges.
333
588
  * @remarks Time O(B), Space O(1)
589
+
590
+
591
+
592
+
593
+
594
+
595
+
596
+
597
+
598
+
599
+
600
+
601
+
602
+
603
+
604
+
605
+
606
+
607
+
608
+
609
+
610
+
611
+
612
+
613
+
614
+
615
+
616
+
617
+
618
+ * @example
619
+ * // Find bridge edges
620
+ * const g = new UndirectedGraph();
621
+ * g.addVertex('A');
622
+ * g.addVertex('B');
623
+ * g.addVertex('C');
624
+ * g.addEdge('A', 'B');
625
+ * g.addEdge('B', 'C');
626
+ * const bridges = g.getBridges();
627
+ * console.log(bridges.length); // 2;
334
628
  */
335
629
  getBridges(): EO[];
336
630
  /**
337
631
  * Get articulation points discovered by `tarjan()`.
338
632
  * @returns Array of cut vertices.
339
633
  * @remarks Time O(C), Space O(1)
634
+
635
+
636
+
637
+
638
+
639
+
640
+
641
+
642
+
643
+
644
+
645
+
646
+
647
+
648
+
649
+
650
+
651
+
652
+
653
+
654
+
655
+
656
+
657
+
658
+
659
+
660
+
661
+
662
+
663
+ * @example
664
+ * // Find articulation points
665
+ * const g = new UndirectedGraph();
666
+ * g.addVertex('A');
667
+ * g.addVertex('B');
668
+ * g.addVertex('C');
669
+ * g.addEdge('A', 'B');
670
+ * g.addEdge('B', 'C');
671
+ * const cuts = g.getCutVertices();
672
+ * console.log(cuts.length); // 1;
673
+ * console.log(cuts[0].key); // 'B';
340
674
  */
341
675
  getCutVertices(): VO[];
342
676
  /**