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
@@ -8,7 +8,7 @@
8
8
 
9
9
  import type { ElementCallback, TrieOptions } from '../../types';
10
10
  import { IterableElementBase } from '../base';
11
- import { ERR } from '../../common';
11
+ import { ERR, raise } from '../../common';
12
12
 
13
13
  /**
14
14
  * Node used by Trie to store one character and its children.
@@ -295,6 +295,30 @@ export class Trie<R = any> extends IterableElementBase<string, R> {
295
295
 
296
296
 
297
297
 
298
+
299
+
300
+
301
+
302
+
303
+
304
+
305
+
306
+
307
+
308
+
309
+
310
+
311
+
312
+
313
+
314
+
315
+
316
+
317
+
318
+
319
+
320
+
321
+
298
322
  * @example
299
323
  * // basic Trie creation and add words
300
324
  * // Create a simple Trie with initial words
@@ -345,6 +369,30 @@ export class Trie<R = any> extends IterableElementBase<string, R> {
345
369
 
346
370
 
347
371
 
372
+
373
+
374
+
375
+
376
+
377
+
378
+
379
+
380
+
381
+
382
+
383
+
384
+
385
+
386
+
387
+
388
+
389
+
390
+
391
+
392
+
393
+
394
+
395
+
348
396
  * @example
349
397
  * // Add multiple words
350
398
  * const trie = new Trie();
@@ -382,6 +430,30 @@ export class Trie<R = any> extends IterableElementBase<string, R> {
382
430
 
383
431
 
384
432
 
433
+
434
+
435
+
436
+
437
+
438
+
439
+
440
+
441
+
442
+
443
+
444
+
445
+
446
+
447
+
448
+
449
+
450
+
451
+
452
+
453
+
454
+
455
+
456
+
385
457
  * @example
386
458
  * // Check if a word exists
387
459
  * const dict = new Trie(['apple', 'app', 'application']);
@@ -414,6 +486,30 @@ export class Trie<R = any> extends IterableElementBase<string, R> {
414
486
 
415
487
 
416
488
 
489
+
490
+
491
+
492
+
493
+
494
+
495
+
496
+
497
+
498
+
499
+
500
+
501
+
502
+
503
+
504
+
505
+
506
+
507
+
508
+
509
+
510
+
511
+
512
+
417
513
  * @example
418
514
  * // Check if empty
419
515
  * const trie = new Trie();
@@ -438,6 +534,30 @@ export class Trie<R = any> extends IterableElementBase<string, R> {
438
534
 
439
535
 
440
536
 
537
+
538
+
539
+
540
+
541
+
542
+
543
+
544
+
545
+
546
+
547
+
548
+
549
+
550
+
551
+
552
+
553
+
554
+
555
+
556
+
557
+
558
+
559
+
560
+
441
561
  * @example
442
562
  * // Remove all words
443
563
  * const trie = new Trie(['a', 'b', 'c']);
@@ -466,6 +586,30 @@ export class Trie<R = any> extends IterableElementBase<string, R> {
466
586
 
467
587
 
468
588
 
589
+
590
+
591
+
592
+
593
+
594
+
595
+
596
+
597
+
598
+
599
+
600
+
601
+
602
+
603
+
604
+
605
+
606
+
607
+
608
+
609
+
610
+
611
+
612
+
469
613
  * @example
470
614
  * // Trie delete and iteration
471
615
  * const trie = new Trie(['car', 'card', 'care', 'careful', 'can', 'cat']);
@@ -581,6 +725,30 @@ export class Trie<R = any> extends IterableElementBase<string, R> {
581
725
 
582
726
 
583
727
 
728
+
729
+
730
+
731
+
732
+
733
+
734
+
735
+
736
+
737
+
738
+
739
+
740
+
741
+
742
+
743
+
744
+
745
+
746
+
747
+
748
+
749
+
750
+
751
+
584
752
  * @example
585
753
  * // Check if a prefix exists
586
754
  * const trie = new Trie(['hello', 'help', 'world']);
@@ -637,6 +805,30 @@ export class Trie<R = any> extends IterableElementBase<string, R> {
637
805
 
638
806
 
639
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
+
640
832
  * @example
641
833
  * // Find shared prefix
642
834
  * const trie = new Trie(['flower', 'flow', 'flight']);
@@ -674,6 +866,30 @@ export class Trie<R = any> extends IterableElementBase<string, R> {
674
866
 
675
867
 
676
868
 
869
+
870
+
871
+
872
+
873
+
874
+
875
+
876
+
877
+
878
+
879
+
880
+
881
+
882
+
883
+
884
+
885
+
886
+
887
+
888
+
889
+
890
+
891
+
892
+
677
893
  * @example
678
894
  * // Trie getWords and prefix search
679
895
  * const trie = new Trie(['apple', 'app', 'apply', 'application', 'apricot']);
@@ -734,6 +950,30 @@ export class Trie<R = any> extends IterableElementBase<string, R> {
734
950
 
735
951
 
736
952
 
953
+
954
+
955
+
956
+
957
+
958
+
959
+
960
+
961
+
962
+
963
+
964
+
965
+
966
+
967
+
968
+
969
+
970
+
971
+
972
+
973
+
974
+
975
+
976
+
737
977
  * @example
738
978
  * // Create independent copy
739
979
  * const trie = new Trie(['hello', 'world']);
@@ -762,6 +1002,30 @@ export class Trie<R = any> extends IterableElementBase<string, R> {
762
1002
 
763
1003
 
764
1004
 
1005
+
1006
+
1007
+
1008
+
1009
+
1010
+
1011
+
1012
+
1013
+
1014
+
1015
+
1016
+
1017
+
1018
+
1019
+
1020
+
1021
+
1022
+
1023
+
1024
+
1025
+
1026
+
1027
+
1028
+
765
1029
  * @example
766
1030
  * // Filter words
767
1031
  * const trie = new Trie(['cat', 'car', 'dog', 'card']);
@@ -769,7 +1033,7 @@ export class Trie<R = any> extends IterableElementBase<string, R> {
769
1033
  * console.log(result.size); // 3;
770
1034
  */
