binary-tree-typed 2.5.1 → 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 (73) hide show
  1. package/dist/cjs/index.cjs +146 -52
  2. package/dist/cjs/index.cjs.map +1 -1
  3. package/dist/cjs-legacy/index.cjs +145 -51
  4. package/dist/cjs-legacy/index.cjs.map +1 -1
  5. package/dist/esm/index.mjs +146 -53
  6. package/dist/esm/index.mjs.map +1 -1
  7. package/dist/esm-legacy/index.mjs +145 -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/binary-tree/avl-tree.d.ts +36 -0
  12. package/dist/types/data-structures/binary-tree/binary-indexed-tree.d.ts +42 -0
  13. package/dist/types/data-structures/binary-tree/binary-tree.d.ts +77 -2
  14. package/dist/types/data-structures/binary-tree/bst.d.ts +171 -0
  15. package/dist/types/data-structures/binary-tree/red-black-tree.d.ts +57 -0
  16. package/dist/types/data-structures/binary-tree/segment-tree.d.ts +18 -0
  17. package/dist/types/data-structures/binary-tree/tree-map.d.ts +409 -0
  18. package/dist/types/data-structures/binary-tree/tree-multi-map.d.ts +411 -6
  19. package/dist/types/data-structures/binary-tree/tree-multi-set.d.ts +339 -6
  20. package/dist/types/data-structures/binary-tree/tree-set.d.ts +391 -0
  21. package/dist/types/data-structures/graph/directed-graph.d.ts +30 -0
  22. package/dist/types/data-structures/graph/undirected-graph.d.ts +27 -0
  23. package/dist/types/data-structures/hash/hash-map.d.ts +33 -0
  24. package/dist/types/data-structures/heap/heap.d.ts +42 -0
  25. package/dist/types/data-structures/linked-list/doubly-linked-list.d.ts +51 -0
  26. package/dist/types/data-structures/linked-list/singly-linked-list.d.ts +45 -0
  27. package/dist/types/data-structures/linked-list/skip-linked-list.d.ts +54 -0
  28. package/dist/types/data-structures/matrix/matrix.d.ts +24 -0
  29. package/dist/types/data-structures/queue/deque.d.ts +45 -0
  30. package/dist/types/data-structures/queue/queue.d.ts +36 -0
  31. package/dist/types/data-structures/stack/stack.d.ts +30 -0
  32. package/dist/types/data-structures/trie/trie.d.ts +36 -0
  33. package/dist/types/types/data-structures/binary-tree/bst.d.ts +1 -0
  34. package/dist/types/types/data-structures/binary-tree/tree-map.d.ts +5 -0
  35. package/dist/types/types/data-structures/binary-tree/tree-multi-set.d.ts +4 -0
  36. package/dist/types/types/data-structures/binary-tree/tree-set.d.ts +4 -0
  37. package/dist/umd/binary-tree-typed.js +143 -50
  38. package/dist/umd/binary-tree-typed.js.map +1 -1
  39. package/dist/umd/binary-tree-typed.min.js +3 -3
  40. package/dist/umd/binary-tree-typed.min.js.map +1 -1
  41. package/package.json +2 -2
  42. package/src/common/error.ts +19 -1
  43. package/src/common/index.ts +1 -1
  44. package/src/data-structures/base/iterable-element-base.ts +3 -2
  45. package/src/data-structures/binary-tree/avl-tree.ts +47 -0
  46. package/src/data-structures/binary-tree/binary-indexed-tree.ts +46 -4
  47. package/src/data-structures/binary-tree/binary-tree.ts +79 -4
  48. package/src/data-structures/binary-tree/bst.ts +441 -6
  49. package/src/data-structures/binary-tree/red-black-tree.ts +73 -0
  50. package/src/data-structures/binary-tree/segment-tree.ts +18 -0
  51. package/src/data-structures/binary-tree/tree-map.ts +434 -9
  52. package/src/data-structures/binary-tree/tree-multi-map.ts +426 -5
  53. package/src/data-structures/binary-tree/tree-multi-set.ts +350 -6
  54. package/src/data-structures/binary-tree/tree-set.ts +410 -8
  55. package/src/data-structures/graph/abstract-graph.ts +2 -2
  56. package/src/data-structures/graph/directed-graph.ts +30 -0
  57. package/src/data-structures/graph/undirected-graph.ts +27 -0
  58. package/src/data-structures/hash/hash-map.ts +35 -4
  59. package/src/data-structures/heap/heap.ts +46 -4
  60. package/src/data-structures/heap/max-heap.ts +2 -2
  61. package/src/data-structures/linked-list/doubly-linked-list.ts +51 -0
  62. package/src/data-structures/linked-list/singly-linked-list.ts +45 -0
  63. package/src/data-structures/linked-list/skip-linked-list.ts +59 -5
  64. package/src/data-structures/matrix/matrix.ts +33 -9
  65. package/src/data-structures/priority-queue/max-priority-queue.ts +2 -2
  66. package/src/data-structures/queue/deque.ts +45 -0
  67. package/src/data-structures/queue/queue.ts +36 -0
  68. package/src/data-structures/stack/stack.ts +30 -0
  69. package/src/data-structures/trie/trie.ts +38 -2
  70. package/src/types/data-structures/binary-tree/bst.ts +1 -0
  71. package/src/types/data-structures/binary-tree/tree-map.ts +6 -0
  72. package/src/types/data-structures/binary-tree/tree-multi-set.ts +5 -0
  73. package/src/types/data-structures/binary-tree/tree-set.ts +5 -0
