data-structure-typed 1.46.8 → 1.46.9

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 (68) hide show
  1. package/CHANGELOG.md +1 -1
  2. package/README.md +1 -1
  3. package/benchmark/report.html +1 -46
  4. package/benchmark/report.json +11 -422
  5. package/dist/cjs/data-structures/binary-tree/avl-tree.d.ts +4 -2
  6. package/dist/cjs/data-structures/binary-tree/avl-tree.js +10 -0
  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 +19 -13
  9. package/dist/cjs/data-structures/binary-tree/binary-tree.js +121 -55
  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 +10 -9
  12. package/dist/cjs/data-structures/binary-tree/bst.js +16 -14
  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 +7 -5
  15. package/dist/cjs/data-structures/binary-tree/rb-tree.js +32 -23
  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 +5 -3
  18. package/dist/cjs/data-structures/binary-tree/tree-multimap.js +11 -2
  19. package/dist/cjs/data-structures/binary-tree/tree-multimap.js.map +1 -1
  20. package/dist/cjs/interfaces/binary-tree.d.ts +3 -3
  21. package/dist/cjs/types/common.d.ts +5 -4
  22. package/dist/cjs/types/data-structures/binary-tree/avl-tree.d.ts +2 -1
  23. package/dist/cjs/types/data-structures/binary-tree/binary-tree.d.ts +3 -1
  24. package/dist/cjs/types/data-structures/binary-tree/binary-tree.js +0 -6
  25. package/dist/cjs/types/data-structures/binary-tree/binary-tree.js.map +1 -1
  26. package/dist/cjs/types/data-structures/binary-tree/bst.d.ts +2 -1
  27. package/dist/cjs/types/data-structures/binary-tree/rb-tree.d.ts +2 -1
  28. package/dist/cjs/types/data-structures/binary-tree/tree-multimap.d.ts +2 -1
  29. package/dist/mjs/data-structures/binary-tree/avl-tree.d.ts +4 -2
  30. package/dist/mjs/data-structures/binary-tree/avl-tree.js +11 -0
  31. package/dist/mjs/data-structures/binary-tree/binary-tree.d.ts +19 -13
  32. package/dist/mjs/data-structures/binary-tree/binary-tree.js +122 -55
  33. package/dist/mjs/data-structures/binary-tree/bst.d.ts +10 -9
  34. package/dist/mjs/data-structures/binary-tree/bst.js +17 -14
  35. package/dist/mjs/data-structures/binary-tree/rb-tree.d.ts +7 -5
  36. package/dist/mjs/data-structures/binary-tree/rb-tree.js +34 -24
  37. package/dist/mjs/data-structures/binary-tree/tree-multimap.d.ts +5 -3
  38. package/dist/mjs/data-structures/binary-tree/tree-multimap.js +12 -2
  39. package/dist/mjs/interfaces/binary-tree.d.ts +3 -3
  40. package/dist/mjs/types/common.d.ts +5 -4
  41. package/dist/mjs/types/data-structures/binary-tree/avl-tree.d.ts +2 -1
  42. package/dist/mjs/types/data-structures/binary-tree/binary-tree.d.ts +3 -1
  43. package/dist/mjs/types/data-structures/binary-tree/binary-tree.js +0 -6
  44. package/dist/mjs/types/data-structures/binary-tree/bst.d.ts +2 -1
  45. package/dist/mjs/types/data-structures/binary-tree/rb-tree.d.ts +2 -1
  46. package/dist/mjs/types/data-structures/binary-tree/tree-multimap.d.ts +2 -1
  47. package/dist/umd/data-structure-typed.js +198 -103
  48. package/dist/umd/data-structure-typed.min.js +4 -1
  49. package/dist/umd/data-structure-typed.min.js.map +1 -1
  50. package/package.json +5 -5
  51. package/src/data-structures/binary-tree/avl-tree.ts +17 -5
  52. package/src/data-structures/binary-tree/binary-tree.ts +143 -62
  53. package/src/data-structures/binary-tree/bst.ts +23 -19
  54. package/src/data-structures/binary-tree/rb-tree.ts +38 -27
  55. package/src/data-structures/binary-tree/tree-multimap.ts +19 -6
  56. package/src/interfaces/binary-tree.ts +3 -3
  57. package/src/types/common.ts +2 -5
  58. package/src/types/data-structures/binary-tree/avl-tree.ts +5 -1
  59. package/src/types/data-structures/binary-tree/binary-tree.ts +5 -7
  60. package/src/types/data-structures/binary-tree/bst.ts +3 -1
  61. package/src/types/data-structures/binary-tree/rb-tree.ts +3 -1
  62. package/src/types/data-structures/binary-tree/tree-multimap.ts +3 -1
  63. package/test/integration/index.html +30 -28
  64. package/test/performance/data-structures/binary-tree/rb-tree.test.ts +7 -0
  65. package/test/unit/data-structures/binary-tree/avl-tree.test.ts +57 -1
  66. package/test/unit/data-structures/binary-tree/binary-tree.test.ts +62 -7
  67. package/test/unit/data-structures/binary-tree/bst.test.ts +56 -1
  68. package/test/unit/data-structures/binary-tree/rb-tree.test.ts +98 -42
