data-structure-typed 1.48.2 → 1.48.4

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 (90) hide show
  1. package/CHANGELOG.md +1 -1
  2. package/README.md +22 -22
  3. package/benchmark/report.html +16 -16
  4. package/benchmark/report.json +184 -184
  5. package/dist/cjs/data-structures/binary-tree/avl-tree.d.ts +16 -16
  6. package/dist/cjs/data-structures/binary-tree/avl-tree.js +7 -7
  7. package/dist/cjs/data-structures/binary-tree/avl-tree.js.map +1 -1
  8. package/dist/cjs/data-structures/binary-tree/binary-tree.d.ts +89 -87
  9. package/dist/cjs/data-structures/binary-tree/binary-tree.js +67 -58
  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 +28 -47
  12. package/dist/cjs/data-structures/binary-tree/bst.js +54 -57
  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 +15 -15
  15. package/dist/cjs/data-structures/binary-tree/rb-tree.js +7 -7
  16. package/dist/cjs/data-structures/binary-tree/rb-tree.js.map +1 -1
  17. package/dist/cjs/data-structures/binary-tree/tree-multimap.d.ts +22 -22
  18. package/dist/cjs/data-structures/binary-tree/tree-multimap.js +11 -11
  19. package/dist/cjs/data-structures/binary-tree/tree-multimap.js.map +1 -1
  20. package/dist/cjs/data-structures/graph/abstract-graph.d.ts +1 -0
  21. package/dist/cjs/data-structures/graph/abstract-graph.js +4 -0
  22. package/dist/cjs/data-structures/graph/abstract-graph.js.map +1 -1
  23. package/dist/cjs/data-structures/graph/directed-graph.d.ts +25 -7
  24. package/dist/cjs/data-structures/graph/directed-graph.js +58 -12
  25. package/dist/cjs/data-structures/graph/directed-graph.js.map +1 -1
  26. package/dist/cjs/data-structures/graph/undirected-graph.d.ts +25 -6
  27. package/dist/cjs/data-structures/graph/undirected-graph.js +70 -7
  28. package/dist/cjs/data-structures/graph/undirected-graph.js.map +1 -1
  29. package/dist/cjs/interfaces/binary-tree.d.ts +6 -6
  30. package/dist/cjs/types/common.d.ts +11 -8
  31. package/dist/cjs/types/common.js +6 -1
  32. package/dist/cjs/types/common.js.map +1 -1
  33. package/dist/cjs/types/data-structures/binary-tree/avl-tree.d.ts +3 -3
  34. package/dist/cjs/types/data-structures/binary-tree/binary-tree.d.ts +4 -4
  35. package/dist/cjs/types/data-structures/binary-tree/bst.d.ts +6 -6
  36. package/dist/cjs/types/data-structures/binary-tree/rb-tree.d.ts +3 -3
  37. package/dist/cjs/types/data-structures/binary-tree/tree-multimap.d.ts +3 -3
  38. package/dist/mjs/data-structures/binary-tree/avl-tree.d.ts +16 -16
  39. package/dist/mjs/data-structures/binary-tree/avl-tree.js +7 -7
  40. package/dist/mjs/data-structures/binary-tree/binary-tree.d.ts +89 -87
  41. package/dist/mjs/data-structures/binary-tree/binary-tree.js +67 -58
  42. package/dist/mjs/data-structures/binary-tree/bst.d.ts +28 -47
  43. package/dist/mjs/data-structures/binary-tree/bst.js +55 -57
  44. package/dist/mjs/data-structures/binary-tree/rb-tree.d.ts +15 -15
  45. package/dist/mjs/data-structures/binary-tree/rb-tree.js +7 -7
  46. package/dist/mjs/data-structures/binary-tree/tree-multimap.d.ts +22 -22
  47. package/dist/mjs/data-structures/binary-tree/tree-multimap.js +11 -11
  48. package/dist/mjs/data-structures/graph/abstract-graph.d.ts +1 -0
  49. package/dist/mjs/data-structures/graph/abstract-graph.js +4 -0
  50. package/dist/mjs/data-structures/graph/directed-graph.d.ts +25 -7
  51. package/dist/mjs/data-structures/graph/directed-graph.js +58 -12
  52. package/dist/mjs/data-structures/graph/undirected-graph.d.ts +25 -6
  53. package/dist/mjs/data-structures/graph/undirected-graph.js +70 -7
  54. package/dist/mjs/interfaces/binary-tree.d.ts +6 -6
  55. package/dist/mjs/types/common.d.ts +11 -8
  56. package/dist/mjs/types/common.js +5 -0
  57. package/dist/mjs/types/data-structures/binary-tree/avl-tree.d.ts +3 -3
  58. package/dist/mjs/types/data-structures/binary-tree/binary-tree.d.ts +4 -4
  59. package/dist/mjs/types/data-structures/binary-tree/bst.d.ts +6 -6
  60. package/dist/mjs/types/data-structures/binary-tree/rb-tree.d.ts +3 -3
  61. package/dist/mjs/types/data-structures/binary-tree/tree-multimap.d.ts +3 -3
  62. package/dist/umd/data-structure-typed.js +276 -158
  63. package/dist/umd/data-structure-typed.min.js +2 -2
  64. package/dist/umd/data-structure-typed.min.js.map +1 -1
  65. package/package.json +2 -2
  66. package/src/data-structures/binary-tree/avl-tree.ts +20 -21
  67. package/src/data-structures/binary-tree/binary-tree.ts +147 -136
  68. package/src/data-structures/binary-tree/bst.ts +86 -82
  69. package/src/data-structures/binary-tree/rb-tree.ts +25 -26
  70. package/src/data-structures/binary-tree/tree-multimap.ts +30 -35
  71. package/src/data-structures/graph/abstract-graph.ts +5 -0
  72. package/src/data-structures/graph/directed-graph.ts +61 -12
  73. package/src/data-structures/graph/undirected-graph.ts +75 -7
  74. package/src/interfaces/binary-tree.ts +5 -6
  75. package/src/types/common.ts +11 -8
  76. package/src/types/data-structures/binary-tree/avl-tree.ts +3 -3
  77. package/src/types/data-structures/binary-tree/binary-tree.ts +6 -5
  78. package/src/types/data-structures/binary-tree/bst.ts +6 -6
  79. package/src/types/data-structures/binary-tree/rb-tree.ts +3 -3
  80. package/src/types/data-structures/binary-tree/tree-multimap.ts +3 -3
  81. package/test/integration/bst.test.ts +1 -1
  82. package/test/unit/data-structures/binary-tree/avl-tree.test.ts +3 -3
  83. package/test/unit/data-structures/binary-tree/binary-tree.test.ts +6 -6
  84. package/test/unit/data-structures/binary-tree/bst.test.ts +10 -9
  85. package/test/unit/data-structures/binary-tree/overall.test.ts +1 -1
  86. package/test/unit/data-structures/binary-tree/rb-tree.test.ts +1 -1
  87. package/test/unit/data-structures/binary-tree/tree-multimap.test.ts +5 -5
  88. package/test/unit/data-structures/graph/directed-graph.test.ts +37 -0
  89. package/test/unit/data-structures/graph/undirected-graph.test.ts +37 -0
  90. package/test/unit/unrestricted-interconversion.test.ts +1 -1
