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
@@ -59,6 +59,61 @@ function makeTrampoline(fn) {
59
59
  }
60
60
  __name(makeTrampoline, "makeTrampoline");
61
61
 
62
+ // src/common/error.ts
63
+ function raise(ErrorClass, message) {
64
+ throw new ErrorClass(message);
65
+ }
66
+ __name(raise, "raise");
67
+ var ERR = {
68
+ // Range / index
69
+ indexOutOfRange: /* @__PURE__ */ __name((index, min, max, ctx) => `${ctx ? ctx + ": " : ""}Index ${index} is out of range [${min}, ${max}].`, "indexOutOfRange"),
70
+ invalidIndex: /* @__PURE__ */ __name((ctx) => `${ctx ? ctx + ": " : ""}Index must be an integer.`, "invalidIndex"),
71
+ // Type / argument
72
+ invalidArgument: /* @__PURE__ */ __name((reason, ctx) => `${ctx ? ctx + ": " : ""}${reason}`, "invalidArgument"),
73
+ comparatorRequired: /* @__PURE__ */ __name((ctx) => `${ctx ? ctx + ": " : ""}Comparator is required for non-number/non-string/non-Date keys.`, "comparatorRequired"),
74
+ invalidKey: /* @__PURE__ */ __name((reason, ctx) => `${ctx ? ctx + ": " : ""}${reason}`, "invalidKey"),
75
+ notAFunction: /* @__PURE__ */ __name((name, ctx) => `${ctx ? ctx + ": " : ""}${name} must be a function.`, "notAFunction"),
76
+ invalidEntry: /* @__PURE__ */ __name((ctx) => `${ctx ? ctx + ": " : ""}Each entry must be a [key, value] tuple.`, "invalidEntry"),
77
+ invalidNaN: /* @__PURE__ */ __name((ctx) => `${ctx ? ctx + ": " : ""}NaN is not a valid key.`, "invalidNaN"),
78
+ invalidDate: /* @__PURE__ */ __name((ctx) => `${ctx ? ctx + ": " : ""}Invalid Date key.`, "invalidDate"),
79
+ reduceEmpty: /* @__PURE__ */ __name((ctx) => `${ctx ? ctx + ": " : ""}Reduce of empty structure with no initial value.`, "reduceEmpty"),
80
+ callbackReturnType: /* @__PURE__ */ __name((expected, got, ctx) => `${ctx ? ctx + ": " : ""}Callback must return ${expected}; got ${got}.`, "callbackReturnType"),
81
+ // State / operation
82
+ invalidOperation: /* @__PURE__ */ __name((reason, ctx) => `${ctx ? ctx + ": " : ""}${reason}`, "invalidOperation"),
83
+ // Matrix
84
+ matrixDimensionMismatch: /* @__PURE__ */ __name((op) => `Matrix: Dimensions must be compatible for ${op}.`, "matrixDimensionMismatch"),
85
+ matrixSingular: /* @__PURE__ */ __name(() => "Matrix: Singular matrix, inverse does not exist.", "matrixSingular"),
86
+ matrixNotSquare: /* @__PURE__ */ __name(() => "Matrix: Must be square for inversion.", "matrixNotSquare"),
87
+ matrixNotRectangular: /* @__PURE__ */ __name(() => "Matrix: Must be rectangular for transposition.", "matrixNotRectangular"),
88
+ matrixRowMismatch: /* @__PURE__ */ __name((expected, got) => `Matrix: Expected row length ${expected}, but got ${got}.`, "matrixRowMismatch"),
89
+ // Order statistic
90
+ orderStatisticNotEnabled: /* @__PURE__ */ __name((method, ctx) => `${ctx ? ctx + ": " : ""}${method}() requires enableOrderStatistic: true.`, "orderStatisticNotEnabled")
91
+ };
92
+
93
+ // src/common/index.ts
94
+ var DFSOperation = /* @__PURE__ */ ((DFSOperation2) => {
95
+ DFSOperation2[DFSOperation2["VISIT"] = 0] = "VISIT";
96
+ DFSOperation2[DFSOperation2["PROCESS"] = 1] = "PROCESS";
97
+ return DFSOperation2;
98
+ })(DFSOperation || {});
99
+ var Range = class {
100
+ constructor(low, high, includeLow = true, includeHigh = true) {
101
+ this.low = low;
102
+ this.high = high;
103
+ this.includeLow = includeLow;
104
+ this.includeHigh = includeHigh;
105
+ }
106
+ static {
107
+ __name(this, "Range");
108
+ }
109
+ // Determine whether a key is within the range
110
+ isInRange(key, comparator) {
111
+ const lowCheck = this.includeLow ? comparator(key, this.low) >= 0 : comparator(key, this.low) > 0;
112
+ const highCheck = this.includeHigh ? comparator(key, this.high) <= 0 : comparator(key, this.high) < 0;
113
+ return lowCheck && highCheck;
114
+ }
115
+ };
116
+
62
117
  // src/data-structures/base/iterable-element-base.ts
