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,60 @@ 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 _Range {
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
+ // Determine whether a key is within the range
107
+ isInRange(key, comparator) {
108
+ const lowCheck = this.includeLow ? comparator(key, this.low) >= 0 : comparator(key, this.low) > 0;
109
+ const highCheck = this.includeHigh ? comparator(key, this.high) <= 0 : comparator(key, this.high) < 0;
110
+ return lowCheck && highCheck;
111
+ }
112
+ };
113
+ __name(_Range, "Range");
114
+ var Range = _Range;
115
+
62
116
  // src/data-structures/base/iterable-element-base.ts
63
117
  var _IterableElementBase = class _IterableElementBase {
64
118
  /**
@@ -81,7 +135,7 @@ var _IterableElementBase = class _IterableElementBase {
81
135
  if (options) {
82
136
  const { toElementFn } = options;
83
137
  if (typeof toElementFn === "function") this._toElementFn = toElementFn;
84
- else if (toElementFn) throw new TypeError("toElementFn must be a function type");
138
+ else if (toElementFn) raise(TypeError, "toElementFn must be a function type");
85
139
  }
86
140
  }
87
141
  /**
@@ -237,7 +291,7 @@ var _IterableElementBase = class _IterableElementBase {
237
291
  acc = initialValue;
238
292
  } else {
239
293
  const first = iter.next();
240
- if (first.done) throw new TypeError("Reduce of empty structure with no initial value");
294
+ if (first.done) raise(TypeError, "Reduce of empty structure with no initial value");
241
295
  acc = first.value;
242
296
  index = 1;
243
297
  }
@@ -473,54 +527,6 @@ var _LinearBase = class _LinearBase extends IterableElementBase {
473
527
  __name(_LinearBase, "LinearBase");
474
528
  var LinearBase = _LinearBase;
475
529
 
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 _Range {
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
- // Determine whether a key is within the range
515
- isInRange(key, comparator) {
516
- const lowCheck = this.includeLow ? comparator(key, this.low) >= 0 : comparator(key, this.low) > 0;
517
- const highCheck = this.includeHigh ? comparator(key, this.high) <= 0 : comparator(key, this.high) < 0;
518
- return lowCheck && highCheck;
519
- }
520
- };
521
- __name(_Range, "Range");
522
- var Range = _Range;
523
-
524
530
  // src/data-structures/base/iterable-entry-base.ts
525
531
  var _IterableEntryBase = class _IterableEntryBase {
526
532
  /**
@@ -787,6 +793,9 @@ var _Queue = class _Queue extends LinearBase {
787
793
 
788
794
 
789
795
 
796
+
797
+
798
+
790
799
 
791
800
 
792
801
 
@@ -834,6 +843,9 @@ var _Queue = class _Queue extends LinearBase {
834
843
 
835
844
 
836
845
 
846
+
847
+
848
+
837
849
 
838
850
 
839
851
 
@@ -897,6 +909,9 @@ var _Queue = class _Queue extends LinearBase {
897
909
 
898
910
 
899
911
 
912
+
913
+
914
+
900
915
 
901
916
 
902
917
 
@@ -956,6 +971,9 @@ var _Queue = class _Queue extends LinearBase {
956
971
 
957
972
 
958
973
 
974
+
975
+
976
+
959
977
 
960
978
 
961
979
 
@@ -1022,6 +1040,9 @@ var _Queue = class _Queue extends LinearBase {
1022
1040
 
1023
1041
 
1024
1042
 
1043
+
1044
+
1045
+
1025
1046
 
1026
1047
 
1027
1048
 
@@ -1078,6 +1099,9 @@ var _Queue = class _Queue extends LinearBase {
1078
1099
 
1079
1100
 
1080
1101
 
1102
+
1103
+
1104
+
1081
1105
 
1082
1106
 
1083
1107
 
@@ -1127,6 +1151,9 @@ var _Queue = class _Queue extends LinearBase {
1127
1151
 
1128
1152
 
1129
1153
 
1154
+
1155
+
1156
+
1130
1157
 
1131
1158
 
1132
1159
 
@@ -1217,6 +1244,9 @@ var _Queue = class _Queue extends LinearBase {
1217
1244
 
1218
1245
 
1219
1246
 
1247
+
1248
+
1249
+
1220
1250
 
1221
1251
 
1222
1252
 
@@ -1260,6 +1290,9 @@ var _Queue = class _Queue extends LinearBase {
1260
1290
 
1261
1291
 
1262
1292
 
1293
+
1294
+
1295
+
1263
1296
 
1264
1297
 
1265
1298
 
@@ -1326,6 +1359,9 @@ var _Queue = class _Queue extends LinearBase {
1326
1359
 
1327
1360
 
1328
1361
 
1362
+
1363
+
1364
+
1329
1365
 
1330
1366
 
1331
1367
 
@@ -1376,6 +1412,9 @@ var _Queue = class _Queue extends LinearBase {
1376
1412
 
1377
1413
 
1378
1414
 
1415
+
1416
+
1417
+
1379
1418
 
1380
1419
 
1381
1420
 
@@ -1430,6 +1469,9 @@ var _Queue = class _Queue extends LinearBase {
1430
1469
 
1431
1470
 
1432
1471
 
1472
+
1473
+
1474
+
1433
1475
 
1434
1476
 
1435
1477
 
@@ -1702,7 +1744,7 @@ var _BinaryTree = class _BinaryTree extends IterableEntryBase {
1702
1744
  if (isMapMode !== void 0) this._isMapMode = isMapMode;
1703
1745
  if (isDuplicate !== void 0) this._isDuplicate = isDuplicate;
1704
1746
  if (typeof toEntryFn === "function") this._toEntryFn = toEntryFn;
1705
- else if (toEntryFn) throw new TypeError(ERR.notAFunction("toEntryFn", "BinaryTree"));
1747
+ else if (toEntryFn) raise(TypeError, ERR.notAFunction("toEntryFn", "BinaryTree"));
1706
1748
  }
1707
1749
  if (keysNodesEntriesOrRaws) this.setMany(keysNodesEntriesOrRaws);
1708
1750
  }
@@ -1935,6 +1977,9 @@ var _BinaryTree = class _BinaryTree extends IterableEntryBase {
1935
1977
 
1936
1978
 
1937
1979
 
1980
+
1981
+
1982
+
1938
1983
 
1939
1984
 
1940
1985
 
@@ -1986,6 +2031,9 @@ var _BinaryTree = class _BinaryTree extends IterableEntryBase {
1986
2031
 
1987
2032
 
1988
2033
 
2034
+
2035
+
2036
+
1989
2037
 
1990
2038
 
1991
2039
 
@@ -2089,6 +2137,9 @@ var _BinaryTree = class _BinaryTree extends IterableEntryBase {
2089
2137
 
2090
2138
 
2091
2139
 
2140
+
2141
+
2142
+
2092
2143
 
2093
2144
 
2094
2145
 
@@ -2128,6 +2179,9 @@ var _BinaryTree = class _BinaryTree extends IterableEntryBase {
2128
2179
 
2129
2180
 
2130
2181
 
2182
+
2183
+
2184
+
2131
2185
 
2132
2186
 
2133
2187
 
@@ -2188,6 +2242,9 @@ var _BinaryTree = class _BinaryTree extends IterableEntryBase {
2188
2242
 
2189
2243
 
2190
2244
 
2245
+
2246
+
2247
+
2191
2248
 
2192
2249
 
2193
2250
 
@@ -2247,6 +2304,9 @@ var _BinaryTree = class _BinaryTree extends IterableEntryBase {
2247
2304
 
2248
2305
 
2249
2306
 
2307
+
2308
+
2309
+
2250
2310
 
2251
2311
 
2252
2312
 
@@ -2384,6 +2444,9 @@ var _BinaryTree = class _BinaryTree extends IterableEntryBase {
2384
2444
 
2385
2445
 
2386
2446
 
2447
+
2448
+
2449
+
2387
2450
 
2388
2451
 
2389
2452
 
@@ -2439,6 +2502,9 @@ var _BinaryTree = class _BinaryTree extends IterableEntryBase {
2439
2502
 
2440
2503
 
2441
2504
 
2505
+
2506
+
2507
+
2442
2508
 
2443
2509
 
2444
2510
 
@@ -2497,6 +2563,9 @@ var _BinaryTree = class _BinaryTree extends IterableEntryBase {
2497
2563
 
2498
2564
 
2499
2565
 
2566
+
2567
+
2568
+
2500
2569
 
2501
2570
 
2502
2571
 
@@ -2542,6 +2611,9 @@ var _BinaryTree = class _BinaryTree extends IterableEntryBase {
2542
2611
 
2543
2612
 
2544
2613
 
2614
+
2615
+
2616
+
2545
2617
 
2546
2618
 
2547
2619
 
@@ -2596,6 +2668,9 @@ var _BinaryTree = class _BinaryTree extends IterableEntryBase {
2596
2668
 
2597
2669
 
2598
2670
 
2671
+
2672
+
2673
+
2599
2674
 
2600
2675
 
2601
2676
 
@@ -2677,6 +2752,9 @@ var _BinaryTree = class _BinaryTree extends IterableEntryBase {
2677
2752
 
2678
2753
 
2679
2754
 
2755
+
2756
+
2757
+
2680
2758
 
2681
2759
 
2682
2760
 
@@ -2735,6 +2813,9 @@ var _BinaryTree = class _BinaryTree extends IterableEntryBase {
2735
2813
 
2736
2814
 
2737
2815
 
2816
+
2817
+
2818
+
2738
2819
 
2739
2820
 
2740
2821
 
@@ -3209,6 +3290,9 @@ var _BinaryTree = class _BinaryTree extends IterableEntryBase {
3209
3290
 
3210
3291
 
3211
3292
 
3293
+
3294
+
3295
+
3212
3296
 
3213
3297
 
3214
3298
 
@@ -3258,6 +3342,9 @@ var _BinaryTree = class _BinaryTree extends IterableEntryBase {
3258
3342
 
3259
3343
 
3260
3344
 
3345
+
3346
+
3347
+
3261
3348
 
3262
3349
 
3263
3350
 
@@ -3311,6 +3398,9 @@ var _BinaryTree = class _BinaryTree extends IterableEntryBase {
3311
3398
 
3312
3399
 
3313
3400
 
3401
+
3402
+
3403
+
3314
3404
 
3315
3405
 
3316
3406
 
@@ -3389,6 +3479,9 @@ var _BinaryTree = class _BinaryTree extends IterableEntryBase {
3389
3479
 
3390
3480
 
3391
3481
 
3482
+
3483
+
3484
+
3392
3485
 
3393
3486
 
3394
3487
 
@@ -3868,6 +3961,6 @@ var BinaryTree = _BinaryTree;
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