data-structure-typed 1.51.8 → 1.51.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 (106) hide show
  1. package/CHANGELOG.md +1 -1
  2. package/README.md +13 -13
  3. package/benchmark/report.html +1 -37
  4. package/benchmark/report.json +13 -385
  5. package/dist/cjs/data-structures/binary-tree/avl-tree-multi-map.d.ts +104 -66
  6. package/dist/cjs/data-structures/binary-tree/avl-tree-multi-map.js +119 -87
  7. package/dist/cjs/data-structures/binary-tree/avl-tree-multi-map.js.map +1 -1
  8. package/dist/cjs/data-structures/binary-tree/avl-tree.d.ts +80 -60
  9. package/dist/cjs/data-structures/binary-tree/avl-tree.js +78 -59
  10. package/dist/cjs/data-structures/binary-tree/avl-tree.js.map +1 -1
  11. package/dist/cjs/data-structures/binary-tree/binary-tree.d.ts +316 -224
  12. package/dist/cjs/data-structures/binary-tree/binary-tree.js +471 -361
  13. package/dist/cjs/data-structures/binary-tree/binary-tree.js.map +1 -1
  14. package/dist/cjs/data-structures/binary-tree/bst.d.ts +198 -200
  15. package/dist/cjs/data-structures/binary-tree/bst.js +215 -249
  16. package/dist/cjs/data-structures/binary-tree/bst.js.map +1 -1
  17. package/dist/cjs/data-structures/binary-tree/rb-tree.d.ts +71 -72
  18. package/dist/cjs/data-structures/binary-tree/rb-tree.js +107 -98
  19. package/dist/cjs/data-structures/binary-tree/rb-tree.js.map +1 -1
  20. package/dist/cjs/data-structures/binary-tree/tree-multi-map.d.ts +90 -73
  21. package/dist/cjs/data-structures/binary-tree/tree-multi-map.js +105 -93
  22. package/dist/cjs/data-structures/binary-tree/tree-multi-map.js.map +1 -1
  23. package/dist/cjs/data-structures/graph/abstract-graph.d.ts +10 -15
  24. package/dist/cjs/data-structures/graph/abstract-graph.js +10 -15
  25. package/dist/cjs/data-structures/graph/abstract-graph.js.map +1 -1
  26. package/dist/cjs/data-structures/hash/hash-map.d.ts +31 -38
  27. package/dist/cjs/data-structures/hash/hash-map.js +40 -55
  28. package/dist/cjs/data-structures/hash/hash-map.js.map +1 -1
  29. package/dist/cjs/data-structures/queue/deque.d.ts +2 -3
  30. package/dist/cjs/data-structures/queue/deque.js +2 -3
  31. package/dist/cjs/data-structures/queue/deque.js.map +1 -1
  32. package/dist/cjs/data-structures/queue/queue.js.map +1 -1
  33. package/dist/cjs/data-structures/trie/trie.d.ts +1 -1
  34. package/dist/cjs/data-structures/trie/trie.js +1 -1
  35. package/dist/cjs/data-structures/trie/trie.js.map +1 -1
  36. package/dist/cjs/interfaces/binary-tree.d.ts +6 -6
  37. package/dist/cjs/types/common.d.ts +1 -2
  38. package/dist/cjs/types/data-structures/binary-tree/avl-tree-multi-map.d.ts +2 -2
  39. package/dist/cjs/types/data-structures/binary-tree/avl-tree.d.ts +2 -2
  40. package/dist/cjs/types/data-structures/binary-tree/binary-tree.d.ts +5 -4
  41. package/dist/cjs/types/data-structures/binary-tree/bst.d.ts +4 -4
  42. package/dist/cjs/types/data-structures/binary-tree/rb-tree.d.ts +2 -2
  43. package/dist/cjs/types/data-structures/binary-tree/tree-multi-map.d.ts +3 -3
  44. package/dist/cjs/utils/utils.js +3 -5
  45. package/dist/cjs/utils/utils.js.map +1 -1
  46. package/dist/mjs/data-structures/binary-tree/avl-tree-multi-map.d.ts +104 -66
  47. package/dist/mjs/data-structures/binary-tree/avl-tree-multi-map.js +119 -87
  48. package/dist/mjs/data-structures/binary-tree/avl-tree.d.ts +80 -60
  49. package/dist/mjs/data-structures/binary-tree/avl-tree.js +78 -59
  50. package/dist/mjs/data-structures/binary-tree/binary-tree.d.ts +316 -224
  51. package/dist/mjs/data-structures/binary-tree/binary-tree.js +472 -362
  52. package/dist/mjs/data-structures/binary-tree/bst.d.ts +198 -200
  53. package/dist/mjs/data-structures/binary-tree/bst.js +219 -255
  54. package/dist/mjs/data-structures/binary-tree/rb-tree.d.ts +71 -72
  55. package/dist/mjs/data-structures/binary-tree/rb-tree.js +107 -98
  56. package/dist/mjs/data-structures/binary-tree/tree-multi-map.d.ts +90 -73
  57. package/dist/mjs/data-structures/binary-tree/tree-multi-map.js +105 -93
  58. package/dist/mjs/data-structures/graph/abstract-graph.d.ts +10 -15
  59. package/dist/mjs/data-structures/graph/abstract-graph.js +10 -15
  60. package/dist/mjs/data-structures/hash/hash-map.d.ts +31 -38
  61. package/dist/mjs/data-structures/hash/hash-map.js +41 -55
  62. package/dist/mjs/data-structures/queue/deque.d.ts +2 -3
  63. package/dist/mjs/data-structures/queue/deque.js +2 -3
  64. package/dist/mjs/data-structures/trie/trie.d.ts +1 -1
  65. package/dist/mjs/data-structures/trie/trie.js +1 -1
  66. package/dist/mjs/interfaces/binary-tree.d.ts +6 -6
  67. package/dist/mjs/types/common.d.ts +1 -2
  68. package/dist/mjs/types/data-structures/binary-tree/avl-tree-multi-map.d.ts +2 -2
  69. package/dist/mjs/types/data-structures/binary-tree/avl-tree.d.ts +2 -2
  70. package/dist/mjs/types/data-structures/binary-tree/binary-tree.d.ts +5 -4
  71. package/dist/mjs/types/data-structures/binary-tree/bst.d.ts +4 -4
  72. package/dist/mjs/types/data-structures/binary-tree/rb-tree.d.ts +2 -2
  73. package/dist/mjs/types/data-structures/binary-tree/tree-multi-map.d.ts +3 -3
  74. package/dist/mjs/utils/utils.js +3 -5
  75. package/dist/umd/data-structure-typed.js +1340 -1181
  76. package/dist/umd/data-structure-typed.min.js +2 -2
  77. package/dist/umd/data-structure-typed.min.js.map +1 -1
  78. package/package.json +6 -6
  79. package/src/data-structures/binary-tree/avl-tree-multi-map.ts +142 -92
  80. package/src/data-structures/binary-tree/avl-tree.ts +94 -66
  81. package/src/data-structures/binary-tree/binary-tree.ts +530 -398
  82. package/src/data-structures/binary-tree/bst.ts +251 -270
  83. package/src/data-structures/binary-tree/rb-tree.ts +121 -100
  84. package/src/data-structures/binary-tree/tree-multi-map.ts +125 -99
  85. package/src/data-structures/graph/abstract-graph.ts +10 -10
  86. package/src/data-structures/hash/hash-map.ts +42 -49
  87. package/src/data-structures/queue/deque.ts +2 -2
  88. package/src/data-structures/queue/queue.ts +1 -1
  89. package/src/data-structures/trie/trie.ts +2 -2
  90. package/src/interfaces/binary-tree.ts +8 -7
  91. package/src/types/common.ts +1 -2
  92. package/src/types/data-structures/binary-tree/avl-tree-multi-map.ts +2 -2
  93. package/src/types/data-structures/binary-tree/avl-tree.ts +2 -2
  94. package/src/types/data-structures/binary-tree/binary-tree.ts +5 -4
  95. package/src/types/data-structures/binary-tree/bst.ts +4 -4
  96. package/src/types/data-structures/binary-tree/rb-tree.ts +2 -2
  97. package/src/types/data-structures/binary-tree/tree-multi-map.ts +3 -3
  98. package/src/utils/utils.ts +3 -3
  99. package/test/integration/avl-tree.test.ts +2 -2
  100. package/test/integration/bst.test.ts +3 -3
  101. package/test/integration/index.html +25 -11
  102. package/test/unit/data-structures/binary-tree/avl-tree-multi-map.test.ts +68 -0
  103. package/test/unit/data-structures/binary-tree/binary-tree.test.ts +56 -0
  104. package/test/unit/data-structures/graph/directed-graph.test.ts +2 -2
  105. package/test/utils/big-o.ts +12 -6
  106. package/tsconfig-base.json +1 -0
