data-structure-typed 1.50.6 → 1.50.8

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 (57) hide show
  1. package/CHANGELOG.md +1 -1
  2. package/README.md +27 -24
  3. package/benchmark/report.html +1 -37
  4. package/benchmark/report.json +17 -395
  5. package/dist/cjs/data-structures/binary-tree/avl-tree-multi-map.d.ts +2 -2
  6. package/dist/cjs/data-structures/binary-tree/avl-tree-multi-map.js +6 -4
  7. package/dist/cjs/data-structures/binary-tree/avl-tree-multi-map.js.map +1 -1
  8. package/dist/cjs/data-structures/binary-tree/avl-tree.js.map +1 -1
  9. package/dist/cjs/data-structures/binary-tree/binary-tree.d.ts +3 -3
  10. package/dist/cjs/data-structures/binary-tree/binary-tree.js +36 -33
  11. package/dist/cjs/data-structures/binary-tree/binary-tree.js.map +1 -1
  12. package/dist/cjs/data-structures/binary-tree/bst.d.ts +7 -5
  13. package/dist/cjs/data-structures/binary-tree/bst.js +68 -47
  14. package/dist/cjs/data-structures/binary-tree/bst.js.map +1 -1
  15. package/dist/cjs/data-structures/binary-tree/rb-tree.d.ts +2 -8
  16. package/dist/cjs/data-structures/binary-tree/rb-tree.js +7 -17
  17. package/dist/cjs/data-structures/binary-tree/rb-tree.js.map +1 -1
  18. package/dist/cjs/data-structures/binary-tree/tree-multi-map.d.ts +1 -2
  19. package/dist/cjs/data-structures/binary-tree/tree-multi-map.js +1 -1
  20. package/dist/cjs/data-structures/binary-tree/tree-multi-map.js.map +1 -1
  21. package/dist/cjs/types/common.d.ts +5 -22
  22. package/dist/cjs/types/common.js +0 -33
  23. package/dist/cjs/types/common.js.map +1 -1
  24. package/dist/mjs/data-structures/binary-tree/avl-tree-multi-map.d.ts +2 -2
  25. package/dist/mjs/data-structures/binary-tree/avl-tree-multi-map.js +6 -4
  26. package/dist/mjs/data-structures/binary-tree/binary-tree.d.ts +3 -3
  27. package/dist/mjs/data-structures/binary-tree/binary-tree.js +36 -33
  28. package/dist/mjs/data-structures/binary-tree/bst.d.ts +7 -5
  29. package/dist/mjs/data-structures/binary-tree/bst.js +68 -47
  30. package/dist/mjs/data-structures/binary-tree/rb-tree.d.ts +2 -8
  31. package/dist/mjs/data-structures/binary-tree/rb-tree.js +7 -17
  32. package/dist/mjs/data-structures/binary-tree/tree-multi-map.d.ts +1 -2
  33. package/dist/mjs/data-structures/binary-tree/tree-multi-map.js +2 -2
  34. package/dist/mjs/types/common.d.ts +5 -22
  35. package/dist/mjs/types/common.js +1 -32
  36. package/dist/umd/data-structure-typed.js +112 -138
  37. package/dist/umd/data-structure-typed.min.js +2 -2
  38. package/dist/umd/data-structure-typed.min.js.map +1 -1
  39. package/package.json +6 -6
  40. package/src/data-structures/binary-tree/avl-tree-multi-map.ts +8 -5
  41. package/src/data-structures/binary-tree/avl-tree.ts +1 -1
  42. package/src/data-structures/binary-tree/binary-tree.ts +35 -36
  43. package/src/data-structures/binary-tree/bst.ts +67 -44
  44. package/src/data-structures/binary-tree/rb-tree.ts +11 -22
  45. package/src/data-structures/binary-tree/tree-multi-map.ts +2 -2
  46. package/src/types/common.ts +6 -23
  47. package/test/integration/all-in-one.test.ts +2 -2
  48. package/test/integration/avl-tree.test.ts +1 -1
  49. package/test/integration/bst.test.ts +2 -2
  50. package/test/performance/data-structures/binary-tree/rb-tree.test.ts +13 -22
  51. package/test/unit/data-structures/binary-tree/avl-tree-multi-map.test.ts +12 -17
  52. package/test/unit/data-structures/binary-tree/avl-tree.test.ts +4 -4
  53. package/test/unit/data-structures/binary-tree/binary-tree.test.ts +118 -65
  54. package/test/unit/data-structures/binary-tree/bst.test.ts +12 -12
  55. package/test/unit/data-structures/binary-tree/overall.test.ts +7 -7
  56. package/test/unit/data-structures/binary-tree/rb-tree.test.ts +272 -267
  57. package/test/unit/data-structures/binary-tree/tree-multi-map.test.ts +249 -245
