max-priority-queue-typed 2.5.1 → 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 (75) hide show
  1. package/dist/cjs/index.cjs +207 -71
  2. package/dist/cjs/index.cjs.map +1 -1
  3. package/dist/cjs-legacy/index.cjs +206 -70
  4. package/dist/cjs-legacy/index.cjs.map +1 -1
  5. package/dist/esm/index.mjs +207 -72
  6. package/dist/esm/index.mjs.map +1 -1
  7. package/dist/esm-legacy/index.mjs +206 -71
  8. package/dist/esm-legacy/index.mjs.map +1 -1
  9. package/dist/types/common/error.d.ts +9 -0
  10. package/dist/types/common/index.d.ts +1 -1
  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 +189 -13
  14. package/dist/types/data-structures/binary-tree/bst.d.ts +270 -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 +1089 -161
  18. package/dist/types/data-structures/binary-tree/tree-multi-map.d.ts +1243 -350
  19. package/dist/types/data-structures/binary-tree/tree-multi-set.d.ts +980 -255
  20. package/dist/types/data-structures/binary-tree/tree-set.d.ts +1174 -284
  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 +126 -0
  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 +127 -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/types/types/data-structures/binary-tree/bst.d.ts +1 -0
  35. package/dist/types/types/data-structures/binary-tree/tree-map.d.ts +5 -0
  36. package/dist/types/types/data-structures/binary-tree/tree-multi-set.d.ts +4 -0
  37. package/dist/types/types/data-structures/binary-tree/tree-set.d.ts +4 -0
  38. package/dist/umd/max-priority-queue-typed.js +204 -69
  39. package/dist/umd/max-priority-queue-typed.js.map +1 -1
  40. package/dist/umd/max-priority-queue-typed.min.js +1 -1
  41. package/dist/umd/max-priority-queue-typed.min.js.map +1 -1
  42. package/package.json +2 -2
  43. package/src/common/error.ts +19 -1
  44. package/src/common/index.ts +1 -1
  45. package/src/data-structures/base/iterable-element-base.ts +3 -2
  46. package/src/data-structures/binary-tree/avl-tree.ts +99 -5
  47. package/src/data-structures/binary-tree/binary-indexed-tree.ts +102 -4
  48. package/src/data-structures/binary-tree/binary-tree.ts +239 -78
  49. package/src/data-structures/binary-tree/bst.ts +542 -13
  50. package/src/data-structures/binary-tree/red-black-tree.ts +155 -15
  51. package/src/data-structures/binary-tree/segment-tree.ts +42 -0
  52. package/src/data-structures/binary-tree/tree-map.ts +1223 -261
  53. package/src/data-structures/binary-tree/tree-multi-map.ts +939 -30
  54. package/src/data-structures/binary-tree/tree-multi-set.ts +746 -10
  55. package/src/data-structures/binary-tree/tree-set.ts +1018 -99
  56. package/src/data-structures/graph/abstract-graph.ts +2 -2
  57. package/src/data-structures/graph/directed-graph.ts +71 -1
  58. package/src/data-structures/graph/undirected-graph.ts +64 -1
  59. package/src/data-structures/hash/hash-map.ts +102 -16
  60. package/src/data-structures/heap/heap.ts +153 -23
  61. package/src/data-structures/heap/max-heap.ts +2 -2
  62. package/src/data-structures/linked-list/doubly-linked-list.ts +139 -0
  63. package/src/data-structures/linked-list/singly-linked-list.ts +106 -1
  64. package/src/data-structures/linked-list/skip-linked-list.ts +131 -5
  65. package/src/data-structures/matrix/matrix.ts +65 -9
  66. package/src/data-structures/priority-queue/max-priority-queue.ts +2 -2
  67. package/src/data-structures/queue/deque.ts +130 -0
  68. package/src/data-structures/queue/queue.ts +109 -0
  69. package/src/data-structures/stack/stack.ts +75 -5
  70. package/src/data-structures/trie/trie.ts +86 -2
  71. package/src/interfaces/binary-tree.ts +1 -9
  72. package/src/types/data-structures/binary-tree/bst.ts +1 -0
  73. package/src/types/data-structures/binary-tree/tree-map.ts +6 -0
  74. package/src/types/data-structures/binary-tree/tree-multi-set.ts +5 -0
  75. package/src/types/data-structures/binary-tree/tree-set.ts +5 -0
