max-priority-queue-typed 2.5.0 → 2.5.2

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 (90) hide show
  1. package/dist/cjs/index.cjs +398 -55
  2. package/dist/cjs/index.cjs.map +1 -1
  3. package/dist/cjs-legacy/index.cjs +397 -54
  4. package/dist/cjs-legacy/index.cjs.map +1 -1
  5. package/dist/esm/index.mjs +398 -56
  6. package/dist/esm/index.mjs.map +1 -1
  7. package/dist/esm-legacy/index.mjs +397 -55
  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/base/index.d.ts +1 -0
  12. package/dist/types/data-structures/base/iterable-entry-base.d.ts +8 -8
  13. package/dist/types/data-structures/base/linear-base.d.ts +3 -3
  14. package/dist/types/data-structures/binary-tree/avl-tree.d.ts +288 -0
  15. package/dist/types/data-structures/binary-tree/binary-indexed-tree.d.ts +336 -0
  16. package/dist/types/data-structures/binary-tree/binary-tree.d.ts +618 -18
  17. package/dist/types/data-structures/binary-tree/bst.d.ts +676 -1
  18. package/dist/types/data-structures/binary-tree/red-black-tree.d.ts +456 -0
  19. package/dist/types/data-structures/binary-tree/segment-tree.d.ts +144 -1
  20. package/dist/types/data-structures/binary-tree/tree-map.d.ts +3307 -399
  21. package/dist/types/data-structures/binary-tree/tree-multi-map.d.ts +3285 -360
  22. package/dist/types/data-structures/binary-tree/tree-multi-set.d.ts +2674 -325
  23. package/dist/types/data-structures/binary-tree/tree-set.d.ts +3072 -287
  24. package/dist/types/data-structures/graph/abstract-graph.d.ts +4 -4
  25. package/dist/types/data-structures/graph/directed-graph.d.ts +240 -0
  26. package/dist/types/data-structures/graph/undirected-graph.d.ts +216 -0
  27. package/dist/types/data-structures/hash/hash-map.d.ts +274 -10
  28. package/dist/types/data-structures/heap/heap.d.ts +336 -0
  29. package/dist/types/data-structures/linked-list/doubly-linked-list.d.ts +411 -3
  30. package/dist/types/data-structures/linked-list/singly-linked-list.d.ts +363 -3
  31. package/dist/types/data-structures/linked-list/skip-linked-list.d.ts +434 -2
  32. package/dist/types/data-structures/matrix/matrix.d.ts +192 -0
  33. package/dist/types/data-structures/queue/deque.d.ts +364 -4
  34. package/dist/types/data-structures/queue/queue.d.ts +288 -0
  35. package/dist/types/data-structures/stack/stack.d.ts +240 -0
  36. package/dist/types/data-structures/trie/trie.d.ts +292 -4
  37. package/dist/types/interfaces/graph.d.ts +1 -1
  38. package/dist/types/types/common.d.ts +2 -2
  39. package/dist/types/types/data-structures/binary-tree/bst.d.ts +1 -0
  40. package/dist/types/types/data-structures/binary-tree/tree-map.d.ts +5 -0
  41. package/dist/types/types/data-structures/binary-tree/tree-multi-set.d.ts +4 -0
  42. package/dist/types/types/data-structures/binary-tree/tree-set.d.ts +4 -0
  43. package/dist/types/types/data-structures/heap/heap.d.ts +1 -0
  44. package/dist/types/types/data-structures/priority-queue/priority-queue.d.ts +1 -0
  45. package/dist/types/types/utils/validate-type.d.ts +4 -4
  46. package/dist/umd/max-priority-queue-typed.js +395 -53
  47. package/dist/umd/max-priority-queue-typed.js.map +1 -1
  48. package/dist/umd/max-priority-queue-typed.min.js +1 -1
  49. package/dist/umd/max-priority-queue-typed.min.js.map +1 -1
  50. package/package.json +2 -2
  51. package/src/common/error.ts +19 -1
  52. package/src/common/index.ts +1 -1
  53. package/src/data-structures/base/index.ts +1 -0
  54. package/src/data-structures/base/iterable-element-base.ts +3 -2
  55. package/src/data-structures/base/iterable-entry-base.ts +8 -8
  56. package/src/data-structures/base/linear-base.ts +3 -3
  57. package/src/data-structures/binary-tree/avl-tree.ts +299 -0
  58. package/src/data-structures/binary-tree/binary-indexed-tree.ts +341 -5
  59. package/src/data-structures/binary-tree/binary-tree.ts +606 -6
  60. package/src/data-structures/binary-tree/bst.ts +946 -7
  61. package/src/data-structures/binary-tree/red-black-tree.ts +472 -0
  62. package/src/data-structures/binary-tree/segment-tree.ts +145 -2
  63. package/src/data-structures/binary-tree/tree-map.ts +3423 -499
  64. package/src/data-structures/binary-tree/tree-multi-map.ts +3537 -596
  65. package/src/data-structures/binary-tree/tree-multi-set.ts +2855 -495
  66. package/src/data-structures/binary-tree/tree-set.ts +3209 -413
  67. package/src/data-structures/graph/abstract-graph.ts +6 -6
  68. package/src/data-structures/graph/directed-graph.ts +240 -0
  69. package/src/data-structures/graph/undirected-graph.ts +216 -0
  70. package/src/data-structures/hash/hash-map.ts +281 -19
  71. package/src/data-structures/heap/heap.ts +340 -4
  72. package/src/data-structures/heap/max-heap.ts +2 -2
  73. package/src/data-structures/linked-list/doubly-linked-list.ts +411 -3
  74. package/src/data-structures/linked-list/singly-linked-list.ts +363 -3
  75. package/src/data-structures/linked-list/skip-linked-list.ts +439 -7
  76. package/src/data-structures/matrix/matrix.ts +202 -10
  77. package/src/data-structures/priority-queue/max-priority-queue.ts +2 -2
  78. package/src/data-structures/queue/deque.ts +365 -5
  79. package/src/data-structures/queue/queue.ts +288 -0
  80. package/src/data-structures/stack/stack.ts +240 -0
  81. package/src/data-structures/trie/trie.ts +295 -7
  82. package/src/interfaces/graph.ts +1 -1
  83. package/src/types/common.ts +2 -2
  84. package/src/types/data-structures/binary-tree/bst.ts +1 -0
  85. package/src/types/data-structures/binary-tree/tree-map.ts +6 -0
  86. package/src/types/data-structures/binary-tree/tree-multi-set.ts +5 -0
  87. package/src/types/data-structures/binary-tree/tree-set.ts +5 -0
  88. package/src/types/data-structures/heap/heap.ts +1 -0
  89. package/src/types/data-structures/priority-queue/priority-queue.ts +1 -0
  90. package/src/types/utils/validate-type.ts +4 -4
