max-priority-queue-typed 2.5.2 → 2.6.0

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 (63) hide show
  1. package/dist/cjs/index.cjs +174 -16
  2. package/dist/cjs/index.cjs.map +1 -1
  3. package/dist/cjs-legacy/index.cjs +174 -16
  4. package/dist/cjs-legacy/index.cjs.map +1 -1
  5. package/dist/esm/index.mjs +174 -16
  6. package/dist/esm/index.mjs.map +1 -1
  7. package/dist/esm-legacy/index.mjs +174 -16
  8. package/dist/esm-legacy/index.mjs.map +1 -1
  9. package/dist/types/data-structures/base/iterable-element-base.d.ts +17 -0
  10. package/dist/types/data-structures/base/linear-base.d.ts +6 -0
  11. package/dist/types/data-structures/binary-tree/avl-tree.d.ts +86 -2
  12. package/dist/types/data-structures/binary-tree/binary-indexed-tree.d.ts +98 -0
  13. package/dist/types/data-structures/binary-tree/binary-tree.d.ts +191 -15
  14. package/dist/types/data-structures/binary-tree/bst.d.ts +171 -3
  15. package/dist/types/data-structures/binary-tree/red-black-tree.d.ts +136 -8
  16. package/dist/types/data-structures/binary-tree/segment-tree.d.ts +42 -0
  17. package/dist/types/data-structures/binary-tree/tree-map.d.ts +1061 -167
  18. package/dist/types/data-structures/binary-tree/tree-multi-map.d.ts +1232 -355
  19. package/dist/types/data-structures/binary-tree/tree-multi-set.d.ts +916 -194
  20. package/dist/types/data-structures/binary-tree/tree-set.d.ts +1078 -141
  21. package/dist/types/data-structures/graph/directed-graph.d.ts +70 -0
  22. package/dist/types/data-structures/graph/undirected-graph.d.ts +63 -0
  23. package/dist/types/data-structures/hash/hash-map.d.ts +84 -6
  24. package/dist/types/data-structures/heap/heap.d.ts +140 -12
  25. package/dist/types/data-structures/linked-list/doubly-linked-list.d.ts +150 -2
  26. package/dist/types/data-structures/linked-list/singly-linked-list.d.ts +106 -1
  27. package/dist/types/data-structures/linked-list/skip-linked-list.d.ts +126 -0
  28. package/dist/types/data-structures/matrix/matrix.d.ts +56 -0
  29. package/dist/types/data-structures/queue/deque.d.ts +171 -0
  30. package/dist/types/data-structures/queue/queue.d.ts +97 -0
  31. package/dist/types/data-structures/stack/stack.d.ts +72 -2
  32. package/dist/types/data-structures/trie/trie.d.ts +84 -0
  33. package/dist/types/interfaces/binary-tree.d.ts +2 -3
  34. package/dist/umd/max-priority-queue-typed.js +174 -16
  35. package/dist/umd/max-priority-queue-typed.js.map +1 -1
  36. package/dist/umd/max-priority-queue-typed.min.js +1 -1
  37. package/dist/umd/max-priority-queue-typed.min.js.map +1 -1
  38. package/package.json +2 -2
  39. package/src/data-structures/base/iterable-element-base.ts +32 -0
  40. package/src/data-structures/base/linear-base.ts +11 -0
  41. package/src/data-structures/binary-tree/avl-tree.ts +88 -5
  42. package/src/data-structures/binary-tree/binary-indexed-tree.ts +98 -0
  43. package/src/data-structures/binary-tree/binary-tree.ts +242 -81
  44. package/src/data-structures/binary-tree/bst.ts +173 -7
  45. package/src/data-structures/binary-tree/red-black-tree.ts +139 -15
  46. package/src/data-structures/binary-tree/segment-tree.ts +42 -0
  47. package/src/data-structures/binary-tree/tree-map.ts +948 -36
  48. package/src/data-structures/binary-tree/tree-multi-map.ts +893 -13
  49. package/src/data-structures/binary-tree/tree-multi-set.ts +761 -33
  50. package/src/data-structures/binary-tree/tree-set.ts +1260 -251
  51. package/src/data-structures/graph/directed-graph.ts +71 -1
  52. package/src/data-structures/graph/undirected-graph.ts +64 -1
  53. package/src/data-structures/hash/hash-map.ts +100 -12
  54. package/src/data-structures/heap/heap.ts +149 -19
  55. package/src/data-structures/linked-list/doubly-linked-list.ts +178 -2
  56. package/src/data-structures/linked-list/singly-linked-list.ts +106 -1
  57. package/src/data-structures/linked-list/skip-linked-list.ts +126 -0
  58. package/src/data-structures/matrix/matrix.ts +56 -0
  59. package/src/data-structures/queue/deque.ts +187 -0
  60. package/src/data-structures/queue/queue.ts +109 -0
  61. package/src/data-structures/stack/stack.ts +75 -5
  62. package/src/data-structures/trie/trie.ts +84 -0
  63. package/src/interfaces/binary-tree.ts +1 -9
