trie-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 +323 -52
  2. package/dist/cjs/index.cjs.map +1 -1
  3. package/dist/cjs-legacy/index.cjs +322 -51
  4. package/dist/cjs-legacy/index.cjs.map +1 -1
  5. package/dist/esm/index.mjs +323 -53
  6. package/dist/esm/index.mjs.map +1 -1
  7. package/dist/esm-legacy/index.mjs +322 -52
  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/trie-typed.js +320 -50
  47. package/dist/umd/trie-typed.js.map +1 -1
  48. package/dist/umd/trie-typed.min.js +1 -1
  49. package/dist/umd/trie-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
@@ -1,6 +1,61 @@
1
1
  var __defProp = Object.defineProperty;
2
2
  var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
3
3
 
4
+ // src/common/error.ts
5
+ function raise(ErrorClass, message) {
6
+ throw new ErrorClass(message);
7
+ }
8
+ __name(raise, "raise");
9
+ var ERR = {
10
+ // Range / index
11
+ indexOutOfRange: /* @__PURE__ */ __name((index, min, max, ctx) => `${ctx ? ctx + ": " : ""}Index ${index} is out of range [${min}, ${max}].`, "indexOutOfRange"),
12
+ invalidIndex: /* @__PURE__ */ __name((ctx) => `${ctx ? ctx + ": " : ""}Index must be an integer.`, "invalidIndex"),
13
+ // Type / argument
14
+ invalidArgument: /* @__PURE__ */ __name((reason, ctx) => `${ctx ? ctx + ": " : ""}${reason}`, "invalidArgument"),
15
+ comparatorRequired: /* @__PURE__ */ __name((ctx) => `${ctx ? ctx + ": " : ""}Comparator is required for non-number/non-string/non-Date keys.`, "comparatorRequired"),
16
+ invalidKey: /* @__PURE__ */ __name((reason, ctx) => `${ctx ? ctx + ": " : ""}${reason}`, "invalidKey"),
17
+ notAFunction: /* @__PURE__ */ __name((name, ctx) => `${ctx ? ctx + ": " : ""}${name} must be a function.`, "notAFunction"),
18
+ invalidEntry: /* @__PURE__ */ __name((ctx) => `${ctx ? ctx + ": " : ""}Each entry must be a [key, value] tuple.`, "invalidEntry"),
19
+ invalidNaN: /* @__PURE__ */ __name((ctx) => `${ctx ? ctx + ": " : ""}NaN is not a valid key.`, "invalidNaN"),
20
+ invalidDate: /* @__PURE__ */ __name((ctx) => `${ctx ? ctx + ": " : ""}Invalid Date key.`, "invalidDate"),
21
+ reduceEmpty: /* @__PURE__ */ __name((ctx) => `${ctx ? ctx + ": " : ""}Reduce of empty structure with no initial value.`, "reduceEmpty"),
22
+ callbackReturnType: /* @__PURE__ */ __name((expected, got, ctx) => `${ctx ? ctx + ": " : ""}Callback must return ${expected}; got ${got}.`, "callbackReturnType"),
23
+ // State / operation
24
+ invalidOperation: /* @__PURE__ */ __name((reason, ctx) => `${ctx ? ctx + ": " : ""}${reason}`, "invalidOperation"),
25
+ // Matrix
26
+ matrixDimensionMismatch: /* @__PURE__ */ __name((op) => `Matrix: Dimensions must be compatible for ${op}.`, "matrixDimensionMismatch"),
27
+ matrixSingular: /* @__PURE__ */ __name(() => "Matrix: Singular matrix, inverse does not exist.", "matrixSingular"),
28
+ matrixNotSquare: /* @__PURE__ */ __name(() => "Matrix: Must be square for inversion.", "matrixNotSquare"),
29
+ matrixNotRectangular: /* @__PURE__ */ __name(() => "Matrix: Must be rectangular for transposition.", "matrixNotRectangular"),
30
+ matrixRowMismatch: /* @__PURE__ */ __name((expected, got) => `Matrix: Expected row length ${expected}, but got ${got}.`, "matrixRowMismatch"),
31
+ // Order statistic
32
+ orderStatisticNotEnabled: /* @__PURE__ */ __name((method, ctx) => `${ctx ? ctx + ": " : ""}${method}() requires enableOrderStatistic: true.`, "orderStatisticNotEnabled")
33
+ };
34
+
35
+ // src/common/index.ts
36
+ var DFSOperation = /* @__PURE__ */ ((DFSOperation2) => {
37
+ DFSOperation2[DFSOperation2["VISIT"] = 0] = "VISIT";
38
+ DFSOperation2[DFSOperation2["PROCESS"] = 1] = "PROCESS";
39
+ return DFSOperation2;
40
+ })(DFSOperation || {});
41
+ var Range = class {
42
+ constructor(low, high, includeLow = true, includeHigh = true) {
43
+ this.low = low;
44
+ this.high = high;
45
+ this.includeLow = includeLow;
46
+ this.includeHigh = includeHigh;
47
+ }
48
+ static {
49
+ __name(this, "Range");
50
+ }
51
+ // Determine whether a key is within the range
52
+ isInRange(key, comparator) {
53
+ const lowCheck = this.includeLow ? comparator(key, this.low) >= 0 : comparator(key, this.low) > 0;
54
+ const highCheck = this.includeHigh ? comparator(key, this.high) <= 0 : comparator(key, this.high) < 0;
55
+ return lowCheck && highCheck;
56
+ }
57
+ };
58
+
4
59
  // src/data-structures/base/iterable-element-base.ts
