max-priority-queue-typed 2.5.3 → 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 (61) hide show
  1. package/dist/cjs/index.cjs +71 -0
  2. package/dist/cjs/index.cjs.map +1 -1
  3. package/dist/cjs-legacy/index.cjs +71 -0
  4. package/dist/cjs-legacy/index.cjs.map +1 -1
  5. package/dist/esm/index.mjs +71 -0
  6. package/dist/esm/index.mjs.map +1 -1
  7. package/dist/esm-legacy/index.mjs +71 -0
  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 +36 -0
  12. package/dist/types/data-structures/binary-tree/binary-indexed-tree.d.ts +42 -0
  13. package/dist/types/data-structures/binary-tree/binary-tree.d.ts +75 -0
  14. package/dist/types/data-structures/binary-tree/bst.d.ts +72 -0
  15. package/dist/types/data-structures/binary-tree/red-black-tree.d.ts +57 -0
  16. package/dist/types/data-structures/binary-tree/segment-tree.d.ts +18 -0
  17. package/dist/types/data-structures/binary-tree/tree-map.d.ts +375 -0
  18. package/dist/types/data-structures/binary-tree/tree-multi-map.d.ts +389 -0
  19. package/dist/types/data-structures/binary-tree/tree-multi-set.d.ts +330 -0
  20. package/dist/types/data-structures/binary-tree/tree-set.d.ts +438 -0
  21. package/dist/types/data-structures/graph/directed-graph.d.ts +30 -0
  22. package/dist/types/data-structures/graph/undirected-graph.d.ts +27 -0
  23. package/dist/types/data-structures/hash/hash-map.d.ts +33 -0
  24. package/dist/types/data-structures/heap/heap.d.ts +42 -0
  25. package/dist/types/data-structures/linked-list/doubly-linked-list.d.ts +75 -2
  26. package/dist/types/data-structures/linked-list/singly-linked-list.d.ts +45 -0
  27. package/dist/types/data-structures/linked-list/skip-linked-list.d.ts +54 -0
  28. package/dist/types/data-structures/matrix/matrix.d.ts +24 -0
  29. package/dist/types/data-structures/queue/deque.d.ts +90 -1
  30. package/dist/types/data-structures/queue/queue.d.ts +36 -0
  31. package/dist/types/data-structures/stack/stack.d.ts +30 -0
  32. package/dist/types/data-structures/trie/trie.d.ts +36 -0
  33. package/dist/umd/max-priority-queue-typed.js +71 -0
  34. package/dist/umd/max-priority-queue-typed.js.map +1 -1
  35. package/dist/umd/max-priority-queue-typed.min.js +1 -1
  36. package/dist/umd/max-priority-queue-typed.min.js.map +1 -1
  37. package/package.json +2 -2
  38. package/src/data-structures/base/iterable-element-base.ts +32 -0
  39. package/src/data-structures/base/linear-base.ts +11 -0
  40. package/src/data-structures/binary-tree/avl-tree.ts +36 -0
  41. package/src/data-structures/binary-tree/binary-indexed-tree.ts +42 -0
  42. package/src/data-structures/binary-tree/binary-tree.ts +75 -0
  43. package/src/data-structures/binary-tree/bst.ts +72 -0
  44. package/src/data-structures/binary-tree/red-black-tree.ts +57 -0
  45. package/src/data-structures/binary-tree/segment-tree.ts +18 -0
  46. package/src/data-structures/binary-tree/tree-map.ts +375 -0
  47. package/src/data-structures/binary-tree/tree-multi-map.ts +392 -0
  48. package/src/data-structures/binary-tree/tree-multi-set.ts +336 -0
  49. package/src/data-structures/binary-tree/tree-set.ts +492 -0
  50. package/src/data-structures/graph/directed-graph.ts +30 -0
  51. package/src/data-structures/graph/undirected-graph.ts +27 -0
  52. package/src/data-structures/hash/hash-map.ts +33 -0
  53. package/src/data-structures/heap/heap.ts +42 -0
  54. package/src/data-structures/linked-list/doubly-linked-list.ts +90 -2
  55. package/src/data-structures/linked-list/singly-linked-list.ts +45 -0
  56. package/src/data-structures/linked-list/skip-linked-list.ts +54 -0
  57. package/src/data-structures/matrix/matrix.ts +24 -0
  58. package/src/data-structures/queue/deque.ts +103 -1
  59. package/src/data-structures/queue/queue.ts +36 -0
  60. package/src/data-structures/stack/stack.ts +30 -0
  61. package/src/data-structures/trie/trie.ts +36 -0