@@ -3,13 +3,26 @@ var dataStructureTyped = (() => {
3
3
  var __defProp = Object.defineProperty;
4
4
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
5
  var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
6
7
  var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
7
9
  var __knownSymbol = (name, symbol) => {
8
10
  if (symbol = Symbol[name])
9
11
  return symbol;
10
12
  throw Error("Symbol." + name + " is not defined");
11
13
  };
12
14
  var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
15
+ var __spreadValues = (a, b) => {
16
+ for (var prop in b || (b = {}))
17
+ if (__hasOwnProp.call(b, prop))
18
+ __defNormalProp(a, prop, b[prop]);
19
+ if (__getOwnPropSymbols)
20
+ for (var prop of __getOwnPropSymbols(b)) {
21
+ if (__propIsEnum.call(b, prop))
22
+ __defNormalProp(a, prop, b[prop]);
23
+ }
24
+ return a;
25
+ };
13
26
  var __export = (target, all) => {
14
27
  for (var name in all)
15
28
  __defProp(target, name, { get: all[name], enumerable: true });
@@ -113,7 +126,6 @@ var dataStructureTyped = (() => {
113
126
  HashTable: () => HashTable,
114
127
  HashTableNode: () => HashTableNode,
115
128
  Heap: () => Heap,
116
- IterateDirection: () => IterateDirection,
117
129
  IterationType: () => IterationType,
118
130
  LinkedListQueue: () => LinkedListQueue,
119
131
  MapEdge: () => MapEdge,
@@ -6511,10 +6523,10 @@ var dataStructureTyped = (() => {
6511
6523
  };
6512
6524
 
6513
6525
  // src/types/data-structures/binary-tree/binary-tree.ts
6514
- var IterationType = /* @__PURE__ */ ((IterationType3) => {
6515
- IterationType3["ITERATIVE"] = "ITERATIVE";
6516
- IterationType3["RECURSIVE"] = "RECURSIVE";
6517
- return IterationType3;
6526
+ var IterationType = /* @__PURE__ */ ((IterationType2) => {
6527
+ IterationType2["ITERATIVE"] = "ITERATIVE";
6528
+ IterationType2["RECURSIVE"] = "RECURSIVE";
6529
+ return IterationType2;
6518
6530
  })(IterationType || {});
6519
6531
  var FamilyPosition = /* @__PURE__ */ ((FamilyPosition2) => {
6520
6532
  FamilyPosition2["ROOT"] = "ROOT";
@@ -6541,11 +6553,6 @@ var dataStructureTyped = (() => {
6541
6553
  CP2["gt"] = "gt";
6542
6554
  return CP2;
6543
6555
  })(CP || {});
6544
- var IterateDirection = /* @__PURE__ */ ((IterateDirection2) => {
6545
- IterateDirection2[IterateDirection2["DEFAULT"] = 0] = "DEFAULT";
6546
- IterateDirection2[IterateDirection2["REVERSE"] = 1] = "REVERSE";
6547
- return IterateDirection2;
6548
- })(IterateDirection || {});
6549
6556
 
6550
6557
  // src/data-structures/binary-tree/binary-tree.ts
6551
6558
  var BinaryTreeNode = class {
@@ -6621,19 +6628,20 @@ var dataStructureTyped = (() => {
6621
6628
  return "MAL_NODE" /* MAL_NODE */;
6622
6629
  }
6623
6630
  };
6624
- var BinaryTree = class {
6631
+ var BinaryTree = class _BinaryTree {
6625
6632
  /**
6626
6633
  * Creates a new instance of BinaryTree.
6627
6634
  * @param {BinaryTreeOptions} [options] - The options for the binary tree.
6628
6635
  */
6629
6636
  constructor(options) {
6630
- __publicField(this, "iterationType", "ITERATIVE" /* ITERATIVE */);
6637
+ __publicField(this, "options");
6631
6638
  __publicField(this, "_root");
6632
6639
  __publicField(this, "_size");
6633
6640
  __publicField(this, "_defaultOneParamCallback", (node) => node.key);
6634
6641
  if (options) {
6635
- const { iterationType = "ITERATIVE" /* ITERATIVE */ } = options;
6636
- this.iterationType = iterationType;
6642
+ this.options = __spreadValues({ iterationType: "ITERATIVE" /* ITERATIVE */ }, options);
6643
+ } else {
6644
+ this.options = { iterationType: "ITERATIVE" /* ITERATIVE */ };
6637
6645
  }
6638
6646
  this._size = 0;
6639
6647
  }
@@ -6658,6 +6666,9 @@ var dataStructureTyped = (() => {
6658
6666
  createNode(key, value) {
6659
6667
  return new BinaryTreeNode(key, value);
6660
6668
  }
6669
+ createTree(options) {
6670
+ return new _BinaryTree(__spreadValues(__spreadValues({}, this.options), options));
6671
+ }
6661
6672
  /**
6662
6673
  * Time Complexity: O(n)
6663
6674
  * Space Complexity: O(1)
@@ -6879,7 +6890,7 @@ var dataStructureTyped = (() => {
6879
6890
  * values:
6880
6891
  * @returns the height of the binary tree.
6881
6892
  */
6882
- getHeight(beginRoot = this.root, iterationType = this.iterationType) {
6893
+ getHeight(beginRoot = this.root, iterationType = this.options.iterationType) {
6883
6894
  beginRoot = this.ensureNotKey(beginRoot);
6884
6895
  if (!beginRoot)
6885
6896
  return -1;
@@ -6924,7 +6935,7 @@ var dataStructureTyped = (() => {
6924
6935
  * to calculate the minimum height of a binary tree. It can have two possible values:
6925
6936
  * @returns The function `getMinHeight` returns the minimum height of a binary tree.
6926
6937
  */
6927
- getMinHeight(beginRoot = this.root, iterationType = this.iterationType) {
6938
+ getMinHeight(beginRoot = this.root, iterationType = this.options.iterationType) {
6928
6939
  var _a, _b, _c;
6929
6940
  beginRoot = this.ensureNotKey(beginRoot);
6930
6941
  if (!beginRoot)
@@ -7013,7 +7024,7 @@ var dataStructureTyped = (() => {
7013
7024
  * traverse the binary tree. It can have two possible values:
7014
7025
  * @returns an array of nodes of type `N`.
7015
7026
  */
7016
- getNodes(identifier, callback = this._defaultOneParamCallback, onlyOne = false, beginRoot = this.root, iterationType = this.iterationType) {
7027
+ getNodes(identifier, callback = this._defaultOneParamCallback, onlyOne = false, beginRoot = this.root, iterationType = this.options.iterationType) {
7017
7028
  if ((!callback || callback === this._defaultOneParamCallback) && identifier instanceof BinaryTreeNode)
7018
7029
  callback = (node) => node;
7019
7030
  beginRoot = this.ensureNotKey(beginRoot);
@@ -7074,7 +7085,7 @@ var dataStructureTyped = (() => {
7074
7085
  * be performed in a pre-order, in-order, or post-order manner.
7075
7086
  * @returns a boolean value.
7076
7087
  */
7077
- has(identifier, callback = this._defaultOneParamCallback, beginRoot = this.root, iterationType = this.iterationType) {
7088
+ has(identifier, callback = this._defaultOneParamCallback, beginRoot = this.root, iterationType = this.options.iterationType) {
7078
7089
  if ((!callback || callback === this._defaultOneParamCallback) && identifier instanceof BinaryTreeNode)
7079
7090
  callback = (node) => node;
7080
7091
  return this.getNodes(identifier, callback, true, beginRoot, iterationType).length > 0;
@@ -7104,7 +7115,7 @@ var dataStructureTyped = (() => {
7104
7115
  * nodes are visited during the search.
7105
7116
  * @returns a value of type `N | null | undefined`.
7106
7117
  */
7107
- getNode(identifier, callback = this._defaultOneParamCallback, beginRoot = this.root, iterationType = this.iterationType) {
7118
+ getNode(identifier, callback = this._defaultOneParamCallback, beginRoot = this.root, iterationType = this.options.iterationType) {
7108
7119
  var _a;
7109
7120
  if ((!callback || callback === this._defaultOneParamCallback) && identifier instanceof BinaryTreeNode)
7110
7121
  callback = (node) => node;
@@ -7196,7 +7207,7 @@ var dataStructureTyped = (() => {
7196
7207
  * @returns The value of the node with the given identifier is being returned. If the node is not
7197
7208
  * found, `undefined` is returned.
7198
7209
  */
7199
- get(identifier, callback = this._defaultOneParamCallback, beginRoot = this.root, iterationType = this.iterationType) {
7210
+ get(identifier, callback = this._defaultOneParamCallback, beginRoot = this.root, iterationType = this.options.iterationType) {
7200
7211
  var _a, _b;
7201
7212
  if ((!callback || callback === this._defaultOneParamCallback) && identifier instanceof BinaryTreeNode)
7202
7213
  callback = (node) => node;
@@ -7264,7 +7275,7 @@ var dataStructureTyped = (() => {
7264
7275
  * @returns The function `getLeftMost` returns the leftmost node (`N`) in the binary tree. If there
7265
7276
  * is no leftmost node, it returns `null` or `undefined` depending on the input.
7266
7277
  */
7267
- getLeftMost(beginRoot = this.root, iterationType = this.iterationType) {
7278
+ getLeftMost(beginRoot = this.root, iterationType = this.options.iterationType) {
7268
7279
  beginRoot = this.ensureNotKey(beginRoot);
7269
7280
  if (!beginRoot)
7270
7281
  return beginRoot;
@@ -7303,7 +7314,7 @@ var dataStructureTyped = (() => {
7303
7314
  * @returns The function `getRightMost` returns the rightmost node (`N`) in a binary tree. If there
7304
7315
  * is no rightmost node, it returns `null` or `undefined`, depending on the input.
7305
7316
  */
7306
- getRightMost(beginRoot = this.root, iterationType = this.iterationType) {
7317
+ getRightMost(beginRoot = this.root, iterationType = this.options.iterationType) {
7307
7318
  beginRoot = this.ensureNotKey(beginRoot);
7308
7319
  if (!beginRoot)
7309
7320
  return beginRoot;
@@ -7339,7 +7350,7 @@ var dataStructureTyped = (() => {
7339
7350
  * possible values:
7340
7351
  * @returns a boolean value.
7341
7352
  */
7342
- isSubtreeBST(beginRoot, iterationType = this.iterationType) {
7353
+ isSubtreeBST(beginRoot, iterationType = this.options.iterationType) {
7343
7354
  beginRoot = this.ensureNotKey(beginRoot);
7344
7355
  if (!beginRoot)
7345
7356
  return true;
@@ -7384,7 +7395,7 @@ var dataStructureTyped = (() => {
7384
7395
  * expected to be
7385
7396
  * @returns a boolean value.
7386
7397
  */
7387
- isBST(iterationType = this.iterationType) {
7398
+ isBST(iterationType = this.options.iterationType) {
7388
7399
  if (this.root === null)
7389
7400
  return true;
7390
7401
  return this.isSubtreeBST(this.root, iterationType);
@@ -7409,13 +7420,13 @@ var dataStructureTyped = (() => {
7409
7420
  * @param iterationType - The `iterationType` parameter determines the type of traversal to be
7410
7421
  * performed on the subtree. It can have two possible values:
7411
7422
  * @param [includeNull=false] - The `includeNull` parameter is a boolean value that determines
7412
- * whether or not to include null values in the traversal. If `includeNull` is set to `true`, the
7423
+ * whether to include null values in the traversal. If `includeNull` is set to `true`, the
7413
7424
  * traversal will include null values, otherwise it will skip them.
7414
7425
  * @returns The function `subTreeTraverse` returns an array of values that are the result of invoking
7415
7426
  * the `callback` function on each node in the subtree. The type of the array elements is determined
7416
7427
  * by the return type of the `callback` function.
7417
7428
  */
7418
- subTreeTraverse(callback = this._defaultOneParamCallback, beginRoot = this.root, iterationType = this.iterationType, includeNull = false) {
7429
+ subTreeTraverse(callback = this._defaultOneParamCallback, beginRoot = this.root, iterationType = this.options.iterationType, includeNull = false) {
7419
7430
  beginRoot = this.ensureNotKey(beginRoot);
7420
7431
  const ans = [];
7421
7432
  if (!beginRoot)
@@ -7632,12 +7643,12 @@ var dataStructureTyped = (() => {
7632
7643
  * @param iterationType - The `iterationType` parameter determines the type of iteration to be
7633
7644
  * performed during the breadth-first search (BFS). It can have two possible values:
7634
7645
  * @param [includeNull=false] - The `includeNull` parameter is a boolean flag that determines whether
7635
- * or not to include null values in the breadth-first search traversal. If `includeNull` is set to
7646
+ * to include null values in the breadth-first search traversal. If `includeNull` is set to
7636
7647
  * `true`, null values will be included in the traversal, otherwise they will be skipped.
7637
7648
  * @returns an array of values that are the result of invoking the callback function on each node in
7638
7649
  * the breadth-first traversal of a binary tree.
7639
7650
  */
7640
- bfs(callback = this._defaultOneParamCallback, beginRoot = this.root, iterationType = this.iterationType, includeNull = false) {
7651
+ bfs(callback = this._defaultOneParamCallback, beginRoot = this.root, iterationType = this.options.iterationType, includeNull = false) {
7641
7652
  beginRoot = this.ensureNotKey(beginRoot);
7642
7653
  if (!beginRoot)
7643
7654
  return [];
@@ -7706,12 +7717,12 @@ var dataStructureTyped = (() => {
7706
7717
  * @param iterationType - The `iterationType` parameter determines the type of iteration to be
7707
7718
  * performed on the tree. It can have two possible values:
7708
7719
  * @param [includeNull=false] - The `includeNull` parameter is a boolean value that determines
7709
- * whether or not to include null values in the resulting levels. If `includeNull` is set to `true`,
7720
+ * whether to include null values in the resulting levels. If `includeNull` is set to `true`,
7710
7721
  * null values will be included in the levels. If `includeNull` is set to `false`, null values will
7711
7722
  * be excluded
7712
7723
  * @returns The function `listLevels` returns a two-dimensional array of type `ReturnType<C>[][]`.
7713
7724
  */
7714
- listLevels(callback = this._defaultOneParamCallback, beginRoot = this.root, iterationType = this.iterationType, includeNull = false) {
7725
+ listLevels(callback = this._defaultOneParamCallback, beginRoot = this.root, iterationType = this.options.iterationType, includeNull = false) {
7715
7726
  beginRoot = this.ensureNotKey(beginRoot);
7716
7727
  const levelsNodes = [];
7717
7728
  if (!beginRoot)
@@ -7902,6 +7913,42 @@ var dataStructureTyped = (() => {
7902
7913
  }
7903
7914
  return ans;
7904
7915
  }
7916
+ forEach(callback) {
7917
+ for (const entry of this) {
7918
+ callback(entry, this);
7919
+ }
7920
+ }
7921
+ filter(predicate) {
7922
+ const newTree = this.createTree();
7923
+ for (const [key, value] of this) {
7924
+ if (predicate([key, value], this)) {
7925
+ newTree.add(key, value);
7926
+ }
7927
+ }
7928
+ return newTree;
7929
+ }
7930
+ // TODO Type error, need to return a TREE<NV> that is a value type only for callback function.
7931
+ // map<NV>(callback: (entry: [BTNKey, V | undefined], tree: typeof this) => NV) {
7932
+ // const newTree = this.createTree();
7933
+ // for (const [key, value] of this) {
7934
+ // newTree.add(key, callback([key, value], this));
7935
+ // }
7936
+ // return newTree;
7937
+ // }
7938
+ map(callback) {
7939
+ const newTree = this.createTree();
7940
+ for (const [key, value] of this) {
7941
+ newTree.add(key, callback([key, value], this));
7942
+ }
7943
+ return newTree;
7944
+ }
7945
+ reduce(callback, initialValue) {
7946
+ let accumulator = initialValue;
7947
+ for (const [key, value] of this) {
7948
+ accumulator = callback(accumulator, [key, value], this);
7949
+ }
7950
+ return accumulator;
7951
+ }
7905
7952
  /**
7906
7953
  * The above function is an iterator for a binary tree that can be used to traverse the tree in
7907
7954
  * either an iterative or recursive manner.
@@ -7912,71 +7959,90 @@ var dataStructureTyped = (() => {
7912
7959
  * binary tree nodes in a specific order.
7913
7960
  */
7914
7961
  *[Symbol.iterator](node = this.root) {
7915
- if (!node) {
7962
+ if (!node)
7916
7963
  return;
7917
- }
7918
- if (this.iterationType === "ITERATIVE" /* ITERATIVE */) {
7964
+ if (this.options.iterationType === "ITERATIVE" /* ITERATIVE */) {
7919
7965
  const stack = [];
7920
7966
  let current = node;
7921
7967
  while (current || stack.length > 0) {
7922
- while (current) {
7968
+ while (current && !isNaN(current.key)) {
7923
7969
  stack.push(current);
7924
7970
  current = current.left;
7925
7971
  }
7926
7972
  current = stack.pop();
7927
- if (current)
7928
- yield current.key;
7929
- if (current)
7973
+ if (current && !isNaN(current.key)) {
7974
+ yield [current.key, current.value];
7930
7975
  current = current.right;
7976
+ }
7931
7977
  }
7932
7978
  } else {
7933
- if (node.left) {
7979
+ if (node.left && !isNaN(node.key)) {
7934
7980
  yield* __yieldStar(this[Symbol.iterator](node.left));
7935
7981
  }
7936
- yield node.key;
7937
- if (node.right) {
7982
+ yield [node.key, node.value];
7983
+ if (node.right && !isNaN(node.key)) {
7938
7984
  yield* __yieldStar(this[Symbol.iterator](node.right));
7939
7985
  }
7940
7986
  }
7941
7987
  }
7942
7988
  /**
7943
7989
  * The `print` function is used to display a binary tree structure in a visually appealing way.
7944
- * @param {N | null | undefined} beginRoot - The `root` parameter is of type `BTNKey | N | null |
7990
+ * @param {BTNKey | N | null | undefined} [beginRoot=this.root] - The `root` parameter is of type `BTNKey | N | null |
7945
7991
  * undefined`. It represents the root node of a binary tree. The root node can have one of the
7946
7992
  * following types:
7993
+ * @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.
7947
7994
  */
7948
- print(beginRoot = this.root) {
7995
+ print(beginRoot = this.root, options) {
7996
+ const opts = __spreadValues({ isShowUndefined: false, isShowNull: false, isShowRedBlackNIL: false }, options);
7949
7997
  beginRoot = this.ensureNotKey(beginRoot);
7950
7998
  if (!beginRoot)
7951
7999
  return;
8000
+ if (opts.isShowUndefined)
8001
+ console.log(`U for undefined
8002
+ `);
8003
+ if (opts.isShowNull)
8004
+ console.log(`N for null
8005
+ `);
8006
+ if (opts.isShowRedBlackNIL)
8007
+ console.log(`S for Sentinel Node
8008
+ `);
7952
8009
  const display = (root) => {
7953
- const [lines, , ,] = this._displayAux(root);
8010
+ const [lines, , ,] = this._displayAux(root, opts);
7954
8011
  for (const line of lines) {
7955
8012
  console.log(line);
7956
8013
  }
7957
8014
  };
7958
8015
  display(beginRoot);
7959
8016
  }
7960
- _displayAux(node) {
7961
- if (!node) {
7962
- return [["\u2500"], 1, 0, 0];
7963
- }
7964
- const line = node.key.toString();
7965
- const width = line.length;
7966
- if (!node.left && !node.right) {
7967
- return [[line], width, 1, Math.floor(width / 2)];
8017
+ _displayAux(node, options) {
8018
+ const { isShowNull, isShowUndefined, isShowRedBlackNIL } = options;
8019
+ const emptyDisplayLayout = [["\u2500"], 1, 0, 0];
8020
+ if (node === null && !isShowNull) {
8021
+ return emptyDisplayLayout;
8022
+ } else if (node === void 0 && !isShowUndefined) {
8023
+ return emptyDisplayLayout;
8024
+ } else if (node !== null && node !== void 0 && isNaN(node.key) && !isShowRedBlackNIL) {
8025
+ return emptyDisplayLayout;
8026
+ } else if (node !== null && node !== void 0) {
8027
+ const key = node.key, line = isNaN(key) ? "S" : key.toString(), width = line.length;
8028
+ return _buildNodeDisplay(line, width, this._displayAux(node.left, options), this._displayAux(node.right, options));
8029
+ } else {
8030
+ const line = node === void 0 ? "U" : "N", width = line.length;
8031
+ return _buildNodeDisplay(line, width, [[""], 1, 0, 0], [[""], 1, 0, 0]);
7968
8032
  }
7969
- const [leftLines, leftWidth, leftHeight, leftMiddle] = node.left ? this._displayAux(node.left) : [[""], 0, 0, 0];
7970
- const [rightLines, rightWidth, rightHeight, rightMiddle] = node.right ? this._displayAux(node.right) : [[""], 0, 0, 0];
7971
- const firstLine = " ".repeat(Math.max(0, leftMiddle + 1)) + "_".repeat(Math.max(0, leftWidth - leftMiddle - 1)) + line + "_".repeat(Math.max(0, rightMiddle)) + " ".repeat(Math.max(0, rightWidth - rightMiddle));
7972
- const secondLine = (leftHeight > 0 ? " ".repeat(leftMiddle) + "/" + " ".repeat(leftWidth - leftMiddle - 1) : " ".repeat(leftWidth)) + " ".repeat(width) + (rightHeight > 0 ? " ".repeat(rightMiddle) + "\\" + " ".repeat(rightWidth - rightMiddle - 1) : " ".repeat(rightWidth));
7973
- const mergedLines = [firstLine, secondLine];
7974
- for (let i = 0; i < Math.max(leftHeight, rightHeight); i++) {
7975
- const leftLine = i < leftHeight ? leftLines[i] : " ".repeat(leftWidth);
7976
- const rightLine = i < rightHeight ? rightLines[i] : " ".repeat(rightWidth);
7977
- mergedLines.push(leftLine + " ".repeat(width) + rightLine);
8033
+ function _buildNodeDisplay(line, width, left, right) {
8034
+ const [leftLines, leftWidth, leftHeight, leftMiddle] = left;
8035
+ const [rightLines, rightWidth, rightHeight, rightMiddle] = right;
8036
+ const firstLine = " ".repeat(Math.max(0, leftMiddle + 1)) + "_".repeat(Math.max(0, leftWidth - leftMiddle - 1)) + line + "_".repeat(Math.max(0, rightMiddle)) + " ".repeat(Math.max(0, rightWidth - rightMiddle));
8037
+ const secondLine = (leftHeight > 0 ? " ".repeat(leftMiddle) + "/" + " ".repeat(leftWidth - leftMiddle - 1) : " ".repeat(leftWidth)) + " ".repeat(width) + (rightHeight > 0 ? " ".repeat(rightMiddle) + "\\" + " ".repeat(rightWidth - rightMiddle - 1) : " ".repeat(rightWidth));
8038
+ const mergedLines = [firstLine, secondLine];
8039
+ for (let i = 0; i < Math.max(leftHeight, rightHeight); i++) {
8040
+ const leftLine = i < leftHeight ? leftLines[i] : " ".repeat(leftWidth);
8041
+ const rightLine = i < rightHeight ? rightLines[i] : " ".repeat(rightWidth);
8042
+ mergedLines.push(leftLine + " ".repeat(width) + rightLine);
8043
+ }
8044
+ return [mergedLines, leftWidth + width + rightWidth, Math.max(leftHeight, rightHeight) + 2, leftWidth + Math.floor(width / 2)];
7978
8045
  }
7979
- return [mergedLines, leftWidth + width + rightWidth, Math.max(leftHeight, rightHeight) + 2, leftWidth + Math.floor(width / 2)];
7980
8046
  }
7981
8047
  /**
7982
8048
  * Swap the data of two nodes in the binary tree.
@@ -8092,7 +8158,7 @@ var dataStructureTyped = (() => {
8092
8158
  this._right = v;
8093
8159
  }
8094
8160
  };
8095
- var BST = class extends BinaryTree {
8161
+ var BST = class _BST extends BinaryTree {
8096
8162
  /**
8097
8163
  * The constructor function initializes a binary search tree with an optional comparator function.
8098
8164
  * @param {BSTOptions} [options] - An optional object that contains additional configuration options
@@ -8100,15 +8166,14 @@ var dataStructureTyped = (() => {
8100
8166
  */
8101
8167
  constructor(options) {
8102
8168
  super(options);
8169
+ __publicField(this, "options");
8103
8170
  __publicField(this, "_root");
8104
- __publicField(this, "_comparator", (a, b) => a - b);
8105
- this._root = void 0;
8106
- if (options !== void 0) {
8107
- const { comparator } = options;
8108
- if (comparator !== void 0) {
8109
- this._comparator = comparator;
8110
- }
8171
+ if (options) {
8172
+ this.options = __spreadValues({ iterationType: "ITERATIVE" /* ITERATIVE */, comparator: (a, b) => a - b }, options);
8173
+ } else {
8174
+ this.options = { iterationType: "ITERATIVE" /* ITERATIVE */, comparator: (a, b) => a - b };
8111
8175
  }
8176
+ this._root = void 0;
8112
8177
  }
8113
8178
  /**
8114
8179
  * Get the root node of the binary tree.
@@ -8127,6 +8192,9 @@ var dataStructureTyped = (() => {
8127
8192
  createNode(key, value) {
8128
8193
  return new BSTNode(key, value);
8129
8194
  }
8195
+ createTree(options) {
8196
+ return new _BST(__spreadValues(__spreadValues({}, this.options), options));
8197
+ }
8130
8198
  /**
8131
8199
  * Time Complexity: O(log n) - Average case for a balanced tree. In the worst case (unbalanced tree), it can be O(n).
8132
8200
  * Space Complexity: O(1) - Constant space is used.
@@ -8228,7 +8296,7 @@ var dataStructureTyped = (() => {
8228
8296
  * current instance of the binary search tree
8229
8297
  * @returns The function `addMany` returns an array of nodes (`N`) or `undefined` values.
8230
8298
  */
8231
- addMany(keysOrNodes, data, isBalanceAdd = true, iterationType = this.iterationType) {
8299
+ addMany(keysOrNodes, data, isBalanceAdd = true, iterationType = this.options.iterationType) {
8232
8300
  function hasNoUndefined(arr) {
8233
8301
  return arr.indexOf(void 0) === -1;
8234
8302
  }
@@ -8314,7 +8382,7 @@ var dataStructureTyped = (() => {
8314
8382
  * the key of the leftmost node if the comparison result is greater than, and the key of the
8315
8383
  * rightmost node otherwise. If no node is found, it returns 0.
8316
8384
  */
8317
- lastKey(beginRoot = this.root, iterationType = this.iterationType) {
8385
+ lastKey(beginRoot = this.root, iterationType = this.options.iterationType) {
8318
8386
  var _a, _b, _c, _d, _e, _f;
8319
8387
  if (this._compare(0, 1) === "lt" /* lt */)
8320
8388
  return (_b = (_a = this.getRightMost(beginRoot, iterationType)) == null ? void 0 : _a.key) != null ? _b : 0;
@@ -8410,7 +8478,7 @@ var dataStructureTyped = (() => {
8410
8478
  * performed on the binary tree. It can have two possible values:
8411
8479
  * @returns The method returns an array of nodes (`N[]`).
8412
8480
  */
8413
- getNodes(identifier, callback = this._defaultOneParamCallback, onlyOne = false, beginRoot = this.root, iterationType = this.iterationType) {
8481
+ getNodes(identifier, callback = this._defaultOneParamCallback, onlyOne = false, beginRoot = this.root, iterationType = this.options.iterationType) {
8414
8482
  beginRoot = this.ensureNotKey(beginRoot);
8415
8483
  if (!beginRoot)
8416
8484
  return [];
@@ -8486,7 +8554,7 @@ var dataStructureTyped = (() => {
8486
8554
  * @returns The function `lesserOrGreaterTraverse` returns an array of values of type
8487
8555
  * `ReturnType<C>`, which is the return type of the callback function passed as an argument.
8488
8556
  */
8489
- lesserOrGreaterTraverse(callback = this._defaultOneParamCallback, lesserOrGreater = "lt" /* lt */, targetNode = this.root, iterationType = this.iterationType) {
8557
+ lesserOrGreaterTraverse(callback = this._defaultOneParamCallback, lesserOrGreater = "lt" /* lt */, targetNode = this.root, iterationType = this.options.iterationType) {
8490
8558
  targetNode = this.ensureNotKey(targetNode);
8491
8559
  const ans = [];
8492
8560
  if (!targetNode)
@@ -8549,7 +8617,7 @@ var dataStructureTyped = (() => {
8549
8617
  * values:
8550
8618
  * @returns The function `perfectlyBalance` returns a boolean value.
8551
8619
  */
8552
- perfectlyBalance(iterationType = this.iterationType) {
8620
+ perfectlyBalance(iterationType = this.options.iterationType) {
8553
8621
  const sorted = this.dfs((node) => node, "in"), n = sorted.length;
8554
8622
  this.clear();
8555
8623
  if (sorted.length < 1)
@@ -8598,7 +8666,7 @@ var dataStructureTyped = (() => {
8598
8666
  * to check if the AVL tree is balanced. It can have two possible values:
8599
8667
  * @returns a boolean value.
8600
8668
  */
8601
- isAVLBalanced(iterationType = this.iterationType) {
8669
+ isAVLBalanced(iterationType = this.options.iterationType) {
8602
8670
  var _a, _b;
8603
8671
  if (!this.root)
8604
8672
  return true;
@@ -8656,7 +8724,7 @@ var dataStructureTyped = (() => {
8656
8724
  * than), CP.lt (less than), or CP.eq (equal).
8657
8725
  */
8658
8726
  _compare(a, b) {
8659
- const compared = this._comparator(a, b);
8727
+ const compared = this.options.comparator(a, b);
8660
8728
  if (compared > 0)
8661
8729
  return "gt" /* gt */;
8662
8730
  else if (compared < 0)
@@ -9100,7 +9168,7 @@ var dataStructureTyped = (() => {
9100
9168
  this.height = 0;
9101
9169
  }
9102
9170
  };
9103
- var AVLTree = class extends BST {
9171
+ var AVLTree = class _AVLTree extends BST {
9104
9172
  /**
9105
9173
  * This is a constructor function for an AVL tree data structure in TypeScript.
9106
9174
  * @param {AVLTreeOptions} [options] - The `options` parameter is an optional object that can be passed to the
@@ -9109,6 +9177,12 @@ var dataStructureTyped = (() => {
9109
9177
  */
9110
9178
  constructor(options) {
9111
9179
  super(options);
9180
+ __publicField(this, "options");
9181
+ if (options) {
9182
+ this.options = __spreadValues({ iterationType: "ITERATIVE" /* ITERATIVE */, comparator: (a, b) => a - b }, options);
9183
+ } else {
9184
+ this.options = { iterationType: "ITERATIVE" /* ITERATIVE */, comparator: (a, b) => a - b };
9185
+ }
9112
9186
  }
9113
9187
  /**
9114
9188
  * The function creates a new AVL tree node with the specified key and value.
@@ -9122,6 +9196,9 @@ var dataStructureTyped = (() => {
9122
9196
  createNode(key, value) {
9123
9197
  return new AVLTreeNode(key, value);
9124
9198
  }
9199
+ createTree(options) {
9200
+ return new _AVLTree(__spreadValues(__spreadValues({}, this.options), options));
9201
+ }
9125
9202
  /**
9126
9203
  * Time Complexity: O(log n) - logarithmic time, where "n" is the number of nodes in the tree. The add method of the superclass (BST) has logarithmic time complexity.
9127
9204
  * Space Complexity: O(1) - constant space, as it doesn't use additional data structures that scale with input size.
@@ -9485,7 +9562,7 @@ var dataStructureTyped = (() => {
9485
9562
  this.color = color;
9486
9563
  }
9487
9564
  };
9488
- var RedBlackTree = class extends BST {
9565
+ var RedBlackTree = class _RedBlackTree extends BST {
9489
9566
  /**
9490
9567
  * The constructor function initializes a Red-Black Tree with an optional set of options.
9491
9568
  * @param {RBTreeOptions} [options] - The `options` parameter is an optional object that can be
@@ -9493,10 +9570,16 @@ var dataStructureTyped = (() => {
9493
9570
  */
9494
9571
  constructor(options) {
9495
9572
  super(options);
9496
- __publicField(this, "NIL", new RedBlackTreeNode(NaN));
9573
+ __publicField(this, "Sentinel", new RedBlackTreeNode(NaN));
9574
+ __publicField(this, "options");
9497
9575
  __publicField(this, "_root");
9498
9576
  __publicField(this, "_size", 0);
9499
- this._root = this.NIL;
9577
+ if (options) {
9578
+ this.options = __spreadValues({ iterationType: "ITERATIVE" /* ITERATIVE */, comparator: (a, b) => a - b }, options);
9579
+ } else {
9580
+ this.options = { iterationType: "ITERATIVE" /* ITERATIVE */, comparator: (a, b) => a - b };
9581
+ }
9582
+ this._root = this.Sentinel;
9500
9583
  }
9501
9584
  get root() {
9502
9585
  return this._root;
@@ -9504,6 +9587,12 @@ var dataStructureTyped = (() => {
9504
9587
  get size() {
9505
9588
  return this._size;
9506
9589
  }
9590
+ createNode(key, value, color = 0 /* BLACK */) {
9591
+ return new RedBlackTreeNode(key, value, color);
9592
+ }
9593
+ createTree(options) {
9594
+ return new _RedBlackTree(__spreadValues(__spreadValues({}, this.options), options));
9595
+ }
9507
9596
  /**
9508
9597
  * Time Complexity: O(log n) on average (where n is the number of nodes in the tree)
9509
9598
  * Space Complexity: O(1)
@@ -9532,11 +9621,11 @@ var dataStructureTyped = (() => {
9532
9621
  } else {
9533
9622
  return;
9534
9623
  }
9535
- node.left = this.NIL;
9536
- node.right = this.NIL;
9624
+ node.left = this.Sentinel;
9625
+ node.right = this.Sentinel;
9537
9626
  let y = void 0;
9538
9627
  let x = this.root;
9539
- while (x !== this.NIL) {
9628
+ while (x !== this.Sentinel) {
9540
9629
  y = x;
9541
9630
  if (x) {
9542
9631
  if (node.key < x.key) {
@@ -9568,9 +9657,6 @@ var dataStructureTyped = (() => {
9568
9657
  this._fixInsert(node);
9569
9658
  this._size++;
9570
9659
  }
9571
- createNode(key, value, color = 0 /* BLACK */) {
9572
- return new RedBlackTreeNode(key, value, color);
9573
- }
9574
9660
  /**
9575
9661
  * Time Complexity: O(log n) on average (where n is the number of nodes in the tree)
9576
9662
  * Space Complexity: O(1)
@@ -9595,9 +9681,9 @@ var dataStructureTyped = (() => {
9595
9681
  if (identifier === null)
9596
9682
  return ans;
9597
9683
  const helper = (node) => {
9598
- let z = this.NIL;
9684
+ let z = this.Sentinel;
9599
9685
  let x, y;
9600
- while (node !== this.NIL) {
9686
+ while (node !== this.Sentinel) {
9601
9687
  if (node && callback(node) === identifier) {
9602
9688
  z = node;
9603
9689
  }
@@ -9607,16 +9693,16 @@ var dataStructureTyped = (() => {
9607
9693
  node = node == null ? void 0 : node.left;
9608
9694
  }
9609
9695
  }
9610
- if (z === this.NIL) {
9696
+ if (z === this.Sentinel) {
9611
9697
  this._size--;
9612
9698
  return;
9613
9699
  }
9614
9700
  y = z;
9615
9701
  let yOriginalColor = y.color;
9616
- if (z.left === this.NIL) {
9702
+ if (z.left === this.Sentinel) {
9617
9703
  x = z.right;
9618
9704
  this._rbTransplant(z, z.right);
9619
- } else if (z.right === this.NIL) {
9705
+ } else if (z.right === this.Sentinel) {
9620
9706
  x = z.left;
9621
9707
  this._rbTransplant(z, z.left);
9622
9708
  } else {
@@ -9644,7 +9730,7 @@ var dataStructureTyped = (() => {
9644
9730
  return ans;
9645
9731
  }
9646
9732
  isRealNode(node) {
9647
- return node !== this.NIL && node !== void 0;
9733
+ return node !== this.Sentinel && node !== void 0;
9648
9734
  }
9649
9735
  /**
9650
9736
  * Time Complexity: O(log n) on average (where n is the number of nodes in the tree)
@@ -9671,7 +9757,7 @@ var dataStructureTyped = (() => {
9671
9757
  * `getNodes` method, which is called within the `getNode` method.
9672
9758
  * @returns a value of type `N`, `null`, or `undefined`.
9673
9759
  */
9674
- getNode(identifier, callback = this._defaultOneParamCallback, beginRoot = this.root, iterationType = this.iterationType) {
9760
+ getNode(identifier, callback = this._defaultOneParamCallback, beginRoot = this.root, iterationType = this.options.iterationType) {
9675
9761
  var _a;
9676
9762
  if (identifier instanceof BinaryTreeNode)
9677
9763
  callback = (node) => node;
@@ -9692,11 +9778,11 @@ var dataStructureTyped = (() => {
9692
9778
  */
9693
9779
  getSuccessor(x) {
9694
9780
  var _a;
9695
- if (x.right !== this.NIL) {
9781
+ if (x.right !== this.Sentinel) {
9696
9782
  return (_a = this.getLeftMost(x.right)) != null ? _a : void 0;
9697
9783
  }
9698
9784
  let y = x.parent;
9699
- while (y !== this.NIL && y !== void 0 && x === y.right) {
9785
+ while (y !== this.Sentinel && y !== void 0 && x === y.right) {
9700
9786
  x = y;
9701
9787
  y = y.parent;
9702
9788
  }
@@ -9716,18 +9802,18 @@ var dataStructureTyped = (() => {
9716
9802
  * @returns the predecessor of the given RedBlackTreeNode 'x'.
9717
9803
  */
9718
9804
  getPredecessor(x) {
9719
- if (x.left !== this.NIL) {
9805
+ if (x.left !== this.Sentinel) {
9720
9806
  return this.getRightMost(x.left);
9721
9807
  }
9722
9808
  let y = x.parent;
9723
- while (y !== this.NIL && x === y.left) {
9809
+ while (y !== this.Sentinel && x === y.left) {
9724
9810
  x = y;
9725
9811
  y = y.parent;
9726
9812
  }
9727
9813
  return y;
9728
9814
  }
9729
9815
  clear() {
9730
- this._root = this.NIL;
9816
+ this._root = this.Sentinel;
9731
9817
  this._size = 0;
9732
9818
  }
9733
9819
  _setRoot(v) {
@@ -9751,7 +9837,7 @@ var dataStructureTyped = (() => {
9751
9837
  if (x.right) {
9752
9838
  const y = x.right;
9753
9839
  x.right = y.left;
9754
- if (y.left !== this.NIL) {
9840
+ if (y.left !== this.Sentinel) {
9755
9841
  if (y.left)
9756
9842
  y.left.parent = x;
9757
9843
  }
@@ -9783,7 +9869,7 @@ var dataStructureTyped = (() => {
9783
9869
  if (x.left) {
9784
9870
  const y = x.left;
9785
9871
  x.left = y.right;
9786
- if (y.right !== this.NIL) {
9872
+ if (y.right !== this.Sentinel) {
9787
9873
  if (y.right)
9788
9874
  y.right.parent = x;
9789
9875
  }
@@ -9967,16 +10053,22 @@ var dataStructureTyped = (() => {
9967
10053
  this.count = count;
9968
10054
  }
9969
10055
  };
9970
- var TreeMultimap = class extends AVLTree {
10056
+ var TreeMultimap = class _TreeMultimap extends AVLTree {
9971
10057
  /**
9972
10058
  * The constructor function for a TreeMultimap class in TypeScript, which extends another class and sets an option to
9973
10059
  * merge duplicated values.
9974
10060
  * @param {TreeMultimapOptions} [options] - An optional object that contains additional configuration options for the
9975
10061
  * TreeMultimap.
9976
10062
  */
9977
- constructor(options) {
10063
+ constructor(options = { iterationType: "ITERATIVE" /* ITERATIVE */ }) {
9978
10064
  super(options);
10065
+ __publicField(this, "options");
9979
10066
  __publicField(this, "_count", 0);
10067
+ if (options) {
10068
+ this.options = __spreadValues({ iterationType: "ITERATIVE" /* ITERATIVE */, comparator: (a, b) => a - b }, options);
10069
+ } else {
10070
+ this.options = { iterationType: "ITERATIVE" /* ITERATIVE */, comparator: (a, b) => a - b };
10071
+ }
9980
10072
  }
9981
10073
  get count() {
9982
10074
  return this._count;
@@ -9993,6 +10085,9 @@ var dataStructureTyped = (() => {
9993
10085
  createNode(key, value, count) {
9994
10086
  return new TreeMultimapNode(key, value, count);
9995
10087
  }
10088
+ createTree(options) {
10089
+ return new _TreeMultimap(__spreadValues(__spreadValues({}, this.options), options));
10090
+ }
9996
10091
  /**
9997
10092
  * Time Complexity: O(log n) - logarithmic time, where "n" is the number of nodes in the tree. The add method of the superclass (AVLTree) has logarithmic time complexity.
9998
10093
  * Space Complexity: O(1) - constant space, as it doesn't use additional data structures that scale with input size.
@@ -10122,7 +10217,7 @@ var dataStructureTyped = (() => {
10122
10217
  * values:
10123
10218
  * @returns a boolean value.
10124
10219
  */
10125
- perfectlyBalance(iterationType = this.iterationType) {
10220
+ perfectlyBalance(iterationType = this.options.iterationType) {
10126
10221
  const sorted = this.dfs((node) => node, "in"), n = sorted.length;
10127
10222
  if (sorted.length < 1)
10128
10223
  return false;