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
@@ -280,6 +280,9 @@ export class Deque<E = any, R = any> extends LinearBase<E, R> {
280
280
 
281
281
 
282
282
 
283
+
284
+
285
+
283
286
 
284
287
 
285
288
 
@@ -300,6 +303,32 @@ export class Deque<E = any, R = any> extends LinearBase<E, R> {
300
303
  * console.log(deque.length); // 5;
301
304
  */
302
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
+ */
303
332
  get first(): E | undefined {
304
333
  if (this._length === 0) return;
305
334
  return this._buckets[this._bucketFirst][this._firstInBucket];
@@ -339,6 +368,10 @@ export class Deque<E = any, R = any> extends LinearBase<E, R> {
339
368
 
340
369
 
341
370
 
371
+
372
+
373
+
374
+
342
375
 
343
376
 
344
377
 
@@ -413,6 +446,10 @@ export class Deque<E = any, R = any> extends LinearBase<E, R> {
413
446
 
414
447
 
415
448
 
449
+
450
+
451
+
452
+
416
453
 
417
454
 
418
455
 
@@ -491,6 +528,10 @@ export class Deque<E = any, R = any> extends LinearBase<E, R> {
491
528
 
492
529
 
493
530
 
531
+
532
+
533
+
534
+
494
535
 
495
536
 
496
537
 
@@ -556,6 +597,10 @@ export class Deque<E = any, R = any> extends LinearBase<E, R> {
556
597
 
557
598
 
558
599
 
600
+
601
+
602
+
603
+
559
604
 
560
605
 
561
606
 
@@ -622,6 +667,10 @@ export class Deque<E = any, R = any> extends LinearBase<E, R> {
622
667
 
623
668
 
624
669
 
670
+
671
+
672
+
673
+
625
674
 
626
675
 
627
676
 
@@ -733,6 +782,10 @@ export class Deque<E = any, R = any> extends LinearBase<E, R> {
733
782
 
734
783
 
735
784
 
785
+
786
+
787
+
788
+
736
789
 
737
790
 
738
791
 
@@ -780,6 +833,10 @@ export class Deque<E = any, R = any> extends LinearBase<E, R> {
780
833
 
781
834
 
782
835
 
836
+
837
+
838
+
839
+
783
840
 
784
841
 
785
842
 
@@ -831,6 +888,10 @@ export class Deque<E = any, R = any> extends LinearBase<E, R> {
831
888
 
832
889
 
833
890
 
891
+
892
+
893
+
894
+
834
895
 
835
896
 
836
897
 
@@ -1055,6 +1116,10 @@ export class Deque<E = any, R = any> extends LinearBase<E, R> {
1055
1116
 
1056
1117
 
1057
1118
 
1119
+
1120
+
1121
+
1122
+
1058
1123
 
1059
1124
 
1060
1125
 
@@ -1148,6 +1213,10 @@ export class Deque<E = any, R = any> extends LinearBase<E, R> {
1148
1213
 
1149
1214
 
1150
1215
 
1216
+
1217
+
1218
+
1219
+
1151
1220
 
1152
1221
 
1153
1222
 
@@ -1268,6 +1337,10 @@ export class Deque<E = any, R = any> extends LinearBase<E, R> {
1268
1337
 
1269
1338
 
1270
1339
 
1340
+
1341
+
1342
+
1343
+
1271
1344
 
1272
1345
 
1273
1346
 
@@ -1341,6 +1414,10 @@ export class Deque<E = any, R = any> extends LinearBase<E, R> {
1341
1414
 
1342
1415
 
1343
1416
 
1417
+
1418
+
1419
+
1420
+
1344
1421
 
1345
1422
 
1346
1423
 
@@ -1397,6 +1474,10 @@ export class Deque<E = any, R = any> extends LinearBase<E, R> {
1397
1474
 
1398
1475
 
1399
1476
 
1477
+
1478
+
1479
+
1480
+
1400
1481
 
1401
1482
 
1402
1483
 
@@ -1475,6 +1556,10 @@ export class Deque<E = any, R = any> extends LinearBase<E, R> {
1475
1556
 
1476
1557
 
1477
1558
 
1559
+
1560
+
1561
+
1562
+
1478
1563
 
1479
1564
 
1480
1565
 
@@ -187,6 +187,10 @@ export class Queue<E = any, R = any> extends LinearBase<E, R> {
187
187
 
188
188
 
189
189
 
190
+
191
+
192
+
193
+
190
194
 
191
195
 
192
196
 
@@ -239,6 +243,10 @@ export class Queue<E = any, R = any> extends LinearBase<E, R> {
239
243
 
240
244
 
241
245
 
246
+
247
+
248
+
249
+
242
250
 
243
251
 
244
252
 
@@ -255,6 +263,15 @@ export class Queue<E = any, R = any> extends LinearBase<E, R> {
255
263
  return this.length > 0 ? this.elements[this._offset] : undefined;
256
264
  }
257
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
+
258
275
  /**
259
276
  * Get the last element (back) without removing it.
260
277
  * @remarks Time O(1), Space O(1)
@@ -311,6 +328,10 @@ export class Queue<E = any, R = any> extends LinearBase<E, R> {
311
328
 
312
329
 
313
330
 
331
+
332
+
333
+
334
+
314
335
 
315
336
 
316
337
 
@@ -375,6 +396,10 @@ export class Queue<E = any, R = any> extends LinearBase<E, R> {
375
396
 
376
397
 
377
398
 
399
+
400
+
401
+
402
+
378
403
 
379
404
 
380
405
 
@@ -448,6 +473,10 @@ export class Queue<E = any, R = any> extends LinearBase<E, R> {
448
473
 
449
474
 
450
475
 
476
+
477
+
478
+
479
+
451
480
 
452
481
 
453
482
 
@@ -509,6 +538,10 @@ export class Queue<E = any, R = any> extends LinearBase<E, R> {
509
538
 
510
539
 
511
540
 
541
+
542
+
543
+
544
+
512
545
 
513
546
 
514
547
 
@@ -563,6 +596,10 @@ export class Queue<E = any, R = any> extends LinearBase<E, R> {
563
596
 
564
597
 
565
598
 
599
+
600
+
601
+
602
+
566
603
 
567
604
 
568
605
 
@@ -622,6 +659,22 @@ export class Queue<E = any, R = any> extends LinearBase<E, R> {
622
659
  return true;
623
660
  }
624
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
+
625
678
  /**
626
679
  * Reverse the queue in-place by compacting then reversing.
627
680
  * @remarks Time O(N), Space O(N)
@@ -666,6 +719,10 @@ export class Queue<E = any, R = any> extends LinearBase<E, R> {
666
719
 
667
720
 
668
721
 
722
+
723
+
724
+
725
+
669
726
 
670
727
 
671
728
 
@@ -714,6 +771,10 @@ export class Queue<E = any, R = any> extends LinearBase<E, R> {
714
771
 
715
772
 
716
773
 
774
+
775
+
776
+
777
+
717
778
 
718
779
 
719
780
 
@@ -791,6 +852,10 @@ export class Queue<E = any, R = any> extends LinearBase<E, R> {
791
852
 
792
853
 
793
854
 
855
+
856
+
857
+
858
+
794
859
 
795
860
 
796
861
 
@@ -846,6 +911,10 @@ export class Queue<E = any, R = any> extends LinearBase<E, R> {
846
911
 
847
912
 
848
913
 
914
+
915
+
916
+
917
+
849
918
 
850
919
 
851
920
 
@@ -905,6 +974,10 @@ export class Queue<E = any, R = any> extends LinearBase<E, R> {
905
974
 
906
975
 
907
976
 
977
+
978
+
979
+
980
+
908
981
 
909
982
 
910
983
 
@@ -192,6 +192,10 @@ export class Stack<E = any, R = any> extends IterableElementBase<E, R> {
192
192
 
193
193
 
194
194
 
195
+
196
+
197
+
198
+
195
199
 
196
200
 
197
201
 
@@ -260,6 +264,10 @@ export class Stack<E = any, R = any> extends IterableElementBase<E, R> {
260
264
 
261
265
 
262
266
 
267
+
268
+
269
+
270
+
263
271
 
264
272
 
265
273
 
@@ -311,6 +319,10 @@ export class Stack<E = any, R = any> extends IterableElementBase<E, R> {
311
319
 
312
320
 
313
321
 
322
+
323
+
324
+
325
+
314
326
 
315
327
 
316
328
 
@@ -362,6 +374,10 @@ export class Stack<E = any, R = any> extends IterableElementBase<E, R> {
362
374
 
363
375
 
364
376
 
377
+
378
+
379
+
380
+
365
381
 
366
382
 
367
383
 
@@ -422,6 +438,10 @@ export class Stack<E = any, R = any> extends IterableElementBase<E, R> {
422
438
 
423
439
 
424
440
 
441
+
442
+
443
+
444
+
425
445
 
426
446
 
427
447
 
@@ -499,6 +519,10 @@ export class Stack<E = any, R = any> extends IterableElementBase<E, R> {
499
519
 
500
520
 
501
521
 
522
+
523
+
524
+
525
+
502
526
 
503
527
 
504
528
 
@@ -513,20 +537,20 @@ export class Stack<E = any, R = any> extends IterableElementBase<E, R> {
513
537
 
514
538
  delete(element: E): boolean {
515
539
  const idx = this._indexOfByEquals(element);
516
- return this.deleteAt(idx);
540
+ return this.deleteAt(idx) !== undefined;
517
541
  }
518
542
 
519
543
  /**
520
544
  * Delete the element at an index.
521
545
  * @remarks Time O(N), Space O(1)
522
546
  * @param index - Zero-based index from the bottom.
523
- * @returns True if removed.
547
+ * @returns The removed element, or undefined if the index is out of range.
524
548
  */
525
549
 
526
- deleteAt(index: number): boolean {
527
- 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;
528
552
  const spliced = this.elements.splice(index, 1);
529
- return spliced.length === 1;
553
+ return spliced[0];
530
554
  }
531
555
 
532
556
  /**
@@ -578,6 +602,10 @@ export class Stack<E = any, R = any> extends IterableElementBase<E, R> {
578
602
 
579
603
 
580
604
 
605
+
606
+
607
+
608
+
581
609
 
582
610
 
583
611
 
@@ -626,6 +654,10 @@ export class Stack<E = any, R = any> extends IterableElementBase<E, R> {
626
654
 
627
655
 
628
656
 
657
+
658
+
659
+
660
+
629
661
 
630
662
 
631
663
 
@@ -680,6 +712,10 @@ export class Stack<E = any, R = any> extends IterableElementBase<E, R> {
680
712
 
681
713
 
682
714
 
715
+
716
+
717
+
718
+
683
719
 
684
720
 
685
721
 
@@ -756,6 +792,10 @@ export class Stack<E = any, R = any> extends IterableElementBase<E, R> {
756
792
 
757
793
 
758
794
 
795
+
796
+
797
+
798
+
759
799
 
760
800
 
761
801
 
@@ -314,6 +314,10 @@ export class Trie<R = any> extends IterableElementBase<string, R> {
314
314
 
315
315
 
316
316
 
317
+
318
+
319
+
320
+
317
321
 
318
322
 
319
323
 
@@ -388,6 +392,10 @@ export class Trie<R = any> extends IterableElementBase<string, R> {
388
392
 
389
393
 
390
394
 
395
+
396
+
397
+
398
+
391
399
 
392
400
 
393
401
 
@@ -449,6 +457,10 @@ export class Trie<R = any> extends IterableElementBase<string, R> {
449
457
 
450
458
 
451
459
 
460
+
461
+
462
+
463
+
452
464
 
453
465
 
454
466
 
@@ -505,6 +517,10 @@ export class Trie<R = any> extends IterableElementBase<string, R> {
505
517
 
506
518
 
507
519
 
520
+
521
+
522
+
523
+
508
524
 
509
525
 
510
526
 
@@ -553,6 +569,10 @@ export class Trie<R = any> extends IterableElementBase<string, R> {
553
569
 
554
570
 
555
571
 
572
+
573
+
574
+
575
+
556
576
 
557
577
 
558
578
 
@@ -605,6 +625,10 @@ export class Trie<R = any> extends IterableElementBase<string, R> {
605
625
 
606
626
 
607
627
 
628
+
629
+
630
+
631
+
608
632
 
609
633
 
610
634
 
@@ -744,6 +768,10 @@ export class Trie<R = any> extends IterableElementBase<string, R> {
744
768
 
745
769
 
746
770
 
771
+
772
+
773
+
774
+
747
775
 
748
776
 
749
777
 
@@ -824,6 +852,10 @@ export class Trie<R = any> extends IterableElementBase<string, R> {
824
852
 
825
853
 
826
854
 
855
+
856
+
857
+
858
+
827
859
 
828
860
 
829
861
 
@@ -885,6 +917,10 @@ export class Trie<R = any> extends IterableElementBase<string, R> {
885
917
 
886
918
 
887
919
 
920
+
921
+
922
+
923
+
888
924
 
889
925
 
890
926
 
@@ -969,6 +1005,10 @@ export class Trie<R = any> extends IterableElementBase<string, R> {
969
1005
 
970
1006
 
971
1007
 
1008
+
1009
+
1010
+
1011
+
972
1012
 
973
1013
 
974
1014
 
@@ -1021,6 +1061,10 @@ export class Trie<R = any> extends IterableElementBase<string, R> {
1021
1061
 
1022
1062
 
1023
1063
 
1064
+
1065
+
1066
+
1067
+
1024
1068
 
1025
1069
 
1026
1070
 
@@ -1074,6 +1118,10 @@ export class Trie<R = any> extends IterableElementBase<string, R> {
1074
1118
 
1075
1119
 
1076
1120
 
1121
+
1122
+
1123
+
1124
+
1077
1125
 
1078
1126
 
1079
1127
 
@@ -1,6 +1,5 @@
1
1
  import { BinaryTreeNode } from '../data-structures';
2
2
  import type {
3
- BinaryTreeDeleteResult,
4
3
  BinaryTreeOptions,
5
4
  BTNRep,
6
5
  DFSOrderPattern,
@@ -51,7 +50,7 @@ export interface IBinaryTree<K = any, V = any, R = any> {
51
50
  // Accept BTNRep, predicate, or raw R for deletion
52
51
  delete(
53
52
  keyNodeEntryRawOrPredicate: BTNRep<K, V, BinaryTreeNode<K, V>> | NodePredicate<BinaryTreeNode<K, V> | null>
54
- ): BinaryTreeDeleteResult<BinaryTreeNode<K, V>>[];
53
+ ): boolean;
55
54
 
56
55
  clear(): void;
57
56
 
@@ -242,11 +241,4 @@ export interface IBinaryTree<K = any, V = any, R = any> {
242
241
 
243
242
  // ---- bulk / interop ----
244
243
  merge(anotherTree: IBinaryTree<K, V, R>): void;
245
-
246
- refill(
247
- keysNodesEntriesOrRaws: Iterable<
248
- K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined | R
249
- >,
250
- values?: Iterable<V | undefined>
251
- ): void;
252
244
  }