@@ -331,6 +331,9 @@ export class SinglyLinkedList<E = any, R = any> extends LinearLinkedBase<E, R, S
331
331
 
332
332
 
333
333
 
334
+
335
+
336
+
334
337
 
335
338
 
336
339
 
@@ -404,6 +407,9 @@ export class SinglyLinkedList<E = any, R = any> extends LinearLinkedBase<E, R, S
404
407
 
405
408
 
406
409
 
410
+
411
+
412
+
407
413
 
408
414
 
409
415
 
@@ -482,6 +488,9 @@ export class SinglyLinkedList<E = any, R = any> extends LinearLinkedBase<E, R, S
482
488
 
483
489
 
484
490
 
491
+
492
+
493
+
485
494
 
486
495
 
487
496
 
@@ -542,6 +551,9 @@ export class SinglyLinkedList<E = any, R = any> extends LinearLinkedBase<E, R, S
542
551
 
543
552
 
544
553
 
554
+
555
+
556
+
545
557
 
546
558
 
547
559
 
@@ -671,6 +683,9 @@ export class SinglyLinkedList<E = any, R = any> extends LinearLinkedBase<E, R, S
671
683
 
672
684
 
673
685
 
686
+
687
+
688
+
674
689
 
675
690
 
676
691
 
@@ -740,6 +755,9 @@ export class SinglyLinkedList<E = any, R = any> extends LinearLinkedBase<E, R, S
740
755
 
741
756
 
742
757
 
758
+
759
+
760
+
743
761
 
744
762
 
745
763
 
@@ -794,6 +812,9 @@ export class SinglyLinkedList<E = any, R = any> extends LinearLinkedBase<E, R, S
794
812
 
795
813
 
796
814
 
815
+
816
+
817
+
797
818
 
798
819
 
799
820
 
@@ -854,6 +875,9 @@ export class SinglyLinkedList<E = any, R = any> extends LinearLinkedBase<E, R, S
854
875
 
855
876
 
856
877
 
878
+
879
+
880
+
857
881
 
858
882
 
859
883
 
@@ -920,6 +944,9 @@ export class SinglyLinkedList<E = any, R = any> extends LinearLinkedBase<E, R, S
920
944
 
921
945
 
922
946
 
947
+
948
+
949
+
923
950
 
924
951
 
925
952
 
@@ -995,6 +1022,9 @@ export class SinglyLinkedList<E = any, R = any> extends LinearLinkedBase<E, R, S
995
1022
 
996
1023
 
997
1024
 
1025
+
1026
+
1027
+
998
1028
 
999
1029
 
1000
1030
 
@@ -1045,6 +1075,9 @@ export class SinglyLinkedList<E = any, R = any> extends LinearLinkedBase<E, R, S
1045
1075
 
1046
1076
 
1047
1077
 
1078
+
1079
+
1080
+
1048
1081
 
1049
1082
 
1050
1083
 
@@ -1101,6 +1134,9 @@ export class SinglyLinkedList<E = any, R = any> extends LinearLinkedBase<E, R, S
1101
1134
 
1102
1135
 
1103
1136
 
1137
+
1138
+
1139
+
1104
1140
 
1105
1141
 
1106
1142
 
@@ -1351,6 +1387,9 @@ export class SinglyLinkedList<E = any, R = any> extends LinearLinkedBase<E, R, S
1351
1387
 
1352
1388
 
1353
1389
 
1390
+
1391
+
1392
+
1354
1393
 
1355
1394
 
1356
1395
 