@@ -715,7 +715,7 @@ var dataStructureTyped = (() => {
715
715
  function isComparable(key) {
716
716
  const keyType = typeof key;
717
717
  if (keyType === "number")
718
- return isNaN(key);
718
+ return !isNaN(key);
719
719
  if (keyType === "string")
720
720
  return true;
721
721
  if (keyType === "bigint")
@@ -731,10 +731,6 @@ var dataStructureTyped = (() => {
731
731
  if (keyType === "object") {
732
732
  if (key === null)
733
733
  return true;
734
- if (typeof key.valueOf === "function")
735
- return isComparable(key.valueOf());
736
- if (typeof key.toString === "function")
737
- return isComparable(key.toString());
738
734
  return false;
739
735
  }
740
736
  return false;
@@ -752,23 +748,15 @@ var dataStructureTyped = (() => {
752
748
  /**
753
749
  * The constructor function initializes a HashMap object with an optional initial collection and
754
750
  * options.
755
- * @param rawCollection - The `rawCollection` parameter is an iterable collection of elements of type
751
+ * @param entryOrRawElements - The `entryOrRawElements` parameter is an iterable collection of elements of a type
756
752
  * `T`. It is an optional parameter and its default value is an empty array `[]`.
757
753
  * @param [options] - The `options` parameter is an optional object that can contain two properties:
758
754
  */
759
- constructor(rawCollection = [], options) {
755
+ constructor(entryOrRawElements = [], options) {
760
756
  super();
761
757
  __publicField(this, "_store", {});
762
758
  __publicField(this, "_objMap", /* @__PURE__ */ new Map());
763
- __publicField(this, "_toEntryFn", (rawElement) => {
764
- if (this.isEntry(rawElement)) {
765
- return rawElement;
766
- } else {
767
- throw new Error(
768
- "If the provided rawCollection does not adhere to the [key, value] type format, the toEntryFn in the constructor's options parameter needs to specified."
769
- );
770
- }
771
- });
759
+ __publicField(this, "_toEntryFn");
772
760
  __publicField(this, "_size", 0);
773
761
  __publicField(this, "_hashFn", (key) => String(key));
774
762
  if (options) {
@@ -780,8 +768,8 @@ var dataStructureTyped = (() => {
780
768
  this._toEntryFn = toEntryFn;
781
769
  }
782
770
  }
783
- if (rawCollection) {
784
- this.setMany(rawCollection);
771
+ if (entryOrRawElements) {
772
+ this.setMany(entryOrRawElements);
785
773
  }
786
774
  }
787
775
  /**
@@ -875,23 +863,24 @@ var dataStructureTyped = (() => {
875
863
  /**
876
864
  * The function `setMany` takes an iterable collection of objects, maps each object to a key-value
877
865
  * pair using a mapping function, and sets each key-value pair in the current object.
878
- * @param rawCollection - The `rawCollection` parameter is an iterable collection of elements of type
866
+ * @param entryOrRawElements - The `entryOrRawElements` parameter is an iterable collection of elements of a type
879
867
  * `T`.
880
868
  * @returns The `setMany` function is returning an array of booleans.
881
869
  */
882
- setMany(rawCollection) {
870
+ setMany(entryOrRawElements) {
883
871
  const results = [];
884
- for (const rawEle of rawCollection) {
872
+ for (const rawEle of entryOrRawElements) {
885
873
  let key, value;
886
874
  if (this.isEntry(rawEle)) {
887
875
  key = rawEle[0];
888
876
  value = rawEle[1];
889
- } else {
877
+ } else if (this.toEntryFn) {
890
878
  const item = this.toEntryFn(rawEle);
891
879
  key = item[0];
892
880
  value = item[1];
893
881
  }
894
- results.push(this.set(key, value));
882
+ if (key !== void 0 && value !== void 0)
883
+ results.push(this.set(key, value));
895
884
  }
896
885
  return results;
897
886
  }
@@ -1072,14 +1061,14 @@ var dataStructureTyped = (() => {
1072
1061
  var LinkedHashMap = class _LinkedHashMap extends IterableEntryBase {
1073
1062
  /**
1074
1063
  * The constructor initializes a LinkedHashMap object with an optional raw collection and options.
1075
- * @param rawCollection - The `rawCollection` parameter is an iterable collection of elements. It is
1064
+ * @param entryOrRawElements - The `entryOrRawElements` parameter is an iterable collection of elements. It is
1076
1065
  * used to initialize the HashMapLinked instance with key-value pairs. Each element in the
1077
- * `rawCollection` is converted to a key-value pair using the `toEntryFn` function (if provided) and
1066
+ * `entryOrRawElements` is converted to a key-value pair using the `toEntryFn` function (if provided) and
1078
1067
  * then added to the HashMap
1079
1068
  * @param [options] - The `options` parameter is an optional object that can contain the following
1080
1069
  * properties:
1081
1070
  */
1082
- constructor(rawCollection = [], options) {
1071
+ constructor(entryOrRawElements = [], options) {
1083
1072
  super();
1084
1073
  __publicField(this, "_sentinel");
1085
1074
  __publicField(this, "_hashFn", (key) => String(key));
@@ -1093,7 +1082,7 @@ var dataStructureTyped = (() => {
1093
1082
  return rawElement;
1094
1083
  } else {
1095
1084
  throw new Error(
1096
- "If the provided rawCollection does not adhere to the [key, value] type format, the toEntryFn in the constructor's options parameter needs to specified."
1085
+ "If the provided entryOrRawElements does not adhere to the [key, value] type format, the toEntryFn in the constructor's options parameter needs to specified."
1097
1086
  );
1098
1087
  }
1099
1088
  });
@@ -1110,8 +1099,8 @@ var dataStructureTyped = (() => {
1110
1099
  this._toEntryFn = toEntryFn;
1111
1100
  }
1112
1101
  }
1113
- if (rawCollection) {
1114
- for (const el of rawCollection) {
1102
+ if (entryOrRawElements) {
1103
+ for (const el of entryOrRawElements) {
1115
1104
  const [key, value] = this.toEntryFn(el);
1116
1105
  this.set(key, value);
1117
1106
  }
@@ -1150,7 +1139,7 @@ var dataStructureTyped = (() => {
1150
1139
  /**
1151
1140
  * The function returns the head node of a HashMapLinkedNode.
1152
1141
  * @returns The method `getHead()` is returning a `HashMapLinkedNode` object with key type `K` and
1153
- * value type `V | undefined`.
1142
+ * a value type `V | undefined`.
1154
1143
  */
1155
1144
  get head() {
1156
1145
  return this._head;
@@ -1286,13 +1275,13 @@ var dataStructureTyped = (() => {
1286
1275
  * The function `setMany` takes an iterable collection, converts each element into a key-value pair
1287
1276
  * using a provided function, and sets each key-value pair in the current object, returning an array
1288
1277
  * of booleans indicating the success of each set operation.
1289
- * @param rawCollection - The rawCollection parameter is an iterable collection of elements of type
1278
+ * @param entryOrRawElements - The entryOrRawElements parameter is an iterable collection of elements of type
1290
1279
  * R.
1291
1280
  * @returns The `setMany` function returns an array of booleans.
1292
1281
  */
1293
- setMany(rawCollection) {
1282
+ setMany(entryOrRawElements) {
1294
1283
  const results = [];
1295
- for (const rawEle of rawCollection) {
1284
+ for (const rawEle of entryOrRawElements) {
1296
1285
  const [key, value] = this.toEntryFn(rawEle);
1297
1286
  results.push(this.set(key, value));
1298
1287
  }
@@ -1342,21 +1331,20 @@ var dataStructureTyped = (() => {
1342
1331
  }
1343
1332
  }
1344
1333
  /**
1345
- * Time Complexity: O(n)
1346
- * Space Complexity: O(1)
1347
- * /
1348
-
1349
- /**
1350
- * Time Complexity: O(n)
1351
- * Space Complexity: O(1)
1352
- *
1353
- * The function `at` retrieves the key-value pair at a specified index in a linked list.
1354
- * @param {number} index - The index parameter is a number that represents the position of the
1355
- * element we want to retrieve from the data structure.
1356
- * @returns The method `at(index: number)` is returning an array containing the key-value pair at
1357
- * the specified index in the data structure. The key-value pair is represented as a tuple `[K, V]`,
1358
- * where `K` is the key and `V` is the value.
1359
- */
1334
+ * Time Complexity: O(n)
1335
+ * Space Complexity: O(1)
1336
+ */
1337
+ /**
1338
+ * Time Complexity: O(n)
1339
+ * Space Complexity: O(1)
1340
+ *
1341
+ * The function `at` retrieves the key-value pair at a specified index in a linked list.
1342
+ * @param {number} index - The index parameter is a number that represents the position of the
1343
+ * element we want to retrieve from the data structure.
1344
+ * @returns The method `at(index: number)` is returning an array containing the key-value pair at
1345
+ * the specified index in the data structure. The key-value pair is represented as a tuple `[K, V]`,
1346
+ * where `K` is the key and `V` is the value.
1347
+ */
1360
1348
  at(index) {
1361
1349
  rangeCheck(index, 0, this._size - 1);
1362
1350
  let node = this.head;
@@ -1366,20 +1354,19 @@ var dataStructureTyped = (() => {
1366
1354
  return node.value;
1367
1355
  }
1368
1356
  /**
1369
- * Time Complexity: O(1)
1370
- * Space Complexity: O(1)
1371
- * /
1372
-
1373
- /**
1374
- * Time Complexity: O(1)
1375
- * Space Complexity: O(1)
1376
- *
1377
- * The `delete` function removes a key-value pair from a map-like data structure.
1378
- * @param {K} key - The `key` parameter is the key that you want to delete from the data structure.
1379
- * It can be of any type, but typically it is a string or an object.
1380
- * @returns a boolean value. It returns `true` if the deletion was successful, and `false` if the key
1381
- * was not found.
1382
- */
1357
+ * Time Complexity: O(1)
1358
+ * Space Complexity: O(1)
1359
+ */
1360
+ /**
1361
+ * Time Complexity: O(1)
1362
+ * Space Complexity: O(1)
1363
+ *
1364
+ * The `delete` function removes a key-value pair from a map-like data structure.
1365
+ * @param {K} key - The `key` parameter is the key that you want to delete from the data structure.
1366
+ * It can be of any type, but typically it is a string or an object.
1367
+ * @returns a boolean value. It returns `true` if the deletion was successful, and `false` if the key
1368
+ * was not found.
1369
+ */
1383
1370
  delete(key) {
1384
1371
  let node;
1385
1372
  if (isWeakKey(key)) {
@@ -1401,19 +1388,18 @@ var dataStructureTyped = (() => {
1401
1388
  return true;
1402
1389
  }
1403
1390
  /**
1404
- * Time Complexity: O(n)
1405
- * Space Complexity: O(1)
1406
- * /
1407
-
1408
- /**
1409
- * Time Complexity: O(n)
1410
- * Space Complexity: O(1)
1411
- *
1412
- * The `deleteAt` function deletes a node at a specified index in a linked list.
1413
- * @param {number} index - The index parameter represents the position at which the node should be
1414
- * deleted in the linked list.
1415
- * @returns The size of the list after deleting the element at the specified index.
1416
- */
1391
+ * Time Complexity: O(n)
1392
+ * Space Complexity: O(1)
1393
+ */
1394
+ /**
1395
+ * Time Complexity: O(n)
1396
+ * Space Complexity: O(1)
1397
+ *
1398
+ * The `deleteAt` function deletes a node at a specified index in a linked list.
1399
+ * @param {number} index - The index parameter represents the position at which the node should be
1400
+ * deleted in the linked list.
1401
+ * @returns The size of the list after deleting the element at the specified index.
1402
+ */
1417
1403
  deleteAt(index) {
1418
1404
  rangeCheck(index, 0, this._size - 1);
1419
1405
  let node = this.head;
@@ -1423,18 +1409,17 @@ var dataStructureTyped = (() => {
1423
1409
  return this._deleteNode(node);
1424
1410
  }
1425
1411
  /**
1426
- * Time Complexity: O(1)
1427
- * Space Complexity: O(1)
1428
- * /
1429
-
1430
- /**
1431
- * Time Complexity: O(1)
1432
- * Space Complexity: O(1)
1433
- *
1434
- * The function checks if a data structure is empty by comparing its size to zero.
1435
- * @returns The method is returning a boolean value indicating whether the size of the object is 0 or
1436
- * not.
1437
- */
1412
+ * Time Complexity: O(1)
1413
+ * Space Complexity: O(1)
1414
+ */
1415
+ /**
1416
+ * Time Complexity: O(1)
1417
+ * Space Complexity: O(1)
1418
+ *
1419
+ * The function checks if a data structure is empty by comparing its size to zero.
1420
+ * @returns The method is returning a boolean value indicating whether the size of the object is 0 or
1421
+ * not.
1422
+ */
1438
1423
  isEmpty() {
1439
1424
  return this._size === 0;
1440
1425
  }
@@ -1448,16 +1433,15 @@ var dataStructureTyped = (() => {
1448
1433
  return Array.isArray(rawElement) && rawElement.length === 2;
1449
1434
  }
1450
1435
  /**
1451
- * Time Complexity: O(1)
1452
- * Space Complexity: O(1)
1453
- * /
1454
-
1455
- /**
1456
- * Time Complexity: O(1)
1457
- * Space Complexity: O(1)
1458
- *
1459
- * The `clear` function clears all the entries in a data structure and resets its properties.
1460
- */
1436
+ * Time Complexity: O(1)
1437
+ * Space Complexity: O(1)
1438
+ */
1439
+ /**
1440
+ * Time Complexity: O(1)
1441
+ * Space Complexity: O(1)
1442
+ *
1443
+ * The `clear` function clears all the entries in a data structure and resets its properties.
1444
+ */
1461
1445
  clear() {
1462
1446
  this._noObjMap = {};
1463
1447
  this._size = 0;
@@ -1485,25 +1469,24 @@ var dataStructureTyped = (() => {
1485
1469
  return cloned;
1486
1470
  }
1487
1471
  /**
1488
- * Time Complexity: O(n)
1489
- * Space Complexity: O(n)
1490
- * /
1491
-
1492
- /**
1493
- * Time Complexity: O(n)
1494
- * Space Complexity: O(n)
1495
- *
1496
- * The `filter` function creates a new `LinkedHashMap` containing key-value pairs from the original
1497
- * map that satisfy a given predicate function.
1498
- * @param predicate - The `predicate` parameter is a callback function that takes four arguments:
1499
- * `value`, `key`, `index`, and `this`. It should return a boolean value indicating whether the
1500
- * current element should be included in the filtered map or not.
1501
- * @param {any} [thisArg] - The `thisArg` parameter is an optional argument that allows you to
1502
- * specify the value of `this` within the `predicate` function. It is used when you want to bind a
1503
- * specific object as the context for the `predicate` function. If `thisArg` is not provided, `this
1504
- * @returns a new `LinkedHashMap` object that contains the key-value pairs from the original
1505
- * `LinkedHashMap` object that satisfy the given predicate function.
1506
- */
1472
+ * Time Complexity: O(n)
1473
+ * Space Complexity: O(n)
1474
+ */
1475
+ /**
1476
+ * Time Complexity: O(n)
1477
+ * Space Complexity: O(n)
1478
+ *
1479
+ * The `filter` function creates a new `LinkedHashMap` containing key-value pairs from the original
1480
+ * map that satisfy a given predicate function.
1481
+ * @param predicate - The `predicate` parameter is a callback function that takes four arguments:
1482
+ * `value`, `key`, `index`, and `this`. It should return a boolean value indicating whether the
1483
+ * current element should be included in the filtered map or not.
1484
+ * @param {any} [thisArg] - The `thisArg` parameter is an optional argument that allows you to
1485
+ * specify the value of `this` within the `predicate` function. It is used when you want to bind a
1486
+ * specific object as the context for the `predicate` function. If `thisArg` is not provided, `this
1487
+ * @returns a new `LinkedHashMap` object that contains the key-value pairs from the original
1488
+ * `LinkedHashMap` object that satisfy the given predicate function.
1489
+ */
1507
1490
  filter(predicate, thisArg) {
1508
1491
  const filteredMap = new _LinkedHashMap();
1509
1492
  let index = 0;
@@ -1516,27 +1499,26 @@ var dataStructureTyped = (() => {
1516
1499
  return filteredMap;
1517
1500
  }
1518
1501
  /**
1519
- * Time Complexity: O(n)
1520
- * Space Complexity: O(n)
1521
- * /
1522
-
1523
- /**
1524
- * Time Complexity: O(n)
1525
- * Space Complexity: O(n)
1526
- *
1527
- * The `map` function in TypeScript creates a new `LinkedHashMap` by applying a callback function to
1528
- * each key-value pair in the original map.
1529
- * @param callback - The callback parameter is a function that will be called for each key-value pair
1530
- * in the map. It takes four arguments: the value of the current key-value pair, the key of the
1531
- * current key-value pair, the index of the current key-value pair, and the map itself. The callback
1532
- * function should
1533
- * @param {any} [thisArg] - The `thisArg` parameter is an optional argument that allows you to
1534
- * specify the value of `this` within the callback function. If provided, the callback function will
1535
- * be called with `thisArg` as its `this` value. If not provided, `this` will refer to the current
1536
- * map
1537
- * @returns a new `LinkedHashMap` object with the values mapped according to the provided callback
1538
- * function.
1539
- */
1502
+ * Time Complexity: O(n)
1503
+ * Space Complexity: O(n)
1504
+ */
1505
+ /**
1506
+ * Time Complexity: O(n)
1507
+ * Space Complexity: O(n)
1508
+ *
1509
+ * The `map` function in TypeScript creates a new `LinkedHashMap` by applying a callback function to
1510
+ * each key-value pair in the original map.
1511
+ * @param callback - The callback parameter is a function that will be called for each key-value pair
1512
+ * in the map. It takes four arguments: the value of the current key-value pair, the key of the
1513
+ * current key-value pair, the index of the current key-value pair, and the map itself. The callback
1514
+ * function should
1515
+ * @param {any} [thisArg] - The `thisArg` parameter is an optional argument that allows you to
1516
+ * specify the value of `this` within the callback function. If provided, the callback function will
1517
+ * be called with `thisArg` as its `this` value. If not provided, `this` will refer to the current
1518
+ * map
1519
+ * @returns a new `LinkedHashMap` object with the values mapped according to the provided callback
1520
+ * function.
1521
+ */
1540
1522
  map(callback, thisArg) {
1541
1523
  const mappedMap = new _LinkedHashMap();
1542
1524
  let index = 0;
@@ -1566,18 +1548,17 @@ var dataStructureTyped = (() => {
1566
1548
  return this.set(key, value);
1567
1549
  }
1568
1550
  /**
1569
- * Time Complexity: O(n)
1570
- * Space Complexity: O(1)
1571
- * where n is the number of entries in the LinkedHashMap.
1572
- * /
1573
-
1574
- /**
1575
- * Time Complexity: O(n)
1576
- * Space Complexity: O(1)
1577
- * where n is the number of entries in the LinkedHashMap.
1578
- *
1579
- * The above function is an iterator that yields key-value pairs from a linked list.
1580
- */
1551
+ * Time Complexity: O(n)
1552
+ * Space Complexity: O(1)
1553
+ * where n is the number of entries in the LinkedHashMap.
1554
+ */
1555
+ /**
1556
+ * Time Complexity: O(n)
1557
+ * Space Complexity: O(1)
1558
+ * where n is the number of entries in the LinkedHashMap.
1559
+ *
1560
+ * The above function is an iterator that yields key-value pairs from a linked list.
1561
+ */
1581
1562
  *_getIterator() {
1582
1563
  let node = this.head;
1583
1564
  while (node !== this._sentinel) {
@@ -4580,17 +4561,16 @@ var dataStructureTyped = (() => {
4580
4561
  return newDeque;
4581
4562
  }
4582
4563
  /**
4583
- * Time Complexity: O(n)
4584
- * Space Complexity: O(1)
4585
- * /
4586
-
4587
- /**
4588
- * Time Complexity: O(n)
4589
- * Space Complexity: O(1)
4590
- *
4591
- * The above function is an implementation of the iterator protocol in TypeScript, allowing the
4592
- * object to be iterated over using a for...of loop.
4593
- */
4564
+ * Time Complexity: O(n)
4565
+ * Space Complexity: O(1)
4566
+ */
4567
+ /**
4568
+ * Time Complexity: O(n)
4569
+ * Space Complexity: O(1)
4570
+ *
4571
+ * The above function is an implementation of the iterator protocol in TypeScript, allowing the
4572
+ * object to be iterated over using a for...of loop.
4573
+ */
4594
4574
  *_getIterator() {
4595
4575
  for (let i = 0; i < this.size; ++i) {
4596
4576
  yield this.at(i);
@@ -5887,13 +5867,12 @@ var dataStructureTyped = (() => {
5887
5867
  }
5888
5868
  }
5889
5869
  /**
5890
- * Dijkstra algorithm time: O(VE) space: O(VO + EO)
5891
- * /
5892
-
5893
- /**
5894
- * Time Complexity: O(V^2 + E) - Quadratic time in the worst case (no heap optimization).
5895
- * Space Complexity: O(V + E) - Depends on the implementation (Dijkstra's algorithm).
5896
- */
5870
+ * Dijkstra algorithm time: O(VE) space: O(VO + EO)
5871
+ */
5872
+ /**
5873
+ * Time Complexity: O(V^2 + E) - Quadratic time in the worst case (no heap optimization).
5874
+ * Space Complexity: O(V + E) - Depends on the implementation (Dijkstra's algorithm).
5875
+ */
5897
5876
  /**
5898
5877
  * Time Complexity: O(V^2 + E) - Quadratic time in the worst case (no heap optimization).
5899
5878
  * Space Complexity: O(V + E) - Depends on the implementation (Dijkstra's algorithm).
@@ -6008,18 +5987,17 @@ var dataStructureTyped = (() => {
6008
5987
  return { distMap, preMap, seen, paths, minDist, minPath };
6009
5988
  }
6010
5989
  /**
6011
- * Dijkstra algorithm time: O(logVE) space: O(VO + EO)
6012
- *
6013
- * Dijkstra's algorithm only solves the single-source shortest path problem, while the Bellman-Ford algorithm and Floyd-Warshall algorithm can address shortest paths between all pairs of nodes.
6014
- * Dijkstra's algorithm is suitable for graphs with non-negative edge weights, whereas the Bellman-Ford algorithm and Floyd-Warshall algorithm can handle negative-weight edgeMap.
6015
- * The time complexity of Dijkstra's algorithm and the Bellman-Ford algorithm depends on the size of the graph, while the time complexity of the Floyd-Warshall algorithm is O(VO^3), where VO is the number of nodes. For dense graphs, Floyd-Warshall might become slower.
6016
- *
6017
- * /
6018
-
6019
- /**
6020
- * Time Complexity: O((V + E) * log(V)) - Depends on the implementation (using a binary heap).
6021
- * Space Complexity: O(V + E) - Depends on the implementation (using a binary heap).
6022
- */
5990
+ * Dijkstra algorithm time: O(logVE) space: O(VO + EO)
5991
+ *
5992
+ * Dijkstra's algorithm only solves the single-source shortest path problem, while the Bellman-Ford algorithm and Floyd-Warshall algorithm can address shortest paths between all pairs of nodes.
5993
+ * Dijkstra's algorithm is suitable for graphs with non-negative edge weights, whereas the Bellman-Ford algorithm and Floyd-Warshall algorithm can handle negative-weight edgeMap.
5994
+ * The time complexity of Dijkstra's algorithm and the Bellman-Ford algorithm depends on the size of the graph, while the time complexity of the Floyd-Warshall algorithm is O(VO^3), where VO is the number of nodes. For dense graphs, Floyd-Warshall might become slower.
5995
+ *
5996
+ */
5997
+ /**
5998
+ * Time Complexity: O((V + E) * log(V)) - Depends on the implementation (using a binary heap).
5999
+ * Space Complexity: O(V + E) - Depends on the implementation (using a binary heap).
6000
+ */
6023
6001
  /**
6024
6002
  * Time Complexity: O((V + E) * log(V)) - Depends on the implementation (using a binary heap).
6025
6003
  * Space Complexity: O(V + E) - Depends on the implementation (using a binary heap).
@@ -6132,29 +6110,28 @@ var dataStructureTyped = (() => {
6132
6110
  return { distMap, preMap, seen, paths, minDist, minPath };
6133
6111
  }
6134
6112
  /**
6135
- * Time Complexity: O(V * E) - Quadratic time in the worst case (Bellman-Ford algorithm).
6136
- * Space Complexity: O(V + E) - Depends on the implementation (Bellman-Ford algorithm).
6137
- * one to rest pairs
6138
- * /
6139
-
6140
- /**
6141
- * Time Complexity: O(V * E) - Quadratic time in the worst case (Bellman-Ford algorithm).
6142
- * Space Complexity: O(V + E) - Depends on the implementation (Bellman-Ford algorithm).
6143
- *
6144
- * one to rest pairs
6145
- * The Bellman-Ford algorithm is also used to find the shortest paths from a source node to all other nodes in a graph. Unlike Dijkstra's algorithm, it can handle edge weights that are negative. Its basic idea involves iterative relaxation of all edgeMap for several rounds to gradually approximate the shortest paths. Due to its ability to handle negative-weight edgeMap, the Bellman-Ford algorithm is more flexible in some scenarios.
6146
- * The `bellmanFord` function implements the Bellman-Ford algorithm to find the shortest path from a source vertex to
6147
- * all other vertexMap in a graph, and optionally detects negative cycles and generates the minimum path.
6148
- * @param {VO | VertexKey} src - The `src` parameter is the source vertex from which the Bellman-Ford algorithm will
6149
- * start calculating the shortest paths. It can be either a vertex object or a vertex ID.
6150
- * @param {boolean} [scanNegativeCycle] - A boolean flag indicating whether to scan for negative cycles in the graph.
6151
- * @param {boolean} [getMin] - The `getMin` parameter is a boolean flag that determines whether the algorithm should
6152
- * calculate the minimum distance from the source vertex to all other vertexMap in the graph. If `getMin` is set to
6153
- * `true`, the algorithm will find the minimum distance and update the `min` variable with the minimum
6154
- * @param {boolean} [genPath] - A boolean flag indicating whether to generate paths for all vertexMap from the source
6155
- * vertex.
6156
- * @returns The function `bellmanFord` returns an object with the following properties:
6157
- */
6113
+ * Time Complexity: O(V * E) - Quadratic time in the worst case (Bellman-Ford algorithm).
6114
+ * Space Complexity: O(V + E) - Depends on the implementation (Bellman-Ford algorithm).
6115
+ * one to rest pairs
6116
+ */
6117
+ /**
6118
+ * Time Complexity: O(V * E) - Quadratic time in the worst case (Bellman-Ford algorithm).
6119
+ * Space Complexity: O(V + E) - Depends on the implementation (Bellman-Ford algorithm).
6120
+ *
6121
+ * one to rest pairs
6122
+ * The Bellman-Ford algorithm is also used to find the shortest paths from a source node to all other nodes in a graph. Unlike Dijkstra's algorithm, it can handle edge weights that are negative. Its basic idea involves iterative relaxation of all edgeMap for several rounds to gradually approximate the shortest paths. Due to its ability to handle negative-weight edgeMap, the Bellman-Ford algorithm is more flexible in some scenarios.
6123
+ * The `bellmanFord` function implements the Bellman-Ford algorithm to find the shortest path from a source vertex to
6124
+ * all other vertexMap in a graph, and optionally detects negative cycles and generates the minimum path.
6125
+ * @param {VO | VertexKey} src - The `src` parameter is the source vertex from which the Bellman-Ford algorithm will
6126
+ * start calculating the shortest paths. It can be either a vertex object or a vertex ID.
6127
+ * @param {boolean} [scanNegativeCycle] - A boolean flag indicating whether to scan for negative cycles in the graph.
6128
+ * @param {boolean} [getMin] - The `getMin` parameter is a boolean flag that determines whether the algorithm should
6129
+ * calculate the minimum distance from the source vertex to all other vertexMap in the graph. If `getMin` is set to
6130
+ * `true`, the algorithm will find the minimum distance and update the `min` variable with the minimum
6131
+ * @param {boolean} [genPath] - A boolean flag indicating whether to generate paths for all vertexMap from the source
6132
+ * vertex.
6133
+ * @returns The function `bellmanFord` returns an object with the following properties:
6134
+ */
6158
6135
  bellmanFord(src, scanNegativeCycle, getMin, genPath) {
6159
6136
  if (getMin === void 0)
6160
6137
  getMin = false;
@@ -6240,13 +6217,12 @@ var dataStructureTyped = (() => {
6240
6217
  return { hasNegativeCycle, distMap, preMap, paths, min, minPath };
6241
6218
  }
6242
6219
  /**
6243
- * Dijkstra algorithm time: O(logVE) space: O(VO + EO)
6244
- * /
6245
-
6246
- /**
6247
- * Dijkstra algorithm time: O(logVE) space: O(VO + EO)
6248
- * Dijkstra's algorithm is used to find the shortest paths from a source node to all other nodes in a graph. Its basic idea is to repeatedly choose the node closest to the source node and update the distances of other nodes using this node as an intermediary. Dijkstra's algorithm requires that the edge weights in the graph are non-negative.
6249
- */
6220
+ * Dijkstra algorithm time: O(logVE) space: O(VO + EO)
6221
+ */
6222
+ /**
6223
+ * Dijkstra algorithm time: O(logVE) space: O(VO + EO)
6224
+ * Dijkstra's algorithm is used to find the shortest paths from a source node to all other nodes in a graph. Its basic idea is to repeatedly choose the node closest to the source node and update the distances of other nodes using this node as an intermediary. Dijkstra's algorithm requires that the edge weights in the graph are non-negative.
6225
+ */
6250
6226
  /**
6251
6227
  * BellmanFord time:O(VE) space:O(VO)
6252
6228
  * one to rest pairs
@@ -6254,27 +6230,26 @@ var dataStructureTyped = (() => {
6254
6230
  * The `bellmanFord` function implements the Bellman-Ford algorithm to find the shortest path from a source vertex to
6255
6231
  */
6256
6232
  /**
6257
- * Time Complexity: O(V^3) - Cubic time (Floyd-Warshall algorithm).
6258
- * Space Complexity: O(V^2) - Quadratic space (Floyd-Warshall algorithm).
6259
- * Not support graph with negative weight cycle
6260
- * all pairs
6261
- * The Floyd-Warshall algorithm is used to find the shortest paths between all pairs of nodes in a graph. It employs dynamic programming to compute the shortest paths from any node to any other node. The Floyd-Warshall algorithm's advantage lies in its ability to handle graphs with negative-weight edgeMap, and it can simultaneously compute shortest paths between any two nodes.
6262
- * /
6263
-
6264
- /**
6265
- * Time Complexity: O(V^3) - Cubic time (Floyd-Warshall algorithm).
6266
- * Space Complexity: O(V^2) - Quadratic space (Floyd-Warshall algorithm).
6267
- *
6268
- * Not support graph with negative weight cycle
6269
- * all pairs
6270
- * The Floyd-Warshall algorithm is used to find the shortest paths between all pairs of nodes in a graph. It employs dynamic programming to compute the shortest paths from any node to any other node. The Floyd-Warshall algorithm's advantage lies in its ability to handle graphs with negative-weight edgeMap, and it can simultaneously compute shortest paths between any two nodes.
6271
- * The function implements the Floyd-Warshall algorithm to find the shortest path between all pairs of vertexMap in a
6272
- * graph.
6273
- * @returns The function `floydWarshall()` returns an object with two properties: `costs` and `predecessor`. The `costs`
6274
- * property is a 2D array of numbers representing the shortest path costs between vertexMap in a graph. The
6275
- * `predecessor` property is a 2D array of vertexMap (or `undefined`) representing the predecessor vertexMap in the shortest
6276
- * path between vertexMap in the
6277
- */
6233
+ * Time Complexity: O(V^3) - Cubic time (Floyd-Warshall algorithm).
6234
+ * Space Complexity: O(V^2) - Quadratic space (Floyd-Warshall algorithm).
6235
+ * Not support graph with negative weight cycle
6236
+ * all pairs
6237
+ * The Floyd-Warshall algorithm is used to find the shortest paths between all pairs of nodes in a graph. It employs dynamic programming to compute the shortest paths from any node to any other node. The Floyd-Warshall algorithm's advantage lies in its ability to handle graphs with negative-weight edgeMap, and it can simultaneously compute shortest paths between any two nodes.
6238
+ */
6239
+ /**
6240
+ * Time Complexity: O(V^3) - Cubic time (Floyd-Warshall algorithm).
6241
+ * Space Complexity: O(V^2) - Quadratic space (Floyd-Warshall algorithm).
6242
+ *
6243
+ * Not support graph with negative weight cycle
6244
+ * all pairs
6245
+ * The Floyd-Warshall algorithm is used to find the shortest paths between all pairs of nodes in a graph. It employs dynamic programming to compute the shortest paths from any node to any other node. The Floyd-Warshall algorithm's advantage lies in its ability to handle graphs with negative-weight edgeMap, and it can simultaneously compute shortest paths between any two nodes.
6246
+ * The function implements the Floyd-Warshall algorithm to find the shortest path between all pairs of vertexMap in a
6247
+ * graph.
6248
+ * @returns The function `floydWarshall()` returns an object with two properties: `costs` and `predecessor`. The `costs`
6249
+ * property is a 2D array of numbers representing the shortest path costs between vertexMap in a graph. The
6250
+ * `predecessor` property is a 2D array of vertexMap (or `undefined`) representing the predecessor vertexMap in the shortest
6251
+ * path between vertexMap in the
6252
+ */
6278
6253
  floydWarshall() {
6279
6254
  var _a;
6280
6255
  const idAndVertices = [...this._vertexMap];
@@ -7762,29 +7737,31 @@ var dataStructureTyped = (() => {
7762
7737
  };
7763
7738
  var BinaryTree = class _BinaryTree extends IterableEntryBase {
7764
7739
  /**
7765
- * The constructor function initializes a binary tree object with optional keysOrNodesOrEntries and options.
7766
- * @param [keysOrNodesOrEntries] - An optional iterable of KeyOrNodeOrEntry objects. These objects represent the
7740
+ * The constructor function initializes a binary tree object with optional keysOrNodesOrEntriesOrRawElements and options.
7741
+ * @param [keysOrNodesOrEntriesOrRawElements] - An optional iterable of KeyOrNodeOrEntry objects. These objects represent the
7767
7742
  * nodes to be added to the binary tree.
7768
7743
  * @param [options] - The `options` parameter is an optional object that can contain additional
7769
7744
  * configuration options for the binary tree. In this case, it is of type
7770
7745
  * `Partial<BinaryTreeOptions>`, which means that not all properties of `BinaryTreeOptions` are
7771
7746
  * required.
7772
7747
  */
7773
- constructor(keysOrNodesOrEntries = [], options) {
7748
+ constructor(keysOrNodesOrEntriesOrRawElements = [], options) {
7774
7749
  super();
7775
7750
  __publicField(this, "iterationType", "ITERATIVE");
7776
7751
  __publicField(this, "_root");
7777
- __publicField(this, "_size");
7752
+ __publicField(this, "_size", 0);
7778
7753
  __publicField(this, "_NIL", new BinaryTreeNode(NaN));
7754
+ __publicField(this, "_toEntryFn");
7779
7755
  __publicField(this, "_DEFAULT_CALLBACK", (node) => node ? node.key : void 0);
7780
7756
  if (options) {
7781
- const { iterationType } = options;
7757
+ const { iterationType, toEntryFn } = options;
7782
7758
  if (iterationType)
7783
7759
  this.iterationType = iterationType;
7760
+ if (typeof toEntryFn === "function")
7761
+ this._toEntryFn = toEntryFn;
7784
7762
  }
7785
- this._size = 0;
7786
- if (keysOrNodesOrEntries)
7787
- this.addMany(keysOrNodesOrEntries);
7763
+ if (keysOrNodesOrEntriesOrRawElements)
7764
+ this.addMany(keysOrNodesOrEntriesOrRawElements);
7788
7765
  }
7789
7766
  /**
7790
7767
  * The function returns the root node, which can be of type NODE, null, or undefined.
@@ -7808,6 +7785,13 @@ var dataStructureTyped = (() => {
7808
7785
  get NIL() {
7809
7786
  return this._NIL;
7810
7787
  }
7788
+ /**
7789
+ * The function returns the value of the _toEntryFn property.
7790
+ * @returns The function being returned is `this._toEntryFn`.
7791
+ */
7792
+ get toEntryFn() {
7793
+ return this._toEntryFn;
7794
+ }
7811
7795
  /**
7812
7796
  * Creates a new instance of BinaryTreeNode with the given key and value.
7813
7797
  * @param {K} key - The key for the new node.
@@ -7828,36 +7812,42 @@ var dataStructureTyped = (() => {
7828
7812
  return new _BinaryTree([], __spreadValues({ iterationType: this.iterationType }, options));
7829
7813
  }
7830
7814
  /**
7831
- * The function `keyValueOrEntryToNode` converts an keyOrNodeOrEntry object into a node object.
7832
- * @param keyOrNodeOrEntry - The `keyOrNodeOrEntry` parameter is of type `KeyOrNodeOrEntry<K, V, NODE>`.
7815
+ * The function `keyValueOrEntryOrRawElementToNode` converts a key-value pair, entry, or raw element
7816
+ * into a node object.
7817
+ * @param {R | KeyOrNodeOrEntry<K, V, NODE>} keyOrNodeOrEntryOrRawElement - The parameter
7818
+ * `keyOrNodeOrEntryOrRawElement` can be of type `R` or `KeyOrNodeOrEntry<K, V, NODE>`.
7833
7819
  * @param {V} [value] - The `value` parameter is an optional value that can be passed to the
7834
- * `keyValueOrEntryToNode` function. It represents the value associated with the keyOrNodeOrEntry node. If no value
7835
- * is provided, it will be `undefined`.
7836
- * @returns a value of type NODE (node), or null, or undefined.
7820
+ * `keyValueOrEntryOrRawElementToNode` function. It represents the value associated with a key in a
7821
+ * key-value pair. If provided, it will be used to create a node with the specified key and value.
7822
+ * @returns The function `keyValueOrEntryOrRawElementToNode` returns either a `NODE` object, `null`,
7823
+ * or `undefined`.
7837
7824
  */
7838
- keyValueOrEntryToNode(keyOrNodeOrEntry, value) {
7839
- if (keyOrNodeOrEntry === void 0)
7825
+ keyValueOrEntryOrRawElementToNode(keyOrNodeOrEntryOrRawElement, value) {
7826
+ if (keyOrNodeOrEntryOrRawElement === void 0)
7840
7827
  return;
7841
- let node;
7842
- if (keyOrNodeOrEntry === null) {
7843
- node = null;
7844
- } else if (this.isEntry(keyOrNodeOrEntry)) {
7845
- const [key, value2] = keyOrNodeOrEntry;
7846
- if (key === void 0) {
7828
+ if (keyOrNodeOrEntryOrRawElement === null)
7829
+ return null;
7830
+ if (this.isNode(keyOrNodeOrEntryOrRawElement))
7831
+ return keyOrNodeOrEntryOrRawElement;
7832
+ if (this.toEntryFn) {
7833
+ const [key, entryValue] = this.toEntryFn(keyOrNodeOrEntryOrRawElement);
7834
+ if (key)
7835
+ return this.createNode(key, entryValue != null ? entryValue : value);
7836
+ else
7847
7837
  return;
7848
- } else if (key === null) {
7849
- node = null;
7850
- } else {
7851
- node = this.createNode(key, value2);
7852
- }
7853
- } else if (this.isNode(keyOrNodeOrEntry)) {
7854
- node = keyOrNodeOrEntry;
7855
- } else if (!this.isNode(keyOrNodeOrEntry)) {
7856
- node = this.createNode(keyOrNodeOrEntry, value);
7857
- } else {
7858
- return;
7859
7838
  }
7860
- return node;
7839
+ if (this.isEntry(keyOrNodeOrEntryOrRawElement)) {
7840
+ const [key, value2] = keyOrNodeOrEntryOrRawElement;
7841
+ if (key === void 0)
7842
+ return;
7843
+ else if (key === null)
7844
+ return null;
7845
+ else
7846
+ return this.createNode(key, value2);
7847
+ }
7848
+ if (this.isKey(keyOrNodeOrEntryOrRawElement))
7849
+ return this.createNode(keyOrNodeOrEntryOrRawElement, value);
7850
+ return;
7861
7851
  }
7862
7852
  /**
7863
7853
  * Time Complexity: O(n)
@@ -7867,56 +7857,56 @@ var dataStructureTyped = (() => {
7867
7857
  * Time Complexity: O(n)
7868
7858
  * Space Complexity: O(log n)
7869
7859
  *
7870
- * The function `ensureNode` returns the node corresponding to the given key if it is a valid node
7871
- * key, otherwise it returns the key itself.
7872
- * @param {K | NODE | null | undefined} keyOrNodeOrEntry - The `key` parameter can be of type `K`, `NODE`,
7873
- * `null`, or `undefined`. It represents a key used to identify a node in a binary tree.
7874
- * @param iterationType - The `iterationType` parameter is an optional parameter that specifies the
7875
- * type of iteration to be used when searching for a node by key. It has a default value of
7876
- * `'ITERATIVE'`.
7877
- * @returns either the node corresponding to the given key if it is a valid node key, or the key
7878
- * itself if it is not a valid node key.
7879
- */
7880
- ensureNode(keyOrNodeOrEntry, iterationType = "ITERATIVE") {
7881
- if (keyOrNodeOrEntry === this.NIL)
7860
+ * The `ensureNode` function checks if the input is a valid node and returns it, or converts it to a
7861
+ * node if it is a key or entry.
7862
+ * @param {R | KeyOrNodeOrEntry<K, V, NODE>} keyOrNodeOrEntryOrRawElement - The parameter
7863
+ * `keyOrNodeOrEntryOrRawElement` can accept a value of type `R`, `KeyOrNodeOrEntry<K, V, NODE>`, or
7864
+ * a raw element.
7865
+ * @param {IterationType} [iterationType=ITERATIVE] - The `iterationType` parameter is an optional
7866
+ * parameter that specifies the type of iteration to be used when searching for a node. It has a
7867
+ * default value of `'ITERATIVE'`.
7868
+ * @returns The function `ensureNode` returns either a `NODE` object, `null`, or `undefined`.
7869
+ */
7870
+ ensureNode(keyOrNodeOrEntryOrRawElement, iterationType = "ITERATIVE") {
7871
+ if (keyOrNodeOrEntryOrRawElement === null)
7872
+ return null;
7873
+ if (keyOrNodeOrEntryOrRawElement === void 0)
7882
7874
  return;
7883
- if (this.isRealNode(keyOrNodeOrEntry)) {
7884
- return keyOrNodeOrEntry;
7885
- }
7886
- if (this.isEntry(keyOrNodeOrEntry)) {
7887
- const key = keyOrNodeOrEntry[0];
7875
+ if (keyOrNodeOrEntryOrRawElement === this.NIL)
7876
+ return;
7877
+ if (this.isNode(keyOrNodeOrEntryOrRawElement))
7878
+ return keyOrNodeOrEntryOrRawElement;
7879
+ if (this.toEntryFn) {
7880
+ const [key] = this.toEntryFn(keyOrNodeOrEntryOrRawElement);
7881
+ if (key)
7882
+ return this.getNodeByKey(key);
7883
+ }
7884
+ if (this.isEntry(keyOrNodeOrEntryOrRawElement)) {
7885
+ const key = keyOrNodeOrEntryOrRawElement[0];
7888
7886
  if (key === null)
7889
7887
  return null;
7890
7888
  if (key === void 0)
7891
7889
  return;
7892
7890
  return this.getNodeByKey(key, iterationType);
7893
7891
  }
7894
- if (keyOrNodeOrEntry === null)
7895
- return null;
7896
- if (keyOrNodeOrEntry === void 0)
7897
- return;
7898
- return this.getNodeByKey(keyOrNodeOrEntry, iterationType);
7899
- }
7900
- /**
7901
- * The function checks if a given node is a real node or null.
7902
- * @param {any} node - The parameter `node` is of type `any`, which means it can be any data type.
7903
- * @returns a boolean value.
7904
- */
7905
- isNodeOrNull(node) {
7906
- return this.isRealNode(node) || node === null;
7892
+ if (this.isKey(keyOrNodeOrEntryOrRawElement))
7893
+ return this.getNodeByKey(keyOrNodeOrEntryOrRawElement, iterationType);
7894
+ return;
7907
7895
  }
7908
7896
  /**
7909
- * The function "isNode" checks if an keyOrNodeOrEntry is an instance of the BinaryTreeNode class.
7910
- * @param keyOrNodeOrEntry - The `keyOrNodeOrEntry` parameter is a variable of type `KeyOrNodeOrEntry<K, V,NODE>`.
7911
- * @returns a boolean value indicating whether the keyOrNodeOrEntry is an instance of the class NODE.
7897
+ * The function checks if the input is an instance of the BinaryTreeNode class.
7898
+ * @param {R | KeyOrNodeOrEntry<K, V, NODE>} keyOrNodeOrEntryOrRawElement - The parameter
7899
+ * `keyOrNodeOrEntryOrRawElement` can be of type `R` or `KeyOrNodeOrEntry<K, V, NODE>`.
7900
+ * @returns a boolean value indicating whether the input parameter `keyOrNodeOrEntryOrRawElement` is
7901
+ * an instance of the `BinaryTreeNode` class.
7912
7902
  */
7913
- isNode(keyOrNodeOrEntry) {
7914
- return keyOrNodeOrEntry instanceof BinaryTreeNode;
7903
+ isNode(keyOrNodeOrEntryOrRawElement) {
7904
+ return keyOrNodeOrEntryOrRawElement instanceof BinaryTreeNode;
7915
7905
  }
7916
7906
  /**
7917
- * The function checks if a given node is a real node by verifying if it is an instance of
7918
- * BinaryTreeNode and its key is not NaN.
7919
- * @param {any} node - The parameter `node` is of type `any`, which means it can be any data type.
7907
+ * The function checks if a given node is a valid node in a binary search tree.
7908
+ * @param {R | KeyOrNodeOrEntry<K, V, NODE>} node - The parameter `node` can be of type `R` or
7909
+ * `KeyOrNodeOrEntry<K, V, NODE>`.
7920
7910
  * @returns a boolean value.
7921
7911
  */
7922
7912
  isRealNode(node) {
@@ -7925,21 +7915,64 @@ var dataStructureTyped = (() => {
7925
7915
  return this.isNode(node);
7926
7916
  }
7927
7917
  /**
7928
- * The function checks if a given node is a BinaryTreeNode instance and has a key value of NaN.
7929
- * @param {any} node - The parameter `node` is of type `any`, which means it can be any data type.
7918
+ * The function checks if a given node is a real node or null.
7919
+ * @param {R | KeyOrNodeOrEntry<K, V, NODE>} node - The parameter `node` can be of type `R` or
7920
+ * `KeyOrNodeOrEntry<K, V, NODE>`.
7921
+ * @returns a boolean value.
7922
+ */
7923
+ isNodeOrNull(node) {
7924
+ return this.isRealNode(node) || node === null;
7925
+ }
7926
+ /**
7927
+ * The function checks if a given node is equal to the NIL value.
7928
+ * @param {R | KeyOrNodeOrEntry<K, V, NODE>} node - The parameter `node` can be of type `R` or
7929
+ * `KeyOrNodeOrEntry<K, V, NODE>`.
7930
7930
  * @returns a boolean value.
7931
7931
  */
7932
7932
  isNIL(node) {
7933
7933
  return node === this.NIL;
7934
7934
  }
7935
7935
  /**
7936
- * The function checks if a given value is an entry in a binary tree node.
7937
- * @param keyOrNodeOrEntry - KeyOrNodeOrEntry<K, V,NODE> - A generic type representing a node in a binary tree. It has
7938
- * two type parameters V and NODE, representing the value and node type respectively.
7936
+ * The function checks if the input is an array with two elements, indicating it is a binary tree
7937
+ * node entry.
7938
+ * @param {R | KeyOrNodeOrEntry<K, V, NODE>} keyOrNodeOrEntryOrRawElement - The parameter
7939
+ * `keyOrNodeOrEntryOrRawElement` can be of type `R` or `KeyOrNodeOrEntry<K, V, NODE>`.
7940
+ * @returns a boolean value.
7941
+ */
7942
+ isEntry(keyOrNodeOrEntryOrRawElement) {
7943
+ return Array.isArray(keyOrNodeOrEntryOrRawElement) && keyOrNodeOrEntryOrRawElement.length === 2;
7944
+ }
7945
+ /**
7946
+ * The function checks if a given value is a valid key by evaluating its type and value.
7947
+ * @param {any} key - The `key` parameter can be of any type. It is the value that we want to check
7948
+ * if it is a valid key.
7949
+ * @param [isCheckValueOf=true] - The `isCheckValueOf` parameter is a boolean flag that determines
7950
+ * whether the function should check the valueOf() method of an object when the key is of type
7951
+ * 'object'. If `isCheckValueOf` is true, the function will recursively call itself with the value
7952
+ * returned by key.valueOf().
7939
7953
  * @returns a boolean value.
7940
7954
  */
7941
- isEntry(keyOrNodeOrEntry) {
7942
- return Array.isArray(keyOrNodeOrEntry) && keyOrNodeOrEntry.length === 2;
7955
+ isKey(key, isCheckValueOf = true) {
7956
+ if (key === null)
7957
+ return true;
7958
+ const keyType = typeof key;
7959
+ if (keyType === "string" || keyType === "bigint" || keyType === "boolean")
7960
+ return true;
7961
+ if (keyType === "number")
7962
+ return !isNaN(key);
7963
+ if (keyType === "symbol" || keyType === "undefined")
7964
+ return false;
7965
+ if (keyType === "function")
7966
+ return this.isKey(key());
7967
+ if (keyType === "object") {
7968
+ if (typeof key.toString === "function")
7969
+ return true;
7970
+ if (isCheckValueOf && typeof key.valueOf === "function") {
7971
+ this.isKey(key.valueOf(), false);
7972
+ }
7973
+ return false;
7974
+ }
7975
+ return false;
7943
7976
  }
7944
7977
  /**
7945
7978
  * Time Complexity O(n)
@@ -7949,14 +7982,20 @@ var dataStructureTyped = (() => {
7949
7982
  * Time Complexity O(n)
7950
7983
  * Space Complexity O(1)
7951
7984
  *
7952
- * The `add` function adds a new node to a binary tree, either by creating a new node or replacing an
7953
- * existing node with the same key.
7954
- * @param keyOrNodeOrEntry - The `keyOrNodeOrEntry` parameter can be one of the following:
7955
- * @param {V} [value] - The value to be inserted into the binary tree.
7956
- * @returns The function `add` returns either a node (`NODE`), `null`, or `undefined`.
7957
- */
7958
- add(keyOrNodeOrEntry, value) {
7959
- const newNode = this.keyValueOrEntryToNode(keyOrNodeOrEntry, value);
7985
+ * The `add` function is used to insert a new node into a binary tree, checking for duplicate keys
7986
+ * and finding the appropriate insertion position.
7987
+ * @param {R | KeyOrNodeOrEntry<K, V, NODE>} keyOrNodeOrEntryOrRawElement - The
7988
+ * `keyOrNodeOrEntryOrRawElement` parameter can accept a value of type `R`, which represents the key,
7989
+ * node, entry, or raw element to be added to the tree. It can also accept a value of type
7990
+ * `KeyOrNodeOrEntry<K, V, NODE>
7991
+ * @param {V} [value] - The `value` parameter is an optional value that can be associated with the
7992
+ * key being added to the tree. It represents the value that will be stored in the tree for the given
7993
+ * key.
7994
+ * @returns a boolean value. It returns `true` if the insertion is successful, and `false` if the
7995
+ * insertion position cannot be found or if there are duplicate keys.
7996
+ */
7997
+ add(keyOrNodeOrEntryOrRawElement, value) {
7998
+ const newNode = this.keyValueOrEntryOrRawElementToNode(keyOrNodeOrEntryOrRawElement, value);
7960
7999
  if (newNode === void 0)
7961
8000
  return false;
7962
8001
  if (!this.root) {
@@ -8004,19 +8043,23 @@ var dataStructureTyped = (() => {
8004
8043
  * Time Complexity: O(k * n)
8005
8044
  * Space Complexity: O(1)
8006
8045
  *
8007
- * The `addMany` function takes in a collection of keysOrNodesOrEntries and an optional collection of values, and
8008
- * adds each node with its corresponding value to the data structure.
8009
- * @param keysOrNodesOrEntries - An iterable collection of KeyOrNodeOrEntry objects.
8010
- * @param [values] - An optional iterable of values that will be assigned to each node being added.
8011
- * @returns The function `addMany` returns an array of `NODE`, `null`, or `undefined` values.
8046
+ * The `addMany` function takes in an iterable of keys or nodes or entries or raw elements, and an
8047
+ * optional iterable of values, and adds each key or node or entry with its corresponding value to a
8048
+ * data structure, returning an array of booleans indicating whether each insertion was successful.
8049
+ * @param keysOrNodesOrEntriesOrRawElements - An iterable containing keys, nodes, entries, or raw
8050
+ * elements. These elements will be added to the data structure.
8051
+ * @param [values] - An optional iterable of values that correspond to the keys or nodes or entries
8052
+ * in the `keysOrNodesOrEntriesOrRawElements` parameter.
8053
+ * @returns The function `addMany` returns an array of booleans indicating whether each element was
8054
+ * successfully added to the data structure.
8012
8055
  */
8013
- addMany(keysOrNodesOrEntries, values) {
8056
+ addMany(keysOrNodesOrEntriesOrRawElements, values) {
8014
8057
  const inserted = [];
8015
8058
  let valuesIterator;
8016
8059
  if (values) {
8017
8060
  valuesIterator = values[Symbol.iterator]();
8018
8061
  }
8019
- for (const keyOrNodeOrEntry of keysOrNodesOrEntries) {
8062
+ for (const keyOrNodeOrEntryOrRawElement of keysOrNodesOrEntriesOrRawElements) {
8020
8063
  let value = void 0;
8021
8064
  if (valuesIterator) {
8022
8065
  const valueResult = valuesIterator.next();
@@ -8024,7 +8067,7 @@ var dataStructureTyped = (() => {
8024
8067
  value = valueResult.value;
8025
8068
  }
8026
8069
  }
8027
- inserted.push(this.add(keyOrNodeOrEntry, value));
8070
+ inserted.push(this.add(keyOrNodeOrEntryOrRawElement, value));
8028
8071
  }
8029
8072
  return inserted;
8030
8073
  }
@@ -8037,38 +8080,36 @@ var dataStructureTyped = (() => {
8037
8080
  * Time Complexity: O(k * n)
8038
8081
  * Space Complexity: O(1)
8039
8082
  *
8040
- * The `refill` function clears the current data and adds new key-value pairs to the data structure.
8041
- * @param keysOrNodesOrEntries - An iterable containing keys, nodes, or entries. These can be of type
8042
- * KeyOrNodeOrEntry<K, V, NODE>.
8043
- * @param [values] - The `values` parameter is an optional iterable that contains the values to be
8044
- * associated with the keys or nodes or entries in the `keysOrNodesOrEntries` parameter. If provided,
8045
- * the values will be associated with the corresponding keys or nodes or entries in the
8046
- * `keysOrNodesOrEntries` iterable
8083
+ * The `refill` function clears the current data and adds new data to the collection.
8084
+ * @param keysOrNodesOrEntriesOrRawElements - An iterable collection of keys, nodes, entries, or raw
8085
+ * elements. These can be of any type (R) or a specific type (KeyOrNodeOrEntry<K, V, NODE>).
8086
+ * @param [values] - The `values` parameter is an optional iterable of values that will be associated
8087
+ * with the keys or nodes being added. If provided, the values will be assigned to the corresponding
8088
+ * keys or nodes. If not provided, the values will be set to `undefined`.
8047
8089
  */
8048
- refill(keysOrNodesOrEntries, values) {
8090
+ refill(keysOrNodesOrEntriesOrRawElements, values) {
8049
8091
  this.clear();
8050
- this.addMany(keysOrNodesOrEntries, values);
8051
- }
8052
- /**
8053
- * Time Complexity: O(n)
8054
- * Space Complexity: O(1)
8055
- * /
8056
-
8057
- /**
8058
- * Time Complexity: O(n)
8059
- * Space Complexity: O(1)
8060
- *
8061
- * The function deletes a node from a binary tree and returns an array of the deleted nodes along
8062
- * with the nodes that need to be balanced.
8063
- * @param {ReturnType<C> | null | undefined} identifier - The identifier parameter is the value or
8064
- * object that you want to delete from the binary tree. It can be of any type that is compatible with
8065
- * the callback function's return type. It can also be null or undefined if you want to delete a
8066
- * specific node based on its value or object.
8067
- * @param {C} callback - The `callback` parameter is a function that is used to determine the
8068
- * identifier of the node to be deleted. It is optional and has a default value of
8069
- * `this._DEFAULT_CALLBACK`. The `callback` function should return the identifier of the node.
8070
- * @returns an array of `BinaryTreeDeleteResult<NODE>`.
8071
- */
8092
+ this.addMany(keysOrNodesOrEntriesOrRawElements, values);
8093
+ }
8094
+ /**
8095
+ * Time Complexity: O(n)
8096
+ * Space Complexity: O(1)
8097
+ */
8098
+ /**
8099
+ * Time Complexity: O(n)
8100
+ * Space Complexity: O(1)
8101
+ *
8102
+ * The above function is a TypeScript implementation of deleting a node from a binary tree, returning
8103
+ * the deleted node and the node that needs to be balanced.
8104
+ * @param {ReturnType<C> | null | undefined} identifier - The `identifier` parameter is the value
8105
+ * used to identify the node that needs to be deleted from the binary tree. It can be of any type
8106
+ * that is returned by the callback function.
8107
+ * @param {C} callback - The `callback` parameter is a function that is used to determine the
8108
+ * identifier of the node to be deleted. It is of type `C`, which extends the `BTNCallback<NODE>`
8109
+ * interface. The `BTNCallback<NODE>` interface represents a callback function that takes a node of
8110
+ * type `NODE
8111
+ * @returns an array of `BinaryTreeDeleteResult<NODE>`.
8112
+ */
8072
8113
  delete(identifier, callback = this._DEFAULT_CALLBACK) {
8073
8114
  const deletedResult = [];
8074
8115
  if (!this.root)
@@ -8117,28 +8158,27 @@ var dataStructureTyped = (() => {
8117
8158
  */
8118
8159
  /**
8119
8160
  * Time Complexity: O(n)
8120
- * Space Complexity: O(k + log n).
8161
+ * Space Complexity: O(k + log n)
8121
8162
  *
8122
- * The function `getNodes` retrieves nodes from a binary tree based on a given identifier and
8123
- * callback function.
8163
+ * The function `getNodes` returns an array of nodes that match a given identifier, using either a
8164
+ * recursive or iterative approach.
8124
8165
  * @param {ReturnType<C> | null | undefined} identifier - The `identifier` parameter is the value
8125
- * that you want to search for in the binary tree. It can be of any type that is returned by the
8126
- * callback function `C`. It can also be `null` or `undefined` if you don't want to search for a
8127
- * specific value.
8128
- * @param {C} callback - The `callback` parameter is a function that takes a node of type `NODE` as
8129
- * input and returns a value of type `C`. It is used to determine if a node matches the given
8130
- * identifier. If no callback is provided, the `_DEFAULT_CALLBACK` function is used as the
8131
- * default
8132
- * @param [onlyOne=false] - A boolean value indicating whether to only return the first node that
8133
- * matches the identifier. If set to true, the function will stop iterating once it finds a matching
8134
- * node and return that node. If set to false (default), the function will continue iterating and
8135
- * return all nodes that match the identifier.
8136
- * @param {K | NODE | null | undefined} beginRoot - The `beginRoot` parameter represents the
8137
- * starting node for the traversal. It can be either a key, a node object, or `null`/`undefined`. If
8138
- * it is `null` or `undefined`, an empty array will be returned.
8139
- * @param iterationType - The `iterationType` parameter determines the type of iteration used to
8140
- * traverse the binary tree. It can have two possible values:
8141
- * @returns an array of nodes of type `NODE`.
8166
+ * that is used to identify the nodes. It can be of any type and is used to match against the result
8167
+ * of the callback function for each node.
8168
+ * @param {C} callback - The `callback` parameter is a function that takes a node as input and
8169
+ * returns a value. This value is used to identify the nodes that match the given identifier. The
8170
+ * `callback` function is optional and defaults to a default callback function
8171
+ * (`this._DEFAULT_CALLBACK`) if not provided.
8172
+ * @param [onlyOne=false] - A boolean value indicating whether to return only one node that matches
8173
+ * the identifier or all nodes that match the identifier. If set to true, only the first matching
8174
+ * node will be returned. If set to false, all matching nodes will be returned. The default value is
8175
+ * false.
8176
+ * @param {R | KeyOrNodeOrEntry<K, V, NODE>} beginRoot - The `beginRoot` parameter is the starting
8177
+ * point for the search. It can be either a node object, a key-value pair, or a key. If it is not
8178
+ * provided, the `root` of the data structure is used as the starting point.
8179
+ * @param {IterationType} iterationType - The `iterationType` parameter determines the type of
8180
+ * iteration to be performed on the nodes of a binary tree. It can have two possible values:
8181
+ * @returns an array of NODE objects.
8142
8182
  */
8143
8183
  getNodes(identifier, callback = this._DEFAULT_CALLBACK, onlyOne = false, beginRoot = this.root, iterationType = this.iterationType) {
8144
8184
  beginRoot = this.ensureNode(beginRoot);
@@ -8182,24 +8222,21 @@ var dataStructureTyped = (() => {
8182
8222
  */
8183
8223
  /**
8184
8224
  * Time Complexity: O(n)
8185
- * Space Complexity: O(log n)
8225
+ * Space Complexity: O(log n).
8186
8226
  *
8187
- * The function `getNode` returns the first node that matches the given identifier and callback
8188
- * function.
8227
+ * The function `getNode` returns the first node that matches the given identifier and callback,
8228
+ * starting from the specified root node and using the specified iteration type.
8189
8229
  * @param {ReturnType<C> | null | undefined} identifier - The `identifier` parameter is the value
8190
- * used to identify the node you want to retrieve. It can be of any type that is returned by the
8191
- * callback function `C`. It can also be `null` or `undefined` if you don't have a specific
8192
- * identifier.
8193
- * @param {C} callback - The `callback` parameter is a function that will be called for each node in
8194
- * the binary tree. It is used to determine if a node matches the given identifier. The `callback`
8195
- * function should take a single parameter of type `NODE` (the type of the nodes in the binary tree) and
8196
- * @param {K | NODE | null | undefined} beginRoot - The `beginRoot` parameter is the starting point
8197
- * for searching the binary tree. It can be either a key value, a node object, or `null`/`undefined`.
8198
- * If `null` or `undefined` is passed, the search will start from the root of the binary tree.
8199
- * @param iterationType - The `iterationType` parameter is used to specify the type of iteration to
8200
- * be performed when searching for nodes in the binary tree. It determines the order in which the
8201
- * nodes are visited during the search.
8202
- * @returns a value of type `NODE | null | undefined`.
8230
+ * used to identify the node you want to retrieve. It can be of any type that is the return type of
8231
+ * the `C` callback function, or it can be `null` or `undefined`.
8232
+ * @param {C} callback - The `callback` parameter is a function that will be used to determine if a
8233
+ * node matches the desired criteria. It should return a value that can be used to identify the node.
8234
+ * @param {R | KeyOrNodeOrEntry<K, V, NODE>} beginRoot - The `beginRoot` parameter is the starting
8235
+ * point for searching nodes in a tree structure. It can be either a root node, a key-value pair, or
8236
+ * a node entry. If not provided, the search will start from the root of the tree.
8237
+ * @param {IterationType} iterationType - The `iterationType` parameter is used to specify the type
8238
+ * of iteration to be performed when searching for nodes. It can have one of the following values:
8239
+ * @returns The method is returning a NODE object, or null, or undefined.
8203
8240
  */
8204
8241
  getNode(identifier, callback = this._DEFAULT_CALLBACK, beginRoot = this.root, iterationType = this.iterationType) {
8205
8242
  var _a;
@@ -8213,15 +8250,13 @@ var dataStructureTyped = (() => {
8213
8250
  * Time Complexity: O(n)
8214
8251
  * Space Complexity: O(log n)
8215
8252
  *
8216
- * The function `getNodeByKey` searches for a node in a binary tree by its key, using either
8217
- * recursive or iterative iteration.
8218
- * @param {K} key - The `key` parameter is the key value that we are searching for in the tree.
8219
- * It is used to find the node with the matching key value.
8220
- * @param iterationType - The `iterationType` parameter is used to determine whether the search for
8221
- * the node with the given key should be performed iteratively or recursively. It has two possible
8222
- * values:
8223
- * @returns The function `getNodeByKey` returns a node (`NODE`) if a node with the specified key is
8224
- * found in the binary tree. If no node is found, it returns `undefined`.
8253
+ * The function `getNodeByKey` returns a node with a specific key value from a tree structure.
8254
+ * @param {K} key - The key parameter is the value that you want to search for in the tree. It is
8255
+ * used to find the node with the matching key value.
8256
+ * @param {IterationType} [iterationType=ITERATIVE] - The `iterationType` parameter is an optional
8257
+ * parameter that specifies the type of iteration to be used when searching for a node in the tree.
8258
+ * It has a default value of `'ITERATIVE'`.
8259
+ * @returns a value of type NODE, null, or undefined.
8225
8260
  */
8226
8261
  getNodeByKey(key, iterationType = "ITERATIVE") {
8227
8262
  return this.getNode(key, this._DEFAULT_CALLBACK, this.root, iterationType);
@@ -8234,23 +8269,22 @@ var dataStructureTyped = (() => {
8234
8269
  * Time Complexity: O(n)
8235
8270
  * Space Complexity: O(log n)
8236
8271
  *
8237
- * The function `get` retrieves the value of a node in a binary tree based on the provided identifier
8238
- * and callback function.
8272
+ * The function `get` in TypeScript overrides the base class method and returns the value associated
8273
+ * with the given identifier.
8239
8274
  * @param {ReturnType<C> | null | undefined} identifier - The `identifier` parameter is the value
8240
- * used to identify the node in the binary tree. It can be of any type that is the return type of the
8275
+ * used to identify the node in the binary tree. It can be of any type that is returned by the
8241
8276
  * callback function `C`. It can also be `null` or `undefined` if no identifier is provided.
8242
- * @param {C} callback - The `callback` parameter is a function that will be called with each node in
8243
- * the binary tree. It is used to determine whether a node matches the given identifier. The callback
8244
- * function should return a value that can be compared to the identifier to determine if it is a
8245
- * match.
8246
- * @param {K | NODE | null | undefined} beginRoot - The `beginRoot` parameter is the starting point
8247
- * for the search in the binary tree. It can be specified as a `K` (a unique identifier for a
8248
- * node), a node object of type `NODE`, or `null`/`undefined` to start the search from the root of
8249
- * @param iterationType - The `iterationType` parameter is used to specify the type of iteration to
8250
- * be performed when searching for a node in the binary tree. It is an optional parameter with a
8251
- * default value specified by `this.iterationType`.
8252
- * @returns The value of the node with the given identifier is being returned. If the node is not
8253
- * found, `undefined` is returned.
8277
+ * @param {C} callback - The `callback` parameter is a function that will be used to determine if a
8278
+ * node matches the given identifier. It is optional and defaults to `this._DEFAULT_CALLBACK`.
8279
+ * @param {R | KeyOrNodeOrEntry<K, V, NODE>} beginRoot - The `beginRoot` parameter is the starting
8280
+ * point for the search in the binary tree. It can be either a root node of the tree or a key, node,
8281
+ * or entry object that exists in the tree. If no specific starting point is provided, the search
8282
+ * will begin from the root of the
8283
+ * @param {IterationType} iterationType - The `iterationType` parameter is used to specify the type
8284
+ * of iteration to be performed when searching for a node in the tree. It can have one of the
8285
+ * following values:
8286
+ * @returns The method is returning the value associated with the specified identifier in the binary
8287
+ * tree.
8254
8288
  */
8255
8289
  get(identifier, callback = this._DEFAULT_CALLBACK, beginRoot = this.root, iterationType = this.iterationType) {
8256
8290
  var _a;
@@ -8258,28 +8292,27 @@ var dataStructureTyped = (() => {
8258
8292
  }
8259
8293
  /**
8260
8294
  * Time Complexity: O(n)
8261
- * Space Complexity: O(log n).
8295
+ * Space Complexity: O(log n)
8262
8296
  */
8263
8297
  /**
8264
8298
  * Time Complexity: O(n)
8265
- * Space Complexity: O(log n).
8299
+ * Space Complexity: O(log n)
8266
8300
  *
8267
- * The function checks if a Binary Tree Node with a specific identifier exists in the tree.
8301
+ * The `has` function checks if a given identifier exists in the data structure and returns a boolean
8302
+ * value.
8268
8303
  * @param {ReturnType<C> | null | undefined} identifier - The `identifier` parameter is the value
8269
- * that you want to search for in the binary tree. It can be of any type that is returned by the
8270
- * callback function `C`. It can also be `null` or `undefined` if you don't want to specify a
8271
- * specific identifier.
8272
- * @param {C} callback - The `callback` parameter is a function that will be called for each node in
8273
- * the binary tree. It is used to filter the nodes based on certain conditions. The `callback`
8274
- * function should return a boolean value indicating whether the node should be included in the
8275
- * result or not.
8276
- * @param {K | NODE | null | undefined} beginRoot - The `beginRoot` parameter is the starting point
8277
- * for the search in the binary tree. It can be specified as a `K` (a unique identifier for a
8278
- * node in the binary tree), a node object (`NODE`), or `null`/`undefined` to start the search from
8279
- * @param iterationType - The `iterationType` parameter is a variable that determines the type of
8280
- * iteration to be performed on the binary tree. It is used to specify whether the iteration should
8281
- * be performed in a pre-order, in-order, or post-order manner.
8282
- * @returns a boolean value.
8304
+ * used to identify a specific node or entry in the data structure. It can be of any type that is
8305
+ * returned by the callback function `C`. It can also be `null` or `undefined` if no specific
8306
+ * identifier is provided.
8307
+ * @param {C} callback - The `callback` parameter is a function that will be used to determine
8308
+ * whether a node should be included in the result or not. It is of type `C`, which extends the
8309
+ * `BTNCallback<NODE>` type.
8310
+ * @param {R | KeyOrNodeOrEntry<K, V, NODE>} beginRoot - The `beginRoot` parameter is the starting
8311
+ * point for the iteration in the data structure. It can be either a root node, a key-value pair, or
8312
+ * a node entry. If not specified, it defaults to the root of the data structure.
8313
+ * @param {IterationType} iterationType - The `iterationType` parameter is used to specify the type
8314
+ * of iteration to be performed. It is an optional parameter with a default value of `IterationType`.
8315
+ * @returns The method is returning a boolean value.
8283
8316
  */
8284
8317
  has(identifier, callback = this._DEFAULT_CALLBACK, beginRoot = this.root, iterationType = this.iterationType) {
8285
8318
  callback = this._ensureCallback(identifier, callback);
@@ -8323,9 +8356,10 @@ var dataStructureTyped = (() => {
8323
8356
  *
8324
8357
  * The function checks if a binary tree is perfectly balanced by comparing the minimum height and the
8325
8358
  * height of the tree.
8326
- * @param {K | NODE | null | undefined} beginRoot - The `beginRoot` parameter is the starting point
8327
- * for calculating the height and minimum height of a binary tree. It can be either a `K` (a key
8328
- * value of a binary tree node), `NODE` (a node of a binary tree), `null`, or `undefined`. If
8359
+ * @param {R | KeyOrNodeOrEntry<K, V, NODE>} beginRoot - The parameter `beginRoot` is optional and
8360
+ * has a default value of `this.root`. It represents the starting point for checking if the tree is
8361
+ * perfectly balanced. It can be either a root node (`R`), a key or node or entry
8362
+ * (`KeyOrNodeOrEntry<K, V, NODE
8329
8363
  * @returns a boolean value.
8330
8364
  */
8331
8365
  isPerfectlyBalanced(beginRoot = this.root) {
@@ -8339,12 +8373,14 @@ var dataStructureTyped = (() => {
8339
8373
  * Time Complexity: O(n)
8340
8374
  * Space Complexity: O(1)
8341
8375
  *
8342
- * The function `isSubtreeBST` checks if a given binary tree is a valid binary search tree.
8343
- * @param {K | NODE | null | undefined} beginRoot - The `beginRoot` parameter represents the root
8344
- * node of the binary search tree (BST) that you want to check if it is a subtree of another BST.
8345
- * @param iterationType - The `iterationType` parameter is an optional parameter that specifies the
8346
- * type of iteration to use when checking if a subtree is a binary search tree (BST). It can have two
8347
- * possible values:
8376
+ * The function `isBST` checks if a binary search tree is valid, either recursively or iteratively.
8377
+ * @param {R | KeyOrNodeOrEntry<K, V, NODE>} beginRoot - The `beginRoot` parameter represents the
8378
+ * starting point for checking if a binary search tree (BST) is valid. It can be either a root node
8379
+ * of the BST, a key value of a node in the BST, or an entry object containing both the key and value
8380
+ * of a node in the BST
8381
+ * @param {IterationType} iterationType - The `iterationType` parameter is used to determine the type
8382
+ * of iteration to be performed while checking if the binary search tree (BST) is valid. It can have
8383
+ * two possible values:
8348
8384
  * @returns a boolean value.
8349
8385
  */
8350
8386
  isBST(beginRoot = this.root, iterationType = this.iterationType) {
@@ -8394,14 +8430,15 @@ var dataStructureTyped = (() => {
8394
8430
  * Time Complexity: O(n)
8395
8431
  * Space Complexity: O(1)
8396
8432
  *
8397
- * The function calculates the depth of a given node in a binary tree.
8398
- * @param {K | NODE | null | undefined} dist - The `dist` parameter represents the node in
8399
- * the binary tree whose depth we want to find. It can be of type `K`, `NODE`, `null`, or
8400
- * `undefined`.
8401
- * @param {K | NODE | null | undefined} beginRoot - The `beginRoot` parameter is the starting node
8402
- * from which we want to calculate the depth. It can be either a `K` (binary tree node key) or
8403
- * `NODE` (binary tree node) or `null` or `undefined`. If no value is provided for `beginRoot
8404
- * @returns the depth of the `dist` relative to the `beginRoot`.
8433
+ * The function calculates the depth of a given node or key in a tree-like data structure.
8434
+ * @param {R | KeyOrNodeOrEntry<K, V, NODE>} dist - The `dist` parameter can be either a `R`
8435
+ * (representing a root node), or a `KeyOrNodeOrEntry<K, V, NODE>` (representing a key, node, or
8436
+ * entry).
8437
+ * @param {R | KeyOrNodeOrEntry<K, V, NODE>} beginRoot - The `beginRoot` parameter is optional and
8438
+ * represents the starting point from which to calculate the depth. It can be either a reference to a
8439
+ * node in the tree or a key-value pair or an entry object. If not provided, the default value is
8440
+ * `this.root`, which refers to the root node
8441
+ * @returns the depth of a node in a tree structure.
8405
8442
  */
8406
8443
  getDepth(dist, beginRoot = this.root) {
8407
8444
  let distEnsured = this.ensureNode(dist);
@@ -8422,17 +8459,16 @@ var dataStructureTyped = (() => {
8422
8459
  */
8423
8460
  /**
8424
8461
  * Time Complexity: O(n)
8425
- * Space Complexity: O(log n)
8462
+ * Space Complexity: O(1)
8426
8463
  *
8427
- * The function `getHeight` calculates the maximum height of a binary tree using either recursive or
8428
- * iterative traversal.
8429
- * @param {K | NODE | null | undefined} beginRoot - The `beginRoot` parameter represents the
8430
- * starting node of the binary tree from which we want to calculate the height. It can be of type
8431
- * `K`, `NODE`, `null`, or `undefined`. If not provided, it defaults to `this.root`.
8432
- * @param iterationType - The `iterationType` parameter is used to determine whether to calculate the
8433
- * height of the tree using a recursive approach or an iterative approach. It can have two possible
8434
- * values:
8435
- * @returns the height of the binary tree.
8464
+ * The `getHeight` function calculates the maximum height of a binary tree using either a recursive
8465
+ * or iterative approach.
8466
+ * @param {R | KeyOrNodeOrEntry<K, V, NODE>} beginRoot - The `beginRoot` parameter represents the
8467
+ * starting point for calculating the height of a tree. It can be either a root node (`R`), a key or
8468
+ * node or entry (`KeyOrNodeOrEntry<K, V, NODE>`), or it defaults to the root of the current tree.
8469
+ * @param {IterationType} iterationType - The `iterationType` parameter determines the type of
8470
+ * iteration used to calculate the height of the tree. It can have two possible values:
8471
+ * @returns the maximum height of the binary tree.
8436
8472
  */
8437
8473
  getHeight(beginRoot = this.root, iterationType = this.iterationType) {
8438
8474
  beginRoot = this.ensureNode(beginRoot);
@@ -8471,12 +8507,15 @@ var dataStructureTyped = (() => {
8471
8507
  *
8472
8508
  * The `getMinHeight` function calculates the minimum height of a binary tree using either a
8473
8509
  * recursive or iterative approach.
8474
- * @param {K | NODE | null | undefined} beginRoot - The `beginRoot` parameter represents the
8475
- * starting node of the binary tree from which we want to calculate the minimum height. It can be of
8476
- * type `K`, `NODE`, `null`, or `undefined`. If no value is provided, it defaults to `this.root`.
8477
- * @param iterationType - The `iterationType` parameter is used to determine the method of iteration
8478
- * to calculate the minimum height of a binary tree. It can have two possible values:
8479
- * @returns The function `getMinHeight` returns the minimum height of a binary tree.
8510
+ * @param {R | KeyOrNodeOrEntry<K, V, NODE>} beginRoot - The `beginRoot` parameter represents the
8511
+ * starting point for calculating the minimum height of a tree. It can be either a root node (`R`), a
8512
+ * key or node or entry (`KeyOrNodeOrEntry<K, V, NODE>`), or it defaults to the root of the current
8513
+ * tree.
8514
+ * @param {IterationType} iterationType - The `iterationType` parameter determines the type of
8515
+ * iteration to be used when calculating the minimum height of the tree. It can have two possible
8516
+ * values:
8517
+ * @returns The function `getMinHeight` returns a number, which represents the minimum height of the
8518
+ * binary tree.
8480
8519
  */
8481
8520
  getMinHeight(beginRoot = this.root, iterationType = this.iterationType) {
8482
8521
  var _a, _b, _c;
@@ -8521,24 +8560,22 @@ var dataStructureTyped = (() => {
8521
8560
  }
8522
8561
  }
8523
8562
  /**
8524
- * Time Complexity: O(log n)
8525
- * Space Complexity: O(log n)
8526
- * /
8527
-
8528
- /**
8529
- * Time Complexity: O(log n)
8530
- * Space Complexity: O(log n)
8531
- *
8532
- * The function `getPathToRoot` returns an array of nodes from a given node to the root of a tree
8533
- * structure, with the option to reverse the order of the nodes.
8534
- * @param {K | NODE | null | undefined} beginNode - The `beginRoot` parameter represents the
8535
- * starting node from which you want to find the path to the root. It can be of type `K`, `NODE`,
8536
- * `null`, or `undefined`.
8537
- * @param [isReverse=true] - The `isReverse` parameter is a boolean flag that determines whether the
8538
- * resulting path should be reversed or not. If `isReverse` is set to `true`, the path will be
8539
- * reversed before returning it. If `isReverse` is set to `false`, the path will be returned as is
8540
- * @returns The function `getPathToRoot` returns an array of nodes (`NODE[]`).
8541
- */
8563
+ * Time Complexity: O(log n)
8564
+ * Space Complexity: O(log n)
8565
+ */
8566
+ /**
8567
+ * Time Complexity: O(log n)
8568
+ * Space Complexity: O(log n)
8569
+ *
8570
+ * The function `getPathToRoot` returns an array of nodes starting from a given node and traversing
8571
+ * up to the root node, with an option to reverse the order of the nodes.
8572
+ * @param {R | KeyOrNodeOrEntry<K, V, NODE>} beginNode - The `beginNode` parameter can be either of
8573
+ * type `R` or `KeyOrNodeOrEntry<K, V, NODE>`.
8574
+ * @param [isReverse=true] - The `isReverse` parameter is a boolean flag that determines whether the
8575
+ * resulting path should be reversed or not. If `isReverse` is set to `true`, the path will be
8576
+ * reversed before returning it. If `isReverse` is set to `false` or not provided, the path will
8577
+ * @returns The function `getPathToRoot` returns an array of `NODE` objects.
8578
+ */
8542
8579
  getPathToRoot(beginNode, isReverse = true) {
8543
8580
  const result = [];
8544
8581
  let beginNodeEnsured = this.ensureNode(beginNode);
@@ -8559,15 +8596,14 @@ var dataStructureTyped = (() => {
8559
8596
  * Time Complexity: O(log n)
8560
8597
  * Space Complexity: O(1)
8561
8598
  *
8562
- * The function `getLeftMost` returns the leftmost node in a binary tree, either recursively or
8563
- * iteratively.
8564
- * @param {K | NODE | null | undefined} beginRoot - The `beginRoot` parameter is the starting point
8565
- * for finding the leftmost node in a binary tree. It can be either a `K` (a key value), `NODE` (a
8566
- * node), `null`, or `undefined`. If not provided, it defaults to `this.root`,
8567
- * @param iterationType - The `iterationType` parameter is used to determine the type of iteration to
8568
- * be performed when finding the leftmost node in a binary tree. It can have two possible values:
8569
- * @returns The function `getLeftMost` returns the leftmost node (`NODE`) in the binary tree. If there
8570
- * is no leftmost node, it returns `null` or `undefined` depending on the input.
8599
+ * The `getLeftMost` function returns the leftmost node in a binary tree, either using recursive or
8600
+ * iterative traversal.
8601
+ * @param {R | KeyOrNodeOrEntry<K, V, NODE>} beginRoot - The `beginRoot` parameter represents the
8602
+ * starting point for finding the leftmost node in a binary tree. It can be either a root node (`R`),
8603
+ * a key or node or entry (`KeyOrNodeOrEntry<K, V, NODE>`), or `null` or `undefined`.
8604
+ * @param {IterationType} iterationType - The `iterationType` parameter is used to specify the type
8605
+ * of iteration to be performed. It can have two possible values:
8606
+ * @returns The function `getLeftMost` returns the leftmost node in a binary tree.
8571
8607
  */
8572
8608
  getLeftMost(beginRoot = this.root, iterationType = this.iterationType) {
8573
8609
  if (this.isNIL(beginRoot))
@@ -8599,16 +8635,15 @@ var dataStructureTyped = (() => {
8599
8635
  * Time Complexity: O(log n)
8600
8636
  * Space Complexity: O(1)
8601
8637
  *
8602
- * The function `getRightMost` returns the rightmost node in a binary tree, either recursively or
8638
+ * The `getRightMost` function returns the rightmost node in a binary tree, either recursively or
8603
8639
  * iteratively.
8604
- * @param {K | NODE | null | undefined} beginRoot - The `beginRoot` parameter represents the
8605
- * starting node from which we want to find the rightmost node. It can be of type `K`, `NODE`,
8606
- * `null`, or `undefined`. If not provided, it defaults to `this.root`, which is a property of the
8607
- * current object.
8608
- * @param iterationType - The `iterationType` parameter is an optional parameter that specifies the
8609
- * type of iteration to use when finding the rightmost node. It can have one of two values:
8610
- * @returns The function `getRightMost` returns the rightmost node (`NODE`) in a binary tree. If there
8611
- * is no rightmost node, it returns `null` or `undefined`, depending on the input.
8640
+ * @param {R | KeyOrNodeOrEntry<K, V, NODE>} beginRoot - The `beginRoot` parameter represents the
8641
+ * starting point for finding the rightmost node in a binary tree. It can be either a root node
8642
+ * (`R`), a key or node or entry (`KeyOrNodeOrEntry<K, V, NODE>`), or `null` or `undefined`.
8643
+ * @param {IterationType} iterationType - The `iterationType` parameter is used to specify the type
8644
+ * of iteration to be performed when finding the rightmost node in a binary tree. It can have two
8645
+ * possible values:
8646
+ * @returns The function `getRightMost` returns a NODE object, `null`, or `undefined`.
8612
8647
  */
8613
8648
  getRightMost(beginRoot = this.root, iterationType = this.iterationType) {
8614
8649
  if (this.isNIL(beginRoot))
@@ -8640,10 +8675,10 @@ var dataStructureTyped = (() => {
8640
8675
  * Time Complexity: O(log n)
8641
8676
  * Space Complexity: O(1)
8642
8677
  *
8643
- * The function returns the predecessor of a given node in a tree.
8644
- * @param {NODE} node - The parameter `node` is of type `RedBlackTreeNode`, which represents a node in a
8678
+ * The function returns the predecessor node of a given node in a binary tree.
8679
+ * @param {NODE} node - The parameter "node" is of type "NODE", which represents a node in a binary
8645
8680
  * tree.
8646
- * @returns the predecessor of the given 'node'.
8681
+ * @returns the predecessor node of the given node.
8647
8682
  */
8648
8683
  getPredecessor(node) {
8649
8684
  if (this.isRealNode(node.left)) {
@@ -8668,8 +8703,8 @@ var dataStructureTyped = (() => {
8668
8703
  *
8669
8704
  * The function `getSuccessor` returns the next node in a binary tree given a current node.
8670
8705
  * @param {K | NODE | null} [x] - The parameter `x` can be of type `K`, `NODE`, or `null`.
8671
- * @returns the successor of the given node or key. The successor is the node that comes immediately
8672
- * after the given node in the inorder traversal of the binary tree.
8706
+ * @returns The function `getSuccessor` returns a `NODE` object if a successor exists, `null` if
8707
+ * there is no successor, and `undefined` if the input `x` is not a valid node.
8673
8708
  */
8674
8709
  getSuccessor(x) {
8675
8710
  x = this.ensureNode(x);
@@ -8686,41 +8721,40 @@ var dataStructureTyped = (() => {
8686
8721
  return y;
8687
8722
  }
8688
8723
  /**
8689
- * Time complexity: O(n)
8690
- * Space complexity: O(n)
8691
- * /
8692
-
8693
- /**
8694
- * Time complexity: O(n)
8695
- * Space complexity: O(n)
8696
- *
8697
- * The `dfs` function performs a depth-first search traversal on a binary tree or graph, based on the
8698
- * specified pattern and iteration type, and returns an array of values obtained from applying a
8699
- * callback function to each visited node.
8700
- * @param {C} callback - The `callback` parameter is a function that will be called for each node in
8701
- * the tree during the depth-first search. It takes a single parameter, which can be of type `NODE`,
8702
- * `null`, or `undefined`, and returns a value of any type. The default value for this parameter is
8703
- * @param {DFSOrderPattern} [pattern=in] - The `pattern` parameter determines the order in which the
8704
- * nodes are traversed during the depth-first search. It can have one of the following values:
8705
- * @param {K | NODE | null | undefined} beginRoot - The `beginRoot` parameter is the starting node
8706
- * for the depth-first search traversal. It can be specified as a key, a node object, or
8707
- * `null`/`undefined`. If not provided, the `beginRoot` will default to the root node of the tree.
8708
- * @param {IterationType} iterationType - The `iterationType` parameter determines the type of
8709
- * iteration to use when traversing the tree. It can have one of the following values:
8710
- * @param [includeNull=false] - The `includeNull` parameter is a boolean value that determines
8711
- * whether null or undefined nodes should be included in the traversal. If `includeNull` is set to
8712
- * `true`, null or undefined nodes will be included in the traversal. If `includeNull` is set to
8713
- * `false`, null or undefined
8714
- * @returns an array of values that are the return values of the callback function.
8715
- */
8716
- dfs(callback = this._DEFAULT_CALLBACK, pattern = "IN", beginRoot = this.root, iterationType = "ITERATIVE", includeNull = false) {
8717
- beginRoot = this.ensureNode(beginRoot);
8718
- if (!beginRoot)
8719
- return [];
8720
- const ans = [];
8721
- if (iterationType === "RECURSIVE") {
8722
- const dfs = (node) => {
8723
- switch (pattern) {
8724
+ * Time complexity: O(n)
8725
+ * Space complexity: O(n)
8726
+ */
8727
+ /**
8728
+ * Time complexity: O(n)
8729
+ * Space complexity: O(n)
8730
+ *
8731
+ * The `dfs` function performs a depth-first search traversal on a binary tree, executing a callback
8732
+ * function on each node according to a specified pattern and iteration type.
8733
+ * @param {C} callback - The `callback` parameter is a function that will be called for each node
8734
+ * visited during the depth-first search. It takes a node as an argument and returns a value. The
8735
+ * return type of the callback function is determined by the generic type `C`.
8736
+ * @param {DFSOrderPattern} [pattern=IN] - The `pattern` parameter determines the order in which the
8737
+ * nodes are visited during the depth-first search. It can have one of the following values:
8738
+ * @param {R | KeyOrNodeOrEntry<K, V, NODE>} beginRoot - The `beginRoot` parameter is the starting
8739
+ * point of the depth-first search. It can be either a node object, a key-value pair, or a key. If it
8740
+ * is a key or key-value pair, the method will find the corresponding node in the tree and start the
8741
+ * search from there.
8742
+ * @param {IterationType} [iterationType=ITERATIVE] - The `iterationType` parameter determines the
8743
+ * type of iteration to use during the depth-first search. It can have two possible values:
8744
+ * @param [includeNull=false] - The `includeNull` parameter is a boolean value that determines
8745
+ * whether or not to include null values in the depth-first search traversal. If `includeNull` is set
8746
+ * to `true`, null values will be included in the traversal. If `includeNull` is set to `false`, null
8747
+ * values will
8748
+ * @returns an array of the return types of the callback function.
8749
+ */
8750
+ dfs(callback = this._DEFAULT_CALLBACK, pattern = "IN", beginRoot = this.root, iterationType = "ITERATIVE", includeNull = false) {
8751
+ beginRoot = this.ensureNode(beginRoot);
8752
+ if (!beginRoot)
8753
+ return [];
8754
+ const ans = [];
8755
+ if (iterationType === "RECURSIVE") {
8756
+ const dfs = (node) => {
8757
+ switch (pattern) {
8724
8758
  case "IN":
8725
8759
  if (includeNull) {
8726
8760
  if (this.isRealNode(node) && this.isNodeOrNull(node.left))
@@ -8820,22 +8854,23 @@ var dataStructureTyped = (() => {
8820
8854
  * Time complexity: O(n)
8821
8855
  * Space complexity: O(n)
8822
8856
  *
8823
- * The `bfs` function performs a breadth-first search traversal on a binary tree, executing a
8824
- * callback function on each node.
8857
+ * The `bfs` function performs a breadth-first search on a binary tree, calling a callback function
8858
+ * on each node and returning an array of the results.
8825
8859
  * @param {C} callback - The `callback` parameter is a function that will be called for each node in
8826
- * the breadth-first search traversal. It takes a single parameter, which is the current node being
8860
+ * the breadth-first search traversal. It takes a single argument, which is the current node being
8827
8861
  * visited, and returns a value of any type.
8828
- * @param {K | NODE | null | undefined} beginRoot - The `beginRoot` parameter represents the
8829
- * starting node for the breadth-first search traversal. It can be specified as a key, a node object,
8830
- * or `null`/`undefined` to indicate the root of the tree. If not provided, the `root` property of
8831
- * the class is used as
8832
- * @param iterationType - The `iterationType` parameter determines the type of iteration to be
8833
- * performed during the breadth-first search (BFS). It can have two possible values:
8834
- * @param [includeNull=false] - The `includeNull` parameter is a boolean flag that determines whether
8835
- * to include null values in the breadth-first search traversal. If `includeNull` is set to
8836
- * `true`, null values will be included in the traversal, otherwise they will be skipped.
8837
- * @returns an array of values that are the result of invoking the callback function on each node in
8838
- * the breadth-first traversal of a binary tree.
8862
+ * @param {R | KeyOrNodeOrEntry<K, V, NODE>} beginRoot - The `beginRoot` parameter represents the
8863
+ * starting point of the breadth-first search. It can be either a root node of a tree or a key, node,
8864
+ * or entry object. If no value is provided, the `root` property of the class is used as the default
8865
+ * starting point.
8866
+ * @param {IterationType} iterationType - The `iterationType` parameter determines the type of
8867
+ * iteration to be performed. It can have two possible values:
8868
+ * @param [includeNull=false] - The `includeNull` parameter is a boolean value that determines
8869
+ * whether or not to include null values in the breadth-first search (BFS) traversal. If
8870
+ * `includeNull` is set to `true`, null values will be included in the traversal. If `includeNull` is
8871
+ * set to `false
8872
+ * @returns The function `bfs` returns an array of values that are the result of invoking the
8873
+ * `callback` function on each node in the breadth-first order traversal of the binary tree.
8839
8874
  */
8840
8875
  bfs(callback = this._DEFAULT_CALLBACK, beginRoot = this.root, iterationType = this.iterationType, includeNull = false) {
8841
8876
  beginRoot = this.ensureNode(beginRoot);
@@ -8895,18 +8930,18 @@ var dataStructureTyped = (() => {
8895
8930
  * Space complexity: O(n)
8896
8931
  *
8897
8932
  * The `listLevels` function returns an array of arrays, where each inner array represents a level in
8898
- * a binary tree and contains the values returned by a callback function applied to the nodes at that
8899
- * level.
8933
+ * a binary tree and contains the results of applying a callback function to the nodes at that level.
8900
8934
  * @param {C} callback - The `callback` parameter is a function that will be called for each node in
8901
- * the tree. It takes a single parameter, which can be of type `NODE`, `null`, or `undefined`, and
8902
- * returns a value of any type.
8903
- * @param {K | NODE | null | undefined} beginRoot - The `beginRoot` parameter represents the
8904
- * starting node for traversing the tree. It can be either a node object (`NODE`), a key value
8905
- * (`K`), `null`, or `undefined`. If not provided, it defaults to the root node of the tree.
8906
- * @param iterationType - The `iterationType` parameter determines the type of iteration to be
8907
- * performed on the tree. It can have two possible values:
8935
+ * the tree. It takes a node as an argument and returns a value. The return type of the callback
8936
+ * function is determined by the generic type `C` which extends `BTNCallback<NODE | null>`.
8937
+ * @param {R | KeyOrNodeOrEntry<K, V, NODE>} beginRoot - The `beginRoot` parameter represents the
8938
+ * starting point for traversing the tree. It can be either a root node, a key-value pair, or a node
8939
+ * entry. If no value is provided, the `root` property of the class is used as the default starting
8940
+ * point.
8941
+ * @param {IterationType} iterationType - The `iterationType` parameter determines the type of
8942
+ * iteration to be performed on the binary tree. It can have two possible values:
8908
8943
  * @param [includeNull=false] - The `includeNull` parameter is a boolean value that determines
8909
- * whether to include null values in the resulting levels. If `includeNull` is set to `true`,
8944
+ * whether or not to include null values in the resulting levels. If `includeNull` is set to `true`,
8910
8945
  * null values will be included in the levels. If `includeNull` is set to `false`, null values will
8911
8946
  * be excluded
8912
8947
  * @returns The function `listLevels` returns a two-dimensional array of type `ReturnType<C>[][]`.
@@ -8968,17 +9003,17 @@ var dataStructureTyped = (() => {
8968
9003
  * The `morris` function performs a depth-first traversal on a binary tree using the Morris traversal
8969
9004
  * algorithm.
8970
9005
  * @param {C} callback - The `callback` parameter is a function that will be called for each node in
8971
- * the tree. It takes a single parameter of type `NODE` (the type of the nodes in the tree) and returns
8972
- * a value of any type.
8973
- * @param {DFSOrderPattern} [pattern=in] - The `pattern` parameter in the `morris` function
8974
- * determines the order in which the nodes of a binary tree are traversed. It can have one of the
9006
+ * the tree. It takes a single argument, which is the current node, and can return any value. The
9007
+ * return type of the `callback` function is determined by the `ReturnType<C>` type, which represents
9008
+ * the return
9009
+ * @param {DFSOrderPattern} [pattern=IN] - The `pattern` parameter in the `morris` function is used
9010
+ * to specify the order in which the nodes of a binary tree are traversed. It can take one of the
8975
9011
  * following values:
8976
- * @param {K | NODE | null | undefined} beginRoot - The `beginRoot` parameter is the starting node
8977
- * for the traversal. It can be specified as a key, a node object, or `null`/`undefined` to indicate
8978
- * the root of the tree. If no value is provided, the default value is the root of the tree.
8979
- * @returns The function `morris` returns an array of values that are the result of invoking the
8980
- * `callback` function on each node in the binary tree. The type of the array nodes is determined
8981
- * by the return type of the `callback` function.
9012
+ * @param {R | KeyOrNodeOrEntry<K, V, NODE>} beginRoot - The `beginRoot` parameter is the starting
9013
+ * point for the traversal. It can be either a node object, a key, or an entry object. If no value is
9014
+ * provided, the `root` of the tree is used as the starting point.
9015
+ * @returns The function `morris` returns an array of values that are the return values of the
9016
+ * callback function `callback`.
8982
9017
  */
8983
9018
  morris(callback = this._DEFAULT_CALLBACK, pattern = "IN", beginRoot = this.root) {
8984
9019
  beginRoot = this.ensureNode(beginRoot);
@@ -9069,8 +9104,7 @@ var dataStructureTyped = (() => {
9069
9104
  * Time complexity: O(n)
9070
9105
  * Space complexity: O(n)
9071
9106
  *
9072
- * The `clone` function creates a new tree object and copies all the nodes from the original tree to
9073
- * the new tree.
9107
+ * The `clone` function creates a deep copy of a tree object.
9074
9108
  * @returns The `clone()` method is returning a cloned instance of the `TREE` object.
9075
9109
  */
9076
9110
  clone() {
@@ -9096,16 +9130,16 @@ var dataStructureTyped = (() => {
9096
9130
  * Time Complexity: O(n)
9097
9131
  * Space Complexity: O(n)
9098
9132
  *
9099
- * The `filter` function creates a new tree by iterating over the nodes of the current tree and
9100
- * adding only the nodes that satisfy the given predicate function.
9101
- * @param predicate - The `predicate` parameter is a function that takes three arguments: `value`,
9102
- * `key`, and `index`. It should return a boolean value indicating whether the pair should be
9103
- * included in the filtered tree or not.
9104
- * @param {any} [thisArg] - The `thisArg` parameter is an optional argument that specifies the value
9105
- * to be used as the `this` value when executing the `predicate` function. If `thisArg` is provided,
9106
- * it will be passed as the first argument to the `predicate` function. If `thisArg` is
9107
- * @returns The `filter` method is returning a new tree object that contains the key-value pairs that
9108
- * pass the given predicate function.
9133
+ * The `filter` function creates a new tree with entries that pass a given predicate function.
9134
+ * @param predicate - The `predicate` parameter is a callback function that is used to test each
9135
+ * element in the tree. It takes three arguments: `value`, `key`, and `index`. The `value` argument
9136
+ * represents the value of the current element being processed, the `key` argument represents the key
9137
+ * of the
9138
+ * @param {any} [thisArg] - The `thisArg` parameter is an optional argument that allows you to
9139
+ * specify the value of `this` within the `predicate` function. When the `predicate` function is
9140
+ * called, `thisArg` will be used as the value of `this` within the function. If `thisArg`
9141
+ * @returns The `filter` method is returning a new tree object that contains the entries that pass
9142
+ * the given predicate function.
9109
9143
  */
9110
9144
  filter(predicate, thisArg) {
9111
9145
  const newTree = this.createTree();
@@ -9125,15 +9159,15 @@ var dataStructureTyped = (() => {
9125
9159
  * Time Complexity: O(n)
9126
9160
  * Space Complexity: O(n)
9127
9161
  *
9128
- * The `map` function creates a new tree by applying a callback function to each key-value pair in
9129
- * the original tree.
9130
- * @param callback - The callback parameter is a function that will be called for each key-value pair
9131
- * in the tree. It takes four arguments: the value of the current pair, the key of the current pair,
9132
- * the index of the current pair, and a reference to the tree itself. The callback function should
9133
- * return a new
9134
- * @param {any} [thisArg] - The `thisArg` parameter is an optional argument that allows you to
9135
- * specify the value of `this` within the callback function. If you pass a value for `thisArg`, it
9136
- * will be used as the `this` value when the callback function is called. If you don't pass a value
9162
+ * The `map` function creates a new tree by applying a callback function to each entry in the current
9163
+ * tree.
9164
+ * @param callback - The callback parameter is a function that will be called for each entry in the
9165
+ * tree. It takes three arguments: value, key, and index. The value argument represents the value of
9166
+ * the current entry, the key argument represents the key of the current entry, and the index
9167
+ * argument represents the index of the
9168
+ * @param {any} [thisArg] - The `thisArg` parameter is an optional argument that specifies the value
9169
+ * to be used as `this` when executing the `callback` function. If `thisArg` is provided, it will be
9170
+ * passed as the `this` value to the `callback` function. If `thisArg` is
9137
9171
  * @returns The `map` method is returning a new tree object.
9138
9172
  */
9139
9173
  map(callback, thisArg) {
@@ -9161,11 +9195,15 @@ var dataStructureTyped = (() => {
9161
9195
  * Time Complexity: O(n)
9162
9196
  * Space Complexity: O(n)
9163
9197
  *
9164
- * The `print` function is used to display a binary tree structure in a visually appealing way.
9165
- * @param {K | NODE | null | undefined} [beginRoot=this.root] - The `root` parameter is of type `K | NODE | null |
9166
- * undefined`. It represents the root node of a binary tree. The root node can have one of the
9167
- * following types:
9168
- * @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.
9198
+ * The `print` function in TypeScript prints the binary tree structure with customizable options.
9199
+ * @param {R | KeyOrNodeOrEntry<K, V, NODE>} beginRoot - The `beginRoot` parameter is the starting
9200
+ * point for printing the binary tree. It can be either a node of the binary tree or a key or entry
9201
+ * that exists in the binary tree. If no value is provided, the root of the binary tree will be used
9202
+ * as the starting point.
9203
+ * @param {BinaryTreePrintOptions} [options] - The `options` parameter is an optional object that
9204
+ * allows you to customize the printing behavior. It has the following properties:
9205
+ * @returns Nothing is being returned. The function has a return type of `void`, which means it does
9206
+ * not return any value.
9169
9207
  */
9170
9208
  print(beginRoot = this.root, options) {
9171
9209
  const opts = __spreadValues({ isShowUndefined: false, isShowNull: false, isShowRedBlackNIL: false }, options);
@@ -9190,13 +9228,18 @@ var dataStructureTyped = (() => {
9190
9228
  display(beginRoot);
9191
9229
  }
9192
9230
  /**
9193
- * The function `_getIterator` is a protected generator function that returns an iterator for the
9194
- * key-value pairs in a binary search tree.
9195
- * @param node - The `node` parameter represents the current node in the binary search tree. It is an
9196
- * optional parameter with a default value of `this.root`, which means if no node is provided, the
9197
- * root node of the tree will be used as the starting point for iteration.
9198
- * @returns The function `_getIterator` returns an `IterableIterator` of key-value pairs `[K, V |
9199
- * undefined]`.
9231
+ * Time Complexity: O(1)
9232
+ * Space Complexity: O(1)
9233
+ */
9234
+ /**
9235
+ * Time Complexity: O(1)
9236
+ * Space Complexity: O(1)
9237
+ *
9238
+ * The function `_getIterator` is a generator function that returns an iterator for the key-value
9239
+ * pairs in a binary search tree.
9240
+ * @param node - The `node` parameter represents the current node in the binary search tree. It is
9241
+ * initially set to the root node of the tree.
9242
+ * @returns an IterableIterator<[K, V | undefined]>.
9200
9243
  */
9201
9244
  *_getIterator(node = this.root) {
9202
9245
  if (!node)
@@ -9226,6 +9269,13 @@ var dataStructureTyped = (() => {
9226
9269
  }
9227
9270
  }
9228
9271
  /**
9272
+ * Time Complexity: O(n)
9273
+ * Space Complexity: O(n)
9274
+ */
9275
+ /**
9276
+ * Time Complexity: O(n)
9277
+ * Space Complexity: O(n)
9278
+ *
9229
9279
  * The `_displayAux` function is responsible for generating the display layout of a binary tree node,
9230
9280
  * taking into account various options such as whether to show null, undefined, or NaN nodes.
9231
9281
  * @param {NODE | null | undefined} node - The `node` parameter represents a node in a binary tree.
@@ -9280,10 +9330,21 @@ var dataStructureTyped = (() => {
9280
9330
  }
9281
9331
  }
9282
9332
  /**
9283
- * Swap the data of two nodes in the binary tree.
9284
- * @param {NODE} srcNode - The source node to swap.
9285
- * @param {NODE} destNode - The destination node to swap.
9286
- * @returns {NODE} - The destination node after the swap.
9333
+ * Time Complexity: O(1)
9334
+ * Space Complexity: O(1)
9335
+ */
9336
+ /**
9337
+ * Time Complexity: O(1)
9338
+ * Space Complexity: O(1)
9339
+ *
9340
+ * The function `_swapProperties` swaps the key-value properties between two nodes.
9341
+ * @param {R | KeyOrNodeOrEntry<K, V, NODE>} srcNode - The source node that will be swapped with the
9342
+ * destination node. It can be either an instance of the class `R`, or an object of type
9343
+ * `KeyOrNodeOrEntry<K, V, NODE>`.
9344
+ * @param {R | KeyOrNodeOrEntry<K, V, NODE>} destNode - The `destNode` parameter is the node where
9345
+ * the properties will be swapped with the `srcNode`.
9346
+ * @returns either the `destNode` object with its properties swapped with the `srcNode` object's
9347
+ * properties, or `undefined` if either `srcNode` or `destNode` is falsy.
9287
9348
  */
9288
9349
  _swapProperties(srcNode, destNode) {
9289
9350
  srcNode = this.ensureNode(srcNode);
@@ -9302,12 +9363,20 @@ var dataStructureTyped = (() => {
9302
9363
  return void 0;
9303
9364
  }
9304
9365
  /**
9305
- * The function replaces an old node with a new node in a binary tree.
9366
+ * Time Complexity: O(1)
9367
+ * Space Complexity: O(1)
9368
+ */
9369
+ /**
9370
+ * Time Complexity: O(1)
9371
+ * Space Complexity: O(1)
9372
+ *
9373
+ * The function replaces a node in a binary tree with a new node, updating the parent, left child,
9374
+ * right child, and root if necessary.
9306
9375
  * @param {NODE} oldNode - The oldNode parameter represents the node that needs to be replaced in the
9307
9376
  * tree.
9308
9377
  * @param {NODE} newNode - The `newNode` parameter is the node that will replace the `oldNode` in the
9309
9378
  * tree.
9310
- * @returns The method is returning the newNode.
9379
+ * @returns the newNode.
9311
9380
  */
9312
9381
  _replaceNode(oldNode, newNode) {
9313
9382
  if (oldNode.parent) {
@@ -9326,10 +9395,17 @@ var dataStructureTyped = (() => {
9326
9395
  return newNode;
9327
9396
  }
9328
9397
  /**
9329
- * The function sets the root property of an object to a given value, and if the value is not null,
9330
- * it also sets the parent property of the value to undefined.
9331
- * @param {NODE | null | undefined} v - The parameter `v` is of type `NODE | null | undefined`, which means it can either be of
9332
- * type `NODE` or `null`.
9398
+ * Time Complexity: O(1)
9399
+ * Space Complexity: O(1)
9400
+ */
9401
+ /**
9402
+ * Time Complexity: O(1)
9403
+ * Space Complexity: O(1)
9404
+ *
9405
+ * The function sets the root property of an object to the provided value, and also updates the
9406
+ * parent property of the new root.
9407
+ * @param {NODE | null | undefined} v - The parameter `v` is of type `NODE | null | undefined`. This
9408
+ * means that it can accept a value of type `NODE`, `null`, or `undefined`.
9333
9409
  */
9334
9410
  _setRoot(v) {
9335
9411
  if (v) {
@@ -9337,6 +9413,23 @@ var dataStructureTyped = (() => {
9337
9413
  }
9338
9414
  this._root = v;
9339
9415
  }
9416
+ /**
9417
+ * Time Complexity: O(1)
9418
+ * Space Complexity: O(1)
9419
+ */
9420
+ /**
9421
+ * Time Complexity: O(1)
9422
+ * Space Complexity: O(1)
9423
+ *
9424
+ * The function `_ensureCallback` ensures that a callback function is provided and returns it.
9425
+ * @param {ReturnType<C> | null | undefined} identifier - The `identifier` parameter is of type
9426
+ * `ReturnType<C> | null | undefined`. This means it can accept a value that is the return type of
9427
+ * the generic type `C`, or it can be `null` or `undefined`.
9428
+ * @param {C} callback - The `callback` parameter is a function that takes a `node` as an argument
9429
+ * and returns a value. It is of type `C`, which is a generic type that extends the
9430
+ * `BTNCallback<NODE>` type.
9431
+ * @returns the callback parameter.
9432
+ */
9340
9433
  _ensureCallback(identifier, callback = this._DEFAULT_CALLBACK) {
9341
9434
  if ((!callback || callback === this._DEFAULT_CALLBACK) && this.isNode(identifier)) {
9342
9435
  callback = (node) => node;
@@ -9396,31 +9489,44 @@ var dataStructureTyped = (() => {
9396
9489
  };
9397
9490
  var BST = class _BST extends BinaryTree {
9398
9491
  /**
9399
- * This is the constructor function for a Binary Search Tree class in TypeScript, which initializes
9400
- * the tree with keys, nodes, or entries and optional options.
9401
- * @param keysOrNodesOrEntries - The `keysOrNodesOrEntries` parameter is an iterable object that can
9402
- * contain keys, nodes, or entries. It is used to initialize the binary search tree with the provided
9403
- * keys, nodes, or entries.
9404
- * @param [options] - The `options` parameter is an optional object that can contain additional
9405
- * configuration options for the binary search tree. It can have the following properties:
9492
+ * This is the constructor function for a Binary Search Tree class in TypeScript.
9493
+ * @param keysOrNodesOrEntriesOrRawElements - The `keysOrNodesOrEntriesOrRawElements` parameter is an
9494
+ * iterable that can contain either keys, nodes, entries, or raw elements. These elements will be
9495
+ * added to the binary search tree during the construction of the object.
9496
+ * @param [options] - An optional object that contains additional options for the Binary Search Tree.
9497
+ * It can include a comparator function that defines the order of the elements in the tree.
9406
9498
  */
9407
- constructor(keysOrNodesOrEntries = [], options) {
9499
+ constructor(keysOrNodesOrEntriesOrRawElements = [], options) {
9408
9500
  super([], options);
9409
9501
  __publicField(this, "_root");
9410
- __publicField(this, "_comparator", (a, b) => {
9502
+ /**
9503
+ * Time complexity: O(n)
9504
+ * Space complexity: O(n)
9505
+ */
9506
+ __publicField(this, "_DEFAULT_COMPARATOR", (a, b) => {
9507
+ if (typeof a === "object" && typeof b === "object" && this.comparator === this._DEFAULT_COMPARATOR) {
9508
+ throw TypeError(
9509
+ "When comparing two object types, it is necessary to customize a [comparator] function of options parameter during the instantiation of the data structure."
9510
+ );
9511
+ }
9411
9512
  if (a > b)
9412
9513
  return 1;
9413
9514
  if (a < b)
9414
9515
  return -1;
9415
9516
  return 0;
9416
9517
  });
9518
+ /**
9519
+ * Time complexity: O(n)
9520
+ * Space complexity: O(n)
9521
+ */
9522
+ __publicField(this, "_comparator", this._DEFAULT_COMPARATOR);
9417
9523
  if (options) {
9418
9524
  const { comparator } = options;
9419
9525
  if (comparator)
9420
9526
  this._comparator = comparator;
9421
9527
  }
9422
- if (keysOrNodesOrEntries)
9423
- this.addMany(keysOrNodesOrEntries);
9528
+ if (keysOrNodesOrEntriesOrRawElements)
9529
+ this.addMany(keysOrNodesOrEntriesOrRawElements);
9424
9530
  }
9425
9531
  /**
9426
9532
  * The function returns the root node of a tree structure.
@@ -9429,13 +9535,6 @@ var dataStructureTyped = (() => {
9429
9535
  get root() {
9430
9536
  return this._root;
9431
9537
  }
9432
- /**
9433
- * The function returns the value of the _comparator property.
9434
- * @returns The `_comparator` property is being returned.
9435
- */
9436
- get comparator() {
9437
- return this._comparator;
9438
- }
9439
9538
  /**
9440
9539
  * The function creates a new BSTNode with the given key and value and returns it.
9441
9540
  * @param {K} key - The key parameter is of type K, which represents the type of the key for the node
@@ -9450,10 +9549,9 @@ var dataStructureTyped = (() => {
9450
9549
  /**
9451
9550
  * The function creates a new binary search tree with the specified options.
9452
9551
  * @param [options] - The `options` parameter is an optional object that allows you to customize the
9453
- * behavior of the `createTree` method. It is of type `Partial<BSTOptions<K>>`, which means it is a
9454
- * partial object of type `BSTOptions<K>`.
9455
- * @returns a new instance of the BST class, with the provided options merged with the default
9456
- * options. The returned value is casted as TREE.
9552
+ * behavior of the `createTree` method. It accepts a partial `BSTOptions` object, which has the
9553
+ * following properties:
9554
+ * @returns a new instance of the BST class with the provided options.
9457
9555
  */
9458
9556
  createTree(options) {
9459
9557
  return new _BST([], __spreadValues({
@@ -9462,90 +9560,60 @@ var dataStructureTyped = (() => {
9462
9560
  }, options));
9463
9561
  }
9464
9562
  /**
9465
- * The function `keyValueOrEntryToNode` takes an keyOrNodeOrEntry and returns a node if the keyOrNodeOrEntry is valid,
9466
- * otherwise it returns undefined.
9467
- * @param keyOrNodeOrEntry - The `keyOrNodeOrEntry` parameter is of type `KeyOrNodeOrEntry<K, V, NODE>`, where:
9468
- * @param {V} [value] - The `value` parameter is an optional value that can be passed to the
9469
- * `keyValueOrEntryToNode` function. It represents the value associated with the keyOrNodeOrEntry node.
9470
- * @returns a node of type NODE or undefined.
9563
+ * The function overrides a method and converts a key, value pair or entry or raw element to a node.
9564
+ * @param {R | KeyOrNodeOrEntry<K, V, NODE>} keyOrNodeOrEntryOrRawElement - A variable that can be of
9565
+ * type R or KeyOrNodeOrEntry<K, V, NODE>. It represents either a key, a node, an entry, or a raw
9566
+ * element.
9567
+ * @param {V} [value] - The `value` parameter is an optional value of type `V`. It represents the
9568
+ * value associated with a key in a key-value pair.
9569
+ * @returns either a NODE object or undefined.
9471
9570
  */
9472
- keyValueOrEntryToNode(keyOrNodeOrEntry, value) {
9473
- let node;
9474
- if (keyOrNodeOrEntry === null || keyOrNodeOrEntry === void 0) {
9475
- return;
9476
- } else if (this.isNode(keyOrNodeOrEntry)) {
9477
- node = keyOrNodeOrEntry;
9478
- } else if (this.isEntry(keyOrNodeOrEntry)) {
9479
- const [key, value2] = keyOrNodeOrEntry;
9480
- if (key === void 0 || key === null) {
9481
- return;
9482
- } else {
9483
- node = this.createNode(key, value2);
9484
- }
9485
- } else if (!this.isNode(keyOrNodeOrEntry)) {
9486
- node = this.createNode(keyOrNodeOrEntry, value);
9487
- } else {
9488
- return;
9489
- }
9490
- return node;
9571
+ keyValueOrEntryOrRawElementToNode(keyOrNodeOrEntryOrRawElement, value) {
9572
+ var _a;
9573
+ return (_a = super.keyValueOrEntryOrRawElementToNode(keyOrNodeOrEntryOrRawElement, value)) != null ? _a : void 0;
9491
9574
  }
9492
- /**
9493
- * Time Complexity: O(log n)
9494
- * Space Complexity: O(log n)
9495
- */
9496
9575
  /**
9497
9576
  * Time Complexity: O(log n)
9498
9577
  * Space Complexity: O(log n)
9499
9578
  *
9500
- * The function `ensureNode` returns the node corresponding to the given key if it is a node key,
9501
- * otherwise it returns the key itself.
9502
- * @param {K | NODE | undefined} keyOrNodeOrEntry - The `key` parameter can be of type `K`, `NODE`, or
9503
- * `undefined`.
9504
- * @param iterationType - The `iterationType` parameter is an optional parameter that specifies the
9505
- * type of iteration to be performed. It has a default value of `'ITERATIVE'`.
9506
- * @returns either a node object (NODE) or undefined.
9507
- */
9508
- ensureNode(keyOrNodeOrEntry, iterationType = "ITERATIVE") {
9509
- if (keyOrNodeOrEntry === this.NIL)
9510
- return;
9511
- if (this.isRealNode(keyOrNodeOrEntry)) {
9512
- return keyOrNodeOrEntry;
9513
- }
9514
- if (this.isEntry(keyOrNodeOrEntry)) {
9515
- const key2 = keyOrNodeOrEntry[0];
9516
- if (key2 === null || key2 === void 0)
9517
- return;
9518
- return this.getNodeByKey(key2, iterationType);
9519
- }
9520
- const key = keyOrNodeOrEntry;
9521
- if (key === null || key === void 0)
9522
- return;
9523
- return this.getNodeByKey(key, iterationType);
9579
+ * The function ensures the existence of a node in a data structure and returns it, or undefined if
9580
+ * it doesn't exist.
9581
+ * @param {R | KeyOrNodeOrEntry<K, V, NODE>} keyOrNodeOrEntryOrRawElement - The parameter
9582
+ * `keyOrNodeOrEntryOrRawElement` can accept a value of type `R`, which represents the key, node,
9583
+ * entry, or raw element that needs to be ensured in the tree.
9584
+ * @param {IterationType} [iterationType=ITERATIVE] - The `iterationType` parameter is an optional
9585
+ * parameter that specifies the type of iteration to be used when ensuring a node. It has a default
9586
+ * value of `'ITERATIVE'`.
9587
+ * @returns The method is returning either the node that was ensured or `undefined` if the node could
9588
+ * not be ensured.
9589
+ */
9590
+ ensureNode(keyOrNodeOrEntryOrRawElement, iterationType = "ITERATIVE") {
9591
+ var _a;
9592
+ return (_a = super.ensureNode(keyOrNodeOrEntryOrRawElement, iterationType)) != null ? _a : void 0;
9524
9593
  }
9525
9594
  /**
9526
- * The function checks if an keyOrNodeOrEntry is an instance of BSTNode.
9527
- * @param keyOrNodeOrEntry - The `keyOrNodeOrEntry` parameter is a variable of type `KeyOrNodeOrEntry<K, V, NODE>`.
9528
- * @returns a boolean value indicating whether the keyOrNodeOrEntry is an instance of the BSTNode class.
9595
+ * The function checks if the input is an instance of the BSTNode class.
9596
+ * @param {R | KeyOrNodeOrEntry<K, V, NODE>} keyOrNodeOrEntryOrRawElement - The parameter
9597
+ * `keyOrNodeOrEntryOrRawElement` can be of type `R` or `KeyOrNodeOrEntry<K, V, NODE>`.
9598
+ * @returns a boolean value indicating whether the input parameter `keyOrNodeOrEntryOrRawElement` is
9599
+ * an instance of the `BSTNode` class.
9529
9600
  */
9530
- isNode(keyOrNodeOrEntry) {
9531
- return keyOrNodeOrEntry instanceof BSTNode;
9601
+ isNode(keyOrNodeOrEntryOrRawElement) {
9602
+ return keyOrNodeOrEntryOrRawElement instanceof BSTNode;
9532
9603
  }
9533
- /**
9534
- * Time Complexity: O(log n)
9535
- * Space Complexity: O(1)
9536
- */
9537
9604
  /**
9538
9605
  * Time Complexity: O(log n)
9539
9606
  * Space Complexity: O(1)
9540
9607
  *
9541
- * The `add` function in TypeScript adds a new node to a binary search tree based on the key value,
9542
- * updating the value if the key already exists.
9543
- * @param keyOrNodeOrEntry - It is a parameter that can accept three types of values:
9544
- * @param {V} [value] - The value to be added to the binary search tree.
9545
- * @returns The method returns a boolean value.
9608
+ * The `add` function in TypeScript adds a new node to a binary search tree based on the key value.
9609
+ * @param {R | KeyOrNodeOrEntry<K, V, NODE>} keyOrNodeOrEntryOrRawElement - The parameter
9610
+ * `keyOrNodeOrEntryOrRawElement` can accept a value of type `R` or `KeyOrNodeOrEntry<K, V, NODE>`.
9611
+ * @param {V} [value] - The `value` parameter is an optional value that can be associated with the
9612
+ * key in the binary search tree. If provided, it will be stored in the node along with the key.
9613
+ * @returns a boolean value.
9546
9614
  */
9547
- add(keyOrNodeOrEntry, value) {
9548
- const newNode = this.keyValueOrEntryToNode(keyOrNodeOrEntry, value);
9615
+ add(keyOrNodeOrEntryOrRawElement, value) {
9616
+ const newNode = this.keyValueOrEntryOrRawElementToNode(keyOrNodeOrEntryOrRawElement, value);
9549
9617
  if (newNode === void 0)
9550
9618
  return false;
9551
9619
  if (this.root === void 0) {
@@ -9577,18 +9645,17 @@ var dataStructureTyped = (() => {
9577
9645
  return false;
9578
9646
  }
9579
9647
  /**
9580
- * Time Complexity: O(k log n)
9581
- * Space Complexity: O(k + log n)
9648
+ * Time Complexity: O(log n)
9649
+ * Space Complexity: O(log n)
9582
9650
  */
9583
9651
  /**
9584
9652
  * Time Complexity: O(k log n)
9585
9653
  * Space Complexity: O(k + log n)
9586
9654
  *
9587
- * The `addMany` function in TypeScript adds multiple keys or nodes to a data structure, balancing
9588
- * the structure if specified, and returns an array indicating whether each key or node was
9589
- * successfully inserted.
9590
- * @param keysOrNodesOrEntries - An iterable containing keys, nodes, or entries to be added to the
9591
- * data structure.
9655
+ * The `addMany` function in TypeScript adds multiple keys or nodes to a data structure and returns
9656
+ * an array indicating whether each key or node was successfully inserted.
9657
+ * @param keysOrNodesOrEntriesOrRawElements - An iterable containing keys, nodes, entries, or raw
9658
+ * elements to be added to the data structure.
9592
9659
  * @param [values] - An optional iterable of values to be associated with the keys or nodes being
9593
9660
  * added. If provided, the values will be assigned to the corresponding keys or nodes in the same
9594
9661
  * order. If not provided, undefined will be assigned as the value for each key or node.
@@ -9597,20 +9664,19 @@ var dataStructureTyped = (() => {
9597
9664
  * algorithm. If set to false, the elements will be added without balancing the tree. The default
9598
9665
  * value is true.
9599
9666
  * @param {IterationType} iterationType - The `iterationType` parameter is an optional parameter that
9600
- * specifies the type of iteration to use when adding multiple keys or nodes to the binary tree. It
9601
- * has a default value of `this.iterationType`, which means it will use the iteration type specified
9602
- * in the binary tree instance.
9603
- * @returns The function `addMany` returns an array of booleans indicating whether each key or node
9604
- * or entry was successfully inserted into the data structure.
9667
+ * specifies the type of iteration to use when adding multiple keys or nodes to the binary search
9668
+ * tree. It can have two possible values:
9669
+ * @returns The function `addMany` returns an array of booleans indicating whether each element was
9670
+ * successfully inserted into the data structure.
9605
9671
  */
9606
- addMany(keysOrNodesOrEntries, values, isBalanceAdd = true, iterationType = this.iterationType) {
9672
+ addMany(keysOrNodesOrEntriesOrRawElements, values, isBalanceAdd = true, iterationType = this.iterationType) {
9607
9673
  const inserted = [];
9608
9674
  let valuesIterator;
9609
9675
  if (values) {
9610
9676
  valuesIterator = values[Symbol.iterator]();
9611
9677
  }
9612
9678
  if (!isBalanceAdd) {
9613
- for (const kve of keysOrNodesOrEntries) {
9679
+ for (const kve of keysOrNodesOrEntriesOrRawElements) {
9614
9680
  const value = valuesIterator == null ? void 0 : valuesIterator.next().value;
9615
9681
  const nn = this.add(kve, value);
9616
9682
  inserted.push(nn);
@@ -9623,24 +9689,30 @@ var dataStructureTyped = (() => {
9623
9689
  return false;
9624
9690
  return !(this.isEntry(kve) && (kve[0] === void 0 || kve[0] === null));
9625
9691
  };
9626
- for (const kve of keysOrNodesOrEntries) {
9692
+ for (const kve of keysOrNodesOrEntriesOrRawElements) {
9627
9693
  isRealBTNExemplar(kve) && realBTNExemplars.push(kve);
9628
9694
  }
9629
9695
  let sorted = [];
9630
9696
  sorted = realBTNExemplars.sort((a, b) => {
9631
9697
  let keyA, keyB;
9632
- if (this.isEntry(a)) {
9698
+ if (this.isEntry(a))
9633
9699
  keyA = a[0];
9634
- } else if (this.isRealNode(a))
9700
+ else if (this.isRealNode(a))
9635
9701
  keyA = a.key;
9636
- else
9702
+ else if (this.toEntryFn) {
9703
+ keyA = this.toEntryFn(a)[0];
9704
+ } else {
9637
9705
  keyA = a;
9706
+ }
9638
9707
  if (this.isEntry(b))
9639
9708
  keyB = b[0];
9640
9709
  else if (this.isRealNode(b))
9641
9710
  keyB = b.key;
9642
- else
9711
+ else if (this.toEntryFn) {
9712
+ keyB = this.toEntryFn(b)[0];
9713
+ } else {
9643
9714
  keyB = b;
9715
+ }
9644
9716
  if (keyA !== void 0 && keyA !== null && keyB !== void 0 && keyB !== null) {
9645
9717
  return this.comparator(keyA, keyB);
9646
9718
  }
@@ -9680,33 +9752,27 @@ var dataStructureTyped = (() => {
9680
9752
  return inserted;
9681
9753
  }
9682
9754
  /**
9683
- * Time Complexity: O(log n)
9684
- * Space Complexity: O(k + log n)
9685
- * /
9686
-
9687
- /**
9688
- * Time Complexity: O(log n)
9689
- * Space Complexity: O(k + log n)
9690
- *
9691
- * The function `getNodes` returns an array of nodes that match a given identifier, using either a
9692
- * recursive or iterative approach.
9693
- * @param {ReturnType<C> | undefined} identifier - The `identifier` parameter is the value that you
9694
- * want to search for in the nodes of the binary tree. It can be of any type that is returned by the
9695
- * callback function `C`.
9696
- * @param {C} callback - The `callback` parameter is a function that takes a node of type `NODE` as its
9697
- * argument and returns a value of type `ReturnType<C>`. The `C` type parameter represents a callback
9698
- * function type that extends the `BTNCallback<NODE>` type. The `BTNCallback<NODE>` type is
9699
- * @param [onlyOne=false] - A boolean flag indicating whether to stop searching after finding the
9700
- * first node that matches the identifier. If set to true, the function will return an array
9701
- * containing only the first matching node. If set to false (default), the function will continue
9702
- * searching for all nodes that match the identifier and return an array containing
9703
- * @param {K | NODE | undefined} beginRoot - The `beginRoot` parameter represents the starting node
9704
- * for the traversal. It can be either a key value or a node object. If it is undefined, the
9705
- * traversal will start from the root of the tree.
9706
- * @param iterationType - The `iterationType` parameter determines the type of iteration to be
9707
- * performed on the binary tree. It can have two possible values:
9708
- * @returns The method returns an array of nodes (`NODE[]`).
9709
- */
9755
+ * Time Complexity: O(log n)
9756
+ * Space Complexity: O(k + log n)
9757
+ *
9758
+ * The `getNodes` function in TypeScript retrieves nodes from a binary tree based on a given
9759
+ * identifier and callback function.
9760
+ * @param {ReturnType<C> | undefined} identifier - The `identifier` parameter is the value that you
9761
+ * want to search for in the binary tree. It can be of any type that is returned by the callback
9762
+ * function.
9763
+ * @param {C} callback - The `callback` parameter is a function that takes a node as input and
9764
+ * returns a value. This value is used to identify the nodes that match the given identifier. The
9765
+ * `callback` function is optional and defaults to `this._DEFAULT_CALLBACK`.
9766
+ * @param [onlyOne=false] - A boolean value indicating whether to return only the first matching node
9767
+ * or all matching nodes. If set to true, only the first matching node will be returned. If set to
9768
+ * false, all matching nodes will be returned. The default value is false.
9769
+ * @param {R | KeyOrNodeOrEntry<K, V, NODE>} beginRoot - The `beginRoot` parameter is the starting
9770
+ * point for the search in the binary tree. It can be either a node object, a key-value pair, or an
9771
+ * entry object. If it is not provided, the `root` of the binary tree is used as the starting point.
9772
+ * @param {IterationType} iterationType - The `iterationType` parameter determines the type of
9773
+ * iteration to be performed. It can have two possible values:
9774
+ * @returns The method `getNodes` returns an array of `NODE` objects.
9775
+ */
9710
9776
  getNodes(identifier, callback = this._DEFAULT_CALLBACK, onlyOne = false, beginRoot = this.root, iterationType = this.iterationType) {
9711
9777
  beginRoot = this.ensureNode(beginRoot);
9712
9778
  if (!beginRoot)
@@ -9765,51 +9831,50 @@ var dataStructureTyped = (() => {
9765
9831
  * Time Complexity: O(log n)
9766
9832
  * Space Complexity: O(1)
9767
9833
  *
9768
- * The `getNode` function retrieves a node from a Red-Black Tree based on the provided identifier and
9769
- * callback function.
9770
- * @param {ReturnType<C> | undefined} identifier - The `identifier` parameter is the value or key
9771
- * that you want to search for in the binary search tree. It can be of any type that is compatible
9772
- * with the type of nodes in the tree.
9773
- * @param {C} callback - The `callback` parameter is a function that will be called for each node in
9774
- * the tree. It is used to determine whether a node matches the given identifier. The `callback`
9775
- * function should take a node as its parameter and return a value that can be compared to the
9776
- * `identifier` parameter.
9834
+ * The function `getNode` returns the first node that matches the given identifier and callback
9835
+ * function in a binary search tree.
9836
+ * @param {ReturnType<C> | undefined} identifier - The `identifier` parameter is the value that you
9837
+ * want to search for in the binary search tree. It can be of any type that is compatible with the
9838
+ * type returned by the callback function.
9839
+ * @param {C} callback - The `callback` parameter is a function that will be used to determine if a
9840
+ * node matches the desired criteria. It should be a function that takes a node as an argument and
9841
+ * returns a boolean value indicating whether the node matches the criteria or not. If no callback is
9842
+ * provided, the default callback will be
9777
9843
  * @param beginRoot - The `beginRoot` parameter is the starting point for the search in the binary
9778
- * search tree. It can be either a key or a node. If it is a key, it will be converted to a node
9779
- * using the `ensureNode` method. If it is not provided, the `root`
9780
- * @param iterationType - The `iterationType` parameter is used to specify the type of iteration to
9781
- * be performed when searching for nodes in the binary search tree. It is an optional parameter and
9782
- * its default value is taken from the `iterationType` property of the class.
9783
- * @returns The method is returning a value of type `NODE | null | undefined`.
9844
+ * search tree. It can be either a key or a node. If it is a key, the search will start from the node
9845
+ * with that key. If it is a node, the search will start from that node.
9846
+ * @param {IterationType} iterationType - The `iterationType` parameter is used to specify the type
9847
+ * of iteration to be performed when searching for nodes in the binary search tree. It can have one
9848
+ * of the following values:
9849
+ * @returns The method is returning a NODE object or undefined.
9784
9850
  */
9785
9851
  getNode(identifier, callback = this._DEFAULT_CALLBACK, beginRoot = this.root, iterationType = this.iterationType) {
9786
9852
  var _a;
9787
9853
  return (_a = this.getNodes(identifier, callback, true, beginRoot, iterationType)[0]) != null ? _a : void 0;
9788
9854
  }
9789
9855
  /**
9790
- * Time Complexity: O(log n)
9791
- * Space Complexity: O(1)
9856
+ * Time Complexity: O(k log n)
9857
+ * Space Complexity: O(k + log n)
9792
9858
  */
9793
9859
  /**
9794
9860
  * Time Complexity: O(log n)
9795
9861
  * Space Complexity: O(1)
9796
9862
  *
9797
- * The function `getNodeByKey` searches for a node in a binary tree based on a given key, using
9798
- * either recursive or iterative methods.
9799
- * @param {K} key - The `key` parameter is the key value that we are searching for in the tree.
9800
- * It is used to identify the node that we want to retrieve.
9801
- * @param iterationType - The `iterationType` parameter is an optional parameter that specifies the
9802
- * type of iteration to use when searching for a node in the binary tree. It can have two possible
9803
- * values:
9804
- * @returns The function `getNodeByKey` returns a node (`NODE`) if a node with the specified key is
9805
- * found in the binary tree. If no node is found, it returns `undefined`.
9863
+ * The function `getNodeByKey` returns a node with a specific key from a tree data structure.
9864
+ * @param {K} key - The key parameter is the value used to search for a specific node in the tree. It
9865
+ * is typically a unique identifier or a value that can be used to determine the position of the node
9866
+ * in the tree structure.
9867
+ * @param {IterationType} [iterationType=ITERATIVE] - The `iterationType` parameter is an optional
9868
+ * parameter that specifies the type of iteration to be used when searching for a node in the tree.
9869
+ * It has a default value of `'ITERATIVE'`.
9870
+ * @returns The method is returning a NODE object or undefined.
9806
9871
  */
9807
9872
  getNodeByKey(key, iterationType = "ITERATIVE") {
9808
9873
  return this.getNode(key, this._DEFAULT_CALLBACK, this.root, iterationType);
9809
9874
  }
9810
9875
  /**
9811
- * Time complexity: O(n)
9812
- * Space complexity: O(n)
9876
+ * Time Complexity: O(log n)
9877
+ * Space Complexity: O(k + log n)
9813
9878
  */
9814
9879
  /**
9815
9880
  * Time complexity: O(n)
@@ -9818,15 +9883,16 @@ var dataStructureTyped = (() => {
9818
9883
  * The function overrides the depth-first search method and returns an array of the return types of
9819
9884
  * the callback function.
9820
9885
  * @param {C} callback - The `callback` parameter is a function that will be called for each node
9821
- * during the depth-first search traversal. It is an optional parameter and if not provided, a
9822
- * default callback function will be used.
9823
- * @param {DFSOrderPattern} [pattern=in] - The `pattern` parameter specifies the order in which the
9824
- * nodes are visited during the depth-first search. It can have one of the following values:
9825
- * @param beginRoot - The `beginRoot` parameter is used to specify the starting point for the
9826
- * Depth-First Search (DFS) traversal. It can be either a key, a node, or an entry in the tree. If no
9827
- * value is provided, the DFS traversal will start from the root of the tree.
9828
- * @param {IterationType} iterationType - The `iterationType` parameter specifies the type of
9829
- * iteration to be used during the Depth-First Search (DFS) traversal. It can have one of the
9886
+ * during the depth-first search traversal. It is an optional parameter and defaults to
9887
+ * `this._DEFAULT_CALLBACK`. The type `C` represents the type of the callback function.
9888
+ * @param {DFSOrderPattern} [pattern=IN] - The "pattern" parameter in the code snippet refers to the
9889
+ * order in which the Depth-First Search (DFS) algorithm visits the nodes in a tree or graph. It can
9890
+ * take one of the following values:
9891
+ * @param {R | KeyOrNodeOrEntry<K, V, NODE>} beginRoot - The `beginRoot` parameter is the starting
9892
+ * point for the depth-first search traversal. It can be either a root node, a key-value pair, or a
9893
+ * node entry. If not specified, the default value is the root of the tree.
9894
+ * @param {IterationType} [iterationType=ITERATIVE] - The `iterationType` parameter specifies the
9895
+ * type of iteration to be used during the Depth-First Search (DFS) traversal. It can have one of the
9830
9896
  * following values:
9831
9897
  * @returns The method is returning an array of the return type of the callback function.
9832
9898
  */
@@ -9834,8 +9900,8 @@ var dataStructureTyped = (() => {
9834
9900
  return super.dfs(callback, pattern, beginRoot, iterationType, false);
9835
9901
  }
9836
9902
  /**
9837
- * Time complexity: O(n)
9838
- * Space complexity: O(n)
9903
+ * Time Complexity: O(log n)
9904
+ * Space Complexity: O(1)
9839
9905
  */
9840
9906
  /**
9841
9907
  * Time complexity: O(n)
@@ -9844,38 +9910,38 @@ var dataStructureTyped = (() => {
9844
9910
  * The function overrides the breadth-first search method and returns an array of the return types of
9845
9911
  * the callback function.
9846
9912
  * @param {C} callback - The `callback` parameter is a function that will be called for each node
9847
- * visited during the breadth-first search traversal. It is an optional parameter and if not
9848
- * provided, a default callback function will be used.
9849
- * @param beginRoot - The `beginRoot` parameter is the starting point for the breadth-first search
9850
- * traversal. It can be either a key, a node, or an entry in the tree. If not specified, the root of
9851
- * the tree is used as the starting point.
9852
- * @param iterationType - The `iterationType` parameter is used to specify the type of iteration to
9853
- * be performed during the breadth-first search (BFS) traversal. It determines the order in which the
9854
- * nodes are visited.
9855
- * @returns The method is returning an array of the return type of the callback function.
9913
+ * visited during the breadth-first search. It should take a single argument, which is the current
9914
+ * node being visited, and it can return a value of any type.
9915
+ * @param {R | KeyOrNodeOrEntry<K, V, NODE>} beginRoot - The `beginRoot` parameter is the starting
9916
+ * point for the breadth-first search. It can be either a root node, a key-value pair, or an entry
9917
+ * object. If no value is provided, the default value is the root of the tree.
9918
+ * @param {IterationType} iterationType - The `iterationType` parameter is used to specify the type
9919
+ * of iteration to be performed during the breadth-first search (BFS) traversal. It can have one of
9920
+ * the following values:
9921
+ * @returns an array of the return type of the callback function.
9856
9922
  */
9857
9923
  bfs(callback = this._DEFAULT_CALLBACK, beginRoot = this.root, iterationType = this.iterationType) {
9858
9924
  return super.bfs(callback, beginRoot, iterationType, false);
9859
9925
  }
9860
9926
  /**
9861
- * Time complexity: O(n)
9862
- * Space complexity: O(n)
9927
+ * Time Complexity: O(log n)
9928
+ * Space Complexity: O(1)
9863
9929
  */
9864
9930
  /**
9865
9931
  * Time complexity: O(n)
9866
9932
  * Space complexity: O(n)
9867
9933
  *
9868
- * The function overrides the listLevels method and returns an array of arrays containing the return
9869
- * type of the callback function for each level of the tree.
9934
+ * The function overrides the listLevels method from the superclass and returns an array of arrays
9935
+ * containing the results of the callback function applied to each level of the tree.
9870
9936
  * @param {C} callback - The `callback` parameter is a generic type `C` that extends
9871
- * `BTNCallback<NODE>`. It represents a callback function that will be called for each node in the tree
9872
- * during the level listing process.
9873
- * @param beginRoot - The `beginRoot` parameter is used to specify the starting point for listing the
9874
- * levels of a binary tree. It can be either a key, a node, or an entry in the binary tree. If not
9875
- * provided, the root of the binary tree is used as the starting point.
9876
- * @param iterationType - The `iterationType` parameter is used to specify the type of iteration to
9877
- * be performed on the tree. It determines the order in which the nodes are visited during the
9878
- * iteration.
9937
+ * `BTNCallback<NODE>`. It represents a callback function that will be called for each node in the
9938
+ * tree during the iteration process.
9939
+ * @param {R | KeyOrNodeOrEntry<K, V, NODE>} beginRoot - The `beginRoot` parameter is the starting
9940
+ * point for listing the levels of the binary tree. It can be either a root node of the tree, a
9941
+ * key-value pair representing a node in the tree, or a key representing a node in the tree. If no
9942
+ * value is provided, the root of
9943
+ * @param {IterationType} iterationType - The `iterationType` parameter is used to specify the type
9944
+ * of iteration to be performed on the tree. It can have one of the following values:
9879
9945
  * @returns The method is returning a two-dimensional array of the return type of the callback
9880
9946
  * function.
9881
9947
  */
@@ -9883,27 +9949,27 @@ var dataStructureTyped = (() => {
9883
9949
  return super.listLevels(callback, beginRoot, iterationType, false);
9884
9950
  }
9885
9951
  /**
9886
- * Time Complexity: O(log n)
9887
- * Space Complexity: O(log n)
9952
+ * Time complexity: O(n)
9953
+ * Space complexity: O(n)
9888
9954
  */
9889
9955
  /**
9890
- * Time Complexity: O(log n)
9891
- * Space Complexity: O(log n)
9956
+ * Time complexity: O(n)
9957
+ * Space complexity: O(n)
9892
9958
  *
9893
- * The `lesserOrGreaterTraverse` function traverses a binary tree and returns an array of nodes that
9894
- * are either lesser or greater than a target node, depending on the specified comparison type.
9959
+ * The `lesserOrGreaterTraverse` function traverses a binary tree and applies a callback function to
9960
+ * each node that meets a certain condition based on a target node and a comparison value.
9895
9961
  * @param {C} callback - The `callback` parameter is a function that will be called for each node
9896
- * that satisfies the condition specified by the `lesserOrGreater` parameter. It takes a single
9897
- * parameter of type `NODE` (the node type) and returns a value of any type.
9962
+ * that meets the condition specified by the `lesserOrGreater` parameter. It takes a single argument,
9963
+ * which is the current node being traversed, and returns a value of any type.
9898
9964
  * @param {CP} lesserOrGreater - The `lesserOrGreater` parameter is used to determine whether to
9899
- * traverse nodes that are lesser than, greater than, or equal to the `targetNode`. It is of type
9900
- * `CP`, which is a custom type representing the comparison operator. The possible values for
9901
- * `lesserOrGreater` are
9902
- * @param {K | NODE | undefined} targetNode - The `targetNode` parameter represents the node in the
9903
- * binary tree that you want to traverse from. It can be specified either by its key, by the node
9904
- * object itself, or it can be left undefined to start the traversal from the root of the tree.
9905
- * @param iterationType - The `iterationType` parameter determines the type of traversal to be
9906
- * performed on the binary tree. It can have two possible values:
9965
+ * traverse nodes that are lesser, greater, or both than the `targetNode`. It accepts the values -1,
9966
+ * 0, or 1, where:
9967
+ * @param {R | KeyOrNodeOrEntry<K, V, NODE>} targetNode - The `targetNode` parameter is the node in
9968
+ * the binary tree that you want to start traversing from. It can be specified either by providing
9969
+ * the key of the node, the node itself, or an entry containing the key and value of the node. If no
9970
+ * `targetNode` is provided,
9971
+ * @param {IterationType} iterationType - The `iterationType` parameter determines the type of
9972
+ * traversal to be performed on the binary tree. It can have two possible values:
9907
9973
  * @returns The function `lesserOrGreaterTraverse` returns an array of values of type
9908
9974
  * `ReturnType<C>`, which is the return type of the callback function passed as an argument.
9909
9975
  */
@@ -9945,18 +10011,19 @@ var dataStructureTyped = (() => {
9945
10011
  }
9946
10012
  }
9947
10013
  /**
9948
- * Time Complexity: O(log n)
9949
- * Space Complexity: O(log n)
10014
+ * Time complexity: O(n)
10015
+ * Space complexity: O(n)
9950
10016
  */
9951
10017
  /**
9952
- * Time Complexity: O(log n)
9953
- * Space Complexity: O(log n)
10018
+ * Time complexity: O(n)
10019
+ * Space complexity: O(n)
9954
10020
  *
9955
- * The `perfectlyBalance` function balances a binary search tree by adding nodes in a way that
9956
- * ensures the tree is perfectly balanced.
9957
- * @param iterationType - The `iterationType` parameter is an optional parameter that specifies the
9958
- * type of iteration to use when building a balanced binary search tree. It can have two possible
9959
- * values:
10021
+ * The `perfectlyBalance` function takes an optional `iterationType` parameter and returns `true` if
10022
+ * the binary search tree is perfectly balanced, otherwise it returns `false`.
10023
+ * @param {IterationType} iterationType - The `iterationType` parameter is an optional parameter that
10024
+ * specifies the type of iteration to use when building a balanced binary search tree. It has a
10025
+ * default value of `this.iterationType`, which means it will use the iteration type specified in the
10026
+ * current instance of the class.
9960
10027
  * @returns The function `perfectlyBalance` returns a boolean value.
9961
10028
  */
9962
10029
  perfectlyBalance(iterationType = this.iterationType) {
@@ -9995,25 +10062,19 @@ var dataStructureTyped = (() => {
9995
10062
  }
9996
10063
  }
9997
10064
  /**
9998
- * Balancing Adjustment:
9999
- * Perfectly Balanced Binary Tree: Since the balance of a perfectly balanced binary tree is already fixed, no additional balancing adjustment is needed. Any insertion or deletion operation will disrupt the perfect balance, often requiring a complete reconstruction of the tree.
10000
- * AVL Tree: After insertion or deletion operations, an AVL tree performs rotation adjustments based on the balance factor of nodes to restore the tree's balance. These rotations can be left rotations, right rotations, left-right rotations, or right-left rotations, performed as needed.
10001
- *
10002
- * Use Cases and Efficiency:
10003
- * Perfectly Balanced Binary Tree: Perfectly balanced binary trees are typically used in specific scenarios such as complete binary heaps in heap sort or certain types of Huffman trees. However, they are not suitable for dynamic operations requiring frequent insertions and deletions, as these operations often necessitate full tree reconstruction.
10004
- * AVL Tree: AVL trees are well-suited for scenarios involving frequent searching, insertion, and deletion operations. Through rotation adjustments, AVL trees maintain their balance, ensuring average and worst-case time complexity of O(log n).
10005
- */
10006
- /**
10007
- * Time Complexity: O(n)
10008
- * Space Complexity: O(log n)
10065
+ * Time complexity: O(n)
10066
+ * Space complexity: O(n)
10009
10067
  */
10010
10068
  /**
10011
10069
  * Time Complexity: O(n)
10012
10070
  * Space Complexity: O(log n)
10013
10071
  *
10014
- * The function checks if a binary tree is AVL balanced using either recursive or iterative approach.
10015
- * @param iterationType - The `iterationType` parameter is used to determine the method of iteration
10016
- * to check if the AVL tree is balanced. It can have two possible values:
10072
+ * The function `isAVLBalanced` checks if a binary tree is AVL balanced using either a recursive or
10073
+ * iterative approach.
10074
+ * @param {IterationType} iterationType - The `iterationType` parameter is an optional parameter that
10075
+ * specifies the type of iteration to use when checking if the AVL tree is balanced. It has a default
10076
+ * value of `this.iterationType`, which means it will use the iteration type specified in the current
10077
+ * instance of the AVL tree.
10017
10078
  * @returns a boolean value.
10018
10079
  */
10019
10080
  isAVLBalanced(iterationType = this.iterationType) {
@@ -10060,9 +10121,20 @@ var dataStructureTyped = (() => {
10060
10121
  return balanced;
10061
10122
  }
10062
10123
  /**
10063
- * The function sets the root property of an object and updates the parent property of the new root.
10064
- * @param {NODE | undefined} v - The parameter `v` is of type `NODE | undefined`. This means that it
10065
- * can either be an object of type `NODE` or it can be `undefined`.
10124
+ * Time Complexity: O(n)
10125
+ * Space Complexity: O(log n)
10126
+ */
10127
+ /**
10128
+ * The function returns the value of the _comparator property.
10129
+ * @returns The `_comparator` property is being returned.
10130
+ */
10131
+ get comparator() {
10132
+ return this._comparator;
10133
+ }
10134
+ /**
10135
+ * The function sets the root of a tree-like structure and updates the parent property of the new
10136
+ * root.
10137
+ * @param {NODE | undefined} v - v is a parameter of type NODE or undefined.
10066
10138
  */
10067
10139
  _setRoot(v) {
10068
10140
  if (v) {
@@ -10670,27 +10742,29 @@ var dataStructureTyped = (() => {
10670
10742
  };
10671
10743
  var AVLTree = class _AVLTree extends BST {
10672
10744
  /**
10673
- * The constructor function initializes an AVLTree object with optional keysOrNodesOrEntries and options.
10674
- * @param [keysOrNodesOrEntries] - The `keysOrNodesOrEntries` parameter is an optional iterable of `KeyOrNodeOrEntry<K, V, NODE>`
10675
- * objects. It represents a collection of nodes that will be added to the AVL tree during
10676
- * initialization.
10677
- * @param [options] - The `options` parameter is an optional object that allows you to customize the
10678
- * behavior of the AVL tree. It is of type `Partial<AVLTreeOptions>`, which means that you can
10679
- * provide only a subset of the properties defined in the `AVLTreeOptions` interface.
10745
+ * This is a constructor function for an AVLTree class that initializes the tree with keys, nodes,
10746
+ * entries, or raw elements.
10747
+ * @param keysOrNodesOrEntriesOrRawElements - The `keysOrNodesOrEntriesOrRawElements` parameter is an
10748
+ * iterable object that can contain either keys, nodes, entries, or raw elements. These elements will
10749
+ * be used to initialize the AVLTree.
10750
+ * @param [options] - The `options` parameter is an optional object that can be used to customize the
10751
+ * behavior of the AVLTree. It can include properties such as `compareFn` (a function used to compare
10752
+ * keys), `allowDuplicates` (a boolean indicating whether duplicate keys are allowed), and
10753
+ * `nodeBuilder` (
10680
10754
  */
10681
- constructor(keysOrNodesOrEntries = [], options) {
10755
+ constructor(keysOrNodesOrEntriesOrRawElements = [], options) {
10682
10756
  super([], options);
10683
- if (keysOrNodesOrEntries)
10684
- super.addMany(keysOrNodesOrEntries);
10757
+ if (keysOrNodesOrEntriesOrRawElements)
10758
+ super.addMany(keysOrNodesOrEntriesOrRawElements);
10685
10759
  }
10686
10760
  /**
10687
- * The function creates a new AVL tree node with the specified key and value.
10688
- * @param {K} key - The key parameter is the key value that will be associated with
10689
- * the new node. It is used to determine the position of the node in the binary search tree.
10690
- * @param [value] - The parameter `value` is an optional value that can be assigned to the node. It is of
10691
- * type `V`, which means it can be any value that is assignable to the `value` property of the
10692
- * node type `NODE`.
10693
- * @returns a new AVLTreeNode object with the specified key and value.
10761
+ * The function creates a new AVL tree node with the given key and value.
10762
+ * @param {K} key - The key parameter is of type K, which represents the key of the node being
10763
+ * created.
10764
+ * @param {V} [value] - The "value" parameter is an optional parameter of type V. It represents the
10765
+ * value associated with the key in the node being created.
10766
+ * @returns The method is returning a new instance of the AVLTreeNode class, casted as the generic
10767
+ * type NODE.
10694
10768
  */
10695
10769
  createNode(key, value) {
10696
10770
  return new AVLTreeNode(key, value);
@@ -10709,12 +10783,14 @@ var dataStructureTyped = (() => {
10709
10783
  }, options));
10710
10784
  }
10711
10785
  /**
10712
- * The function checks if an keyOrNodeOrEntry is an instance of AVLTreeNode.
10713
- * @param keyOrNodeOrEntry - The `keyOrNodeOrEntry` parameter is of type `KeyOrNodeOrEntry<K, V, NODE>`.
10714
- * @returns a boolean value indicating whether the keyOrNodeOrEntry is an instance of the AVLTreeNode class.
10786
+ * The function checks if the input is an instance of AVLTreeNode.
10787
+ * @param {R | KeyOrNodeOrEntry<K, V, NODE>} keyOrNodeOrEntryOrRawElement - The parameter
10788
+ * `keyOrNodeOrEntryOrRawElement` can be of type `R` or `KeyOrNodeOrEntry<K, V, NODE>`.
10789
+ * @returns a boolean value indicating whether the input parameter `keyOrNodeOrEntryOrRawElement` is
10790
+ * an instance of the `AVLTreeNode` class.
10715
10791
  */
10716
- isNode(keyOrNodeOrEntry) {
10717
- return keyOrNodeOrEntry instanceof AVLTreeNode;
10792
+ isNode(keyOrNodeOrEntryOrRawElement) {
10793
+ return keyOrNodeOrEntryOrRawElement instanceof AVLTreeNode;
10718
10794
  }
10719
10795
  /**
10720
10796
  * Time Complexity: O(log n)
@@ -10725,20 +10801,21 @@ var dataStructureTyped = (() => {
10725
10801
  * Time Complexity: O(log n)
10726
10802
  * Space Complexity: O(1)
10727
10803
  *
10728
- * The function overrides the add method of a binary tree node and balances the tree after inserting
10729
- * a new node.
10730
- * @param keyOrNodeOrEntry - The `keyOrNodeOrEntry` parameter can be either a key, a node, or an
10731
- * entry.
10732
- * @param {V} [value] - The `value` parameter represents the value associated with the key that is
10733
- * being added to the binary tree.
10734
- * @returns The method is returning either the inserted node or undefined.
10804
+ * The function overrides the add method of a class and inserts a key-value pair into a data
10805
+ * structure, then balances the path.
10806
+ * @param {R | KeyOrNodeOrEntry<K, V, NODE>} keyOrNodeOrEntryOrRawElement - The parameter
10807
+ * `keyOrNodeOrEntryOrRawElement` can accept values of type `R`, `KeyOrNodeOrEntry<K, V, NODE>`, or
10808
+ * `RawElement`.
10809
+ * @param {V} [value] - The `value` parameter is an optional value that you want to associate with
10810
+ * the key or node being added to the data structure.
10811
+ * @returns The method is returning a boolean value.
10735
10812
  */
10736
- add(keyOrNodeOrEntry, value) {
10737
- if (keyOrNodeOrEntry === null)
10813
+ add(keyOrNodeOrEntryOrRawElement, value) {
10814
+ if (keyOrNodeOrEntryOrRawElement === null)
10738
10815
  return false;
10739
- const inserted = super.add(keyOrNodeOrEntry, value);
10816
+ const inserted = super.add(keyOrNodeOrEntryOrRawElement, value);
10740
10817
  if (inserted)
10741
- this._balancePath(keyOrNodeOrEntry);
10818
+ this._balancePath(keyOrNodeOrEntryOrRawElement);
10742
10819
  return inserted;
10743
10820
  }
10744
10821
  /**
@@ -10749,16 +10826,14 @@ var dataStructureTyped = (() => {
10749
10826
  * Time Complexity: O(log n)
10750
10827
  * Space Complexity: O(1)
10751
10828
  *
10752
- * The function overrides the delete method of a binary tree, performs the deletion, and then
10753
- * balances the tree if necessary.
10829
+ * The function overrides the delete method of a binary tree class and performs additional operations
10830
+ * to balance the tree after deletion.
10754
10831
  * @param identifier - The `identifier` parameter is the value or condition used to identify the
10755
- * node(s) to be deleted from the binary tree. It can be of any type and is the return type of the
10756
- * `callback` function.
10757
- * @param {C} callback - The `callback` parameter is a function that will be called for each node
10758
- * that is deleted from the binary tree. It is an optional parameter and if not provided, it will
10759
- * default to the `_DEFAULT_CALLBACK` function. The `callback` function should have a single
10760
- * parameter of type `NODE
10761
- * @returns The method is returning an array of `BinaryTreeDeleteResult<NODE>`.
10832
+ * node(s) to be deleted from the binary tree. It can be of any type that is compatible with the
10833
+ * binary tree's node type.
10834
+ * @param {C} callback - The `callback` parameter is a function that will be used to determine if a
10835
+ * node should be deleted or not. It is optional and has a default value of `this._DEFAULT_CALLBACK`.
10836
+ * @returns The method is returning an array of BinaryTreeDeleteResult<NODE> objects.
10762
10837
  */
10763
10838
  delete(identifier, callback = this._DEFAULT_CALLBACK) {
10764
10839
  const deletedResults = super.delete(identifier, callback);
@@ -10770,14 +10845,21 @@ var dataStructureTyped = (() => {
10770
10845
  return deletedResults;
10771
10846
  }
10772
10847
  /**
10773
- * The `_swapProperties` function swaps the key, value, and height properties between two nodes in a binary
10774
- * tree.
10775
- * @param {K | NODE | undefined} srcNode - The `srcNode` parameter represents the source node that
10776
- * needs to be swapped with the destination node. It can be of type `K`, `NODE`, or `undefined`.
10777
- * @param {K | NODE | undefined} destNode - The `destNode` parameter represents the destination
10778
- * node where the values from the source node will be swapped to.
10779
- * @returns either the `destNode` object if both `srcNode` and `destNode` are defined, or `undefined`
10780
- * if either `srcNode` or `destNode` is undefined.
10848
+ * Time Complexity: O(1)
10849
+ * Space Complexity: O(1)
10850
+ */
10851
+ /**
10852
+ * Time Complexity: O(1)
10853
+ * Space Complexity: O(1)
10854
+ *
10855
+ * The `_swapProperties` function swaps the key, value, and height properties between two nodes in a
10856
+ * binary search tree.
10857
+ * @param {R | BSTNKeyOrNode<K, NODE>} srcNode - The `srcNode` parameter represents either a node
10858
+ * object (`NODE`) or a key-value pair (`R`) that is being swapped with another node.
10859
+ * @param {R | BSTNKeyOrNode<K, NODE>} destNode - The `destNode` parameter is either an instance of
10860
+ * `R` or an instance of `BSTNKeyOrNode<K, NODE>`.
10861
+ * @returns The method is returning the `destNodeEnsured` object if both `srcNodeEnsured` and
10862
+ * `destNodeEnsured` are truthy. Otherwise, it returns `undefined`.
10781
10863
  */
10782
10864
  _swapProperties(srcNode, destNode) {
10783
10865
  const srcNodeEnsured = this.ensureNode(srcNode);
@@ -10807,7 +10889,8 @@ var dataStructureTyped = (() => {
10807
10889
  * Space Complexity: O(1)
10808
10890
  *
10809
10891
  * The function calculates the balance factor of a node in a binary tree.
10810
- * @param {NODE} node - The parameter "node" represents a node in a binary tree data structure.
10892
+ * @param {NODE} node - The parameter "node" is of type "NODE", which likely represents a node in a
10893
+ * binary tree data structure.
10811
10894
  * @returns the balance factor of a given node. The balance factor is calculated by subtracting the
10812
10895
  * height of the left subtree from the height of the right subtree.
10813
10896
  */
@@ -10850,7 +10933,7 @@ var dataStructureTyped = (() => {
10850
10933
  * Time Complexity: O(1)
10851
10934
  * Space Complexity: O(1)
10852
10935
  *
10853
- * The function `_balanceLL` performs a left-left rotation to balance a binary tree.
10936
+ * The `_balanceLL` function performs a left-left rotation to balance a binary search tree.
10854
10937
  * @param {NODE} A - A is a node in a binary tree.
10855
10938
  */
10856
10939
  _balanceLL(A) {
@@ -11040,8 +11123,8 @@ var dataStructureTyped = (() => {
11040
11123
  *
11041
11124
  * The `_balancePath` function is used to update the heights of nodes and perform rotation operations
11042
11125
  * to restore balance in an AVL tree after inserting a node.
11043
- * @param {NODE} node - The `node` parameter in the `_balancePath` function represents the node in the
11044
- * AVL tree that needs to be balanced.
11126
+ * @param {R | KeyOrNodeOrEntry<K, V, NODE>} node - The `node` parameter can be of type `R` or
11127
+ * `KeyOrNodeOrEntry<K, V, NODE>`.
11045
11128
  */
11046
11129
  _balancePath(node) {
11047
11130
  node = this.ensureNode(node);
@@ -11071,13 +11154,21 @@ var dataStructureTyped = (() => {
11071
11154
  }
11072
11155
  }
11073
11156
  /**
11074
- * The function replaces an old node with a new node while preserving the height of the old node.
11075
- * @param {NODE} oldNode - The `oldNode` parameter is the node that you want to replace with the
11076
- * `newNode`.
11157
+ * Time Complexity: O(1)
11158
+ * Space Complexity: O(1)
11159
+ */
11160
+ /**
11161
+ * Time Complexity: O(1)
11162
+ * Space Complexity: O(1)
11163
+ *
11164
+ * The function replaces an old node with a new node and sets the height of the new node to be the
11165
+ * same as the old node.
11166
+ * @param {NODE} oldNode - The `oldNode` parameter represents the node that needs to be replaced in
11167
+ * the data structure.
11077
11168
  * @param {NODE} newNode - The `newNode` parameter is the new node that will replace the `oldNode` in
11078
11169
  * the data structure.
11079
- * @returns the result of calling the `_replaceNode` method on the superclass, passing in the
11080
- * `oldNode` and `newNode` as arguments.
11170
+ * @returns The method is returning the result of calling the `_replaceNode` method from the
11171
+ * superclass, with the `oldNode` and `newNode` as arguments.
11081
11172
  */
11082
11173
  _replaceNode(oldNode, newNode) {
11083
11174
  newNode.height = oldNode.height;
@@ -11121,20 +11212,20 @@ var dataStructureTyped = (() => {
11121
11212
  var RedBlackTree = class _RedBlackTree extends BST {
11122
11213
  /**
11123
11214
  * This is the constructor function for a Red-Black Tree data structure in TypeScript.
11124
- * @param keysOrNodesOrEntries - The `keysOrNodesOrEntries` parameter is an iterable object that can
11125
- * contain keys, nodes, or entries. It is used to initialize the RBTree with the provided keys,
11126
- * nodes, or entries.
11215
+ * @param keysOrNodesOrEntriesOrRawElements - The `keysOrNodesOrEntriesOrRawElements` parameter is an
11216
+ * iterable object that can contain either keys, nodes, entries, or raw elements. It is used to
11217
+ * initialize the RBTree with the provided elements.
11127
11218
  * @param [options] - The `options` parameter is an optional object that can be passed to the
11128
- * constructor. It allows you to customize the behavior of the RBTree. It can include properties such
11129
- * as `compareKeys`, `compareValues`, `allowDuplicates`, etc. These properties define how the RBTree
11130
- * should compare keys and
11219
+ * constructor. It is of type `RBTreeOptions<K, V, R>`. This object can contain various options for
11220
+ * configuring the behavior of the Red-Black Tree. The specific properties and their meanings would
11221
+ * depend on the implementation
11131
11222
  */
11132
- constructor(keysOrNodesOrEntries = [], options) {
11223
+ constructor(keysOrNodesOrEntriesOrRawElements = [], options) {
11133
11224
  super([], options);
11134
11225
  __publicField(this, "_root");
11135
11226
  this._root = this.NIL;
11136
- if (keysOrNodesOrEntries) {
11137
- this.addMany(keysOrNodesOrEntries);
11227
+ if (keysOrNodesOrEntriesOrRawElements) {
11228
+ this.addMany(keysOrNodesOrEntriesOrRawElements);
11138
11229
  }
11139
11230
  }
11140
11231
  /**
@@ -11146,24 +11237,25 @@ var dataStructureTyped = (() => {
11146
11237
  }
11147
11238
  /**
11148
11239
  * The function creates a new Red-Black Tree node with the specified key, value, and color.
11149
- * @param {K} key - The key parameter represents the key of the node being created. It is of type K,
11150
- * which is a generic type representing the key's data type.
11240
+ * @param {K} key - The key parameter represents the key value of the node being created. It is of
11241
+ * type K, which is a generic type that can be replaced with any specific type when using the
11242
+ * function.
11151
11243
  * @param {V} [value] - The `value` parameter is an optional parameter that represents the value
11152
- * associated with the key in the node. It is not required and can be omitted if not needed.
11153
- * @param {RBTNColor} color - The "color" parameter is used to specify the color of the node in a
11154
- * Red-Black Tree. It is an optional parameter with a default value of "'BLACK'". The color
11155
- * can be either "'RED'" or "'BLACK'".
11156
- * @returns The method is returning a new instance of a RedBlackTreeNode with the specified key,
11157
- * value, and color.
11244
+ * associated with the key in the node. It is not required and can be omitted if you only need to
11245
+ * create a node with a key.
11246
+ * @param {RBTNColor} [color=BLACK] - The "color" parameter is used to specify the color of the node
11247
+ * in a Red-Black Tree. It can have two possible values: "RED" or "BLACK". By default, the color is
11248
+ * set to "BLACK" if not specified.
11249
+ * @returns A new instance of a RedBlackTreeNode with the specified key, value, and color is being
11250
+ * returned.
11158
11251
  */
11159
11252
  createNode(key, value, color = "BLACK") {
11160
11253
  return new RedBlackTreeNode(key, value, color);
11161
11254
  }
11162
11255
  /**
11163
- * The function creates a Red-Black Tree with the given options and returns it.
11164
- * @param [options] - The `options` parameter is an optional object that contains configuration
11165
- * options for creating the Red-Black Tree. It is of type `RBTreeOptions<K>`, where `K` represents
11166
- * the type of keys in the tree.
11256
+ * The function creates a new Red-Black Tree with the specified options.
11257
+ * @param [options] - The `options` parameter is an optional object that contains additional
11258
+ * configuration options for creating the Red-Black Tree. It has the following properties:
11167
11259
  * @returns a new instance of a RedBlackTree object.
11168
11260
  */
11169
11261
  createTree(options) {
@@ -11179,48 +11271,50 @@ var dataStructureTyped = (() => {
11179
11271
  * Time Complexity: O(1)
11180
11272
  * Space Complexity: O(1)
11181
11273
  *
11182
- * The function `keyValueOrEntryToNode` takes a key, value, or entry and returns a node if it is
11183
- * valid, otherwise it returns undefined.
11184
- * @param {KeyOrNodeOrEntry<K, V, NODE>} keyOrNodeOrEntry - The key, value, or entry to convert.
11185
- * @param {V} [value] - The value associated with the key (if `keyOrNodeOrEntry` is a key).
11186
- * @returns {NODE | undefined} - The corresponding Red-Black Tree node, or `undefined` if conversion fails.
11274
+ * The function checks if the input is an instance of the RedBlackTreeNode class.
11275
+ * @param {R | KeyOrNodeOrEntry<K, V, NODE>} keyOrNodeOrEntryOrRawElement - The parameter
11276
+ * `keyOrNodeOrEntryOrRawElement` can be of type `R` or `KeyOrNodeOrEntry<K, V, NODE>`.
11277
+ * @returns a boolean value indicating whether the input parameter `keyOrNodeOrEntryOrRawElement` is
11278
+ * an instance of the `RedBlackTreeNode` class.
11187
11279
  */
11188
- keyValueOrEntryToNode(keyOrNodeOrEntry, value) {
11189
- let node;
11190
- if (keyOrNodeOrEntry === null || keyOrNodeOrEntry === void 0) {
11191
- return;
11192
- } else if (this.isNode(keyOrNodeOrEntry)) {
11193
- node = keyOrNodeOrEntry;
11194
- } else if (this.isEntry(keyOrNodeOrEntry)) {
11195
- const [key, value2] = keyOrNodeOrEntry;
11196
- if (key === void 0 || key === null) {
11197
- return;
11198
- } else {
11199
- node = this.createNode(key, value2, "RED");
11200
- }
11201
- } else if (!this.isNode(keyOrNodeOrEntry)) {
11202
- node = this.createNode(keyOrNodeOrEntry, value, "RED");
11203
- } else {
11204
- return;
11205
- }
11206
- return node;
11207
- }
11208
- /**
11209
- * Time Complexity: O(1)
11210
- * Space Complexity: O(1)
11211
- * /
11212
-
11213
- /**
11214
- * Time Complexity: O(1)
11215
- * Space Complexity: O(1)
11216
- *
11217
- * The function checks if the input is an instance of the RedBlackTreeNode class.
11218
- * @param {KeyOrNodeOrEntry<K, V, NODE>} keyOrNodeOrEntry - The object to check.
11219
- * @returns {boolean} - `true` if the object is a Red-Black Tree node, `false` otherwise.
11220
- */
11221
- isNode(keyOrNodeOrEntry) {
11222
- return keyOrNodeOrEntry instanceof RedBlackTreeNode;
11280
+ isNode(keyOrNodeOrEntryOrRawElement) {
11281
+ return keyOrNodeOrEntryOrRawElement instanceof RedBlackTreeNode;
11223
11282
  }
11283
+ // /**
11284
+ // * Time Complexity: O(1)
11285
+ // * Space Complexity: O(1)
11286
+ // */
11287
+ //
11288
+ // /**
11289
+ // * Time Complexity: O(1)
11290
+ // * Space Complexity: O(1)
11291
+ // *
11292
+ // * The function `keyValueOrEntryOrRawElementToNode` takes a key, value, or entry and returns a node if it is
11293
+ // * valid, otherwise it returns undefined.
11294
+ // * @param {KeyOrNodeOrEntry<K, V, NODE>} keyOrNodeOrEntryOrRawElement - The key, value, or entry to convert.
11295
+ // * @param {V} [value] - The value associated with the key (if `keyOrNodeOrEntryOrRawElement` is a key).
11296
+ // * @returns {NODE | undefined} - The corresponding Red-Black Tree node, or `undefined` if conversion fails.
11297
+ // */
11298
+ // override keyValueOrEntryOrRawElementToNode(keyOrNodeOrEntryOrRawElement: R | KeyOrNodeOrEntry<K, V, NODE>, value?: V): NODE | undefined {
11299
+ //
11300
+ // if (keyOrNodeOrEntryOrRawElement === null || keyOrNodeOrEntryOrRawElement === undefined) return;
11301
+ // if (this.isNode(keyOrNodeOrEntryOrRawElement)) return keyOrNodeOrEntryOrRawElement;
11302
+ //
11303
+ // if (this.toEntryFn) {
11304
+ // const [key, entryValue] = this.toEntryFn(keyOrNodeOrEntryOrRawElement as R);
11305
+ // if (key) return this.createNode(key, entryValue ?? value, 'RED');
11306
+ // }
11307
+ //
11308
+ // if (this.isEntry(keyOrNodeOrEntryOrRawElement)) {
11309
+ // const [key, value] = keyOrNodeOrEntryOrRawElement;
11310
+ // if (key === undefined || key === null) return;
11311
+ // else return this.createNode(key, value, 'RED');
11312
+ // }
11313
+ //
11314
+ // if (this.isKey(keyOrNodeOrEntryOrRawElement)) return this.createNode(keyOrNodeOrEntryOrRawElement, value, 'RED');
11315
+ //
11316
+ // return ;
11317
+ // }
11224
11318
  /**
11225
11319
  * Time Complexity: O(1)
11226
11320
  * Space Complexity: O(1)
@@ -11244,17 +11338,19 @@ var dataStructureTyped = (() => {
11244
11338
  * Time Complexity: O(log n)
11245
11339
  * Space Complexity: O(1)
11246
11340
  *
11247
- * The function adds a new node to a Red-Black Tree data structure and returns a boolean indicating
11248
- * whether the operation was successful.
11249
- * @param keyOrNodeOrEntry - The `keyOrNodeOrEntry` parameter can be either a key, a node, or an
11250
- * entry.
11251
- * @param {V} [value] - The `value` parameter is the value associated with the key that is being
11252
- * added to the tree.
11253
- * @returns The method is returning a boolean value. It returns true if the node was successfully
11254
- * added or updated, and false otherwise.
11341
+ * The function adds a new node to a binary search tree and returns true if the node was successfully
11342
+ * added.
11343
+ * @param {R | KeyOrNodeOrEntry<K, V, NODE>} keyOrNodeOrEntryOrRawElement - The parameter
11344
+ * `keyOrNodeOrEntryOrRawElement` can accept a value of type `R` or `KeyOrNodeOrEntry<K, V, NODE>`.
11345
+ * @param {V} [value] - The `value` parameter is an optional value that you want to associate with
11346
+ * the key in the data structure. It represents the value that you want to add or update in the data
11347
+ * structure.
11348
+ * @returns The method is returning a boolean value. If a new node is successfully added to the tree,
11349
+ * the method returns true. If the node already exists and its value is updated, the method also
11350
+ * returns true. If the node cannot be added or updated, the method returns false.
11255
11351
  */
11256
- add(keyOrNodeOrEntry, value) {
11257
- const newNode = this.keyValueOrEntryToNode(keyOrNodeOrEntry, value);
11352
+ add(keyOrNodeOrEntryOrRawElement, value) {
11353
+ const newNode = this.keyValueOrEntryOrRawElementToNode(keyOrNodeOrEntryOrRawElement, value);
11258
11354
  if (!this.isRealNode(newNode))
11259
11355
  return false;
11260
11356
  const insertStatus = this._insert(newNode);
@@ -11277,16 +11373,16 @@ var dataStructureTyped = (() => {
11277
11373
  * Time Complexity: O(log n)
11278
11374
  * Space Complexity: O(1)
11279
11375
  *
11280
- * The function `delete` in a binary tree class deletes a node from the tree and fixes the tree if
11281
- * necessary.
11282
- * @param {ReturnType<C> | null | undefined} identifier - The `identifier` parameter is the
11283
- * identifier of the node that needs to be deleted from the binary tree. It can be of any type that
11284
- * is returned by the callback function `C`. It can also be `null` or `undefined` if the node to be
11285
- * deleted is not found.
11286
- * @param {C} callback - The `callback` parameter is a function that is used to retrieve a node from
11287
- * the binary tree based on its identifier. It is an optional parameter and if not provided, the
11288
- * `_DEFAULT_CALLBACK` function is used as the default callback. The callback function should
11289
- * return the identifier of the node to
11376
+ * The function overrides the delete method of a binary tree data structure, allowing for the
11377
+ * deletion of a node and maintaining the balance of the tree.
11378
+ * @param {ReturnType<C> | null | undefined} identifier - The `identifier` parameter is the value
11379
+ * that identifies the node to be deleted from the binary tree. It can be of any type that is
11380
+ * returned by the callback function `C`. It can also be `null` or `undefined` if there is no node to
11381
+ * delete.
11382
+ * @param {C} callback - The `callback` parameter is a function that is used to determine the
11383
+ * equality of nodes in the binary tree. It is optional and has a default value of
11384
+ * `this._DEFAULT_CALLBACK`. The type of the `callback` parameter is `C`, which is a generic type
11385
+ * that extends the `BTNCallback
11290
11386
  * @returns an array of BinaryTreeDeleteResult<NODE> objects.
11291
11387
  */
11292
11388
  delete(identifier, callback = this._DEFAULT_CALLBACK) {
@@ -11338,6 +11434,13 @@ var dataStructureTyped = (() => {
11338
11434
  return results;
11339
11435
  }
11340
11436
  /**
11437
+ * Time Complexity: O(1)
11438
+ * Space Complexity: O(1)
11439
+ */
11440
+ /**
11441
+ * Time Complexity: O(1)
11442
+ * Space Complexity: O(1)
11443
+ *
11341
11444
  * The function sets the root of a tree-like structure and updates the parent property of the new
11342
11445
  * root.
11343
11446
  * @param {NODE | undefined} v - v is a parameter of type NODE or undefined.
@@ -11359,8 +11462,8 @@ var dataStructureTyped = (() => {
11359
11462
  * The function replaces an old node with a new node while preserving the color of the old node.
11360
11463
  * @param {NODE} oldNode - The `oldNode` parameter represents the node that needs to be replaced in
11361
11464
  * the data structure.
11362
- * @param {NODE} newNode - The `newNode` parameter is the new node that will replace the old node in
11363
- * the data structure.
11465
+ * @param {NODE} newNode - The `newNode` parameter is of type `NODE`, which represents a node in a
11466
+ * data structure.
11364
11467
  * @returns The method is returning the result of calling the `_replaceNode` method from the
11365
11468
  * superclass, with the `oldNode` and `newNode` parameters.
11366
11469
  */
@@ -11376,12 +11479,13 @@ var dataStructureTyped = (() => {
11376
11479
  * Time Complexity: O(log n)
11377
11480
  * Space Complexity: O(1)
11378
11481
  *
11379
- * The `_insert` function inserts or updates a node in a binary search tree and performs necessary
11380
- * fix-ups to maintain the red-black tree properties.
11381
- * @param {NODE} node - The `node` parameter represents the node that needs to be inserted into a
11382
- * binary search tree. It contains a `key` property that is used to determine the position of the
11383
- * node in the tree.
11384
- * @returns {'inserted' | 'updated'} - The result of the insertion.
11482
+ * The `_insert` function inserts a node into a binary search tree and performs necessary fix-ups to
11483
+ * maintain the red-black tree properties.
11484
+ * @param {NODE} node - The `node` parameter represents the node that needs to be inserted into the
11485
+ * binary search tree.
11486
+ * @returns a string value indicating the result of the insertion operation. It can return either
11487
+ * 'UPDATED' if the node with the same key already exists and was updated, or 'CREATED' if a new node
11488
+ * was created and inserted into the tree.
11385
11489
  */
11386
11490
  _insert(node) {
11387
11491
  var _a, _b;
@@ -11447,8 +11551,8 @@ var dataStructureTyped = (() => {
11447
11551
  * Space Complexity: O(1)
11448
11552
  *
11449
11553
  * The `_insertFixup` function is used to fix the Red-Black Tree after inserting a new node.
11450
- * @param {NODE | undefined} z - The parameter `z` represents a node in the Red-Black Tree. It can
11451
- * either be a valid node object or `undefined`.
11554
+ * @param {NODE | undefined} z - The parameter `z` represents a node in the Red-Black Tree data
11555
+ * structure. It can either be a valid node or `undefined`.
11452
11556
  */
11453
11557
  _insertFixup(z) {
11454
11558
  var _a, _b, _c, _d;
@@ -11504,9 +11608,10 @@ var dataStructureTyped = (() => {
11504
11608
  *
11505
11609
  * The `_deleteFixup` function is used to fix the red-black tree after a node deletion by adjusting
11506
11610
  * the colors and performing rotations.
11507
- * @param {NODE | undefined} node - The `node` parameter represents a node in a Red-Black Tree data
11508
- * structure. It can be either a valid node object or `undefined`.
11509
- * @returns The function does not return any value. It has a return type of `void`.
11611
+ * @param {NODE | undefined} node - The `node` parameter represents a node in a binary tree. It can
11612
+ * be either a valid node object or `undefined`.
11613
+ * @returns The function does not return any value. It has a return type of `void`, which means it
11614
+ * does not return anything.
11510
11615
  */
11511
11616
  _deleteFixup(node) {
11512
11617
  var _a, _b, _c, _d;
@@ -11674,13 +11779,20 @@ var dataStructureTyped = (() => {
11674
11779
  }
11675
11780
  };
11676
11781
  var AVLTreeMultiMap = class _AVLTreeMultiMap extends AVLTree {
11677
- constructor(keysOrNodesOrEntries = [], options) {
11782
+ /**
11783
+ * The constructor initializes a new AVLTreeMultiMap object with optional initial elements.
11784
+ * @param keysOrNodesOrEntriesOrRawElements - The `keysOrNodesOrEntriesOrRawElements` parameter is an
11785
+ * iterable object that can contain either keys, nodes, entries, or raw elements.
11786
+ * @param [options] - The `options` parameter is an optional object that can be used to customize the
11787
+ * behavior of the AVLTreeMultiMap. It can include properties such as `compareKeys` and
11788
+ * `compareValues` functions to define custom comparison logic for keys and values, respectively.
11789
+ */
11790
+ constructor(keysOrNodesOrEntriesOrRawElements = [], options) {
11678
11791
  super([], options);
11679
11792
  __publicField(this, "_count", 0);
11680
- if (keysOrNodesOrEntries)
11681
- this.addMany(keysOrNodesOrEntries);
11793
+ if (keysOrNodesOrEntriesOrRawElements)
11794
+ this.addMany(keysOrNodesOrEntriesOrRawElements);
11682
11795
  }
11683
- // TODO the _count is not accurate after nodes count modified
11684
11796
  /**
11685
11797
  * The function calculates the sum of the count property of all nodes in a tree using depth-first
11686
11798
  * search.
@@ -11707,17 +11819,26 @@ var dataStructureTyped = (() => {
11707
11819
  return sum;
11708
11820
  }
11709
11821
  /**
11710
- * The function creates a new BSTNode with the given key, value, and count.
11711
- * @param {K} key - The key parameter is the unique identifier for the binary tree node. It is used to
11712
- * distinguish one node from another in the tree.
11713
- * @param {NODE} value - The `value` parameter represents the value that will be stored in the binary search tree node.
11714
- * @param {number} [count] - The "count" parameter is an optional parameter of type number. It represents the number of
11715
- * occurrences of the value in the binary search tree node. If not provided, the count will default to 1.
11716
- * @returns A new instance of the BSTNode class with the specified key, value, and count (if provided).
11822
+ * The function creates a new AVLTreeMultiMapNode with the specified key, value, and count.
11823
+ * @param {K} key - The key parameter represents the key of the node being created. It is of type K,
11824
+ * which is a generic type that can be replaced with any specific type when using the function.
11825
+ * @param {V} [value] - The `value` parameter is an optional parameter that represents the value
11826
+ * associated with the key in the node. It is of type `V`, which can be any data type.
11827
+ * @param {number} [count] - The `count` parameter represents the number of occurrences of a
11828
+ * key-value pair in the AVLTreeMultiMapNode. It is an optional parameter, so it can be omitted when
11829
+ * calling the `createNode` method. If provided, it specifies the initial count for the node.
11830
+ * @returns a new instance of the AVLTreeMultiMapNode class, casted as NODE.
11717
11831
  */
11718
11832
  createNode(key, value, count) {
11719
11833
  return new AVLTreeMultiMapNode(key, value, count);
11720
11834
  }
11835
+ /**
11836
+ * The function creates a new AVLTreeMultiMap object with the specified options and returns it.
11837
+ * @param [options] - The `options` parameter is an optional object that contains additional
11838
+ * configuration options for creating the AVLTreeMultiMap. It can have the following properties:
11839
+ * @returns a new instance of the AVLTreeMultiMap class, with the specified options, as a TREE
11840
+ * object.
11841
+ */
11721
11842
  createTree(options) {
11722
11843
  return new _AVLTreeMultiMap([], __spreadValues({
11723
11844
  iterationType: this.iterationType,
@@ -11725,44 +11846,47 @@ var dataStructureTyped = (() => {
11725
11846
  }, options));
11726
11847
  }
11727
11848
  /**
11728
- * The function `keyValueOrEntryToNode` converts an keyOrNodeOrEntry object into a node object.
11729
- * @param keyOrNodeOrEntry - The `keyOrNodeOrEntry` parameter is of type `KeyOrNodeOrEntry<K, V, NODE>`, which means it
11730
- * can be one of the following:
11731
- * @param {V} [value] - The `value` parameter is an optional argument that represents the value
11732
- * associated with the node. It is of type `V`, which can be any data type. If no value is provided,
11733
- * it defaults to `undefined`.
11849
+ * The function checks if the input is an instance of AVLTreeMultiMapNode.
11850
+ * @param {R | KeyOrNodeOrEntry<K, V, NODE>} keyOrNodeOrEntryOrRawElement - The parameter
11851
+ * `keyOrNodeOrEntryOrRawElement` can be of type `R` or `KeyOrNodeOrEntry<K, V, NODE>`.
11852
+ * @returns a boolean value indicating whether the input parameter `keyOrNodeOrEntryOrRawElement` is
11853
+ * an instance of the `AVLTreeMultiMapNode` class.
11854
+ */
11855
+ isNode(keyOrNodeOrEntryOrRawElement) {
11856
+ return keyOrNodeOrEntryOrRawElement instanceof AVLTreeMultiMapNode;
11857
+ }
11858
+ /**
11859
+ * The function `keyValueOrEntryOrRawElementToNode` converts a key, value, entry, or raw element into
11860
+ * a node object.
11861
+ * @param {R | KeyOrNodeOrEntry<K, V, NODE>} keyOrNodeOrEntryOrRawElement - The
11862
+ * `keyOrNodeOrEntryOrRawElement` parameter can be of type `R` or `KeyOrNodeOrEntry<K, V, NODE>`.
11863
+ * @param {V} [value] - The `value` parameter is an optional value that can be passed to the
11864
+ * `override` function. It represents the value associated with the key in the data structure. If no
11865
+ * value is provided, it will default to `undefined`.
11734
11866
  * @param [count=1] - The `count` parameter is an optional parameter that specifies the number of
11735
- * times the value should be added to the node. If not provided, it defaults to 1.
11736
- * @returns a node of type `NODE` or `undefined`.
11867
+ * times the key-value pair should be added to the data structure. If not provided, it defaults to 1.
11868
+ * @returns either a NODE object or undefined.
11737
11869
  */
11738
- keyValueOrEntryToNode(keyOrNodeOrEntry, value, count = 1) {
11739
- let node;
11740
- if (keyOrNodeOrEntry === void 0 || keyOrNodeOrEntry === null) {
11870
+ keyValueOrEntryOrRawElementToNode(keyOrNodeOrEntryOrRawElement, value, count = 1) {
11871
+ if (keyOrNodeOrEntryOrRawElement === void 0 || keyOrNodeOrEntryOrRawElement === null)
11741
11872
  return;
11742
- } else if (this.isNode(keyOrNodeOrEntry)) {
11743
- node = keyOrNodeOrEntry;
11744
- } else if (this.isEntry(keyOrNodeOrEntry)) {
11745
- const [key, value2] = keyOrNodeOrEntry;
11746
- if (key === void 0 || key === null) {
11873
+ if (this.isNode(keyOrNodeOrEntryOrRawElement))
11874
+ return keyOrNodeOrEntryOrRawElement;
11875
+ if (this.toEntryFn) {
11876
+ const [key, entryValue] = this.toEntryFn(keyOrNodeOrEntryOrRawElement);
11877
+ if (key)
11878
+ return this.createNode(key, entryValue != null ? entryValue : value, count);
11879
+ }
11880
+ if (this.isEntry(keyOrNodeOrEntryOrRawElement)) {
11881
+ const [key, value2] = keyOrNodeOrEntryOrRawElement;
11882
+ if (key === void 0 || key === null)
11747
11883
  return;
11748
- } else {
11749
- node = this.createNode(key, value2, count);
11750
- }
11751
- } else if (!this.isNode(keyOrNodeOrEntry)) {
11752
- node = this.createNode(keyOrNodeOrEntry, value, count);
11753
- } else {
11754
- return;
11884
+ else
11885
+ return this.createNode(key, value2, count);
11755
11886
  }
11756
- return node;
11757
- }
11758
- /**
11759
- * The function checks if an keyOrNodeOrEntry is an instance of the AVLTreeMultiMapNode class.
11760
- * @param keyOrNodeOrEntry - The `keyOrNodeOrEntry` parameter is of type `KeyOrNodeOrEntry<K, V, NODE>`.
11761
- * @returns a boolean value indicating whether the keyOrNodeOrEntry is an instance of the AVLTreeMultiMapNode
11762
- * class.
11763
- */
11764
- isNode(keyOrNodeOrEntry) {
11765
- return keyOrNodeOrEntry instanceof AVLTreeMultiMapNode;
11887
+ if (this.isKey(keyOrNodeOrEntryOrRawElement))
11888
+ return this.createNode(keyOrNodeOrEntryOrRawElement, value, count);
11889
+ return;
11766
11890
  }
11767
11891
  /**
11768
11892
  * Time Complexity: O(log n)
@@ -11772,20 +11896,21 @@ var dataStructureTyped = (() => {
11772
11896
  * Time Complexity: O(log n)
11773
11897
  * Space Complexity: O(1)
11774
11898
  *
11775
- * The function overrides the add method of a binary tree node and adds a new node to the tree.
11776
- * @param keyOrNodeOrEntry - The `keyOrNodeOrEntry` parameter can be either a key, a node, or an
11777
- * entry. It represents the key, node, or entry that you want to add to the binary tree.
11899
+ * The function overrides the add method of a TypeScript class to add a new node to a data structure
11900
+ * and update the count.
11901
+ * @param {R | KeyOrNodeOrEntry<K, V, NODE>} keyOrNodeOrEntryOrRawElement - The
11902
+ * `keyOrNodeOrEntryOrRawElement` parameter can accept a value of type `R`, which can be any type. It
11903
+ * can also accept a value of type `KeyOrNodeOrEntry<K, V, NODE>`, which represents a key, node,
11904
+ * entry, or raw element
11778
11905
  * @param {V} [value] - The `value` parameter represents the value associated with the key in the
11779
- * binary tree node. It is an optional parameter, meaning it can be omitted when calling the `add`
11780
- * method.
11906
+ * data structure. It is an optional parameter, so it can be omitted if not needed.
11781
11907
  * @param [count=1] - The `count` parameter represents the number of times the key-value pair should
11782
- * be added to the binary tree. By default, it is set to 1, meaning that the key-value pair will be
11783
- * added once. However, you can specify a different value for `count` if you want to add
11784
- * @returns The method is returning either the newly inserted node or `undefined` if the insertion
11785
- * was not successful.
11908
+ * be added to the data structure. By default, it is set to 1, meaning that the key-value pair will
11909
+ * be added once. However, you can specify a different value for `count` if you want to add
11910
+ * @returns a boolean value.
11786
11911
  */
11787
- add(keyOrNodeOrEntry, value, count = 1) {
11788
- const newNode = this.keyValueOrEntryToNode(keyOrNodeOrEntry, value, count);
11912
+ add(keyOrNodeOrEntryOrRawElement, value, count = 1) {
11913
+ const newNode = this.keyValueOrEntryOrRawElementToNode(keyOrNodeOrEntryOrRawElement, value, count);
11789
11914
  if (newNode === void 0)
11790
11915
  return false;
11791
11916
  const orgNodeCount = (newNode == null ? void 0 : newNode.count) || 0;
@@ -11803,19 +11928,19 @@ var dataStructureTyped = (() => {
11803
11928
  * Time Complexity: O(log n)
11804
11929
  * Space Complexity: O(1)
11805
11930
  *
11806
- * The `delete` function in TypeScript is used to remove a node from a binary tree, taking into
11807
- * account the count of the node and balancing the tree if necessary.
11808
- * @param identifier - The identifier is the value or key that is used to identify the node that
11809
- * needs to be deleted from the binary tree. It can be of any type that is returned by the callback
11931
+ * The `delete` function in a binary tree data structure deletes a node based on its identifier and
11932
+ * returns the deleted node along with the parent node that needs to be balanced.
11933
+ * @param identifier - The identifier parameter is the value used to identify the node that needs to
11934
+ * be deleted from the binary tree. It can be of any type and is the return type of the callback
11810
11935
  * function.
11811
- * @param {C} callback - The `callback` parameter is a function that is used to determine if a node
11812
- * should be deleted. It is optional and defaults to a default callback function. The `callback`
11813
- * function takes one parameter, which is the identifier of the node, and returns a value that is
11814
- * used to identify the node to
11936
+ * @param {C} callback - The `callback` parameter is a function that is used to determine the
11937
+ * equality of nodes in the binary tree. It is optional and has a default value of
11938
+ * `this._DEFAULT_CALLBACK`. The `callback` function takes a single argument, which is the identifier
11939
+ * of a node, and returns a value that
11815
11940
  * @param [ignoreCount=false] - A boolean flag indicating whether to ignore the count of the node
11816
11941
  * being deleted. If set to true, the count of the node will not be considered and the node will be
11817
- * deleted regardless of its count. If set to false (default), the count of the node will be
11818
- * decremented by 1 and
11942
+ * deleted regardless of its count. If set to false (default), the count of the node will be taken
11943
+ * into account and the node
11819
11944
  * @returns an array of `BinaryTreeDeleteResult<NODE>`.
11820
11945
  */
11821
11946
  delete(identifier, callback = this._DEFAULT_CALLBACK, ignoreCount = false) {
@@ -11879,7 +12004,8 @@ var dataStructureTyped = (() => {
11879
12004
  * Time Complexity: O(1)
11880
12005
  * Space Complexity: O(1)
11881
12006
  *
11882
- * The clear() function clears the contents of a data structure and sets the count to zero.
12007
+ * The "clear" function overrides the parent class's "clear" function and also resets the count to
12008
+ * zero.
11883
12009
  */
11884
12010
  clear() {
11885
12011
  super.clear();
@@ -11892,13 +12018,14 @@ var dataStructureTyped = (() => {
11892
12018
  /**
11893
12019
  * Time Complexity: O(n log n)
11894
12020
  * Space Complexity: O(log n)
11895
- *
11896
12021
  * The `perfectlyBalance` function takes a sorted array of nodes and builds a balanced binary search
11897
12022
  * tree using either a recursive or iterative approach.
11898
- * @param iterationType - The `iterationType` parameter is an optional parameter that specifies the
11899
- * type of iteration to use when building the balanced binary search tree. It can have two possible
11900
- * values:
11901
- * @returns a boolean value.
12023
+ * @param {IterationType} iterationType - The `iterationType` parameter is an optional parameter that
12024
+ * specifies the type of iteration to use when building the balanced binary search tree. It has a
12025
+ * default value of `this.iterationType`, which means it will use the iteration type currently set in
12026
+ * the object.
12027
+ * @returns The function `perfectlyBalance` returns a boolean value. It returns `true` if the
12028
+ * balancing operation is successful, and `false` if there are no nodes to balance.
11902
12029
  */
11903
12030
  perfectlyBalance(iterationType = this.iterationType) {
11904
12031
  const sorted = this.dfs((node) => node, "IN"), n = sorted.length;
@@ -11943,7 +12070,7 @@ var dataStructureTyped = (() => {
11943
12070
  * Time complexity: O(n)
11944
12071
  * Space complexity: O(n)
11945
12072
  *
11946
- * The `clone` function creates a deep copy of a tree object.
12073
+ * The function overrides the clone method to create a deep copy of a tree object.
11947
12074
  * @returns The `clone()` method is returning a cloned instance of the `TREE` object.
11948
12075
  */
11949
12076
  clone() {
@@ -11952,13 +12079,21 @@ var dataStructureTyped = (() => {
11952
12079
  return cloned;
11953
12080
  }
11954
12081
  /**
11955
- * The `_swapProperties` function swaps the key, value, count, and height properties between two nodes.
11956
- * @param {K | NODE | undefined} srcNode - The `srcNode` parameter represents the source node from
11957
- * which the values will be swapped. It can be of type `K`, `NODE`, or `undefined`.
11958
- * @param {K | NODE | undefined} destNode - The `destNode` parameter represents the destination
11959
- * node where the values from the source node will be swapped to.
11960
- * @returns either the `destNode` object if both `srcNode` and `destNode` are defined, or `undefined`
11961
- * if either `srcNode` or `destNode` is undefined.
12082
+ * Time Complexity: O(1)
12083
+ * Space Complexity: O(1)
12084
+ */
12085
+ /**
12086
+ * Time Complexity: O(1)
12087
+ * Space Complexity: O(1)
12088
+ *
12089
+ * The `_swapProperties` function swaps the properties (key, value, count, height) between two nodes
12090
+ * in a binary search tree.
12091
+ * @param {R | BSTNKeyOrNode<K, NODE>} srcNode - The `srcNode` parameter represents the source node
12092
+ * that will be swapped with the `destNode`.
12093
+ * @param {R | BSTNKeyOrNode<K, NODE>} destNode - The `destNode` parameter represents the destination
12094
+ * node where the properties will be swapped with the source node.
12095
+ * @returns The method is returning the `destNode` after swapping its properties with the `srcNode`.
12096
+ * If either `srcNode` or `destNode` is undefined, it returns `undefined`.
11962
12097
  */
11963
12098
  _swapProperties(srcNode, destNode) {
11964
12099
  srcNode = this.ensureNode(srcNode);
@@ -11982,12 +12117,19 @@ var dataStructureTyped = (() => {
11982
12117
  return void 0;
11983
12118
  }
11984
12119
  /**
12120
+ * Time Complexity: O(1)
12121
+ * Space Complexity: O(1)
12122
+ */
12123
+ /**
12124
+ * Time Complexity: O(1)
12125
+ * Space Complexity: O(1)
12126
+ *
11985
12127
  * The function replaces an old node with a new node and updates the count property of the new node.
11986
- * @param {NODE} oldNode - The `oldNode` parameter is of type `NODE` and represents the node that
11987
- * needs to be replaced in a data structure.
11988
- * @param {NODE} newNode - The `newNode` parameter is an object of type `NODE`.
12128
+ * @param {NODE} oldNode - The oldNode parameter represents the node that needs to be replaced in the
12129
+ * data structure. It is of type NODE.
12130
+ * @param {NODE} newNode - The `newNode` parameter is an instance of the `NODE` class.
11989
12131
  * @returns The method is returning the result of calling the `_replaceNode` method from the
11990
- * superclass, after updating the `count` property of the `newNode` object.
12132
+ * superclass, which is of type `NODE`.
11991
12133
  */
11992
12134
  _replaceNode(oldNode, newNode) {
11993
12135
  newNode.count = oldNode.count + newNode.count;
@@ -12032,19 +12174,19 @@ var dataStructureTyped = (() => {
12032
12174
  };
12033
12175
  var TreeMultiMap = class _TreeMultiMap extends RedBlackTree {
12034
12176
  /**
12035
- * The constructor function initializes a new instance of the TreeMultiMap class with optional
12036
- * initial keys, nodes, or entries.
12037
- * @param keysOrNodesOrEntries - The `keysOrNodesOrEntries` parameter is an iterable object that can
12038
- * contain keys, nodes, or entries. It is used to initialize the TreeMultiMap with the provided keys,
12039
- * nodes, or entries.
12040
- * @param [options] - The `options` parameter is an optional object that can be passed to the
12041
- * constructor. It allows you to customize the behavior of the `TreeMultiMap` instance.
12177
+ * The constructor function initializes a TreeMultiMap object with optional initial data.
12178
+ * @param keysOrNodesOrEntriesOrRawElements - The parameter `keysOrNodesOrEntriesOrRawElements` is an
12179
+ * iterable that can contain keys, nodes, entries, or raw elements. It is used to initialize the
12180
+ * TreeMultiMap with initial data.
12181
+ * @param [options] - The `options` parameter is an optional object that can be used to customize the
12182
+ * behavior of the `TreeMultiMap` constructor. It can include properties such as `compareKeys` and
12183
+ * `compareValues`, which are functions used to compare keys and values respectively.
12042
12184
  */
12043
- constructor(keysOrNodesOrEntries = [], options) {
12185
+ constructor(keysOrNodesOrEntriesOrRawElements = [], options) {
12044
12186
  super([], options);
12045
12187
  __publicField(this, "_count", 0);
12046
- if (keysOrNodesOrEntries)
12047
- this.addMany(keysOrNodesOrEntries);
12188
+ if (keysOrNodesOrEntriesOrRawElements)
12189
+ this.addMany(keysOrNodesOrEntriesOrRawElements);
12048
12190
  }
12049
12191
  // TODO the _count is not accurate after nodes count modified
12050
12192
  /**
@@ -12074,16 +12216,15 @@ var dataStructureTyped = (() => {
12074
12216
  /**
12075
12217
  * The function creates a new TreeMultiMapNode with the specified key, value, color, and count.
12076
12218
  * @param {K} key - The key parameter represents the key of the node being created. It is of type K,
12077
- * which is a generic type representing the key type of the node.
12078
- * @param {V} [value] - The `value` parameter represents the value associated with the key in the
12079
- * node. It is an optional parameter, which means it can be omitted when calling the `createNode`
12080
- * function. If provided, it should be of type `V`.
12219
+ * which is a generic type representing the type of keys in the tree.
12220
+ * @param {V} [value] - The `value` parameter is an optional parameter that represents the value
12221
+ * associated with the key in the node. It is of type `V`, which can be any data type.
12081
12222
  * @param {RBTNColor} [color=BLACK] - The color parameter is used to specify the color of the node in
12082
12223
  * a Red-Black Tree. It can have two possible values: 'RED' or 'BLACK'. The default value is 'BLACK'.
12083
12224
  * @param {number} [count] - The `count` parameter represents the number of occurrences of a key in
12084
12225
  * the tree. It is an optional parameter and is used to keep track of the number of values associated
12085
12226
  * with a key in the tree.
12086
- * @returns A new instance of the TreeMultiMapNode class is being returned.
12227
+ * @returns A new instance of the TreeMultiMapNode class, casted as NODE.
12087
12228
  */
12088
12229
  createNode(key, value, color = "BLACK", count) {
12089
12230
  return new TreeMultiMapNode(key, value, count, color);
@@ -12091,10 +12232,10 @@ var dataStructureTyped = (() => {
12091
12232
  /**
12092
12233
  * The function creates a new instance of a TreeMultiMap with the specified options and returns it.
12093
12234
  * @param [options] - The `options` parameter is an optional object that contains additional
12094
- * configuration options for creating the `TreeMultiMap`. It can include properties such as
12095
- * `keyComparator`, `valueComparator`, `allowDuplicates`, etc.
12235
+ * configuration options for creating the `TreeMultiMap`. It is of type `TreeMultiMapOptions<K, V,
12236
+ * R>`.
12096
12237
  * @returns a new instance of the `TreeMultiMap` class, with the provided options merged with the
12097
- * existing `iterationType` option. The returned value is casted as `TREE`.
12238
+ * existing `iterationType` property. The returned value is casted as `TREE`.
12098
12239
  */
12099
12240
  createTree(options) {
12100
12241
  return new _TreeMultiMap([], __spreadValues({
@@ -12102,46 +12243,47 @@ var dataStructureTyped = (() => {
12102
12243
  }, options));
12103
12244
  }
12104
12245
  /**
12105
- * The function `keyValueOrEntryToNode` takes a key, value, and count and returns a node if the input
12106
- * is valid.
12107
- * @param keyOrNodeOrEntry - The parameter `keyOrNodeOrEntry` can be of type `KeyOrNodeOrEntry<K, V,
12108
- * NODE>`. It can accept three types of values:
12109
- * @param {V} [value] - The `value` parameter is an optional value of type `V`. It represents the
12110
- * value associated with a key in a key-value pair.
12111
- * @param [count=1] - The count parameter is an optional parameter that specifies the number of times
12112
- * the key-value pair should be added to the node. If not provided, it defaults to 1.
12113
- * @returns a NODE object or undefined.
12246
+ * The function `keyValueOrEntryOrRawElementToNode` takes in a key, value, and count and returns a
12247
+ * node based on the input.
12248
+ * @param {R | KeyOrNodeOrEntry<K, V, NODE>} keyOrNodeOrEntryOrRawElement - The parameter
12249
+ * `keyOrNodeOrEntryOrRawElement` can be of type `R` or `KeyOrNodeOrEntry<K, V, NODE>`.
12250
+ * @param {V} [value] - The `value` parameter is an optional value that represents the value
12251
+ * associated with the key in the node. It is used when creating a new node or updating the value of
12252
+ * an existing node.
12253
+ * @param [count=1] - The `count` parameter is an optional parameter that specifies the number of
12254
+ * times the key-value pair should be added to the data structure. If not provided, it defaults to 1.
12255
+ * @returns either a NODE object or undefined.
12114
12256
  */
12115
- keyValueOrEntryToNode(keyOrNodeOrEntry, value, count = 1) {
12116
- let node;
12117
- if (keyOrNodeOrEntry === void 0 || keyOrNodeOrEntry === null) {
12257
+ keyValueOrEntryOrRawElementToNode(keyOrNodeOrEntryOrRawElement, value, count = 1) {
12258
+ if (keyOrNodeOrEntryOrRawElement === void 0 || keyOrNodeOrEntryOrRawElement === null)
12118
12259
  return;
12119
- } else if (this.isNode(keyOrNodeOrEntry)) {
12120
- node = keyOrNodeOrEntry;
12121
- } else if (this.isEntry(keyOrNodeOrEntry)) {
12122
- const [key, value2] = keyOrNodeOrEntry;
12123
- if (key === void 0 || key === null) {
12260
+ if (this.isNode(keyOrNodeOrEntryOrRawElement))
12261
+ return keyOrNodeOrEntryOrRawElement;
12262
+ if (this.toEntryFn) {
12263
+ const [key] = this.toEntryFn(keyOrNodeOrEntryOrRawElement);
12264
+ if (key)
12265
+ return this.getNodeByKey(key);
12266
+ }
12267
+ if (this.isEntry(keyOrNodeOrEntryOrRawElement)) {
12268
+ const [key, value2] = keyOrNodeOrEntryOrRawElement;
12269
+ if (key === void 0 || key === null)
12124
12270
  return;
12125
- } else {
12126
- node = this.createNode(key, value2, "BLACK", count);
12127
- }
12128
- } else if (!this.isNode(keyOrNodeOrEntry)) {
12129
- node = this.createNode(keyOrNodeOrEntry, value, "BLACK", count);
12130
- } else {
12131
- return;
12271
+ else
12272
+ return this.createNode(key, value2, "BLACK", count);
12132
12273
  }
12133
- return node;
12274
+ if (this.isKey(keyOrNodeOrEntryOrRawElement))
12275
+ return this.createNode(keyOrNodeOrEntryOrRawElement, value, "BLACK", count);
12276
+ return;
12134
12277
  }
12135
12278
  /**
12136
- * The function "isNode" checks if a given key, node, or entry is an instance of the TreeMultiMapNode
12137
- * class.
12138
- * @param keyOrNodeOrEntry - The parameter `keyOrNodeOrEntry` can be of type `KeyOrNodeOrEntry<K, V,
12139
- * NODE>`.
12140
- * @returns a boolean value indicating whether the input parameter `keyOrNodeOrEntry` is an instance
12141
- * of the `TreeMultiMapNode` class.
12279
+ * The function checks if the input is an instance of the TreeMultiMapNode class.
12280
+ * @param {R | KeyOrNodeOrEntry<K, V, NODE>} keyOrNodeOrEntryOrRawElement - The parameter
12281
+ * `keyOrNodeOrEntryOrRawElement` can be of type `R` or `KeyOrNodeOrEntry<K, V, NODE>`.
12282
+ * @returns a boolean value indicating whether the input parameter `keyOrNodeOrEntryOrRawElement` is
12283
+ * an instance of the `TreeMultiMapNode` class.
12142
12284
  */
12143
- isNode(keyOrNodeOrEntry) {
12144
- return keyOrNodeOrEntry instanceof TreeMultiMapNode;
12285
+ isNode(keyOrNodeOrEntryOrRawElement) {
12286
+ return keyOrNodeOrEntryOrRawElement instanceof TreeMultiMapNode;
12145
12287
  }
12146
12288
  /**
12147
12289
  * Time Complexity: O(log n)
@@ -12151,17 +12293,20 @@ var dataStructureTyped = (() => {
12151
12293
  * Time Complexity: O(log n)
12152
12294
  * Space Complexity: O(1)
12153
12295
  *
12154
- * The function overrides the add method in TypeScript and adds a new node to the data structure.
12155
- * @param keyOrNodeOrEntry - The `keyOrNodeOrEntry` parameter can accept three types of values:
12296
+ * The function overrides the add method of a class and adds a new node to a data structure, updating
12297
+ * the count and returning a boolean indicating success.
12298
+ * @param {R | KeyOrNodeOrEntry<K, V, NODE>} keyOrNodeOrEntryOrRawElement - The
12299
+ * `keyOrNodeOrEntryOrRawElement` parameter can accept one of the following types:
12156
12300
  * @param {V} [value] - The `value` parameter represents the value associated with the key in the
12157
- * data structure.
12301
+ * data structure. It is an optional parameter, so it can be omitted if not needed.
12158
12302
  * @param [count=1] - The `count` parameter represents the number of times the key-value pair should
12159
- * be added to the data structure. By default, it is set to 1, meaning that the key-value pair will
12160
- * be added once. However, you can specify a different value for `count` if you want to add
12161
- * @returns a boolean value.
12303
+ * be added to the data structure. By default, it is set to 1, meaning that if no value is provided
12304
+ * for `count`, the key-value pair will be added once.
12305
+ * @returns The method is returning a boolean value. It returns true if the addition of the new node
12306
+ * was successful, and false otherwise.
12162
12307
  */
12163
- add(keyOrNodeOrEntry, value, count = 1) {
12164
- const newNode = this.keyValueOrEntryToNode(keyOrNodeOrEntry, value, count);
12308
+ add(keyOrNodeOrEntryOrRawElement, value, count = 1) {
12309
+ const newNode = this.keyValueOrEntryOrRawElementToNode(keyOrNodeOrEntryOrRawElement, value, count);
12165
12310
  const orgCount = (newNode == null ? void 0 : newNode.count) || 0;
12166
12311
  const isSuccessAdded = super.add(newNode);
12167
12312
  if (isSuccessAdded) {
@@ -12179,20 +12324,18 @@ var dataStructureTyped = (() => {
12179
12324
  * Time Complexity: O(log n)
12180
12325
  * Space Complexity: O(1)
12181
12326
  *
12182
- * The `delete` function in a TypeScript class is used to delete nodes from a binary tree based on a
12183
- * given identifier, and it returns an array of results containing information about the deleted
12184
- * nodes.
12185
- * @param {ReturnType<C> | null | undefined} identifier - The identifier parameter is the value used
12186
- * to identify the node to be deleted. It can be of any type that is returned by the callback
12187
- * function. It can also be null or undefined if no node needs to be deleted.
12188
- * @param {C} callback - The `callback` parameter is a function that takes a node of type `NODE` as
12189
- * input and returns a value of type `ReturnType<C>`. It is used to determine if a node matches the
12190
- * identifier for deletion. If no callback is provided, the `_DEFAULT_CALLBACK` function is
12191
- * used
12192
- * @param [ignoreCount=false] - A boolean value indicating whether to ignore the count of the target
12193
- * node when performing deletion. If set to true, the count of the target node will not be considered
12194
- * and the node will be deleted regardless of its count. If set to false (default), the count of the
12195
- * target node will be decremented
12327
+ * The function `delete` is used to remove a node from a binary tree and fix the tree if necessary.
12328
+ * @param {ReturnType<C> | null | undefined} identifier - The `identifier` parameter is the value or
12329
+ * key that is used to identify the node that needs to be deleted from the binary tree. It can be of
12330
+ * any type that is returned by the callback function `C`. It can also be `null` or `undefined` if
12331
+ * the node to be deleted
12332
+ * @param {C} callback - The `callback` parameter is a function that is used to determine the
12333
+ * equality of nodes in the binary tree. It is optional and has a default value of
12334
+ * `this._DEFAULT_CALLBACK`. The `callback` function is used to compare nodes when searching for a
12335
+ * specific node or when performing other operations on the
12336
+ * @param [ignoreCount=false] - A boolean flag indicating whether to ignore the count of the node
12337
+ * being deleted. If set to true, the count of the node will not be taken into account when deleting
12338
+ * it. If set to false, the count of the node will be decremented by 1 before deleting it.
12196
12339
  * @returns an array of BinaryTreeDeleteResult<NODE> objects.
12197
12340
  */
12198
12341
  delete(identifier, callback = this._DEFAULT_CALLBACK, ignoreCount = false) {
@@ -12300,10 +12443,12 @@ var dataStructureTyped = (() => {
12300
12443
  *
12301
12444
  * The `perfectlyBalance` function takes a sorted array of nodes and builds a balanced binary search
12302
12445
  * tree using either a recursive or iterative approach.
12303
- * @param iterationType - The `iterationType` parameter is an optional parameter that specifies the
12304
- * type of iteration to use when building the balanced binary search tree. It can have two possible
12305
- * values:
12306
- * @returns a boolean value.
12446
+ * @param {IterationType} iterationType - The `iterationType` parameter is an optional parameter that
12447
+ * specifies the type of iteration to use when building the balanced binary search tree. It has a
12448
+ * default value of `this.iterationType`, which means it will use the iteration type specified by the
12449
+ * `iterationType` property of the current object.
12450
+ * @returns The function `perfectlyBalance` returns a boolean value. It returns `true` if the
12451
+ * balancing operation is successful, and `false` if there are no nodes to balance.
12307
12452
  */
12308
12453
  perfectlyBalance(iterationType = this.iterationType) {
12309
12454
  const sorted = this.dfs((node) => node, "IN"), n = sorted.length;
@@ -12357,15 +12502,22 @@ var dataStructureTyped = (() => {
12357
12502
  return cloned;
12358
12503
  }
12359
12504
  /**
12360
- * The function swaps the properties of two nodes in a binary search tree.
12361
- * @param srcNode - The source node that needs to be swapped with the destination node. It can be
12362
- * either a key or a node object.
12363
- * @param destNode - The `destNode` parameter is the node in the binary search tree where the
12364
- * properties will be swapped with the `srcNode`.
12505
+ * Time Complexity: O(1)
12506
+ * Space Complexity: O(1)
12507
+ */
12508
+ /**
12509
+ * Time Complexity: O(1)
12510
+ * Space Complexity: O(1)
12511
+ *
12512
+ * The `_swapProperties` function swaps the properties (key, value, count, color) between two nodes
12513
+ * in a binary search tree.
12514
+ * @param {R | BSTNKeyOrNode<K, NODE>} srcNode - The `srcNode` parameter represents the source node
12515
+ * that will be swapped with the `destNode`. It can be either an instance of the `R` class or an
12516
+ * instance of the `BSTNKeyOrNode<K, NODE>` class.
12517
+ * @param {R | BSTNKeyOrNode<K, NODE>} destNode - The `destNode` parameter represents the destination
12518
+ * node where the properties will be swapped with the source node.
12365
12519
  * @returns The method is returning the `destNode` after swapping its properties with the `srcNode`.
12366
- * If both `srcNode` and `destNode` are valid nodes, the method swaps their `key`, `value`, `count`,
12367
- * and `color` properties. If the swapping is successful, the method returns the modified `destNode`.
12368
- * If either `srcNode` or `destNode` is
12520
+ * If either `srcNode` or `destNode` is undefined, it returns undefined.
12369
12521
  */
12370
12522
  _swapProperties(srcNode, destNode) {
12371
12523
  srcNode = this.ensureNode(srcNode);
@@ -12389,12 +12541,19 @@ var dataStructureTyped = (() => {
12389
12541
  return void 0;
12390
12542
  }
12391
12543
  /**
12544
+ * Time Complexity: O(1)
12545
+ * Space Complexity: O(1)
12546
+ */
12547
+ /**
12548
+ * Time Complexity: O(1)
12549
+ * Space Complexity: O(1)
12550
+ *
12392
12551
  * The function replaces an old node with a new node and updates the count property of the new node.
12393
- * @param {NODE} oldNode - The `oldNode` parameter is of type `NODE` and represents the node that
12394
- * needs to be replaced in the data structure.
12395
- * @param {NODE} newNode - The `newNode` parameter is an object of type `NODE`.
12552
+ * @param {NODE} oldNode - The `oldNode` parameter is the node that you want to replace in the data
12553
+ * structure.
12554
+ * @param {NODE} newNode - The `newNode` parameter is an instance of the `NODE` class.
12396
12555
  * @returns The method is returning the result of calling the `_replaceNode` method from the
12397
- * superclass, after updating the `count` property of the `newNode` object.
12556
+ * superclass, which is of type `NODE`.
12398
12557
  */
12399
12558
  _replaceNode(oldNode, newNode) {
12400
12559
  newNode.count = oldNode.count + newNode.count;