binary-tree-typed 2.5.1 → 2.5.3

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 (75) hide show
  1. package/dist/cjs/index.cjs +340 -107
  2. package/dist/cjs/index.cjs.map +1 -1
  3. package/dist/cjs-legacy/index.cjs +339 -106
  4. package/dist/cjs-legacy/index.cjs.map +1 -1
  5. package/dist/esm/index.mjs +340 -108
  6. package/dist/esm/index.mjs.map +1 -1
  7. package/dist/esm-legacy/index.mjs +339 -107
  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 +86 -2
  12. package/dist/types/data-structures/binary-tree/binary-indexed-tree.d.ts +98 -0
  13. package/dist/types/data-structures/binary-tree/binary-tree.d.ts +189 -13
  14. package/dist/types/data-structures/binary-tree/bst.d.ts +270 -3
  15. package/dist/types/data-structures/binary-tree/red-black-tree.d.ts +136 -8
  16. package/dist/types/data-structures/binary-tree/segment-tree.d.ts +42 -0
  17. package/dist/types/data-structures/binary-tree/tree-map.d.ts +1089 -161
  18. package/dist/types/data-structures/binary-tree/tree-multi-map.d.ts +1243 -350
  19. package/dist/types/data-structures/binary-tree/tree-multi-set.d.ts +980 -255
  20. package/dist/types/data-structures/binary-tree/tree-set.d.ts +1174 -284
  21. package/dist/types/data-structures/graph/directed-graph.d.ts +70 -0
  22. package/dist/types/data-structures/graph/undirected-graph.d.ts +63 -0
  23. package/dist/types/data-structures/hash/hash-map.d.ts +84 -6
  24. package/dist/types/data-structures/heap/heap.d.ts +140 -12
  25. package/dist/types/data-structures/linked-list/doubly-linked-list.d.ts +126 -0
  26. package/dist/types/data-structures/linked-list/singly-linked-list.d.ts +106 -1
  27. package/dist/types/data-structures/linked-list/skip-linked-list.d.ts +126 -0
  28. package/dist/types/data-structures/matrix/matrix.d.ts +56 -0
  29. package/dist/types/data-structures/queue/deque.d.ts +127 -0
  30. package/dist/types/data-structures/queue/queue.d.ts +97 -0
  31. package/dist/types/data-structures/stack/stack.d.ts +72 -2
  32. package/dist/types/data-structures/trie/trie.d.ts +84 -0
  33. package/dist/types/interfaces/binary-tree.d.ts +2 -3
  34. package/dist/types/types/data-structures/binary-tree/bst.d.ts +1 -0
  35. package/dist/types/types/data-structures/binary-tree/tree-map.d.ts +5 -0
  36. package/dist/types/types/data-structures/binary-tree/tree-multi-set.d.ts +4 -0
  37. package/dist/types/types/data-structures/binary-tree/tree-set.d.ts +4 -0
  38. package/dist/umd/binary-tree-typed.js +337 -105
  39. package/dist/umd/binary-tree-typed.js.map +1 -1
  40. package/dist/umd/binary-tree-typed.min.js +5 -5
  41. package/dist/umd/binary-tree-typed.min.js.map +1 -1
  42. package/package.json +2 -2
  43. package/src/common/error.ts +19 -1
  44. package/src/common/index.ts +1 -1
  45. package/src/data-structures/base/iterable-element-base.ts +3 -2
  46. package/src/data-structures/binary-tree/avl-tree.ts +99 -5
  47. package/src/data-structures/binary-tree/binary-indexed-tree.ts +102 -4
  48. package/src/data-structures/binary-tree/binary-tree.ts +239 -78
  49. package/src/data-structures/binary-tree/bst.ts +542 -13
  50. package/src/data-structures/binary-tree/red-black-tree.ts +155 -15
  51. package/src/data-structures/binary-tree/segment-tree.ts +42 -0
  52. package/src/data-structures/binary-tree/tree-map.ts +1223 -261
  53. package/src/data-structures/binary-tree/tree-multi-map.ts +939 -30
  54. package/src/data-structures/binary-tree/tree-multi-set.ts +746 -10
  55. package/src/data-structures/binary-tree/tree-set.ts +1018 -99
  56. package/src/data-structures/graph/abstract-graph.ts +2 -2
  57. package/src/data-structures/graph/directed-graph.ts +71 -1
  58. package/src/data-structures/graph/undirected-graph.ts +64 -1
  59. package/src/data-structures/hash/hash-map.ts +102 -16
  60. package/src/data-structures/heap/heap.ts +153 -23
  61. package/src/data-structures/heap/max-heap.ts +2 -2
  62. package/src/data-structures/linked-list/doubly-linked-list.ts +139 -0
  63. package/src/data-structures/linked-list/singly-linked-list.ts +106 -1
  64. package/src/data-structures/linked-list/skip-linked-list.ts +131 -5
  65. package/src/data-structures/matrix/matrix.ts +65 -9
  66. package/src/data-structures/priority-queue/max-priority-queue.ts +2 -2
  67. package/src/data-structures/queue/deque.ts +130 -0
  68. package/src/data-structures/queue/queue.ts +109 -0
  69. package/src/data-structures/stack/stack.ts +75 -5
  70. package/src/data-structures/trie/trie.ts +86 -2
  71. package/src/interfaces/binary-tree.ts +1 -9
  72. package/src/types/data-structures/binary-tree/bst.ts +1 -0
  73. package/src/types/data-structures/binary-tree/tree-map.ts +6 -0
  74. package/src/types/data-structures/binary-tree/tree-multi-set.ts +5 -0
  75. 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 {
@@ -790,6 +796,13 @@ var Queue = class _Queue extends LinearBase {
790
796
 
791
797
 
792
798
 
799
+
800
+
801
+
802
+
803
+
804
+
805
+
793
806
 
794
807
 
795
808
 
@@ -837,6 +850,13 @@ var Queue = class _Queue extends LinearBase {
837
850
 
838
851
 
839
852
 
853
+
854
+
855
+
856
+
857
+
858
+
859
+
840
860
 
841
861
 
842
862
 
@@ -854,6 +874,14 @@ var Queue = class _Queue extends LinearBase {
854
874
  get first() {
855
875
  return this.length > 0 ? this.elements[this._offset] : void 0;
856
876
  }
877
+ /**
878
+ * Peek at the front element without removing it (alias for `first`).
879
+ * @remarks Time O(1), Space O(1)
880
+ * @returns Front element or undefined.
881
+ */
882
+ peek() {
883
+ return this.first;
884
+ }
857
885
  /**
858
886
  * Get the last element (back) without removing it.
859
887
  * @remarks Time O(1), Space O(1)
@@ -900,6 +928,13 @@ var Queue = class _Queue extends LinearBase {
900
928
 
901
929
 
902
930
 
931
+
932
+
933
+
934
+
935
+
936
+
937
+
903
938
 
904
939
 
905
940
 
@@ -959,6 +994,13 @@ var Queue = class _Queue extends LinearBase {
959
994
 
960
995
 
961
996
 
997
+
998
+
999
+
1000
+
1001
+
1002
+
1003
+
962
1004
 
963
1005
 
964
1006
 
@@ -1025,6 +1067,13 @@ var Queue = class _Queue extends LinearBase {
1025
1067
 
1026
1068
 
1027
1069
 
1070
+
1071
+
1072
+
1073
+
1074
+
1075
+
1076
+
1028
1077
 
1029
1078
 
1030
1079
 
@@ -1081,6 +1130,13 @@ var Queue = class _Queue extends LinearBase {
1081
1130
 
1082
1131
 
1083
1132
 
1133
+
1134
+
1135
+
1136
+
1137
+
1138
+
1139
+
1084
1140
 
1085
1141
 
1086
1142
 
@@ -1130,6 +1186,13 @@ var Queue = class _Queue extends LinearBase {
1130
1186
 
1131
1187
 
1132
1188
 
1189
+
1190
+
1191
+
1192
+
1193
+
1194
+
1195
+
1133
1196
 
1134
1197
 
1135
1198
 
@@ -1184,6 +1247,21 @@ var Queue = class _Queue extends LinearBase {
1184
1247
  this._elements[this._offset + index] = newElement;
1185
1248
  return true;
1186
1249
  }
1250
+ /**
1251
+ * Delete the first element that satisfies a predicate.
1252
+ * @remarks Time O(N), Space O(N)
1253
+ * @param predicate - Function (value, index, queue) → boolean to decide deletion.
1254
+ * @returns True if a match was removed.
1255
+ */
1256
+ deleteWhere(predicate) {
1257
+ for (let i = 0; i < this.length; i++) {
1258
+ if (predicate(this._elements[this._offset + i], i, this)) {
1259
+ this.deleteAt(i);
1260
+ return true;
1261
+ }
1262
+ }
1263
+ return false;
1264
+ }
1187
1265
  /**
1188
1266
  * Reverse the queue in-place by compacting then reversing.
1189
1267
  * @remarks Time O(N), Space O(N)
@@ -1220,6 +1298,13 @@ var Queue = class _Queue extends LinearBase {
1220
1298
 
1221
1299
 
1222
1300
 
1301
+
1302
+
1303
+
1304
+
1305
+
1306
+
1307
+
1223
1308
 
1224
1309
 
1225
1310
 
@@ -1263,6 +1348,13 @@ var Queue = class _Queue extends LinearBase {
1263
1348
 
1264
1349
 
1265
1350
 
1351
+
1352
+
1353
+
1354
+
1355
+
1356
+
1357
+
1266
1358
 
1267
1359
 
1268
1360
 
@@ -1329,6 +1421,13 @@ var Queue = class _Queue extends LinearBase {
1329
1421
 
1330
1422
 
1331
1423
 
1424
+
1425
+
1426
+
1427
+
1428
+
1429
+
1430
+
1332
1431
 
1333
1432
 
1334
1433
 
@@ -1379,6 +1478,13 @@ var Queue = class _Queue extends LinearBase {
1379
1478
 
1380
1479
 
1381
1480
 
1481
+
1482
+
1483
+
1484
+
1485
+
1486
+
1487
+
1382
1488
 
1383
1489
 
1384
1490
 
@@ -1433,6 +1539,13 @@ var Queue = class _Queue extends LinearBase {
1433
1539
 
1434
1540
 
1435
1541
 
1542
+
1543
+
1544
+
1545
+
1546
+
1547
+
1548
+
1436
1549
 
1437
1550
 
1438
1551
 
@@ -1691,7 +1804,7 @@ var BinaryTree = class _BinaryTree extends IterableEntryBase {
1691
1804
  if (isMapMode !== void 0) this._isMapMode = isMapMode;
1692
1805
  if (isDuplicate !== void 0) this._isDuplicate = isDuplicate;
1693
1806
  if (typeof toEntryFn === "function") this._toEntryFn = toEntryFn;
1694
- else if (toEntryFn) throw new TypeError(ERR.notAFunction("toEntryFn", "BinaryTree"));
1807
+ else if (toEntryFn) raise(TypeError, ERR.notAFunction("toEntryFn", "BinaryTree"));
1695
1808
  }
1696
1809
  if (keysNodesEntriesOrRaws) this.setMany(keysNodesEntriesOrRaws);
1697
1810
  }
@@ -1907,7 +2020,7 @@ var BinaryTree = class _BinaryTree extends IterableEntryBase {
1907
2020
  }
1908
2021
  /**
1909
2022
  * Adds a new node to the tree.
1910
- * @remarks Time O(log N), For BST, Red-Black Tree, and AVL Tree subclasses, the worst-case time is O(log N). This implementation adds the node at the first available position in a level-order (BFS) traversal. This is NOT a Binary Search Tree insertion. Time O(N), where N is the number of nodes. It must traverse level-by-level to find an empty slot. Space O(N) in the worst case for the BFS queue (e.g., a full last level).
2023
+ * @remarks Time O(N) level-order traversal to find an empty slot. Space O(N) for the BFS queue. BST/Red-Black Tree/AVL Tree subclasses override to O(log N).
1911
2024
  *
1912
2025
  * @param keyNodeOrEntry - The key, node, or entry to add.
1913
2026
  * @returns True if the addition was successful, false otherwise.
@@ -1930,6 +2043,13 @@ var BinaryTree = class _BinaryTree extends IterableEntryBase {
1930
2043
 
1931
2044
 
1932
2045
 
2046
+
2047
+
2048
+
2049
+
2050
+
2051
+
2052
+
1933
2053
 
1934
2054
 
1935
2055
 
@@ -1952,7 +2072,7 @@ var BinaryTree = class _BinaryTree extends IterableEntryBase {
1952
2072
  }
1953
2073
  /**
1954
2074
  * Adds or updates a new node to the tree.
1955
- * @remarks Time O(log N), For BST, Red-Black Tree, and AVL Tree subclasses, the worst-case time is O(log N). This implementation sets the node at the first available position in a level-order (BFS) traversal. This is NOT a Binary Search Tree insertion. Time O(N), where N is the number of nodes. It must traverse level-by-level to find an empty slot. Space O(N) in the worst case for the BFS queue (e.g., a full last level).
2075
+ * @remarks Time O(N) level-order traversal to find an empty slot. Space O(N) for the BFS queue. BST/Red-Black Tree/AVL Tree subclasses override to O(log N).
1956
2076
  *
1957
2077
  * @param keyNodeOrEntry - The key, node, or entry to set or update.
1958
2078
  * @param [value] - The value, if providing just a key.
@@ -1981,6 +2101,13 @@ var BinaryTree = class _BinaryTree extends IterableEntryBase {
1981
2101
 
1982
2102
 
1983
2103
 
2104
+
2105
+
2106
+
2107
+
2108
+
2109
+
2110
+
1984
2111
 
1985
2112
 
1986
2113
 
@@ -2084,6 +2211,13 @@ var BinaryTree = class _BinaryTree extends IterableEntryBase {
2084
2211
 
2085
2212
 
2086
2213
 
2214
+
2215
+
2216
+
2217
+
2218
+
2219
+
2220
+
2087
2221
 
2088
2222
 
2089
2223
 
@@ -2123,6 +2257,13 @@ var BinaryTree = class _BinaryTree extends IterableEntryBase {
2123
2257
 
2124
2258
 
2125
2259
 
2260
+
2261
+
2262
+
2263
+
2264
+
2265
+
2266
+
2126
2267
 
2127
2268
 
2128
2269
 
@@ -2183,6 +2324,13 @@ var BinaryTree = class _BinaryTree extends IterableEntryBase {
2183
2324
 
2184
2325
 
2185
2326
 
2327
+
2328
+
2329
+
2330
+
2331
+
2332
+
2333
+
2186
2334
 
2187
2335
 
2188
2336
 
@@ -2202,22 +2350,69 @@ var BinaryTree = class _BinaryTree extends IterableEntryBase {
2202
2350
  this.setMany(anotherTree, []);
2203
2351
  }
2204
2352
  /**
2205
- * Clears the tree and refills it with new items.
2206
- * @remarks Time O(N) (for `clear`) + O(N * M) (for `setMany`) = O(N * M). Space O(M) (from `setMany`).
2353
+ * Deletes a node from the tree (internal, returns balancing metadata).
2354
+ * @remarks Time O(N) O(N) to find the node + O(H) for predecessor swap. Space O(1). BST/Red-Black Tree/AVL Tree subclasses override to O(log N).
2355
+ * @internal Used by AVL/BST subclasses that need balancing metadata after deletion.
2207
2356
  *
2208
- * @param keysNodesEntriesOrRaws - An iterable of items to set.
2209
- * @param [values] - An optional parallel iterable of values.
2357
+ * @param keyNodeEntryRawOrPredicate - The node to delete.
2358
+ * @returns An array containing deletion results with balancing metadata.
2210
2359
  */
2211
- refill(keysNodesEntriesOrRaws, values) {
2212
- this.clear();
2213
- this.setMany(keysNodesEntriesOrRaws, values);
2360
+ _deleteInternal(keyNodeEntryRawOrPredicate) {
2361
+ const deletedResult = [];
2362
+ if (!this._root) return deletedResult;
2363
+ const curr = this.getNode(keyNodeEntryRawOrPredicate);
2364
+ if (!curr) return deletedResult;
2365
+ const parent = curr?.parent;
2366
+ let needBalanced;
2367
+ let orgCurrent = curr;
2368
+ if (!curr.left && !curr.right && !parent) {
2369
+ this._setRoot(void 0);
2370
+ } else if (curr.left) {
2371
+ const leftSubTreeRightMost = this.getRightMost((node) => node, curr.left);
2372
+ if (leftSubTreeRightMost) {
2373
+ const parentOfLeftSubTreeMax = leftSubTreeRightMost.parent;
2374
+ orgCurrent = this._swapProperties(curr, leftSubTreeRightMost);
2375
+ if (this._isMapMode) {
2376
+ this._store.set(curr.key, curr);
2377
+ this._store.set(leftSubTreeRightMost.key, leftSubTreeRightMost);
2378
+ }
2379
+ if (parentOfLeftSubTreeMax) {
2380
+ if (parentOfLeftSubTreeMax.right === leftSubTreeRightMost)
2381
+ parentOfLeftSubTreeMax.right = leftSubTreeRightMost.left;
2382
+ else parentOfLeftSubTreeMax.left = leftSubTreeRightMost.left;
2383
+ needBalanced = parentOfLeftSubTreeMax;
2384
+ }
2385
+ }
2386
+ } else if (parent) {
2387
+ const { familyPosition: fp } = curr;
2388
+ if (fp === "LEFT" || fp === "ROOT_LEFT") {
2389
+ parent.left = curr.right;
2390
+ } else if (fp === "RIGHT" || fp === "ROOT_RIGHT") {
2391
+ parent.right = curr.right;
2392
+ }
2393
+ needBalanced = parent;
2394
+ } else {
2395
+ this._setRoot(curr.right);
2396
+ curr.right = void 0;
2397
+ }
2398
+ this._size = this._size - 1;
2399
+ deletedResult.push({ deleted: orgCurrent, needBalanced });
2400
+ if (this._isMapMode && orgCurrent) this._store.delete(orgCurrent.key);
2401
+ return deletedResult;
2214
2402
  }
2215
2403
  /**
2216
2404
  * Deletes a node from the tree.
2217
- * @remarks Time O(log N), For BST, Red-Black Tree, and AVL Tree subclasses, the worst-case time is O(log N). This implementation finds the node, and if it has two children, swaps it with the rightmost node of its left subtree (in-order predecessor) before deleting. Time O(N) in the worst case. O(N) to find the node (`getNode`) and O(H) (which is O(N) worst-case) to find the rightmost node. Space O(1) (if `getNode` is iterative, which it is).
2405
+ * @remarks Time O(N) O(N) to find the node + O(H) for predecessor swap. Space O(1). BST/Red-Black Tree/AVL Tree subclasses override to O(log N).
2218
2406
  *
2219
2407
  * @param keyNodeEntryRawOrPredicate - The node to delete.
2220
- * @returns An array containing deletion results (for compatibility with self-balancing trees).
2408
+ * @returns True if the node was found and deleted, false otherwise.
2409
+
2410
+
2411
+
2412
+
2413
+
2414
+
2415
+
2221
2416
 
2222
2417
 
2223
2418
 
@@ -2258,51 +2453,11 @@ var BinaryTree = class _BinaryTree extends IterableEntryBase {
2258
2453
  * console.log(tree.size); // 4;
2259
2454
  */
2260
2455
  delete(keyNodeEntryRawOrPredicate) {
2261
- const deletedResult = [];
2262
- if (!this._root) return deletedResult;
2263
- const curr = this.getNode(keyNodeEntryRawOrPredicate);
2264
- if (!curr) return deletedResult;
2265
- const parent = curr?.parent;
2266
- let needBalanced;
2267
- let orgCurrent = curr;
2268
- if (!curr.left && !curr.right && !parent) {
2269
- this._setRoot(void 0);
2270
- } else if (curr.left) {
2271
- const leftSubTreeRightMost = this.getRightMost((node) => node, curr.left);
2272
- if (leftSubTreeRightMost) {
2273
- const parentOfLeftSubTreeMax = leftSubTreeRightMost.parent;
2274
- orgCurrent = this._swapProperties(curr, leftSubTreeRightMost);
2275
- if (this._isMapMode) {
2276
- this._store.set(curr.key, curr);
2277
- this._store.set(leftSubTreeRightMost.key, leftSubTreeRightMost);
2278
- }
2279
- if (parentOfLeftSubTreeMax) {
2280
- if (parentOfLeftSubTreeMax.right === leftSubTreeRightMost)
2281
- parentOfLeftSubTreeMax.right = leftSubTreeRightMost.left;
2282
- else parentOfLeftSubTreeMax.left = leftSubTreeRightMost.left;
2283
- needBalanced = parentOfLeftSubTreeMax;
2284
- }
2285
- }
2286
- } else if (parent) {
2287
- const { familyPosition: fp } = curr;
2288
- if (fp === "LEFT" || fp === "ROOT_LEFT") {
2289
- parent.left = curr.right;
2290
- } else if (fp === "RIGHT" || fp === "ROOT_RIGHT") {
2291
- parent.right = curr.right;
2292
- }
2293
- needBalanced = parent;
2294
- } else {
2295
- this._setRoot(curr.right);
2296
- curr.right = void 0;
2297
- }
2298
- this._size = this._size - 1;
2299
- deletedResult.push({ deleted: orgCurrent, needBalanced });
2300
- if (this._isMapMode && orgCurrent) this._store.delete(orgCurrent.key);
2301
- return deletedResult;
2456
+ return this._deleteInternal(keyNodeEntryRawOrPredicate).length > 0;
2302
2457
  }
2303
2458
  /**
2304
2459
  * Searches the tree for nodes matching a predicate.
2305
- * @remarks Time O(log N), For BST, Red-Black Tree, and AVL Tree subclasses, the worst-case time is O(log N). Performs a full DFS (pre-order) scan of the tree. Time O(N), as it may visit every node. Space O(H) for the call stack (recursive) or explicit stack (iterative), where H is the tree height (O(N) worst-case).
2460
+ * @remarks Time O(N) full DFS scan; may visit every node. Space O(H) for call/explicit stack (O(N) worst-case). BST subclasses with key search override to O(log N).
2306
2461
  *
2307
2462
  * @template C - The type of the callback function.
2308
2463
  * @param keyNodeEntryOrPredicate - The key, node, entry, or predicate function to search for.
@@ -2351,7 +2506,7 @@ var BinaryTree = class _BinaryTree extends IterableEntryBase {
2351
2506
  }
2352
2507
  /**
2353
2508
  * Gets the first node matching a predicate.
2354
- * @remarks Time O(log N), For BST, Red-Black Tree, and AVL Tree subclasses, the worst-case time is O(log N). Time O(N) in the worst case (via `search`). Space O(H) or O(N) (via `search`).
2509
+ * @remarks Time O(N) via `search`. Space O(H) or O(N). BST/Red-Black Tree/AVL Tree subclasses override to O(log N) for key lookups.
2355
2510
  *
2356
2511
  * @param keyNodeEntryOrPredicate - The key, node, entry, or predicate function to search for.
2357
2512
  * @param [startNode=this._root] - The node to start the search from.
@@ -2379,6 +2534,13 @@ var BinaryTree = class _BinaryTree extends IterableEntryBase {
2379
2534
 
2380
2535
 
2381
2536
 
2537
+
2538
+
2539
+
2540
+
2541
+
2542
+
2543
+
2382
2544
 
2383
2545
 
2384
2546
 
@@ -2404,7 +2566,7 @@ var BinaryTree = class _BinaryTree extends IterableEntryBase {
2404
2566
  }
2405
2567
  /**
2406
2568
  * Gets the value associated with a key.
2407
- * @remarks Time O(log N), For BST, Red-Black Tree, and AVL Tree subclasses, the worst-case time is O(log N). Time O(1) if in Map mode. O(N) if not in Map mode (uses `getNode`). Space O(1) if in Map mode. O(H) or O(N) otherwise.
2569
+ * @remarks Time O(1) in Map mode, O(N) otherwise (via `getNode`). Space O(1) in Map mode, O(H) or O(N) otherwise. BST subclasses override non-Map-mode to O(log N).
2408
2570
  *
2409
2571
  * @param keyNodeEntryOrPredicate - The key, node, or entry to get the value for.
2410
2572
  * @param [startNode=this._root] - The node to start searching from (if not in Map mode).
@@ -2434,6 +2596,13 @@ var BinaryTree = class _BinaryTree extends IterableEntryBase {
2434
2596
 
2435
2597
 
2436
2598
 
2599
+
2600
+
2601
+
2602
+
2603
+
2604
+
2605
+
2437
2606
 
2438
2607
 
2439
2608
 
@@ -2491,6 +2660,13 @@ var BinaryTree = class _BinaryTree extends IterableEntryBase {
2491
2660
 
2492
2661
 
2493
2662
 
2663
+
2664
+
2665
+
2666
+
2667
+
2668
+
2669
+
2494
2670
 
2495
2671
 
2496
2672
 
@@ -2536,6 +2712,13 @@ var BinaryTree = class _BinaryTree extends IterableEntryBase {
2536
2712
 
2537
2713
 
2538
2714
 
2715
+
2716
+
2717
+
2718
+
2719
+
2720
+
2721
+
2539
2722
 
2540
2723
 
2541
2724
 
@@ -2590,6 +2773,13 @@ var BinaryTree = class _BinaryTree extends IterableEntryBase {
2590
2773
 
2591
2774
 
2592
2775
 
2776
+
2777
+
2778
+
2779
+
2780
+
2781
+
2782
+
2593
2783
 
2594
2784
 
2595
2785
 
@@ -2671,6 +2861,13 @@ var BinaryTree = class _BinaryTree extends IterableEntryBase {
2671
2861
 
2672
2862
 
2673
2863
 
2864
+
2865
+
2866
+
2867
+
2868
+
2869
+
2870
+
2674
2871
 
2675
2872
 
2676
2873
 
@@ -2729,6 +2926,13 @@ var BinaryTree = class _BinaryTree extends IterableEntryBase {
2729
2926
 
2730
2927
 
2731
2928
 
2929
+
2930
+
2931
+
2932
+
2933
+
2934
+
2935
+
2732
2936
 
2733
2937
 
2734
2938
 
@@ -3203,6 +3407,13 @@ var BinaryTree = class _BinaryTree extends IterableEntryBase {
3203
3407
 
3204
3408
 
3205
3409
 
3410
+
3411
+
3412
+
3413
+
3414
+
3415
+
3416
+
3206
3417
 
3207
3418
 
3208
3419
 
@@ -3252,6 +3463,13 @@ var BinaryTree = class _BinaryTree extends IterableEntryBase {
3252
3463
 
3253
3464
 
3254
3465
 
3466
+
3467
+
3468
+
3469
+
3470
+
3471
+
3472
+
3255
3473
 
3256
3474
 
3257
3475
 
@@ -3305,6 +3523,13 @@ var BinaryTree = class _BinaryTree extends IterableEntryBase {
3305
3523
 
3306
3524
 
3307
3525
 
3526
+
3527
+
3528
+
3529
+
3530
+
3531
+
3532
+
3308
3533
 
3309
3534
 
3310
3535
 
@@ -3383,6 +3608,13 @@ var BinaryTree = class _BinaryTree extends IterableEntryBase {
3383
3608
 
3384
3609
 
3385
3610
 
3611
+
3612
+
3613
+
3614
+
3615
+
3616
+
3617
+
3386
3618
 
3387
3619
 
3388
3620
 
@@ -3875,5 +4107,6 @@ exports.BinaryTreeNode = BinaryTreeNode;
3875
4107
  exports.DFSOperation = DFSOperation;
3876
4108
  exports.ERR = ERR;
3877
4109
  exports.Range = Range;
4110
+ exports.raise = raise;
3878
4111
  //# sourceMappingURL=index.cjs.map
3879
4112
  //# sourceMappingURL=index.cjs.map