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
@@ -61,6 +61,60 @@ function makeTrampoline(fn) {
61
61
  }
62
62
  __name(makeTrampoline, "makeTrampoline");
63
63
 
64
+ // src/common/error.ts
65
+ function raise(ErrorClass, message) {
66
+ throw new ErrorClass(message);
67
+ }
68
+ __name(raise, "raise");
69
+ var ERR = {
70
+ // Range / index
71
+ indexOutOfRange: /* @__PURE__ */ __name((index, min, max, ctx) => `${ctx ? ctx + ": " : ""}Index ${index} is out of range [${min}, ${max}].`, "indexOutOfRange"),
72
+ invalidIndex: /* @__PURE__ */ __name((ctx) => `${ctx ? ctx + ": " : ""}Index must be an integer.`, "invalidIndex"),
73
+ // Type / argument
74
+ invalidArgument: /* @__PURE__ */ __name((reason, ctx) => `${ctx ? ctx + ": " : ""}${reason}`, "invalidArgument"),
75
+ comparatorRequired: /* @__PURE__ */ __name((ctx) => `${ctx ? ctx + ": " : ""}Comparator is required for non-number/non-string/non-Date keys.`, "comparatorRequired"),
76
+ invalidKey: /* @__PURE__ */ __name((reason, ctx) => `${ctx ? ctx + ": " : ""}${reason}`, "invalidKey"),
77
+ notAFunction: /* @__PURE__ */ __name((name, ctx) => `${ctx ? ctx + ": " : ""}${name} must be a function.`, "notAFunction"),
78
+ invalidEntry: /* @__PURE__ */ __name((ctx) => `${ctx ? ctx + ": " : ""}Each entry must be a [key, value] tuple.`, "invalidEntry"),
79
+ invalidNaN: /* @__PURE__ */ __name((ctx) => `${ctx ? ctx + ": " : ""}NaN is not a valid key.`, "invalidNaN"),
80
+ invalidDate: /* @__PURE__ */ __name((ctx) => `${ctx ? ctx + ": " : ""}Invalid Date key.`, "invalidDate"),
81
+ reduceEmpty: /* @__PURE__ */ __name((ctx) => `${ctx ? ctx + ": " : ""}Reduce of empty structure with no initial value.`, "reduceEmpty"),
82
+ callbackReturnType: /* @__PURE__ */ __name((expected, got, ctx) => `${ctx ? ctx + ": " : ""}Callback must return ${expected}; got ${got}.`, "callbackReturnType"),
83
+ // State / operation
84
+ invalidOperation: /* @__PURE__ */ __name((reason, ctx) => `${ctx ? ctx + ": " : ""}${reason}`, "invalidOperation"),
85
+ // Matrix
86
+ matrixDimensionMismatch: /* @__PURE__ */ __name((op) => `Matrix: Dimensions must be compatible for ${op}.`, "matrixDimensionMismatch"),
87
+ matrixSingular: /* @__PURE__ */ __name(() => "Matrix: Singular matrix, inverse does not exist.", "matrixSingular"),
88
+ matrixNotSquare: /* @__PURE__ */ __name(() => "Matrix: Must be square for inversion.", "matrixNotSquare"),
89
+ matrixNotRectangular: /* @__PURE__ */ __name(() => "Matrix: Must be rectangular for transposition.", "matrixNotRectangular"),
90
+ matrixRowMismatch: /* @__PURE__ */ __name((expected, got) => `Matrix: Expected row length ${expected}, but got ${got}.`, "matrixRowMismatch"),
91
+ // Order statistic
92
+ orderStatisticNotEnabled: /* @__PURE__ */ __name((method, ctx) => `${ctx ? ctx + ": " : ""}${method}() requires enableOrderStatistic: true.`, "orderStatisticNotEnabled")
93
+ };
94
+
95
+ // src/common/index.ts
96
+ var DFSOperation = /* @__PURE__ */ ((DFSOperation2) => {
97
+ DFSOperation2[DFSOperation2["VISIT"] = 0] = "VISIT";
98
+ DFSOperation2[DFSOperation2["PROCESS"] = 1] = "PROCESS";
99
+ return DFSOperation2;
100
+ })(DFSOperation || {});
101
+ var _Range = class _Range {
102
+ constructor(low, high, includeLow = true, includeHigh = true) {
103
+ this.low = low;
104
+ this.high = high;
105
+ this.includeLow = includeLow;
106
+ this.includeHigh = includeHigh;
107
+ }
108
+ // Determine whether a key is within the range
109
+ isInRange(key, comparator) {
110
+ const lowCheck = this.includeLow ? comparator(key, this.low) >= 0 : comparator(key, this.low) > 0;
111
+ const highCheck = this.includeHigh ? comparator(key, this.high) <= 0 : comparator(key, this.high) < 0;
112
+ return lowCheck && highCheck;
113
+ }
114
+ };
115
+ __name(_Range, "Range");
116
+ var Range = _Range;
117
+
64
118
  // src/data-structures/base/iterable-element-base.ts