@@ -57,6 +57,61 @@ function makeTrampoline(fn) {
57
57
  }
58
58
  __name(makeTrampoline, "makeTrampoline");
59
59
 
60
+ // src/common/error.ts
61
+ function raise(ErrorClass, message) {
62
+ throw new ErrorClass(message);
63
+ }
64
+ __name(raise, "raise");
65
+ var ERR = {
66
+ // Range / index
67
+ indexOutOfRange: /* @__PURE__ */ __name((index, min, max, ctx) => `${ctx ? ctx + ": " : ""}Index ${index} is out of range [${min}, ${max}].`, "indexOutOfRange"),
68
+ invalidIndex: /* @__PURE__ */ __name((ctx) => `${ctx ? ctx + ": " : ""}Index must be an integer.`, "invalidIndex"),
69
+ // Type / argument
70
+ invalidArgument: /* @__PURE__ */ __name((reason, ctx) => `${ctx ? ctx + ": " : ""}${reason}`, "invalidArgument"),
71
+ comparatorRequired: /* @__PURE__ */ __name((ctx) => `${ctx ? ctx + ": " : ""}Comparator is required for non-number/non-string/non-Date keys.`, "comparatorRequired"),
72
+ invalidKey: /* @__PURE__ */ __name((reason, ctx) => `${ctx ? ctx + ": " : ""}${reason}`, "invalidKey"),
73
+ notAFunction: /* @__PURE__ */ __name((name, ctx) => `${ctx ? ctx + ": " : ""}${name} must be a function.`, "notAFunction"),
74
+ invalidEntry: /* @__PURE__ */ __name((ctx) => `${ctx ? ctx + ": " : ""}Each entry must be a [key, value] tuple.`, "invalidEntry"),
75
+ invalidNaN: /* @__PURE__ */ __name((ctx) => `${ctx ? ctx + ": " : ""}NaN is not a valid key.`, "invalidNaN"),
76
+ invalidDate: /* @__PURE__ */ __name((ctx) => `${ctx ? ctx + ": " : ""}Invalid Date key.`, "invalidDate"),
77
+ reduceEmpty: /* @__PURE__ */ __name((ctx) => `${ctx ? ctx + ": " : ""}Reduce of empty structure with no initial value.`, "reduceEmpty"),
78
+ callbackReturnType: /* @__PURE__ */ __name((expected, got, ctx) => `${ctx ? ctx + ": " : ""}Callback must return ${expected}; got ${got}.`, "callbackReturnType"),
79
+ // State / operation
80
+ invalidOperation: /* @__PURE__ */ __name((reason, ctx) => `${ctx ? ctx + ": " : ""}${reason}`, "invalidOperation"),
81
+ // Matrix
82
+ matrixDimensionMismatch: /* @__PURE__ */ __name((op) => `Matrix: Dimensions must be compatible for ${op}.`, "matrixDimensionMismatch"),
83
+ matrixSingular: /* @__PURE__ */ __name(() => "Matrix: Singular matrix, inverse does not exist.", "matrixSingular"),
84
+ matrixNotSquare: /* @__PURE__ */ __name(() => "Matrix: Must be square for inversion.", "matrixNotSquare"),
85
+ matrixNotRectangular: /* @__PURE__ */ __name(() => "Matrix: Must be rectangular for transposition.", "matrixNotRectangular"),
86
+ matrixRowMismatch: /* @__PURE__ */ __name((expected, got) => `Matrix: Expected row length ${expected}, but got ${got}.`, "matrixRowMismatch"),
87
+ // Order statistic
88
+ orderStatisticNotEnabled: /* @__PURE__ */ __name((method, ctx) => `${ctx ? ctx + ": " : ""}${method}() requires enableOrderStatistic: true.`, "orderStatisticNotEnabled")
89
+ };
90
+
91
+ // src/common/index.ts
92
+ var DFSOperation = /* @__PURE__ */ ((DFSOperation2) => {
93
+ DFSOperation2[DFSOperation2["VISIT"] = 0] = "VISIT";
94
+ DFSOperation2[DFSOperation2["PROCESS"] = 1] = "PROCESS";
95
+ return DFSOperation2;
96
+ })(DFSOperation || {});
97
+ var Range = class {
98
+ constructor(low, high, includeLow = true, includeHigh = true) {
99
+ this.low = low;
100
+ this.high = high;
101
+ this.includeLow = includeLow;
102
+ this.includeHigh = includeHigh;
103
+ }
104
+ static {
105
+ __name(this, "Range");
106
+ }
107
+ // Determine whether a key is within the range
108
+ isInRange(key, comparator) {
109
+ const lowCheck = this.includeLow ? comparator(key, this.low) >= 0 : comparator(key, this.low) > 0;
110
+ const highCheck = this.includeHigh ? comparator(key, this.high) <= 0 : comparator(key, this.high) < 0;
111
+ return lowCheck && highCheck;
112
+ }
113
+ };
114
+
60
115
  // src/data-structures/base/iterable-element-base.ts