5
60
  var IterableElementBase = class {
6
61
  static {
@@ -19,7 +74,7 @@ var IterableElementBase = class {
19
74
  if (options) {
20
75
  const { toElementFn } = options;
21
76
  if (typeof toElementFn === "function") this._toElementFn = toElementFn;
22
- else if (toElementFn) throw new TypeError("toElementFn must be a function type");
77
+ else if (toElementFn) raise(TypeError, "toElementFn must be a function type");
23
78
  }
24
79
  }
25
80
  /**
@@ -182,7 +237,7 @@ var IterableElementBase = class {
182
237
  acc = initialValue;
183
238
  } else {
184
239
  const first = iter.next();
185
- if (first.done) throw new TypeError("Reduce of empty structure with no initial value");
240
+ if (first.done) raise(TypeError, "Reduce of empty structure with no initial value");
186
241
  acc = first.value;
187
242
  index = 1;
188
243
  }
@@ -224,55 +279,6 @@ var IterableElementBase = class {
224
279
  }
225
280
  };
226
281
 
227
- // src/common/error.ts
228
- var ERR = {
229
- // Range / index
230
- indexOutOfRange: /* @__PURE__ */ __name((index, min, max, ctx) => `${ctx ? ctx + ": " : ""}Index ${index} is out of range [${min}, ${max}].`, "indexOutOfRange"),
231
- invalidIndex: /* @__PURE__ */ __name((ctx) => `${ctx ? ctx + ": " : ""}Index must be an integer.`, "invalidIndex"),
232
- // Type / argument
233
- invalidArgument: /* @__PURE__ */ __name((reason, ctx) => `${ctx ? ctx + ": " : ""}${reason}`, "invalidArgument"),
234
- comparatorRequired: /* @__PURE__ */ __name((ctx) => `${ctx ? ctx + ": " : ""}Comparator is required for non-number/non-string/non-Date keys.`, "comparatorRequired"),
235
- invalidKey: /* @__PURE__ */ __name((reason, ctx) => `${ctx ? ctx + ": " : ""}${reason}`, "invalidKey"),
236
- notAFunction: /* @__PURE__ */ __name((name, ctx) => `${ctx ? ctx + ": " : ""}${name} must be a function.`, "notAFunction"),
237
- invalidEntry: /* @__PURE__ */ __name((ctx) => `${ctx ? ctx + ": " : ""}Each entry must be a [key, value] tuple.`, "invalidEntry"),
238
- invalidNaN: /* @__PURE__ */ __name((ctx) => `${ctx ? ctx + ": " : ""}NaN is not a valid key.`, "invalidNaN"),
239
- invalidDate: /* @__PURE__ */ __name((ctx) => `${ctx ? ctx + ": " : ""}Invalid Date key.`, "invalidDate"),
240
- reduceEmpty: /* @__PURE__ */ __name((ctx) => `${ctx ? ctx + ": " : ""}Reduce of empty structure with no initial value.`, "reduceEmpty"),
241
- callbackReturnType: /* @__PURE__ */ __name((expected, got, ctx) => `${ctx ? ctx + ": " : ""}Callback must return ${expected}; got ${got}.`, "callbackReturnType"),
242
- // State / operation
243
- invalidOperation: /* @__PURE__ */ __name((reason, ctx) => `${ctx ? ctx + ": " : ""}${reason}`, "invalidOperation"),
244
- // Matrix
245
- matrixDimensionMismatch: /* @__PURE__ */ __name((op) => `Matrix: Dimensions must be compatible for ${op}.`, "matrixDimensionMismatch"),
246
- matrixSingular: /* @__PURE__ */ __name(() => "Matrix: Singular matrix, inverse does not exist.", "matrixSingular"),
247
- matrixNotSquare: /* @__PURE__ */ __name(() => "Matrix: Must be square for inversion.", "matrixNotSquare"),
248
- matrixNotRectangular: /* @__PURE__ */ __name(() => "Matrix: Must be rectangular for transposition.", "matrixNotRectangular"),
249
- matrixRowMismatch: /* @__PURE__ */ __name((expected, got) => `Matrix: Expected row length ${expected}, but got ${got}.`, "matrixRowMismatch")
250
- };
251
-
252
- // src/common/index.ts
253
- var DFSOperation = /* @__PURE__ */ ((DFSOperation2) => {
254
- DFSOperation2[DFSOperation2["VISIT"] = 0] = "VISIT";
255
- DFSOperation2[DFSOperation2["PROCESS"] = 1] = "PROCESS";
256
- return DFSOperation2;
257
- })(DFSOperation || {});
258
- var Range = class {
259
- constructor(low, high, includeLow = true, includeHigh = true) {
260
- this.low = low;
261
- this.high = high;
262
- this.includeLow = includeLow;
263
- this.includeHigh = includeHigh;
264
- }
265
- static {
266
- __name(this, "Range");
267
- }
268
- // Determine whether a key is within the range
269
- isInRange(key, comparator) {
270
- const lowCheck = this.includeLow ? comparator(key, this.low) >= 0 : comparator(key, this.low) > 0;
271
- const highCheck = this.includeHigh ? comparator(key, this.high) <= 0 : comparator(key, this.high) < 0;
272
- return lowCheck && highCheck;
273
- }
274
- };
275
-
276
282
  // src/data-structures/trie/trie.ts
277
283
  var TrieNode = class {
278
284
  static {
@@ -415,6 +421,30 @@ var Trie = class extends IterableElementBase {
415
421
 
416
422
 
417
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
+
418
448
  * @example
419
449
  * // basic Trie creation and add words
420
450
  * // Create a simple Trie with initial words
@@ -463,6 +493,30 @@ var Trie = class extends IterableElementBase {
463
493
 
464
494
 
465
495
 
496
+
497
+
498
+
499
+
500
+
501
+
502
+
503
+
504
+
505
+
506
+
507
+
508
+
509
+
510
+
511
+
512
+
513
+
514
+
515
+
516
+
517
+
518
+
519
+
466
520
  * @example
467
521
  * // Add multiple words
468
522
  * const trie = new Trie();
@@ -498,6 +552,30 @@ var Trie = class extends IterableElementBase {
498
552
 
499
553
 
500
554
 
555
+
556
+
557
+
558
+
559
+
560
+
561
+
562
+
563
+
564
+
565
+
566
+
567
+
568
+
569
+
570
+
571
+
572
+
573
+
574
+
575
+
576
+
577
+
578
+
501
579
  * @example
502
580
  * // Check if a word exists
503
581
  * const dict = new Trie(['apple', 'app', 'application']);
@@ -528,6 +606,30 @@ var Trie = class extends IterableElementBase {
528
606
 
529
607
 
530
608
 
609
+
610
+
611
+
612
+
613
+
614
+
615
+
616
+
617
+
618
+
619
+
620
+
621
+
622
+
623
+
624
+
625
+
626
+
627
+
628
+
629
+
630
+
631
+
632
+
531
633
  * @example
532
634
  * // Check if empty
533
635
  * const trie = new Trie();
@@ -550,6 +652,30 @@ var Trie = class extends IterableElementBase {
550
652
 
551
653
 
552
654
 
655
+
656
+
657
+
658
+
659
+
660
+
661
+
662
+
663
+
664
+
665
+
666
+
667
+
668
+
669
+
670
+
671
+
672
+
673
+
674
+
675
+
676
+
677
+
678
+
553
679
  * @example
554
680
  * // Remove all words
555
681
  * const trie = new Trie(['a', 'b', 'c']);
@@ -576,6 +702,30 @@ var Trie = class extends IterableElementBase {
576
702
 
577
703
 
578
704
 
705
+
706
+
707
+
708
+
709
+
710
+
711
+
712
+
713
+
714
+
715
+
716
+
717
+
718
+
719
+
720
+
721
+
722
+
723
+
724
+
725
+
726
+
727
+
728
+
579
729
  * @example
580
730
  * // Trie delete and iteration
581
731
  * const trie = new Trie(['car', 'card', 'care', 'careful', 'can', 'cat']);
@@ -684,6 +834,30 @@ var Trie = class extends IterableElementBase {
684
834
 
685
835
 
686
836
 
837
+
838
+
839
+
840
+
841
+
842
+
843
+
844
+
845
+
846
+
847
+
848
+
849
+
850
+
851
+
852
+
853
+
854
+
855
+
856
+
857
+
858
+
859
+
860
+
687
861
  * @example
688
862
  * // Check if a prefix exists
689
863
  * const trie = new Trie(['hello', 'help', 'world']);
@@ -736,6 +910,30 @@ var Trie = class extends IterableElementBase {
736
910
 
737
911
 
738
912
 
913
+
914
+
915
+
916
+
917
+
918
+
919
+
920
+
921
+
922
+
923
+
924
+
925
+
926
+
927
+
928
+
929
+
930
+
931
+
932
+
933
+
934
+
935
+
936
+
739
937
  * @example
740
938
  * // Find shared prefix
741
939
  * const trie = new Trie(['flower', 'flow', 'flight']);
@@ -771,6 +969,30 @@ var Trie = class extends IterableElementBase {
771
969
 
772
970
 
773
971
 
972
+
973
+
974
+
975
+
976
+
977
+
978
+
979
+
980
+
981
+
982
+
983
+
984
+
985
+
986
+
987
+
988
+
989
+
990
+
991
+
992
+
993
+
994
+
995
+
774
996
  * @example
775
997
  * // Trie getWords and prefix search
776
998
  * const trie = new Trie(['apple', 'app', 'apply', 'application', 'apricot']);
@@ -824,6 +1046,30 @@ var Trie = class extends IterableElementBase {
824
1046
 
825
1047
 
826
1048
 
1049
+
1050
+
1051
+
1052
+
1053
+
1054
+
1055
+
1056
+
1057
+
1058
+
1059
+
1060
+
1061
+
1062
+
1063
+
1064
+
1065
+
1066
+
1067
+
1068
+
1069
+
1070
+
1071
+
1072
+
827
1073
  * @example
828
1074
  * // Create independent copy
829
1075
  * const trie = new Trie(['hello', 'world']);
@@ -850,6 +1096,30 @@ var Trie = class extends IterableElementBase {
850
1096
 
851
1097
 
852
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
+
853
1123
  * @example
854
1124
  * // Filter words
855
1125
  * const trie = new Trie(['cat', 'car', 'dog', 'card']);
@@ -873,7 +1143,7 @@ var Trie = class extends IterableElementBase {
873
1143
  for (const x of this) {
874
1144
  const v = thisArg === void 0 ? callback(x, i++, this) : callback.call(thisArg, x, i++, this);
875
1145
  if (typeof v !== "string") {
876
- throw new TypeError(ERR.callbackReturnType("string", typeof v, "Trie.map"));
1146
+ raise(TypeError, ERR.callbackReturnType("string", typeof v, "Trie.map"));
877
1147
  }
878
1148
  newTrie.add(v);
879
1149
  }
@@ -969,6 +1239,6 @@ var Trie = class extends IterableElementBase {
969
1239
  * @license MIT License
970
1240
  */
971
1241
 
972
- export { DFSOperation, ERR, Range, Trie, TrieNode };
1242
+ export { DFSOperation, ERR, Range, Trie, TrieNode, raise };
973
1243
  //# sourceMappingURL=index.mjs.map
974
1244
  //# sourceMappingURL=index.mjs.map