63
118
  var IterableElementBase = class {
64
119
  static {
@@ -77,7 +132,7 @@ var IterableElementBase = class {
77
132
  if (options) {
78
133
  const { toElementFn } = options;
79
134
  if (typeof toElementFn === "function") this._toElementFn = toElementFn;
80
- else if (toElementFn) throw new TypeError("toElementFn must be a function type");
135
+ else if (toElementFn) raise(TypeError, "toElementFn must be a function type");
81
136
  }
82
137
  }
83
138
  /**
@@ -240,7 +295,7 @@ var IterableElementBase = class {
240
295
  acc = initialValue;
241
296
  } else {
242
297
  const first = iter.next();
243
- if (first.done) throw new TypeError("Reduce of empty structure with no initial value");
298
+ if (first.done) raise(TypeError, "Reduce of empty structure with no initial value");
244
299
  acc = first.value;
245
300
  index = 1;
246
301
  }
@@ -475,55 +530,6 @@ var LinearBase = class _LinearBase extends IterableElementBase {
475
530
  }
476
531
  };
477
532
 
478
- // src/common/error.ts
479
- var ERR = {
480
- // Range / index
481
- indexOutOfRange: /* @__PURE__ */ __name((index, min, max, ctx) => `${ctx ? ctx + ": " : ""}Index ${index} is out of range [${min}, ${max}].`, "indexOutOfRange"),
482
- invalidIndex: /* @__PURE__ */ __name((ctx) => `${ctx ? ctx + ": " : ""}Index must be an integer.`, "invalidIndex"),
483
- // Type / argument
484
- invalidArgument: /* @__PURE__ */ __name((reason, ctx) => `${ctx ? ctx + ": " : ""}${reason}`, "invalidArgument"),
485
- comparatorRequired: /* @__PURE__ */ __name((ctx) => `${ctx ? ctx + ": " : ""}Comparator is required for non-number/non-string/non-Date keys.`, "comparatorRequired"),
486
- invalidKey: /* @__PURE__ */ __name((reason, ctx) => `${ctx ? ctx + ": " : ""}${reason}`, "invalidKey"),
487
- notAFunction: /* @__PURE__ */ __name((name, ctx) => `${ctx ? ctx + ": " : ""}${name} must be a function.`, "notAFunction"),
488
- invalidEntry: /* @__PURE__ */ __name((ctx) => `${ctx ? ctx + ": " : ""}Each entry must be a [key, value] tuple.`, "invalidEntry"),
489
- invalidNaN: /* @__PURE__ */ __name((ctx) => `${ctx ? ctx + ": " : ""}NaN is not a valid key.`, "invalidNaN"),
490
- invalidDate: /* @__PURE__ */ __name((ctx) => `${ctx ? ctx + ": " : ""}Invalid Date key.`, "invalidDate"),
491
- reduceEmpty: /* @__PURE__ */ __name((ctx) => `${ctx ? ctx + ": " : ""}Reduce of empty structure with no initial value.`, "reduceEmpty"),
492
- callbackReturnType: /* @__PURE__ */ __name((expected, got, ctx) => `${ctx ? ctx + ": " : ""}Callback must return ${expected}; got ${got}.`, "callbackReturnType"),
493
- // State / operation
494
- invalidOperation: /* @__PURE__ */ __name((reason, ctx) => `${ctx ? ctx + ": " : ""}${reason}`, "invalidOperation"),
495
- // Matrix
496
- matrixDimensionMismatch: /* @__PURE__ */ __name((op) => `Matrix: Dimensions must be compatible for ${op}.`, "matrixDimensionMismatch"),
497
- matrixSingular: /* @__PURE__ */ __name(() => "Matrix: Singular matrix, inverse does not exist.", "matrixSingular"),
498
- matrixNotSquare: /* @__PURE__ */ __name(() => "Matrix: Must be square for inversion.", "matrixNotSquare"),
499
- matrixNotRectangular: /* @__PURE__ */ __name(() => "Matrix: Must be rectangular for transposition.", "matrixNotRectangular"),
500
- matrixRowMismatch: /* @__PURE__ */ __name((expected, got) => `Matrix: Expected row length ${expected}, but got ${got}.`, "matrixRowMismatch")
501
- };
502
-
503
- // src/common/index.ts
504
- var DFSOperation = /* @__PURE__ */ ((DFSOperation2) => {
505
- DFSOperation2[DFSOperation2["VISIT"] = 0] = "VISIT";
506
- DFSOperation2[DFSOperation2["PROCESS"] = 1] = "PROCESS";
507
- return DFSOperation2;
508
- })(DFSOperation || {});
509
- var Range = class {
510
- constructor(low, high, includeLow = true, includeHigh = true) {
511
- this.low = low;
512
- this.high = high;
513
- this.includeLow = includeLow;
514
- this.includeHigh = includeHigh;
515
- }
516
- static {
517
- __name(this, "Range");
518
- }
519
- // Determine whether a key is within the range
520
- isInRange(key, comparator) {
521
- const lowCheck = this.includeLow ? comparator(key, this.low) >= 0 : comparator(key, this.low) > 0;
522
- const highCheck = this.includeHigh ? comparator(key, this.high) <= 0 : comparator(key, this.high) < 0;
523
- return lowCheck && highCheck;
524
- }
525
- };
526
-
527
533
  // src/data-structures/base/iterable-entry-base.ts
528
534
  var IterableEntryBase = class {
529
535
  static {
@@ -794,6 +800,9 @@ var Queue = class _Queue extends LinearBase {
794
800
 
795
801
 
796
802
 
803
+
804
+
805
+
797
806
 
798
807
 
799
808
 
@@ -841,6 +850,9 @@ var Queue = class _Queue extends LinearBase {
841
850
 
842
851
 
843
852
 
853
+
854
+
855
+
844
856
 
845
857
 
846
858
 
@@ -904,6 +916,9 @@ var Queue = class _Queue extends LinearBase {
904
916
 
905
917
 
906
918
 
919
+
920
+
921
+
907
922
 
908
923
 
909
924
 
@@ -963,6 +978,9 @@ var Queue = class _Queue extends LinearBase {
963
978
 
964
979
 
965
980
 
981
+
982
+
983
+
966
984
 
967
985
 
968
986
 
@@ -1029,6 +1047,9 @@ var Queue = class _Queue extends LinearBase {
1029
1047
 
1030
1048
 
1031
1049
 
1050
+
1051
+
1052
+
1032
1053
 
1033
1054
 
1034
1055
 
@@ -1085,6 +1106,9 @@ var Queue = class _Queue extends LinearBase {
1085
1106
 
1086
1107
 
1087
1108
 
1109
+
1110
+
1111
+
1088
1112
 
1089
1113
 
1090
1114
 
@@ -1134,6 +1158,9 @@ var Queue = class _Queue extends LinearBase {
1134
1158
 
1135
1159
 
1136
1160
 
1161
+
1162
+
1163
+
1137
1164
 
1138
1165
 
1139
1166
 
@@ -1224,6 +1251,9 @@ var Queue = class _Queue extends LinearBase {
1224
1251
 
1225
1252
 
1226
1253
 
1254
+
1255
+
1256
+
1227
1257
 
1228
1258
 
1229
1259
 
@@ -1267,6 +1297,9 @@ var Queue = class _Queue extends LinearBase {
1267
1297
 
1268
1298
 
1269
1299
 
1300
+
1301
+
1302
+
1270
1303
 
1271
1304
 
1272
1305
 
@@ -1333,6 +1366,9 @@ var Queue = class _Queue extends LinearBase {
1333
1366
 
1334
1367
 
1335
1368
 
1369
+
1370
+
1371
+
1336
1372
 
1337
1373
 
1338
1374
 
@@ -1383,6 +1419,9 @@ var Queue = class _Queue extends LinearBase {
1383
1419
 
1384
1420
 
1385
1421
 
1422
+
1423
+
1424
+
1386
1425
 
1387
1426
 
1388
1427
 
@@ -1437,6 +1476,9 @@ var Queue = class _Queue extends LinearBase {
1437
1476
 
1438
1477
 
1439
1478
 
1479
+
1480
+
1481
+
1440
1482
 
1441
1483
 
1442
1484
 
@@ -1691,7 +1733,7 @@ var BinaryTree = class _BinaryTree extends IterableEntryBase {
1691
1733
  if (isMapMode !== void 0) this._isMapMode = isMapMode;
1692
1734
  if (isDuplicate !== void 0) this._isDuplicate = isDuplicate;
1693
1735
  if (typeof toEntryFn === "function") this._toEntryFn = toEntryFn;
1694
- else if (toEntryFn) throw new TypeError(ERR.notAFunction("toEntryFn", "BinaryTree"));
1736
+ else if (toEntryFn) raise(TypeError, ERR.notAFunction("toEntryFn", "BinaryTree"));
1695
1737
  }
1696
1738
  if (keysNodesEntriesOrRaws) this.setMany(keysNodesEntriesOrRaws);
1697
1739
  }
@@ -1934,6 +1976,9 @@ var BinaryTree = class _BinaryTree extends IterableEntryBase {
1934
1976
 
1935
1977
 
1936
1978
 
1979
+
1980
+
1981
+
1937
1982
 
1938
1983
 
1939
1984
 
@@ -1985,6 +2030,9 @@ var BinaryTree = class _BinaryTree extends IterableEntryBase {
1985
2030
 
1986
2031
 
1987
2032
 
2033
+
2034
+
2035
+
1988
2036
 
1989
2037
 
1990
2038
 
@@ -2088,6 +2136,9 @@ var BinaryTree = class _BinaryTree extends IterableEntryBase {
2088
2136
 
2089
2137
 
2090
2138
 
2139
+
2140
+
2141
+
2091
2142
 
2092
2143
 
2093
2144
 
@@ -2127,6 +2178,9 @@ var BinaryTree = class _BinaryTree extends IterableEntryBase {
2127
2178
 
2128
2179
 
2129
2180
 
2181
+
2182
+
2183
+
2130
2184
 
2131
2185
 
2132
2186
 
@@ -2187,6 +2241,9 @@ var BinaryTree = class _BinaryTree extends IterableEntryBase {
2187
2241
 
2188
2242
 
2189
2243
 
2244
+
2245
+
2246
+
2190
2247
 
2191
2248
 
2192
2249
 
@@ -2246,6 +2303,9 @@ var BinaryTree = class _BinaryTree extends IterableEntryBase {
2246
2303
 
2247
2304
 
2248
2305
 
2306
+
2307
+
2308
+
2249
2309
 
2250
2310
 
2251
2311
 
@@ -2383,6 +2443,9 @@ var BinaryTree = class _BinaryTree extends IterableEntryBase {
2383
2443
 
2384
2444
 
2385
2445
 
2446
+
2447
+
2448
+
2386
2449
 
2387
2450
 
2388
2451
 
@@ -2438,6 +2501,9 @@ var BinaryTree = class _BinaryTree extends IterableEntryBase {
2438
2501
 
2439
2502
 
2440
2503
 
2504
+
2505
+
2506
+
2441
2507
 
2442
2508
 
2443
2509
 
@@ -2495,6 +2561,9 @@ var BinaryTree = class _BinaryTree extends IterableEntryBase {
2495
2561
 
2496
2562
 
2497
2563
 
2564
+
2565
+
2566
+
2498
2567
 
2499
2568
 
2500
2569
 
@@ -2540,6 +2609,9 @@ var BinaryTree = class _BinaryTree extends IterableEntryBase {
2540
2609
 
2541
2610
 
2542
2611
 
2612
+
2613
+
2614
+
2543
2615
 
2544
2616
 
2545
2617
 
@@ -2594,6 +2666,9 @@ var BinaryTree = class _BinaryTree extends IterableEntryBase {
2594
2666
 
2595
2667
 
2596
2668
 
2669
+
2670
+
2671
+
2597
2672
 
2598
2673
 
2599
2674
 
@@ -2675,6 +2750,9 @@ var BinaryTree = class _BinaryTree extends IterableEntryBase {
2675
2750
 
2676
2751
 
2677
2752
 
2753
+
2754
+
2755
+
2678
2756
 
2679
2757
 
2680
2758
 
@@ -2733,6 +2811,9 @@ var BinaryTree = class _BinaryTree extends IterableEntryBase {
2733
2811
 
2734
2812
 
2735
2813
 
2814
+
2815
+
2816
+
2736
2817
 
2737
2818
 
2738
2819
 
@@ -3207,6 +3288,9 @@ var BinaryTree = class _BinaryTree extends IterableEntryBase {
3207
3288
 
3208
3289
 
3209
3290
 
3291
+
3292
+
3293
+
3210
3294
 
3211
3295
 
3212
3296
 
@@ -3256,6 +3340,9 @@ var BinaryTree = class _BinaryTree extends IterableEntryBase {
3256
3340
 
3257
3341
 
3258
3342
 
3343
+
3344
+
3345
+
3259
3346
 
3260
3347
 
3261
3348
 
@@ -3309,6 +3396,9 @@ var BinaryTree = class _BinaryTree extends IterableEntryBase {
3309
3396
 
3310
3397
 
3311
3398
 
3399
+
3400
+
3401
+
3312
3402
 
3313
3403
 
3314
3404
 
@@ -3387,6 +3477,9 @@ var BinaryTree = class _BinaryTree extends IterableEntryBase {
3387
3477
 
3388
3478
 
3389
3479
 
3480
+
3481
+
3482
+
3390
3483
 
3391
3484
 
3392
3485
 
@@ -3875,5 +3968,6 @@ exports.BinaryTreeNode = BinaryTreeNode;
3875
3968
  exports.DFSOperation = DFSOperation;
3876
3969
  exports.ERR = ERR;
3877
3970
  exports.Range = Range;
3971
+ exports.raise = raise;
3878
3972
  //# sourceMappingURL=index.cjs.map
3879
3973
  //# sourceMappingURL=index.cjs.map