61
116
  var IterableElementBase = class {
62
117
  static {
@@ -75,7 +130,7 @@ var IterableElementBase = class {
75
130
  if (options) {
76
131
  const { toElementFn } = options;
77
132
  if (typeof toElementFn === "function") this._toElementFn = toElementFn;
78
- else if (toElementFn) throw new TypeError("toElementFn must be a function type");
133
+ else if (toElementFn) raise(TypeError, "toElementFn must be a function type");
79
134
  }
80
135
  }
81
136
  /**
@@ -238,7 +293,7 @@ var IterableElementBase = class {
238
293
  acc = initialValue;
239
294
  } else {
240
295
  const first = iter.next();
241
- if (first.done) throw new TypeError("Reduce of empty structure with no initial value");
296
+ if (first.done) raise(TypeError, "Reduce of empty structure with no initial value");
242
297
  acc = first.value;
243
298
  index = 1;
244
299
  }
@@ -473,55 +528,6 @@ var LinearBase = class _LinearBase extends IterableElementBase {
473
528
  }
474
529
  };
475
530
 
476
- // src/common/error.ts
477
- var ERR = {
478
- // Range / index
479
- indexOutOfRange: /* @__PURE__ */ __name((index, min, max, ctx) => `${ctx ? ctx + ": " : ""}Index ${index} is out of range [${min}, ${max}].`, "indexOutOfRange"),
480
- invalidIndex: /* @__PURE__ */ __name((ctx) => `${ctx ? ctx + ": " : ""}Index must be an integer.`, "invalidIndex"),
481
- // Type / argument
482
- invalidArgument: /* @__PURE__ */ __name((reason, ctx) => `${ctx ? ctx + ": " : ""}${reason}`, "invalidArgument"),
483
- comparatorRequired: /* @__PURE__ */ __name((ctx) => `${ctx ? ctx + ": " : ""}Comparator is required for non-number/non-string/non-Date keys.`, "comparatorRequired"),
484
- invalidKey: /* @__PURE__ */ __name((reason, ctx) => `${ctx ? ctx + ": " : ""}${reason}`, "invalidKey"),
485
- notAFunction: /* @__PURE__ */ __name((name, ctx) => `${ctx ? ctx + ": " : ""}${name} must be a function.`, "notAFunction"),
486
- invalidEntry: /* @__PURE__ */ __name((ctx) => `${ctx ? ctx + ": " : ""}Each entry must be a [key, value] tuple.`, "invalidEntry"),
487
- invalidNaN: /* @__PURE__ */ __name((ctx) => `${ctx ? ctx + ": " : ""}NaN is not a valid key.`, "invalidNaN"),
488
- invalidDate: /* @__PURE__ */ __name((ctx) => `${ctx ? ctx + ": " : ""}Invalid Date key.`, "invalidDate"),
489
- reduceEmpty: /* @__PURE__ */ __name((ctx) => `${ctx ? ctx + ": " : ""}Reduce of empty structure with no initial value.`, "reduceEmpty"),
490
- callbackReturnType: /* @__PURE__ */ __name((expected, got, ctx) => `${ctx ? ctx + ": " : ""}Callback must return ${expected}; got ${got}.`, "callbackReturnType"),
491
- // State / operation
492
- invalidOperation: /* @__PURE__ */ __name((reason, ctx) => `${ctx ? ctx + ": " : ""}${reason}`, "invalidOperation"),
493
- // Matrix
494
- matrixDimensionMismatch: /* @__PURE__ */ __name((op) => `Matrix: Dimensions must be compatible for ${op}.`, "matrixDimensionMismatch"),
495
- matrixSingular: /* @__PURE__ */ __name(() => "Matrix: Singular matrix, inverse does not exist.", "matrixSingular"),
496
- matrixNotSquare: /* @__PURE__ */ __name(() => "Matrix: Must be square for inversion.", "matrixNotSquare"),
497
- matrixNotRectangular: /* @__PURE__ */ __name(() => "Matrix: Must be rectangular for transposition.", "matrixNotRectangular"),
498
- matrixRowMismatch: /* @__PURE__ */ __name((expected, got) => `Matrix: Expected row length ${expected}, but got ${got}.`, "matrixRowMismatch")
499
- };
500
-
501
- // src/common/index.ts
502
- var DFSOperation = /* @__PURE__ */ ((DFSOperation2) => {
503
- DFSOperation2[DFSOperation2["VISIT"] = 0] = "VISIT";
504
- DFSOperation2[DFSOperation2["PROCESS"] = 1] = "PROCESS";
505
- return DFSOperation2;
506
- })(DFSOperation || {});
507
- var Range = class {
508
- constructor(low, high, includeLow = true, includeHigh = true) {
509
- this.low = low;
510
- this.high = high;
511
- this.includeLow = includeLow;
512
- this.includeHigh = includeHigh;
513
- }
514
- static {
515
- __name(this, "Range");
516
- }
517
- // Determine whether a key is within the range
518
- isInRange(key, comparator) {
519
- const lowCheck = this.includeLow ? comparator(key, this.low) >= 0 : comparator(key, this.low) > 0;
520
- const highCheck = this.includeHigh ? comparator(key, this.high) <= 0 : comparator(key, this.high) < 0;
521
- return lowCheck && highCheck;
522
- }
523
- };
524
-
525
531
  // src/data-structures/base/iterable-entry-base.ts
526
532
  var IterableEntryBase = class {
527
533
  static {
@@ -792,6 +798,9 @@ var Queue = class _Queue extends LinearBase {
792
798
 
793
799
 
794
800
 
801
+
802
+
803
+
795
804
 
796
805
 
797
806
 
@@ -839,6 +848,9 @@ var Queue = class _Queue extends LinearBase {
839
848
 
840
849
 
841
850
 
851
+
852
+
853
+
842
854
 
843
855
 
844
856
 
@@ -902,6 +914,9 @@ var Queue = class _Queue extends LinearBase {
902
914
 
903
915
 
904
916
 
917
+
918
+
919
+
905
920
 
906
921
 
907
922
 
@@ -961,6 +976,9 @@ var Queue = class _Queue extends LinearBase {
961
976
 
962
977
 
963
978
 
979
+
980
+
981
+
964
982
 
965
983
 
966
984
 
@@ -1027,6 +1045,9 @@ var Queue = class _Queue extends LinearBase {
1027
1045
 
1028
1046
 
1029
1047
 
1048
+
1049
+
1050
+
1030
1051
 
1031
1052
 
1032
1053
 
@@ -1083,6 +1104,9 @@ var Queue = class _Queue extends LinearBase {
1083
1104
 
1084
1105
 
1085
1106
 
1107
+
1108
+
1109
+
1086
1110
 
1087
1111
 
1088
1112
 
@@ -1132,6 +1156,9 @@ var Queue = class _Queue extends LinearBase {
1132
1156
 
1133
1157
 
1134
1158
 
1159
+
1160
+
1161
+
1135
1162
 
1136
1163
 
1137
1164
 
@@ -1222,6 +1249,9 @@ var Queue = class _Queue extends LinearBase {
1222
1249
 
1223
1250
 
1224
1251
 
1252
+
1253
+
1254
+
1225
1255
 
1226
1256
 
1227
1257
 
@@ -1265,6 +1295,9 @@ var Queue = class _Queue extends LinearBase {
1265
1295
 
1266
1296
 
1267
1297
 
1298
+
1299
+
1300
+
1268
1301
 
1269
1302
 
1270
1303
 
@@ -1331,6 +1364,9 @@ var Queue = class _Queue extends LinearBase {
1331
1364
 
1332
1365
 
1333
1366
 
1367
+
1368
+
1369
+
1334
1370
 
1335
1371
 
1336
1372
 
@@ -1381,6 +1417,9 @@ var Queue = class _Queue extends LinearBase {
1381
1417
 
1382
1418
 
1383
1419
 
1420
+
1421
+
1422
+
1384
1423
 
1385
1424
 
1386
1425
 
@@ -1435,6 +1474,9 @@ var Queue = class _Queue extends LinearBase {
1435
1474
 
1436
1475
 
1437
1476
 
1477
+
1478
+
1479
+
1438
1480
 
1439
1481
 
1440
1482
 
@@ -1689,7 +1731,7 @@ var BinaryTree = class _BinaryTree extends IterableEntryBase {
1689
1731
  if (isMapMode !== void 0) this._isMapMode = isMapMode;
1690
1732
  if (isDuplicate !== void 0) this._isDuplicate = isDuplicate;
1691
1733
  if (typeof toEntryFn === "function") this._toEntryFn = toEntryFn;
1692
- else if (toEntryFn) throw new TypeError(ERR.notAFunction("toEntryFn", "BinaryTree"));
1734
+ else if (toEntryFn) raise(TypeError, ERR.notAFunction("toEntryFn", "BinaryTree"));
1693
1735
  }
1694
1736
  if (keysNodesEntriesOrRaws) this.setMany(keysNodesEntriesOrRaws);
1695
1737
  }
@@ -1932,6 +1974,9 @@ var BinaryTree = class _BinaryTree extends IterableEntryBase {
1932
1974
 
1933
1975
 
1934
1976
 
1977
+
1978
+
1979
+
1935
1980
 
1936
1981
 
1937
1982
 
@@ -1983,6 +2028,9 @@ var BinaryTree = class _BinaryTree extends IterableEntryBase {
1983
2028
 
1984
2029
 
1985
2030
 
2031
+
2032
+
2033
+
1986
2034
 
1987
2035
 
1988
2036
 
@@ -2086,6 +2134,9 @@ var BinaryTree = class _BinaryTree extends IterableEntryBase {
2086
2134
 
2087
2135
 
2088
2136
 
2137
+
2138
+
2139
+
2089
2140
 
2090
2141
 
2091
2142
 
@@ -2125,6 +2176,9 @@ var BinaryTree = class _BinaryTree extends IterableEntryBase {
2125
2176
 
2126
2177
 
2127
2178
 
2179
+
2180
+
2181
+
2128
2182
 
2129
2183
 
2130
2184
 
@@ -2185,6 +2239,9 @@ var BinaryTree = class _BinaryTree extends IterableEntryBase {
2185
2239
 
2186
2240
 
2187
2241
 
2242
+
2243
+
2244
+
2188
2245
 
2189
2246
 
2190
2247
 
@@ -2244,6 +2301,9 @@ var BinaryTree = class _BinaryTree extends IterableEntryBase {
2244
2301
 
2245
2302
 
2246
2303
 
2304
+
2305
+
2306
+
2247
2307
 
2248
2308
 
2249
2309
 
@@ -2381,6 +2441,9 @@ var BinaryTree = class _BinaryTree extends IterableEntryBase {
2381
2441
 
2382
2442
 
2383
2443
 
2444
+
2445
+
2446
+
2384
2447
 
2385
2448
 
2386
2449
 
@@ -2436,6 +2499,9 @@ var BinaryTree = class _BinaryTree extends IterableEntryBase {
2436
2499
 
2437
2500
 
2438
2501
 
2502
+
2503
+
2504
+
2439
2505
 
2440
2506
 
2441
2507
 
@@ -2493,6 +2559,9 @@ var BinaryTree = class _BinaryTree extends IterableEntryBase {
2493
2559
 
2494
2560
 
2495
2561
 
2562
+
2563
+
2564
+
2496
2565
 
2497
2566
 
2498
2567
 
@@ -2538,6 +2607,9 @@ var BinaryTree = class _BinaryTree extends IterableEntryBase {
2538
2607
 
2539
2608
 
2540
2609
 
2610
+
2611
+
2612
+
2541
2613
 
2542
2614
 
2543
2615
 
@@ -2592,6 +2664,9 @@ var BinaryTree = class _BinaryTree extends IterableEntryBase {
2592
2664
 
2593
2665
 
2594
2666
 
2667
+
2668
+
2669
+
2595
2670
 
2596
2671
 
2597
2672
 
@@ -2673,6 +2748,9 @@ var BinaryTree = class _BinaryTree extends IterableEntryBase {
2673
2748
 
2674
2749
 
2675
2750
 
2751
+
2752
+
2753
+
2676
2754
 
2677
2755
 
2678
2756
 
@@ -2731,6 +2809,9 @@ var BinaryTree = class _BinaryTree extends IterableEntryBase {
2731
2809
 
2732
2810
 
2733
2811
 
2812
+
2813
+
2814
+
2734
2815
 
2735
2816
 
2736
2817
 
@@ -3205,6 +3286,9 @@ var BinaryTree = class _BinaryTree extends IterableEntryBase {
3205
3286
 
3206
3287
 
3207
3288
 
3289
+
3290
+
3291
+
3208
3292
 
3209
3293
 
3210
3294
 
@@ -3254,6 +3338,9 @@ var BinaryTree = class _BinaryTree extends IterableEntryBase {
3254
3338
 
3255
3339
 
3256
3340
 
3341
+
3342
+
3343
+
3257
3344
 
3258
3345
 
3259
3346
 
@@ -3307,6 +3394,9 @@ var BinaryTree = class _BinaryTree extends IterableEntryBase {
3307
3394
 
3308
3395
 
3309
3396
 
3397
+
3398
+
3399
+
3310
3400
 
3311
3401
 
3312
3402
 
@@ -3385,6 +3475,9 @@ var BinaryTree = class _BinaryTree extends IterableEntryBase {
3385
3475
 
3386
3476
 
3387
3477
 
3478
+
3479
+
3480
+
3388
3481
 
3389
3482
 
3390
3483
 
@@ -3868,6 +3961,6 @@ var BinaryTree = class _BinaryTree extends IterableEntryBase {
3868
3961
  * @license MIT License
3869
3962
  */
3870
3963
 
3871
- export { BinaryTree, BinaryTreeNode, DFSOperation, ERR, Range };
3964
+ export { BinaryTree, BinaryTreeNode, DFSOperation, ERR, Range, raise };
3872
3965
  //# sourceMappingURL=index.mjs.map
3873
3966
  //# sourceMappingURL=index.mjs.map