max-priority-queue-typed 2.5.0 → 2.5.1
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.
- package/dist/cjs/index.cjs +294 -0
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs-legacy/index.cjs +294 -0
- package/dist/cjs-legacy/index.cjs.map +1 -1
- package/dist/esm/index.mjs +294 -0
- package/dist/esm/index.mjs.map +1 -1
- package/dist/esm-legacy/index.mjs +294 -0
- package/dist/esm-legacy/index.mjs.map +1 -1
- package/dist/types/data-structures/base/index.d.ts +1 -0
- package/dist/types/data-structures/base/iterable-entry-base.d.ts +8 -8
- package/dist/types/data-structures/base/linear-base.d.ts +3 -3
- package/dist/types/data-structures/binary-tree/avl-tree.d.ts +252 -0
- package/dist/types/data-structures/binary-tree/binary-indexed-tree.d.ts +294 -0
- package/dist/types/data-structures/binary-tree/binary-tree.d.ts +527 -2
- package/dist/types/data-structures/binary-tree/bst.d.ts +505 -1
- package/dist/types/data-structures/binary-tree/red-black-tree.d.ts +399 -0
- package/dist/types/data-structures/binary-tree/segment-tree.d.ts +126 -1
- package/dist/types/data-structures/binary-tree/tree-map.d.ts +2881 -382
- package/dist/types/data-structures/binary-tree/tree-multi-map.d.ts +2867 -347
- package/dist/types/data-structures/binary-tree/tree-multi-set.d.ts +2328 -312
- package/dist/types/data-structures/binary-tree/tree-set.d.ts +2671 -277
- package/dist/types/data-structures/graph/abstract-graph.d.ts +4 -4
- package/dist/types/data-structures/graph/directed-graph.d.ts +210 -0
- package/dist/types/data-structures/graph/undirected-graph.d.ts +189 -0
- package/dist/types/data-structures/hash/hash-map.d.ts +241 -10
- package/dist/types/data-structures/heap/heap.d.ts +294 -0
- package/dist/types/data-structures/linked-list/doubly-linked-list.d.ts +360 -3
- package/dist/types/data-structures/linked-list/singly-linked-list.d.ts +318 -3
- package/dist/types/data-structures/linked-list/skip-linked-list.d.ts +380 -2
- package/dist/types/data-structures/matrix/matrix.d.ts +168 -0
- package/dist/types/data-structures/queue/deque.d.ts +319 -4
- package/dist/types/data-structures/queue/queue.d.ts +252 -0
- package/dist/types/data-structures/stack/stack.d.ts +210 -0
- package/dist/types/data-structures/trie/trie.d.ts +256 -4
- package/dist/types/interfaces/graph.d.ts +1 -1
- package/dist/types/types/common.d.ts +2 -2
- package/dist/types/types/data-structures/heap/heap.d.ts +1 -0
- package/dist/types/types/data-structures/priority-queue/priority-queue.d.ts +1 -0
- package/dist/types/types/utils/validate-type.d.ts +4 -4
- package/dist/umd/max-priority-queue-typed.js +294 -0
- package/dist/umd/max-priority-queue-typed.js.map +1 -1
- package/dist/umd/max-priority-queue-typed.min.js.map +1 -1
- package/package.json +2 -2
- package/src/data-structures/base/index.ts +1 -0
- package/src/data-structures/base/iterable-entry-base.ts +8 -8
- package/src/data-structures/base/linear-base.ts +3 -3
- package/src/data-structures/binary-tree/avl-tree.ts +252 -0
- package/src/data-structures/binary-tree/binary-indexed-tree.ts +295 -1
- package/src/data-structures/binary-tree/binary-tree.ts +527 -2
- package/src/data-structures/binary-tree/bst.ts +505 -1
- package/src/data-structures/binary-tree/red-black-tree.ts +399 -0
- package/src/data-structures/binary-tree/segment-tree.ts +127 -2
- package/src/data-structures/binary-tree/tree-map.ts +2958 -459
- package/src/data-structures/binary-tree/tree-multi-map.ts +3069 -549
- package/src/data-structures/binary-tree/tree-multi-set.ts +2476 -460
- package/src/data-structures/binary-tree/tree-set.ts +2816 -422
- package/src/data-structures/graph/abstract-graph.ts +4 -4
- package/src/data-structures/graph/directed-graph.ts +210 -0
- package/src/data-structures/graph/undirected-graph.ts +189 -0
- package/src/data-structures/hash/hash-map.ts +246 -15
- package/src/data-structures/heap/heap.ts +294 -0
- package/src/data-structures/linked-list/doubly-linked-list.ts +360 -3
- package/src/data-structures/linked-list/singly-linked-list.ts +318 -3
- package/src/data-structures/linked-list/skip-linked-list.ts +380 -2
- package/src/data-structures/matrix/matrix.ts +169 -1
- package/src/data-structures/queue/deque.ts +320 -5
- package/src/data-structures/queue/queue.ts +252 -0
- package/src/data-structures/stack/stack.ts +210 -0
- package/src/data-structures/trie/trie.ts +257 -5
- package/src/interfaces/graph.ts +1 -1
- package/src/types/common.ts +2 -2
- package/src/types/data-structures/heap/heap.ts +1 -0
- package/src/types/data-structures/priority-queue/priority-queue.ts +1 -0
- package/src/types/utils/validate-type.ts +4 -4
|
@@ -229,6 +229,27 @@ 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
|
+
|
|
232
253
|
* @example
|
|
233
254
|
* // basic Trie creation and add words
|
|
234
255
|
* // Create a simple Trie with initial words
|
|
@@ -259,6 +280,27 @@ export declare class Trie<R = any> extends IterableElementBase<string, R> {
|
|
|
259
280
|
|
|
260
281
|
|
|
261
282
|
|
|
283
|
+
|
|
284
|
+
|
|
285
|
+
|
|
286
|
+
|
|
287
|
+
|
|
288
|
+
|
|
289
|
+
|
|
290
|
+
|
|
291
|
+
|
|
292
|
+
|
|
293
|
+
|
|
294
|
+
|
|
295
|
+
|
|
296
|
+
|
|
297
|
+
|
|
298
|
+
|
|
299
|
+
|
|
300
|
+
|
|
301
|
+
|
|
302
|
+
|
|
303
|
+
|
|
262
304
|
* @example
|
|
263
305
|
* // Add multiple words
|
|
264
306
|
* const trie = new Trie();
|
|
@@ -284,6 +326,27 @@ export declare class Trie<R = any> extends IterableElementBase<string, R> {
|
|
|
284
326
|
|
|
285
327
|
|
|
286
328
|
|
|
329
|
+
|
|
330
|
+
|
|
331
|
+
|
|
332
|
+
|
|
333
|
+
|
|
334
|
+
|
|
335
|
+
|
|
336
|
+
|
|
337
|
+
|
|
338
|
+
|
|
339
|
+
|
|
340
|
+
|
|
341
|
+
|
|
342
|
+
|
|
343
|
+
|
|
344
|
+
|
|
345
|
+
|
|
346
|
+
|
|
347
|
+
|
|
348
|
+
|
|
349
|
+
|
|
287
350
|
* @example
|
|
288
351
|
* // Check if a word exists
|
|
289
352
|
* const dict = new Trie(['apple', 'app', 'application']);
|
|
@@ -305,6 +368,27 @@ export declare class Trie<R = any> extends IterableElementBase<string, R> {
|
|
|
305
368
|
|
|
306
369
|
|
|
307
370
|
|
|
371
|
+
|
|
372
|
+
|
|
373
|
+
|
|
374
|
+
|
|
375
|
+
|
|
376
|
+
|
|
377
|
+
|
|
378
|
+
|
|
379
|
+
|
|
380
|
+
|
|
381
|
+
|
|
382
|
+
|
|
383
|
+
|
|
384
|
+
|
|
385
|
+
|
|
386
|
+
|
|
387
|
+
|
|
388
|
+
|
|
389
|
+
|
|
390
|
+
|
|
391
|
+
|
|
308
392
|
* @example
|
|
309
393
|
* // Check if empty
|
|
310
394
|
* const trie = new Trie();
|
|
@@ -325,6 +409,27 @@ export declare class Trie<R = any> extends IterableElementBase<string, R> {
|
|
|
325
409
|
|
|
326
410
|
|
|
327
411
|
|
|
412
|
+
|
|
413
|
+
|
|
414
|
+
|
|
415
|
+
|
|
416
|
+
|
|
417
|
+
|
|
418
|
+
|
|
419
|
+
|
|
420
|
+
|
|
421
|
+
|
|
422
|
+
|
|
423
|
+
|
|
424
|
+
|
|
425
|
+
|
|
426
|
+
|
|
427
|
+
|
|
428
|
+
|
|
429
|
+
|
|
430
|
+
|
|
431
|
+
|
|
432
|
+
|
|
328
433
|
* @example
|
|
329
434
|
* // Remove all words
|
|
330
435
|
* const trie = new Trie(['a', 'b', 'c']);
|
|
@@ -348,6 +453,27 @@ export declare class Trie<R = any> extends IterableElementBase<string, R> {
|
|
|
348
453
|
|
|
349
454
|
|
|
350
455
|
|
|
456
|
+
|
|
457
|
+
|
|
458
|
+
|
|
459
|
+
|
|
460
|
+
|
|
461
|
+
|
|
462
|
+
|
|
463
|
+
|
|
464
|
+
|
|
465
|
+
|
|
466
|
+
|
|
467
|
+
|
|
468
|
+
|
|
469
|
+
|
|
470
|
+
|
|
471
|
+
|
|
472
|
+
|
|
473
|
+
|
|
474
|
+
|
|
475
|
+
|
|
476
|
+
|
|
351
477
|
* @example
|
|
352
478
|
* // Trie delete and iteration
|
|
353
479
|
* const trie = new Trie(['car', 'card', 'care', 'careful', 'can', 'cat']);
|
|
@@ -396,6 +522,27 @@ export declare class Trie<R = any> extends IterableElementBase<string, R> {
|
|
|
396
522
|
|
|
397
523
|
|
|
398
524
|
|
|
525
|
+
|
|
526
|
+
|
|
527
|
+
|
|
528
|
+
|
|
529
|
+
|
|
530
|
+
|
|
531
|
+
|
|
532
|
+
|
|
533
|
+
|
|
534
|
+
|
|
535
|
+
|
|
536
|
+
|
|
537
|
+
|
|
538
|
+
|
|
539
|
+
|
|
540
|
+
|
|
541
|
+
|
|
542
|
+
|
|
543
|
+
|
|
544
|
+
|
|
545
|
+
|
|
399
546
|
* @example
|
|
400
547
|
* // Check if a prefix exists
|
|
401
548
|
* const trie = new Trie(['hello', 'help', 'world']);
|
|
@@ -427,6 +574,27 @@ export declare class Trie<R = any> extends IterableElementBase<string, R> {
|
|
|
427
574
|
|
|
428
575
|
|
|
429
576
|
|
|
577
|
+
|
|
578
|
+
|
|
579
|
+
|
|
580
|
+
|
|
581
|
+
|
|
582
|
+
|
|
583
|
+
|
|
584
|
+
|
|
585
|
+
|
|
586
|
+
|
|
587
|
+
|
|
588
|
+
|
|
589
|
+
|
|
590
|
+
|
|
591
|
+
|
|
592
|
+
|
|
593
|
+
|
|
594
|
+
|
|
595
|
+
|
|
596
|
+
|
|
597
|
+
|
|
430
598
|
* @example
|
|
431
599
|
* // Find shared prefix
|
|
432
600
|
* const trie = new Trie(['flower', 'flow', 'flight']);
|
|
@@ -452,6 +620,27 @@ export declare class Trie<R = any> extends IterableElementBase<string, R> {
|
|
|
452
620
|
|
|
453
621
|
|
|
454
622
|
|
|
623
|
+
|
|
624
|
+
|
|
625
|
+
|
|
626
|
+
|
|
627
|
+
|
|
628
|
+
|
|
629
|
+
|
|
630
|
+
|
|
631
|
+
|
|
632
|
+
|
|
633
|
+
|
|
634
|
+
|
|
635
|
+
|
|
636
|
+
|
|
637
|
+
|
|
638
|
+
|
|
639
|
+
|
|
640
|
+
|
|
641
|
+
|
|
642
|
+
|
|
643
|
+
|
|
455
644
|
* @example
|
|
456
645
|
* // Trie getWords and prefix search
|
|
457
646
|
* const trie = new Trie(['apple', 'app', 'apply', 'application', 'apricot']);
|
|
@@ -477,6 +666,27 @@ export declare class Trie<R = any> extends IterableElementBase<string, R> {
|
|
|
477
666
|
|
|
478
667
|
|
|
479
668
|
|
|
669
|
+
|
|
670
|
+
|
|
671
|
+
|
|
672
|
+
|
|
673
|
+
|
|
674
|
+
|
|
675
|
+
|
|
676
|
+
|
|
677
|
+
|
|
678
|
+
|
|
679
|
+
|
|
680
|
+
|
|
681
|
+
|
|
682
|
+
|
|
683
|
+
|
|
684
|
+
|
|
685
|
+
|
|
686
|
+
|
|
687
|
+
|
|
688
|
+
|
|
689
|
+
|
|
480
690
|
* @example
|
|
481
691
|
* // Create independent copy
|
|
482
692
|
* const trie = new Trie(['hello', 'world']);
|
|
@@ -499,13 +709,34 @@ export declare class Trie<R = any> extends IterableElementBase<string, R> {
|
|
|
499
709
|
|
|
500
710
|
|
|
501
711
|
|
|
712
|
+
|
|
713
|
+
|
|
714
|
+
|
|
715
|
+
|
|
716
|
+
|
|
717
|
+
|
|
718
|
+
|
|
719
|
+
|
|
720
|
+
|
|
721
|
+
|
|
722
|
+
|
|
723
|
+
|
|
724
|
+
|
|
725
|
+
|
|
726
|
+
|
|
727
|
+
|
|
728
|
+
|
|
729
|
+
|
|
730
|
+
|
|
731
|
+
|
|
732
|
+
|
|
502
733
|
* @example
|
|
503
734
|
* // Filter words
|
|
504
735
|
* const trie = new Trie(['cat', 'car', 'dog', 'card']);
|
|
505
736
|
* const result = trie.filter(w => w.startsWith('ca'));
|
|
506
737
|
* console.log(result.size); // 3;
|
|
507
738
|
*/
|
|
508
|
-
filter(predicate: ElementCallback<string, R, boolean>, thisArg?:
|
|
739
|
+
filter(predicate: ElementCallback<string, R, boolean>, thisArg?: unknown): this;
|
|
509
740
|
/**
|
|
510
741
|
* Transform words
|
|
511
742
|
|
|
@@ -516,13 +747,34 @@ export declare class Trie<R = any> extends IterableElementBase<string, R> {
|
|
|
516
747
|
|
|
517
748
|
|
|
518
749
|
|
|
750
|
+
|
|
751
|
+
|
|
752
|
+
|
|
753
|
+
|
|
754
|
+
|
|
755
|
+
|
|
756
|
+
|
|
757
|
+
|
|
758
|
+
|
|
759
|
+
|
|
760
|
+
|
|
761
|
+
|
|
762
|
+
|
|
763
|
+
|
|
764
|
+
|
|
765
|
+
|
|
766
|
+
|
|
767
|
+
|
|
768
|
+
|
|
769
|
+
|
|
770
|
+
|
|
519
771
|
* @example
|
|
520
772
|
* // Transform words
|
|
521
773
|
* const trie = new Trie(['hello', 'world']);
|
|
522
774
|
* const upper = trie.map(w => w.toUpperCase());
|
|
523
775
|
* console.log(upper.has('HELLO')); // true;
|
|
524
776
|
*/
|
|
525
|
-
map<RM>(callback: ElementCallback<string, R, string>, options?: TrieOptions<RM>, thisArg?:
|
|
777
|
+
map<RM>(callback: ElementCallback<string, R, string>, options?: TrieOptions<RM>, thisArg?: unknown): Trie<RM>;
|
|
526
778
|
/**
|
|
527
779
|
* Map words into a new trie (possibly different record type).
|
|
528
780
|
* @remarks Time O(ΣL), Space O(ΣL)
|
|
@@ -533,7 +785,7 @@ export declare class Trie<R = any> extends IterableElementBase<string, R> {
|
|
|
533
785
|
* @param [thisArg] - Value for `this` inside the callback.
|
|
534
786
|
* @returns A new Trie constructed from mapped words.
|
|
535
787
|
*/
|
|
536
|
-
map<EM, RM>(callback: ElementCallback<string, R, EM>, options?: TrieOptions<RM>, thisArg?:
|
|
788
|
+
map<EM, RM>(callback: ElementCallback<string, R, EM>, options?: TrieOptions<RM>, thisArg?: unknown): IterableElementBase<EM, RM>;
|
|
537
789
|
/**
|
|
538
790
|
* Map words into a new trie of the same element type.
|
|
539
791
|
* @remarks Time O(ΣL), Space O(ΣL)
|
|
@@ -541,7 +793,7 @@ export declare class Trie<R = any> extends IterableElementBase<string, R> {
|
|
|
541
793
|
* @param [thisArg] - Value for `this` inside the callback.
|
|
542
794
|
* @returns A new trie with mapped words.
|
|
543
795
|
*/
|
|
544
|
-
mapSame(callback: ElementCallback<string, R, string>, thisArg?:
|
|
796
|
+
mapSame(callback: ElementCallback<string, R, string>, thisArg?: unknown): this;
|
|
545
797
|
/**
|
|
546
798
|
* (Protected) Create an empty instance of the same concrete class.
|
|
547
799
|
* @remarks Time O(1), Space O(1)
|
|
@@ -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:
|
|
8
|
+
size: number | ((...args: unknown[]) => number);
|
|
9
9
|
}
|
|
10
10
|
export interface IterableWithLength<T> extends Iterable<T> {
|
|
11
|
-
length: number | ((...args:
|
|
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>;
|
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
export type KeyValueObject = {
|
|
2
|
-
[key: string]:
|
|
2
|
+
[key: string]: unknown;
|
|
3
3
|
};
|
|
4
4
|
export type KeyValueObjectWithKey = {
|
|
5
|
-
[key: string]:
|
|
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]:
|
|
11
|
+
[key: string]: unknown;
|
|
12
12
|
key: string | boolean | symbol | null | object | undefined;
|
|
13
13
|
};
|
|
14
14
|
export type ObjectWithNumberKey = {
|
|
15
|
-
[key: string]:
|
|
15
|
+
[key: string]: unknown;
|
|
16
16
|
key: number;
|
|
17
17
|
};
|
|
18
18
|
export type RestrictValByKey = NonNumberNonObjectButDefined | ObjectWithoutKey | ObjectWithNonNumberKey | ObjectWithNumberKey;
|