@@ -7,7 +7,7 @@
7
7
  */
8
8
 
9
9
  import type { Comparator, EntryCallback } from '../../types';
10
- import { ERR } from '../../common';
10
+ import { ERR, raise } from '../../common';
11
11
  import { IterableEntryBase } from '../base';
12
12
 
13
13
  export class SkipListNode<K, V> {
@@ -72,7 +72,7 @@ export class SkipList<K = any, V = any, R = [K, V]> extends IterableEntryBase<K,
72
72
  [k, v] = toEntryFn(item as R);
73
73
  } else {
74
74
  if (!Array.isArray(item) || item.length < 2) {
75
- throw new TypeError(ERR.invalidEntry('SkipList'));
75
+ raise(TypeError, ERR.invalidEntry('SkipList'));
76
76
  }
77
77
  [k, v] = item as [K, V];
78
78
  }
@@ -86,7 +86,7 @@ export class SkipList<K = any, V = any, R = [K, V]> extends IterableEntryBase<K,
86
86
  static createDefaultComparator<K>(): Comparator<K> {
87
87
  return (a: K, b: K): number => {
88
88
  if (typeof a === 'number' && typeof b === 'number') {
89
- if (Number.isNaN(a) || Number.isNaN(b)) throw new TypeError(ERR.invalidNaN('SkipList'));
89
+ if (Number.isNaN(a) || Number.isNaN(b)) raise(TypeError, ERR.invalidNaN('SkipList'));
90
90
  return a - b;
91
91
  }
92
92
  if (typeof a === 'string' && typeof b === 'string') {
@@ -95,13 +95,13 @@ export class SkipList<K = any, V = any, R = [K, V]> extends IterableEntryBase<K,
95
95
  if (a instanceof Date && b instanceof Date) {
96
96
  const ta = a.getTime(),
97
97
  tb = b.getTime();
98
- if (Number.isNaN(ta) || Number.isNaN(tb)) throw new TypeError(ERR.invalidDate('SkipList'));
98
+ if (Number.isNaN(ta) || Number.isNaN(tb)) raise(TypeError, ERR.invalidDate('SkipList'));
99
99
  return ta - tb;
100
100
  }
101
101
  if (typeof a === 'bigint' && typeof b === 'bigint') {
102
102
  return a < b ? -1 : a > b ? 1 : 0;
103
103
  }
104
- throw new TypeError(ERR.comparatorRequired('SkipList'));
104
+ raise(TypeError, ERR.comparatorRequired('SkipList'));
105
105
  };
106
106
  }
107
107
 
@@ -145,6 +145,30 @@ export class SkipList<K = any, V = any, R = [K, V]> extends IterableEntryBase<K,
145
145
 
146
146
 
147
147
 
148
+
149
+
150
+
151
+
152
+
153
+
154
+
155
+
156
+
157
+
158
+
159
+
160
+
161
+
162
+
163
+
164
+
165
+
166
+
167
+
168
+
169
+
170
+
171
+
148
172
  * @example
149
173
  * // Check if empty
150
174
  * const sl = new SkipList<number, string>();
@@ -164,6 +188,30 @@ export class SkipList<K = any, V = any, R = [K, V]> extends IterableEntryBase<K,
164
188
 
165
189
 
166
190
 
191
+
192
+
193
+
194
+
195
+
196
+
197
+
198
+
199
+
200
+
201
+
202
+
203
+
204
+
205
+
206
+
207
+
208
+
209
+
210
+
211
+
212
+
213
+
214
+
167
215
  * @example
168
216
  * // Remove all entries
169
217
  * const sl = new SkipList<number, string>([[1, 'a'], [2, 'b']]);
@@ -186,6 +234,30 @@ export class SkipList<K = any, V = any, R = [K, V]> extends IterableEntryBase<K,
186
234
 
187
235
 
188
236
 
237
+
238
+
239
+
240
+
241
+
242
+
243
+
244
+
245
+
246
+
247
+
248
+
249
+
250
+
251
+
252
+
253
+
254
+
255
+
256
+
257
+
258
+
259
+
260
+
189
261
  * @example
190
262
  * // Create independent copy
191
263
  * const sl = new SkipList<number, string>([[1, 'a'], [2, 'b']]);
@@ -217,6 +289,30 @@ export class SkipList<K = any, V = any, R = [K, V]> extends IterableEntryBase<K,
217
289
 
218
290
 
219
291
 
292
+
293
+
294
+
295
+
296
+
297
+
298
+
299
+
300
+
301
+
302
+
303
+
304
+
305
+
306
+
307
+
308
+
309
+
310
+
311
+
312
+
313
+
314
+
315
+
220
316
  * @example
221
317
  * // In-memory sorted key-value store
222
318
  * const store = new SkipList<number, string>();
@@ -278,6 +374,30 @@ export class SkipList<K = any, V = any, R = [K, V]> extends IterableEntryBase<K,
278
374
 
279
375
 
280
376
 
377
+
378
+
379
+
380
+
381
+
382
+
383
+
384
+
385
+
386
+
387
+
388
+
389
+
390
+
391
+
392
+
393
+
394
+
395
+
396
+
397
+
398
+
399
+
400
+
281
401
  * @example
282
402
  * // Building a sorted index
283
403
  * type Product = { id: number; name: string; price: number };
@@ -287,8 +407,8 @@ export class SkipList<K = any, V = any, R = [K, V]> extends IterableEntryBase<K,
287
407
  * { id: 3, name: 'Doohickey', price: 15 }
288
408
  * ];
