max-priority-queue-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 +63 -0
  2. package/dist/cjs/index.cjs +694 -119
  3. package/dist/cjs/index.cjs.map +1 -1
  4. package/dist/cjs-legacy/index.cjs +693 -118
  5. package/dist/cjs-legacy/index.cjs.map +1 -1
  6. package/dist/esm/index.mjs +694 -119
  7. package/dist/esm/index.mjs.map +1 -1
  8. package/dist/esm-legacy/index.mjs +693 -118
  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/max-priority-queue-typed.js +691 -116
  51. package/dist/umd/max-priority-queue-typed.js.map +1 -1
  52. package/dist/umd/max-priority-queue-typed.min.js +1 -1
  53. package/dist/umd/max-priority-queue-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
@@ -123,16 +123,12 @@ export class AVLTreeNode<K = any, V = any> {
123
123
  *
124
124
  * @returns The node's color.
125
125
  */
126
+ /* istanbul ignore next -- inherited field, used by RedBlackTree subclass */ /* istanbul ignore next -- inherited field, not used by AVLTree */
126
127
  get color(): RBTNColor {
127
128
  return this._color;
128
129
  }
129
130
 
130
- /**
131
- * Sets the color of the node.
132
- * @remarks Time O(1), Space O(1)
133
- *
134
- * @param value - The new color.
135
- */
131
+ /* istanbul ignore next -- inherited field, not used by AVLTree */
136
132
  set color(value: RBTNColor) {
137
133
  this._color = value;
138
134
  }
@@ -145,16 +141,12 @@ export class AVLTreeNode<K = any, V = any> {
145
141
  *
146
142
  * @returns The subtree node count.
147
143
  */
144
+ /* istanbul ignore next -- inherited field, not used by AVLTree */
148
145
  get count(): number {
149
146
  return this._count;
150
147
  }
151
148
 
152
- /**
153
- * Sets the count of nodes in the subtree.
154
- * @remarks Time O(1), Space O(1)
155
- *
156
- * @param value - The new count.
157
- */
149
+ /* istanbul ignore next -- inherited field, not used by AVLTree */
158
150
  set count(value: number) {
159
151
  this._count = value;
160
152
  }
@@ -176,6 +168,7 @@ export class AVLTreeNode<K = any, V = any> {
176
168
  return this.left || this.right ? 'ROOT_RIGHT' : 'RIGHT';
177
169
  }
178
170
 
171
+ /* istanbul ignore next -- defensive: unreachable if tree structure is correct */
179
172
  return 'MAL_NODE';
180
173
  }
181
174
  }
