max-priority-queue-typed 2.5.2 → 2.5.3

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 (59) hide show
  1. package/dist/cjs/index.cjs +103 -16
  2. package/dist/cjs/index.cjs.map +1 -1
  3. package/dist/cjs-legacy/index.cjs +103 -16
  4. package/dist/cjs-legacy/index.cjs.map +1 -1
  5. package/dist/esm/index.mjs +103 -16
  6. package/dist/esm/index.mjs.map +1 -1
  7. package/dist/esm-legacy/index.mjs +103 -16
  8. package/dist/esm-legacy/index.mjs.map +1 -1
  9. package/dist/types/data-structures/binary-tree/avl-tree.d.ts +50 -2
  10. package/dist/types/data-structures/binary-tree/binary-indexed-tree.d.ts +56 -0
  11. package/dist/types/data-structures/binary-tree/binary-tree.d.ts +116 -15
  12. package/dist/types/data-structures/binary-tree/bst.d.ts +99 -3
  13. package/dist/types/data-structures/binary-tree/red-black-tree.d.ts +79 -8
  14. package/dist/types/data-structures/binary-tree/segment-tree.d.ts +24 -0
  15. package/dist/types/data-structures/binary-tree/tree-map.d.ts +520 -1
  16. package/dist/types/data-structures/binary-tree/tree-multi-map.d.ts +489 -1
  17. package/dist/types/data-structures/binary-tree/tree-multi-set.d.ts +393 -1
  18. package/dist/types/data-structures/binary-tree/tree-set.d.ts +500 -1
  19. package/dist/types/data-structures/graph/directed-graph.d.ts +40 -0
  20. package/dist/types/data-structures/graph/undirected-graph.d.ts +36 -0
  21. package/dist/types/data-structures/hash/hash-map.d.ts +51 -6
  22. package/dist/types/data-structures/heap/heap.d.ts +98 -12
  23. package/dist/types/data-structures/linked-list/doubly-linked-list.d.ts +75 -0
  24. package/dist/types/data-structures/linked-list/singly-linked-list.d.ts +61 -1
  25. package/dist/types/data-structures/linked-list/skip-linked-list.d.ts +72 -0
  26. package/dist/types/data-structures/matrix/matrix.d.ts +32 -0
  27. package/dist/types/data-structures/queue/deque.d.ts +82 -0
  28. package/dist/types/data-structures/queue/queue.d.ts +61 -0
  29. package/dist/types/data-structures/stack/stack.d.ts +42 -2
  30. package/dist/types/data-structures/trie/trie.d.ts +48 -0
  31. package/dist/types/interfaces/binary-tree.d.ts +2 -3
  32. package/dist/umd/max-priority-queue-typed.js +103 -16
  33. package/dist/umd/max-priority-queue-typed.js.map +1 -1
  34. package/dist/umd/max-priority-queue-typed.min.js +1 -1
  35. package/dist/umd/max-priority-queue-typed.min.js.map +1 -1
  36. package/package.json +2 -2
  37. package/src/data-structures/binary-tree/avl-tree.ts +52 -5
  38. package/src/data-structures/binary-tree/binary-indexed-tree.ts +56 -0
  39. package/src/data-structures/binary-tree/binary-tree.ts +167 -81
  40. package/src/data-structures/binary-tree/bst.ts +101 -7
  41. package/src/data-structures/binary-tree/red-black-tree.ts +82 -15
  42. package/src/data-structures/binary-tree/segment-tree.ts +24 -0
  43. package/src/data-structures/binary-tree/tree-map.ts +540 -3
  44. package/src/data-structures/binary-tree/tree-multi-map.ts +490 -2
  45. package/src/data-structures/binary-tree/tree-multi-set.ts +393 -1
  46. package/src/data-structures/binary-tree/tree-set.ts +520 -3
  47. package/src/data-structures/graph/directed-graph.ts +41 -1
  48. package/src/data-structures/graph/undirected-graph.ts +37 -1
  49. package/src/data-structures/hash/hash-map.ts +67 -12
  50. package/src/data-structures/heap/heap.ts +107 -19
  51. package/src/data-structures/linked-list/doubly-linked-list.ts +88 -0
  52. package/src/data-structures/linked-list/singly-linked-list.ts +61 -1
  53. package/src/data-structures/linked-list/skip-linked-list.ts +72 -0
  54. package/src/data-structures/matrix/matrix.ts +32 -0
  55. package/src/data-structures/queue/deque.ts +85 -0
  56. package/src/data-structures/queue/queue.ts +73 -0
  57. package/src/data-structures/stack/stack.ts +45 -5
  58. package/src/data-structures/trie/trie.ts +48 -0
  59. package/src/interfaces/binary-tree.ts +1 -9