289
409
  *
290
- * const index = new SkipList<number, Product>(products as any, {
291
- * toEntryFn: (p: any) => [p.price, p]
410
+ * const index = new SkipList<number, Product, Product>(products, {
411
+ * toEntryFn: (p: Product) => [p.price, p]
292
412
  * });
293
413
  *
294
414
  * // Iterate in sorted order by price
@@ -318,6 +438,30 @@ export class SkipList<K = any, V = any, R = [K, V]> extends IterableEntryBase<K,
318
438
 
319
439
 
320
440
 
441
+
442
+
443
+
444
+
445
+
446
+
447
+
448
+
449
+
450
+
451
+
452
+
453
+
454
+
455
+
456
+
457
+
458
+
459
+
460
+
461
+
462
+
463
+
464
+
321
465
  * @example
322
466
  * // Check key existence
323
467
  * const sl = new SkipList<number, string>([[1, 'a'], [3, 'c'], [5, 'e']]);
@@ -341,6 +485,30 @@ export class SkipList<K = any, V = any, R = [K, V]> extends IterableEntryBase<K,
341
485
 
342
486
 
343
487
 
488
+
489
+
490
+
491
+
492
+
493
+
494
+
495
+
496
+
497
+
498
+
499
+
500
+
501
+
502
+
503
+
504
+
505
+
506
+
507
+
508
+
509
+
510
+
511
+
344
512
  * @example
345
513
  * // Fast lookup with deletion
346
514
  * const cache = new SkipList<string, number>();
@@ -389,6 +557,30 @@ export class SkipList<K = any, V = any, R = [K, V]> extends IterableEntryBase<K,
389
557
 
390
558
 
391
559
 
560
+
561
+
562
+
563
+
564
+
565
+
566
+
567
+
568
+
569
+
570
+
571
+
572
+
573
+
574
+
575
+
576
+
577
+
578
+
579
+
580
+
581
+
582
+
583
+
392
584
  * @example
393
585
  * // Access the minimum entry
394
586
  * const sl = new SkipList<number, string>([[5, 'e'], [1, 'a'], [3, 'c']]);
@@ -412,6 +604,30 @@ export class SkipList<K = any, V = any, R = [K, V]> extends IterableEntryBase<K,
412
604
 
413
605
 
414
606
 
607
+
608
+
609
+
610
+
611
+
612
+
613
+
614
+
615
+
616
+
617
+
618
+
619
+
620
+
621
+
622
+
623
+
624
+
625
+
626
+
627
+
628
+
629
+
630
+
415
631
  * @example
416
632
  * // Access the maximum entry
417
633
  * const sl = new SkipList<number, string>([[5, 'e'], [1, 'a'], [3, 'c']]);
@@ -437,6 +653,30 @@ export class SkipList<K = any, V = any, R = [K, V]> extends IterableEntryBase<K,
437
653
 
438
654
 
439
655
 
656
+
657
+
658
+
659
+
660
+
661
+
662
+
663
+
664
+
665
+
666
+
667
+
668
+
669
+
670
+
671
+
672
+
673
+
674
+
675
+
676
+
677
+
678
+
679
+
440
680
  * @example
441
681
  * // Remove and return smallest
442
682
  * const sl = new SkipList<number, string>([[1, 'a'], [2, 'b'], [3, 'c']]);
@@ -460,6 +700,30 @@ export class SkipList<K = any, V = any, R = [K, V]> extends IterableEntryBase<K,
460
700
 
461
701
 
462
702
 
703
+
704
+
705
+
706
+
707
+
708
+
709
+
710
+
711
+
712
+
713
+
714
+
715
+
716
+
717
+
718
+
719
+
720
+
721
+
722
+
723
+
724
+
725
+
726
+
463
727
  * @example
464
728
  * // Remove and return largest
465
729
  * const sl = new SkipList<number, string>([[1, 'a'], [2, 'b'], [3, 'c']]);
@@ -486,6 +750,30 @@ export class SkipList<K = any, V = any, R = [K, V]> extends IterableEntryBase<K,
486
750
 
487
751
 
488
752
 
753
+
754
+
755
+
756
+
757
+
758
+
759
+
760
+
761
+
762
+
763
+
764
+
765
+
766
+
767
+
768
+
769
+
770
+
771
+
772
+
773
+
774
+
775
+
776
+
489
777
  * @example
490
778
  * // Least entry ≥ key
491
779
  * const sl = new SkipList<number, string>([[10, 'a'], [20, 'b'], [30, 'c']]);
@@ -517,6 +805,30 @@ export class SkipList<K = any, V = any, R = [K, V]> extends IterableEntryBase<K,
517
805
 
518
806
 
519
807
 
808
+
809
+
810
+
811
+
812
+
813
+
814
+
815
+
816
+
817
+
818
+
819
+
820
+
821
+
822
+
823
+
824
+
825
+
826
+
827
+
828
+
829
+
830
+
831
+
520
832
  * @example
521
833
  * // Greatest entry ≤ key
522
834
  * const sl = new SkipList<number, string>([[10, 'a'], [20, 'b'], [30, 'c']]);
@@ -548,6 +860,30 @@ export class SkipList<K = any, V = any, R = [K, V]> extends IterableEntryBase<K,
548
860
 
549
861
 
550
862
 
863
+
864
+
865
+
866
+
867
+
868
+
869
+
870
+
871
+
872
+
873
+
874
+
875
+
876
+
877
+
878
+
879
+
880
+
881
+
882
+
883
+
884
+
885
+
886
+
551
887
  * @example
552
888
  * // Strictly greater entry
553
889
  * const sl = new SkipList<number, string>([[10, 'a'], [20, 'b'], [30, 'c']]);
@@ -576,6 +912,30 @@ export class SkipList<K = any, V = any, R = [K, V]> extends IterableEntryBase<K,
576
912
 
577
913
 
578
914
 
915
+
916
+
917
+
918
+
919
+
920
+
921
+
922
+
923
+
924
+
925
+
926
+
927
+
928
+
929
+
930
+
931
+
932
+
933
+
934
+
935
+
936
+
937
+
938
+
579
939
  * @example
580
940
  * // Strictly less entry
581
941
  * const sl = new SkipList<number, string>([[10, 'a'], [20, 'b'], [30, 'c']]);
@@ -610,6 +970,30 @@ export class SkipList<K = any, V = any, R = [K, V]> extends IterableEntryBase<K,
610
970
 
611
971
 
612
972
 
973
+
974
+
975
+
976
+
977
+
978
+
979
+
980
+
981
+
982
+
983
+
984
+
985
+
986
+
987
+
988
+
989
+
990
+
991
+
992
+
993
+
994
+
995
+
996
+
613
997
  * @example
614
998
  * // Find entries in a range
615
999
  * const sl = new SkipList<number, string>([[1, 'a'], [2, 'b'], [3, 'c'], [4, 'd'], [5, 'e']]);
@@ -659,6 +1043,30 @@ export class SkipList<K = any, V = any, R = [K, V]> extends IterableEntryBase<K,
659
1043
 
660
1044
 
661
1045
 
1046
+
1047
+
1048
+
1049
+
1050
+
1051
+
1052
+
1053
+
1054
+
1055
+
1056
+
1057
+
1058
+
1059
+
1060
+
1061
+
1062
+
1063
+
1064
+
1065
+
1066
+
1067
+
1068
+
1069
+
662
1070
  * @example
663
1071
  * // Transform entries
664
1072
  * const sl = new SkipList<number, string>([[1, 'a'], [2, 'b']]);
@@ -688,6 +1096,30 @@ export class SkipList<K = any, V = any, R = [K, V]> extends IterableEntryBase<K,
688
1096
 
689
1097
 
690
1098
 
1099
+
1100
+
1101
+
1102
+
1103
+
1104
+
1105
+
1106
+
1107
+
1108
+
1109
+
1110
+
1111
+
1112
+
1113
+
1114
+
1115
+
1116
+
1117
+
1118
+
1119
+
1120
+
1121
+
1122
+
691
1123
  * @example
692
1124
  * // Filter entries
693
1125
  * const sl = new SkipList<number, string>([[1, 'a'], [2, 'b'], [3, 'c']]);