@@ -169,6 +169,13 @@ export declare class Matrix {
169
169
 
170
170
 
171
171
 
172
+
173
+
174
+
175
+
176
+
177
+
178
+
172
179
 
173
180
 
174
181
 
@@ -233,6 +240,13 @@ export declare class Matrix {
233
240
 
234
241
 
235
242
 
243
+
244
+
245
+
246
+
247
+
248
+
249
+
236
250
 
237
251
 
238
252
 
@@ -289,6 +303,13 @@ export declare class Matrix {
289
303
 
290
304
 
291
305
 
306
+
307
+
308
+
309
+
310
+
311
+
312
+
292
313
 
293
314
 
294
315
 
@@ -354,6 +375,13 @@ export declare class Matrix {
354
375
 
355
376
 
356
377
 
378
+
379
+
380
+
381
+
382
+
383
+
384
+
357
385
 
358
386
 
359
387
 
@@ -402,6 +430,13 @@ export declare class Matrix {
402
430
 
403
431
 
404
432
 
433
+
434
+
435
+
436
+
437
+
438
+
439
+
405
440
 
406
441
 
407
442
 
@@ -465,6 +500,13 @@ export declare class Matrix {
465
500
 
466
501
 
467
502
 
503
+
504
+
505
+
506
+
507
+
508
+
509
+
468
510
 
469
511
 
470
512
 
@@ -524,6 +566,13 @@ export declare class Matrix {
524
566
 
525
567
 
526
568
 
569
+
570
+
571
+
572
+
573
+
574
+
575
+
527
576
 
528
577
 
529
578
 
@@ -576,6 +625,13 @@ export declare class Matrix {
576
625
 
577
626
 
578
627
 
628
+
629
+
630
+
631
+
632
+
633
+
634
+
579
635
 
580
636
 
581
637
 
@@ -197,6 +197,9 @@ export declare class Deque<E = any, R = any> extends LinearBase<E, R> {
197
197
 
198
198
 
199
199
 
200
+
201
+
202
+
200
203
 
201
204
 
202
205
 
@@ -216,6 +219,32 @@ export declare class Deque<E = any, R = any> extends LinearBase<E, R> {
216
219
  * // Length unchanged
217
220
  * console.log(deque.length); // 5;
218
221
  */
222
+ /**
223
+ * Peek at the front element without removing it (alias for `first`).
224
+ * @remarks Time O(1), Space O(1)
225
+ * @returns Front element or undefined.
226
+ */
227
+ peek(): E | undefined;
228
+ /**
229
+ * Deque peek at both ends
230
+
231
+
232
+
233
+ * @example
234
+ * // Deque peek at both ends
235
+ * const deque = new Deque<number>([10, 20, 30, 40, 50]);
236
+ *
237
+ * // Get first element without removing
238
+ * const first = deque.at(0);
239
+ * console.log(first); // 10;
240
+ *
241
+ * // Get last element without removing
242
+ * const last = deque.at(deque.length - 1);
243
+ * console.log(last); // 50;
244
+ *
245
+ * // Length unchanged
246
+ * console.log(deque.length); // 5;
247
+ */
219
248
  get first(): E | undefined;
220
249
  /**
221
250
  * Get the last element without removing it.
@@ -248,6 +277,13 @@ export declare class Deque<E = any, R = any> extends LinearBase<E, R> {
248
277
 
249
278
 
250
279
 
280
+
281
+
282
+
283
+
284
+
285
+
286
+
251
287
 
252
288
 
253
289
 
@@ -306,6 +342,13 @@ export declare class Deque<E = any, R = any> extends LinearBase<E, R> {
306
342
 
307
343
 
308
344
 
345
+
346
+
347
+
348
+
349
+
350
+
351
+
309
352
 
310
353
 
311
354
 
@@ -365,6 +408,13 @@ export declare class Deque<E = any, R = any> extends LinearBase<E, R> {
365
408
 
366
409
 
367
410
 
411
+
412
+
413
+
414
+
415
+
416
+
417
+
368
418
 
369
419
 
370
420
 
@@ -411,6 +461,13 @@ export declare class Deque<E = any, R = any> extends LinearBase<E, R> {
411
461
 
412
462
 
413
463
 
464
+
465
+
466
+
467
+
468
+
469
+
470
+
414
471
 
415
472
 
416
473
 
@@ -458,6 +515,13 @@ export declare class Deque<E = any, R = any> extends LinearBase<E, R> {
458
515
 
459
516
 
460
517
 
518
+
519
+
520
+
521
+
522
+
523
+
524
+
461
525
 
462
526
 
463
527
 
@@ -526,6 +590,13 @@ export declare class Deque<E = any, R = any> extends LinearBase<E, R> {
526
590
 
527
591
 
528
592
 
593
+
594
+
595
+
596
+
597
+
598
+
599
+
529
600
 
530
601
 
531
602
 
@@ -569,6 +640,13 @@ export declare class Deque<E = any, R = any> extends LinearBase<E, R> {
569
640
 
570
641
 
571
642
 
643
+
644
+
645
+
646
+
647
+
648
+
649
+
572
650
 
573
651
 
574
652
 
@@ -613,6 +691,13 @@ export declare class Deque<E = any, R = any> extends LinearBase<E, R> {
613
691
 
614
692
 
615
693
 
694
+
695
+
696
+
697
+
698
+
699
+
700
+
616
701
 
617
702
 
618
703
 
@@ -706,6 +791,13 @@ export declare class Deque<E = any, R = any> extends LinearBase<E, R> {
706
791
 
707
792
 
708
793
 
794
+
795
+
796
+
797
+
798
+
799
+
800
+
709
801
 
710
802
 
711
803
 
@@ -769,6 +861,10 @@ export declare class Deque<E = any, R = any> extends LinearBase<E, R> {
769
861
 
770
862
 
771
863
 
864
+
865
+
866
+
867
+
772
868
 
773
869
 
774
870
 
@@ -793,6 +889,53 @@ export declare class Deque<E = any, R = any> extends LinearBase<E, R> {
793
889
  * }
794
890
  * console.log(backward); // ['D', 'C', 'B', 'A'];
795
891
  */
892
+ /**
893
+ * Find the last value matching a predicate (scans back-to-front).
894
+ * @remarks Provided for familiarity when migrating from Array. Time O(n), Space O(1).
895
+ * @param predicate - Function called with (value, index, deque).
896
+ * @returns Matching value or undefined.
897
+ * @example
898
+ * // Find last matching value
899
+ * const d = new Deque([1, 2, 3, 4, 5]);
900
+ * console.log(d.findLast(v => v > 2)); // 5;
901
+ * console.log(d.findLast(v => v % 2 === 0)); // 4;
902
+ */
903
+ findLast(predicate: (value: E, index: number, deque: this) => boolean): E | undefined;
904
+ /**
905
+ * Find the index of the last value matching a predicate (scans back-to-front).
906
+ * @remarks Provided for familiarity when migrating from Array. Time O(n), Space O(1).
907
+ * @param predicate - Function called with (value, index, deque).
908
+ * @returns Matching index, or -1 if not found.
909
+ * @example
910
+ * // Find last matching index
911
+ * const d = new Deque([10, 20, 30, 20, 10]);
912
+ * console.log(d.findLastIndex(v => v === 20)); // 3;
913
+ * console.log(d.findLastIndex(v => v === 10)); // 4;
914
+ */
915
+ findLastIndex(predicate: (value: E, index: number, deque: this) => boolean): number;
916
+ /**
917
+ * Deque for...of iteration and reverse
918
+
919
+
920
+ * @example
921
+ * // Deque for...of iteration and reverse
922
+ * const deque = new Deque<string>(['A', 'B', 'C', 'D']);
923
+ *
924
+ * // Iterate forward
925
+ * const forward: string[] = [];
926
+ * for (const item of deque) {
927
+ * forward.push(item);
928
+ * }
929
+ * console.log(forward); // ['A', 'B', 'C', 'D'];
930
+ *
931
+ * // Reverse the deque
932
+ * deque.reverse();
933
+ * const backward: string[] = [];
934
+ * for (const item of deque) {
935
+ * backward.push(item);
936
+ * }
937
+ * console.log(backward); // ['D', 'C', 'B', 'A'];
938
+ */
796
939
  reverse(): this;
797
940
  /**
798
941
  * Deduplicate consecutive equal elements in-place.
@@ -844,6 +987,13 @@ export declare class Deque<E = any, R = any> extends LinearBase<E, R> {
844
987
 
845
988
 
846
989
 
990
+
991
+
992
+
993
+
994
+
995
+
996
+
847
997
 
848
998
 
849
999
 
@@ -891,6 +1041,13 @@ export declare class Deque<E = any, R = any> extends LinearBase<E, R> {
891
1041
 
892
1042
 
893
1043
 
1044
+
1045
+
1046
+
1047
+
1048
+
1049
+
1050
+
894
1051
 
895
1052
 
896
1053
 
@@ -939,6 +1096,13 @@ export declare class Deque<E = any, R = any> extends LinearBase<E, R> {
939
1096
 
940
1097
 
941
1098
 
1099
+
1100
+
1101
+
1102
+
1103
+
1104
+
1105
+
942
1106
 
943
1107
 
944
1108
 
@@ -995,6 +1159,13 @@ export declare class Deque<E = any, R = any> extends LinearBase<E, R> {
995
1159
 
996
1160
 
997
1161
 
1162
+
1163
+
1164
+
1165
+
1166
+
1167
+
1168
+
998
1169
 
999
1170
 
1000
1171
 
@@ -154,6 +154,13 @@ export declare class Queue<E = any, R = any> extends LinearBase<E, R> {
154
154
 
155
155
 
156
156
 
157
+
158
+
159
+
160
+
161
+
162
+
163
+
157
164
 
158
165
 
159
166
 
@@ -202,6 +209,13 @@ export declare class Queue<E = any, R = any> extends LinearBase<E, R> {
202
209
 
203
210
 
204
211
 
212
+
213
+
214
+
215
+
216
+
217
+
218
+
205
219
 
206
220
 
207
221
 
@@ -217,6 +231,12 @@ export declare class Queue<E = any, R = any> extends LinearBase<E, R> {
217
231
  * console.log(q.length); // 3;
218
232
  */
219
233
  get first(): E | undefined;
234
+ /**
235
+ * Peek at the front element without removing it (alias for `first`).
236
+ * @remarks Time O(1), Space O(1)
237
+ * @returns Front element or undefined.
238
+ */
239
+ peek(): E | undefined;
220
240
  /**
221
241
  * Get the last element (back) without removing it.
222
242
  * @remarks Time O(1), Space O(1)
@@ -262,6 +282,13 @@ export declare class Queue<E = any, R = any> extends LinearBase<E, R> {
262
282
 
263
283
 
264
284
 
285
+
286
+
287
+
288
+
289
+
290
+
291
+
265
292
 
266
293
 
267
294
 
@@ -322,6 +349,13 @@ export declare class Queue<E = any, R = any> extends LinearBase<E, R> {
322
349
 
323
350
 
324
351
 
352
+
353
+
354
+
355
+
356
+
357
+
358
+
325
359
 
326
360
 
327
361
 
@@ -380,6 +414,13 @@ export declare class Queue<E = any, R = any> extends LinearBase<E, R> {
380
414
 
381
415
 
382
416
 
417
+
418
+
419
+
420
+
421
+
422
+
423
+
383
424
 
384
425
 
385
426
 
@@ -433,6 +474,13 @@ export declare class Queue<E = any, R = any> extends LinearBase<E, R> {
433
474
 
434
475
 
435
476
 
477
+
478
+
479
+
480
+
481
+
482
+
483
+
436
484
 
437
485
 
438
486
 
@@ -477,6 +525,13 @@ export declare class Queue<E = any, R = any> extends LinearBase<E, R> {
477
525
 
478
526
 
479
527
 
528
+
529
+
530
+
531
+
532
+
533
+
534
+
480
535
 
481
536
 
482
537
 
@@ -515,6 +570,13 @@ export declare class Queue<E = any, R = any> extends LinearBase<E, R> {
515
570
  * @returns True if updated.
516
571
  */
517
572
  setAt(index: number, newElement: E): boolean;
573
+ /**
574
+ * Delete the first element that satisfies a predicate.
575
+ * @remarks Time O(N), Space O(N)
576
+ * @param predicate - Function (value, index, queue) → boolean to decide deletion.
577
+ * @returns True if a match was removed.
578
+ */
579
+ deleteWhere(predicate: (value: E, index: number, queue: this) => boolean): boolean;
518
580
  /**
519
581
  * Reverse the queue in-place by compacting then reversing.
520
582
  * @remarks Time O(N), Space O(N)
@@ -550,6 +612,13 @@ export declare class Queue<E = any, R = any> extends LinearBase<E, R> {
550
612
 
551
613
 
552
614
 
615
+
616
+
617
+
618
+
619
+
620
+
621
+
553
622
 
554
623
 
555
624
 
@@ -593,6 +662,13 @@ export declare class Queue<E = any, R = any> extends LinearBase<E, R> {
593
662
 
594
663
 
595
664
 
665
+
666
+
667
+
668
+
669
+
670
+
671
+
596
672
 
597
673
 
598
674
 
@@ -648,6 +724,13 @@ export declare class Queue<E = any, R = any> extends LinearBase<E, R> {
648
724
 
649
725
 
650
726
 
727
+
728
+
729
+
730
+
731
+
732
+
733
+
651
734
 
652
735
 
653
736
 
@@ -696,6 +779,13 @@ export declare class Queue<E = any, R = any> extends LinearBase<E, R> {
696
779
 
697
780
 
698
781
 
782
+
783
+
784
+
785
+
786
+
787
+
788
+
699
789
 
700
790
 
701
791
 
@@ -744,6 +834,13 @@ export declare class Queue<E = any, R = any> extends LinearBase<E, R> {
744
834
 
745
835
 
746
836
 
837
+
838
+
839
+
840
+
841
+
842
+
843
+
747
844
 
748
845
 
749
846
 
@@ -176,6 +176,13 @@ export declare class Stack<E = any, R = any> extends IterableElementBase<E, R> {
176
176
 
177
177
 
178
178
 
179
+
180
+
181
+
182
+
183
+
184
+
185
+
179
186
 
180
187
 
181
188
 
@@ -232,6 +239,13 @@ export declare class Stack<E = any, R = any> extends IterableElementBase<E, R> {
232
239
 
233
240
 
234
241
 
242
+
243
+
244
+
245
+
246
+
247
+
248
+
235
249
 
236
250
 
237
251
 
@@ -279,6 +293,13 @@ export declare class Stack<E = any, R = any> extends IterableElementBase<E, R> {
279
293
 
280
294
 
281
295
 
296
+
297
+
298
+
299
+
300
+
301
+
302
+
282
303
 
283
304
 
284
305
 
@@ -326,6 +347,13 @@ export declare class Stack<E = any, R = any> extends IterableElementBase<E, R> {
326
347
 
327
348
 
328
349
 
350
+
351
+
352
+
353
+
354
+
355
+
356
+
329
357
 
330
358
 
331
359
 
@@ -381,6 +409,13 @@ export declare class Stack<E = any, R = any> extends IterableElementBase<E, R> {
381
409
 
382
410
 
383
411
 
412
+
413
+
414
+
415
+
416
+
417
+
418
+
384
419
 
385
420
 
386
421
 
@@ -445,6 +480,13 @@ export declare class Stack<E = any, R = any> extends IterableElementBase<E, R> {
445
480
 
446
481
 
447
482
 
483
+
484
+
485
+
486
+
487
+
488
+
489
+
448
490
 
449
491
 
450
492
 
@@ -464,9 +506,9 @@ export declare class Stack<E = any, R = any> extends IterableElementBase<E, R> {
464
506
  * Delete the element at an index.
465
507
  * @remarks Time O(N), Space O(1)
466
508
  * @param index - Zero-based index from the bottom.
467
- * @returns True if removed.
509
+ * @returns The removed element, or undefined if the index is out of range.
468
510
  */
469
- deleteAt(index: number): boolean;
511
+ deleteAt(index: number): E | undefined;
470
512
  /**
471
513
  * Delete the first element that satisfies a predicate.
472
514
  * @remarks Time O(N), Space O(1)
@@ -503,6 +545,13 @@ export declare class Stack<E = any, R = any> extends IterableElementBase<E, R> {
503
545
 
504
546
 
505
547
 
548
+
549
+
550
+
551
+
552
+
553
+
554
+
506
555
 
507
556
 
508
557
 
@@ -547,6 +596,13 @@ export declare class Stack<E = any, R = any> extends IterableElementBase<E, R> {
547
596
 
548
597
 
549
598
 
599
+
600
+
601
+
602
+
603
+
604
+
605
+
550
606
 
551
607
 
552
608
 
@@ -595,6 +651,13 @@ export declare class Stack<E = any, R = any> extends IterableElementBase<E, R> {
595
651
 
596
652
 
597
653
 
654
+
655
+
656
+
657
+
658
+
659
+
660
+
598
661
 
599
662
 
600
663
 
@@ -651,6 +714,13 @@ export declare class Stack<E = any, R = any> extends IterableElementBase<E, R> {
651
714
 
652
715
 
653
716
 
717
+
718
+
719
+
720
+
721
+
722
+
723
+
654
724
 
655
725
 
656
726