@@ -1411,6 +1450,9 @@ export class SinglyLinkedList<E = any, R = any> extends LinearLinkedBase<E, R, S
1411
1450
 
1412
1451
 
1413
1452
 
1453
+
1454
+
1455
+
1414
1456
 
1415
1457
 
1416
1458
 
@@ -1501,6 +1543,9 @@ export class SinglyLinkedList<E = any, R = any> extends LinearLinkedBase<E, R, S
1501
1543
 
1502
1544
 
1503
1545
 
1546
+
1547
+
1548
+
1504
1549
 
1505
1550
 
1506
1551
 
@@ -169,6 +169,9 @@ export class SkipList<K = any, V = any, R = [K, V]> extends IterableEntryBase<K,
169
169
 
170
170
 
171
171
 
172
+
173
+
174
+
172
175
 
173
176
 
174
177
 
@@ -216,6 +219,9 @@ export class SkipList<K = any, V = any, R = [K, V]> extends IterableEntryBase<K,
216
219
 
217
220
 
218
221
 
222
+
223
+
224
+
219
225
 
220
226
 
221
227
 
@@ -266,6 +272,9 @@ export class SkipList<K = any, V = any, R = [K, V]> extends IterableEntryBase<K,
266
272
 
267
273
 
268
274
 
275
+
276
+
277
+
269
278
 
270
279
 
271
280
 
@@ -325,6 +334,9 @@ export class SkipList<K = any, V = any, R = [K, V]> extends IterableEntryBase<K,
325
334
 
326
335
 
327
336
 
337
+
338
+
339
+
328
340
 
329
341
 
330
342
 
@@ -414,6 +426,9 @@ export class SkipList<K = any, V = any, R = [K, V]> extends IterableEntryBase<K,
414
426
 
415
427
 
416
428
 
429
+
430
+
431
+
417
432
 
418
433
 
419
434
 
@@ -482,6 +497,9 @@ export class SkipList<K = any, V = any, R = [K, V]> extends IterableEntryBase<K,
482
497
 
483
498
 
484
499
 
500
+
501
+
502
+
485
503
 
486
504
 
487
505
 
@@ -533,6 +551,9 @@ export class SkipList<K = any, V = any, R = [K, V]> extends IterableEntryBase<K,
533
551
 
534
552
 
535
553
 
554
+
555
+
556
+
536
557
 
537
558
 
538
559
 
@@ -609,6 +630,9 @@ export class SkipList<K = any, V = any, R = [K, V]> extends IterableEntryBase<K,
609
630
 
610
631
 
611
632
 
633
+
634
+
635
+
612
636
 
613
637
 
614
638
 
@@ -660,6 +684,9 @@ export class SkipList<K = any, V = any, R = [K, V]> extends IterableEntryBase<K,
660
684
 
661
685
 
662
686
 
687
+
688
+
689
+
663
690
 
664
691
 
665
692
 
@@ -713,6 +740,9 @@ export class SkipList<K = any, V = any, R = [K, V]> extends IterableEntryBase<K,
713
740
 
714
741
 
715
742
 
743
+
744
+
745
+
716
746
 
717
747
 
718
748
 
@@ -764,6 +794,9 @@ export class SkipList<K = any, V = any, R = [K, V]> extends IterableEntryBase<K,
764
794
 
765
795
 
766
796
 
797
+
798
+
799
+
767
800
 
768
801
 
769
802
 
@@ -818,6 +851,9 @@ export class SkipList<K = any, V = any, R = [K, V]> extends IterableEntryBase<K,
818
851
 
819
852
 
820
853
 
854
+
855
+
856
+
821
857
 
822
858
 
823
859
 
@@ -877,6 +913,9 @@ export class SkipList<K = any, V = any, R = [K, V]> extends IterableEntryBase<K,
877
913
 
878
914
 
879
915
 
916
+
917
+
918
+
880
919
 
881
920
 
882
921
 
@@ -936,6 +975,9 @@ export class SkipList<K = any, V = any, R = [K, V]> extends IterableEntryBase<K,
936
975
 
937
976
 
938
977
 
978
+
979
+
980
+
939
981
 