@@ -274,6 +274,12 @@ export class Deque<E = any, R = any> extends LinearBase<E, R> {
274
274
 
275
275
 
276
276
 
277
+
278
+
279
+
280
+
281
+
282
+
277
283
 
278
284
 
279
285
 
@@ -297,6 +303,32 @@ export class Deque<E = any, R = any> extends LinearBase<E, R> {
297
303
  * console.log(deque.length); // 5;
298
304
  */
299
305
 
306
+ /**
307
+ * Peek at the front element without removing it (alias for `first`).
308
+ * @remarks Time O(1), Space O(1)
309
+ * @returns Front element or undefined.
310
+ */
311
+ peek(): E | undefined {
312
+ return this.first;
313
+ }
314
+
315
+ /**
316
+ * Deque peek at both ends
317
+ * @example
318
+ * // Deque peek at both ends
319
+ * const deque = new Deque<number>([10, 20, 30, 40, 50]);
320
+ *
321
+ * // Get first element without removing
322
+ * const first = deque.at(0);
323
+ * console.log(first); // 10;
324
+ *
325
+ * // Get last element without removing
326
+ * const last = deque.at(deque.length - 1);
327
+ * console.log(last); // 50;
328
+ *
329
+ * // Length unchanged
330
+ * console.log(deque.length); // 5;
331
+ */
300
332
  get first(): E | undefined {
301
333
  if (this._length === 0) return;
302
334
  return this._buckets[this._bucketFirst][this._firstInBucket];
@@ -330,6 +362,13 @@ export class Deque<E = any, R = any> extends LinearBase<E, R> {
330
362
 
331
363
 
332
364
 
365
+
366
+
367
+
368
+
369
+
370
+
371
+
333
372
 
334
373
 
335
374
 
@@ -401,6 +440,13 @@ export class Deque<E = any, R = any> extends LinearBase<E, R> {
401
440
 
402
441
 
403
442
 
443
+
444
+
445
+
446
+
447
+
448
+
449
+
404
450
 
405
451
 
406
452
 
@@ -476,6 +522,13 @@ export class Deque<E = any, R = any> extends LinearBase<E, R> {
476
522
 
477
523
 
478
524
 
525
+
526
+
527
+
528
+
529
+
530
+
531
+
479
532
 
480
533
 
481
534
 
@@ -538,6 +591,13 @@ export class Deque<E = any, R = any> extends LinearBase<E, R> {
538
591
 
539
592
 
540
593
 
594
+
595
+
596
+
597
+
598
+
599
+
600
+
541
601
 
542
602
 
543
603
 
@@ -601,6 +661,13 @@ export class Deque<E = any, R = any> extends LinearBase<E, R> {
601
661
 
602
662
 
603
663
 
664
+
665
+
666
+
667
+
668
+
669
+
670
+
604
671
 
605
672
 
606
673
 
@@ -709,6 +776,13 @@ export class Deque<E = any, R = any> extends LinearBase<E, R> {
709
776
 
710
777
 
711
778
 
779
+
780
+
781
+
782
+
783
+
784
+
785
+
712
786
 
713
787
 
714
788
 
@@ -753,6 +827,13 @@ export class Deque<E = any, R = any> extends LinearBase<E, R> {
753
827
 
754
828
 
755
829
 
830
+
831
+
832
+
833
+
834
+
835
+
836
+
756
837
 
757
838
 
758
839
 
@@ -801,6 +882,13 @@ export class Deque<E = any, R = any> extends LinearBase<E, R> {
801
882
 
802
883
 
803
884
 
885
+
886
+
887
+
888
+
889
+
890
+
891
+
804
892
 
805
893
 
806
894
 
@@ -1022,6 +1110,13 @@ export class Deque<E = any, R = any> extends LinearBase<E, R> {
1022
1110
 
1023
1111
 
1024
1112
 
1113
+
1114
+
1115
+
1116
+
1117
+
1118
+
1119
+
1025
1120
 
1026
1121
 
1027
1122
 
@@ -1112,6 +1207,13 @@ export class Deque<E = any, R = any> extends LinearBase<E, R> {
1112
1207
 
1113
1208
 
1114
1209
 
1210
+
1211
+
1212
+
1213
+
1214
+
1215
+
1216
+
1115
1217
 
1116
1218
 
1117
1219
 
@@ -1229,6 +1331,13 @@ export class Deque<E = any, R = any> extends LinearBase<E, R> {
1229
1331
 
1230
1332
 
1231
1333
 
1334
+
1335
+
1336
+
1337
+
1338
+
1339
+
1340
+
1232
1341
 
1233
1342
 
1234
1343
 
@@ -1299,6 +1408,13 @@ export class Deque<E = any, R = any> extends LinearBase<E, R> {
1299
1408
 
1300
1409
 
1301
1410
 
1411
+
1412
+
1413
+
1414
+
1415
+
1416
+
1417
+
1302
1418
 
1303
1419
 
1304
1420
 
@@ -1352,6 +1468,13 @@ export class Deque<E = any, R = any> extends LinearBase<E, R> {
1352
1468
 
1353
1469
 
1354
1470
 
1471
+
1472
+
1473
+
1474
+
1475
+
1476
+
1477
+
1355
1478
 
1356
1479
 
1357
1480
 
@@ -1427,6 +1550,13 @@ export class Deque<E = any, R = any> extends LinearBase<E, R> {
1427
1550
 
1428
1551
 
1429
1552
 
1553
+
1554
+
1555
+
1556
+
1557
+
1558
+
1559
+
1430
1560
 
1431
1561
 
1432
1562
 
@@ -181,6 +181,13 @@ export class Queue<E = any, R = any> extends LinearBase<E, R> {
181
181
 
182
182
 
183
183
 
184
+
185
+
186
+
187
+
188
+
189
+
190
+
184
191
 
185
192
 
186
193
 
@@ -230,6 +237,13 @@ export class Queue<E = any, R = any> extends LinearBase<E, R> {
230
237
 
231
238
 
232
239
 
240
+
241
+
242
+
243
+
244
+
245
+
246
+
233
247
 
234
248
 
235
249
 
@@ -249,6 +263,15 @@ export class Queue<E = any, R = any> extends LinearBase<E, R> {
249
263
  return this.length > 0 ? this.elements[this._offset] : undefined;
250
264
  }
251
265
 
266
+ /**
267
+ * Peek at the front element without removing it (alias for `first`).
268
+ * @remarks Time O(1), Space O(1)
269
+ * @returns Front element or undefined.
270
+ */
271
+ peek(): E | undefined {
272
+ return this.first;
273
+ }
274
+
252
275
  /**
253
276
  * Get the last element (back) without removing it.
254
277
  * @remarks Time O(1), Space O(1)
@@ -299,6 +322,13 @@ export class Queue<E = any, R = any> extends LinearBase<E, R> {
299
322
 
300
323
 
301
324
 
325
+
326
+
327
+
328
+
329
+
330
+
331
+
302
332
 
303
333
 
304
334
 
@@ -360,6 +390,13 @@ export class Queue<E = any, R = any> extends LinearBase<E, R> {
360
390
 
361
391
 
362
392
 
393
+
394
+
395
+
396
+
397
+
398
+
399
+
363
400
 
364
401
 
365
402
 
@@ -430,6 +467,13 @@ export class Queue<E = any, R = any> extends LinearBase<E, R> {
430
467
 
431
468
 
432
469
 
470
+
471
+
472
+
473
+
474
+
475
+
476
+
433
477
 
434
478
 
435
479
 
@@ -488,6 +532,13 @@ export class Queue<E = any, R = any> extends LinearBase<E, R> {
488
532
 
489
533
 
490
534
 
535
+
536
+
537
+
538
+
539
+
540
+
541
+
491
542
 
492
543
 
493
544
 
@@ -539,6 +590,13 @@ export class Queue<E = any, R = any> extends LinearBase<E, R> {
539
590
 
540
591
 
541
592
 
593
+
594
+
595
+
596
+
597
+
598
+
599
+
542
600
 
543
601
 
544
602
 
@@ -601,6 +659,22 @@ export class Queue<E = any, R = any> extends LinearBase<E, R> {
601
659
  return true;
602
660
  }
603
661
 
662
+ /**
663
+ * Delete the first element that satisfies a predicate.
664
+ * @remarks Time O(N), Space O(N)
665
+ * @param predicate - Function (value, index, queue) → boolean to decide deletion.
666
+ * @returns True if a match was removed.
667
+ */
668
+ deleteWhere(predicate: (value: E, index: number, queue: this) => boolean): boolean {
669
+ for (let i = 0; i < this.length; i++) {
670
+ if (predicate(this._elements[this._offset + i], i, this)) {
671
+ this.deleteAt(i);
672
+ return true;
673
+ }
674
+ }
675
+ return false;
676
+ }
677
+
604
678
  /**
605
679
  * Reverse the queue in-place by compacting then reversing.
606
680
  * @remarks Time O(N), Space O(N)
@@ -639,6 +713,13 @@ export class Queue<E = any, R = any> extends LinearBase<E, R> {
639
713
 
640
714
 
641
715
 
716
+
717
+
718
+
719
+
720
+
721
+
722
+
642
723
 
643
724
 
644
725
 
@@ -684,6 +765,13 @@ export class Queue<E = any, R = any> extends LinearBase<E, R> {
684
765
 
685
766
 
686
767
 
768
+
769
+
770
+
771
+
772
+
773
+
774
+
687
775
 
688
776
 
689
777
 
@@ -758,6 +846,13 @@ export class Queue<E = any, R = any> extends LinearBase<E, R> {
758
846
 
759
847
 
760
848
 
849
+
850
+
851
+
852
+
853
+
854
+
855
+
761
856
 
762
857
 
763
858
 
@@ -810,6 +905,13 @@ export class Queue<E = any, R = any> extends LinearBase<E, R> {
810
905
 
811
906
 
812
907
 
908
+
909
+
910
+
911
+
912
+
913
+
914
+
813
915
 
814
916
 
815
917
 
@@ -866,6 +968,13 @@ export class Queue<E = any, R = any> extends LinearBase<E, R> {
866
968
 
867
969
 
868
970
 
971
+
972
+
973
+
974
+
975
+
976
+
977
+
869
978
 
870
979
 
871
980
 
@@ -186,6 +186,13 @@ export class Stack<E = any, R = any> extends IterableElementBase<E, R> {
186
186
 
187
187
 
188
188
 
189
+
190
+
191
+
192
+
193
+
194
+
195
+
189
196
 
190
197
 
191
198
 
@@ -251,6 +258,13 @@ export class Stack<E = any, R = any> extends IterableElementBase<E, R> {
251
258
 
252
259
 
253
260
 
261
+
262
+
263
+
264
+
265
+
266
+
267
+
254
268
 
255
269
 
256
270
 
@@ -299,6 +313,13 @@ export class Stack<E = any, R = any> extends IterableElementBase<E, R> {
299
313
 
300
314
 
301
315
 
316
+
317
+
318
+
319
+
320
+
321
+
322
+
302
323
 
303
324
 
304
325
 
@@ -347,6 +368,13 @@ export class Stack<E = any, R = any> extends IterableElementBase<E, R> {
347
368
 
348
369
 
349
370
 
371
+
372
+
373
+
374
+
375
+
376
+
377
+
350
378
 
351
379
 
352
380
 
@@ -404,6 +432,13 @@ export class Stack<E = any, R = any> extends IterableElementBase<E, R> {
404
432
 
405
433
 
406
434
 
435
+
436
+
437
+
438
+
439
+
440
+
441
+
407
442
 
408
443
 
409
444
 
@@ -478,6 +513,13 @@ export class Stack<E = any, R = any> extends IterableElementBase<E, R> {
478
513
 
479
514
 
480
515
 
516
+
517
+
518
+
519
+
520
+
521
+
522
+
481
523
 
482
524
 
483
525
 
@@ -495,20 +537,20 @@ export class Stack<E = any, R = any> extends IterableElementBase<E, R> {
495
537
 
496
538
  delete(element: E): boolean {
497
539
  const idx = this._indexOfByEquals(element);
498
- return this.deleteAt(idx);
540
+ return this.deleteAt(idx) !== undefined;
499
541
  }
500
542
 
501
543
  /**
502
544
  * Delete the element at an index.
503
545
  * @remarks Time O(N), Space O(1)
504
546
  * @param index - Zero-based index from the bottom.
505
- * @returns True if removed.
547
+ * @returns The removed element, or undefined if the index is out of range.
506
548
  */
507
549
 
508
- deleteAt(index: number): boolean {
509
- if (index < 0 || index >= this.elements.length) return false;
550
+ deleteAt(index: number): E | undefined {
551
+ if (index < 0 || index >= this.elements.length) return undefined;
510
552
  const spliced = this.elements.splice(index, 1);
511
- return spliced.length === 1;
553
+ return spliced[0];
512
554
  }
513
555
 
514
556
  /**
@@ -554,6 +596,13 @@ export class Stack<E = any, R = any> extends IterableElementBase<E, R> {
554
596
 
555
597
 
556
598
 
599
+
600
+
601
+
602
+
603
+
604
+
605
+
557
606
 
558
607
 
559
608
 
@@ -599,6 +648,13 @@ export class Stack<E = any, R = any> extends IterableElementBase<E, R> {
599
648
 
600
649
 
601
650
 
651
+
652
+
653
+
654
+
655
+
656
+
657
+
602
658
 
603
659
 
604
660
 
@@ -650,6 +706,13 @@ export class Stack<E = any, R = any> extends IterableElementBase<E, R> {
650
706
 
651
707
 
652
708
 
709
+
710
+
711
+
712
+
713
+
714
+
715
+
653
716
 
654
717
 
655
718
 
@@ -723,6 +786,13 @@ export class Stack<E = any, R = any> extends IterableElementBase<E, R> {
723
786
 
724
787
 
725
788
 
789
+
790
+
791
+
792
+
793
+
794
+
795
+
726
796
 
727
797
 
728
798