data-structure-typed 1.50.8 → 1.51.0

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 (65) hide show
  1. package/CHANGELOG.md +1 -1
  2. package/README.md +74 -76
  3. package/benchmark/report.html +2 -2
  4. package/benchmark/report.json +15 -15
  5. package/dist/cjs/data-structures/binary-tree/avl-tree-multi-map.d.ts +15 -3
  6. package/dist/cjs/data-structures/binary-tree/avl-tree-multi-map.js +14 -2
  7. package/dist/cjs/data-structures/binary-tree/avl-tree-multi-map.js.map +1 -1
  8. package/dist/cjs/data-structures/binary-tree/binary-tree.d.ts +2 -2
  9. package/dist/cjs/data-structures/binary-tree/binary-tree.js +11 -11
  10. package/dist/cjs/data-structures/binary-tree/binary-tree.js.map +1 -1
  11. package/dist/cjs/data-structures/binary-tree/bst.d.ts +19 -2
  12. package/dist/cjs/data-structures/binary-tree/bst.js +20 -2
  13. package/dist/cjs/data-structures/binary-tree/bst.js.map +1 -1
  14. package/dist/cjs/data-structures/binary-tree/rb-tree.d.ts +5 -5
  15. package/dist/cjs/data-structures/binary-tree/rb-tree.js +42 -44
  16. package/dist/cjs/data-structures/binary-tree/rb-tree.js.map +1 -1
  17. package/dist/cjs/data-structures/binary-tree/tree-multi-map.d.ts +40 -22
  18. package/dist/cjs/data-structures/binary-tree/tree-multi-map.js +43 -27
  19. package/dist/cjs/data-structures/binary-tree/tree-multi-map.js.map +1 -1
  20. package/dist/cjs/data-structures/heap/heap.d.ts +1 -1
  21. package/dist/cjs/data-structures/heap/heap.js +5 -5
  22. package/dist/cjs/types/common.d.ts +1 -1
  23. package/dist/cjs/types/data-structures/binary-tree/rb-tree.d.ts +1 -4
  24. package/dist/cjs/types/data-structures/binary-tree/rb-tree.js +0 -6
  25. package/dist/cjs/types/data-structures/binary-tree/rb-tree.js.map +1 -1
  26. package/dist/mjs/data-structures/binary-tree/avl-tree-multi-map.d.ts +15 -3
  27. package/dist/mjs/data-structures/binary-tree/avl-tree-multi-map.js +14 -2
  28. package/dist/mjs/data-structures/binary-tree/binary-tree.d.ts +2 -2
  29. package/dist/mjs/data-structures/binary-tree/binary-tree.js +11 -11
  30. package/dist/mjs/data-structures/binary-tree/bst.d.ts +19 -2
  31. package/dist/mjs/data-structures/binary-tree/bst.js +20 -2
  32. package/dist/mjs/data-structures/binary-tree/rb-tree.d.ts +5 -5
  33. package/dist/mjs/data-structures/binary-tree/rb-tree.js +42 -44
  34. package/dist/mjs/data-structures/binary-tree/tree-multi-map.d.ts +40 -22
  35. package/dist/mjs/data-structures/binary-tree/tree-multi-map.js +43 -27
  36. package/dist/mjs/data-structures/heap/heap.d.ts +1 -1
  37. package/dist/mjs/data-structures/heap/heap.js +5 -5
  38. package/dist/mjs/types/common.d.ts +1 -1
  39. package/dist/mjs/types/data-structures/binary-tree/rb-tree.d.ts +1 -4
  40. package/dist/mjs/types/data-structures/binary-tree/rb-tree.js +1 -5
  41. package/dist/umd/data-structure-typed.js +135 -97
  42. package/dist/umd/data-structure-typed.min.js +2 -2
  43. package/dist/umd/data-structure-typed.min.js.map +1 -1
  44. package/package.json +7 -7
  45. package/src/data-structures/binary-tree/avl-tree-multi-map.ts +17 -3
  46. package/src/data-structures/binary-tree/binary-tree.ts +36 -24
  47. package/src/data-structures/binary-tree/bst.ts +32 -11
  48. package/src/data-structures/binary-tree/rb-tree.ts +44 -44
  49. package/src/data-structures/binary-tree/tree-multi-map.ts +46 -27
  50. package/src/data-structures/heap/heap.ts +5 -5
  51. package/src/types/common.ts +1 -1
  52. package/src/types/data-structures/binary-tree/rb-tree.ts +1 -1
  53. package/test/integration/all-in-one.test.ts +2 -2
  54. package/test/integration/avl-tree.test.ts +4 -4
  55. package/test/integration/bst.test.ts +7 -7
  56. package/test/integration/index.html +2 -2
  57. package/test/performance/data-structures/binary-tree/avl-tree.test.ts +20 -15
  58. package/test/performance/data-structures/binary-tree/binary-tree.test.ts +1 -1
  59. package/test/unit/data-structures/binary-tree/avl-tree-multi-map.test.ts +7 -7
  60. package/test/unit/data-structures/binary-tree/avl-tree.test.ts +4 -4
  61. package/test/unit/data-structures/binary-tree/binary-tree.test.ts +24 -24
  62. package/test/unit/data-structures/binary-tree/bst.test.ts +12 -12
  63. package/test/unit/data-structures/binary-tree/rb-tree.test.ts +25 -25
  64. package/test/unit/data-structures/binary-tree/tree-multi-map.test.ts +19 -19
  65. package/test/unit/data-structures/priority-queue/priority-queue.test.ts +3 -3
