binary-tree-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 +609 -0
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs-legacy/index.cjs +609 -0
- package/dist/cjs-legacy/index.cjs.map +1 -1
- package/dist/esm/index.mjs +609 -0
- package/dist/esm/index.mjs.map +1 -1
- package/dist/esm-legacy/index.mjs +609 -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/binary-tree-typed.js +609 -0
- package/dist/umd/binary-tree-typed.js.map +1 -1
- package/dist/umd/binary-tree-typed.min.js +5 -5
- package/dist/umd/binary-tree-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
|
@@ -295,6 +295,27 @@ 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
|
+
|
|
298
319
|
* @example
|
|
299
320
|
* // basic Trie creation and add words
|
|
300
321
|
* // Create a simple Trie with initial words
|
|
@@ -345,6 +366,27 @@ export class Trie<R = any> extends IterableElementBase<string, R> {
|
|
|
345
366
|
|
|
346
367
|
|
|
347
368
|
|
|
369
|
+
|
|
370
|
+
|
|
371
|
+
|
|
372
|
+
|
|
373
|
+
|
|
374
|
+
|
|
375
|
+
|
|
376
|
+
|
|
377
|
+
|
|
378
|
+
|
|
379
|
+
|
|
380
|
+
|
|
381
|
+
|
|
382
|
+
|
|
383
|
+
|
|
384
|
+
|
|
385
|
+
|
|
386
|
+
|
|
387
|
+
|
|
388
|
+
|
|
389
|
+
|
|
348
390
|
* @example
|
|
349
391
|
* // Add multiple words
|
|
350
392
|
* const trie = new Trie();
|
|
@@ -382,6 +424,27 @@ export class Trie<R = any> extends IterableElementBase<string, R> {
|
|
|
382
424
|
|
|
383
425
|
|
|
384
426
|
|
|
427
|
+
|
|
428
|
+
|
|
429
|
+
|
|
430
|
+
|
|
431
|
+
|
|
432
|
+
|
|
433
|
+
|
|
434
|
+
|
|
435
|
+
|
|
436
|
+
|
|
437
|
+
|
|
438
|
+
|
|
439
|
+
|
|
440
|
+
|
|
441
|
+
|
|
442
|
+
|
|
443
|
+
|
|
444
|
+
|
|
445
|
+
|
|
446
|
+
|
|
447
|
+
|
|
385
448
|
* @example
|
|
386
449
|
* // Check if a word exists
|
|
387
450
|
* const dict = new Trie(['apple', 'app', 'application']);
|
|
@@ -414,6 +477,27 @@ export class Trie<R = any> extends IterableElementBase<string, R> {
|
|
|
414
477
|
|
|
415
478
|
|
|
416
479
|
|
|
480
|
+
|
|
481
|
+
|
|
482
|
+
|
|
483
|
+
|
|
484
|
+
|
|
485
|
+
|
|
486
|
+
|
|
487
|
+
|
|
488
|
+
|
|
489
|
+
|
|
490
|
+
|
|
491
|
+
|
|
492
|
+
|
|
493
|
+
|
|
494
|
+
|
|
495
|
+
|
|
496
|
+
|
|
497
|
+
|
|
498
|
+
|
|
499
|
+
|
|
500
|
+
|
|
417
501
|
* @example
|
|
418
502
|
* // Check if empty
|
|
419
503
|
* const trie = new Trie();
|
|
@@ -438,6 +522,27 @@ export class Trie<R = any> extends IterableElementBase<string, R> {
|
|
|
438
522
|
|
|
439
523
|
|
|
440
524
|
|
|
525
|
+
|
|
526
|
+
|
|
527
|
+
|
|
528
|
+
|
|
529
|
+
|
|
530
|
+
|
|
531
|
+
|
|
532
|
+
|
|
533
|
+
|
|
534
|
+
|
|
535
|
+
|
|
536
|
+
|
|
537
|
+
|
|
538
|
+
|
|
539
|
+
|
|
540
|
+
|
|
541
|
+
|
|
542
|
+
|
|
543
|
+
|
|
544
|
+
|
|
545
|
+
|
|
441
546
|
* @example
|
|
442
547
|
* // Remove all words
|
|
443
548
|
* const trie = new Trie(['a', 'b', 'c']);
|
|
@@ -466,6 +571,27 @@ export class Trie<R = any> extends IterableElementBase<string, R> {
|
|
|
466
571
|
|
|
467
572
|
|
|
468
573
|
|
|
574
|
+
|
|
575
|
+
|
|
576
|
+
|
|
577
|
+
|
|
578
|
+
|
|
579
|
+
|
|
580
|
+
|
|
581
|
+
|
|
582
|
+
|
|
583
|
+
|
|
584
|
+
|
|
585
|
+
|
|
586
|
+
|
|
587
|
+
|
|
588
|
+
|
|
589
|
+
|
|
590
|
+
|
|
591
|
+
|
|
592
|
+
|
|
593
|
+
|
|
594
|
+
|
|
469
595
|
* @example
|
|
470
596
|
* // Trie delete and iteration
|
|
471
597
|
* const trie = new Trie(['car', 'card', 'care', 'careful', 'can', 'cat']);
|
|
@@ -581,6 +707,27 @@ export class Trie<R = any> extends IterableElementBase<string, R> {
|
|
|
581
707
|
|
|
582
708
|
|
|
583
709
|
|
|
710
|
+
|
|
711
|
+
|
|
712
|
+
|
|
713
|
+
|
|
714
|
+
|
|
715
|
+
|
|
716
|
+
|
|
717
|
+
|
|
718
|
+
|
|
719
|
+
|
|
720
|
+
|
|
721
|
+
|
|
722
|
+
|
|
723
|
+
|
|
724
|
+
|
|
725
|
+
|
|
726
|
+
|
|
727
|
+
|
|
728
|
+
|
|
729
|
+
|
|
730
|
+
|
|
584
731
|
* @example
|
|
585
732
|
* // Check if a prefix exists
|
|
586
733
|
* const trie = new Trie(['hello', 'help', 'world']);
|
|
@@ -637,6 +784,27 @@ export class Trie<R = any> extends IterableElementBase<string, R> {
|
|
|
637
784
|
|
|
638
785
|
|
|
639
786
|
|
|
787
|
+
|
|
788
|
+
|
|
789
|
+
|
|
790
|
+
|
|
791
|
+
|
|
792
|
+
|
|
793
|
+
|
|
794
|
+
|
|
795
|
+
|
|
796
|
+
|
|
797
|
+
|
|
798
|
+
|
|
799
|
+
|
|
800
|
+
|
|
801
|
+
|
|
802
|
+
|
|
803
|
+
|
|
804
|
+
|
|
805
|
+
|
|
806
|
+
|
|
807
|
+
|
|
640
808
|
* @example
|
|
641
809
|
* // Find shared prefix
|
|
642
810
|
* const trie = new Trie(['flower', 'flow', 'flight']);
|
|
@@ -674,6 +842,27 @@ export class Trie<R = any> extends IterableElementBase<string, R> {
|
|
|
674
842
|
|
|
675
843
|
|
|
676
844
|
|
|
845
|
+
|
|
846
|
+
|
|
847
|
+
|
|
848
|
+
|
|
849
|
+
|
|
850
|
+
|
|
851
|
+
|
|
852
|
+
|
|
853
|
+
|
|
854
|
+
|
|
855
|
+
|
|
856
|
+
|
|
857
|
+
|
|
858
|
+
|
|
859
|
+
|
|
860
|
+
|
|
861
|
+
|
|
862
|
+
|
|
863
|
+
|
|
864
|
+
|
|
865
|
+
|
|
677
866
|
* @example
|
|
678
867
|
* // Trie getWords and prefix search
|
|
679
868
|
* const trie = new Trie(['apple', 'app', 'apply', 'application', 'apricot']);
|
|
@@ -734,6 +923,27 @@ export class Trie<R = any> extends IterableElementBase<string, R> {
|
|
|
734
923
|
|
|
735
924
|
|
|
736
925
|
|
|
926
|
+
|
|
927
|
+
|
|
928
|
+
|
|
929
|
+
|
|
930
|
+
|
|
931
|
+
|
|
932
|
+
|
|
933
|
+
|
|
934
|
+
|
|
935
|
+
|
|
936
|
+
|
|
937
|
+
|
|
938
|
+
|
|
939
|
+
|
|
940
|
+
|
|
941
|
+
|
|
942
|
+
|
|
943
|
+
|
|
944
|
+
|
|
945
|
+
|
|
946
|
+
|
|
737
947
|
* @example
|
|
738
948
|
* // Create independent copy
|
|
739
949
|
* const trie = new Trie(['hello', 'world']);
|
|
@@ -762,6 +972,27 @@ export class Trie<R = any> extends IterableElementBase<string, R> {
|
|
|
762
972
|
|
|
763
973
|
|
|
764
974
|
|
|
975
|
+
|
|
976
|
+
|
|
977
|
+
|
|
978
|
+
|
|
979
|
+
|
|
980
|
+
|
|
981
|
+
|
|
982
|
+
|
|
983
|
+
|
|
984
|
+
|
|
985
|
+
|
|
986
|
+
|
|
987
|
+
|
|
988
|
+
|
|
989
|
+
|
|
990
|
+
|
|
991
|
+
|
|
992
|
+
|
|
993
|
+
|
|
994
|
+
|
|
995
|
+
|
|
765
996
|
* @example
|
|
766
997
|
* // Filter words
|
|
767
998
|
* const trie = new Trie(['cat', 'car', 'dog', 'card']);
|
|
@@ -769,7 +1000,7 @@ export class Trie<R = any> extends IterableElementBase<string, R> {
|
|
|
769
1000
|
* console.log(result.size); // 3;
|
|
770
1001
|
*/
|
|
771
1002
|
|
|
772
|
-
filter(predicate: ElementCallback<string, R, boolean>, thisArg?:
|
|
1003
|
+
filter(predicate: ElementCallback<string, R, boolean>, thisArg?: unknown): this {
|
|
773
1004
|
const results = this._createInstance();
|
|
774
1005
|
let index = 0;
|
|
775
1006
|
for (const word of this) {
|
|
@@ -791,13 +1022,34 @@ export class Trie<R = any> extends IterableElementBase<string, R> {
|
|
|
791
1022
|
|
|
792
1023
|
|
|
793
1024
|
|
|
1025
|
+
|
|
1026
|
+
|
|
1027
|
+
|
|
1028
|
+
|
|
1029
|
+
|
|
1030
|
+
|
|
1031
|
+
|
|
1032
|
+
|
|
1033
|
+
|
|
1034
|
+
|
|
1035
|
+
|
|
1036
|
+
|
|
1037
|
+
|
|
1038
|
+
|
|
1039
|
+
|
|
1040
|
+
|
|
1041
|
+
|
|
1042
|
+
|
|
1043
|
+
|
|
1044
|
+
|
|
1045
|
+
|
|
794
1046
|
* @example
|
|
795
1047
|
* // Transform words
|
|
796
1048
|
* const trie = new Trie(['hello', 'world']);
|
|
797
1049
|
* const upper = trie.map(w => w.toUpperCase());
|
|
798
1050
|
* console.log(upper.has('HELLO')); // true;
|
|
799
1051
|
*/
|
|
800
|
-
map<RM>(callback: ElementCallback<string, R, string>, options?: TrieOptions<RM>, thisArg?:
|
|
1052
|
+
map<RM>(callback: ElementCallback<string, R, string>, options?: TrieOptions<RM>, thisArg?: unknown): Trie<RM>;
|
|
801
1053
|
|
|
802
1054
|
/**
|
|
803
1055
|
* Map words into a new trie (possibly different record type).
|
|
@@ -813,10 +1065,10 @@ export class Trie<R = any> extends IterableElementBase<string, R> {
|
|
|
813
1065
|
map<EM, RM>(
|
|
814
1066
|
callback: ElementCallback<string, R, EM>,
|
|
815
1067
|
options?: TrieOptions<RM>,
|
|
816
|
-
thisArg?:
|
|
1068
|
+
thisArg?: unknown
|
|
817
1069
|
): IterableElementBase<EM, RM>;
|
|
818
1070
|
|
|
819
|
-
map<EM, RM>(callback: ElementCallback<string, R, EM>, options?: TrieOptions<RM>, thisArg?:
|
|
1071
|
+
map<EM, RM>(callback: ElementCallback<string, R, EM>, options?: TrieOptions<RM>, thisArg?: unknown): any {
|
|
820
1072
|
const newTrie = this._createLike<RM>([], options);
|
|
821
1073
|
let i = 0;
|
|
822
1074
|
for (const x of this) {
|
|
@@ -837,7 +1089,7 @@ export class Trie<R = any> extends IterableElementBase<string, R> {
|
|
|
837
1089
|
* @returns A new trie with mapped words.
|
|
838
1090
|
*/
|
|
839
1091
|
|
|
840
|
-
mapSame(callback: ElementCallback<string, R, string>, thisArg?:
|
|
1092
|
+
mapSame(callback: ElementCallback<string, R, string>, thisArg?: unknown): this {
|
|
841
1093
|
const next = this._createInstance();
|
|
842
1094
|
let i = 0;
|
|
843
1095
|
for (const key of this) {
|
package/src/interfaces/graph.ts
CHANGED
package/src/types/common.ts
CHANGED
|
@@ -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:
|
|
14
|
+
size: number | ((...args: unknown[]) => number);
|
|
15
15
|
}
|
|
16
16
|
|
|
17
17
|
export interface IterableWithLength<T> extends Iterable<T> {
|
|
18
|
-
length: number | ((...args:
|
|
18
|
+
length: number | ((...args: unknown[]) => number);
|
|
19
19
|
}
|
|
20
20
|
|
|
21
21
|
export type OptValue<V> = V | undefined;
|
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
export type KeyValueObject = { [key: string]:
|
|
1
|
+
export type KeyValueObject = { [key: string]: unknown };
|
|
2
2
|
|
|
3
|
-
export type KeyValueObjectWithKey = { [key: string]:
|
|
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]:
|
|
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]:
|
|
15
|
+
[key: string]: unknown;
|
|
16
16
|
key: number;
|
|
17
17
|
};
|
|
18
18
|
|