940
982
 
941
983
 
@@ -992,6 +1034,9 @@ export class SkipList<K = any, V = any, R = [K, V]> extends IterableEntryBase<K,
992
1034
 
993
1035
 
994
1036
 
1037
+
1038
+
1039
+
995
1040
 
996
1041
 
997
1042
 
@@ -1054,6 +1099,9 @@ export class SkipList<K = any, V = any, R = [K, V]> extends IterableEntryBase<K,
1054
1099
 
1055
1100
 
1056
1101
 
1102
+
1103
+
1104
+
1057
1105
 
1058
1106
 
1059
1107
 
@@ -1131,6 +1179,9 @@ export class SkipList<K = any, V = any, R = [K, V]> extends IterableEntryBase<K,
1131
1179
 
1132
1180
 
1133
1181
 
1182
+
1183
+
1184
+
1134
1185
 
1135
1186
 
1136
1187
 
@@ -1188,6 +1239,9 @@ export class SkipList<K = any, V = any, R = [K, V]> extends IterableEntryBase<K,
1188
1239
 
1189
1240
 
1190
1241
 
1242
+
1243
+
1244
+
1191
1245
 
1192
1246
 
1193
1247
 
@@ -224,6 +224,9 @@ export class Matrix {
224
224
 
225
225
 
226
226
 
227
+
228
+
229
+
227
230
 
228
231
 
229
232
 
@@ -297,6 +300,9 @@ export class Matrix {
297
300
 
298
301
 
299
302
 
303
+
304
+
305
+
300
306
 
301
307
 
302
308
 
@@ -367,6 +373,9 @@ export class Matrix {
367
373
 
368
374
 
369
375
 
376
+
377
+
378
+
370
379
 
371
380
 
372
381
 
@@ -461,6 +470,9 @@ export class Matrix {
461
470
 
462
471
 
463
472
 
473
+
474
+
475
+
464
476
 
465
477
 
466
478
 
@@ -538,6 +550,9 @@ export class Matrix {
538
550
 
539
551
 
540
552
 
553
+
554
+
555
+
541
556
 
542
557
 
543
558
 
@@ -637,6 +652,9 @@ export class Matrix {
637
652
 
638
653
 
639
654
 
655
+
656
+
657
+
640
658
 
641
659
 
642
660
 
@@ -723,6 +741,9 @@ export class Matrix {
723
741
 
724
742
 
725
743
 
744
+
745
+
746
+
726
747
 
727
748
 
728
749
 
@@ -853,6 +874,9 @@ export class Matrix {
853
874
 
854
875
 
855
876
 
877
+
878
+
879
+
856
880
 
857
881
 
858
882
 
@@ -314,7 +314,10 @@ export class Deque<E = any, R = any> extends LinearBase<E, R> {
314
314
 
315
315
  /**
316
316
  * Deque peek at both ends
317
- * @example
317
+
318
+
319
+
320
+ * @example
318
321
  * // Deque peek at both ends
319
322
  * const deque = new Deque<number>([10, 20, 30, 40, 50]);
320
323
  *
@@ -373,6 +376,9 @@ export class Deque<E = any, R = any> extends LinearBase<E, R> {
373
376
 
374
377
 
375
378
 
379
+
380
+
381
+
376
382
 
377
383
 
378
384
 
@@ -451,6 +457,9 @@ export class Deque<E = any, R = any> extends LinearBase<E, R> {
451
457
 
452
458
 
453
459
 
460
+
461
+
462
+
454
463
 
455
464
 
456
465
 
@@ -533,6 +542,9 @@ export class Deque<E = any, R = any> extends LinearBase<E, R> {
533
542
 
534
543
 
535
544
 
545
+
546
+
547
+
536
548
 
537
549
 
538
550
 
@@ -602,6 +614,9 @@ export class Deque<E = any, R = any> extends LinearBase<E, R> {
602
614
 
603
615
 
604
616
 
617
+
618
+
619
+
605
620
 
606
621
 
607
622
 
@@ -672,6 +687,9 @@ export class Deque<E = any, R = any> extends LinearBase<E, R> {
672
687
 
673
688
 
674
689
 
690
+
691
+
692
+
675
693
 
676
694
 
677
695
 
@@ -787,6 +805,9 @@ export class Deque<E = any, R = any> extends LinearBase<E, R> {
787
805
 
788
806
 
789
807
 
808
+
809
+
810
+
790
811
 
791
812
 
792
813
 
@@ -838,6 +859,9 @@ export class Deque<E = any, R = any> extends LinearBase<E, R> {
838
859
 
839
860
 
840
861
 
862
+
863
+
864
+
841
865
 
842
866
 
843
867
 
@@ -893,6 +917,9 @@ export class Deque<E = any, R = any> extends LinearBase<E, R> {
893
917
 
894
918
 
895
919
 
920
+
921
+
922
+
896
923
 
897
924
 
898
925
 
@@ -1121,6 +1148,9 @@ export class Deque<E = any, R = any> extends LinearBase<E, R> {
1121
1148
 
1122
1149
 
1123
1150
 
1151
+
1152
+
1153
+
1124
1154
 
1125
1155
 
1126
1156
 
@@ -1242,6 +1272,66 @@ export class Deque<E = any, R = any> extends LinearBase<E, R> {
1242
1272
  * console.log(backward); // ['D', 'C', 'B', 'A'];
1243
1273
  */
1244
1274
 
1275
+ /**
1276
+ * Find the last value matching a predicate (scans back-to-front).
1277
+ * @remarks Provided for familiarity when migrating from Array. Time O(n), Space O(1).
1278
+ * @param predicate - Function called with (value, index, deque).
1279
+ * @returns Matching value or undefined.
1280
+ * @example
1281
+ * // Find last matching value
1282
+ * const d = new Deque([1, 2, 3, 4, 5]);
1283
+ * console.log(d.findLast(v => v > 2)); // 5;
1284
+ * console.log(d.findLast(v => v % 2 === 0)); // 4;
1285
+ */
1286
+ findLast(predicate: (value: E, index: number, deque: this) => boolean): E | undefined {
1287
+ for (let i = this.length - 1; i >= 0; i--) {
1288
+ const val = this.at(i)!;
1289
+ if (predicate(val, i, this)) return val;
1290
+ }
1291
+ return undefined;
1292
+ }
1293
+
1294
+ /**
1295
+ * Find the index of the last value matching a predicate (scans back-to-front).
1296
+ * @remarks Provided for familiarity when migrating from Array. Time O(n), Space O(1).
1297
+ * @param predicate - Function called with (value, index, deque).
1298
+ * @returns Matching index, or -1 if not found.
1299
+ * @example
1300
+ * // Find last matching index
1301
+ * const d = new Deque([10, 20, 30, 20, 10]);
1302
+ * console.log(d.findLastIndex(v => v === 20)); // 3;
1303
+ * console.log(d.findLastIndex(v => v === 10)); // 4;
1304
+ */
1305
+ findLastIndex(predicate: (value: E, index: number, deque: this) => boolean): number {
1306
+ for (let i = this.length - 1; i >= 0; i--) {
1307
+ if (predicate(this.at(i)!, i, this)) return i;
1308
+ }
1309
+ return -1;
1310
+ }
1311
+
1312
+ /**
1313
+ * Deque for...of iteration and reverse
1314
+
1315
+
1316
+ * @example
1317
+ * // Deque for...of iteration and reverse
1318
+ * const deque = new Deque<string>(['A', 'B', 'C', 'D']);
1319
+ *
1320
+ * // Iterate forward
1321
+ * const forward: string[] = [];
1322
+ * for (const item of deque) {
1323
+ * forward.push(item);
1324
+ * }
1325
+ * console.log(forward); // ['A', 'B', 'C', 'D'];
1326
+ *
1327
+ * // Reverse the deque
1328
+ * deque.reverse();
1329
+ * const backward: string[] = [];
1330
+ * for (const item of deque) {
1331
+ * backward.push(item);
1332
+ * }
1333
+ * console.log(backward); // ['D', 'C', 'B', 'A'];
1334
+ */
1245
1335
  reverse(): this {
1246
1336
  this._buckets.reverse().forEach(function (bucket) {
1247
1337
  bucket.reverse();
@@ -1342,6 +1432,9 @@ export class Deque<E = any, R = any> extends LinearBase<E, R> {
1342
1432
 
1343
1433
 
1344
1434
 
1435
+
1436
+
1437
+
1345
1438
 
1346
1439
 
1347
1440
 
@@ -1419,6 +1512,9 @@ export class Deque<E = any, R = any> extends LinearBase<E, R> {
1419
1512
 
1420
1513
 
1421
1514
 
1515
+
1516
+
1517
+
1422
1518
 
1423
1519
 
1424
1520
 
@@ -1479,6 +1575,9 @@ export class Deque<E = any, R = any> extends LinearBase<E, R> {
1479
1575
 
1480
1576
 
1481
1577
 
1578
+
1579
+
1580
+
1482
1581
 
1483
1582
 
1484
1583
 
@@ -1561,6 +1660,9 @@ export class Deque<E = any, R = any> extends LinearBase<E, R> {
1561
1660
 
1562
1661
 
1563
1662
 
1663
+
1664
+
1665
+
1564
1666
 
1565
1667
 
1566
1668
 
@@ -192,6 +192,9 @@ export class Queue<E = any, R = any> extends LinearBase<E, R> {
192
192
 
193
193
 
194
194
 
195
+
196
+
197
+
195
198
 
196
199
 
197
200
 
@@ -248,6 +251,9 @@ export class Queue<E = any, R = any> extends LinearBase<E, R> {
248
251
 
249
252
 
250
253
 
254
+
255
+
256
+
251
257
 
252
258
 
253
259
 
@@ -333,6 +339,9 @@ export class Queue<E = any, R = any> extends LinearBase<E, R> {
333
339
 
334
340
 
335
341
 
342
+
343
+
344
+
336
345
 
337
346
 
338
347
 
@@ -401,6 +410,9 @@ export class Queue<E = any, R = any> extends LinearBase<E, R> {
401
410
 
402
411
 
403
412
 
413
+
414
+
415
+
404
416
 
405
417
 
406
418
 
@@ -478,6 +490,9 @@ export class Queue<E = any, R = any> extends LinearBase<E, R> {
478
490
 
479
491
 
480
492
 
493
+
494
+
495
+
481
496
 
482
497
 
483
498
 
@@ -543,6 +558,9 @@ export class Queue<E = any, R = any> extends LinearBase<E, R> {
543
558
 
544
559
 
545
560
 
561
+
562
+
563
+
546
564
 
547
565
 
548
566
 
@@ -601,6 +619,9 @@ export class Queue<E = any, R = any> extends LinearBase<E, R> {
601
619
 
602
620
 
603
621
 
622
+
623
+
624
+
604
625
 
605
626
 
606
627
 
@@ -724,6 +745,9 @@ export class Queue<E = any, R = any> extends LinearBase<E, R> {
724
745
 
725
746
 
726
747
 
748
+
749
+
750
+
727
751
 
728
752
 
729
753
 
@@ -776,6 +800,9 @@ export class Queue<E = any, R = any> extends LinearBase<E, R> {
776
800
 
777
801
 
778
802
 
803
+
804
+
805
+
779
806
 
780
807
 
781
808
 
@@ -857,6 +884,9 @@ export class Queue<E = any, R = any> extends LinearBase<E, R> {
857
884
 
858
885
 
859
886
 
887
+
888
+
889
+
860
890
 
861
891
 
862
892
 
@@ -916,6 +946,9 @@ export class Queue<E = any, R = any> extends LinearBase<E, R> {
916
946
 
917
947
 
918
948
 
949
+
950
+
951
+
919
952
 
920
953
 
921
954
 
@@ -979,6 +1012,9 @@ export class Queue<E = any, R = any> extends LinearBase<E, R> {
979
1012
 
980
1013
 
981
1014
 
1015
+
1016
+
1017
+
982
1018
 
983
1019
 
984
1020