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
@@ -229,6 +229,30 @@ export declare class Trie<R = any> extends IterableElementBase<string, R> {
229
229
 
230
230
 
231
231
 
232
+
233
+
234
+
235
+
236
+
237
+
238
+
239
+
240
+
241
+
242
+
243
+
244
+
245
+
246
+
247
+
248
+
249
+
250
+
251
+
252
+
253
+
254
+
255
+
232
256
  * @example
233
257
  * // basic Trie creation and add words
234
258
  * // Create a simple Trie with initial words
@@ -259,6 +283,30 @@ export declare class Trie<R = any> extends IterableElementBase<string, R> {
259
283
 
260
284
 
261
285
 
286
+
287
+
288
+
289
+
290
+
291
+
292
+
293
+
294
+
295
+
296
+
297
+
298
+
299
+
300
+
301
+
302
+
303
+
304
+
305
+
306
+
307
+
308
+
309
+
262
310
  * @example
263
311
  * // Add multiple words
264
312
  * const trie = new Trie();
@@ -284,6 +332,30 @@ export declare class Trie<R = any> extends IterableElementBase<string, R> {
284
332
 
285
333
 
286
334
 
335
+
336
+
337
+
338
+
339
+
340
+
341
+
342
+
343
+
344
+
345
+
346
+
347
+
348
+
349
+
350
+
351
+
352
+
353
+
354
+
355
+
356
+
357
+
358
+
287
359
  * @example
288
360
  * // Check if a word exists
289
361
  * const dict = new Trie(['apple', 'app', 'application']);
@@ -305,6 +377,30 @@ export declare class Trie<R = any> extends IterableElementBase<string, R> {
305
377
 
306
378
 
307
379
 
380
+
381
+
382
+
383
+
384
+
385
+
386
+
387
+
388
+
389
+
390
+
391
+
392
+
393
+
394
+
395
+
396
+
397
+
398
+
399
+
400
+
401
+
402
+
403
+
308
404
  * @example
309
405
  * // Check if empty
310
406
  * const trie = new Trie();
@@ -325,6 +421,30 @@ export declare class Trie<R = any> extends IterableElementBase<string, R> {
325
421
 
326
422
 
327
423
 
424
+
425
+
426
+
427
+
428
+
429
+
430
+
431
+
432
+
433
+
434
+
435
+
436
+
437
+
438
+
439
+
440
+
441
+
442
+
443
+
444
+
445
+
446
+
447
+
328
448
  * @example
329
449
  * // Remove all words
330
450
  * const trie = new Trie(['a', 'b', 'c']);
@@ -348,6 +468,30 @@ export declare class Trie<R = any> extends IterableElementBase<string, R> {
348
468
 
349
469
 
350
470
 
471
+
472
+
473
+
474
+
475
+
476
+
477
+
478
+
479
+
480
+
481
+
482
+
483
+
484
+
485
+
486
+
487
+
488
+
489
+
490
+
491
+
492
+
493
+
494
+
351
495
  * @example
352
496
  * // Trie delete and iteration
353
497
  * const trie = new Trie(['car', 'card', 'care', 'careful', 'can', 'cat']);
@@ -396,6 +540,30 @@ export declare class Trie<R = any> extends IterableElementBase<string, R> {
396
540
 
397
541
 
398
542
 
543
+
544
+
545
+
546
+
547
+
548
+
549
+
550
+
551
+
552
+
553
+
554
+
555
+
556
+
557
+
558
+
559
+
560
+
561
+
562
+
563
+
564
+
565
+
566
+
399
567
  * @example
400
568
  * // Check if a prefix exists
401
569
  * const trie = new Trie(['hello', 'help', 'world']);
@@ -427,6 +595,30 @@ export declare class Trie<R = any> extends IterableElementBase<string, R> {
427
595
 
428
596
 
429
597
 
598
+
599
+
600
+
601
+
602
+
603
+
604
+
605
+
606
+
607
+
608
+
609
+
610
+
611
+
612
+
613
+
614
+
615
+
616
+
617
+
618
+
619
+
620
+
621
+
430
622
  * @example
431
623
  * // Find shared prefix
432
624
  * const trie = new Trie(['flower', 'flow', 'flight']);
@@ -452,6 +644,30 @@ export declare class Trie<R = any> extends IterableElementBase<string, R> {
452
644
 
453
645
 
454
646
 
647
+
648
+
649
+
650
+
651
+
652
+
653
+
654
+
655
+
656
+
657
+
658
+
659
+
660
+
661
+
662
+
663
+
664
+
665
+
666
+
667
+
668
+
669
+
670
+
455
671
  * @example
456
672
  * // Trie getWords and prefix search
457
673
  * const trie = new Trie(['apple', 'app', 'apply', 'application', 'apricot']);
@@ -477,6 +693,30 @@ export declare class Trie<R = any> extends IterableElementBase<string, R> {
477
693
 
478
694
 
479
695
 
696
+
697
+
698
+
699
+
700
+
701
+
702
+
703
+
704
+
705
+
706
+
707
+
708
+
709
+
710
+
711
+
712
+
713
+
714
+
715
+
716
+
717
+
718
+
719
+
480
720
  * @example
481
721
  * // Create independent copy
482
722
  * const trie = new Trie(['hello', 'world']);
@@ -499,13 +739,37 @@ export declare class Trie<R = any> extends IterableElementBase<string, R> {
499
739
 
500
740
 
501
741
 
742
+
743
+
744
+
745
+
746
+
747
+
748
+
749
+
750
+
751
+
752
+
753
+
754
+
755
+
756
+
757
+
758
+
759
+
760
+
761
+
762
+
763
+
764
+
765
+
502
766
  * @example
503
767
  * // Filter words
504
768
  * const trie = new Trie(['cat', 'car', 'dog', 'card']);
505
769
  * const result = trie.filter(w => w.startsWith('ca'));
506
770
  * console.log(result.size); // 3;
507
771
  */
508
- filter(predicate: ElementCallback<string, R, boolean>, thisArg?: any): this;
772
+ filter(predicate: ElementCallback<string, R, boolean>, thisArg?: unknown): this;
509
773
  /**
510
774
  * Transform words
511
775
 
@@ -516,13 +780,37 @@ export declare class Trie<R = any> extends IterableElementBase<string, R> {
516
780
 
517
781
 
518
782
 
783
+
784
+
785
+
786
+
787
+
788
+
789
+
790
+
791
+
792
+
793
+
794
+
795
+
796
+
797
+
798
+
799
+
800
+
801
+
802
+
803
+
804
+
805
+
806
+
519
807
  * @example
520
808
  * // Transform words
521
809
  * const trie = new Trie(['hello', 'world']);
522
810
  * const upper = trie.map(w => w.toUpperCase());
523
811
  * console.log(upper.has('HELLO')); // true;
524
812
  */
525
- map<RM>(callback: ElementCallback<string, R, string>, options?: TrieOptions<RM>, thisArg?: any): Trie<RM>;
813
+ map<RM>(callback: ElementCallback<string, R, string>, options?: TrieOptions<RM>, thisArg?: unknown): Trie<RM>;
526
814
  /**
527
815
  * Map words into a new trie (possibly different record type).
528
816
  * @remarks Time O(ΣL), Space O(ΣL)
@@ -533,7 +821,7 @@ export declare class Trie<R = any> extends IterableElementBase<string, R> {
533
821
  * @param [thisArg] - Value for `this` inside the callback.
534
822
  * @returns A new Trie constructed from mapped words.
535
823
  */
536
- map<EM, RM>(callback: ElementCallback<string, R, EM>, options?: TrieOptions<RM>, thisArg?: any): IterableElementBase<EM, RM>;
824
+ map<EM, RM>(callback: ElementCallback<string, R, EM>, options?: TrieOptions<RM>, thisArg?: unknown): IterableElementBase<EM, RM>;
537
825
  /**
538
826
  * Map words into a new trie of the same element type.
539
827
  * @remarks Time O(ΣL), Space O(ΣL)
@@ -541,7 +829,7 @@ export declare class Trie<R = any> extends IterableElementBase<string, R> {
541
829
  * @param [thisArg] - Value for `this` inside the callback.
542
830
  * @returns A new trie with mapped words.
543
831
  */
544
- mapSame(callback: ElementCallback<string, R, string>, thisArg?: any): this;
832
+ mapSame(callback: ElementCallback<string, R, string>, thisArg?: unknown): this;
545
833
  /**
546
834
  * (Protected) Create an empty instance of the same concrete class.
547
835
  * @remarks Time O(1), Space O(1)
@@ -17,5 +17,5 @@ export interface IGraph<V, E, VO, EO> {
17
17
  isEmpty(): boolean;
18
18
  clear(): void;
19
19
  clone(): this;
20
- filter(...args: any[]): this;
20
+ filter(...args: unknown[]): this;
21
21
  }
@@ -5,10 +5,10 @@ export type Comparator<K> = (a: K, b: K) => number;
5
5
  export type DFSOrderPattern = 'PRE' | 'IN' | 'POST';
6
6
  export type NodeDisplayLayout = [string[], number, number, number];
7
7
  export interface IterableWithSize<T> extends Iterable<T> {
8
- size: number | ((...args: any[]) => number);
8
+ size: number | ((...args: unknown[]) => number);
9
9
  }
10
10
  export interface IterableWithLength<T> extends Iterable<T> {
11
- length: number | ((...args: any[]) => number);
11
+ length: number | ((...args: unknown[]) => number);
12
12
  }
13
13
  export type OptValue<V> = V | undefined;
14
14
  export type IterableWithSizeOrLength<T> = IterableWithSize<T> | IterableWithLength<T>;
@@ -3,6 +3,7 @@ import type { Comparator, OptValue } from '../../common';
3
3
  type BSTBaseOptions<K, V, R> = Omit<BinaryTreeOptions<K, V, R>, 'isDuplicate'>;
4
4
  export type BSTOptions<K, V, R> = BSTBaseOptions<K, V, R> & {
5
5
  comparator?: Comparator<K>;
6
+ enableOrderStatistic?: boolean;
6
7
  };
7
8
  export type BSTNOptKey<K> = K | undefined;
8
9
  export type OptNode<NODE> = NODE | undefined;
@@ -8,6 +8,11 @@ export interface TreeMapOptions<K, V, R = [K, V]> {
8
8
  * - `false`: store values on tree nodes (Node Mode).
9
9
  */
10
10
  isMapMode?: boolean;
11
+ /**
12
+ * Enable order-statistic operations (select, rank, rangeByRank).
13
+ * When true, subtree counts are maintained on every node.
14
+ */
15
+ enableOrderStatistic?: boolean;
11
16
  /**
12
17
  * Transform raw elements into `[key, value]` entries.
13
18
  * When provided, the constructor accepts `Iterable<R>` instead of `Iterable<[K, V]>`.
@@ -8,6 +8,10 @@ export interface TreeMultiSetOptions<K, R = K> {
8
8
  * - `false`: Node Mode.
9
9
  */
10
10
  isMapMode?: boolean;
11
+ /**
12
+ * Enable order-statistic operations (select, rank, rangeByRank).
13
+ */
14
+ enableOrderStatistic?: boolean;
11
15
  /**
12
16
  * Transform raw elements into keys.
13
17
  * When provided, the constructor accepts `Iterable<R>` instead of `Iterable<K>`.
@@ -8,6 +8,10 @@ export interface TreeSetOptions<K, R = K> {
8
8
  * - `false`: store values on tree nodes (Node Mode).
9
9
  */
10
10
  isMapMode?: boolean;
11
+ /**
12
+ * Enable order-statistic operations (select, rank, rangeByRank).
13
+ */
14
+ enableOrderStatistic?: boolean;
11
15
  /**
12
16
  * Transform raw elements into keys.
13
17
  * When provided, the constructor accepts `Iterable<R>` instead of `Iterable<K>`.
@@ -1,5 +1,6 @@
1
1
  import { Comparator } from '../../common';
2
2
  import { IterableElementBaseOptions } from '../base';
3
+ /** Configuration options for Heap and PriorityQueue. */
3
4
  export type HeapOptions<E, R> = IterableElementBaseOptions<E, R> & {
4
5
  comparator?: Comparator<E>;
5
6
  };
@@ -1,2 +1,3 @@
1
1
  import { HeapOptions } from '../heap';
2
+ /** Configuration options for PriorityQueue, same as {@link HeapOptions}. */
2
3
  export type PriorityQueueOptions<E, R> = HeapOptions<E, R>;
@@ -1,18 +1,18 @@
1
1
  export type KeyValueObject = {
2
- [key: string]: any;
2
+ [key: string]: unknown;
3
3
  };
4
4
  export type KeyValueObjectWithKey = {
5
- [key: string]: any;
5
+ [key: string]: unknown;
6
6
  key: string | number | symbol;
7
7
  };
8
8
  export type NonNumberNonObjectButDefined = string | boolean | symbol | null;
9
9
  export type ObjectWithoutKey = Omit<KeyValueObject, 'key'>;
10
10
  export type ObjectWithNonNumberKey = {
11
- [key: string]: any;
11
+ [key: string]: unknown;
12
12
  key: string | boolean | symbol | null | object | undefined;
13
13
  };
14
14
  export type ObjectWithNumberKey = {
15
- [key: string]: any;
15
+ [key: string]: unknown;
16
16
  key: number;
17
17
  };
18
18
  export type RestrictValByKey = NonNumberNonObjectButDefined | ObjectWithoutKey | ObjectWithNonNumberKey | ObjectWithNumberKey;