@@ -139,7 +139,6 @@ var dataStructureTyped = (() => {
139
139
  Navigator: () => Navigator,
140
140
  PriorityQueue: () => PriorityQueue,
141
141
  Queue: () => Queue,
142
- RBTNColor: () => RBTNColor,
143
142
  RedBlackTree: () => RedBlackTree,
144
143
  RedBlackTreeNode: () => RedBlackTreeNode,
145
144
  SegmentTree: () => SegmentTree,
@@ -4831,23 +4830,23 @@ var dataStructureTyped = (() => {
4831
4830
  * Space Complexity: O(log n)
4832
4831
  *
4833
4832
  * Depth-first search (DFS) method, different traversal orders can be selected。
4834
- * @param order - Traverse order parameter: 'in' (in-order), 'pre' (pre-order) or 'post' (post-order).
4833
+ * @param order - Traverse order parameter: 'IN' (in-order), 'PRE' (pre-order) or 'POST' (post-order).
4835
4834
  * @returns An array containing elements traversed in the specified order.
4836
4835
  */
4837
- dfs(order = "pre") {
4836
+ dfs(order = "PRE") {
4838
4837
  const result = [];
4839
4838
  const _dfs = (index) => {
4840
4839
  const left = 2 * index + 1, right = left + 1;
4841
4840
  if (index < this.size) {
4842
- if (order === "in") {
4841
+ if (order === "IN") {
4843
4842
  _dfs(left);
4844
4843
  result.push(this.elements[index]);
4845
4844
  _dfs(right);
4846
- } else if (order === "pre") {
4845
+ } else if (order === "PRE") {
4847
4846
  result.push(this.elements[index]);
4848
4847
  _dfs(left);
4849
4848
  _dfs(right);
4850
- } else if (order === "post") {
4849
+ } else if (order === "POST") {
4851
4850
  _dfs(left);
4852
4851
  _dfs(right);
4853
4852
  result.push(this.elements[index]);
@@ -8707,7 +8706,7 @@ var dataStructureTyped = (() => {
8707
8706
  * `false`, null or undefined
8708
8707
  * @returns an array of values that are the return values of the callback function.
8709
8708
  */
8710
- dfs(callback = this._defaultOneParamCallback, pattern = "in", beginRoot = this.root, iterationType = "ITERATIVE", includeNull = false) {
8709
+ dfs(callback = this._defaultOneParamCallback, pattern = "IN", beginRoot = this.root, iterationType = "ITERATIVE", includeNull = false) {
8711
8710
  beginRoot = this.ensureNode(beginRoot);
8712
8711
  if (!beginRoot)
8713
8712
  return [];
@@ -8715,7 +8714,7 @@ var dataStructureTyped = (() => {
8715
8714
  if (iterationType === "RECURSIVE") {
8716
8715
  const _traverse = (node) => {
8717
8716
  switch (pattern) {
8718
- case "in":
8717
+ case "IN":
8719
8718
  if (includeNull) {
8720
8719
  if (this.isRealNode(node) && this.isNodeOrNull(node.left))
8721
8720
  _traverse(node.left);
@@ -8730,7 +8729,7 @@ var dataStructureTyped = (() => {
8730
8729
  _traverse(node.right);
8731
8730
  }
8732
8731
  break;
8733
- case "pre":
8732
+ case "PRE":
8734
8733
  if (includeNull) {
8735
8734
  this.isNodeOrNull(node) && ans.push(callback(node));
8736
8735
  if (this.isRealNode(node) && this.isNodeOrNull(node.left))
@@ -8745,7 +8744,7 @@ var dataStructureTyped = (() => {
8745
8744
  _traverse(node.right);
8746
8745
  }
8747
8746
  break;
8748
- case "post":
8747
+ case "POST":
8749
8748
  if (includeNull) {
8750
8749
  if (this.isRealNode(node) && this.isNodeOrNull(node.left))
8751
8750
  _traverse(node.left);
@@ -8780,17 +8779,17 @@ var dataStructureTyped = (() => {
8780
8779
  ans.push(callback(cur.node));
8781
8780
  } else {
8782
8781
  switch (pattern) {
8783
- case "in":
8782
+ case "IN":
8784
8783
  cur.node && stack.push({ opt: 0, node: cur.node.right });
8785
8784
  stack.push({ opt: 1, node: cur.node });
8786
8785
  cur.node && stack.push({ opt: 0, node: cur.node.left });
8787
8786
  break;
8788
- case "pre":
8787
+ case "PRE":
8789
8788
  cur.node && stack.push({ opt: 0, node: cur.node.right });
8790
8789
  cur.node && stack.push({ opt: 0, node: cur.node.left });
8791
8790
  stack.push({ opt: 1, node: cur.node });
8792
8791
  break;
8793
- case "post":
8792
+ case "POST":
8794
8793
  stack.push({ opt: 1, node: cur.node });
8795
8794
  cur.node && stack.push({ opt: 0, node: cur.node.right });
8796
8795
  cur.node && stack.push({ opt: 0, node: cur.node.left });
@@ -8974,7 +8973,7 @@ var dataStructureTyped = (() => {
8974
8973
  * `callback` function on each node in the binary tree. The type of the array nodes is determined
8975
8974
  * by the return type of the `callback` function.
8976
8975
  */
8977
- morris(callback = this._defaultOneParamCallback, pattern = "in", beginRoot = this.root) {
8976
+ morris(callback = this._defaultOneParamCallback, pattern = "IN", beginRoot = this.root) {
8978
8977
  beginRoot = this.ensureNode(beginRoot);
8979
8978
  if (beginRoot === null)
8980
8979
  return [];
@@ -9001,7 +9000,7 @@ var dataStructureTyped = (() => {
9001
9000
  _reverseEdge(tail);
9002
9001
  };
9003
9002
  switch (pattern) {
9004
- case "in":
9003
+ case "IN":
9005
9004
  while (cur) {
9006
9005
  if (cur.left) {
9007
9006
  const predecessor = this.getPredecessor(cur);
@@ -9017,7 +9016,7 @@ var dataStructureTyped = (() => {
9017
9016
  cur = cur.right;
9018
9017
  }
9019
9018
  break;
9020
- case "pre":
9019
+ case "PRE":
9021
9020
  while (cur) {
9022
9021
  if (cur.left) {
9023
9022
  const predecessor = this.getPredecessor(cur);
@@ -9035,7 +9034,7 @@ var dataStructureTyped = (() => {
9035
9034
  cur = cur.right;
9036
9035
  }
9037
9036
  break;
9038
- case "post":
9037
+ case "POST":
9039
9038
  while (cur) {
9040
9039
  if (cur.left) {
9041
9040
  const predecessor = this.getPredecessor(cur);
@@ -9803,7 +9802,7 @@ var dataStructureTyped = (() => {
9803
9802
  * following values:
9804
9803
  * @returns The method is returning an array of the return type of the callback function.
9805
9804
  */
9806
- dfs(callback = this._defaultOneParamCallback, pattern = "in", beginRoot = this.root, iterationType = "ITERATIVE") {
9805
+ dfs(callback = this._defaultOneParamCallback, pattern = "IN", beginRoot = this.root, iterationType = "ITERATIVE") {
9807
9806
  return super.dfs(callback, pattern, beginRoot, iterationType, false);
9808
9807
  }
9809
9808
  /**
@@ -9965,7 +9964,7 @@ var dataStructureTyped = (() => {
9965
9964
  * @returns The function `perfectlyBalance` returns a boolean value.
9966
9965
  */
9967
9966
  perfectlyBalance(iterationType = this.iterationType) {
9968
- const sorted = this.dfs((node) => node, "in"), n = sorted.length;
9967
+ const sorted = this.dfs((node) => node, "IN"), n = sorted.length;
9969
9968
  this.clear();
9970
9969
  if (sorted.length < 1)
9971
9970
  return false;
@@ -10089,11 +10088,28 @@ var dataStructureTyped = (() => {
10089
10088
  const compared = this.variant === "STANDARD" ? extractedA - extractedB : extractedB - extractedA;
10090
10089
  return compared > 0 ? "GT" : compared < 0 ? "LT" : "EQ";
10091
10090
  }
10091
+ /**
10092
+ * The function `_lt` compares two values `a` and `b` using an extractor function and returns true if
10093
+ * `a` is less than `b` based on the specified variant.
10094
+ * @param {K} a - The parameter "a" is of type "K", which means it can be any type. It represents the
10095
+ * first value to be compared in the function.
10096
+ * @param {K} b - The parameter `b` is of type `K`, which means it can be any type. It is used as one
10097
+ * of the arguments for the comparison in the `_lt` function.
10098
+ * @returns a boolean value.
10099
+ */
10092
10100
  _lt(a, b) {
10093
10101
  const extractedA = this.extractor(a);
10094
10102
  const extractedB = this.extractor(b);
10095
10103
  return this.variant === "STANDARD" ? extractedA < extractedB : extractedA > extractedB;
10096
10104
  }
10105
+ /**
10106
+ * The function compares two values using a custom extractor function and returns true if the first
10107
+ * value is greater than the second value.
10108
+ * @param {K} a - The parameter "a" is of type K, which means it can be any type.
10109
+ * @param {K} b - The parameter "b" is of type K, which means it can be any type. It is used as one
10110
+ * of the arguments for the comparison in the function.
10111
+ * @returns a boolean value.
10112
+ */
10097
10113
  _gt(a, b) {
10098
10114
  const extractedA = this.extractor(a);
10099
10115
  const extractedB = this.extractor(b);
@@ -11116,13 +11132,6 @@ var dataStructureTyped = (() => {
11116
11132
  }
11117
11133
  };
11118
11134
 
11119
- // src/types/data-structures/binary-tree/rb-tree.ts
11120
- var RBTNColor = /* @__PURE__ */ ((RBTNColor2) => {
11121
- RBTNColor2[RBTNColor2["RED"] = 1] = "RED";
11122
- RBTNColor2[RBTNColor2["BLACK"] = 0] = "BLACK";
11123
- return RBTNColor2;
11124
- })(RBTNColor || {});
11125
-
11126
11135
  // src/data-structures/binary-tree/rb-tree.ts
11127
11136
  var RedBlackTreeNode = class extends BSTNode {
11128
11137
  /**
@@ -11134,9 +11143,9 @@ var dataStructureTyped = (() => {
11134
11143
  * associated with the key in the Red-Black Tree Node. It is not required and can be omitted when
11135
11144
  * creating a new instance of the Red-Black Tree Node.
11136
11145
  * @param {RBTNColor} color - The `color` parameter is used to specify the color of the Red-Black
11137
- * Tree Node. It is an optional parameter with a default value of `RBTNColor.BLACK`.
11146
+ * Tree Node. It is an optional parameter with a default value of `'BLACK'`.
11138
11147
  */
11139
- constructor(key, value, color = 0 /* BLACK */) {
11148
+ constructor(key, value, color = "BLACK") {
11140
11149
  super(key, value);
11141
11150
  __publicField(this, "_color");
11142
11151
  this._color = color;
@@ -11197,12 +11206,12 @@ var dataStructureTyped = (() => {
11197
11206
  * @param {V} [value] - The `value` parameter is an optional parameter that represents the value
11198
11207
  * associated with the key in the node. It is not required and can be omitted if not needed.
11199
11208
  * @param {RBTNColor} color - The "color" parameter is used to specify the color of the node in a
11200
- * Red-Black Tree. It is an optional parameter with a default value of "RBTNColor.BLACK". The color
11201
- * can be either "RBTNColor.RED" or "RBTNColor.BLACK".
11209
+ * Red-Black Tree. It is an optional parameter with a default value of "'BLACK'". The color
11210
+ * can be either "'RED'" or "'BLACK'".
11202
11211
  * @returns The method is returning a new instance of a RedBlackTreeNode with the specified key,
11203
11212
  * value, and color.
11204
11213
  */
11205
- createNode(key, value, color = 0 /* BLACK */) {
11214
+ createNode(key, value, color = "BLACK") {
11206
11215
  return new RedBlackTreeNode(key, value, color);
11207
11216
  }
11208
11217
  /**
@@ -11242,10 +11251,10 @@ var dataStructureTyped = (() => {
11242
11251
  if (key === void 0 || key === null) {
11243
11252
  return;
11244
11253
  } else {
11245
- node = this.createNode(key, value2, 1 /* RED */);
11254
+ node = this.createNode(key, value2, "RED");
11246
11255
  }
11247
11256
  } else if (!this.isNode(keyOrNodeOrEntry)) {
11248
- node = this.createNode(keyOrNodeOrEntry, value, 1 /* RED */);
11257
+ node = this.createNode(keyOrNodeOrEntry, value, "RED");
11249
11258
  } else {
11250
11259
  return;
11251
11260
  }
@@ -11353,7 +11362,7 @@ var dataStructureTyped = (() => {
11353
11362
  const insertStatus = this._insert(newNode);
11354
11363
  if (insertStatus === "CREATED") {
11355
11364
  if (this.isRealNode(this._root)) {
11356
- this._root.color = 0 /* BLACK */;
11365
+ this._root.color = "BLACK";
11357
11366
  } else {
11358
11367
  return false;
11359
11368
  }
@@ -11423,7 +11432,7 @@ var dataStructureTyped = (() => {
11423
11432
  }
11424
11433
  }
11425
11434
  this._size--;
11426
- if (originalColor === 0 /* BLACK */) {
11435
+ if (originalColor === "BLACK") {
11427
11436
  this._deleteFixup(replacementNode);
11428
11437
  }
11429
11438
  results.push({ deleted: nodeToDelete, needBalanced: void 0 });
@@ -11500,7 +11509,7 @@ var dataStructureTyped = (() => {
11500
11509
  }
11501
11510
  node.left = this.SENTINEL;
11502
11511
  node.right = this.SENTINEL;
11503
- node.color = 1 /* RED */;
11512
+ node.color = "RED";
11504
11513
  this._insertFixup(node);
11505
11514
  return "CREATED";
11506
11515
  }
@@ -11543,13 +11552,13 @@ var dataStructureTyped = (() => {
11543
11552
  */
11544
11553
  _insertFixup(z) {
11545
11554
  var _a, _b, _c, _d;
11546
- while (((_a = z == null ? void 0 : z.parent) == null ? void 0 : _a.color) === 1 /* RED */) {
11555
+ while (((_a = z == null ? void 0 : z.parent) == null ? void 0 : _a.color) === "RED") {
11547
11556
  if (z.parent === ((_b = z.parent.parent) == null ? void 0 : _b.left)) {
11548
11557
  const y = z.parent.parent.right;
11549
- if ((y == null ? void 0 : y.color) === 1 /* RED */) {
11550
- z.parent.color = 0 /* BLACK */;
11551
- y.color = 0 /* BLACK */;
11552
- z.parent.parent.color = 1 /* RED */;
11558
+ if ((y == null ? void 0 : y.color) === "RED") {
11559
+ z.parent.color = "BLACK";
11560
+ y.color = "BLACK";
11561
+ z.parent.parent.color = "RED";
11553
11562
  z = z.parent.parent;
11554
11563
  } else {
11555
11564
  if (z === z.parent.right) {
@@ -11557,17 +11566,17 @@ var dataStructureTyped = (() => {
11557
11566
  this._leftRotate(z);
11558
11567
  }
11559
11568
  if (z && this.isRealNode(z.parent) && this.isRealNode(z.parent.parent)) {
11560
- z.parent.color = 0 /* BLACK */;
11561
- z.parent.parent.color = 1 /* RED */;
11569
+ z.parent.color = "BLACK";
11570
+ z.parent.parent.color = "RED";
11562
11571
  this._rightRotate(z.parent.parent);
11563
11572
  }
11564
11573
  }
11565
11574
  } else {
11566
11575
  const y = (_d = (_c = z == null ? void 0 : z.parent) == null ? void 0 : _c.parent) == null ? void 0 : _d.left;
11567
- if ((y == null ? void 0 : y.color) === 1 /* RED */) {
11568
- z.parent.color = 0 /* BLACK */;
11569
- y.color = 0 /* BLACK */;
11570
- z.parent.parent.color = 1 /* RED */;
11576
+ if ((y == null ? void 0 : y.color) === "RED") {
11577
+ z.parent.color = "BLACK";
11578
+ y.color = "BLACK";
11579
+ z.parent.parent.color = "RED";
11571
11580
  z = z.parent.parent;
11572
11581
  } else {
11573
11582
  if (z === z.parent.left) {
@@ -11575,15 +11584,15 @@ var dataStructureTyped = (() => {
11575
11584
  this._rightRotate(z);
11576
11585
  }
11577
11586
  if (z && this.isRealNode(z.parent) && this.isRealNode(z.parent.parent)) {
11578
- z.parent.color = 0 /* BLACK */;
11579
- z.parent.parent.color = 1 /* RED */;
11587
+ z.parent.color = "BLACK";
11588
+ z.parent.parent.color = "RED";
11580
11589
  this._leftRotate(z.parent.parent);
11581
11590
  }
11582
11591
  }
11583
11592
  }
11584
11593
  }
11585
11594
  if (this.isRealNode(this._root))
11586
- this._root.color = 0 /* BLACK */;
11595
+ this._root.color = "BLACK";
11587
11596
  }
11588
11597
  /**
11589
11598
  * Time Complexity: O(log n)
@@ -11601,66 +11610,66 @@ var dataStructureTyped = (() => {
11601
11610
  */
11602
11611
  _deleteFixup(node) {
11603
11612
  var _a, _b, _c, _d;
11604
- if (!node || node === this.root || node.color === 0 /* BLACK */) {
11613
+ if (!node || node === this.root || node.color === "BLACK") {
11605
11614
  if (node) {
11606
- node.color = 0 /* BLACK */;
11615
+ node.color = "BLACK";
11607
11616
  }
11608
11617
  return;
11609
11618
  }
11610
- while (node && node !== this.root && node.color === 0 /* BLACK */) {
11619
+ while (node && node !== this.root && node.color === "BLACK") {
11611
11620
  const parent = node.parent;
11612
11621
  if (!parent) {
11613
11622
  break;
11614
11623
  }
11615
11624
  if (node === parent.left) {
11616
11625
  let sibling = parent.right;
11617
- if ((sibling == null ? void 0 : sibling.color) === 1 /* RED */) {
11618
- sibling.color = 0 /* BLACK */;
11619
- parent.color = 1 /* RED */;
11626
+ if ((sibling == null ? void 0 : sibling.color) === "RED") {
11627
+ sibling.color = "BLACK";
11628
+ parent.color = "RED";
11620
11629
  this._leftRotate(parent);
11621
11630
  sibling = parent.right;
11622
11631
  }
11623
- if (((_b = (_a = sibling == null ? void 0 : sibling.left) == null ? void 0 : _a.color) != null ? _b : 0 /* BLACK */) === 0 /* BLACK */) {
11632
+ if (((_b = (_a = sibling == null ? void 0 : sibling.left) == null ? void 0 : _a.color) != null ? _b : "BLACK") === "BLACK") {
11624
11633
  if (sibling)
11625
- sibling.color = 1 /* RED */;
11634
+ sibling.color = "RED";
11626
11635
  node = parent;
11627
11636
  } else {
11628
11637
  if (sibling == null ? void 0 : sibling.left)
11629
- sibling.left.color = 0 /* BLACK */;
11638
+ sibling.left.color = "BLACK";
11630
11639
  if (sibling)
11631
11640
  sibling.color = parent.color;
11632
- parent.color = 0 /* BLACK */;
11641
+ parent.color = "BLACK";
11633
11642
  this._rightRotate(parent);
11634
11643
  node = this.root;
11635
11644
  }
11636
11645
  } else {
11637
11646
  let sibling = parent.left;
11638
- if ((sibling == null ? void 0 : sibling.color) === 1 /* RED */) {
11639
- sibling.color = 0 /* BLACK */;
11647
+ if ((sibling == null ? void 0 : sibling.color) === "RED") {
11648
+ sibling.color = "BLACK";
11640
11649
  if (parent)
11641
- parent.color = 1 /* RED */;
11650
+ parent.color = "RED";
11642
11651
  this._rightRotate(parent);
11643
11652
  if (parent)
11644
11653
  sibling = parent.left;
11645
11654
  }
11646
- if (((_d = (_c = sibling == null ? void 0 : sibling.right) == null ? void 0 : _c.color) != null ? _d : 0 /* BLACK */) === 0 /* BLACK */) {
11655
+ if (((_d = (_c = sibling == null ? void 0 : sibling.right) == null ? void 0 : _c.color) != null ? _d : "BLACK") === "BLACK") {
11647
11656
  if (sibling)
11648
- sibling.color = 1 /* RED */;
11657
+ sibling.color = "RED";
11649
11658
  node = parent;
11650
11659
  } else {
11651
11660
  if (sibling == null ? void 0 : sibling.right)
11652
- sibling.right.color = 0 /* BLACK */;
11661
+ sibling.right.color = "BLACK";
11653
11662
  if (sibling)
11654
11663
  sibling.color = parent.color;
11655
11664
  if (parent)
11656
- parent.color = 0 /* BLACK */;
11665
+ parent.color = "BLACK";
11657
11666
  this._leftRotate(parent);
11658
11667
  node = this.root;
11659
11668
  }
11660
11669
  }
11661
11670
  }
11662
11671
  if (node) {
11663
- node.color = 0 /* BLACK */;
11672
+ node.color = "BLACK";
11664
11673
  }
11665
11674
  }
11666
11675
  /**
@@ -11780,7 +11789,19 @@ var dataStructureTyped = (() => {
11780
11789
  get count() {
11781
11790
  return this._count;
11782
11791
  }
11783
- getMutableCount() {
11792
+ /**
11793
+ * Time Complexity: O(n)
11794
+ * Space Complexity: O(1)
11795
+ */
11796
+ /**
11797
+ * Time Complexity: O(n)
11798
+ * Space Complexity: O(1)
11799
+ *
11800
+ * The function calculates the sum of the count property of all nodes in a tree using depth-first
11801
+ * search.
11802
+ * @returns the sum of the count property of all nodes in the tree.
11803
+ */
11804
+ getComputedCount() {
11784
11805
  let sum = 0;
11785
11806
  this.dfs((node) => sum += node.count);
11786
11807
  return sum;
@@ -11988,7 +12009,7 @@ var dataStructureTyped = (() => {
11988
12009
  * @returns a boolean value.
11989
12010
  */
11990
12011
  perfectlyBalance(iterationType = this.iterationType) {
11991
- const sorted = this.dfs((node) => node, "in"), n = sorted.length;
12012
+ const sorted = this.dfs((node) => node, "IN"), n = sorted.length;
11992
12013
  if (sorted.length < 1)
11993
12014
  return false;
11994
12015
  this.clear();
@@ -12085,17 +12106,19 @@ var dataStructureTyped = (() => {
12085
12106
  // src/data-structures/binary-tree/tree-multi-map.ts
12086
12107
  var TreeMultiMapNode = class extends RedBlackTreeNode {
12087
12108
  /**
12088
- * The constructor function initializes an instance of a class with a key, value, and count.
12089
- * @param {K} key - The key parameter is of type K, which represents the type of the key for the
12090
- * constructor. It is required and must be provided when creating an instance of the class.
12091
- * @param {V} [value] - The `value` parameter is an optional parameter of type `V`. It represents the
12092
- * value associated with the key in the constructor. If no value is provided, it will be `undefined`.
12093
- * @param [count=1] - The "count" parameter is an optional parameter that specifies the number of
12094
- * times the key-value pair should be repeated. If no value is provided for "count", it defaults to
12095
- * 1.
12096
- */
12097
- constructor(key, value, count = 1) {
12098
- super(key, value);
12109
+ * The constructor function initializes a Red-Black Tree node with a key, value, count, and color.
12110
+ * @param {K} key - The key parameter represents the key of the node in the Red-Black Tree. It is
12111
+ * used to identify and locate the node within the tree.
12112
+ * @param {V} [value] - The `value` parameter is an optional parameter that represents the value
12113
+ * associated with the key in the Red-Black Tree node. It is not required and can be omitted when
12114
+ * creating a new node.
12115
+ * @param [count=1] - The `count` parameter represents the number of occurrences of a particular key
12116
+ * in the Red-Black Tree. It is an optional parameter with a default value of 1.
12117
+ * @param {RBTNColor} [color=BLACK] - The `color` parameter is used to specify the color of the node
12118
+ * in a Red-Black Tree. It is optional and has a default value of `'BLACK'`.
12119
+ */
12120
+ constructor(key, value, count = 1, color = "BLACK") {
12121
+ super(key, value, color);
12099
12122
  __publicField(this, "_count", 1);
12100
12123
  this.count = count;
12101
12124
  }
@@ -12139,24 +12162,39 @@ var dataStructureTyped = (() => {
12139
12162
  get count() {
12140
12163
  return this._count;
12141
12164
  }
12142
- getMutableCount() {
12165
+ /**
12166
+ * Time Complexity: O(n)
12167
+ * Space Complexity: O(1)
12168
+ */
12169
+ /**
12170
+ * Time Complexity: O(n)
12171
+ * Space Complexity: O(1)
12172
+ *
12173
+ * The function calculates the sum of the count property of all nodes in a tree using depth-first
12174
+ * search.
12175
+ * @returns the sum of the count property of all nodes in the tree.
12176
+ */
12177
+ getComputedCount() {
12143
12178
  let sum = 0;
12144
12179
  this.dfs((node) => sum += node.count);
12145
12180
  return sum;
12146
12181
  }
12147
12182
  /**
12148
- * The function creates a new TreeMultiMapNode object with the specified key, value, and count.
12183
+ * The function creates a new TreeMultiMapNode with the specified key, value, color, and count.
12149
12184
  * @param {K} key - The key parameter represents the key of the node being created. It is of type K,
12150
- * which is a generic type that can be replaced with any specific type when using the function.
12151
- * @param {V} [value] - The `value` parameter is an optional parameter that represents the value
12152
- * associated with the key in the node. It is of type `V`, which can be any data type.
12153
- * @param {number} [count] - The `count` parameter represents the number of occurrences of a
12154
- * key-value pair in the TreeMultiMap. It is an optional parameter, so if it is not provided, it will
12155
- * default to 1.
12156
- * @returns a new instance of the TreeMultiMapNode class, casted as NODE.
12185
+ * which is a generic type representing the key type of the node.
12186
+ * @param {V} [value] - The `value` parameter represents the value associated with the key in the
12187
+ * node. It is an optional parameter, which means it can be omitted when calling the `createNode`
12188
+ * function. If provided, it should be of type `V`.
12189
+ * @param {RBTNColor} [color=BLACK] - The color parameter is used to specify the color of the node in
12190
+ * a Red-Black Tree. It can have two possible values: 'RED' or 'BLACK'. The default value is 'BLACK'.
12191
+ * @param {number} [count] - The `count` parameter represents the number of occurrences of a key in
12192
+ * the tree. It is an optional parameter and is used to keep track of the number of values associated
12193
+ * with a key in the tree.
12194
+ * @returns A new instance of the TreeMultiMapNode class is being returned.
12157
12195
  */
12158
- createNode(key, value, count) {
12159
- return new TreeMultiMapNode(key, value, count);
12196
+ createNode(key, value, color = "BLACK", count) {
12197
+ return new TreeMultiMapNode(key, value, count, color);
12160
12198
  }
12161
12199
  /**
12162
12200
  * The function creates a new instance of a TreeMultiMap with the specified options and returns it.
@@ -12193,10 +12231,10 @@ var dataStructureTyped = (() => {
12193
12231
  if (key === void 0 || key === null) {
12194
12232
  return;
12195
12233
  } else {
12196
- node = this.createNode(key, value2, count);
12234
+ node = this.createNode(key, value2, "BLACK", count);
12197
12235
  }
12198
12236
  } else if (!this.isNode(keyOrNodeOrEntry)) {
12199
- node = this.createNode(keyOrNodeOrEntry, value, count);
12237
+ node = this.createNode(keyOrNodeOrEntry, value, "BLACK", count);
12200
12238
  } else {
12201
12239
  return;
12202
12240
  }
@@ -12338,7 +12376,7 @@ var dataStructureTyped = (() => {
12338
12376
  }
12339
12377
  }
12340
12378
  this._size--;
12341
- if (originalColor === 0 /* BLACK */) {
12379
+ if (originalColor === "BLACK") {
12342
12380
  this._deleteFixup(replacementNode);
12343
12381
  }
12344
12382
  results.push({ deleted: nodeToDelete, needBalanced: void 0 });
@@ -12375,7 +12413,7 @@ var dataStructureTyped = (() => {
12375
12413
  * @returns a boolean value.
12376
12414
  */
12377
12415
  perfectlyBalance(iterationType = this.iterationType) {
12378
- const sorted = this.dfs((node) => node, "in"), n = sorted.length;
12416
+ const sorted = this.dfs((node) => node, "IN"), n = sorted.length;
12379
12417
  if (sorted.length < 1)
12380
12418
  return false;
12381
12419
  this.clear();
@@ -12441,7 +12479,7 @@ var dataStructureTyped = (() => {
12441
12479
  destNode = this.ensureNode(destNode);
12442
12480
  if (srcNode && destNode) {
12443
12481
  const { key, value, count, color } = destNode;
12444
- const tempNode = this.createNode(key, value, count);
12482
+ const tempNode = this.createNode(key, value, color, count);
12445
12483
  if (tempNode) {
12446
12484
  tempNode.color = color;
12447
12485
  destNode.key = srcNode.key;