771
1035
 
772
- filter(predicate: ElementCallback<string, R, boolean>, thisArg?: any): this {
1036
+ filter(predicate: ElementCallback<string, R, boolean>, thisArg?: unknown): this {
773
1037
  const results = this._createInstance();
774
1038
  let index = 0;
775
1039
  for (const word of this) {
@@ -791,13 +1055,37 @@ export class Trie<R = any> extends IterableElementBase<string, R> {
791
1055
 
792
1056
 
793
1057
 
1058
+
1059
+
1060
+
1061
+
1062
+
1063
+
1064
+
1065
+
1066
+
1067
+
1068
+
1069
+
1070
+
1071
+
1072
+
1073
+
1074
+
1075
+
1076
+
1077
+
1078
+
1079
+
1080
+
1081
+
794
1082
  * @example
795
1083
  * // Transform words
796
1084
  * const trie = new Trie(['hello', 'world']);
797
1085
  * const upper = trie.map(w => w.toUpperCase());
798
1086
  * console.log(upper.has('HELLO')); // true;
799
1087
  */
800
- map<RM>(callback: ElementCallback<string, R, string>, options?: TrieOptions<RM>, thisArg?: any): Trie<RM>;
1088
+ map<RM>(callback: ElementCallback<string, R, string>, options?: TrieOptions<RM>, thisArg?: unknown): Trie<RM>;
801
1089
 
802
1090
  /**
803
1091
  * Map words into a new trie (possibly different record type).
@@ -813,16 +1101,16 @@ export class Trie<R = any> extends IterableElementBase<string, R> {
813
1101
  map<EM, RM>(
814
1102
  callback: ElementCallback<string, R, EM>,
815
1103
  options?: TrieOptions<RM>,
816
- thisArg?: any
1104
+ thisArg?: unknown
817
1105
  ): IterableElementBase<EM, RM>;
818
1106
 
819
- map<EM, RM>(callback: ElementCallback<string, R, EM>, options?: TrieOptions<RM>, thisArg?: any): any {
1107
+ map<EM, RM>(callback: ElementCallback<string, R, EM>, options?: TrieOptions<RM>, thisArg?: unknown): any {
820
1108
  const newTrie = this._createLike<RM>([], options);
821
1109
  let i = 0;
822
1110
  for (const x of this) {
823
1111
  const v = thisArg === undefined ? callback(x, i++, this) : callback.call(thisArg, x, i++, this);
824
1112
  if (typeof v !== 'string') {
825
- throw new TypeError(ERR.callbackReturnType('string', typeof v, 'Trie.map'));
1113
+ raise(TypeError, ERR.callbackReturnType('string', typeof v, 'Trie.map'));
826
1114
  }
827
1115
  newTrie.add(v);
828
1116
  }
@@ -837,7 +1125,7 @@ export class Trie<R = any> extends IterableElementBase<string, R> {
837
1125
  * @returns A new trie with mapped words.
838
1126
  */
839
1127
 
840
- mapSame(callback: ElementCallback<string, R, string>, thisArg?: any): this {
1128
+ mapSame(callback: ElementCallback<string, R, string>, thisArg?: unknown): this {
841
1129
  const next = this._createInstance();
842
1130
  let i = 0;
843
1131
  for (const key of this) {
@@ -40,5 +40,5 @@ export interface IGraph<V, E, VO, EO> {
40
40
 
41
41
  clone(): this;
42
42
 
43
- filter(...args: any[]): this;
43
+ filter(...args: unknown[]): this;
44
44
  }
@@ -11,11 +11,11 @@ export type DFSOrderPattern = 'PRE' | 'IN' | 'POST';
11
11
  export type NodeDisplayLayout = [string[], number, number, number];
12
12
 
13
13
  export interface IterableWithSize<T> extends Iterable<T> {
14
- size: number | ((...args: any[]) => number);
14
+ size: number | ((...args: unknown[]) => number);
15
15
  }
16
16
 
17
17
  export interface IterableWithLength<T> extends Iterable<T> {
18
- length: number | ((...args: any[]) => number);
18
+ length: number | ((...args: unknown[]) => number);
19
19
  }
20
20
 
21
21
  export type OptValue<V> = V | undefined;
@@ -5,6 +5,7 @@ type BSTBaseOptions<K, V, R> = Omit<BinaryTreeOptions<K, V, R>, 'isDuplicate'>;
5
5
 
6
6
  export type BSTOptions<K, V, R> = BSTBaseOptions<K, V, R> & {
7
7
  comparator?: Comparator<K>;
8
+ enableOrderStatistic?: boolean;
8
9
  }
9
10
 
10
11
  export type BSTNOptKey<K> = K | undefined;
@@ -11,6 +11,12 @@ export interface TreeMapOptions<K, V, R = [K, V]> {
11
11
  */
12
12
  isMapMode?: boolean;
13
13
 
14
+ /**
15
+ * Enable order-statistic operations (select, rank, rangeByRank).
16
+ * When true, subtree counts are maintained on every node.
17
+ */
18
+ enableOrderStatistic?: boolean;
19
+
14
20
  /**
15
21
  * Transform raw elements into `[key, value]` entries.
16
22
  * When provided, the constructor accepts `Iterable<R>` instead of `Iterable<[K, V]>`.
@@ -11,6 +11,11 @@ export interface TreeMultiSetOptions<K, R = K> {
11
11
  */
12
12
  isMapMode?: boolean;
13
13
 
14
+ /**
15
+ * Enable order-statistic operations (select, rank, rangeByRank).
16
+ */
17
+ enableOrderStatistic?: boolean;
18
+
14
19
  /**
15
20
  * Transform raw elements into keys.
16
21
  * When provided, the constructor accepts `Iterable<R>` instead of `Iterable<K>`.
@@ -11,6 +11,11 @@ export interface TreeSetOptions<K, R = K> {
11
11
  */
12
12
  isMapMode?: boolean;
13
13
 
14
+ /**
15
+ * Enable order-statistic operations (select, rank, rangeByRank).
16
+ */
17
+ enableOrderStatistic?: boolean;
18
+
14
19
  /**
15
20
  * Transform raw elements into keys.
16
21
  * When provided, the constructor accepts `Iterable<R>` instead of `Iterable<K>`.
@@ -1,6 +1,7 @@
1
1
  import { Comparator } from '../../common';
2
2
  import { IterableElementBaseOptions } from '../base';
3
3
 
4
+ /** Configuration options for Heap and PriorityQueue. */
4
5
  export type HeapOptions<E, R> = IterableElementBaseOptions<E, R> & {
5
6
  comparator?: Comparator<E>;
6
7
  };
@@ -1,3 +1,4 @@
1
1
  import { HeapOptions } from '../heap';
2
2
 
3
+ /** Configuration options for PriorityQueue, same as {@link HeapOptions}. */
3
4
  export type PriorityQueueOptions<E, R> = HeapOptions<E, R>;
@@ -1,18 +1,18 @@
1
- export type KeyValueObject = { [key: string]: any };
1
+ export type KeyValueObject = { [key: string]: unknown };
2
2
 
3
- export type KeyValueObjectWithKey = { [key: string]: any; key: string | number | symbol };
3
+ export type KeyValueObjectWithKey = { [key: string]: unknown; key: string | number | symbol };
4
4
 
5
5
  export type NonNumberNonObjectButDefined = string | boolean | symbol | null;
6
6
 
7
7
  export type ObjectWithoutKey = Omit<KeyValueObject, 'key'>;
8
8
 
9
9
  export type ObjectWithNonNumberKey = {
10
- [key: string]: any;
10
+ [key: string]: unknown;
11
11
  key: string | boolean | symbol | null | object | undefined;
12
12
  };
13
13
 
14
14
  export type ObjectWithNumberKey = {
15
- [key: string]: any;
15
+ [key: string]: unknown;
16
16
  key: number;
17
17
  };
18
18