65
119
  var _IterableElementBase = class _IterableElementBase {
66
120
  /**
@@ -83,7 +137,7 @@ var _IterableElementBase = class _IterableElementBase {
83
137
  if (options) {
84
138
  const { toElementFn } = options;
85
139
  if (typeof toElementFn === "function") this._toElementFn = toElementFn;
86
- else if (toElementFn) throw new TypeError("toElementFn must be a function type");
140
+ else if (toElementFn) raise(TypeError, "toElementFn must be a function type");
87
141
  }
88
142
  }
89
143
  /**
@@ -239,7 +293,7 @@ var _IterableElementBase = class _IterableElementBase {
239
293
  acc = initialValue;
240
294
  } else {
241
295
  const first = iter.next();
242
- 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");
243
297
  acc = first.value;
244
298
  index = 1;
245
299
  }
@@ -475,54 +529,6 @@ var _LinearBase = class _LinearBase extends IterableElementBase {
475
529
  __name(_LinearBase, "LinearBase");
476
530
  var LinearBase = _LinearBase;
477
531
 
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 _Range {
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
- // Determine whether a key is within the range
517
- isInRange(key, comparator) {
518
- const lowCheck = this.includeLow ? comparator(key, this.low) >= 0 : comparator(key, this.low) > 0;
519
- const highCheck = this.includeHigh ? comparator(key, this.high) <= 0 : comparator(key, this.high) < 0;
520
- return lowCheck && highCheck;
521
- }
522
- };
523
- __name(_Range, "Range");
524
- var Range = _Range;
525
-
526
532
  // src/data-structures/base/iterable-entry-base.ts
527
533
  var _IterableEntryBase = class _IterableEntryBase {
528
534
  /**
@@ -789,6 +795,9 @@ var _Queue = class _Queue extends LinearBase {
789
795
 
790
796
 
791
797
 
798
+
799
+
800
+
792
801
 
793
802
 
794
803
 
@@ -836,6 +845,9 @@ var _Queue = class _Queue extends LinearBase {
836
845
 
837
846
 
838
847
 
848
+
849
+
850
+
839
851
 
840
852
 
841
853
 
@@ -899,6 +911,9 @@ var _Queue = class _Queue extends LinearBase {
899
911
 
900
912
 
901
913
 
914
+
915
+
916
+
902
917
 
903
918
 
904
919
 
@@ -958,6 +973,9 @@ var _Queue = class _Queue extends LinearBase {
958
973
 
959
974
 
960
975
 
976
+
977
+
978
+
961
979
 
962
980
 
963
981
 
@@ -1024,6 +1042,9 @@ var _Queue = class _Queue extends LinearBase {
1024
1042
 
1025
1043
 
1026
1044
 
1045
+
1046
+
1047
+
1027
1048
 
1028
1049
 
1029
1050
 
@@ -1080,6 +1101,9 @@ var _Queue = class _Queue extends LinearBase {
1080
1101
 
1081
1102
 
1082
1103
 
1104
+
1105
+
1106
+
1083
1107
 
1084
1108
 
1085
1109
 
@@ -1129,6 +1153,9 @@ var _Queue = class _Queue extends LinearBase {
1129
1153
 
1130
1154
 
1131
1155
 
1156
+
1157
+
1158
+
1132
1159
 
1133
1160
 
1134
1161
 
@@ -1219,6 +1246,9 @@ var _Queue = class _Queue extends LinearBase {
1219
1246
 
1220
1247
 
1221
1248
 
1249
+
1250
+
1251
+
1222
1252
 
1223
1253
 
1224
1254
 
@@ -1262,6 +1292,9 @@ var _Queue = class _Queue extends LinearBase {
1262
1292
 
1263
1293
 
1264
1294
 
1295
+
1296
+
1297
+
1265
1298
 
1266
1299
 
1267
1300
 
@@ -1328,6 +1361,9 @@ var _Queue = class _Queue extends LinearBase {
1328
1361
 
1329
1362
 
1330
1363
 
1364
+
1365
+
1366
+
1331
1367
 
1332
1368
 
1333
1369
 
@@ -1378,6 +1414,9 @@ var _Queue = class _Queue extends LinearBase {
1378
1414
 
1379
1415
 
1380
1416
 
1417
+
1418
+
1419
+
1381
1420
 
1382
1421
 
1383
1422
 
@@ -1432,6 +1471,9 @@ var _Queue = class _Queue extends LinearBase {
1432
1471
 
1433
1472
 
1434
1473
 
1474
+
1475
+
1476
+
1435
1477
 
1436
1478
 
1437
1479
 
@@ -1704,7 +1746,7 @@ var _BinaryTree = class _BinaryTree extends IterableEntryBase {
1704
1746
  if (isMapMode !== void 0) this._isMapMode = isMapMode;
1705
1747
  if (isDuplicate !== void 0) this._isDuplicate = isDuplicate;
1706
1748
  if (typeof toEntryFn === "function") this._toEntryFn = toEntryFn;
1707
- else if (toEntryFn) throw new TypeError(ERR.notAFunction("toEntryFn", "BinaryTree"));
1749
+ else if (toEntryFn) raise(TypeError, ERR.notAFunction("toEntryFn", "BinaryTree"));
1708
1750
  }
1709
1751
  if (keysNodesEntriesOrRaws) this.setMany(keysNodesEntriesOrRaws);
1710
1752
  }
@@ -1937,6 +1979,9 @@ var _BinaryTree = class _BinaryTree extends IterableEntryBase {
1937
1979
 
1938
1980
 
1939
1981
 
1982
+
1983
+
1984
+
1940
1985
 
1941
1986
 
1942
1987
 
@@ -1988,6 +2033,9 @@ var _BinaryTree = class _BinaryTree extends IterableEntryBase {
1988
2033
 
1989
2034
 
1990
2035
 
2036
+
2037
+
2038
+
1991
2039
 
1992
2040
 
1993
2041
 
@@ -2091,6 +2139,9 @@ var _BinaryTree = class _BinaryTree extends IterableEntryBase {
2091
2139
 
2092
2140
 
2093
2141
 
2142
+
2143
+
2144
+
2094
2145
 
2095
2146
 
2096
2147
 
@@ -2130,6 +2181,9 @@ var _BinaryTree = class _BinaryTree extends IterableEntryBase {
2130
2181
 
2131
2182
 
2132
2183
 
2184
+
2185
+
2186
+
2133
2187
 
2134
2188
 
2135
2189
 
@@ -2190,6 +2244,9 @@ var _BinaryTree = class _BinaryTree extends IterableEntryBase {
2190
2244
 
2191
2245
 
2192
2246
 
2247
+
2248
+
2249
+
2193
2250
 
2194
2251
 
2195
2252
 
@@ -2249,6 +2306,9 @@ var _BinaryTree = class _BinaryTree extends IterableEntryBase {
2249
2306
 
2250
2307
 
2251
2308
 
2309
+
2310
+
2311
+
2252
2312
 
2253
2313
 
2254
2314
 
@@ -2386,6 +2446,9 @@ var _BinaryTree = class _BinaryTree extends IterableEntryBase {
2386
2446
 
2387
2447
 
2388
2448
 
2449
+
2450
+
2451
+
2389
2452
 
2390
2453
 
2391
2454
 
@@ -2441,6 +2504,9 @@ var _BinaryTree = class _BinaryTree extends IterableEntryBase {
2441
2504
 
2442
2505
 
2443
2506
 
2507
+
2508
+
2509
+
2444
2510
 
2445
2511
 
2446
2512
 
@@ -2499,6 +2565,9 @@ var _BinaryTree = class _BinaryTree extends IterableEntryBase {
2499
2565
 
2500
2566
 
2501
2567
 
2568
+
2569
+
2570
+
2502
2571
 
2503
2572
 
2504
2573
 
@@ -2544,6 +2613,9 @@ var _BinaryTree = class _BinaryTree extends IterableEntryBase {
2544
2613
 
2545
2614
 
2546
2615
 
2616
+
2617
+
2618
+
2547
2619
 
2548
2620
 
2549
2621
 
@@ -2598,6 +2670,9 @@ var _BinaryTree = class _BinaryTree extends IterableEntryBase {
2598
2670
 
2599
2671
 
2600
2672
 
2673
+
2674
+
2675
+
2601
2676
 
2602
2677
 
2603
2678
 
@@ -2679,6 +2754,9 @@ var _BinaryTree = class _BinaryTree extends IterableEntryBase {
2679
2754
 
2680
2755
 
2681
2756
 
2757
+
2758
+
2759
+
2682
2760
 
2683
2761
 
2684
2762
 
@@ -2737,6 +2815,9 @@ var _BinaryTree = class _BinaryTree extends IterableEntryBase {
2737
2815
 
2738
2816
 
2739
2817
 
2818
+
2819
+
2820
+
2740
2821
 
2741
2822
 
2742
2823
 
@@ -3211,6 +3292,9 @@ var _BinaryTree = class _BinaryTree extends IterableEntryBase {
3211
3292
 
3212
3293
 
3213
3294
 
3295
+
3296
+
3297
+
3214
3298
 
3215
3299
 
3216
3300
 
@@ -3260,6 +3344,9 @@ var _BinaryTree = class _BinaryTree extends IterableEntryBase {
3260
3344
 
3261
3345
 
3262
3346
 
3347
+
3348
+
3349
+
3263
3350
 
3264
3351
 
3265
3352
 
@@ -3313,6 +3400,9 @@ var _BinaryTree = class _BinaryTree extends IterableEntryBase {
3313
3400
 
3314
3401
 
3315
3402
 
3403
+
3404
+
3405
+
3316
3406
 
3317
3407
 
3318
3408
 
@@ -3391,6 +3481,9 @@ var _BinaryTree = class _BinaryTree extends IterableEntryBase {
3391
3481
 
3392
3482
 
3393
3483
 
3484
+
3485
+
3486
+
3394
3487
 
3395
3488
 
3396
3489
 
@@ -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