@@ -197,28 +190,6 @@ export class AVLTreeNode<K = any, V = any> {
197
190
  * 7. Path Length: The path length from the root to any leaf is longer compared to an unbalanced BST, but shorter than a linear chain of nodes.
198
191
  *
199
192
  * @example
200
- * // basic AVLTree creation and add operation
201
- * // Create a simple AVLTree with initial values
202
- * const tree = new AVLTree([5, 2, 8, 1, 9]);
203
- *
204
- * tree.print();
205
- * // _2___
206
- * // / \
207
- * // 1 _8_
208
- * // / \
209
- * // 5 9
210
- *
211
- * // Verify the tree maintains sorted order
212
- * console.log([...tree.keys()]); // [1, 2, 5, 8, 9];
213
- *
214
- * // Check size
215
- * console.log(tree.size); // 5;
216
- *
217
- * // Add a new element
218
- * tree.set(3);
219
- * console.log(tree.size); // 6;
220
- * console.log([...tree.keys()]); // [1, 2, 3, 5, 8, 9];
221
- * @example
222
193
  * // AVLTree has and get operations
223
194
  * const tree = new AVLTree<number>([11, 3, 15, 1, 8, 13, 16, 2, 6, 9, 12, 14, 4, 7, 10, 5]);
224
195
  *
@@ -233,23 +204,6 @@ export class AVLTreeNode<K = any, V = any> {
233
204
  * // Verify tree is balanced
234
205
  * console.log(tree.isAVLBalanced()); // true;
235
206
  * @example
236
- * // AVLTree delete and balance verification
237
- * const tree = new AVLTree([11, 3, 15, 1, 8, 13, 16, 2, 6, 9, 12, 14, 4, 7, 10, 5]);
238
- *
239
- * // Delete an element
240
- * tree.delete(10);
241
- * console.log(tree.has(10)); // false;
242
- *
243
- * // Tree should remain balanced after deletion
244
- * console.log(tree.isAVLBalanced()); // true;
245
- *
246
- * // Size decreased
247
- * console.log(tree.size); // 15;
248
- *
249
- * // Remaining elements are still sorted
250
- * const keys = [...tree.keys()];
251
- * console.log(keys); // [1, 2, 3, 4, 5, 6, 7, 8, 9, 11, 12, 13, 14, 15, 16];
252
- * @example
253
207
  * // AVLTree for university ranking system with strict balance
254
208
  * interface University {
255
209
  * name: string;
@@ -406,6 +360,132 @@ export class AVLTree<K = any, V = any, R = any> extends BST<K, V, R> implements
406
360
  * @param keyNodeOrEntry - The key, node, or entry to set.
407
361
  * @param [value] - The value, if providing just a key.
408
362
  * @returns True if the addition was successful, false otherwise.
363
+
364
+
365
+
366
+
367
+
368
+
369
+
370
+
371
+
372
+
373
+
374
+
375
+
376
+
377
+
378
+
379
+
380
+
381
+
382
+
383
+
384
+
385
+
386
+
387
+
388
+
389
+
390
+
391
+
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
+
425
+
426
+
427
+
428
+
429
+
430
+
431
+
432
+
433
+
434
+
435
+
436
+
437
+
438
+
439
+
440
+
441
+
442
+
443
+
444
+
445
+
446
+
447
+
448
+
449
+
450
+
451
+
452
+
453
+
454
+
455
+
456
+
457
+
458
+
459
+
460
+
461
+
462
+
463
+
464
+
465
+
466
+
467
+
468
+
469
+
470
+
471
+
472
+
473
+
474
+
475
+
476
+
477
+
478
+
479
+
480
+
481
+
482
+
483
+ * @example
484
+ * // Set a key-value pair
485
+ * const avl = new AVLTree<number, string>();
486
+ * avl.set(1, 'one');
487
+ * avl.set(2, 'two');
488
+ * console.log(avl.get(1)); // 'one';
409
489
  */
410
490
  override set(
411
491
  keyNodeOrEntry: K | AVLTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined,
@@ -424,6 +504,108 @@ export class AVLTree<K = any, V = any, R = any> extends BST<K, V, R> implements
424
504
  *
425
505
  * @param keyNodeOrEntry - The node to delete.
426
506
  * @returns An array containing deletion results.
507
+
508
+
509
+
510
+
511
+
512
+
513
+
514
+
515
+
516
+
517
+
518
+
519
+
520
+
521
+
522
+
523
+
524
+
525
+
526
+
527
+
528
+
529
+
530
+
531
+
532
+
533
+
534
+
535
+
536
+
537
+
538
+
539
+
540
+
541
+
542
+
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
+
573
+
574
+
575
+
576
+
577
+
578
+
579
+
580
+
581
+
582
+
583
+
584
+
585
+
586
+
587
+
588
+
589
+
590
+
591
+
592
+
593
+
594
+
595
+
596
+
597
+
598
+
599
+
600
+
601
+
602
+
603
+ * @example
604
+ * // Remove nodes and verify structure
605
+ * const avl = new AVLTree<number>([5, 3, 7, 1, 4, 6, 8]);
606
+ * avl.delete(3);
607
+ * console.log(avl.has(3)); // false;
608
+ * console.log(avl.size); // 6;
427
609
  */
428
610
  override delete(
429
611
  keyNodeOrEntry: K | AVLTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined
@@ -445,6 +627,68 @@ export class AVLTree<K = any, V = any, R = any> extends BST<K, V, R> implements
445
627
  *
446
628
  * @param [iterationType=this.iterationType] - The traversal method for the initial node export.
447
629
  * @returns True if successful, false if the tree was empty.
630
+
631
+
632
+
633
+
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
+
664
+
665
+
666
+
667
+
668
+
669
+
670
+
671
+
672
+
673
+
674
+
675
+
676
+
677
+
678
+
679
+
680
+
681
+
682
+
683
+
684
+ * @example
685
+ * // Rebalance the tree
686
+ * const avl = new AVLTree<number>();
687
+ * // Insert in sorted order (worst case for BST)
688
+ * for (let i = 1; i <= 7; i++) avl.add(i);
689
+ * console.log(avl.isAVLBalanced()); // false;
690
+ * avl.perfectlyBalance();
691
+ * console.log(avl.isAVLBalanced()); // true;
448
692
  */
449
693
  override perfectlyBalance(iterationType: IterationType = this.iterationType): boolean {
450
694
  const nodes = this.dfs(node => node, 'IN', false, this._root, iterationType);
@@ -486,6 +730,96 @@ export class AVLTree<K = any, V = any, R = any> extends BST<K, V, R> implements
486
730
  * @param [options] - Options for the new AVLTree.
487
731
  * @param [thisArg] - `this` context for the callback.
488
732
  * @returns A new, mapped AVLTree.
733
+
734
+
735
+
736
+
737
+
738
+
739
+
740
+
741
+
742
+
743
+
744
+
745
+
746
+
747
+
748
+
749
+
750
+
751
+
752
+
753
+
754
+
755
+
756
+
757
+
758
+
759
+
760
+
761
+
762
+
763
+
764
+
765
+
766
+
767
+
768
+
769
+
770
+
771
+
772
+
773
+
774
+
775
+
776
+
777
+
778
+
779
+
780
+
781
+
782
+
783
+
784
+
785
+
786
+
787
+
788
+
789
+
790
+
791
+
792
+
793
+
794
+
795
+
796
+
797
+
798
+
799
+
800
+
801
+
802
+
803
+
804
+
805
+
806
+
807
+
808
+
809
+
810
+
811
+
812
+
813
+
814
+
815
+
816
+
817
+
818
+ * @example
819
+ * // Transform to new tree
820
+ * const avl = new AVLTree<number, number>([[1, 10], [2, 20], [3, 30]]);
821
+ * const doubled = avl.map((value, key) => [key, (value ?? 0) * 2] as [number, number]);
822
+ * console.log([...doubled.values()]); // [20, 40, 60];
489
823
  */
490
824
  override map<MK = K, MV = V, MR = any>(
491
825
  callback: EntryCallback<K, V | undefined, [MK, MV]>,
@@ -574,6 +908,7 @@ export class AVLTree<K = any, V = any, R = any> extends BST<K, V, R> implements
574
908
 
575
909
  return destNodeEnsured;
576
910
  }
911
+ /* istanbul ignore next -- defensive: srcNode/destNode are always valid when called internally */
577
912
  return undefined;
578
913
  }
579
914