@@ -351,6 +351,10 @@ var _Heap = class _Heap extends IterableElementBase {
351
351
 
352
352
 
353
353
 
354
+
355
+
356
+
357
+
354
358
 
355
359
 
356
360
 
@@ -405,7 +409,7 @@ var _Heap = class _Heap extends IterableElementBase {
405
409
  }
406
410
  /**
407
411
  * Insert an element.
408
- * @remarks Time O(1) amortized, Space O(1)
412
+ * @remarks Time O(log N) amortized, Space O(1)
409
413
  * @param element - Element to insert.
410
414
  * @returns True.
411
415
 
@@ -438,6 +442,10 @@ var _Heap = class _Heap extends IterableElementBase {
438
442
 
439
443
 
440
444
 
445
+
446
+
447
+
448
+
441
449
 
442
450
 
443
451
 
@@ -495,6 +503,10 @@ var _Heap = class _Heap extends IterableElementBase {
495
503
 
496
504
 
497
505
 
506
+
507
+
508
+
509
+
498
510
 
499
511
 
500
512
 
@@ -555,10 +567,41 @@ var _Heap = class _Heap extends IterableElementBase {
555
567
 
556
568
 
557
569
 
570
+
571
+
572
+
558
573
 
559
574
 
560
575
 
561
576
 
577
+ * @example
578
+ * // Heap with custom comparator (MaxHeap behavior)
579
+ * interface Task {
580
+ * id: number;
581
+ * priority: number;
582
+ * name: string;
583
+ * }
584
+ *
585
+ * // Custom comparator for max heap behavior (higher priority first)
586
+ * const tasks: Task[] = [
587
+ * { id: 1, priority: 5, name: 'Email' },
588
+ * { id: 2, priority: 3, name: 'Chat' },
589
+ * { id: 3, priority: 8, name: 'Alert' }
590
+ * ];
591
+ *
592
+ * const maxHeap = new Heap(tasks, {
593
+ * comparator: (a: Task, b: Task) => b.priority - a.priority
594
+ * });
595
+ *
596
+ * console.log(maxHeap.size); // 3;
597
+ *
598
+ * // Peek returns highest priority task
599
+ * const topTask = maxHeap.peek();
600
+ * console.log(topTask?.priority); // 8;
601
+ * console.log(topTask?.name); // 'Alert';
602
+ */
603
+ /**
604
+ * @deprecated Use `pop` instead. Will be removed in a future major version.
562
605
  * @example
563
606
  * // Heap with custom comparator (MaxHeap behavior)
564
607
  * interface Task {
@@ -586,6 +629,14 @@ var _Heap = class _Heap extends IterableElementBase {
586
629
  * console.log(topTask?.name); // 'Alert';
587
630
  */
588
631
  poll() {
632
+ return this.pop();
633
+ }
634
+ /**
635
+ * Remove and return the top element (min or max depending on comparator).
636
+ * @remarks Time O(log N) amortized, Space O(1)
637
+ * @returns The removed top element, or undefined if empty.
638
+ */
639
+ pop() {
589
640
  if (this.elements.length === 0) return;
590
641
  const value = this.elements[0];
591
642
  const last = this.elements.pop();
@@ -629,6 +680,10 @@ var _Heap = class _Heap extends IterableElementBase {
629
680
 
630
681
 
631
682
 
683
+
684
+
685
+
686
+
632
687
 
633
688
 
634
689
 
@@ -729,6 +784,10 @@ var _Heap = class _Heap extends IterableElementBase {
729
784
 
730
785
 
731
786
 
787
+
788
+
789
+
790
+
732
791
 
733
792
 
734
793
 
@@ -776,6 +835,10 @@ var _Heap = class _Heap extends IterableElementBase {
776
835
 
777
836
 
778
837
 
838
+
839
+
840
+
841
+
779
842
 
780
843
 
781
844
 
@@ -790,16 +853,6 @@ var _Heap = class _Heap extends IterableElementBase {
790
853
  clear() {
791
854
  this._elements = [];
792
855
  }
793
- /**
794
- * Replace the backing array and rebuild the heap.
795
- * @remarks Time O(N), Space O(N)
796
- * @param elements - Iterable used to refill the heap.
797
- * @returns Array of per-node results from fixing steps.
798
- */
799
- refill(elements) {
800
- this._elements = Array.from(elements);
801
- return this.fix();
802
- }
803
856
  /**
804
857
  * Check if an equal element exists in the heap.
805
858
  * @remarks Time O(N), Space O(1)
@@ -826,6 +879,10 @@ var _Heap = class _Heap extends IterableElementBase {
826
879
 
827
880
 
828
881
 
882
+
883
+
884
+
885
+
829
886
 
830
887
 
831
888
 
@@ -873,6 +930,10 @@ var _Heap = class _Heap extends IterableElementBase {
873
930
 
874
931
 
875
932
 
933
+
934
+
935
+
936
+
876
937
 
877
938
 
878
939
 
@@ -894,7 +955,7 @@ var _Heap = class _Heap extends IterableElementBase {
894
955
  }
895
956
  if (index < 0) return false;
896
957
  if (index === 0) {
897
- this.poll();
958
+ this.pop();
898
959
  } else if (index === this.elements.length - 1) {
899
960
  this.elements.pop();
900
961
  } else {
@@ -904,13 +965,19 @@ var _Heap = class _Heap extends IterableElementBase {
904
965
  }
905
966
  return true;
906
967
  }
968
+ /**
969
+ * @deprecated Use `deleteWhere` instead. Will be removed in a future major version.
970
+ */
971
+ deleteBy(predicate) {
972
+ return this.deleteWhere(predicate);
973
+ }
907
974
  /**
908
975
  * Delete the first element that matches a predicate.
909
976
  * @remarks Time O(N), Space O(1)
910
977
  * @param predicate - Function (element, index, heap) → boolean.
911
978
  * @returns True if an element was removed.
912
979
  */
913
- deleteBy(predicate) {
980
+ deleteWhere(predicate) {
914
981
  let idx = -1;
915
982
  for (let i = 0; i < this.elements.length; i++) {
916
983
  if (predicate(this.elements[i], i, this)) {
@@ -920,7 +987,7 @@ var _Heap = class _Heap extends IterableElementBase {
920
987
  }
921
988
  if (idx < 0) return false;
922
989
  if (idx === 0) {
923
- this.poll();
990
+ this.pop();
924
991
  } else if (idx === this.elements.length - 1) {
925
992
  this.elements.pop();
926
993
  } else {
@@ -966,6 +1033,10 @@ var _Heap = class _Heap extends IterableElementBase {
966
1033
 
967
1034
 
968
1035
 
1036
+
1037
+
1038
+
1039
+
969
1040
 
970
1041
 
971
1042
 
@@ -1046,6 +1117,10 @@ var _Heap = class _Heap extends IterableElementBase {
1046
1117
 
1047
1118
 
1048
1119
 
1120
+
1121
+
1122
+
1123
+
1049
1124
 
1050
1125
 
1051
1126
 
@@ -1099,6 +1174,10 @@ var _Heap = class _Heap extends IterableElementBase {
1099
1174
 
1100
1175
 
1101
1176
 
1177
+
1178
+
1179
+
1180
+
1102
1181
 
1103
1182
 
1104
1183
 
@@ -1151,6 +1230,10 @@ var _Heap = class _Heap extends IterableElementBase {
1151
1230
 
1152
1231
 
1153
1232
 
1233
+
1234
+
1235
+
1236
+
1154
1237
 
1155
1238
 
1156
1239
 
@@ -1210,6 +1293,10 @@ var _Heap = class _Heap extends IterableElementBase {
1210
1293
 
1211
1294
 
1212
1295
 
1296
+
1297
+
1298
+
1299
+
1213
1300
 
1214
1301
 
1215
1302
 
@@ -1392,7 +1479,7 @@ var _FibonacciHeap = class _FibonacciHeap {
1392
1479
  * Push an element into the root list.
1393
1480
  * @remarks Time O(1) amortized, Space O(1)
1394
1481
  * @param element - Element to insert.
1395
- * @returns This heap.
1482
+ * @returns True when the element is added.
1396
1483
  */
1397
1484
  push(element) {
1398
1485
  const node = this.createNode(element);
@@ -1401,7 +1488,7 @@ var _FibonacciHeap = class _FibonacciHeap {
1401
1488
  this.mergeWithRoot(node);
1402
1489
  if (!this.min || this.comparator(node.element, this.min.element) <= 0) this._min = node;
1403
1490
  this._size++;
1404
- return this;
1491
+ return true;
1405
1492
  }
1406
1493
  peek() {
1407
1494
  return this.min ? this.min.element : void 0;