@@ -110,11 +110,9 @@ var dataStructureTyped = (() => {
110
110
  AbstractVertex: () => AbstractVertex,
111
111
  BST: () => BST,
112
112
  BSTNode: () => BSTNode,
113
- BSTVariant: () => BSTVariant,
114
113
  BinaryIndexedTree: () => BinaryIndexedTree,
115
114
  BinaryTree: () => BinaryTree,
116
115
  BinaryTreeNode: () => BinaryTreeNode,
117
- CP: () => CP,
118
116
  Character: () => Character,
119
117
  Deque: () => Deque,
120
118
  DirectedEdge: () => DirectedEdge,
@@ -122,14 +120,12 @@ var dataStructureTyped = (() => {
122
120
  DirectedVertex: () => DirectedVertex,
123
121
  DoublyLinkedList: () => DoublyLinkedList,
124
122
  DoublyLinkedListNode: () => DoublyLinkedListNode,
125
- FamilyPosition: () => FamilyPosition,
126
123
  FibonacciHeap: () => FibonacciHeap,
127
124
  FibonacciHeapNode: () => FibonacciHeapNode,
128
125
  HashMap: () => HashMap,
129
126
  Heap: () => Heap,
130
127
  IterableElementBase: () => IterableElementBase,
131
128
  IterableEntryBase: () => IterableEntryBase,
132
- IterationType: () => IterationType,
133
129
  LinkedHashMap: () => LinkedHashMap,
134
130
  LinkedListQueue: () => LinkedListQueue,
135
131
  MapEdge: () => MapEdge,
@@ -7655,41 +7651,6 @@ var dataStructureTyped = (() => {
7655
7651
  }
7656
7652
  };
7657
7653
 
7658
- // src/types/data-structures/binary-tree/rb-tree.ts
7659
- var RBTNColor = /* @__PURE__ */ ((RBTNColor2) => {
7660
- RBTNColor2[RBTNColor2["RED"] = 1] = "RED";
7661
- RBTNColor2[RBTNColor2["BLACK"] = 0] = "BLACK";
7662
- return RBTNColor2;
7663
- })(RBTNColor || {});
7664
-
7665
- // src/types/common.ts
7666
- var BSTVariant = /* @__PURE__ */ ((BSTVariant2) => {
7667
- BSTVariant2["STANDARD"] = "STANDARD";
7668
- BSTVariant2["INVERSE"] = "INVERSE";
7669
- return BSTVariant2;
7670
- })(BSTVariant || {});
7671
- var CP = /* @__PURE__ */ ((CP2) => {
7672
- CP2["lt"] = "lt";
7673
- CP2["eq"] = "eq";
7674
- CP2["gt"] = "gt";
7675
- return CP2;
7676
- })(CP || {});
7677
- var IterationType = /* @__PURE__ */ ((IterationType2) => {
7678
- IterationType2["ITERATIVE"] = "ITERATIVE";
7679
- IterationType2["RECURSIVE"] = "RECURSIVE";
7680
- return IterationType2;
7681
- })(IterationType || {});
7682
- var FamilyPosition = /* @__PURE__ */ ((FamilyPosition2) => {
7683
- FamilyPosition2["ROOT"] = "ROOT";
7684
- FamilyPosition2["LEFT"] = "LEFT";
7685
- FamilyPosition2["RIGHT"] = "RIGHT";
7686
- FamilyPosition2["ROOT_LEFT"] = "ROOT_LEFT";
7687
- FamilyPosition2["ROOT_RIGHT"] = "ROOT_RIGHT";
7688
- FamilyPosition2["ISOLATED"] = "ISOLATED";
7689
- FamilyPosition2["MAL_NODE"] = "MAL_NODE";
7690
- return FamilyPosition2;
7691
- })(FamilyPosition || {});
7692
-
7693
7654
  // src/data-structures/binary-tree/binary-tree.ts
7694
7655
  var BinaryTreeNode = class {
7695
7656
  /**
@@ -7754,14 +7715,14 @@ var dataStructureTyped = (() => {
7754
7715
  get familyPosition() {
7755
7716
  const that = this;
7756
7717
  if (!this.parent) {
7757
- return this.left || this.right ? "ROOT" /* ROOT */ : "ISOLATED" /* ISOLATED */;
7718
+ return this.left || this.right ? "ROOT" : "ISOLATED";
7758
7719
  }
7759
7720
  if (this.parent.left === that) {
7760
- return this.left || this.right ? "ROOT_LEFT" /* ROOT_LEFT */ : "LEFT" /* LEFT */;
7721
+ return this.left || this.right ? "ROOT_LEFT" : "LEFT";
7761
7722
  } else if (this.parent.right === that) {
7762
- return this.left || this.right ? "ROOT_RIGHT" /* ROOT_RIGHT */ : "RIGHT" /* RIGHT */;
7723
+ return this.left || this.right ? "ROOT_RIGHT" : "RIGHT";
7763
7724
  }
7764
- return "MAL_NODE" /* MAL_NODE */;
7725
+ return "MAL_NODE";
7765
7726
  }
7766
7727
  };
7767
7728
  var BinaryTree = class _BinaryTree extends IterableEntryBase {
@@ -7776,8 +7737,8 @@ var dataStructureTyped = (() => {
7776
7737
  */
7777
7738
  constructor(keysOrNodesOrEntries = [], options) {
7778
7739
  super();
7779
- __publicField(this, "iterationType", "ITERATIVE" /* ITERATIVE */);
7780
- __publicField(this, "_extractor", (key) => Number(key));
7740
+ __publicField(this, "iterationType", "ITERATIVE");
7741
+ __publicField(this, "_extractor", (key) => typeof key === "number" ? key : Number(key));
7781
7742
  __publicField(this, "_root");
7782
7743
  __publicField(this, "_size");
7783
7744
  __publicField(this, "_defaultOneParamCallback", (node) => node ? node.key : void 0);
@@ -7879,11 +7840,11 @@ var dataStructureTyped = (() => {
7879
7840
  * `null`, or `undefined`. It represents a key used to identify a node in a binary tree.
7880
7841
  * @param iterationType - The `iterationType` parameter is an optional parameter that specifies the
7881
7842
  * type of iteration to be used when searching for a node by key. It has a default value of
7882
- * `IterationType.ITERATIVE`.
7843
+ * `'ITERATIVE'`.
7883
7844
  * @returns either the node corresponding to the given key if it is a valid node key, or the key
7884
7845
  * itself if it is not a valid node key.
7885
7846
  */
7886
- ensureNode(keyOrNodeOrEntry, iterationType = "ITERATIVE" /* ITERATIVE */) {
7847
+ ensureNode(keyOrNodeOrEntry, iterationType = "ITERATIVE") {
7887
7848
  let res;
7888
7849
  if (this.isRealNode(keyOrNodeOrEntry)) {
7889
7850
  res = keyOrNodeOrEntry;
@@ -8099,9 +8060,9 @@ var dataStructureTyped = (() => {
8099
8060
  }
8100
8061
  } else if (parent) {
8101
8062
  const { familyPosition: fp } = curr;
8102
- if (fp === "LEFT" /* LEFT */ || fp === "ROOT_LEFT" /* ROOT_LEFT */) {
8063
+ if (fp === "LEFT" || fp === "ROOT_LEFT") {
8103
8064
  parent.left = curr.right;
8104
- } else if (fp === "RIGHT" /* RIGHT */ || fp === "ROOT_RIGHT" /* ROOT_RIGHT */) {
8065
+ } else if (fp === "RIGHT" || fp === "ROOT_RIGHT") {
8105
8066
  parent.right = curr.right;
8106
8067
  }
8107
8068
  needBalanced = parent;
@@ -8149,7 +8110,7 @@ var dataStructureTyped = (() => {
8149
8110
  if (!beginRoot)
8150
8111
  return [];
8151
8112
  const ans = [];
8152
- if (iterationType === "RECURSIVE" /* RECURSIVE */) {
8113
+ if (iterationType === "RECURSIVE") {
8153
8114
  const _traverse = (cur) => {
8154
8115
  if (callback(cur) === identifier) {
8155
8116
  ans.push(cur);
@@ -8228,10 +8189,10 @@ var dataStructureTyped = (() => {
8228
8189
  * @returns The function `getNodeByKey` returns a node (`NODE`) if a node with the specified key is
8229
8190
  * found in the binary tree. If no node is found, it returns `undefined`.
8230
8191
  */
8231
- getNodeByKey(key, iterationType = "ITERATIVE" /* ITERATIVE */) {
8192
+ getNodeByKey(key, iterationType = "ITERATIVE") {
8232
8193
  if (!this.root)
8233
8194
  return void 0;
8234
- if (iterationType === "RECURSIVE" /* RECURSIVE */) {
8195
+ if (iterationType === "RECURSIVE") {
8235
8196
  const _dfs = (cur) => {
8236
8197
  if (cur.key === key)
8237
8198
  return cur;
@@ -8384,7 +8345,7 @@ var dataStructureTyped = (() => {
8384
8345
  beginRoot = this.ensureNode(beginRoot);
8385
8346
  if (!beginRoot)
8386
8347
  return true;
8387
- if (iterationType === "RECURSIVE" /* RECURSIVE */) {
8348
+ if (iterationType === "RECURSIVE") {
8388
8349
  const dfs = (cur, min, max) => {
8389
8350
  if (!this.isRealNode(cur))
8390
8351
  return true;
@@ -8469,9 +8430,9 @@ var dataStructureTyped = (() => {
8469
8430
  */
8470
8431
  getHeight(beginRoot = this.root, iterationType = this.iterationType) {
8471
8432
  beginRoot = this.ensureNode(beginRoot);
8472
- if (!beginRoot)
8433
+ if (!this.isRealNode(beginRoot))
8473
8434
  return -1;
8474
- if (iterationType === "RECURSIVE" /* RECURSIVE */) {
8435
+ if (iterationType === "RECURSIVE") {
8475
8436
  const _getMaxHeight = (cur) => {
8476
8437
  if (!this.isRealNode(cur))
8477
8438
  return -1;
@@ -8516,11 +8477,11 @@ var dataStructureTyped = (() => {
8516
8477
  beginRoot = this.ensureNode(beginRoot);
8517
8478
  if (!beginRoot)
8518
8479
  return -1;
8519
- if (iterationType === "RECURSIVE" /* RECURSIVE */) {
8480
+ if (iterationType === "RECURSIVE") {
8520
8481
  const _getMinHeight = (cur) => {
8521
- if (!cur)
8482
+ if (!this.isRealNode(cur))
8522
8483
  return 0;
8523
- if (!cur.left && !cur.right)
8484
+ if (!this.isRealNode(cur.left) && !this.isRealNode(cur.right))
8524
8485
  return 0;
8525
8486
  const leftMinHeight = _getMinHeight(cur.left);
8526
8487
  const rightMinHeight = _getMinHeight(cur.right);
@@ -8532,16 +8493,16 @@ var dataStructureTyped = (() => {
8532
8493
  let node = beginRoot, last = null;
8533
8494
  const depths = /* @__PURE__ */ new Map();
8534
8495
  while (stack.length > 0 || node) {
8535
- if (node) {
8496
+ if (this.isRealNode(node)) {
8536
8497
  stack.push(node);
8537
8498
  node = node.left;
8538
8499
  } else {
8539
8500
  node = stack[stack.length - 1];
8540
- if (!node.right || last === node.right) {
8501
+ if (!this.isRealNode(node.right) || last === node.right) {
8541
8502
  node = stack.pop();
8542
- if (node) {
8543
- const leftMinHeight = node.left ? (_a = depths.get(node.left)) != null ? _a : -1 : -1;
8544
- const rightMinHeight = node.right ? (_b = depths.get(node.right)) != null ? _b : -1 : -1;
8503
+ if (this.isRealNode(node)) {
8504
+ const leftMinHeight = this.isRealNode(node.left) ? (_a = depths.get(node.left)) != null ? _a : -1 : -1;
8505
+ const rightMinHeight = this.isRealNode(node.right) ? (_b = depths.get(node.right)) != null ? _b : -1 : -1;
8545
8506
  depths.set(node, 1 + Math.min(leftMinHeight, rightMinHeight));
8546
8507
  last = node;
8547
8508
  node = null;
@@ -8603,10 +8564,12 @@ var dataStructureTyped = (() => {
8603
8564
  * is no leftmost node, it returns `null` or `undefined` depending on the input.
8604
8565
  */
8605
8566
  getLeftMost(beginRoot = this.root, iterationType = this.iterationType) {
8567
+ if (this.isNIL(beginRoot))
8568
+ return beginRoot;
8606
8569
  beginRoot = this.ensureNode(beginRoot);
8607
- if (!beginRoot)
8570
+ if (!this.isRealNode(beginRoot))
8608
8571
  return beginRoot;
8609
- if (iterationType === "RECURSIVE" /* RECURSIVE */) {
8572
+ if (iterationType === "RECURSIVE") {
8610
8573
  const _traverse = (cur) => {
8611
8574
  if (!this.isRealNode(cur.left))
8612
8575
  return cur;
@@ -8642,10 +8605,12 @@ var dataStructureTyped = (() => {
8642
8605
  * is no rightmost node, it returns `null` or `undefined`, depending on the input.
8643
8606
  */
8644
8607
  getRightMost(beginRoot = this.root, iterationType = this.iterationType) {
8608
+ if (this.isNIL(beginRoot))
8609
+ return beginRoot;
8645
8610
  beginRoot = this.ensureNode(beginRoot);
8646
8611
  if (!beginRoot)
8647
8612
  return beginRoot;
8648
- if (iterationType === "RECURSIVE" /* RECURSIVE */) {
8613
+ if (iterationType === "RECURSIVE") {
8649
8614
  const _traverse = (cur) => {
8650
8615
  if (!this.isRealNode(cur.right))
8651
8616
  return cur;
@@ -8742,12 +8707,12 @@ var dataStructureTyped = (() => {
8742
8707
  * `false`, null or undefined
8743
8708
  * @returns an array of values that are the return values of the callback function.
8744
8709
  */
8745
- dfs(callback = this._defaultOneParamCallback, pattern = "in", beginRoot = this.root, iterationType = "ITERATIVE" /* ITERATIVE */, includeNull = false) {
8710
+ dfs(callback = this._defaultOneParamCallback, pattern = "in", beginRoot = this.root, iterationType = "ITERATIVE", includeNull = false) {
8746
8711
  beginRoot = this.ensureNode(beginRoot);
8747
8712
  if (!beginRoot)
8748
8713
  return [];
8749
8714
  const ans = [];
8750
- if (iterationType === "RECURSIVE" /* RECURSIVE */) {
8715
+ if (iterationType === "RECURSIVE") {
8751
8716
  const _traverse = (node) => {
8752
8717
  switch (pattern) {
8753
8718
  case "in":
@@ -8871,7 +8836,7 @@ var dataStructureTyped = (() => {
8871
8836
  if (!beginRoot)
8872
8837
  return [];
8873
8838
  const ans = [];
8874
- if (iterationType === "RECURSIVE" /* RECURSIVE */) {
8839
+ if (iterationType === "RECURSIVE") {
8875
8840
  const queue = new Queue([beginRoot]);
8876
8841
  const traverse = (level) => {
8877
8842
  if (queue.size === 0)
@@ -8945,7 +8910,7 @@ var dataStructureTyped = (() => {
8945
8910
  const levelsNodes = [];
8946
8911
  if (!beginRoot)
8947
8912
  return levelsNodes;
8948
- if (iterationType === "RECURSIVE" /* RECURSIVE */) {
8913
+ if (iterationType === "RECURSIVE") {
8949
8914
  const _recursive = (node, level) => {
8950
8915
  if (!levelsNodes[level])
8951
8916
  levelsNodes[level] = [];
@@ -9230,7 +9195,7 @@ var dataStructureTyped = (() => {
9230
9195
  *_getIterator(node = this.root) {
9231
9196
  if (!node)
9232
9197
  return;
9233
- if (this.iterationType === "ITERATIVE" /* ITERATIVE */) {
9198
+ if (this.iterationType === "ITERATIVE") {
9234
9199
  const stack = [];
9235
9200
  let current = node;
9236
9201
  while (current || stack.length > 0) {
@@ -9429,7 +9394,7 @@ var dataStructureTyped = (() => {
9429
9394
  constructor(keysOrNodesOrEntries = [], options) {
9430
9395
  super([], options);
9431
9396
  __publicField(this, "_root");
9432
- __publicField(this, "_variant", "STANDARD" /* STANDARD */);
9397
+ __publicField(this, "_variant", "STANDARD");
9433
9398
  if (options) {
9434
9399
  const { variant } = options;
9435
9400
  if (variant)
@@ -9519,10 +9484,10 @@ var dataStructureTyped = (() => {
9519
9484
  * @param {K | NODE | undefined} keyOrNodeOrEntry - The `key` parameter can be of type `K`, `NODE`, or
9520
9485
  * `undefined`.
9521
9486
  * @param iterationType - The `iterationType` parameter is an optional parameter that specifies the
9522
- * type of iteration to be performed. It has a default value of `IterationType.ITERATIVE`.
9487
+ * type of iteration to be performed. It has a default value of `'ITERATIVE'`.
9523
9488
  * @returns either a node object (NODE) or undefined.
9524
9489
  */
9525
- ensureNode(keyOrNodeOrEntry, iterationType = "ITERATIVE" /* ITERATIVE */) {
9490
+ ensureNode(keyOrNodeOrEntry, iterationType = "ITERATIVE") {
9526
9491
  let res;
9527
9492
  if (this.isRealNode(keyOrNodeOrEntry)) {
9528
9493
  res = keyOrNodeOrEntry;
@@ -9570,10 +9535,10 @@ var dataStructureTyped = (() => {
9570
9535
  }
9571
9536
  let current = this.root;
9572
9537
  while (current !== void 0) {
9573
- if (this._compare(current.key, newNode.key) === "eq" /* eq */) {
9538
+ if (this._compare(current.key, newNode.key) === "EQ") {
9574
9539
  this._replaceNode(current, newNode);
9575
9540
  return true;
9576
- } else if (this._compare(current.key, newNode.key) === "gt" /* gt */) {
9541
+ } else if (this._compare(current.key, newNode.key) === "GT") {
9577
9542
  if (current.left === void 0) {
9578
9543
  current.left = newNode;
9579
9544
  this._size++;
@@ -9681,7 +9646,7 @@ var dataStructureTyped = (() => {
9681
9646
  }
9682
9647
  }
9683
9648
  };
9684
- if (iterationType === "RECURSIVE" /* RECURSIVE */) {
9649
+ if (iterationType === "RECURSIVE") {
9685
9650
  _dfs(sorted);
9686
9651
  } else {
9687
9652
  _iterate();
@@ -9706,18 +9671,18 @@ var dataStructureTyped = (() => {
9706
9671
  * @returns The function `getNodeByKey` returns a node (`NODE`) if a node with the specified key is
9707
9672
  * found in the binary tree. If no node is found, it returns `undefined`.
9708
9673
  */
9709
- getNodeByKey(key, iterationType = "ITERATIVE" /* ITERATIVE */) {
9710
- if (!this.root)
9674
+ getNodeByKey(key, iterationType = "ITERATIVE") {
9675
+ if (!this.isRealNode(this.root))
9711
9676
  return void 0;
9712
- if (iterationType === "RECURSIVE" /* RECURSIVE */) {
9677
+ if (iterationType === "RECURSIVE") {
9713
9678
  const _dfs = (cur) => {
9714
9679
  if (cur.key === key)
9715
9680
  return cur;
9716
- if (!cur.left && !cur.right)
9681
+ if (!this.isRealNode(cur.left) && !this.isRealNode(cur.right))
9717
9682
  return;
9718
- if (this._compare(cur.key, key) === "gt" /* gt */ && cur.left)
9683
+ if (this._compare(cur.key, key) === "GT" && this.isRealNode(cur.left))
9719
9684
  return _dfs(cur.left);
9720
- if (this._compare(cur.key, key) === "lt" /* lt */ && cur.right)
9685
+ if (this._compare(cur.key, key) === "LT" && this.isRealNode(cur.right))
9721
9686
  return _dfs(cur.right);
9722
9687
  };
9723
9688
  return _dfs(this.root);
@@ -9725,13 +9690,13 @@ var dataStructureTyped = (() => {
9725
9690
  const queue = new Queue([this.root]);
9726
9691
  while (queue.size > 0) {
9727
9692
  const cur = queue.shift();
9728
- if (cur) {
9729
- if (this._compare(cur.key, key) === "eq" /* eq */)
9693
+ if (this.isRealNode(cur)) {
9694
+ if (this._compare(cur.key, key) === "EQ")
9730
9695
  return cur;
9731
- if (this._compare(cur.key, key) === "gt" /* gt */)
9732
- cur.left && queue.push(cur.left);
9733
- if (this._compare(cur.key, key) === "lt" /* lt */)
9734
- cur.right && queue.push(cur.right);
9696
+ if (this._compare(cur.key, key) === "GT")
9697
+ this.isRealNode(cur.left) && queue.push(cur.left);
9698
+ if (this._compare(cur.key, key) === "LT")
9699
+ this.isRealNode(cur.right) && queue.push(cur.right);
9735
9700
  }
9736
9701
  }
9737
9702
  }
@@ -9769,7 +9734,7 @@ var dataStructureTyped = (() => {
9769
9734
  if (!beginRoot)
9770
9735
  return [];
9771
9736
  const ans = [];
9772
- if (iterationType === "RECURSIVE" /* RECURSIVE */) {
9737
+ if (iterationType === "RECURSIVE") {
9773
9738
  const _traverse = (cur) => {
9774
9739
  const callbackResult = callback(cur);
9775
9740
  if (callbackResult === identifier) {
@@ -9777,24 +9742,24 @@ var dataStructureTyped = (() => {
9777
9742
  if (onlyOne)
9778
9743
  return;
9779
9744
  }
9780
- if (!cur.left && !cur.right)
9745
+ if (!this.isRealNode(cur.left) && !this.isRealNode(cur.right))
9781
9746
  return;
9782
9747
  if (callback === this._defaultOneParamCallback) {
9783
- if (this._compare(cur.key, identifier) === "gt" /* gt */)
9784
- cur.left && _traverse(cur.left);
9785
- if (this._compare(cur.key, identifier) === "lt" /* lt */)
9786
- cur.right && _traverse(cur.right);
9748
+ if (this.isRealNode(cur.left) && this._compare(cur.key, identifier) === "GT")
9749
+ _traverse(cur.left);
9750
+ if (this.isRealNode(cur.right) && this._compare(cur.key, identifier) === "LT")
9751
+ _traverse(cur.right);
9787
9752
  } else {
9788
- cur.left && _traverse(cur.left);
9789
- cur.right && _traverse(cur.right);
9753
+ this.isRealNode(cur.left) && _traverse(cur.left);
9754
+ this.isRealNode(cur.right) && _traverse(cur.right);
9790
9755
  }
9791
9756
  };
9792
9757
  _traverse(beginRoot);
9793
9758
  } else {
9794
- const queue = new Queue([beginRoot]);
9795
- while (queue.size > 0) {
9796
- const cur = queue.shift();
9797
- if (cur) {
9759
+ const stack = [beginRoot];
9760
+ while (stack.length > 0) {
9761
+ const cur = stack.pop();
9762
+ if (this.isRealNode(cur)) {
9798
9763
  const callbackResult = callback(cur);
9799
9764
  if (callbackResult === identifier) {
9800
9765
  ans.push(cur);
@@ -9802,13 +9767,13 @@ var dataStructureTyped = (() => {
9802
9767
  return ans;
9803
9768
  }
9804
9769
  if (callback === this._defaultOneParamCallback) {
9805
- if (this._compare(cur.key, identifier) === "gt" /* gt */)
9806
- cur.left && queue.push(cur.left);
9807
- if (this._compare(cur.key, identifier) === "lt" /* lt */)
9808
- cur.right && queue.push(cur.right);
9770
+ if (this.isRealNode(cur.right) && this._compare(cur.key, identifier) === "LT")
9771
+ stack.push(cur.right);
9772
+ if (this.isRealNode(cur.left) && this._compare(cur.key, identifier) === "GT")
9773
+ stack.push(cur.left);
9809
9774
  } else {
9810
- cur.left && queue.push(cur.left);
9811
- cur.right && queue.push(cur.right);
9775
+ this.isRealNode(cur.right) && stack.push(cur.right);
9776
+ this.isRealNode(cur.left) && stack.push(cur.left);
9812
9777
  }
9813
9778
  }
9814
9779
  }
@@ -9838,7 +9803,7 @@ var dataStructureTyped = (() => {
9838
9803
  * following values:
9839
9804
  * @returns The method is returning an array of the return type of the callback function.
9840
9805
  */
9841
- dfs(callback = this._defaultOneParamCallback, pattern = "in", beginRoot = this.root, iterationType = "ITERATIVE" /* ITERATIVE */) {
9806
+ dfs(callback = this._defaultOneParamCallback, pattern = "in", beginRoot = this.root, iterationType = "ITERATIVE") {
9842
9807
  return super.dfs(callback, pattern, beginRoot, iterationType, false);
9843
9808
  }
9844
9809
  /**
@@ -9911,7 +9876,7 @@ var dataStructureTyped = (() => {
9911
9876
  let current = this.ensureNode(beginRoot);
9912
9877
  if (!current)
9913
9878
  return void 0;
9914
- if (this._variant === "STANDARD" /* STANDARD */) {
9879
+ if (this._variant === "STANDARD") {
9915
9880
  while (current.right !== void 0) {
9916
9881
  current = current.right;
9917
9882
  }
@@ -9947,7 +9912,7 @@ var dataStructureTyped = (() => {
9947
9912
  * @returns The function `lesserOrGreaterTraverse` returns an array of values of type
9948
9913
  * `ReturnType<C>`, which is the return type of the callback function passed as an argument.
9949
9914
  */
9950
- lesserOrGreaterTraverse(callback = this._defaultOneParamCallback, lesserOrGreater = "lt" /* lt */, targetNode = this.root, iterationType = this.iterationType) {
9915
+ lesserOrGreaterTraverse(callback = this._defaultOneParamCallback, lesserOrGreater = "LT", targetNode = this.root, iterationType = this.iterationType) {
9951
9916
  targetNode = this.ensureNode(targetNode);
9952
9917
  const ans = [];
9953
9918
  if (!targetNode)
@@ -9955,7 +9920,7 @@ var dataStructureTyped = (() => {
9955
9920
  if (!this.root)
9956
9921
  return ans;
9957
9922
  const targetKey = targetNode.key;
9958
- if (iterationType === "RECURSIVE" /* RECURSIVE */) {
9923
+ if (iterationType === "RECURSIVE") {
9959
9924
  const _traverse = (cur) => {
9960
9925
  const compared = this._compare(cur.key, targetKey);
9961
9926
  if (compared === lesserOrGreater)
@@ -10004,7 +9969,7 @@ var dataStructureTyped = (() => {
10004
9969
  this.clear();
10005
9970
  if (sorted.length < 1)
10006
9971
  return false;
10007
- if (iterationType === "RECURSIVE" /* RECURSIVE */) {
9972
+ if (iterationType === "RECURSIVE") {
10008
9973
  const buildBalanceBST = (l, r) => {
10009
9974
  if (l > r)
10010
9975
  return;
@@ -10061,7 +10026,7 @@ var dataStructureTyped = (() => {
10061
10026
  if (!this.root)
10062
10027
  return true;
10063
10028
  let balanced = true;
10064
- if (iterationType === "RECURSIVE" /* RECURSIVE */) {
10029
+ if (iterationType === "RECURSIVE") {
10065
10030
  const _height = (cur) => {
10066
10031
  if (!cur)
10067
10032
  return 0;
@@ -10115,14 +10080,24 @@ var dataStructureTyped = (() => {
10115
10080
  * is greater than, less than, or equal to the second value.
10116
10081
  * @param {K} a - The parameter "a" is of type K.
10117
10082
  * @param {K} b - The parameter "b" in the above code represents a K.
10118
- * @returns a value of type CP (ComparisonResult). The possible return values are CP.gt (greater
10119
- * than), CP.lt (less than), or CP.eq (equal).
10083
+ * @returns a value of type CP (ComparisonResult). The possible return values are 'GT' (greater
10084
+ * than), 'LT' (less than), or 'EQ' (equal).
10120
10085
  */
10121
10086
  _compare(a, b) {
10122
10087
  const extractedA = this.extractor(a);
10123
10088
  const extractedB = this.extractor(b);
10124
- const compared = this.variant === "STANDARD" /* STANDARD */ ? extractedA - extractedB : extractedB - extractedA;
10125
- return compared > 0 ? "gt" /* gt */ : compared < 0 ? "lt" /* lt */ : "eq" /* eq */;
10089
+ const compared = this.variant === "STANDARD" ? extractedA - extractedB : extractedB - extractedA;
10090
+ return compared > 0 ? "GT" : compared < 0 ? "LT" : "EQ";
10091
+ }
10092
+ _lt(a, b) {
10093
+ const extractedA = this.extractor(a);
10094
+ const extractedB = this.extractor(b);
10095
+ return this.variant === "STANDARD" ? extractedA < extractedB : extractedA > extractedB;
10096
+ }
10097
+ _gt(a, b) {
10098
+ const extractedA = this.extractor(a);
10099
+ const extractedB = this.extractor(b);
10100
+ return this.variant === "STANDARD" ? extractedA > extractedB : extractedA < extractedB;
10126
10101
  }
10127
10102
  };
10128
10103
 
@@ -11141,6 +11116,13 @@ var dataStructureTyped = (() => {
11141
11116
  }
11142
11117
  };
11143
11118
 
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
+
11144
11126
  // src/data-structures/binary-tree/rb-tree.ts
11145
11127
  var RedBlackTreeNode = class extends BSTNode {
11146
11128
  /**
@@ -11189,7 +11171,6 @@ var dataStructureTyped = (() => {
11189
11171
  super([], options);
11190
11172
  __publicField(this, "_SENTINEL", new RedBlackTreeNode(NaN));
11191
11173
  __publicField(this, "_root");
11192
- __publicField(this, "_size", 0);
11193
11174
  this._root = this.SENTINEL;
11194
11175
  if (keysOrNodesOrEntries) {
11195
11176
  this.addMany(keysOrNodesOrEntries);
@@ -11209,13 +11190,6 @@ var dataStructureTyped = (() => {
11209
11190
  get root() {
11210
11191
  return this._root;
11211
11192
  }
11212
- /**
11213
- * The function returns the size of an object.
11214
- * @returns The size of the object, which is a number.
11215
- */
11216
- get size() {
11217
- return this._size;
11218
- }
11219
11193
  /**
11220
11194
  * The function creates a new Red-Black Tree node with the specified key, value, and color.
11221
11195
  * @param {K} key - The key parameter represents the key of the node being created. It is of type K,
@@ -11307,7 +11281,7 @@ var dataStructureTyped = (() => {
11307
11281
  * @returns a boolean value.
11308
11282
  */
11309
11283
  isRealNode(node) {
11310
- if (node === this._SENTINEL || node === void 0)
11284
+ if (node === this.SENTINEL || node === void 0)
11311
11285
  return false;
11312
11286
  return node instanceof RedBlackTreeNode;
11313
11287
  }
@@ -11338,9 +11312,6 @@ var dataStructureTyped = (() => {
11338
11312
  */
11339
11313
  getNode(identifier, callback = this._defaultOneParamCallback, beginRoot = this.root, iterationType = this.iterationType) {
11340
11314
  var _a;
11341
- if (identifier instanceof RedBlackTreeNode)
11342
- callback = (node) => node;
11343
- beginRoot = this.ensureNode(beginRoot);
11344
11315
  return (_a = this.getNodes(identifier, callback, true, beginRoot, iterationType)[0]) != null ? _a : void 0;
11345
11316
  }
11346
11317
  /**
@@ -11355,8 +11326,8 @@ var dataStructureTyped = (() => {
11355
11326
  * size counter to zero.
11356
11327
  */
11357
11328
  clear() {
11329
+ super.clear();
11358
11330
  this._root = this.SENTINEL;
11359
- this._size = 0;
11360
11331
  }
11361
11332
  /**
11362
11333
  * Time Complexity: O(log n)
@@ -11380,7 +11351,7 @@ var dataStructureTyped = (() => {
11380
11351
  if (!this.isRealNode(newNode))
11381
11352
  return false;
11382
11353
  const insertStatus = this._insert(newNode);
11383
- if (insertStatus === "inserted") {
11354
+ if (insertStatus === "CREATED") {
11384
11355
  if (this.isRealNode(this._root)) {
11385
11356
  this._root.color = 0 /* BLACK */;
11386
11357
  } else {
@@ -11389,7 +11360,7 @@ var dataStructureTyped = (() => {
11389
11360
  this._size++;
11390
11361
  return true;
11391
11362
  } else
11392
- return insertStatus === "updated";
11363
+ return insertStatus === "UPDATED";
11393
11364
  }
11394
11365
  /**
11395
11366
  * Time Complexity: O(log n)
@@ -11516,7 +11487,7 @@ var dataStructureTyped = (() => {
11516
11487
  current = (_b = current.right) != null ? _b : this.SENTINEL;
11517
11488
  } else {
11518
11489
  this._replaceNode(current, node);
11519
- return "updated";
11490
+ return "UPDATED";
11520
11491
  }
11521
11492
  }
11522
11493
  node.parent = parent;
@@ -11531,7 +11502,7 @@ var dataStructureTyped = (() => {
11531
11502
  node.right = this.SENTINEL;
11532
11503
  node.color = 1 /* RED */;
11533
11504
  this._insertFixup(node);
11534
- return "inserted";
11505
+ return "CREATED";
11535
11506
  }
11536
11507
  /**
11537
11508
  * Time Complexity: O(1)
@@ -11807,6 +11778,9 @@ var dataStructureTyped = (() => {
11807
11778
  * @returns the sum of the count property of all nodes in the tree.
11808
11779
  */
11809
11780
  get count() {
11781
+ return this._count;
11782
+ }
11783
+ getMutableCount() {
11810
11784
  let sum = 0;
11811
11785
  this.dfs((node) => sum += node.count);
11812
11786
  return sum;
@@ -11952,9 +11926,9 @@ var dataStructureTyped = (() => {
11952
11926
  this._setRoot(curr.right);
11953
11927
  } else {
11954
11928
  const { familyPosition: fp } = curr;
11955
- if (fp === "LEFT" /* LEFT */ || fp === "ROOT_LEFT" /* ROOT_LEFT */) {
11929
+ if (fp === "LEFT" || fp === "ROOT_LEFT") {
11956
11930
  parent.left = curr.right;
11957
- } else if (fp === "RIGHT" /* RIGHT */ || fp === "ROOT_RIGHT" /* ROOT_RIGHT */) {
11931
+ } else if (fp === "RIGHT" || fp === "ROOT_RIGHT") {
11958
11932
  parent.right = curr.right;
11959
11933
  }
11960
11934
  needBalanced = parent;
@@ -12018,7 +11992,7 @@ var dataStructureTyped = (() => {
12018
11992
  if (sorted.length < 1)
12019
11993
  return false;
12020
11994
  this.clear();
12021
- if (iterationType === "RECURSIVE" /* RECURSIVE */) {
11995
+ if (iterationType === "RECURSIVE") {
12022
11996
  const buildBalanceBST = (l, r) => {
12023
11997
  if (l > r)
12024
11998
  return;
@@ -12405,7 +12379,7 @@ var dataStructureTyped = (() => {
12405
12379
  if (sorted.length < 1)
12406
12380
  return false;
12407
12381
  this.clear();
12408
- if (iterationType === "RECURSIVE" /* RECURSIVE */) {
12382
+ if (iterationType === "RECURSIVE") {
12409
12383
  const buildBalanceBST = (l, r) => {
12410
12384
  if (l > r)
12411
12385
  return;