@@ -108,6 +108,7 @@ var dataStructureTyped = (() => {
108
108
  AbstractVertex: () => AbstractVertex,
109
109
  BST: () => BST,
110
110
  BSTNode: () => BSTNode,
111
+ BSTVariant: () => BSTVariant,
111
112
  BinaryIndexedTree: () => BinaryIndexedTree,
112
113
  BinaryTree: () => BinaryTree,
113
114
  BinaryTreeNode: () => BinaryTreeNode,
@@ -5472,6 +5473,10 @@ var dataStructureTyped = (() => {
5472
5473
  return this._addVertexOnly(newVertex);
5473
5474
  }
5474
5475
  }
5476
+ isVertexKey(potentialKey) {
5477
+ const potentialKeyType = typeof potentialKey;
5478
+ return potentialKeyType === "string" || potentialKeyType === "number";
5479
+ }
5475
5480
  /**
5476
5481
  * Time Complexity: O(1) - Constant time for Map operations.
5477
5482
  * Space Complexity: O(1) - Constant space, as it creates only a few variables.
@@ -6597,34 +6602,77 @@ var dataStructureTyped = (() => {
6597
6602
  return removed;
6598
6603
  }
6599
6604
  /**
6600
- * Time Complexity: O(|E|) where |E| is the number of edges
6605
+ * Time Complexity: O(E) where E is the number of edges
6601
6606
  * Space Complexity: O(1)
6602
6607
  */
6603
6608
  /**
6604
- * Time Complexity: O(|E|) where |E| is the number of edges
6609
+ * Time Complexity: O(E) where E is the number of edges
6605
6610
  * Space Complexity: O(1)
6606
6611
  *
6607
- * The function removes an edge from a graph and returns the removed edge, or undefined if the edge was not found.
6608
- * @param {EO} edge - The `edge` parameter is an object that represents an edge in a graph. It has two properties: `src`
6609
- * and `dest`, which represent the source and destination vertices of the edge, respectively.
6610
- * @returns The method `deleteEdge` returns the removed edge (`EO`) if it exists, or `undefined` if the edge does not exist.
6612
+ * The `deleteEdge` function removes an edge from a graph and returns the removed edge.
6613
+ * @param {EO | VertexKey} edgeOrSrcVertexKey - The `edge` parameter can be either an `EO` object (edge object) or
6614
+ * a `VertexKey` (key of a vertex).
6615
+ * @param {VertexKey} [destVertexKey] - The `destVertexKey` parameter is an optional parameter that
6616
+ * represents the key of the destination vertex of the edge. It is used to specify the destination
6617
+ * vertex when the `edge` parameter is a vertex key. If `destVertexKey` is not provided, the function
6618
+ * assumes that the `edge`
6619
+ * @returns the removed edge (EO) or undefined if no edge was removed.
6611
6620
  */
6612
- deleteEdge(edge) {
6621
+ deleteEdge(edgeOrSrcVertexKey, destVertexKey) {
6613
6622
  let removed = void 0;
6614
- const src = this._getVertex(edge.src);
6615
- const dest = this._getVertex(edge.dest);
6623
+ let src, dest;
6624
+ if (this.isVertexKey(edgeOrSrcVertexKey)) {
6625
+ if (this.isVertexKey(destVertexKey)) {
6626
+ src = this._getVertex(edgeOrSrcVertexKey);
6627
+ dest = this._getVertex(destVertexKey);
6628
+ } else {
6629
+ return;
6630
+ }
6631
+ } else {
6632
+ src = this._getVertex(edgeOrSrcVertexKey.src);
6633
+ dest = this._getVertex(edgeOrSrcVertexKey.dest);
6634
+ }
6616
6635
  if (src && dest) {
6617
6636
  const srcOutEdges = this._outEdgeMap.get(src);
6618
6637
  if (srcOutEdges && srcOutEdges.length > 0) {
6619
- arrayRemove(srcOutEdges, (edge2) => edge2.src === src.key);
6638
+ arrayRemove(srcOutEdges, (edge) => edge.src === src.key && edge.dest === (dest == null ? void 0 : dest.key));
6620
6639
  }
6621
6640
  const destInEdges = this._inEdgeMap.get(dest);
6622
6641
  if (destInEdges && destInEdges.length > 0) {
6623
- removed = arrayRemove(destInEdges, (edge2) => edge2.dest === dest.key)[0];
6642
+ removed = arrayRemove(destInEdges, (edge) => edge.src === src.key && edge.dest === dest.key)[0];
6624
6643
  }
6625
6644
  }
6626
6645
  return removed;
6627
6646
  }
6647
+ /**
6648
+ * Time Complexity: O(1) - Constant time for Map operations.
6649
+ * Space Complexity: O(1) - Constant space, as it creates only a few variables.
6650
+ */
6651
+ /**
6652
+ * Time Complexity: O(1) - Constant time for Map operations.
6653
+ * Space Complexity: O(1) - Constant space, as it creates only a few variables.
6654
+ *
6655
+ * The `deleteVertex` function removes a vertex from a graph by its ID or by the vertex object itself.
6656
+ * @param {VO | VertexKey} vertexOrKey - The parameter `vertexOrKey` can be either a vertex object (`VO`) or a vertex ID
6657
+ * (`VertexKey`).
6658
+ * @returns The method is returning a boolean value.
6659
+ */
6660
+ deleteVertex(vertexOrKey) {
6661
+ let vertexKey;
6662
+ let vertex;
6663
+ if (this.isVertexKey(vertexOrKey)) {
6664
+ vertex = this.getVertex(vertexOrKey);
6665
+ vertexKey = vertexOrKey;
6666
+ } else {
6667
+ vertex = vertexOrKey;
6668
+ vertexKey = this._getVertexKey(vertexOrKey);
6669
+ }
6670
+ if (vertex) {
6671
+ this._outEdgeMap.delete(vertex);
6672
+ this._inEdgeMap.delete(vertex);
6673
+ }
6674
+ return this._vertices.delete(vertexKey);
6675
+ }
6628
6676
  /**
6629
6677
  * Time Complexity: O(|E|) where |E| is the number of edges
6630
6678
  * Space Complexity: O(1)
@@ -7092,19 +7140,78 @@ var dataStructureTyped = (() => {
7092
7140
  return removed;
7093
7141
  }
7094
7142
  /**
7095
- * Time Complexity: O(|E|), where |E| is the number of edges incident to the given vertex.
7143
+ * Time Complexity: O(E), where E is the number of edges incident to the given vertex.
7096
7144
  * Space Complexity: O(1)
7097
7145
  */
7098
7146
  /**
7099
- * Time Complexity: O(|E|), where |E| is the number of edges incident to the given vertex.
7147
+ * Time Complexity: O(E), where E is the number of edges incident to the given vertex.
7100
7148
  * Space Complexity: O(1)
7101
7149
  *
7102
- * The deleteEdge function removes an edge between two vertices in a graph.
7103
- * @param {EO} edge - The parameter "edge" is of type EO, which represents an edge in a graph.
7104
- * @returns The method is returning either the removed edge (of type EO) or undefined if the edge was not found.
7150
+ * The function `deleteEdge` deletes an edge between two vertices in a graph.
7151
+ * @param {EO | VertexKey} edgeOrOneSideVertexKey - The parameter `edgeOrOneSideVertexKey` can be
7152
+ * either an edge object or a vertex key.
7153
+ * @param {VertexKey} [otherSideVertexKey] - The parameter `otherSideVertexKey` is an optional
7154
+ * parameter that represents the key of the vertex on the other side of the edge. It is used when the
7155
+ * `edgeOrOneSideVertexKey` parameter is a vertex key, and it specifies the key of the vertex on the
7156
+ * other side of the
7157
+ * @returns The `deleteEdge` function returns either the deleted edge object (EO) or `undefined`.
7105
7158
  */
7106
- deleteEdge(edge) {
7107
- return this.deleteEdgeBetween(edge.vertices[0], edge.vertices[1]);
7159
+ deleteEdge(edgeOrOneSideVertexKey, otherSideVertexKey) {
7160
+ let oneSide, otherSide;
7161
+ if (this.isVertexKey(edgeOrOneSideVertexKey)) {
7162
+ if (this.isVertexKey(otherSideVertexKey)) {
7163
+ oneSide = this._getVertex(edgeOrOneSideVertexKey);
7164
+ otherSide = this._getVertex(otherSideVertexKey);
7165
+ } else {
7166
+ return;
7167
+ }
7168
+ } else {
7169
+ oneSide = this._getVertex(edgeOrOneSideVertexKey.vertices[0]);
7170
+ otherSide = this._getVertex(edgeOrOneSideVertexKey.vertices[1]);
7171
+ }
7172
+ if (oneSide && otherSide) {
7173
+ return this.deleteEdgeBetween(oneSide, otherSide);
7174
+ } else {
7175
+ return;
7176
+ }
7177
+ }
7178
+ /**
7179
+ * Time Complexity: O(1) - Constant time for Map operations.
7180
+ * Space Complexity: O(1) - Constant space, as it creates only a few variables.
7181
+ */
7182
+ /**
7183
+ * Time Complexity: O(1) - Constant time for Map operations.
7184
+ * Space Complexity: O(1) - Constant space, as it creates only a few variables.
7185
+ *
7186
+ * The `deleteVertex` function removes a vertex from a graph by its ID or by the vertex object itself.
7187
+ * @param {VO | VertexKey} vertexOrKey - The parameter `vertexOrKey` can be either a vertex object (`VO`) or a vertex ID
7188
+ * (`VertexKey`).
7189
+ * @returns The method is returning a boolean value.
7190
+ */
7191
+ deleteVertex(vertexOrKey) {
7192
+ let vertexKey;
7193
+ let vertex;
7194
+ if (this.isVertexKey(vertexOrKey)) {
7195
+ vertex = this.getVertex(vertexOrKey);
7196
+ vertexKey = vertexOrKey;
7197
+ } else {
7198
+ vertex = vertexOrKey;
7199
+ vertexKey = this._getVertexKey(vertexOrKey);
7200
+ }
7201
+ const neighbors = this.getNeighbors(vertexOrKey);
7202
+ if (vertex) {
7203
+ neighbors.forEach((neighbor) => {
7204
+ const neighborEdges = this._edges.get(neighbor);
7205
+ if (neighborEdges) {
7206
+ const restEdges = neighborEdges.filter((edge) => {
7207
+ return !edge.vertices.includes(vertexKey);
7208
+ });
7209
+ this._edges.set(neighbor, restEdges);
7210
+ }
7211
+ });
7212
+ this._edges.delete(vertex);
7213
+ }
7214
+ return this._vertices.delete(vertexKey);
7108
7215
  }
7109
7216
  /**
7110
7217
  * Time Complexity: O(1)
@@ -7369,6 +7476,11 @@ var dataStructureTyped = (() => {
7369
7476
  })(RBTNColor || {});
7370
7477
 
7371
7478
  // src/types/common.ts
7479
+ var BSTVariant = /* @__PURE__ */ ((BSTVariant2) => {
7480
+ BSTVariant2["MIN"] = "MIN";
7481
+ BSTVariant2["MAX"] = "MAX";
7482
+ return BSTVariant2;
7483
+ })(BSTVariant || {});
7372
7484
  var CP = /* @__PURE__ */ ((CP2) => {
7373
7485
  CP2["lt"] = "lt";
7374
7486
  CP2["eq"] = "eq";
@@ -7435,19 +7547,26 @@ var dataStructureTyped = (() => {
7435
7547
  constructor(elements, options) {
7436
7548
  super();
7437
7549
  __publicField(this, "iterationType", "ITERATIVE" /* ITERATIVE */);
7550
+ __publicField(this, "_extractor", (key) => Number(key));
7438
7551
  __publicField(this, "_root");
7439
7552
  __publicField(this, "_size");
7440
7553
  __publicField(this, "_defaultOneParamCallback", (node) => node.key);
7441
7554
  if (options) {
7442
- const { iterationType } = options;
7555
+ const { iterationType, extractor } = options;
7443
7556
  if (iterationType) {
7444
7557
  this.iterationType = iterationType;
7445
7558
  }
7559
+ if (extractor) {
7560
+ this._extractor = extractor;
7561
+ }
7446
7562
  }
7447
7563
  this._size = 0;
7448
7564
  if (elements)
7449
7565
  this.addMany(elements);
7450
7566
  }
7567
+ get extractor() {
7568
+ return this._extractor;
7569
+ }
7451
7570
  get root() {
7452
7571
  return this._root;
7453
7572
  }
@@ -7456,7 +7575,7 @@ var dataStructureTyped = (() => {
7456
7575
  }
7457
7576
  /**
7458
7577
  * Creates a new instance of BinaryTreeNode with the given key and value.
7459
- * @param {BTNKey} key - The key for the new node.
7578
+ * @param {K} key - The key for the new node.
7460
7579
  * @param {V} value - The value for the new node.
7461
7580
  * @returns {N} - The newly created BinaryTreeNode.
7462
7581
  */
@@ -7475,7 +7594,7 @@ var dataStructureTyped = (() => {
7475
7594
  }
7476
7595
  /**
7477
7596
  * The function "isNode" checks if an exemplar is an instance of the BinaryTreeNode class.
7478
- * @param exemplar - The `exemplar` parameter is a variable of type `BTNodeExemplar<V, N>`.
7597
+ * @param exemplar - The `exemplar` parameter is a variable of type `BTNodeExemplar<K, V,N>`.
7479
7598
  * @returns a boolean value indicating whether the exemplar is an instance of the class N.
7480
7599
  */
7481
7600
  isNode(exemplar) {
@@ -7484,7 +7603,7 @@ var dataStructureTyped = (() => {
7484
7603
  /**
7485
7604
  * The function `exemplarToNode` converts an exemplar of a binary tree node into an actual node
7486
7605
  * object.
7487
- * @param exemplar - BTNodeExemplar<V, N> - A generic type representing the exemplar parameter of the
7606
+ * @param exemplar - BTNodeExemplar<K, V,N> - A generic type representing the exemplar parameter of the
7488
7607
  * function. It can be any type.
7489
7608
  * @returns a value of type `N` (which represents a node), or `null`, or `undefined`.
7490
7609
  */
@@ -7505,7 +7624,7 @@ var dataStructureTyped = (() => {
7505
7624
  }
7506
7625
  } else if (this.isNode(exemplar)) {
7507
7626
  node = exemplar;
7508
- } else if (this.isNodeKey(exemplar)) {
7627
+ } else if (this.isNotNodeInstance(exemplar)) {
7509
7628
  node = this.createNode(exemplar);
7510
7629
  } else {
7511
7630
  return;
@@ -7514,7 +7633,7 @@ var dataStructureTyped = (() => {
7514
7633
  }
7515
7634
  /**
7516
7635
  * The function checks if a given value is an entry in a binary tree node.
7517
- * @param kne - BTNodeExemplar<V, N> - A generic type representing a node in a binary tree. It has
7636
+ * @param kne - BTNodeExemplar<K, V,N> - A generic type representing a node in a binary tree. It has
7518
7637
  * two type parameters V and N, representing the value and node type respectively.
7519
7638
  * @returns a boolean value.
7520
7639
  */
@@ -7580,7 +7699,7 @@ var dataStructureTyped = (() => {
7580
7699
  * The function `addMany` takes in an iterable of `BTNodeExemplar` objects, adds each object to the
7581
7700
  * current instance, and returns an array of the inserted nodes.
7582
7701
  * @param nodes - The `nodes` parameter is an iterable (such as an array or a set) of
7583
- * `BTNodeExemplar<V, N>` objects.
7702
+ * `BTNodeExemplar<K, V,N>` objects.
7584
7703
  * @returns The function `addMany` returns an array of values, where each value is either of type
7585
7704
  * `N`, `null`, or `undefined`.
7586
7705
  */
@@ -7675,11 +7794,11 @@ var dataStructureTyped = (() => {
7675
7794
  * Space Complexity: O(1)
7676
7795
  *
7677
7796
  * The function calculates the depth of a given node in a binary tree.
7678
- * @param {BTNKey | N | null | undefined} distNode - The `distNode` parameter represents the node in
7679
- * the binary tree whose depth we want to find. It can be of type `BTNKey`, `N`, `null`, or
7797
+ * @param {K | N | null | undefined} distNode - The `distNode` parameter represents the node in
7798
+ * the binary tree whose depth we want to find. It can be of type `K`, `N`, `null`, or
7680
7799
  * `undefined`.
7681
- * @param {BTNKey | N | null | undefined} beginRoot - The `beginRoot` parameter is the starting node
7682
- * from which we want to calculate the depth. It can be either a `BTNKey` (binary tree node key) or
7800
+ * @param {K | N | null | undefined} beginRoot - The `beginRoot` parameter is the starting node
7801
+ * from which we want to calculate the depth. It can be either a `K` (binary tree node key) or
7683
7802
  * `N` (binary tree node) or `null` or `undefined`. If no value is provided for `beginRoot
7684
7803
  * @returns the depth of the `distNode` relative to the `beginRoot`.
7685
7804
  */
@@ -7706,9 +7825,9 @@ var dataStructureTyped = (() => {
7706
7825
  *
7707
7826
  * The function `getHeight` calculates the maximum height of a binary tree using either recursive or
7708
7827
  * iterative traversal.
7709
- * @param {BTNKey | N | null | undefined} beginRoot - The `beginRoot` parameter represents the
7828
+ * @param {K | N | null | undefined} beginRoot - The `beginRoot` parameter represents the
7710
7829
  * starting node of the binary tree from which we want to calculate the height. It can be of type
7711
- * `BTNKey`, `N`, `null`, or `undefined`. If not provided, it defaults to `this.root`.
7830
+ * `K`, `N`, `null`, or `undefined`. If not provided, it defaults to `this.root`.
7712
7831
  * @param iterationType - The `iterationType` parameter is used to determine whether to calculate the
7713
7832
  * height of the tree using a recursive approach or an iterative approach. It can have two possible
7714
7833
  * values:
@@ -7752,9 +7871,9 @@ var dataStructureTyped = (() => {
7752
7871
  *
7753
7872
  * The `getMinHeight` function calculates the minimum height of a binary tree using either a
7754
7873
  * recursive or iterative approach.
7755
- * @param {BTNKey | N | null | undefined} beginRoot - The `beginRoot` parameter represents the
7874
+ * @param {K | N | null | undefined} beginRoot - The `beginRoot` parameter represents the
7756
7875
  * starting node of the binary tree from which we want to calculate the minimum height. It can be of
7757
- * type `BTNKey`, `N`, `null`, or `undefined`. If no value is provided, it defaults to `this.root`.
7876
+ * type `K`, `N`, `null`, or `undefined`. If no value is provided, it defaults to `this.root`.
7758
7877
  * @param iterationType - The `iterationType` parameter is used to determine the method of iteration
7759
7878
  * to calculate the minimum height of a binary tree. It can have two possible values:
7760
7879
  * @returns The function `getMinHeight` returns the minimum height of a binary tree.
@@ -7812,8 +7931,8 @@ var dataStructureTyped = (() => {
7812
7931
  *
7813
7932
  * The function checks if a binary tree is perfectly balanced by comparing the minimum height and the
7814
7933
  * height of the tree.
7815
- * @param {BTNKey | N | null | undefined} beginRoot - The `beginRoot` parameter is the starting point
7816
- * for calculating the height and minimum height of a binary tree. It can be either a `BTNKey` (a key
7934
+ * @param {K | N | null | undefined} beginRoot - The `beginRoot` parameter is the starting point
7935
+ * for calculating the height and minimum height of a binary tree. It can be either a `K` (a key
7817
7936
  * value of a binary tree node), `N` (a node of a binary tree), `null`, or `undefined`. If
7818
7937
  * @returns a boolean value.
7819
7938
  */
@@ -7838,7 +7957,7 @@ var dataStructureTyped = (() => {
7838
7957
  * matches the identifier. If set to true, the function will stop iterating once it finds a matching
7839
7958
  * node and return that node. If set to false (default), the function will continue iterating and
7840
7959
  * return all nodes that match the identifier.
7841
- * @param {BTNKey | N | null | undefined} beginRoot - The `beginRoot` parameter represents the
7960
+ * @param {K | N | null | undefined} beginRoot - The `beginRoot` parameter represents the
7842
7961
  * starting node for the traversal. It can be either a key, a node object, or `null`/`undefined`. If
7843
7962
  * it is `null` or `undefined`, an empty array will be returned.
7844
7963
  * @param iterationType - The `iterationType` parameter determines the type of iteration used to
@@ -7894,8 +8013,8 @@ var dataStructureTyped = (() => {
7894
8013
  * the binary tree. It is used to filter the nodes based on certain conditions. The `callback`
7895
8014
  * function should return a boolean value indicating whether the node should be included in the
7896
8015
  * result or not.
7897
- * @param {BTNKey | N | null | undefined} beginRoot - The `beginRoot` parameter is the starting point
7898
- * for the search in the binary tree. It can be specified as a `BTNKey` (a unique identifier for a
8016
+ * @param {K | N | null | undefined} beginRoot - The `beginRoot` parameter is the starting point
8017
+ * for the search in the binary tree. It can be specified as a `K` (a unique identifier for a
7899
8018
  * node in the binary tree), a node object (`N`), or `null`/`undefined` to start the search from
7900
8019
  * @param iterationType - The `iterationType` parameter is a variable that determines the type of
7901
8020
  * iteration to be performed on the binary tree. It is used to specify whether the iteration should
@@ -7920,7 +8039,7 @@ var dataStructureTyped = (() => {
7920
8039
  * @param {C} callback - The `callback` parameter is a function that will be called for each node in
7921
8040
  * the binary tree. It is used to determine if a node matches the given identifier. The `callback`
7922
8041
  * function should take a single parameter of type `N` (the type of the nodes in the binary tree) and
7923
- * @param {BTNKey | N | null | undefined} beginRoot - The `beginRoot` parameter is the starting point
8042
+ * @param {K | N | null | undefined} beginRoot - The `beginRoot` parameter is the starting point
7924
8043
  * for searching the binary tree. It can be either a key value, a node object, or `null`/`undefined`.
7925
8044
  * If `null` or `undefined` is passed, the search will start from the root of the binary tree.
7926
8045
  * @param iterationType - The `iterationType` parameter is used to specify the type of iteration to
@@ -7944,7 +8063,7 @@ var dataStructureTyped = (() => {
7944
8063
  *
7945
8064
  * The function `getNodeByKey` searches for a node in a binary tree by its key, using either
7946
8065
  * recursive or iterative iteration.
7947
- * @param {BTNKey} key - The `key` parameter is the key value that we are searching for in the tree.
8066
+ * @param {K} key - The `key` parameter is the key value that we are searching for in the tree.
7948
8067
  * It is used to find the node with the matching key value.
7949
8068
  * @param iterationType - The `iterationType` parameter is used to determine whether the search for
7950
8069
  * the node with the given key should be performed iteratively or recursively. It has two possible
@@ -7987,7 +8106,7 @@ var dataStructureTyped = (() => {
7987
8106
  /**
7988
8107
  * The function `ensureNode` returns the node corresponding to the given key if it is a valid node
7989
8108
  * key, otherwise it returns the key itself.
7990
- * @param {BTNKey | N | null | undefined} key - The `key` parameter can be of type `BTNKey`, `N`,
8109
+ * @param {K | N | null | undefined} key - The `key` parameter can be of type `K`, `N`,
7991
8110
  * `null`, or `undefined`. It represents a key used to identify a node in a binary tree.
7992
8111
  * @param iterationType - The `iterationType` parameter is an optional parameter that specifies the
7993
8112
  * type of iteration to be used when searching for a node by key. It has a default value of
@@ -7996,7 +8115,7 @@ var dataStructureTyped = (() => {
7996
8115
  * itself if it is not a valid node key.
7997
8116
  */
7998
8117
  ensureNode(key, iterationType = "ITERATIVE" /* ITERATIVE */) {
7999
- return this.isNodeKey(key) ? this.getNodeByKey(key, iterationType) : key;
8118
+ return this.isNotNodeInstance(key) ? this.getNodeByKey(key, iterationType) : key;
8000
8119
  }
8001
8120
  /**
8002
8121
  * Time Complexity: O(n)
@@ -8011,8 +8130,8 @@ var dataStructureTyped = (() => {
8011
8130
  * the binary tree. It is used to determine whether a node matches the given identifier. The callback
8012
8131
  * function should return a value that can be compared to the identifier to determine if it is a
8013
8132
  * match.
8014
- * @param {BTNKey | N | null | undefined} beginRoot - The `beginRoot` parameter is the starting point
8015
- * for the search in the binary tree. It can be specified as a `BTNKey` (a unique identifier for a
8133
+ * @param {K | N | null | undefined} beginRoot - The `beginRoot` parameter is the starting point
8134
+ * for the search in the binary tree. It can be specified as a `K` (a unique identifier for a
8016
8135
  * node), a node object of type `N`, or `null`/`undefined` to start the search from the root of
8017
8136
  * @param iterationType - The `iterationType` parameter is used to specify the type of iteration to
8018
8137
  * be performed when searching for a node in the binary tree. It is an optional parameter with a
@@ -8050,8 +8169,8 @@ var dataStructureTyped = (() => {
8050
8169
  *
8051
8170
  * The function `getPathToRoot` returns an array of nodes from a given node to the root of a tree
8052
8171
  * structure, with the option to reverse the order of the nodes.
8053
- * @param {BTNKey | N | null | undefined} beginRoot - The `beginRoot` parameter represents the
8054
- * starting node from which you want to find the path to the root. It can be of type `BTNKey`, `N`,
8172
+ * @param {K | N | null | undefined} beginRoot - The `beginRoot` parameter represents the
8173
+ * starting node from which you want to find the path to the root. It can be of type `K`, `N`,
8055
8174
  * `null`, or `undefined`.
8056
8175
  * @param [isReverse=true] - The `isReverse` parameter is a boolean flag that determines whether the
8057
8176
  * resulting path should be reversed or not. If `isReverse` is set to `true`, the path will be
@@ -8080,8 +8199,8 @@ var dataStructureTyped = (() => {
8080
8199
  *
8081
8200
  * The function `getLeftMost` returns the leftmost node in a binary tree, either recursively or
8082
8201
  * iteratively.
8083
- * @param {BTNKey | N | null | undefined} beginRoot - The `beginRoot` parameter is the starting point
8084
- * for finding the leftmost node in a binary tree. It can be either a `BTNKey` (a key value), `N` (a
8202
+ * @param {K | N | null | undefined} beginRoot - The `beginRoot` parameter is the starting point
8203
+ * for finding the leftmost node in a binary tree. It can be either a `K` (a key value), `N` (a
8085
8204
  * node), `null`, or `undefined`. If not provided, it defaults to `this.root`,
8086
8205
  * @param iterationType - The `iterationType` parameter is used to determine the type of iteration to
8087
8206
  * be performed when finding the leftmost node in a binary tree. It can have two possible values:
@@ -8118,8 +8237,8 @@ var dataStructureTyped = (() => {
8118
8237
  *
8119
8238
  * The function `getRightMost` returns the rightmost node in a binary tree, either recursively or
8120
8239
  * iteratively.
8121
- * @param {BTNKey | N | null | undefined} beginRoot - The `beginRoot` parameter represents the
8122
- * starting node from which we want to find the rightmost node. It can be of type `BTNKey`, `N`,
8240
+ * @param {K | N | null | undefined} beginRoot - The `beginRoot` parameter represents the
8241
+ * starting node from which we want to find the rightmost node. It can be of type `K`, `N`,
8123
8242
  * `null`, or `undefined`. If not provided, it defaults to `this.root`, which is a property of the
8124
8243
  * current object.
8125
8244
  * @param iterationType - The `iterationType` parameter is an optional parameter that specifies the
@@ -8156,7 +8275,7 @@ var dataStructureTyped = (() => {
8156
8275
  * Space Complexity: O(1)
8157
8276
  *
8158
8277
  * The function `isSubtreeBST` checks if a given binary tree is a valid binary search tree.
8159
- * @param {BTNKey | N | null | undefined} beginRoot - The `beginRoot` parameter represents the root
8278
+ * @param {K | N | null | undefined} beginRoot - The `beginRoot` parameter represents the root
8160
8279
  * node of the binary search tree (BST) that you want to check if it is a subtree of another BST.
8161
8280
  * @param iterationType - The `iterationType` parameter is an optional parameter that specifies the
8162
8281
  * type of iteration to use when checking if a subtree is a binary search tree (BST). It can have two
@@ -8171,9 +8290,10 @@ var dataStructureTyped = (() => {
8171
8290
  const dfs = (cur, min, max) => {
8172
8291
  if (!cur)
8173
8292
  return true;
8174
- if (cur.key <= min || cur.key >= max)
8293
+ const numKey = this.extractor(cur.key);
8294
+ if (numKey <= min || numKey >= max)
8175
8295
  return false;
8176
- return dfs(cur.left, min, cur.key) && dfs(cur.right, cur.key, max);
8296
+ return dfs(cur.left, min, numKey) && dfs(cur.right, numKey, max);
8177
8297
  };
8178
8298
  return dfs(beginRoot, Number.MIN_SAFE_INTEGER, Number.MAX_SAFE_INTEGER);
8179
8299
  } else {
@@ -8185,9 +8305,10 @@ var dataStructureTyped = (() => {
8185
8305
  curr = curr.left;
8186
8306
  }
8187
8307
  curr = stack.pop();
8188
- if (!curr || prev >= curr.key)
8308
+ const numKey = this.extractor(curr.key);
8309
+ if (!curr || prev >= numKey)
8189
8310
  return false;
8190
- prev = curr.key;
8311
+ prev = numKey;
8191
8312
  curr = curr.right;
8192
8313
  }
8193
8314
  return true;
@@ -8222,8 +8343,8 @@ var dataStructureTyped = (() => {
8222
8343
  * @param {C} callback - The `callback` parameter is a function that will be called for each node in
8223
8344
  * the subtree traversal. It takes a single parameter, which is the current node being traversed, and
8224
8345
  * returns a value of any type.
8225
- * @param {BTNKey | N | null | undefined} beginRoot - The `beginRoot` parameter represents the
8226
- * starting node or key from which the subtree traversal should begin. It can be of type `BTNKey`,
8346
+ * @param {K | N | null | undefined} beginRoot - The `beginRoot` parameter represents the
8347
+ * starting node or key from which the subtree traversal should begin. It can be of type `K`,
8227
8348
  * `N`, `null`, or `undefined`. If not provided, the `root` property of the current object is used as
8228
8349
  * the default value.
8229
8350
  * @param iterationType - The `iterationType` parameter determines the type of traversal to be
@@ -8302,13 +8423,13 @@ var dataStructureTyped = (() => {
8302
8423
  return this.isRealNode(node) || node === null;
8303
8424
  }
8304
8425
  /**
8305
- * The function "isNodeKey" checks if a potential key is a number.
8426
+ * The function "isNotNodeInstance" checks if a potential key is a number.
8306
8427
  * @param {any} potentialKey - The potentialKey parameter is of type any, which means it can be any
8307
8428
  * data type.
8308
8429
  * @returns a boolean value indicating whether the potentialKey is of type number or not.
8309
8430
  */
8310
- isNodeKey(potentialKey) {
8311
- return typeof potentialKey === "number";
8431
+ isNotNodeInstance(potentialKey) {
8432
+ return !(potentialKey instanceof BinaryTreeNode);
8312
8433
  }
8313
8434
  /**
8314
8435
  * Time complexity: O(n)
@@ -8322,7 +8443,7 @@ var dataStructureTyped = (() => {
8322
8443
  * `null`, or `undefined`, and returns a value of any type. The default value for this parameter is
8323
8444
  * @param {DFSOrderPattern} [pattern=in] - The `pattern` parameter determines the order in which the
8324
8445
  * nodes are traversed during the depth-first search. It can have one of the following values:
8325
- * @param {BTNKey | N | null | undefined} beginRoot - The `beginRoot` parameter is the starting node
8446
+ * @param {K | N | null | undefined} beginRoot - The `beginRoot` parameter is the starting node
8326
8447
  * for the depth-first search traversal. It can be specified as a key, a node object, or
8327
8448
  * `null`/`undefined`. If not provided, the `beginRoot` will default to the root node of the tree.
8328
8449
  * @param {IterationType} iterationType - The `iterationType` parameter determines the type of
@@ -8441,7 +8562,7 @@ var dataStructureTyped = (() => {
8441
8562
  * @param {C} callback - The `callback` parameter is a function that will be called for each node in
8442
8563
  * the breadth-first search traversal. It takes a single parameter, which is the current node being
8443
8564
  * visited, and returns a value of any type.
8444
- * @param {BTNKey | N | null | undefined} beginRoot - The `beginRoot` parameter represents the
8565
+ * @param {K | N | null | undefined} beginRoot - The `beginRoot` parameter represents the
8445
8566
  * starting node for the breadth-first search traversal. It can be specified as a key, a node object,
8446
8567
  * or `null`/`undefined` to indicate the root of the tree. If not provided, the `root` property of
8447
8568
  * the class is used as
@@ -8512,9 +8633,9 @@ var dataStructureTyped = (() => {
8512
8633
  * @param {C} callback - The `callback` parameter is a function that will be called for each node in
8513
8634
  * the tree. It takes a single parameter, which can be of type `N`, `null`, or `undefined`, and
8514
8635
  * returns a value of any type.
8515
- * @param {BTNKey | N | null | undefined} beginRoot - The `beginRoot` parameter represents the
8636
+ * @param {K | N | null | undefined} beginRoot - The `beginRoot` parameter represents the
8516
8637
  * starting node for traversing the tree. It can be either a node object (`N`), a key value
8517
- * (`BTNKey`), `null`, or `undefined`. If not provided, it defaults to the root node of the tree.
8638
+ * (`K`), `null`, or `undefined`. If not provided, it defaults to the root node of the tree.
8518
8639
  * @param iterationType - The `iterationType` parameter determines the type of iteration to be
8519
8640
  * performed on the tree. It can have two possible values:
8520
8641
  * @param [includeNull=false] - The `includeNull` parameter is a boolean value that determines
@@ -8571,7 +8692,7 @@ var dataStructureTyped = (() => {
8571
8692
  }
8572
8693
  /**
8573
8694
  * The function `getPredecessor` returns the predecessor node of a given node in a binary tree.
8574
- * @param {BTNKey | N | null | undefined} node - The `node` parameter can be of type `BTNKey`, `N`,
8695
+ * @param {K | N | null | undefined} node - The `node` parameter can be of type `K`, `N`,
8575
8696
  * `null`, or `undefined`.
8576
8697
  * @returns The function `getPredecessor` returns a value of type `N | undefined`.
8577
8698
  */
@@ -8593,7 +8714,7 @@ var dataStructureTyped = (() => {
8593
8714
  }
8594
8715
  /**
8595
8716
  * The function `getSuccessor` returns the next node in a binary tree given a current node.
8596
- * @param {BTNKey | N | null} [x] - The parameter `x` can be of type `BTNKey`, `N`, or `null`.
8717
+ * @param {K | N | null} [x] - The parameter `x` can be of type `K`, `N`, or `null`.
8597
8718
  * @returns the successor of the given node or key. The successor is the node that comes immediately
8598
8719
  * after the given node in the inorder traversal of the binary tree.
8599
8720
  */
@@ -8622,7 +8743,7 @@ var dataStructureTyped = (() => {
8622
8743
  * @param {DFSOrderPattern} [pattern=in] - The `pattern` parameter in the `morris` function
8623
8744
  * determines the order in which the nodes of a binary tree are traversed. It can have one of the
8624
8745
  * following values:
8625
- * @param {BTNKey | N | null | undefined} beginRoot - The `beginRoot` parameter is the starting node
8746
+ * @param {K | N | null | undefined} beginRoot - The `beginRoot` parameter is the starting node
8626
8747
  * for the traversal. It can be specified as a key, a node object, or `null`/`undefined` to indicate
8627
8748
  * the root of the tree. If no value is provided, the default value is the root of the tree.
8628
8749
  * @returns The function `morris` returns an array of values that are the result of invoking the
@@ -8784,7 +8905,7 @@ var dataStructureTyped = (() => {
8784
8905
  return newTree;
8785
8906
  }
8786
8907
  // // TODO Type error, need to return a TREE<NV> that is a value type only for callback function.
8787
- // // map<NV>(callback: (entry: [BTNKey, V | undefined], tree: this) => NV) {
8908
+ // // map<NV>(callback: (entry: [K, V | undefined], tree: this) => NV) {
8788
8909
  // // const newTree = this.createTree();
8789
8910
  // // for (const [key, value] of this) {
8790
8911
  // // newTree.add(key, callback([key, value], this));
@@ -8794,7 +8915,7 @@ var dataStructureTyped = (() => {
8794
8915
  //
8795
8916
  /**
8796
8917
  * The `print` function is used to display a binary tree structure in a visually appealing way.
8797
- * @param {BTNKey | N | null | undefined} [beginRoot=this.root] - The `root` parameter is of type `BTNKey | N | null |
8918
+ * @param {K | N | null | undefined} [beginRoot=this.root] - The `root` parameter is of type `K | N | null |
8798
8919
  * undefined`. It represents the root node of a binary tree. The root node can have one of the
8799
8920
  * following types:
8800
8921
  * @param {BinaryTreePrintOptions} [options={ isShowUndefined: false, isShowNull: false, isShowRedBlackNIL: false}] - Options object that controls printing behavior. You can specify whether to display undefined, null, or sentinel nodes.
@@ -8828,22 +8949,22 @@ var dataStructureTyped = (() => {
8828
8949
  const stack = [];
8829
8950
  let current = node;
8830
8951
  while (current || stack.length > 0) {
8831
- while (current && !isNaN(current.key)) {
8952
+ while (current && !isNaN(this.extractor(current.key))) {
8832
8953
  stack.push(current);
8833
8954
  current = current.left;
8834
8955
  }
8835
8956
  current = stack.pop();
8836
- if (current && !isNaN(current.key)) {
8957
+ if (current && !isNaN(this.extractor(current.key))) {
8837
8958
  yield [current.key, current.value];
8838
8959
  current = current.right;
8839
8960
  }
8840
8961
  }
8841
8962
  } else {
8842
- if (node.left && !isNaN(node.key)) {
8963
+ if (node.left && !isNaN(this.extractor(node.key))) {
8843
8964
  yield* __yieldStar(this[Symbol.iterator](node.left));
8844
8965
  }
8845
8966
  yield [node.key, node.value];
8846
- if (node.right && !isNaN(node.key)) {
8967
+ if (node.right && !isNaN(this.extractor(node.key))) {
8847
8968
  yield* __yieldStar(this[Symbol.iterator](node.right));
8848
8969
  }
8849
8970
  }
@@ -8855,10 +8976,10 @@ var dataStructureTyped = (() => {
8855
8976
  return emptyDisplayLayout;
8856
8977
  } else if (node === void 0 && !isShowUndefined) {
8857
8978
  return emptyDisplayLayout;
8858
- } else if (node !== null && node !== void 0 && isNaN(node.key) && !isShowRedBlackNIL) {
8979
+ } else if (node !== null && node !== void 0 && isNaN(this.extractor(node.key)) && !isShowRedBlackNIL) {
8859
8980
  return emptyDisplayLayout;
8860
8981
  } else if (node !== null && node !== void 0) {
8861
- const key = node.key, line = isNaN(key) ? "S" : key.toString(), width = line.length;
8982
+ const key = node.key, line = isNaN(this.extractor(key)) ? "S" : this.extractor(key).toString(), width = line.length;
8862
8983
  return _buildNodeDisplay(line, width, this._displayAux(node.left, options), this._displayAux(node.right, options));
8863
8984
  } else {
8864
8985
  const line = node === void 0 ? "U" : "N", width = line.length;
@@ -8936,7 +9057,7 @@ var dataStructureTyped = (() => {
8936
9057
  * If the parent node is null, the function also returns undefined.
8937
9058
  */
8938
9059
  _addTo(newNode, parent) {
8939
- if (this.isNodeKey(parent))
9060
+ if (this.isNotNodeInstance(parent))
8940
9061
  parent = this.getNode(parent);
8941
9062
  if (parent) {
8942
9063
  if (parent.left === void 0) {
@@ -9028,11 +9149,11 @@ var dataStructureTyped = (() => {
9028
9149
  constructor(elements, options) {
9029
9150
  super([], options);
9030
9151
  __publicField(this, "_root");
9031
- __publicField(this, "comparator", (a, b) => a - b);
9152
+ __publicField(this, "_variant", "MIN" /* MIN */);
9032
9153
  if (options) {
9033
- const { comparator } = options;
9034
- if (comparator) {
9035
- this.comparator = comparator;
9154
+ const { variant } = options;
9155
+ if (variant) {
9156
+ this._variant = variant;
9036
9157
  }
9037
9158
  }
9038
9159
  this._root = void 0;
@@ -9042,9 +9163,12 @@ var dataStructureTyped = (() => {
9042
9163
  get root() {
9043
9164
  return this._root;
9044
9165
  }
9166
+ get variant() {
9167
+ return this._variant;
9168
+ }
9045
9169
  /**
9046
9170
  * The function creates a new binary search tree node with the given key and value.
9047
- * @param {BTNKey} key - The key parameter is the key value that will be associated with
9171
+ * @param {K} key - The key parameter is the key value that will be associated with
9048
9172
  * the new node. It is used to determine the position of the node in the binary search tree.
9049
9173
  * @param [value] - The parameter `value` is an optional value that can be assigned to the node. It
9050
9174
  * represents the value associated with the node in a binary search tree.
@@ -9063,12 +9187,12 @@ var dataStructureTyped = (() => {
9063
9187
  createTree(options) {
9064
9188
  return new _BST([], __spreadValues({
9065
9189
  iterationType: this.iterationType,
9066
- comparator: this.comparator
9190
+ variant: this.variant
9067
9191
  }, options));
9068
9192
  }
9069
9193
  /**
9070
9194
  * The function checks if an exemplar is an instance of BSTNode.
9071
- * @param exemplar - The `exemplar` parameter is a variable of type `BTNodeExemplar<V, N>`.
9195
+ * @param exemplar - The `exemplar` parameter is a variable of type `BTNodeExemplar<K, V, N>`.
9072
9196
  * @returns a boolean value indicating whether the exemplar is an instance of the BSTNode class.
9073
9197
  */
9074
9198
  isNode(exemplar) {
@@ -9077,7 +9201,7 @@ var dataStructureTyped = (() => {
9077
9201
  /**
9078
9202
  * The function `exemplarToNode` takes an exemplar and returns a corresponding node if the exemplar
9079
9203
  * is valid, otherwise it returns undefined.
9080
- * @param exemplar - The `exemplar` parameter is of type `BTNodeExemplar<V, N>`.
9204
+ * @param exemplar - The `exemplar` parameter is of type `BTNodeExemplar<K, V, N>`.
9081
9205
  * @returns a variable `node` which is of type `N` or `undefined`.
9082
9206
  */
9083
9207
  exemplarToNode(exemplar) {
@@ -9093,7 +9217,7 @@ var dataStructureTyped = (() => {
9093
9217
  } else {
9094
9218
  node = this.createNode(key, value);
9095
9219
  }
9096
- } else if (this.isNodeKey(exemplar)) {
9220
+ } else if (this.isNotNodeInstance(exemplar)) {
9097
9221
  node = this.createNode(exemplar);
9098
9222
  } else {
9099
9223
  return;
@@ -9190,17 +9314,17 @@ var dataStructureTyped = (() => {
9190
9314
  sorted = realBTNExemplars.sort((a, b) => {
9191
9315
  let aR, bR;
9192
9316
  if (this.isEntry(a))
9193
- aR = a[0];
9317
+ aR = this.extractor(a[0]);
9194
9318
  else if (this.isRealNode(a))
9195
- aR = a.key;
9319
+ aR = this.extractor(a.key);
9196
9320
  else
9197
- aR = a;
9321
+ aR = this.extractor(a);
9198
9322
  if (this.isEntry(b))
9199
- bR = b[0];
9323
+ bR = this.extractor(b[0]);
9200
9324
  else if (this.isRealNode(b))
9201
- bR = b.key;
9325
+ bR = this.extractor(b.key);
9202
9326
  else
9203
- bR = b;
9327
+ bR = this.extractor(b);
9204
9328
  return aR - bR;
9205
9329
  });
9206
9330
  const _dfs = (arr) => {
@@ -9236,34 +9360,31 @@ var dataStructureTyped = (() => {
9236
9360
  }
9237
9361
  return inserted;
9238
9362
  }
9239
- /**
9240
- * Time Complexity: O(n log n) - Adding each element individually in a balanced tree.
9241
- * Space Complexity: O(n) - Additional space is required for the sorted array.
9242
- */
9243
- /**
9244
- * Time Complexity: O(log n) - Average case for a balanced tree.
9245
- * Space Complexity: O(1) - Constant space is used.
9246
- *
9247
- * The `lastKey` function returns the key of the rightmost node in a binary tree, or the key of the
9248
- * leftmost node if the comparison result is greater than.
9249
- * @param {BTNKey | N | undefined} beginRoot - The `beginRoot` parameter is optional and can be of
9250
- * type `BTNKey`, `N`, or `undefined`. It represents the starting point for finding the last key in
9251
- * the binary tree. If not provided, it defaults to the root of the binary tree (`this.root`).
9252
- * @param iterationType - The `iterationType` parameter is used to specify the type of iteration to
9253
- * be performed. It can have one of the following values:
9254
- * @returns the key of the rightmost node in the binary tree if the comparison result is less than,
9255
- * the key of the leftmost node if the comparison result is greater than, and the key of the
9256
- * rightmost node otherwise. If no node is found, it returns 0.
9257
- */
9258
- lastKey(beginRoot = this.root, iterationType = this.iterationType) {
9259
- var _a, _b, _c, _d, _e, _f;
9260
- if (this._compare(0, 1) === "lt" /* lt */)
9261
- return (_b = (_a = this.getRightMost(beginRoot, iterationType)) == null ? void 0 : _a.key) != null ? _b : 0;
9262
- else if (this._compare(0, 1) === "gt" /* gt */)
9263
- return (_d = (_c = this.getLeftMost(beginRoot, iterationType)) == null ? void 0 : _c.key) != null ? _d : 0;
9264
- else
9265
- return (_f = (_e = this.getRightMost(beginRoot, iterationType)) == null ? void 0 : _e.key) != null ? _f : 0;
9266
- }
9363
+ // /**
9364
+ // * Time Complexity: O(n log n) - Adding each element individually in a balanced tree.
9365
+ // * Space Complexity: O(n) - Additional space is required for the sorted array.
9366
+ // */
9367
+ //
9368
+ // /**
9369
+ // * Time Complexity: O(log n) - Average case for a balanced tree.
9370
+ // * Space Complexity: O(1) - Constant space is used.
9371
+ // *
9372
+ // * The `lastKey` function returns the key of the rightmost node in a binary tree, or the key of the
9373
+ // * leftmost node if the comparison result is greater than.
9374
+ // * @param {K | N | undefined} beginRoot - The `beginRoot` parameter is optional and can be of
9375
+ // * type `K`, `N`, or `undefined`. It represents the starting point for finding the last key in
9376
+ // * the binary tree. If not provided, it defaults to the root of the binary tree (`this.root`).
9377
+ // * @param iterationType - The `iterationType` parameter is used to specify the type of iteration to
9378
+ // * be performed. It can have one of the following values:
9379
+ // * @returns the key of the rightmost node in the binary tree if the comparison result is less than,
9380
+ // * the key of the leftmost node if the comparison result is greater than, and the key of the
9381
+ // * rightmost node otherwise. If no node is found, it returns 0.
9382
+ // */
9383
+ // lastKey(beginRoot: BSTNodeKeyOrNode<K,N> = this.root, iterationType = this.iterationType): K {
9384
+ // if (this._compare(0, 1) === CP.lt) return this.getRightMost(beginRoot, iterationType)?.key ?? 0;
9385
+ // else if (this._compare(0, 1) === CP.gt) return this.getLeftMost(beginRoot, iterationType)?.key ?? 0;
9386
+ // else return this.getRightMost(beginRoot, iterationType)?.key ?? 0;
9387
+ // }
9267
9388
  /**
9268
9389
  * Time Complexity: O(log n) - Average case for a balanced tree.
9269
9390
  * Space Complexity: O(1) - Constant space is used.
@@ -9274,7 +9395,7 @@ var dataStructureTyped = (() => {
9274
9395
  *
9275
9396
  * The function `getNodeByKey` searches for a node in a binary tree based on a given key, using
9276
9397
  * either recursive or iterative methods.
9277
- * @param {BTNKey} key - The `key` parameter is the key value that we are searching for in the tree.
9398
+ * @param {K} key - The `key` parameter is the key value that we are searching for in the tree.
9278
9399
  * It is used to identify the node that we want to retrieve.
9279
9400
  * @param iterationType - The `iterationType` parameter is an optional parameter that specifies the
9280
9401
  * type of iteration to use when searching for a node in the binary tree. It can have two possible
@@ -9319,14 +9440,14 @@ var dataStructureTyped = (() => {
9319
9440
  /**
9320
9441
  * The function `ensureNode` returns the node corresponding to the given key if it is a node key,
9321
9442
  * otherwise it returns the key itself.
9322
- * @param {BTNKey | N | undefined} key - The `key` parameter can be of type `BTNKey`, `N`, or
9443
+ * @param {K | N | undefined} key - The `key` parameter can be of type `K`, `N`, or
9323
9444
  * `undefined`.
9324
9445
  * @param iterationType - The `iterationType` parameter is an optional parameter that specifies the
9325
9446
  * type of iteration to be performed. It has a default value of `IterationType.ITERATIVE`.
9326
9447
  * @returns either a node object (N) or undefined.
9327
9448
  */
9328
9449
  ensureNode(key, iterationType = "ITERATIVE" /* ITERATIVE */) {
9329
- return this.isNodeKey(key) ? this.getNodeByKey(key, iterationType) : key;
9450
+ return this.isNotNodeInstance(key) ? this.getNodeByKey(key, iterationType) : key;
9330
9451
  }
9331
9452
  /**
9332
9453
  * Time Complexity: O(log n) - Average case for a balanced tree. O(n) - Visiting each node once when identifier is not node's key.
@@ -9344,7 +9465,7 @@ var dataStructureTyped = (() => {
9344
9465
  * first node that matches the identifier. If set to true, the function will return an array
9345
9466
  * containing only the first matching node. If set to false (default), the function will continue
9346
9467
  * searching for all nodes that match the identifier and return an array containing
9347
- * @param {BTNKey | N | undefined} beginRoot - The `beginRoot` parameter represents the starting node
9468
+ * @param {K | N | undefined} beginRoot - The `beginRoot` parameter represents the starting node
9348
9469
  * for the traversal. It can be either a key value or a node object. If it is undefined, the
9349
9470
  * traversal will start from the root of the tree.
9350
9471
  * @param iterationType - The `iterationType` parameter determines the type of iteration to be
@@ -9419,7 +9540,7 @@ var dataStructureTyped = (() => {
9419
9540
  * traverse nodes that are lesser than, greater than, or equal to the `targetNode`. It is of type
9420
9541
  * `CP`, which is a custom type representing the comparison operator. The possible values for
9421
9542
  * `lesserOrGreater` are
9422
- * @param {BTNKey | N | undefined} targetNode - The `targetNode` parameter represents the node in the
9543
+ * @param {K | N | undefined} targetNode - The `targetNode` parameter represents the node in the
9423
9544
  * binary tree that you want to traverse from. It can be specified either by its key, by the node
9424
9545
  * object itself, or it can be left undefined to start the traversal from the root of the tree.
9425
9546
  * @param iterationType - The `iterationType` parameter determines the type of traversal to be
@@ -9591,19 +9712,16 @@ var dataStructureTyped = (() => {
9591
9712
  /**
9592
9713
  * The function compares two values using a comparator function and returns whether the first value
9593
9714
  * is greater than, less than, or equal to the second value.
9594
- * @param {BTNKey} a - The parameter "a" is of type BTNKey.
9595
- * @param {BTNKey} b - The parameter "b" in the above code represents a BTNKey.
9715
+ * @param {K} a - The parameter "a" is of type K.
9716
+ * @param {K} b - The parameter "b" in the above code represents a K.
9596
9717
  * @returns a value of type CP (ComparisonResult). The possible return values are CP.gt (greater
9597
9718
  * than), CP.lt (less than), or CP.eq (equal).
9598
9719
  */
9599
9720
  _compare(a, b) {
9600
- const compared = this.comparator(a, b);
9601
- if (compared > 0)
9602
- return "gt" /* gt */;
9603
- else if (compared < 0)
9604
- return "lt" /* lt */;
9605
- else
9606
- return "eq" /* eq */;
9721
+ const extractedA = this.extractor(a);
9722
+ const extractedB = this.extractor(b);
9723
+ const compared = this.variant === "MIN" /* MIN */ ? extractedA - extractedB : extractedB - extractedA;
9724
+ return compared > 0 ? "gt" /* gt */ : compared < 0 ? "lt" /* lt */ : "eq" /* eq */;
9607
9725
  }
9608
9726
  };
9609
9727
 
@@ -10044,7 +10162,7 @@ var dataStructureTyped = (() => {
10044
10162
  var AVLTree = class _AVLTree extends BST {
10045
10163
  /**
10046
10164
  * The constructor function initializes an AVLTree object with optional elements and options.
10047
- * @param [elements] - The `elements` parameter is an optional iterable of `BTNodeExemplar<V, N>`
10165
+ * @param [elements] - The `elements` parameter is an optional iterable of `BTNodeExemplar<K, V, N>`
10048
10166
  * objects. It represents a collection of elements that will be added to the AVL tree during
10049
10167
  * initialization.
10050
10168
  * @param [options] - The `options` parameter is an optional object that allows you to customize the
@@ -10058,7 +10176,7 @@ var dataStructureTyped = (() => {
10058
10176
  }
10059
10177
  /**
10060
10178
  * The function creates a new AVL tree node with the specified key and value.
10061
- * @param {BTNKey} key - The key parameter is the key value that will be associated with
10179
+ * @param {K} key - The key parameter is the key value that will be associated with
10062
10180
  * the new node. It is used to determine the position of the node in the binary search tree.
10063
10181
  * @param [value] - The parameter `value` is an optional value that can be assigned to the node. It is of
10064
10182
  * type `V`, which means it can be any value that is assignable to the `value` property of the
@@ -10078,12 +10196,12 @@ var dataStructureTyped = (() => {
10078
10196
  createTree(options) {
10079
10197
  return new _AVLTree([], __spreadValues({
10080
10198
  iterationType: this.iterationType,
10081
- comparator: this.comparator
10199
+ variant: this.variant
10082
10200
  }, options));
10083
10201
  }
10084
10202
  /**
10085
10203
  * The function checks if an exemplar is an instance of AVLTreeNode.
10086
- * @param exemplar - The `exemplar` parameter is of type `BTNodeExemplar<V, N>`.
10204
+ * @param exemplar - The `exemplar` parameter is of type `BTNodeExemplar<K, V, N>`.
10087
10205
  * @returns a boolean value indicating whether the exemplar is an instance of the AVLTreeNode class.
10088
10206
  */
10089
10207
  isNode(exemplar) {
@@ -10144,9 +10262,9 @@ var dataStructureTyped = (() => {
10144
10262
  /**
10145
10263
  * The `_swapProperties` function swaps the key, value, and height properties between two nodes in a binary
10146
10264
  * tree.
10147
- * @param {BTNKey | N | undefined} srcNode - The `srcNode` parameter represents the source node that
10148
- * needs to be swapped with the destination node. It can be of type `BTNKey`, `N`, or `undefined`.
10149
- * @param {BTNKey | N | undefined} destNode - The `destNode` parameter represents the destination
10265
+ * @param {K | N | undefined} srcNode - The `srcNode` parameter represents the source node that
10266
+ * needs to be swapped with the destination node. It can be of type `K`, `N`, or `undefined`.
10267
+ * @param {K | N | undefined} destNode - The `destNode` parameter represents the destination
10150
10268
  * node where the values from the source node will be swapped to.
10151
10269
  * @returns either the `destNode` object if both `srcNode` and `destNode` are defined, or `undefined`
10152
10270
  * if either `srcNode` or `destNode` is undefined.
@@ -10458,7 +10576,7 @@ var dataStructureTyped = (() => {
10458
10576
  /**
10459
10577
  * This is the constructor function for a Red-Black Tree data structure in TypeScript, which
10460
10578
  * initializes the tree with optional elements and options.
10461
- * @param [elements] - The `elements` parameter is an optional iterable of `BTNodeExemplar<V, N>`
10579
+ * @param [elements] - The `elements` parameter is an optional iterable of `BTNodeExemplar<K, V, N>`
10462
10580
  * objects. It represents the initial elements that will be added to the RBTree during its
10463
10581
  * construction. If this parameter is provided, the `addMany` method is called to add all the
10464
10582
  * elements to the
@@ -10483,7 +10601,7 @@ var dataStructureTyped = (() => {
10483
10601
  }
10484
10602
  /**
10485
10603
  * The function creates a new Red-Black Tree node with the specified key, value, and color.
10486
- * @param {BTNKey} key - The key parameter is the key value associated with the node. It is used to
10604
+ * @param {K} key - The key parameter is the key value associated with the node. It is used to
10487
10605
  * identify and compare nodes in the Red-Black Tree.
10488
10606
  * @param {V} [value] - The `value` parameter is an optional parameter that represents the value
10489
10607
  * associated with the node. It is of type `V`, which is a generic type that can be replaced with any
@@ -10506,12 +10624,12 @@ var dataStructureTyped = (() => {
10506
10624
  createTree(options) {
10507
10625
  return new _RedBlackTree([], __spreadValues({
10508
10626
  iterationType: this.iterationType,
10509
- comparator: this.comparator
10627
+ variant: this.variant
10510
10628
  }, options));
10511
10629
  }
10512
10630
  /**
10513
10631
  * The function checks if an exemplar is an instance of the RedBlackTreeNode class.
10514
- * @param exemplar - The `exemplar` parameter is of type `BTNodeExemplar<V, N>`.
10632
+ * @param exemplar - The `exemplar` parameter is of type `BTNodeExemplar<K, V, N>`.
10515
10633
  * @returns a boolean value indicating whether the exemplar is an instance of the RedBlackTreeNode
10516
10634
  * class.
10517
10635
  */
@@ -10521,7 +10639,7 @@ var dataStructureTyped = (() => {
10521
10639
  /**
10522
10640
  * The function `exemplarToNode` takes an exemplar and returns a node if the exemplar is valid,
10523
10641
  * otherwise it returns undefined.
10524
- * @param exemplar - BTNodeExemplar<V, N> - A generic type representing an exemplar of a binary tree
10642
+ * @param exemplar - BTNodeExemplar<K, V, N> - A generic type representing an exemplar of a binary tree
10525
10643
  * node. It can be either a node itself, an entry (key-value pair), a node key, or any other value
10526
10644
  * that is not a valid exemplar.
10527
10645
  * @returns a variable `node` which is of type `N | undefined`.
@@ -10539,7 +10657,7 @@ var dataStructureTyped = (() => {
10539
10657
  } else {
10540
10658
  node = this.createNode(key, value, 1 /* RED */);
10541
10659
  }
10542
- } else if (this.isNodeKey(exemplar)) {
10660
+ } else if (this.isNotNodeInstance(exemplar)) {
10543
10661
  node = this.createNode(exemplar, void 0, 1 /* RED */);
10544
10662
  } else {
10545
10663
  return;
@@ -10695,7 +10813,7 @@ var dataStructureTyped = (() => {
10695
10813
  * @param {C} callback - The `callback` parameter is a function that will be called for each node in
10696
10814
  * the binary tree. It is used to determine if a node matches the given identifier. The `callback`
10697
10815
  * function should take a single parameter of type `N` (the type of the nodes in the binary tree) and
10698
- * @param {BTNKey | N | undefined} beginRoot - The `beginRoot` parameter is the starting point for
10816
+ * @param {K | N | undefined} beginRoot - The `beginRoot` parameter is the starting point for
10699
10817
  * searching for a node in a binary tree. It can be either a key value or a node object. If it is not
10700
10818
  * provided, the search will start from the root of the binary tree.
10701
10819
  * @param iterationType - The `iterationType` parameter is a variable that determines the type of
@@ -11002,7 +11120,7 @@ var dataStructureTyped = (() => {
11002
11120
  var TreeMultimapNode = class extends AVLTreeNode {
11003
11121
  /**
11004
11122
  * The constructor function initializes a BinaryTreeNode object with a key, value, and count.
11005
- * @param {BTNKey} key - The `key` parameter is of type `BTNKey` and represents the unique identifier
11123
+ * @param {K} key - The `key` parameter is of type `K` and represents the unique identifier
11006
11124
  * of the binary tree node.
11007
11125
  * @param {V} [value] - The `value` parameter is an optional parameter of type `V`. It represents the value of the binary
11008
11126
  * tree node. If no value is provided, it will be `undefined`.
@@ -11031,7 +11149,7 @@ var dataStructureTyped = (() => {
11031
11149
  }
11032
11150
  /**
11033
11151
  * The function creates a new BSTNode with the given key, value, and count.
11034
- * @param {BTNKey} key - The key parameter is the unique identifier for the binary tree node. It is used to
11152
+ * @param {K} key - The key parameter is the unique identifier for the binary tree node. It is used to
11035
11153
  * distinguish one node from another in the tree.
11036
11154
  * @param {N} value - The `value` parameter represents the value that will be stored in the binary search tree node.
11037
11155
  * @param {number} [count] - The "count" parameter is an optional parameter of type number. It represents the number of
@@ -11044,12 +11162,12 @@ var dataStructureTyped = (() => {
11044
11162
  createTree(options) {
11045
11163
  return new _TreeMultimap([], __spreadValues({
11046
11164
  iterationType: this.iterationType,
11047
- comparator: this.comparator
11165
+ variant: this.variant
11048
11166
  }, options));
11049
11167
  }
11050
11168
  /**
11051
11169
  * The function checks if an exemplar is an instance of the TreeMultimapNode class.
11052
- * @param exemplar - The `exemplar` parameter is of type `BTNodeExemplar<V, N>`.
11170
+ * @param exemplar - The `exemplar` parameter is of type `BTNodeExemplar<K, V, N>`.
11053
11171
  * @returns a boolean value indicating whether the exemplar is an instance of the TreeMultimapNode
11054
11172
  * class.
11055
11173
  */
@@ -11058,7 +11176,7 @@ var dataStructureTyped = (() => {
11058
11176
  }
11059
11177
  /**
11060
11178
  * The function `exemplarToNode` converts an exemplar object into a node object.
11061
- * @param exemplar - The `exemplar` parameter is of type `BTNodeExemplar<V, N>`, where `V` represents
11179
+ * @param exemplar - The `exemplar` parameter is of type `BTNodeExemplar<K, V, N>`, where `V` represents
11062
11180
  * the value type and `N` represents the node type.
11063
11181
  * @param [count=1] - The `count` parameter is an optional parameter that specifies the number of
11064
11182
  * times the node should be created. If not provided, it defaults to 1.
@@ -11077,7 +11195,7 @@ var dataStructureTyped = (() => {
11077
11195
  } else {
11078
11196
  node = this.createNode(key, value, count);
11079
11197
  }
11080
- } else if (this.isNodeKey(exemplar)) {
11198
+ } else if (this.isNotNodeInstance(exemplar)) {
11081
11199
  node = this.createNode(exemplar, void 0, count);
11082
11200
  } else {
11083
11201
  return;
@@ -11289,9 +11407,9 @@ var dataStructureTyped = (() => {
11289
11407
  * @param {N | undefined} newNode - The `newNode` parameter represents the node that needs to be
11290
11408
  * added to the binary tree. It can be of type `N` (which represents a node in the binary tree) or
11291
11409
  * `undefined` if there is no node to add.
11292
- * @param {BTNKey | N | undefined} parent - The `parent` parameter represents the parent node to
11410
+ * @param {K | N | undefined} parent - The `parent` parameter represents the parent node to
11293
11411
  * which the new node will be added as a child. It can be either a node object (`N`) or a key value
11294
- * (`BTNKey`).
11412
+ * (`K`).
11295
11413
  * @returns The method `_addTo` returns either the `parent.left` or `parent.right` node that was
11296
11414
  * added, or `undefined` if no node was added.
11297
11415
  */
@@ -11321,9 +11439,9 @@ var dataStructureTyped = (() => {
11321
11439
  }
11322
11440
  /**
11323
11441
  * The `_swapProperties` function swaps the key, value, count, and height properties between two nodes.
11324
- * @param {BTNKey | N | undefined} srcNode - The `srcNode` parameter represents the source node from
11325
- * which the values will be swapped. It can be of type `BTNKey`, `N`, or `undefined`.
11326
- * @param {BTNKey | N | undefined} destNode - The `destNode` parameter represents the destination
11442
+ * @param {K | N | undefined} srcNode - The `srcNode` parameter represents the source node from
11443
+ * which the values will be swapped. It can be of type `K`, `N`, or `undefined`.
11444
+ * @param {K | N | undefined} destNode - The `destNode` parameter represents the destination
11327
11445
  * node where the values from the source node will be swapped to.
11328
11446
  * @returns either the `destNode` object if both `srcNode` and `destNode` are defined, or `undefined`
11329
11447
  * if either `srcNode` or `destNode` is undefined.