data-structure-typed 1.51.9 → 1.52.1

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 (206) hide show
  1. package/CHANGELOG.md +1 -1
  2. package/README.md +141 -54
  3. package/benchmark/report.html +37 -1
  4. package/benchmark/report.json +385 -13
  5. package/dist/cjs/data-structures/base/index.d.ts +2 -1
  6. package/dist/cjs/data-structures/base/index.js +2 -1
  7. package/dist/cjs/data-structures/base/index.js.map +1 -1
  8. package/dist/cjs/data-structures/base/iterable-element-base.d.ts +171 -0
  9. package/dist/cjs/data-structures/base/iterable-element-base.js +226 -0
  10. package/dist/cjs/data-structures/base/iterable-element-base.js.map +1 -0
  11. package/dist/cjs/data-structures/base/{iterable-base.d.ts → iterable-entry-base.d.ts} +4 -147
  12. package/dist/cjs/data-structures/base/{iterable-base.js → iterable-entry-base.js} +13 -190
  13. package/dist/cjs/data-structures/base/iterable-entry-base.js.map +1 -0
  14. package/dist/cjs/data-structures/binary-tree/avl-tree-multi-map.d.ts +13 -13
  15. package/dist/cjs/data-structures/binary-tree/avl-tree-multi-map.js +6 -6
  16. package/dist/cjs/data-structures/binary-tree/avl-tree-multi-map.js.map +1 -1
  17. package/dist/cjs/data-structures/binary-tree/avl-tree.d.ts +13 -13
  18. package/dist/cjs/data-structures/binary-tree/avl-tree.js +6 -6
  19. package/dist/cjs/data-structures/binary-tree/avl-tree.js.map +1 -1
  20. package/dist/cjs/data-structures/binary-tree/binary-tree.d.ts +99 -99
  21. package/dist/cjs/data-structures/binary-tree/binary-tree.js +54 -52
  22. package/dist/cjs/data-structures/binary-tree/binary-tree.js.map +1 -1
  23. package/dist/cjs/data-structures/binary-tree/bst.d.ts +37 -45
  24. package/dist/cjs/data-structures/binary-tree/bst.js +17 -25
  25. package/dist/cjs/data-structures/binary-tree/bst.js.map +1 -1
  26. package/dist/cjs/data-structures/binary-tree/rb-tree.d.ts +10 -10
  27. package/dist/cjs/data-structures/binary-tree/rb-tree.js +6 -6
  28. package/dist/cjs/data-structures/binary-tree/rb-tree.js.map +1 -1
  29. package/dist/cjs/data-structures/binary-tree/tree-multi-map.d.ts +12 -12
  30. package/dist/cjs/data-structures/binary-tree/tree-multi-map.js +5 -5
  31. package/dist/cjs/data-structures/binary-tree/tree-multi-map.js.map +1 -1
  32. package/dist/cjs/data-structures/graph/directed-graph.js +2 -1
  33. package/dist/cjs/data-structures/graph/directed-graph.js.map +1 -1
  34. package/dist/cjs/data-structures/hash/hash-map.d.ts +2 -2
  35. package/dist/cjs/data-structures/hash/hash-map.js.map +1 -1
  36. package/dist/cjs/data-structures/heap/heap.d.ts +43 -114
  37. package/dist/cjs/data-structures/heap/heap.js +59 -127
  38. package/dist/cjs/data-structures/heap/heap.js.map +1 -1
  39. package/dist/cjs/data-structures/heap/max-heap.d.ts +50 -4
  40. package/dist/cjs/data-structures/heap/max-heap.js +76 -10
  41. package/dist/cjs/data-structures/heap/max-heap.js.map +1 -1
  42. package/dist/cjs/data-structures/heap/min-heap.d.ts +51 -5
  43. package/dist/cjs/data-structures/heap/min-heap.js +68 -11
  44. package/dist/cjs/data-structures/heap/min-heap.js.map +1 -1
  45. package/dist/cjs/data-structures/linked-list/doubly-linked-list.d.ts +22 -28
  46. package/dist/cjs/data-structures/linked-list/doubly-linked-list.js +26 -28
  47. package/dist/cjs/data-structures/linked-list/doubly-linked-list.js.map +1 -1
  48. package/dist/cjs/data-structures/linked-list/singly-linked-list.d.ts +22 -25
  49. package/dist/cjs/data-structures/linked-list/singly-linked-list.js +29 -26
  50. package/dist/cjs/data-structures/linked-list/singly-linked-list.js.map +1 -1
  51. package/dist/cjs/data-structures/priority-queue/max-priority-queue.d.ts +50 -4
  52. package/dist/cjs/data-structures/priority-queue/max-priority-queue.js +79 -10
  53. package/dist/cjs/data-structures/priority-queue/max-priority-queue.js.map +1 -1
  54. package/dist/cjs/data-structures/priority-queue/min-priority-queue.d.ts +51 -5
  55. package/dist/cjs/data-structures/priority-queue/min-priority-queue.js +71 -11
  56. package/dist/cjs/data-structures/priority-queue/min-priority-queue.js.map +1 -1
  57. package/dist/cjs/data-structures/priority-queue/priority-queue.d.ts +50 -4
  58. package/dist/cjs/data-structures/priority-queue/priority-queue.js +70 -1
  59. package/dist/cjs/data-structures/priority-queue/priority-queue.js.map +1 -1
  60. package/dist/cjs/data-structures/queue/deque.d.ts +27 -18
  61. package/dist/cjs/data-structures/queue/deque.js +43 -21
  62. package/dist/cjs/data-structures/queue/deque.js.map +1 -1
  63. package/dist/cjs/data-structures/queue/queue.d.ts +8 -29
  64. package/dist/cjs/data-structures/queue/queue.js +15 -32
  65. package/dist/cjs/data-structures/queue/queue.js.map +1 -1
  66. package/dist/cjs/data-structures/stack/stack.d.ts +17 -22
  67. package/dist/cjs/data-structures/stack/stack.js +25 -24
  68. package/dist/cjs/data-structures/stack/stack.js.map +1 -1
  69. package/dist/cjs/data-structures/trie/trie.d.ts +18 -13
  70. package/dist/cjs/data-structures/trie/trie.js +26 -15
  71. package/dist/cjs/data-structures/trie/trie.js.map +1 -1
  72. package/dist/cjs/interfaces/binary-tree.d.ts +4 -4
  73. package/dist/cjs/types/common.d.ts +1 -22
  74. package/dist/cjs/types/data-structures/base/base.d.ts +5 -2
  75. package/dist/cjs/types/data-structures/binary-tree/avl-tree-multi-map.d.ts +2 -3
  76. package/dist/cjs/types/data-structures/binary-tree/avl-tree.d.ts +2 -3
  77. package/dist/cjs/types/data-structures/binary-tree/binary-tree.d.ts +20 -4
  78. package/dist/cjs/types/data-structures/binary-tree/bst.d.ts +5 -3
  79. package/dist/cjs/types/data-structures/binary-tree/rb-tree.d.ts +2 -3
  80. package/dist/cjs/types/data-structures/binary-tree/tree-multi-map.d.ts +2 -3
  81. package/dist/cjs/types/data-structures/heap/heap.d.ts +3 -2
  82. package/dist/cjs/types/data-structures/linked-list/doubly-linked-list.d.ts +2 -1
  83. package/dist/cjs/types/data-structures/linked-list/singly-linked-list.d.ts +2 -1
  84. package/dist/cjs/types/data-structures/priority-queue/priority-queue.d.ts +1 -1
  85. package/dist/cjs/types/data-structures/queue/deque.d.ts +4 -2
  86. package/dist/cjs/types/data-structures/queue/queue.d.ts +2 -1
  87. package/dist/cjs/types/data-structures/stack/stack.d.ts +2 -1
  88. package/dist/cjs/types/data-structures/trie/trie.d.ts +3 -2
  89. package/dist/cjs/utils/number.js +1 -2
  90. package/dist/cjs/utils/number.js.map +1 -1
  91. package/dist/cjs/utils/utils.js +2 -2
  92. package/dist/cjs/utils/utils.js.map +1 -1
  93. package/dist/mjs/data-structures/base/index.d.ts +2 -1
  94. package/dist/mjs/data-structures/base/index.js +2 -1
  95. package/dist/mjs/data-structures/base/iterable-element-base.d.ts +171 -0
  96. package/dist/mjs/data-structures/base/iterable-element-base.js +222 -0
  97. package/dist/mjs/data-structures/base/{iterable-base.d.ts → iterable-entry-base.d.ts} +4 -147
  98. package/dist/mjs/data-structures/base/{iterable-base.js → iterable-entry-base.js} +10 -186
  99. package/dist/mjs/data-structures/binary-tree/avl-tree-multi-map.d.ts +13 -13
  100. package/dist/mjs/data-structures/binary-tree/avl-tree-multi-map.js +6 -6
  101. package/dist/mjs/data-structures/binary-tree/avl-tree.d.ts +13 -13
  102. package/dist/mjs/data-structures/binary-tree/avl-tree.js +6 -6
  103. package/dist/mjs/data-structures/binary-tree/binary-tree.d.ts +99 -99
  104. package/dist/mjs/data-structures/binary-tree/binary-tree.js +54 -52
  105. package/dist/mjs/data-structures/binary-tree/bst.d.ts +37 -45
  106. package/dist/mjs/data-structures/binary-tree/bst.js +17 -25
  107. package/dist/mjs/data-structures/binary-tree/rb-tree.d.ts +10 -10
  108. package/dist/mjs/data-structures/binary-tree/rb-tree.js +6 -6
  109. package/dist/mjs/data-structures/binary-tree/tree-multi-map.d.ts +12 -12
  110. package/dist/mjs/data-structures/binary-tree/tree-multi-map.js +5 -5
  111. package/dist/mjs/data-structures/graph/directed-graph.js +2 -1
  112. package/dist/mjs/data-structures/hash/hash-map.d.ts +2 -2
  113. package/dist/mjs/data-structures/heap/heap.d.ts +43 -114
  114. package/dist/mjs/data-structures/heap/heap.js +60 -128
  115. package/dist/mjs/data-structures/heap/max-heap.d.ts +50 -4
  116. package/dist/mjs/data-structures/heap/max-heap.js +79 -10
  117. package/dist/mjs/data-structures/heap/min-heap.d.ts +51 -5
  118. package/dist/mjs/data-structures/heap/min-heap.js +68 -11
  119. package/dist/mjs/data-structures/linked-list/doubly-linked-list.d.ts +22 -28
  120. package/dist/mjs/data-structures/linked-list/doubly-linked-list.js +26 -28
  121. package/dist/mjs/data-structures/linked-list/singly-linked-list.d.ts +22 -25
  122. package/dist/mjs/data-structures/linked-list/singly-linked-list.js +29 -26
  123. package/dist/mjs/data-structures/priority-queue/max-priority-queue.d.ts +50 -4
  124. package/dist/mjs/data-structures/priority-queue/max-priority-queue.js +82 -10
  125. package/dist/mjs/data-structures/priority-queue/min-priority-queue.d.ts +51 -5
  126. package/dist/mjs/data-structures/priority-queue/min-priority-queue.js +71 -11
  127. package/dist/mjs/data-structures/priority-queue/priority-queue.d.ts +50 -4
  128. package/dist/mjs/data-structures/priority-queue/priority-queue.js +70 -1
  129. package/dist/mjs/data-structures/queue/deque.d.ts +27 -18
  130. package/dist/mjs/data-structures/queue/deque.js +43 -21
  131. package/dist/mjs/data-structures/queue/queue.d.ts +8 -29
  132. package/dist/mjs/data-structures/queue/queue.js +15 -32
  133. package/dist/mjs/data-structures/stack/stack.d.ts +17 -22
  134. package/dist/mjs/data-structures/stack/stack.js +25 -24
  135. package/dist/mjs/data-structures/trie/trie.d.ts +18 -13
  136. package/dist/mjs/data-structures/trie/trie.js +26 -15
  137. package/dist/mjs/interfaces/binary-tree.d.ts +4 -4
  138. package/dist/mjs/types/common.d.ts +1 -22
  139. package/dist/mjs/types/data-structures/base/base.d.ts +5 -2
  140. package/dist/mjs/types/data-structures/binary-tree/avl-tree-multi-map.d.ts +2 -3
  141. package/dist/mjs/types/data-structures/binary-tree/avl-tree.d.ts +2 -3
  142. package/dist/mjs/types/data-structures/binary-tree/binary-tree.d.ts +20 -4
  143. package/dist/mjs/types/data-structures/binary-tree/bst.d.ts +5 -3
  144. package/dist/mjs/types/data-structures/binary-tree/rb-tree.d.ts +2 -3
  145. package/dist/mjs/types/data-structures/binary-tree/tree-multi-map.d.ts +2 -3
  146. package/dist/mjs/types/data-structures/heap/heap.d.ts +3 -2
  147. package/dist/mjs/types/data-structures/linked-list/doubly-linked-list.d.ts +2 -1
  148. package/dist/mjs/types/data-structures/linked-list/singly-linked-list.d.ts +2 -1
  149. package/dist/mjs/types/data-structures/priority-queue/priority-queue.d.ts +1 -1
  150. package/dist/mjs/types/data-structures/queue/deque.d.ts +4 -2
  151. package/dist/mjs/types/data-structures/queue/queue.d.ts +2 -1
  152. package/dist/mjs/types/data-structures/stack/stack.d.ts +2 -1
  153. package/dist/mjs/types/data-structures/trie/trie.d.ts +3 -2
  154. package/dist/umd/data-structure-typed.js +732 -409
  155. package/dist/umd/data-structure-typed.min.js +2 -2
  156. package/dist/umd/data-structure-typed.min.js.map +1 -1
  157. package/package.json +7 -7
  158. package/src/data-structures/base/index.ts +2 -1
  159. package/src/data-structures/base/iterable-element-base.ts +250 -0
  160. package/src/data-structures/base/{iterable-base.ts → iterable-entry-base.ts} +22 -213
  161. package/src/data-structures/binary-tree/avl-tree-multi-map.ts +14 -15
  162. package/src/data-structures/binary-tree/avl-tree.ts +13 -14
  163. package/src/data-structures/binary-tree/binary-tree.ts +156 -152
  164. package/src/data-structures/binary-tree/bst.ts +52 -60
  165. package/src/data-structures/binary-tree/rb-tree.ts +12 -13
  166. package/src/data-structures/binary-tree/tree-multi-map.ts +12 -13
  167. package/src/data-structures/graph/directed-graph.ts +2 -1
  168. package/src/data-structures/hash/hash-map.ts +4 -4
  169. package/src/data-structures/heap/heap.ts +71 -152
  170. package/src/data-structures/heap/max-heap.ts +88 -13
  171. package/src/data-structures/heap/min-heap.ts +78 -15
  172. package/src/data-structures/linked-list/doubly-linked-list.ts +32 -32
  173. package/src/data-structures/linked-list/singly-linked-list.ts +37 -29
  174. package/src/data-structures/priority-queue/max-priority-queue.ts +94 -13
  175. package/src/data-structures/priority-queue/min-priority-queue.ts +84 -15
  176. package/src/data-structures/priority-queue/priority-queue.ts +81 -4
  177. package/src/data-structures/queue/deque.ts +50 -25
  178. package/src/data-structures/queue/queue.ts +23 -37
  179. package/src/data-structures/stack/stack.ts +31 -26
  180. package/src/data-structures/trie/trie.ts +33 -18
  181. package/src/interfaces/binary-tree.ts +4 -5
  182. package/src/types/common.ts +2 -24
  183. package/src/types/data-structures/base/base.ts +14 -6
  184. package/src/types/data-structures/binary-tree/avl-tree-multi-map.ts +2 -3
  185. package/src/types/data-structures/binary-tree/avl-tree.ts +2 -3
  186. package/src/types/data-structures/binary-tree/binary-tree.ts +24 -5
  187. package/src/types/data-structures/binary-tree/bst.ts +9 -3
  188. package/src/types/data-structures/binary-tree/rb-tree.ts +2 -3
  189. package/src/types/data-structures/binary-tree/tree-multi-map.ts +2 -3
  190. package/src/types/data-structures/heap/heap.ts +4 -1
  191. package/src/types/data-structures/linked-list/doubly-linked-list.ts +3 -1
  192. package/src/types/data-structures/linked-list/singly-linked-list.ts +3 -1
  193. package/src/types/data-structures/priority-queue/priority-queue.ts +1 -1
  194. package/src/types/data-structures/queue/deque.ts +6 -1
  195. package/src/types/data-structures/queue/queue.ts +3 -1
  196. package/src/types/data-structures/stack/stack.ts +3 -1
  197. package/src/types/data-structures/trie/trie.ts +3 -1
  198. package/test/unit/data-structures/binary-tree/avl-tree-multi-map.test.ts +1 -1
  199. package/test/unit/data-structures/graph/directed-graph.test.ts +28 -0
  200. package/test/unit/data-structures/heap/heap.test.ts +100 -0
  201. package/test/unit/data-structures/heap/max-heap.test.ts +44 -1
  202. package/test/unit/data-structures/heap/min-heap.test.ts +18 -1
  203. package/test/unit/data-structures/priority-queue/max-priority-queue.test.ts +42 -0
  204. package/test/unit/data-structures/queue/deque.test.ts +49 -0
  205. package/test/unit/data-structures/queue/queue.test.ts +56 -0
  206. package/dist/cjs/data-structures/base/iterable-base.js.map +0 -1
@@ -173,8 +173,17 @@ var dataStructureTyped = (() => {
173
173
  uuidV4: () => uuidV4
174
174
  });
175
175
 
176
- // src/data-structures/base/iterable-base.ts
176
+ // src/data-structures/base/iterable-entry-base.ts
177
177
  var IterableEntryBase = class {
178
+ // protected _toEntryFn?: (rawElement: R) => BTNEntry<K, V>;
179
+ //
180
+ // /**
181
+ // * The function returns the value of the _toEntryFn property.
182
+ // * @returns The function being returned is `this._toEntryFn`.
183
+ // */
184
+ // get toEntryFn() {
185
+ // return this._toEntryFn;
186
+ // }
178
187
  /**
179
188
  * Time Complexity: O(n)
180
189
  * Space Complexity: O(1)
@@ -439,11 +448,44 @@ var dataStructureTyped = (() => {
439
448
  * Time Complexity: O(n)
440
449
  * Space Complexity: O(n)
441
450
  */
451
+ /**
452
+ * Time Complexity: O(n)
453
+ * Space Complexity: O(n)
454
+ *
455
+ * The print function logs the elements of an array to the console.
456
+ */
442
457
  print() {
443
458
  console.log([...this]);
444
459
  }
445
460
  };
461
+
462
+ // src/data-structures/base/iterable-element-base.ts
446
463
  var IterableElementBase = class {
464
+ /**
465
+ * The protected constructor initializes the options for the IterableElementBase class, including the
466
+ * toElementFn function.
467
+ * @param [options] - An optional object that contains the following properties:
468
+ */
469
+ constructor(options) {
470
+ __publicField(this, "_toElementFn");
471
+ if (options) {
472
+ const { toElementFn } = options;
473
+ if (typeof toElementFn === "function")
474
+ this._toElementFn = toElementFn;
475
+ else if (toElementFn)
476
+ throw new TypeError("toElementFn must be a function type");
477
+ }
478
+ }
479
+ /**
480
+ * The function returns the _toElementFn property, which is a function that converts a raw element to
481
+ * a specific type.
482
+ * @returns The function `get toElementFn()` is returning either a function that takes a raw element
483
+ * `rawElement` of type `R` and returns an element `E`, or `undefined` if no function is assigned to
484
+ * `_toElementFn`.
485
+ */
486
+ get toElementFn() {
487
+ return this._toElementFn;
488
+ }
447
489
  /**
448
490
  * Time Complexity: O(n)
449
491
  * Space Complexity: O(1)
@@ -630,6 +672,12 @@ var dataStructureTyped = (() => {
630
672
  * Time Complexity: O(n)
631
673
  * Space Complexity: O(n)
632
674
  */
675
+ /**
676
+ * Time Complexity: O(n)
677
+ * Space Complexity: O(n)
678
+ *
679
+ * The print function logs the elements of an array to the console.
680
+ */
633
681
  print() {
634
682
  console.log([...this]);
635
683
  }
@@ -1641,20 +1689,19 @@ var dataStructureTyped = (() => {
1641
1689
  }
1642
1690
  };
1643
1691
  var SinglyLinkedList = class _SinglyLinkedList extends IterableElementBase {
1644
- /**
1645
- * The constructor initializes a new instance of a class with an optional iterable of elements.
1646
- * @param elements - The `elements` parameter is an optional iterable object that contains the
1647
- * initial elements to be added to the instance of the class. If no `elements` are provided, an empty
1648
- * array will be used as the default value.
1649
- */
1650
- constructor(elements = []) {
1651
- super();
1692
+ constructor(elements = [], options) {
1693
+ super(options);
1652
1694
  __publicField(this, "_head");
1653
1695
  __publicField(this, "_tail");
1654
1696
  __publicField(this, "_size", 0);
1655
1697
  if (elements) {
1656
- for (const el of elements)
1657
- this.push(el);
1698
+ for (const el of elements) {
1699
+ if (this.toElementFn) {
1700
+ this.push(this.toElementFn(el));
1701
+ } else {
1702
+ this.push(el);
1703
+ }
1704
+ }
1658
1705
  }
1659
1706
  }
1660
1707
  /**
@@ -2199,7 +2246,7 @@ var dataStructureTyped = (() => {
2199
2246
  * is a clone of the original list.
2200
2247
  */
2201
2248
  clone() {
2202
- return new _SinglyLinkedList(this.values());
2249
+ return new _SinglyLinkedList(this, { toElementFn: this.toElementFn });
2203
2250
  }
2204
2251
  /**
2205
2252
  * Time Complexity: O(n)
@@ -2223,7 +2270,7 @@ var dataStructureTyped = (() => {
2223
2270
  * elements that pass the filter condition specified by the `callback` function.
2224
2271
  */
2225
2272
  filter(callback, thisArg) {
2226
- const filteredList = new _SinglyLinkedList();
2273
+ const filteredList = new _SinglyLinkedList([], { toElementFn: this.toElementFn });
2227
2274
  let index = 0;
2228
2275
  for (const current of this) {
2229
2276
  if (callback.call(thisArg, current, index, this)) {
@@ -2238,21 +2285,24 @@ var dataStructureTyped = (() => {
2238
2285
  * Space Complexity: O(n)
2239
2286
  */
2240
2287
  /**
2241
- * Time Complexity: O(n)
2242
- * Space Complexity: O(n)
2243
- *
2244
- * The `map` function creates a new SinglyLinkedList by applying a callback function to each element
2245
- * of the original list.
2288
+ * The `map` function takes a callback function and returns a new SinglyLinkedList with the results
2289
+ * of applying the callback to each element in the original list.
2246
2290
  * @param callback - The `callback` parameter is a function that will be called for each element in
2247
- * the linked list. It takes three arguments:
2248
- * @param {any} [thisArg] - The `thisArg` parameter is an optional argument that specifies the value
2249
- * to be used as `this` when executing the `callback` function. If `thisArg` is provided, it will be
2250
- * passed as the `this` value to the `callback` function. If `thisArg` is
2251
- * @returns The `map` function is returning a new `SinglyLinkedList` object that contains the results
2252
- * of applying the provided `callback` function to each element in the original list.
2291
+ * the original list. It takes three arguments: `current` (the current element being processed),
2292
+ * `index` (the index of the current element), and `this` (the original list). It should return a
2293
+ * value
2294
+ * @param [toElementFn] - The `toElementFn` parameter is an optional function that can be used to
2295
+ * convert the raw element (`RR`) to the desired element type (`T`). It takes the raw element as
2296
+ * input and returns the converted element. If this parameter is not provided, the raw element will
2297
+ * be used as is.
2298
+ * @param {any} [thisArg] - The `thisArg` parameter is an optional argument that allows you to
2299
+ * specify the value of `this` within the callback function. It is used to set the context or scope
2300
+ * in which the callback function will be executed. If `thisArg` is provided, it will be used as the
2301
+ * value of
2302
+ * @returns a new instance of the `SinglyLinkedList` class with the mapped elements.
2253
2303
  */
2254
- map(callback, thisArg) {
2255
- const mappedList = new _SinglyLinkedList();
2304
+ map(callback, toElementFn, thisArg) {
2305
+ const mappedList = new _SinglyLinkedList([], { toElementFn });
2256
2306
  let index = 0;
2257
2307
  for (const current of this) {
2258
2308
  mappedList.push(callback.call(thisArg, current, index, this));
@@ -2337,14 +2387,8 @@ var dataStructureTyped = (() => {
2337
2387
  }
2338
2388
  };
2339
2389
  var DoublyLinkedList = class _DoublyLinkedList extends IterableElementBase {
2340
- /**
2341
- * The constructor initializes a linked list with optional elements.
2342
- * @param elements - The `elements` parameter is an optional iterable object that contains the
2343
- * initial elements to be added to the data structure. It defaults to an empty array if no elements
2344
- * are provided.
2345
- */
2346
- constructor(elements = []) {
2347
- super();
2390
+ constructor(elements = [], options) {
2391
+ super(options);
2348
2392
  __publicField(this, "_head");
2349
2393
  __publicField(this, "_tail");
2350
2394
  __publicField(this, "_size");
@@ -2353,7 +2397,10 @@ var dataStructureTyped = (() => {
2353
2397
  this._size = 0;
2354
2398
  if (elements) {
2355
2399
  for (const el of elements) {
2356
- this.push(el);
2400
+ if (this.toElementFn) {
2401
+ this.push(this.toElementFn(el));
2402
+ } else
2403
+ this.push(el);
2357
2404
  }
2358
2405
  }
2359
2406
  }
@@ -2924,7 +2971,7 @@ var dataStructureTyped = (() => {
2924
2971
  * is a copy of the original list.
2925
2972
  */
2926
2973
  clone() {
2927
- return new _DoublyLinkedList(this.values());
2974
+ return new _DoublyLinkedList(this);
2928
2975
  }
2929
2976
  /**
2930
2977
  * Time Complexity: O(n)
@@ -2948,7 +2995,7 @@ var dataStructureTyped = (() => {
2948
2995
  * elements that pass the filter condition specified by the `callback` function.
2949
2996
  */
2950
2997
  filter(callback, thisArg) {
2951
- const filteredList = new _DoublyLinkedList();
2998
+ const filteredList = new _DoublyLinkedList([], { toElementFn: this.toElementFn });
2952
2999
  let index = 0;
2953
3000
  for (const current of this) {
2954
3001
  if (callback.call(thisArg, current, index, this)) {
@@ -2963,24 +3010,24 @@ var dataStructureTyped = (() => {
2963
3010
  * Space Complexity: O(n)
2964
3011
  */
2965
3012
  /**
2966
- * Time Complexity: O(n)
2967
- * Space Complexity: O(n)
2968
- *
2969
- * The `map` function creates a new DoublyLinkedList by applying a callback function to each element
2970
- * in the original list.
3013
+ * The `map` function takes a callback function and returns a new DoublyLinkedList with the results
3014
+ * of applying the callback to each element in the original list.
2971
3015
  * @param callback - The callback parameter is a function that will be called for each element in the
2972
- * DoublyLinkedList. It takes three arguments: the current element, the index of the current element,
2973
- * and the DoublyLinkedList itself. The callback function should return a value that will be added to
2974
- * the new DoublyLinkedList that
2975
- * @param {any} [thisArg] - The `thisArg` parameter is an optional argument that specifies the value
2976
- * to be used as `this` when executing the `callback` function. If `thisArg` is provided, it will be
2977
- * passed as the `this` value to the `callback` function. If `thisArg` is
2978
- * @returns The `map` function is returning a new `DoublyLinkedList` object that contains the results
2979
- * of applying the provided `callback` function to each element in the original `DoublyLinkedList`
2980
- * object.
3016
+ * original DoublyLinkedList. It takes three arguments: current (the current element being
3017
+ * processed), index (the index of the current element), and this (the original DoublyLinkedList).
3018
+ * The callback function should return a value of type
3019
+ * @param [toElementFn] - The `toElementFn` parameter is an optional function that can be used to
3020
+ * convert the raw element (`RR`) to the desired element type (`T`). It takes the raw element as
3021
+ * input and returns the converted element. If this parameter is not provided, the raw element will
3022
+ * be used as is.
3023
+ * @param {any} [thisArg] - The `thisArg` parameter is an optional argument that allows you to
3024
+ * specify the value of `this` within the callback function. It is used to set the context or scope
3025
+ * in which the callback function will be executed. If `thisArg` is provided, it will be used as the
3026
+ * value of
3027
+ * @returns a new instance of the `DoublyLinkedList` class with elements of type `T` and `RR`.
2981
3028
  */
2982
- map(callback, thisArg) {
2983
- const mappedList = new _DoublyLinkedList();
3029
+ map(callback, toElementFn, thisArg) {
3030
+ const mappedList = new _DoublyLinkedList([], { toElementFn });
2984
3031
  let index = 0;
2985
3032
  for (const current of this) {
2986
3033
  mappedList.push(callback.call(thisArg, current, index, this));
@@ -3277,18 +3324,17 @@ var dataStructureTyped = (() => {
3277
3324
 
3278
3325
  // src/data-structures/stack/stack.ts
3279
3326
  var Stack = class _Stack extends IterableElementBase {
3280
- /**
3281
- * The constructor initializes an array of elements, which can be provided as an optional parameter.
3282
- * @param {E[]} [elements] - The `elements` parameter is an optional parameter of type `E[]`, which represents an array
3283
- * of elements of type `E`. It is used to initialize the `_elements` property of the class. If the `elements` parameter
3284
- * is provided and is an array, it is assigned to the `_elements
3285
- */
3286
- constructor(elements = []) {
3287
- super();
3327
+ constructor(elements = [], options) {
3328
+ super(options);
3288
3329
  __publicField(this, "_elements", []);
3289
3330
  if (elements) {
3290
- for (const el of elements)
3291
- this.push(el);
3331
+ for (const el of elements) {
3332
+ if (this.toElementFn) {
3333
+ this.push(this.toElementFn(el));
3334
+ } else {
3335
+ this.push(el);
3336
+ }
3337
+ }
3292
3338
  }
3293
3339
  }
3294
3340
  /**
@@ -3434,7 +3480,7 @@ var dataStructureTyped = (() => {
3434
3480
  * @returns The `clone()` method is returning a new `Stack` object with a copy of the `_elements` array.
3435
3481
  */
3436
3482
  clone() {
3437
- return new _Stack(this.elements.slice());
3483
+ return new _Stack(this, { toElementFn: this.toElementFn });
3438
3484
  }
3439
3485
  /**
3440
3486
  * Time Complexity: O(n)
@@ -3457,7 +3503,7 @@ var dataStructureTyped = (() => {
3457
3503
  * satisfy the given predicate function.
3458
3504
  */
3459
3505
  filter(predicate, thisArg) {
3460
- const newStack = new _Stack();
3506
+ const newStack = new _Stack([], { toElementFn: this.toElementFn });
3461
3507
  let index = 0;
3462
3508
  for (const el of this) {
3463
3509
  if (predicate.call(thisArg, el, index, this)) {
@@ -3472,20 +3518,21 @@ var dataStructureTyped = (() => {
3472
3518
  * Space Complexity: O(n)
3473
3519
  */
3474
3520
  /**
3475
- * Time Complexity: O(n)
3476
- * Space Complexity: O(n)
3477
- *
3478
3521
  * The `map` function takes a callback function and applies it to each element in the stack,
3479
3522
  * returning a new stack with the results.
3480
- * @param callback - The `callback` parameter is a function that will be called for each element in
3481
- * the stack. It takes three arguments:
3482
- * @param {any} [thisArg] - The `thisArg` parameter is an optional argument that specifies the value
3483
- * to be used as `this` when executing the `callback` function. If `thisArg` is provided, it will be
3484
- * passed as the `this` value to the `callback` function. If `thisArg` is
3485
- * @returns The `map` method is returning a new `Stack` object.
3523
+ * @param callback - The callback parameter is a function that will be called for each element in the
3524
+ * stack. It takes three arguments: the current element, the index of the element, and the stack
3525
+ * itself. It should return a new value that will be added to the new stack.
3526
+ * @param [toElementFn] - The `toElementFn` parameter is an optional function that can be used to
3527
+ * transform the raw element (`RM`) into a new element (`EM`) before pushing it into the new stack.
3528
+ * @param {any} [thisArg] - The `thisArg` parameter is an optional argument that allows you to
3529
+ * specify the value of `this` within the callback function. It is used to set the context or scope
3530
+ * in which the callback function will be executed. If `thisArg` is provided, it will be used as the
3531
+ * value of
3532
+ * @returns a new Stack object with elements of type EM and raw elements of type RM.
3486
3533
  */
3487
- map(callback, thisArg) {
3488
- const newStack = new _Stack();
3534
+ map(callback, toElementFn, thisArg) {
3535
+ const newStack = new _Stack([], { toElementFn });
3489
3536
  let index = 0;
3490
3537
  for (const el of this) {
3491
3538
  newStack.push(callback.call(thisArg, el, index, this));
@@ -3513,19 +3560,17 @@ var dataStructureTyped = (() => {
3513
3560
 
3514
3561
  // src/data-structures/queue/queue.ts
3515
3562
  var Queue = class _Queue extends IterableElementBase {
3516
- /**
3517
- * The constructor initializes an instance of a class with an optional array of elements and sets the offset to 0.
3518
- * @param {E[]} [elements] - The `elements` parameter is an optional array of elements of type `E`. If provided, it
3519
- * will be used to initialize the `_elements` property of the class. If not provided, the `_elements` property will be
3520
- * initialized as an empty array.
3521
- */
3522
- constructor(elements = []) {
3523
- super();
3563
+ constructor(elements = [], options) {
3564
+ super(options);
3524
3565
  __publicField(this, "_elements", []);
3525
3566
  __publicField(this, "_offset", 0);
3526
3567
  if (elements) {
3527
- for (const el of elements)
3528
- this.push(el);
3568
+ for (const el of elements) {
3569
+ if (this.toElementFn)
3570
+ this.push(this.toElementFn(el));
3571
+ else
3572
+ this.push(el);
3573
+ }
3529
3574
  }
3530
3575
  }
3531
3576
  /**
@@ -3589,7 +3634,6 @@ var dataStructureTyped = (() => {
3589
3634
  *
3590
3635
  * The function "fromArray" creates a new Queue object from an array of elements.Creates a queue from an existing array.
3591
3636
  * @public
3592
- * @static
3593
3637
  * @param {E[]} elements - The "elements" parameter is an array of elements of type E.
3594
3638
  * @returns The method is returning a new instance of the Queue class, initialized with the elements from the input
3595
3639
  * array.
@@ -3665,7 +3709,7 @@ var dataStructureTyped = (() => {
3665
3709
  * @param index
3666
3710
  */
3667
3711
  at(index) {
3668
- return this.elements[index];
3712
+ return this.elements[index + this._offset];
3669
3713
  }
3670
3714
  /**
3671
3715
  * Time Complexity: O(1)
@@ -3722,7 +3766,7 @@ var dataStructureTyped = (() => {
3722
3766
  * @returns The `clone()` method is returning a new instance of the `Queue` class.
3723
3767
  */
3724
3768
  clone() {
3725
- return new _Queue(this.elements.slice(this.offset));
3769
+ return new _Queue(this.elements.slice(this.offset), { toElementFn: this.toElementFn });
3726
3770
  }
3727
3771
  /**
3728
3772
  * Time Complexity: O(n)
@@ -3745,7 +3789,7 @@ var dataStructureTyped = (() => {
3745
3789
  * satisfy the given predicate function.
3746
3790
  */
3747
3791
  filter(predicate, thisArg) {
3748
- const newDeque = new _Queue([]);
3792
+ const newDeque = new _Queue([], { toElementFn: this.toElementFn });
3749
3793
  let index = 0;
3750
3794
  for (const el of this) {
3751
3795
  if (predicate.call(thisArg, el, index, this)) {
@@ -3759,22 +3803,8 @@ var dataStructureTyped = (() => {
3759
3803
  * Time Complexity: O(n)
3760
3804
  * Space Complexity: O(n)
3761
3805
  */
3762
- /**
3763
- * Time Complexity: O(n)
3764
- * Space Complexity: O(n)
3765
- *
3766
- * The `map` function takes a callback function and applies it to each element in the queue,
3767
- * returning a new queue with the results.
3768
- * @param callback - The callback parameter is a function that will be called for each element in the
3769
- * queue. It takes three arguments: the current element, the index of the current element, and the
3770
- * queue itself. The callback function should return a new value that will be added to the new queue.
3771
- * @param {any} [thisArg] - The `thisArg` parameter is an optional argument that specifies the value
3772
- * to be used as `this` when executing the `callback` function. If `thisArg` is provided, it will be
3773
- * passed as the `this` value to the `callback` function. If `thisArg` is
3774
- * @returns The `map` function is returning a new `Queue` object with the transformed elements.
3775
- */
3776
- map(callback, thisArg) {
3777
- const newDeque = new _Queue([]);
3806
+ map(callback, toElementFn, thisArg) {
3807
+ const newDeque = new _Queue([], { toElementFn });
3778
3808
  let index = 0;
3779
3809
  for (const el of this) {
3780
3810
  newDeque.push(callback.call(thisArg, el, index, this));
@@ -3793,7 +3823,7 @@ var dataStructureTyped = (() => {
3793
3823
  * The function `_getIterator` returns an iterable iterator for the elements in the class.
3794
3824
  */
3795
3825
  *_getIterator() {
3796
- for (const item of this.elements) {
3826
+ for (const item of this.elements.slice(this.offset)) {
3797
3827
  yield item;
3798
3828
  }
3799
3829
  }
@@ -3812,14 +3842,14 @@ var dataStructureTyped = (() => {
3812
3842
  * values as the original `LinkedListQueue`.
3813
3843
  */
3814
3844
  clone() {
3815
- return new _LinkedListQueue(this.values());
3845
+ return new _LinkedListQueue(this, { toElementFn: this.toElementFn });
3816
3846
  }
3817
3847
  };
3818
3848
 
3819
3849
  // src/data-structures/queue/deque.ts
3820
3850
  var Deque = class _Deque extends IterableElementBase {
3821
3851
  /**
3822
- * The constructor initializes a Deque object with an optional iterable of elements and options.
3852
+ * The constructor initializes a Deque object with optional iterable of elements and options.
3823
3853
  * @param elements - An iterable object (such as an array or a Set) that contains the initial
3824
3854
  * elements to be added to the deque. It can also be an object with a `length` or `size` property
3825
3855
  * that represents the number of elements in the iterable object. If no elements are provided, an
@@ -3830,8 +3860,9 @@ var dataStructureTyped = (() => {
3830
3860
  * or is not a number
3831
3861
  */
3832
3862
  constructor(elements = [], options) {
3833
- super();
3863
+ super(options);
3834
3864
  __publicField(this, "_bucketSize", 1 << 12);
3865
+ __publicField(this, "_maxLen", -1);
3835
3866
  __publicField(this, "_bucketFirst", 0);
3836
3867
  __publicField(this, "_firstInBucket", 0);
3837
3868
  __publicField(this, "_bucketLast", 0);
@@ -3840,9 +3871,11 @@ var dataStructureTyped = (() => {
3840
3871
  __publicField(this, "_buckets", []);
3841
3872
  __publicField(this, "_size", 0);
3842
3873
  if (options) {
3843
- const { bucketSize } = options;
3874
+ const { bucketSize, maxLen } = options;
3844
3875
  if (typeof bucketSize === "number")
3845
3876
  this._bucketSize = bucketSize;
3877
+ if (typeof maxLen === "number" && maxLen > 0 && maxLen % 1 === 0)
3878
+ this._maxLen = maxLen;
3846
3879
  }
3847
3880
  let _size;
3848
3881
  if ("length" in elements) {
@@ -3863,8 +3896,12 @@ var dataStructureTyped = (() => {
3863
3896
  const needBucketNum = calcMinUnitsRequired(_size, this._bucketSize);
3864
3897
  this._bucketFirst = this._bucketLast = (this._bucketCount >> 1) - (needBucketNum >> 1);
3865
3898
  this._firstInBucket = this._lastInBucket = this._bucketSize - _size % this._bucketSize >> 1;
3866
- for (const element of elements) {
3867
- this.push(element);
3899
+ for (const el of elements) {
3900
+ if (this.toElementFn) {
3901
+ this.push(this.toElementFn(el));
3902
+ } else {
3903
+ this.push(el);
3904
+ }
3868
3905
  }
3869
3906
  }
3870
3907
  /**
@@ -3875,6 +3912,14 @@ var dataStructureTyped = (() => {
3875
3912
  get bucketSize() {
3876
3913
  return this._bucketSize;
3877
3914
  }
3915
+ /**
3916
+ * The maxLen function returns the max length of the deque.
3917
+ *
3918
+ * @return The max length of the deque
3919
+ */
3920
+ get maxLen() {
3921
+ return this._maxLen;
3922
+ }
3878
3923
  /**
3879
3924
  * The function returns the value of the protected variable `_bucketFirst`.
3880
3925
  * @returns The value of the `_bucketFirst` property.
@@ -3974,6 +4019,8 @@ var dataStructureTyped = (() => {
3974
4019
  }
3975
4020
  this._size += 1;
3976
4021
  this._buckets[this._bucketLast][this._lastInBucket] = element;
4022
+ if (this._maxLen > 0 && this._size > this._maxLen)
4023
+ this.shift();
3977
4024
  return true;
3978
4025
  }
3979
4026
  /**
@@ -4036,6 +4083,8 @@ var dataStructureTyped = (() => {
4036
4083
  }
4037
4084
  this._size += 1;
4038
4085
  this._buckets[this._bucketFirst][this._firstInBucket] = element;
4086
+ if (this._maxLen > 0 && this._size > this._maxLen)
4087
+ this.pop();
4039
4088
  return true;
4040
4089
  }
4041
4090
  /**
@@ -4501,7 +4550,7 @@ var dataStructureTyped = (() => {
4501
4550
  * elements as the original deque (`this`) and the same bucket size.
4502
4551
  */
4503
4552
  clone() {
4504
- return new _Deque([...this], { bucketSize: this.bucketSize });
4553
+ return new _Deque(this, { bucketSize: this.bucketSize, toElementFn: this.toElementFn });
4505
4554
  }
4506
4555
  /**
4507
4556
  * Time Complexity: O(n)
@@ -4524,7 +4573,7 @@ var dataStructureTyped = (() => {
4524
4573
  * satisfy the given predicate function.
4525
4574
  */
4526
4575
  filter(predicate, thisArg) {
4527
- const newDeque = new _Deque([], { bucketSize: this._bucketSize });
4576
+ const newDeque = new _Deque([], { bucketSize: this._bucketSize, toElementFn: this.toElementFn });
4528
4577
  let index = 0;
4529
4578
  for (const el of this) {
4530
4579
  if (predicate.call(thisArg, el, index, this)) {
@@ -4539,20 +4588,22 @@ var dataStructureTyped = (() => {
4539
4588
  * Space Complexity: O(n)
4540
4589
  */
4541
4590
  /**
4542
- * Time Complexity: O(n)
4543
- * Space Complexity: O(n)
4544
- *
4545
- * The `map` function creates a new Deque by applying a callback function to each element of the
4546
- * original Deque.
4547
- * @param callback - The `callback` parameter is a function that will be called for each element in
4548
- * the deque. It takes three arguments:
4549
- * @param {any} [thisArg] - The `thisArg` parameter is an optional argument that specifies the value
4550
- * to be used as `this` when executing the `callback` function. If `thisArg` is provided, it will be
4551
- * passed as the `this` value to the `callback` function. If `thisArg` is
4552
- * @returns a new Deque object with the mapped values.
4591
+ * The `map` function takes a callback function and applies it to each element in the deque,
4592
+ * returning a new deque with the results.
4593
+ * @param callback - The callback parameter is a function that will be called for each element in the
4594
+ * deque. It takes three arguments: the current element, the index of the element, and the deque
4595
+ * itself. It should return a value of type EM.
4596
+ * @param [toElementFn] - The `toElementFn` parameter is an optional function that can be used to
4597
+ * transform the raw element (`RM`) into a new element (`EM`) before adding it to the new deque. If
4598
+ * provided, this function will be called for each raw element in the original deque.
4599
+ * @param {any} [thisArg] - The `thisArg` parameter is an optional argument that allows you to
4600
+ * specify the value of `this` within the callback function. It is used to set the context or scope
4601
+ * in which the callback function will be executed. If `thisArg` is provided, it will be used as the
4602
+ * value of
4603
+ * @returns a new Deque object with elements of type EM and raw elements of type RM.
4553
4604
  */
4554
- map(callback, thisArg) {
4555
- const newDeque = new _Deque([], { bucketSize: this._bucketSize });
4605
+ map(callback, toElementFn, thisArg) {
4606
+ const newDeque = new _Deque([], { bucketSize: this._bucketSize, toElementFn });
4556
4607
  let index = 0;
4557
4608
  for (const el of this) {
4558
4609
  newDeque.push(callback.call(thisArg, el, index, this));
@@ -4644,23 +4695,32 @@ var dataStructureTyped = (() => {
4644
4695
  /**
4645
4696
  * The constructor initializes a heap data structure with optional elements and options.
4646
4697
  * @param elements - The `elements` parameter is an iterable object that contains the initial
4647
- * elements to be added to the heap. It is an optional parameter and if not provided, the heap will
4698
+ * elements to be added to the heap.
4699
+ * It is an optional parameter, and if not provided, the heap will
4648
4700
  * be initialized as empty.
4649
4701
  * @param [options] - The `options` parameter is an optional object that can contain additional
4650
- * configuration options for the heap. In this case, it is used to specify a custom comparator
4651
- * function for comparing elements in the heap. The comparator function is used to determine the
4702
+ * configuration options for the heap.
4703
+ * In this case, it is used to specify a custom comparator
4704
+ * function for comparing elements in the heap.
4705
+ * The comparator function is used to determine the
4652
4706
  * order of elements in the heap.
4653
4707
  */
4654
4708
  constructor(elements = [], options) {
4655
- super();
4656
- __publicField(this, "_comparator", (a, b) => {
4657
- if (!(typeof a === "number" && typeof b === "number")) {
4658
- throw new Error("The a, b params of compare function must be number");
4659
- } else {
4660
- return a - b;
4709
+ super(options);
4710
+ __publicField(this, "_elements", []);
4711
+ __publicField(this, "_DEFAULT_COMPARATOR", (a, b) => {
4712
+ if (typeof a === "object" || typeof b === "object") {
4713
+ throw TypeError(
4714
+ `When comparing object types, a custom comparator must be defined in the constructor's options parameter.`
4715
+ );
4661
4716
  }
4717
+ if (a > b)
4718
+ return 1;
4719
+ if (a < b)
4720
+ return -1;
4721
+ return 0;
4662
4722
  });
4663
- __publicField(this, "_elements", []);
4723
+ __publicField(this, "_comparator", this._DEFAULT_COMPARATOR);
4664
4724
  if (options) {
4665
4725
  const { comparator } = options;
4666
4726
  if (comparator)
@@ -4668,20 +4728,16 @@ var dataStructureTyped = (() => {
4668
4728
  }
4669
4729
  if (elements) {
4670
4730
  for (const el of elements) {
4671
- this.add(el);
4731
+ if (this.toElementFn)
4732
+ this.add(this.toElementFn(el));
4733
+ else
4734
+ this.add(el);
4672
4735
  }
4673
4736
  }
4674
4737
  }
4675
- /**
4676
- * The function returns the value of the _comparator property.
4677
- * @returns The `_comparator` property is being returned.
4678
- */
4679
- get comparator() {
4680
- return this._comparator;
4681
- }
4682
4738
  /**
4683
4739
  * The function returns an array of elements.
4684
- * @returns The elements array is being returned.
4740
+ * @returns The element array is being returned.
4685
4741
  */
4686
4742
  get elements() {
4687
4743
  return this._elements;
@@ -4709,11 +4765,6 @@ var dataStructureTyped = (() => {
4709
4765
  static heapify(elements, options) {
4710
4766
  return new _Heap(elements, options);
4711
4767
  }
4712
- /**
4713
- * Time Complexity: O(log n)
4714
- * Space Complexity: O(1)
4715
- * where n is the number of elements in the heap.
4716
- */
4717
4768
  /**
4718
4769
  * Time Complexity: O(log n)
4719
4770
  * Space Complexity: O(1)
@@ -4725,16 +4776,11 @@ var dataStructureTyped = (() => {
4725
4776
  this._elements.push(element);
4726
4777
  return this._bubbleUp(this.elements.length - 1);
4727
4778
  }
4728
- /**
4729
- * Time Complexity: O(log n)
4730
- * Space Complexity: O(1)
4731
- * where n is the number of elements in the heap.
4732
- */
4733
4779
  /**
4734
4780
  * Time Complexity: O(log n)
4735
4781
  * Space Complexity: O(1)
4736
4782
  *
4737
- * Remove and return the top element (smallest or largest element) from the heap.
4783
+ * Remove and return the top element (the smallest or largest element) from the heap.
4738
4784
  * @returns The top element or undefined if the heap is empty.
4739
4785
  */
4740
4786
  poll() {
@@ -4748,10 +4794,6 @@ var dataStructureTyped = (() => {
4748
4794
  }
4749
4795
  return value;
4750
4796
  }
4751
- /**
4752
- * Time Complexity: O(1)
4753
- * Space Complexity: O(1)
4754
- */
4755
4797
  /**
4756
4798
  * Time Complexity: O(1)
4757
4799
  * Space Complexity: O(1)
@@ -4775,10 +4817,6 @@ var dataStructureTyped = (() => {
4775
4817
  clear() {
4776
4818
  this._elements = [];
4777
4819
  }
4778
- /**
4779
- * Time Complexity: O(n)
4780
- * Space Complexity: O(n)
4781
- */
4782
4820
  /**
4783
4821
  * Time Complexity: O(n)
4784
4822
  * Space Complexity: O(n)
@@ -4790,10 +4828,6 @@ var dataStructureTyped = (() => {
4790
4828
  this._elements = elements;
4791
4829
  return this.fix();
4792
4830
  }
4793
- /**
4794
- * Time Complexity: O(n)
4795
- * Space Complexity: O(1)
4796
- */
4797
4831
  /**
4798
4832
  * Time Complexity: O(n)
4799
4833
  * Space Complexity: O(1)
@@ -4806,12 +4840,7 @@ var dataStructureTyped = (() => {
4806
4840
  return this.elements.includes(element);
4807
4841
  }
4808
4842
  /**
4809
- * Time Complexity: O(n)
4810
- * Space Complexity: O(1)
4811
- * The worst-case O(n) This is because, in the worst case, the element to be deleted is located at the end of the heap (not the root), and after deletion, we may need to reorganize the elements by performing a sinkDown operation.
4812
- */
4813
- /**
4814
- * Time Complexity: O(n)
4843
+ * Time Complexity: O(n)
4815
4844
  * Space Complexity: O(1)
4816
4845
  *
4817
4846
  * The `delete` function removes an element from an array-like data structure, maintaining the order
@@ -4836,11 +4865,6 @@ var dataStructureTyped = (() => {
4836
4865
  }
4837
4866
  return true;
4838
4867
  }
4839
- /**
4840
- * Time Complexity: O(n)
4841
- * Space Complexity: O(log n)
4842
- * where log n is the height of the heap.
4843
- */
4844
4868
  /**
4845
4869
  * Time Complexity: O(n)
4846
4870
  * Space Complexity: O(log n)
@@ -4872,10 +4896,6 @@ var dataStructureTyped = (() => {
4872
4896
  _dfs(0);
4873
4897
  return result;
4874
4898
  }
4875
- /**
4876
- * Time Complexity: O(n)
4877
- * Space Complexity: O(n)
4878
- */
4879
4899
  /**
4880
4900
  * Time Complexity: O(n)
4881
4901
  * Space Complexity: O(n)
@@ -4886,10 +4906,6 @@ var dataStructureTyped = (() => {
4886
4906
  toArray() {
4887
4907
  return [...this.elements];
4888
4908
  }
4889
- /**
4890
- * Time Complexity: O(n)
4891
- * Space Complexity: O(n)
4892
- */
4893
4909
  /**
4894
4910
  * Time Complexity: O(n)
4895
4911
  * Space Complexity: O(n)
@@ -4898,14 +4914,8 @@ var dataStructureTyped = (() => {
4898
4914
  * @returns A new Heap instance containing the same elements.
4899
4915
  */
4900
4916
  clone() {
4901
- const clonedHeap = new _Heap([], { comparator: this.comparator });
4902
- clonedHeap._elements = [...this.elements];
4903
- return clonedHeap;
4917
+ return new _Heap(this, { comparator: this.comparator, toElementFn: this.toElementFn });
4904
4918
  }
4905
- /**
4906
- * Time Complexity: O(n log n)
4907
- * Space Complexity: O(n)
4908
- */
4909
4919
  /**
4910
4920
  * Time Complexity: O(n log n)
4911
4921
  * Space Complexity: O(n)
@@ -4915,18 +4925,14 @@ var dataStructureTyped = (() => {
4915
4925
  */
4916
4926
  sort() {
4917
4927
  const visitedNode = [];
4918
- const cloned = this.clone();
4928
+ const cloned = new _Heap(this, { comparator: this.comparator });
4919
4929
  while (cloned.size !== 0) {
4920
4930
  const top = cloned.poll();
4921
- if (top)
4931
+ if (top !== void 0)
4922
4932
  visitedNode.push(top);
4923
4933
  }
4924
4934
  return visitedNode;
4925
4935
  }
4926
- /**
4927
- * Time Complexity: O(n log n)
4928
- * Space Complexity: O(n)
4929
- */
4930
4936
  /**
4931
4937
  * Time Complexity: O(n log n)
4932
4938
  * Space Complexity: O(n)
@@ -4939,10 +4945,6 @@ var dataStructureTyped = (() => {
4939
4945
  results.push(this._sinkDown(i, this.elements.length >> 1));
4940
4946
  return results;
4941
4947
  }
4942
- /**
4943
- * Time Complexity: O(n)
4944
- * Space Complexity: O(n)
4945
- */
4946
4948
  /**
4947
4949
  * Time Complexity: O(n)
4948
4950
  * Space Complexity: O(n)
@@ -4960,7 +4962,7 @@ var dataStructureTyped = (() => {
4960
4962
  * the filter condition specified by the `callback` function.
4961
4963
  */
4962
4964
  filter(callback, thisArg) {
4963
- const filteredList = new _Heap();
4965
+ const filteredList = new _Heap([], { toElementFn: this.toElementFn, comparator: this.comparator });
4964
4966
  let index = 0;
4965
4967
  for (const current of this) {
4966
4968
  if (callback.call(thisArg, current, index, this)) {
@@ -4971,31 +4973,28 @@ var dataStructureTyped = (() => {
4971
4973
  return filteredList;
4972
4974
  }
4973
4975
  /**
4974
- * Time Complexity: O(n)
4975
- * Space Complexity: O(n)
4976
- */
4977
- /**
4978
- * Time Complexity: O(n)
4976
+ * Time Complexity: O(n log n)
4979
4977
  * Space Complexity: O(n)
4980
4978
  *
4981
4979
  * The `map` function creates a new heap by applying a callback function to each element of the
4982
4980
  * original heap.
4983
- * @param callback - The callback parameter is a function that will be called for each element in the
4984
- * original heap. It takes three arguments: the current element, the index of the current element,
4985
- * and the original heap itself. The callback function should return a value of type T, which will be
4986
- * added to the mapped heap.
4987
- * @param comparator - The `comparator` parameter is a function that is used to compare elements in
4988
- * the heap. It takes two arguments, `a` and `b`, and returns a negative number if `a` is less than
4989
- * `b`, a positive number if `a` is greater than `b`, or
4981
+ * @param callback - The `callback` parameter is a function that will be called for each element in
4982
+ * the heap. It takes three arguments: `el` (the current element), `index` (the index of the current
4983
+ * element), and `this` (the heap itself). The callback function should return a value of
4984
+ * @param comparator - The `comparator` parameter is a function that defines the order of the
4985
+ * elements in the heap. It takes two elements `a` and `b` as arguments and returns a negative number
4986
+ * if `a` should be placed before `b`, a positive number if `a` should be placed after
4987
+ * @param [toElementFn] - The `toElementFn` parameter is an optional function that converts the raw
4988
+ * element `RR` to the desired type `T`. It takes a single argument `rawElement` of type `RR` and
4989
+ * returns a value of type `T`. This function is used to transform the elements of the original
4990
4990
  * @param {any} [thisArg] - The `thisArg` parameter is an optional argument that allows you to
4991
- * specify the value of `this` within the callback function. It is used when you want to bind a
4992
- * specific object as the context for the callback function. If `thisArg` is not provided,
4993
- * `undefined` is used as
4994
- * @returns a new instance of the Heap class, which is created using the mapped elements from the
4995
- * original Heap.
4996
- */
4997
- map(callback, comparator, thisArg) {
4998
- const mappedHeap = new _Heap([], { comparator });
4991
+ * specify the value of `this` within the callback function. It is used to set the context or scope
4992
+ * in which the callback function will be executed. If `thisArg` is provided, it will be used as the
4993
+ * value of
4994
+ * @returns a new instance of the `Heap` class with the mapped elements.
4995
+ */
4996
+ map(callback, comparator, toElementFn, thisArg) {
4997
+ const mappedHeap = new _Heap([], { comparator, toElementFn });
4999
4998
  let index = 0;
5000
4999
  for (const el of this) {
5001
5000
  mappedHeap.add(callback.call(thisArg, el, index, this));
@@ -5003,6 +5002,13 @@ var dataStructureTyped = (() => {
5003
5002
  }
5004
5003
  return mappedHeap;
5005
5004
  }
5005
+ /**
5006
+ * The function returns the value of the _comparator property.
5007
+ * @returns The `_comparator` property is being returned.
5008
+ */
5009
+ get comparator() {
5010
+ return this._comparator;
5011
+ }
5006
5012
  /**
5007
5013
  * The function `_getIterator` returns an iterable iterator for the elements in the class.
5008
5014
  */
@@ -5011,10 +5017,6 @@ var dataStructureTyped = (() => {
5011
5017
  yield element;
5012
5018
  }
5013
5019
  }
5014
- /**
5015
- * Time Complexity: O(log n)
5016
- * Space Complexity: O(1)
5017
- */
5018
5020
  /**
5019
5021
  * Time Complexity: O(log n)
5020
5022
  * Space Complexity: O(1)
@@ -5035,10 +5037,6 @@ var dataStructureTyped = (() => {
5035
5037
  this.elements[index] = element;
5036
5038
  return true;
5037
5039
  }
5038
- /**
5039
- * Time Complexity: O(log n)
5040
- * Space Complexity: O(1)
5041
- */
5042
5040
  /**
5043
5041
  * Time Complexity: O(log n)
5044
5042
  * Space Complexity: O(1)
@@ -5147,10 +5145,6 @@ var dataStructureTyped = (() => {
5147
5145
  this._min = void 0;
5148
5146
  this._size = 0;
5149
5147
  }
5150
- /**
5151
- * Time Complexity: O(1)
5152
- * Space Complexity: O(1)
5153
- */
5154
5148
  /**
5155
5149
  * Time Complexity: O(1)
5156
5150
  * Space Complexity: O(1)
@@ -5162,10 +5156,6 @@ var dataStructureTyped = (() => {
5162
5156
  add(element) {
5163
5157
  return this.push(element);
5164
5158
  }
5165
- /**
5166
- * Time Complexity: O(1)
5167
- * Space Complexity: O(1)
5168
- */
5169
5159
  /**
5170
5160
  * Time Complexity: O(1)
5171
5161
  * Space Complexity: O(1)
@@ -5185,10 +5175,6 @@ var dataStructureTyped = (() => {
5185
5175
  this._size++;
5186
5176
  return this;
5187
5177
  }
5188
- /**
5189
- * Time Complexity: O(1)
5190
- * Space Complexity: O(1)
5191
- */
5192
5178
  /**
5193
5179
  * Time Complexity: O(1)
5194
5180
  * Space Complexity: O(1)
@@ -5256,7 +5242,7 @@ var dataStructureTyped = (() => {
5256
5242
  * Time Complexity: O(log n)
5257
5243
  * Space Complexity: O(1)
5258
5244
  *
5259
- * Remove and return the top element (smallest or largest element) from the heap.
5245
+ * Remove and return the top element (the smallest or largest element) from the heap.
5260
5246
  * @returns The top element or undefined if the heap is empty.
5261
5247
  */
5262
5248
  poll() {
@@ -5270,7 +5256,7 @@ var dataStructureTyped = (() => {
5270
5256
  * Time Complexity: O(log n)
5271
5257
  * Space Complexity: O(1)
5272
5258
  *
5273
- * Remove and return the top element (smallest or largest element) from the heap.
5259
+ * Remove and return the top element (the smallest or largest element) from the heap.
5274
5260
  * @returns The top element or undefined if the heap is empty.
5275
5261
  */
5276
5262
  pop() {
@@ -5375,8 +5361,8 @@ var dataStructureTyped = (() => {
5375
5361
  /**
5376
5362
  * Time Complexity: O(1)
5377
5363
  * Space Complexity: O(1)
5378
- *.
5379
- * Remove and return the top element (smallest or largest element) from the heap.
5364
+ *
5365
+ * Remove and return the top element (the smallest or largest element) from the heap.
5380
5366
  * @param node - The node to be removed.
5381
5367
  * @protected
5382
5368
  */
@@ -5396,7 +5382,7 @@ var dataStructureTyped = (() => {
5396
5382
  * Time Complexity: O(1)
5397
5383
  * Space Complexity: O(1)
5398
5384
  *
5399
- * Remove and return the top element (smallest or largest element) from the heap.
5385
+ * Remove and return the top element (the smallest or largest element) from the heap.
5400
5386
  * @param y
5401
5387
  * @param x
5402
5388
  * @protected
@@ -5417,7 +5403,7 @@ var dataStructureTyped = (() => {
5417
5403
  * Time Complexity: O(n log n)
5418
5404
  * Space Complexity: O(n)
5419
5405
  *
5420
- * Remove and return the top element (smallest or largest element) from the heap.
5406
+ * Remove and return the top element (the smallest or largest element) from the heap.
5421
5407
  * @protected
5422
5408
  */
5423
5409
  _consolidate() {
@@ -5449,32 +5435,161 @@ var dataStructureTyped = (() => {
5449
5435
  };
5450
5436
 
5451
5437
  // src/data-structures/heap/max-heap.ts
5452
- var MaxHeap = class extends Heap {
5453
- constructor(elements = [], options = {
5454
- comparator: (a, b) => {
5455
- if (!(typeof a === "number" && typeof b === "number")) {
5456
- throw new Error("The a, b params of compare function must be number");
5457
- } else {
5458
- return b - a;
5438
+ var MaxHeap = class _MaxHeap extends Heap {
5439
+ constructor(elements = [], options) {
5440
+ super(elements, __spreadValues({
5441
+ comparator: (a, b) => {
5442
+ if (typeof a === "object" || typeof b === "object") {
5443
+ throw TypeError(
5444
+ `When comparing object types, a custom comparator must be defined in the constructor's options parameter.`
5445
+ );
5446
+ }
5447
+ if (a < b)
5448
+ return 1;
5449
+ if (a > b)
5450
+ return -1;
5451
+ return 0;
5459
5452
  }
5453
+ }, options));
5454
+ }
5455
+ /**
5456
+ * The `clone` function returns a new instance of the `MaxHeap` class with the same properties as the
5457
+ * current instance.
5458
+ * @returns The `clone()` method is returning a new instance of the `MaxHeap` class with the same
5459
+ * properties as the current instance.
5460
+ */
5461
+ clone() {
5462
+ return new _MaxHeap(this, { comparator: this.comparator, toElementFn: this.toElementFn });
5463
+ }
5464
+ /**
5465
+ * Time Complexity: O(n)
5466
+ * Space Complexity: O(n)
5467
+ *
5468
+ * The `filter` function creates a new MaxHeap object containing elements that pass a given callback
5469
+ * function.
5470
+ * @param callback - The `callback` parameter is a function that will be called for each element in
5471
+ * the heap. It takes three arguments: the current element, the index of the current element, and the
5472
+ * heap itself. The callback function should return a boolean value indicating whether the current
5473
+ * element should be included in the filtered list
5474
+ * @param {any} [thisArg] - The `thisArg` parameter is an optional argument that specifies the value
5475
+ * to be used as `this` when executing the `callback` function. If `thisArg` is provided, it will be
5476
+ * passed as the `this` value to the `callback` function. If `thisArg` is
5477
+ * @returns The `filter` method is returning a new `MaxHeap` object that contains the elements that pass
5478
+ * the filter condition specified by the `callback` function.
5479
+ */
5480
+ filter(callback, thisArg) {
5481
+ const filteredList = new _MaxHeap([], { toElementFn: this.toElementFn, comparator: this.comparator });
5482
+ let index = 0;
5483
+ for (const current of this) {
5484
+ if (callback.call(thisArg, current, index, this)) {
5485
+ filteredList.add(current);
5486
+ }
5487
+ index++;
5460
5488
  }
5461
- }) {
5462
- super(elements, options);
5489
+ return filteredList;
5490
+ }
5491
+ /**
5492
+ * Time Complexity: O(n log n)
5493
+ * Space Complexity: O(n)
5494
+ *
5495
+ * The `map` function creates a new heap by applying a callback function to each element of the
5496
+ * original heap.
5497
+ * @param callback - The `callback` parameter is a function that will be called for each element in
5498
+ * the heap. It takes three arguments: `el` (the current element), `index` (the index of the current
5499
+ * element), and `this` (the heap itself). The callback function should return a value of
5500
+ * @param comparator - The `comparator` parameter is a function that defines the order of the
5501
+ * elements in the heap. It takes two elements `a` and `b` as arguments and returns a negative number
5502
+ * if `a` should be placed before `b`, a positive number if `a` should be placed after
5503
+ * @param [toElementFn] - The `toElementFn` parameter is an optional function that converts the raw
5504
+ * element `RR` to the desired type `T`. It takes a single argument `rawElement` of type `RR` and
5505
+ * returns a value of type `T`. This function is used to transform the elements of the original
5506
+ * @param {any} [thisArg] - The `thisArg` parameter is an optional argument that allows you to
5507
+ * specify the value of `this` within the callback function. It is used to set the context or scope
5508
+ * in which the callback function will be executed. If `thisArg` is provided, it will be used as the
5509
+ * value of
5510
+ * @returns a new instance of the `MaxHeap` class with the mapped elements.
5511
+ */
5512
+ map(callback, comparator, toElementFn, thisArg) {
5513
+ const mappedHeap = new _MaxHeap([], { comparator, toElementFn });
5514
+ let index = 0;
5515
+ for (const el of this) {
5516
+ mappedHeap.add(callback.call(thisArg, el, index, this));
5517
+ index++;
5518
+ }
5519
+ return mappedHeap;
5463
5520
  }
5464
5521
  };
5465
5522
 
5466
5523
  // src/data-structures/heap/min-heap.ts
5467
- var MinHeap = class extends Heap {
5468
- constructor(elements = [], options = {
5469
- comparator: (a, b) => {
5470
- if (!(typeof a === "number" && typeof b === "number")) {
5471
- throw new Error("The a, b params of compare function must be number");
5472
- } else {
5473
- return a - b;
5524
+ var MinHeap = class _MinHeap extends Heap {
5525
+ constructor(elements = [], options) {
5526
+ super(elements, options);
5527
+ }
5528
+ /**
5529
+ * The `clone` function returns a new instance of the `MinHeap` class with the same comparator and
5530
+ * toElementFn as the original instance.
5531
+ * @returns The `clone()` method is returning a new instance of the `MinHeap` class with the same
5532
+ * properties as the current instance.
5533
+ */
5534
+ clone() {
5535
+ return new _MinHeap(this, { comparator: this.comparator, toElementFn: this.toElementFn });
5536
+ }
5537
+ /**
5538
+ * Time Complexity: O(n)
5539
+ * Space Complexity: O(n)
5540
+ *
5541
+ * The `filter` function creates a new MinHeap object containing elements that pass a given callback
5542
+ * function.
5543
+ * @param callback - The `callback` parameter is a function that will be called for each element in
5544
+ * the heap. It takes three arguments: the current element, the index of the current element, and the
5545
+ * heap itself. The callback function should return a boolean value indicating whether the current
5546
+ * element should be included in the filtered list
5547
+ * @param {any} [thisArg] - The `thisArg` parameter is an optional argument that specifies the value
5548
+ * to be used as `this` when executing the `callback` function. If `thisArg` is provided, it will be
5549
+ * passed as the `this` value to the `callback` function. If `thisArg` is
5550
+ * @returns The `filter` method is returning a new `MinHeap` object that contains the elements that pass
5551
+ * the filter condition specified by the `callback` function.
5552
+ */
5553
+ filter(callback, thisArg) {
5554
+ const filteredList = new _MinHeap([], { toElementFn: this.toElementFn, comparator: this.comparator });
5555
+ let index = 0;
5556
+ for (const current of this) {
5557
+ if (callback.call(thisArg, current, index, this)) {
5558
+ filteredList.add(current);
5474
5559
  }
5560
+ index++;
5475
5561
  }
5476
- }) {
5477
- super(elements, options);
5562
+ return filteredList;
5563
+ }
5564
+ /**
5565
+ * Time Complexity: O(n log n)
5566
+ * Space Complexity: O(n)
5567
+ *
5568
+ * The `map` function creates a new heap by applying a callback function to each element of the
5569
+ * original heap.
5570
+ * @param callback - The `callback` parameter is a function that will be called for each element in
5571
+ * the heap. It takes three arguments: `el` (the current element), `index` (the index of the current
5572
+ * element), and `this` (the heap itself). The callback function should return a value of
5573
+ * @param comparator - The `comparator` parameter is a function that defines the order of the
5574
+ * elements in the heap. It takes two elements `a` and `b` as arguments and returns a negative number
5575
+ * if `a` should be placed before `b`, a positive number if `a` should be placed after
5576
+ * @param [toElementFn] - The `toElementFn` parameter is an optional function that converts the raw
5577
+ * element `RR` to the desired type `T`. It takes a single argument `rawElement` of type `RR` and
5578
+ * returns a value of type `T`. This function is used to transform the elements of the original
5579
+ * @param {any} [thisArg] - The `thisArg` parameter is an optional argument that allows you to
5580
+ * specify the value of `this` within the callback function. It is used to set the context or scope
5581
+ * in which the callback function will be executed. If `thisArg` is provided, it will be used as the
5582
+ * value of
5583
+ * @returns a new instance of the `MinHeap` class with the mapped elements.
5584
+ */
5585
+ map(callback, comparator, toElementFn, thisArg) {
5586
+ const mappedHeap = new _MinHeap([], { comparator, toElementFn });
5587
+ let index = 0;
5588
+ for (const el of this) {
5589
+ mappedHeap.add(callback.call(thisArg, el, index, this));
5590
+ index++;
5591
+ }
5592
+ return mappedHeap;
5478
5593
  }
5479
5594
  };
5480
5595
 
@@ -6609,7 +6724,7 @@ var dataStructureTyped = (() => {
6609
6724
  if (vertex) {
6610
6725
  const neighbors = this.getNeighbors(vertex);
6611
6726
  for (const neighbor of neighbors) {
6612
- this._inEdgeMap.delete(neighbor);
6727
+ this.deleteEdgeSrcToDest(vertex, neighbor);
6613
6728
  }
6614
6729
  this._outEdgeMap.delete(vertex);
6615
6730
  this._inEdgeMap.delete(vertex);
@@ -7690,7 +7805,7 @@ var dataStructureTyped = (() => {
7690
7805
  }
7691
7806
  /**
7692
7807
  * The function sets the left child of a node and updates its parent reference.
7693
- * @param {NODE | null | undefined} v - The parameter `v` can be of type `NODE`, `null`, or
7808
+ * @param {OptBTNOrNull<NODE>} v - The parameter `v` can be of type `NODE`, `null`, or
7694
7809
  * `undefined`.
7695
7810
  */
7696
7811
  set left(v) {
@@ -7709,7 +7824,7 @@ var dataStructureTyped = (() => {
7709
7824
  }
7710
7825
  /**
7711
7826
  * The function sets the right child of a node and updates its parent.
7712
- * @param {NODE | null | undefined} v - The parameter `v` can be of type `NODE`, `null`, or
7827
+ * @param {OptBTNOrNull<NODE>} v - The parameter `v` can be of type `NODE`, `null`, or
7713
7828
  * `undefined`.
7714
7829
  */
7715
7830
  set right(v) {
@@ -7738,7 +7853,7 @@ var dataStructureTyped = (() => {
7738
7853
  var BinaryTree = class _BinaryTree extends IterableEntryBase {
7739
7854
  /**
7740
7855
  * 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
7856
+ * @param [keysOrNodesOrEntriesOrRawElements] - Optional iterable of BTNKeyOrNodeOrEntry objects. These objects represent the
7742
7857
  * nodes to be added to the binary tree.
7743
7858
  * @param [options] - The `options` parameter is an optional object that can contain additional
7744
7859
  * configuration options for the binary tree. In this case, it is of type
@@ -7759,6 +7874,8 @@ var dataStructureTyped = (() => {
7759
7874
  this.iterationType = iterationType;
7760
7875
  if (typeof toEntryFn === "function")
7761
7876
  this._toEntryFn = toEntryFn;
7877
+ else if (toEntryFn)
7878
+ throw TypeError("toEntryFn must be a function type");
7762
7879
  }
7763
7880
  if (keysOrNodesOrEntriesOrRawElements)
7764
7881
  this.addMany(keysOrNodesOrEntriesOrRawElements);
@@ -7814,8 +7931,8 @@ var dataStructureTyped = (() => {
7814
7931
  /**
7815
7932
  * The function `keyValueOrEntryOrRawElementToNode` converts a key-value pair, entry, or raw element
7816
7933
  * 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>`.
7934
+ * @param {R | BTNKeyOrNodeOrEntry<K, V, NODE>} keyOrNodeOrEntryOrRawElement - The parameter
7935
+ * `keyOrNodeOrEntryOrRawElement` can be of type `R` or `BTNKeyOrNodeOrEntry<K, V, NODE>`.
7819
7936
  * @param {V} [value] - The `value` parameter is an optional value that can be passed to the
7820
7937
  * `keyValueOrEntryOrRawElementToNode` function. It represents the value associated with a key in a
7821
7938
  * key-value pair. If provided, it will be used to create a node with the specified key and value.
@@ -7859,8 +7976,8 @@ var dataStructureTyped = (() => {
7859
7976
  *
7860
7977
  * The `ensureNode` function checks if the input is a valid node and returns it, or converts it to a
7861
7978
  * 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
7979
+ * @param {R | BTNKeyOrNodeOrEntry<K, V, NODE>} keyOrNodeOrEntryOrRawElement - The parameter
7980
+ * `keyOrNodeOrEntryOrRawElement` can accept a value of type `R`, `BTNKeyOrNodeOrEntry<K, V, NODE>`, or
7864
7981
  * a raw element.
7865
7982
  * @param {IterationType} [iterationType=ITERATIVE] - The `iterationType` parameter is an optional
7866
7983
  * parameter that specifies the type of iteration to be used when searching for a node. It has a
@@ -7895,8 +8012,8 @@ var dataStructureTyped = (() => {
7895
8012
  }
7896
8013
  /**
7897
8014
  * 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>`.
8015
+ * @param {R | BTNKeyOrNodeOrEntry<K, V, NODE>} keyOrNodeOrEntryOrRawElement - The parameter
8016
+ * `keyOrNodeOrEntryOrRawElement` can be of type `R` or `BTNKeyOrNodeOrEntry<K, V, NODE>`.
7900
8017
  * @returns a boolean value indicating whether the input parameter `keyOrNodeOrEntryOrRawElement` is
7901
8018
  * an instance of the `BinaryTreeNode` class.
7902
8019
  */
@@ -7905,8 +8022,8 @@ var dataStructureTyped = (() => {
7905
8022
  }
7906
8023
  /**
7907
8024
  * 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>`.
8025
+ * @param {R | BTNKeyOrNodeOrEntry<K, V, NODE>} node - The parameter `node` can be of type `R` or
8026
+ * `BTNKeyOrNodeOrEntry<K, V, NODE>`.
7910
8027
  * @returns a boolean value.
7911
8028
  */
7912
8029
  isRealNode(node) {
@@ -7916,8 +8033,8 @@ var dataStructureTyped = (() => {
7916
8033
  }
7917
8034
  /**
7918
8035
  * 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>`.
8036
+ * @param {R | BTNKeyOrNodeOrEntry<K, V, NODE>} node - The parameter `node` can be of type `R` or
8037
+ * `BTNKeyOrNodeOrEntry<K, V, NODE>`.
7921
8038
  * @returns a boolean value.
7922
8039
  */
7923
8040
  isNodeOrNull(node) {
@@ -7925,8 +8042,8 @@ var dataStructureTyped = (() => {
7925
8042
  }
7926
8043
  /**
7927
8044
  * 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>`.
8045
+ * @param {R | BTNKeyOrNodeOrEntry<K, V, NODE>} node - The parameter `node` can be of type `R` or
8046
+ * `BTNKeyOrNodeOrEntry<K, V, NODE>`.
7930
8047
  * @returns a boolean value.
7931
8048
  */
7932
8049
  isNIL(node) {
@@ -7935,8 +8052,8 @@ var dataStructureTyped = (() => {
7935
8052
  /**
7936
8053
  * The function checks if the input is an array with two elements, indicating it is a binary tree
7937
8054
  * node entry.
7938
- * @param {R | KeyOrNodeOrEntry<K, V, NODE>} keyOrNodeOrEntryOrRawElement - The parameter
7939
- * `keyOrNodeOrEntryOrRawElement` can be of type `R` or `KeyOrNodeOrEntry<K, V, NODE>`.
8055
+ * @param {R | BTNKeyOrNodeOrEntry<K, V, NODE>} keyOrNodeOrEntryOrRawElement - The parameter
8056
+ * `keyOrNodeOrEntryOrRawElement` can be of type `R` or `BTNKeyOrNodeOrEntry<K, V, NODE>`.
7940
8057
  * @returns a boolean value.
7941
8058
  */
7942
8059
  isEntry(keyOrNodeOrEntryOrRawElement) {
@@ -7984,10 +8101,10 @@ var dataStructureTyped = (() => {
7984
8101
  *
7985
8102
  * The `add` function is used to insert a new node into a binary tree, checking for duplicate keys
7986
8103
  * and finding the appropriate insertion position.
7987
- * @param {R | KeyOrNodeOrEntry<K, V, NODE>} keyOrNodeOrEntryOrRawElement - The
8104
+ * @param {R | BTNKeyOrNodeOrEntry<K, V, NODE>} keyOrNodeOrEntryOrRawElement - The
7988
8105
  * `keyOrNodeOrEntryOrRawElement` parameter can accept a value of type `R`, which represents the key,
7989
8106
  * node, entry, or raw element to be added to the tree. It can also accept a value of type
7990
- * `KeyOrNodeOrEntry<K, V, NODE>
8107
+ * `BTNKeyOrNodeOrEntry<K, V, NODE>
7991
8108
  * @param {V} [value] - The `value` parameter is an optional value that can be associated with the
7992
8109
  * key being added to the tree. It represents the value that will be stored in the tree for the given
7993
8110
  * key.
@@ -8082,7 +8199,7 @@ var dataStructureTyped = (() => {
8082
8199
  *
8083
8200
  * The `refill` function clears the current data and adds new data to the collection.
8084
8201
  * @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>).
8202
+ * elements. These can be of any type (R) or a specific type (BTNKeyOrNodeOrEntry<K, V, NODE>).
8086
8203
  * @param [values] - The `values` parameter is an optional iterable of values that will be associated
8087
8204
  * with the keys or nodes being added. If provided, the values will be assigned to the corresponding
8088
8205
  * keys or nodes. If not provided, the values will be set to `undefined`.
@@ -8173,7 +8290,7 @@ var dataStructureTyped = (() => {
8173
8290
  * the identifier or all nodes that match the identifier. If set to true, only the first matching
8174
8291
  * node will be returned. If set to false, all matching nodes will be returned. The default value is
8175
8292
  * false.
8176
- * @param {R | KeyOrNodeOrEntry<K, V, NODE>} beginRoot - The `beginRoot` parameter is the starting
8293
+ * @param {R | BTNKeyOrNodeOrEntry<K, V, NODE>} beginRoot - The `beginRoot` parameter is the starting
8177
8294
  * point for the search. It can be either a node object, a key-value pair, or a key. If it is not
8178
8295
  * provided, the `root` of the data structure is used as the starting point.
8179
8296
  * @param {IterationType} iterationType - The `iterationType` parameter determines the type of
@@ -8231,7 +8348,7 @@ var dataStructureTyped = (() => {
8231
8348
  * the `C` callback function, or it can be `null` or `undefined`.
8232
8349
  * @param {C} callback - The `callback` parameter is a function that will be used to determine if a
8233
8350
  * 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
8351
+ * @param {R | BTNKeyOrNodeOrEntry<K, V, NODE>} beginRoot - The `beginRoot` parameter is the starting
8235
8352
  * point for searching nodes in a tree structure. It can be either a root node, a key-value pair, or
8236
8353
  * a node entry. If not provided, the search will start from the root of the tree.
8237
8354
  * @param {IterationType} iterationType - The `iterationType` parameter is used to specify the type
@@ -8276,7 +8393,7 @@ var dataStructureTyped = (() => {
8276
8393
  * callback function `C`. It can also be `null` or `undefined` if no identifier is provided.
8277
8394
  * @param {C} callback - The `callback` parameter is a function that will be used to determine if a
8278
8395
  * 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
8396
+ * @param {R | BTNKeyOrNodeOrEntry<K, V, NODE>} beginRoot - The `beginRoot` parameter is the starting
8280
8397
  * point for the search in the binary tree. It can be either a root node of the tree or a key, node,
8281
8398
  * or entry object that exists in the tree. If no specific starting point is provided, the search
8282
8399
  * will begin from the root of the
@@ -8307,7 +8424,7 @@ var dataStructureTyped = (() => {
8307
8424
  * @param {C} callback - The `callback` parameter is a function that will be used to determine
8308
8425
  * whether a node should be included in the result or not. It is of type `C`, which extends the
8309
8426
  * `BTNCallback<NODE>` type.
8310
- * @param {R | KeyOrNodeOrEntry<K, V, NODE>} beginRoot - The `beginRoot` parameter is the starting
8427
+ * @param {R | BTNKeyOrNodeOrEntry<K, V, NODE>} beginRoot - The `beginRoot` parameter is the starting
8311
8428
  * point for the iteration in the data structure. It can be either a root node, a key-value pair, or
8312
8429
  * a node entry. If not specified, it defaults to the root of the data structure.
8313
8430
  * @param {IterationType} iterationType - The `iterationType` parameter is used to specify the type
@@ -8356,10 +8473,10 @@ var dataStructureTyped = (() => {
8356
8473
  *
8357
8474
  * The function checks if a binary tree is perfectly balanced by comparing the minimum height and the
8358
8475
  * height of the tree.
8359
- * @param {R | KeyOrNodeOrEntry<K, V, NODE>} beginRoot - The parameter `beginRoot` is optional and
8476
+ * @param {R | BTNKeyOrNodeOrEntry<K, V, NODE>} beginRoot - The parameter `beginRoot` is optional and
8360
8477
  * has a default value of `this.root`. It represents the starting point for checking if the tree is
8361
8478
  * perfectly balanced. It can be either a root node (`R`), a key or node or entry
8362
- * (`KeyOrNodeOrEntry<K, V, NODE
8479
+ * (`BTNKeyOrNodeOrEntry<K, V, NODE
8363
8480
  * @returns a boolean value.
8364
8481
  */
8365
8482
  isPerfectlyBalanced(beginRoot = this.root) {
@@ -8374,7 +8491,7 @@ var dataStructureTyped = (() => {
8374
8491
  * Space Complexity: O(1)
8375
8492
  *
8376
8493
  * 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
8494
+ * @param {R | BTNKeyOrNodeOrEntry<K, V, NODE>} beginRoot - The `beginRoot` parameter represents the
8378
8495
  * starting point for checking if a binary search tree (BST) is valid. It can be either a root node
8379
8496
  * of the BST, a key value of a node in the BST, or an entry object containing both the key and value
8380
8497
  * of a node in the BST
@@ -8431,10 +8548,10 @@ var dataStructureTyped = (() => {
8431
8548
  * Space Complexity: O(1)
8432
8549
  *
8433
8550
  * 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
8551
+ * @param {R | BTNKeyOrNodeOrEntry<K, V, NODE>} dist - The `dist` parameter can be either a `R`
8552
+ * (representing a root node), or a `BTNKeyOrNodeOrEntry<K, V, NODE>` (representing a key, node, or
8436
8553
  * entry).
8437
- * @param {R | KeyOrNodeOrEntry<K, V, NODE>} beginRoot - The `beginRoot` parameter is optional and
8554
+ * @param {R | BTNKeyOrNodeOrEntry<K, V, NODE>} beginRoot - The `beginRoot` parameter is optional and
8438
8555
  * represents the starting point from which to calculate the depth. It can be either a reference to a
8439
8556
  * node in the tree or a key-value pair or an entry object. If not provided, the default value is
8440
8557
  * `this.root`, which refers to the root node
@@ -8463,9 +8580,9 @@ var dataStructureTyped = (() => {
8463
8580
  *
8464
8581
  * The `getHeight` function calculates the maximum height of a binary tree using either a recursive
8465
8582
  * or iterative approach.
8466
- * @param {R | KeyOrNodeOrEntry<K, V, NODE>} beginRoot - The `beginRoot` parameter represents the
8583
+ * @param {R | BTNKeyOrNodeOrEntry<K, V, NODE>} beginRoot - The `beginRoot` parameter represents the
8467
8584
  * 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.
8585
+ * node or entry (`BTNKeyOrNodeOrEntry<K, V, NODE>`), or it defaults to the root of the current tree.
8469
8586
  * @param {IterationType} iterationType - The `iterationType` parameter determines the type of
8470
8587
  * iteration used to calculate the height of the tree. It can have two possible values:
8471
8588
  * @returns the maximum height of the binary tree.
@@ -8507,9 +8624,9 @@ var dataStructureTyped = (() => {
8507
8624
  *
8508
8625
  * The `getMinHeight` function calculates the minimum height of a binary tree using either a
8509
8626
  * recursive or iterative approach.
8510
- * @param {R | KeyOrNodeOrEntry<K, V, NODE>} beginRoot - The `beginRoot` parameter represents the
8627
+ * @param {R | BTNKeyOrNodeOrEntry<K, V, NODE>} beginRoot - The `beginRoot` parameter represents the
8511
8628
  * 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
8629
+ * key or node or entry (`BTNKeyOrNodeOrEntry<K, V, NODE>`), or it defaults to the root of the current
8513
8630
  * tree.
8514
8631
  * @param {IterationType} iterationType - The `iterationType` parameter determines the type of
8515
8632
  * iteration to be used when calculating the minimum height of the tree. It can have two possible
@@ -8569,8 +8686,8 @@ var dataStructureTyped = (() => {
8569
8686
  *
8570
8687
  * The function `getPathToRoot` returns an array of nodes starting from a given node and traversing
8571
8688
  * 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>`.
8689
+ * @param {R | BTNKeyOrNodeOrEntry<K, V, NODE>} beginNode - The `beginNode` parameter can be either of
8690
+ * type `R` or `BTNKeyOrNodeOrEntry<K, V, NODE>`.
8574
8691
  * @param [isReverse=true] - The `isReverse` parameter is a boolean flag that determines whether the
8575
8692
  * resulting path should be reversed or not. If `isReverse` is set to `true`, the path will be
8576
8693
  * reversed before returning it. If `isReverse` is set to `false` or not provided, the path will
@@ -8598,9 +8715,9 @@ var dataStructureTyped = (() => {
8598
8715
  *
8599
8716
  * The `getLeftMost` function returns the leftmost node in a binary tree, either using recursive or
8600
8717
  * iterative traversal.
8601
- * @param {R | KeyOrNodeOrEntry<K, V, NODE>} beginRoot - The `beginRoot` parameter represents the
8718
+ * @param {R | BTNKeyOrNodeOrEntry<K, V, NODE>} beginRoot - The `beginRoot` parameter represents the
8602
8719
  * 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`.
8720
+ * a key or node or entry (`BTNKeyOrNodeOrEntry<K, V, NODE>`), or `null` or `undefined`.
8604
8721
  * @param {IterationType} iterationType - The `iterationType` parameter is used to specify the type
8605
8722
  * of iteration to be performed. It can have two possible values:
8606
8723
  * @returns The function `getLeftMost` returns the leftmost node in a binary tree.
@@ -8637,9 +8754,9 @@ var dataStructureTyped = (() => {
8637
8754
  *
8638
8755
  * The `getRightMost` function returns the rightmost node in a binary tree, either recursively or
8639
8756
  * iteratively.
8640
- * @param {R | KeyOrNodeOrEntry<K, V, NODE>} beginRoot - The `beginRoot` parameter represents the
8757
+ * @param {R | BTNKeyOrNodeOrEntry<K, V, NODE>} beginRoot - The `beginRoot` parameter represents the
8641
8758
  * 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`.
8759
+ * (`R`), a key or node or entry (`BTNKeyOrNodeOrEntry<K, V, NODE>`), or `null` or `undefined`.
8643
8760
  * @param {IterationType} iterationType - The `iterationType` parameter is used to specify the type
8644
8761
  * of iteration to be performed when finding the rightmost node in a binary tree. It can have two
8645
8762
  * possible values:
@@ -8735,7 +8852,7 @@ var dataStructureTyped = (() => {
8735
8852
  * return type of the callback function is determined by the generic type `C`.
8736
8853
  * @param {DFSOrderPattern} [pattern=IN] - The `pattern` parameter determines the order in which the
8737
8854
  * 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
8855
+ * @param {R | BTNKeyOrNodeOrEntry<K, V, NODE>} beginRoot - The `beginRoot` parameter is the starting
8739
8856
  * point of the depth-first search. It can be either a node object, a key-value pair, or a key. If it
8740
8857
  * is a key or key-value pair, the method will find the corresponding node in the tree and start the
8741
8858
  * search from there.
@@ -8859,7 +8976,7 @@ var dataStructureTyped = (() => {
8859
8976
  * @param {C} callback - The `callback` parameter is a function that will be called for each node in
8860
8977
  * the breadth-first search traversal. It takes a single argument, which is the current node being
8861
8978
  * visited, and returns a value of any type.
8862
- * @param {R | KeyOrNodeOrEntry<K, V, NODE>} beginRoot - The `beginRoot` parameter represents the
8979
+ * @param {R | BTNKeyOrNodeOrEntry<K, V, NODE>} beginRoot - The `beginRoot` parameter represents the
8863
8980
  * starting point of the breadth-first search. It can be either a root node of a tree or a key, node,
8864
8981
  * or entry object. If no value is provided, the `root` property of the class is used as the default
8865
8982
  * starting point.
@@ -8934,7 +9051,7 @@ var dataStructureTyped = (() => {
8934
9051
  * @param {C} callback - The `callback` parameter is a function that will be called for each node in
8935
9052
  * the tree. It takes a node as an argument and returns a value. The return type of the callback
8936
9053
  * 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
9054
+ * @param {R | BTNKeyOrNodeOrEntry<K, V, NODE>} beginRoot - The `beginRoot` parameter represents the
8938
9055
  * starting point for traversing the tree. It can be either a root node, a key-value pair, or a node
8939
9056
  * entry. If no value is provided, the `root` property of the class is used as the default starting
8940
9057
  * point.
@@ -9009,7 +9126,7 @@ var dataStructureTyped = (() => {
9009
9126
  * @param {DFSOrderPattern} [pattern=IN] - The `pattern` parameter in the `morris` function is used
9010
9127
  * to specify the order in which the nodes of a binary tree are traversed. It can take one of the
9011
9128
  * following values:
9012
- * @param {R | KeyOrNodeOrEntry<K, V, NODE>} beginRoot - The `beginRoot` parameter is the starting
9129
+ * @param {R | BTNKeyOrNodeOrEntry<K, V, NODE>} beginRoot - The `beginRoot` parameter is the starting
9013
9130
  * point for the traversal. It can be either a node object, a key, or an entry object. If no value is
9014
9131
  * provided, the `root` of the tree is used as the starting point.
9015
9132
  * @returns The function `morris` returns an array of values that are the return values of the
@@ -9196,7 +9313,7 @@ var dataStructureTyped = (() => {
9196
9313
  * Space Complexity: O(n)
9197
9314
  *
9198
9315
  * 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
9316
+ * @param {R | BTNKeyOrNodeOrEntry<K, V, NODE>} beginRoot - The `beginRoot` parameter is the starting
9200
9317
  * point for printing the binary tree. It can be either a node of the binary tree or a key or entry
9201
9318
  * that exists in the binary tree. If no value is provided, the root of the binary tree will be used
9202
9319
  * as the starting point.
@@ -9278,7 +9395,7 @@ var dataStructureTyped = (() => {
9278
9395
  *
9279
9396
  * The `_displayAux` function is responsible for generating the display layout of a binary tree node,
9280
9397
  * taking into account various options such as whether to show null, undefined, or NaN nodes.
9281
- * @param {NODE | null | undefined} node - The `node` parameter represents a node in a binary tree.
9398
+ * @param {OptBTNOrNull<NODE>} node - The `node` parameter represents a node in a binary tree.
9282
9399
  * It can be of type `NODE`, `null`, or `undefined`.
9283
9400
  * @param {BinaryTreePrintOptions} options - The `options` parameter is an object that contains the
9284
9401
  * following properties:
@@ -9299,7 +9416,7 @@ var dataStructureTyped = (() => {
9299
9416
  } else if (this.isNIL(node) && !isShowRedBlackNIL) {
9300
9417
  return emptyDisplayLayout;
9301
9418
  } else if (node !== null && node !== void 0) {
9302
- const key = node.key, line = this.isNIL(node) ? "S" : key.toString(), width = line.length;
9419
+ const key = node.key, line = this.isNIL(node) ? "S" : String(key), width = line.length;
9303
9420
  return _buildNodeDisplay(
9304
9421
  line,
9305
9422
  width,
@@ -9307,7 +9424,7 @@ var dataStructureTyped = (() => {
9307
9424
  this._displayAux(node.right, options)
9308
9425
  );
9309
9426
  } else {
9310
- const line = node === void 0 ? "U" : "NODE", width = line.length;
9427
+ const line = node === void 0 ? "U" : "N", width = line.length;
9311
9428
  return _buildNodeDisplay(line, width, [[""], 1, 0, 0], [[""], 1, 0, 0]);
9312
9429
  }
9313
9430
  function _buildNodeDisplay(line, width, left, right) {
@@ -9338,10 +9455,10 @@ var dataStructureTyped = (() => {
9338
9455
  * Space Complexity: O(1)
9339
9456
  *
9340
9457
  * 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
9458
+ * @param {R | BTNKeyOrNodeOrEntry<K, V, NODE>} srcNode - The source node that will be swapped with the
9342
9459
  * 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
9460
+ * `BTNKeyOrNodeOrEntry<K, V, NODE>`.
9461
+ * @param {R | BTNKeyOrNodeOrEntry<K, V, NODE>} destNode - The `destNode` parameter is the node where
9345
9462
  * the properties will be swapped with the `srcNode`.
9346
9463
  * @returns either the `destNode` object with its properties swapped with the `srcNode` object's
9347
9464
  * properties, or `undefined` if either `srcNode` or `destNode` is falsy.
@@ -9404,7 +9521,7 @@ var dataStructureTyped = (() => {
9404
9521
  *
9405
9522
  * The function sets the root property of an object to the provided value, and also updates the
9406
9523
  * parent property of the new root.
9407
- * @param {NODE | null | undefined} v - The parameter `v` is of type `NODE | null | undefined`. This
9524
+ * @param {OptBTNOrNull<NODE>} v - The parameter `v` is of type `OptBTNOrNull<NODE>`. This
9408
9525
  * means that it can accept a value of type `NODE`, `null`, or `undefined`.
9409
9526
  */
9410
9527
  _setRoot(v) {
@@ -9458,7 +9575,7 @@ var dataStructureTyped = (() => {
9458
9575
  }
9459
9576
  /**
9460
9577
  * The function sets the left child of a node and updates the parent reference of the child.
9461
- * @param {NODE | undefined} v - The parameter `v` is of type `NODE | undefined`. It can either be an
9578
+ * @param {OptBSTN<NODE>} v - The parameter `v` is of type `OptBSTN<NODE>`. It can either be an
9462
9579
  * instance of the `NODE` class or `undefined`.
9463
9580
  */
9464
9581
  set left(v) {
@@ -9477,7 +9594,7 @@ var dataStructureTyped = (() => {
9477
9594
  }
9478
9595
  /**
9479
9596
  * The function sets the right child of a node and updates the parent reference of the child.
9480
- * @param {NODE | undefined} v - The parameter `v` is of type `NODE | undefined`. It can either be a
9597
+ * @param {OptBSTN<NODE>} v - The parameter `v` is of type `OptBSTN<NODE>`. It can either be a
9481
9598
  * `NODE` object or `undefined`.
9482
9599
  */
9483
9600
  set right(v) {
@@ -9499,14 +9616,10 @@ var dataStructureTyped = (() => {
9499
9616
  constructor(keysOrNodesOrEntriesOrRawElements = [], options) {
9500
9617
  super([], options);
9501
9618
  __publicField(this, "_root");
9502
- /**
9503
- * Time complexity: O(n)
9504
- * Space complexity: O(n)
9505
- */
9506
9619
  __publicField(this, "_DEFAULT_COMPARATOR", (a, b) => {
9507
- if (typeof a === "object" && typeof b === "object" && this.comparator === this._DEFAULT_COMPARATOR) {
9620
+ if (typeof a === "object" || typeof b === "object") {
9508
9621
  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."
9622
+ `When comparing object types, a custom comparator must be defined in the constructor's options parameter.`
9510
9623
  );
9511
9624
  }
9512
9625
  if (a > b)
@@ -9515,10 +9628,6 @@ var dataStructureTyped = (() => {
9515
9628
  return -1;
9516
9629
  return 0;
9517
9630
  });
9518
- /**
9519
- * Time complexity: O(n)
9520
- * Space complexity: O(n)
9521
- */
9522
9631
  __publicField(this, "_comparator", this._DEFAULT_COMPARATOR);
9523
9632
  if (options) {
9524
9633
  const { comparator } = options;
@@ -9561,8 +9670,8 @@ var dataStructureTyped = (() => {
9561
9670
  }
9562
9671
  /**
9563
9672
  * 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
9673
+ * @param {R | BTNKeyOrNodeOrEntry<K, V, NODE>} keyOrNodeOrEntryOrRawElement - A variable that can be of
9674
+ * type R or BTNKeyOrNodeOrEntry<K, V, NODE>. It represents either a key, a node, an entry, or a raw
9566
9675
  * element.
9567
9676
  * @param {V} [value] - The `value` parameter is an optional value of type `V`. It represents the
9568
9677
  * value associated with a key in a key-value pair.
@@ -9578,7 +9687,7 @@ var dataStructureTyped = (() => {
9578
9687
  *
9579
9688
  * The function ensures the existence of a node in a data structure and returns it, or undefined if
9580
9689
  * it doesn't exist.
9581
- * @param {R | KeyOrNodeOrEntry<K, V, NODE>} keyOrNodeOrEntryOrRawElement - The parameter
9690
+ * @param {R | BTNKeyOrNodeOrEntry<K, V, NODE>} keyOrNodeOrEntryOrRawElement - The parameter
9582
9691
  * `keyOrNodeOrEntryOrRawElement` can accept a value of type `R`, which represents the key, node,
9583
9692
  * entry, or raw element that needs to be ensured in the tree.
9584
9693
  * @param {IterationType} [iterationType=ITERATIVE] - The `iterationType` parameter is an optional
@@ -9593,8 +9702,8 @@ var dataStructureTyped = (() => {
9593
9702
  }
9594
9703
  /**
9595
9704
  * 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>`.
9705
+ * @param {R | BTNKeyOrNodeOrEntry<K, V, NODE>} keyOrNodeOrEntryOrRawElement - The parameter
9706
+ * `keyOrNodeOrEntryOrRawElement` can be of type `R` or `BTNKeyOrNodeOrEntry<K, V, NODE>`.
9598
9707
  * @returns a boolean value indicating whether the input parameter `keyOrNodeOrEntryOrRawElement` is
9599
9708
  * an instance of the `BSTNode` class.
9600
9709
  */
@@ -9606,8 +9715,8 @@ var dataStructureTyped = (() => {
9606
9715
  * Space Complexity: O(1)
9607
9716
  *
9608
9717
  * 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>`.
9718
+ * @param {R | BTNKeyOrNodeOrEntry<K, V, NODE>} keyOrNodeOrEntryOrRawElement - The parameter
9719
+ * `keyOrNodeOrEntryOrRawElement` can accept a value of type `R` or `BTNKeyOrNodeOrEntry<K, V, NODE>`.
9611
9720
  * @param {V} [value] - The `value` parameter is an optional value that can be associated with the
9612
9721
  * key in the binary search tree. If provided, it will be stored in the node along with the key.
9613
9722
  * @returns a boolean value.
@@ -9766,7 +9875,7 @@ var dataStructureTyped = (() => {
9766
9875
  * @param [onlyOne=false] - A boolean value indicating whether to return only the first matching node
9767
9876
  * or all matching nodes. If set to true, only the first matching node will be returned. If set to
9768
9877
  * 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
9878
+ * @param {R | BTNKeyOrNodeOrEntry<K, V, NODE>} beginRoot - The `beginRoot` parameter is the starting
9770
9879
  * point for the search in the binary tree. It can be either a node object, a key-value pair, or an
9771
9880
  * entry object. If it is not provided, the `root` of the binary tree is used as the starting point.
9772
9881
  * @param {IterationType} iterationType - The `iterationType` parameter determines the type of
@@ -9888,7 +9997,7 @@ var dataStructureTyped = (() => {
9888
9997
  * @param {DFSOrderPattern} [pattern=IN] - The "pattern" parameter in the code snippet refers to the
9889
9998
  * order in which the Depth-First Search (DFS) algorithm visits the nodes in a tree or graph. It can
9890
9999
  * take one of the following values:
9891
- * @param {R | KeyOrNodeOrEntry<K, V, NODE>} beginRoot - The `beginRoot` parameter is the starting
10000
+ * @param {R | BTNKeyOrNodeOrEntry<K, V, NODE>} beginRoot - The `beginRoot` parameter is the starting
9892
10001
  * point for the depth-first search traversal. It can be either a root node, a key-value pair, or a
9893
10002
  * node entry. If not specified, the default value is the root of the tree.
9894
10003
  * @param {IterationType} [iterationType=ITERATIVE] - The `iterationType` parameter specifies the
@@ -9912,7 +10021,7 @@ var dataStructureTyped = (() => {
9912
10021
  * @param {C} callback - The `callback` parameter is a function that will be called for each node
9913
10022
  * visited during the breadth-first search. It should take a single argument, which is the current
9914
10023
  * 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
10024
+ * @param {R | BTNKeyOrNodeOrEntry<K, V, NODE>} beginRoot - The `beginRoot` parameter is the starting
9916
10025
  * point for the breadth-first search. It can be either a root node, a key-value pair, or an entry
9917
10026
  * object. If no value is provided, the default value is the root of the tree.
9918
10027
  * @param {IterationType} iterationType - The `iterationType` parameter is used to specify the type
@@ -9936,7 +10045,7 @@ var dataStructureTyped = (() => {
9936
10045
  * @param {C} callback - The `callback` parameter is a generic type `C` that extends
9937
10046
  * `BTNCallback<NODE>`. It represents a callback function that will be called for each node in the
9938
10047
  * tree during the iteration process.
9939
- * @param {R | KeyOrNodeOrEntry<K, V, NODE>} beginRoot - The `beginRoot` parameter is the starting
10048
+ * @param {R | BTNKeyOrNodeOrEntry<K, V, NODE>} beginRoot - The `beginRoot` parameter is the starting
9940
10049
  * point for listing the levels of the binary tree. It can be either a root node of the tree, a
9941
10050
  * key-value pair representing a node in the tree, or a key representing a node in the tree. If no
9942
10051
  * value is provided, the root of
@@ -9964,7 +10073,7 @@ var dataStructureTyped = (() => {
9964
10073
  * @param {CP} lesserOrGreater - The `lesserOrGreater` parameter is used to determine whether to
9965
10074
  * traverse nodes that are lesser, greater, or both than the `targetNode`. It accepts the values -1,
9966
10075
  * 0, or 1, where:
9967
- * @param {R | KeyOrNodeOrEntry<K, V, NODE>} targetNode - The `targetNode` parameter is the node in
10076
+ * @param {R | BTNKeyOrNodeOrEntry<K, V, NODE>} targetNode - The `targetNode` parameter is the node in
9968
10077
  * the binary tree that you want to start traversing from. It can be specified either by providing
9969
10078
  * the key of the node, the node itself, or an entry containing the key and value of the node. If no
9970
10079
  * `targetNode` is provided,
@@ -10134,7 +10243,7 @@ var dataStructureTyped = (() => {
10134
10243
  /**
10135
10244
  * The function sets the root of a tree-like structure and updates the parent property of the new
10136
10245
  * root.
10137
- * @param {NODE | undefined} v - v is a parameter of type NODE or undefined.
10246
+ * @param {OptBSTN<NODE>} v - v is a parameter of type NODE or undefined.
10138
10247
  */
10139
10248
  _setRoot(v) {
10140
10249
  if (v) {
@@ -10784,8 +10893,8 @@ var dataStructureTyped = (() => {
10784
10893
  }
10785
10894
  /**
10786
10895
  * 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>`.
10896
+ * @param {R | BTNKeyOrNodeOrEntry<K, V, NODE>} keyOrNodeOrEntryOrRawElement - The parameter
10897
+ * `keyOrNodeOrEntryOrRawElement` can be of type `R` or `BTNKeyOrNodeOrEntry<K, V, NODE>`.
10789
10898
  * @returns a boolean value indicating whether the input parameter `keyOrNodeOrEntryOrRawElement` is
10790
10899
  * an instance of the `AVLTreeNode` class.
10791
10900
  */
@@ -10803,8 +10912,8 @@ var dataStructureTyped = (() => {
10803
10912
  *
10804
10913
  * The function overrides the add method of a class and inserts a key-value pair into a data
10805
10914
  * 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
10915
+ * @param {R | BTNKeyOrNodeOrEntry<K, V, NODE>} keyOrNodeOrEntryOrRawElement - The parameter
10916
+ * `keyOrNodeOrEntryOrRawElement` can accept values of type `R`, `BTNKeyOrNodeOrEntry<K, V, NODE>`, or
10808
10917
  * `RawElement`.
10809
10918
  * @param {V} [value] - The `value` parameter is an optional value that you want to associate with
10810
10919
  * the key or node being added to the data structure.
@@ -11123,8 +11232,8 @@ var dataStructureTyped = (() => {
11123
11232
  *
11124
11233
  * The `_balancePath` function is used to update the heights of nodes and perform rotation operations
11125
11234
  * to restore balance in an AVL tree after inserting a node.
11126
- * @param {R | KeyOrNodeOrEntry<K, V, NODE>} node - The `node` parameter can be of type `R` or
11127
- * `KeyOrNodeOrEntry<K, V, NODE>`.
11235
+ * @param {R | BTNKeyOrNodeOrEntry<K, V, NODE>} node - The `node` parameter can be of type `R` or
11236
+ * `BTNKeyOrNodeOrEntry<K, V, NODE>`.
11128
11237
  */
11129
11238
  _balancePath(node) {
11130
11239
  node = this.ensureNode(node);
@@ -11272,8 +11381,8 @@ var dataStructureTyped = (() => {
11272
11381
  * Space Complexity: O(1)
11273
11382
  *
11274
11383
  * 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>`.
11384
+ * @param {R | BTNKeyOrNodeOrEntry<K, V, NODE>} keyOrNodeOrEntryOrRawElement - The parameter
11385
+ * `keyOrNodeOrEntryOrRawElement` can be of type `R` or `BTNKeyOrNodeOrEntry<K, V, NODE>`.
11277
11386
  * @returns a boolean value indicating whether the input parameter `keyOrNodeOrEntryOrRawElement` is
11278
11387
  * an instance of the `RedBlackTreeNode` class.
11279
11388
  */
@@ -11291,11 +11400,11 @@ var dataStructureTyped = (() => {
11291
11400
  // *
11292
11401
  // * The function `keyValueOrEntryOrRawElementToNode` takes a key, value, or entry and returns a node if it is
11293
11402
  // * valid, otherwise it returns undefined.
11294
- // * @param {KeyOrNodeOrEntry<K, V, NODE>} keyOrNodeOrEntryOrRawElement - The key, value, or entry to convert.
11403
+ // * @param {BTNKeyOrNodeOrEntry<K, V, NODE>} keyOrNodeOrEntryOrRawElement - The key, value, or entry to convert.
11295
11404
  // * @param {V} [value] - The value associated with the key (if `keyOrNodeOrEntryOrRawElement` is a key).
11296
11405
  // * @returns {NODE | undefined} - The corresponding Red-Black Tree node, or `undefined` if conversion fails.
11297
11406
  // */
11298
- // override keyValueOrEntryOrRawElementToNode(keyOrNodeOrEntryOrRawElement: R | KeyOrNodeOrEntry<K, V, NODE>, value?: V): NODE | undefined {
11407
+ // override keyValueOrEntryOrRawElementToNode(keyOrNodeOrEntryOrRawElement: R | BTNKeyOrNodeOrEntry<K, V, NODE>, value?: V): NODE | undefined {
11299
11408
  //
11300
11409
  // if (keyOrNodeOrEntryOrRawElement === null || keyOrNodeOrEntryOrRawElement === undefined) return;
11301
11410
  // if (this.isNode(keyOrNodeOrEntryOrRawElement)) return keyOrNodeOrEntryOrRawElement;
@@ -11340,8 +11449,8 @@ var dataStructureTyped = (() => {
11340
11449
  *
11341
11450
  * The function adds a new node to a binary search tree and returns true if the node was successfully
11342
11451
  * 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>`.
11452
+ * @param {R | BTNKeyOrNodeOrEntry<K, V, NODE>} keyOrNodeOrEntryOrRawElement - The parameter
11453
+ * `keyOrNodeOrEntryOrRawElement` can accept a value of type `R` or `BTNKeyOrNodeOrEntry<K, V, NODE>`.
11345
11454
  * @param {V} [value] - The `value` parameter is an optional value that you want to associate with
11346
11455
  * the key in the data structure. It represents the value that you want to add or update in the data
11347
11456
  * structure.
@@ -11847,8 +11956,8 @@ var dataStructureTyped = (() => {
11847
11956
  }
11848
11957
  /**
11849
11958
  * 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>`.
11959
+ * @param {R | BTNKeyOrNodeOrEntry<K, V, NODE>} keyOrNodeOrEntryOrRawElement - The parameter
11960
+ * `keyOrNodeOrEntryOrRawElement` can be of type `R` or `BTNKeyOrNodeOrEntry<K, V, NODE>`.
11852
11961
  * @returns a boolean value indicating whether the input parameter `keyOrNodeOrEntryOrRawElement` is
11853
11962
  * an instance of the `AVLTreeMultiMapNode` class.
11854
11963
  */
@@ -11858,8 +11967,8 @@ var dataStructureTyped = (() => {
11858
11967
  /**
11859
11968
  * The function `keyValueOrEntryOrRawElementToNode` converts a key, value, entry, or raw element into
11860
11969
  * 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>`.
11970
+ * @param {R | BTNKeyOrNodeOrEntry<K, V, NODE>} keyOrNodeOrEntryOrRawElement - The
11971
+ * `keyOrNodeOrEntryOrRawElement` parameter can be of type `R` or `BTNKeyOrNodeOrEntry<K, V, NODE>`.
11863
11972
  * @param {V} [value] - The `value` parameter is an optional value that can be passed to the
11864
11973
  * `override` function. It represents the value associated with the key in the data structure. If no
11865
11974
  * value is provided, it will default to `undefined`.
@@ -11898,9 +12007,9 @@ var dataStructureTyped = (() => {
11898
12007
  *
11899
12008
  * The function overrides the add method of a TypeScript class to add a new node to a data structure
11900
12009
  * and update the count.
11901
- * @param {R | KeyOrNodeOrEntry<K, V, NODE>} keyOrNodeOrEntryOrRawElement - The
12010
+ * @param {R | BTNKeyOrNodeOrEntry<K, V, NODE>} keyOrNodeOrEntryOrRawElement - The
11902
12011
  * `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,
12012
+ * can also accept a value of type `BTNKeyOrNodeOrEntry<K, V, NODE>`, which represents a key, node,
11904
12013
  * entry, or raw element
11905
12014
  * @param {V} [value] - The `value` parameter represents the value associated with the key in the
11906
12015
  * data structure. It is an optional parameter, so it can be omitted if not needed.
@@ -12245,8 +12354,8 @@ var dataStructureTyped = (() => {
12245
12354
  /**
12246
12355
  * The function `keyValueOrEntryOrRawElementToNode` takes in a key, value, and count and returns a
12247
12356
  * 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>`.
12357
+ * @param {R | BTNKeyOrNodeOrEntry<K, V, NODE>} keyOrNodeOrEntryOrRawElement - The parameter
12358
+ * `keyOrNodeOrEntryOrRawElement` can be of type `R` or `BTNKeyOrNodeOrEntry<K, V, NODE>`.
12250
12359
  * @param {V} [value] - The `value` parameter is an optional value that represents the value
12251
12360
  * associated with the key in the node. It is used when creating a new node or updating the value of
12252
12361
  * an existing node.
@@ -12277,8 +12386,8 @@ var dataStructureTyped = (() => {
12277
12386
  }
12278
12387
  /**
12279
12388
  * 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>`.
12389
+ * @param {R | BTNKeyOrNodeOrEntry<K, V, NODE>} keyOrNodeOrEntryOrRawElement - The parameter
12390
+ * `keyOrNodeOrEntryOrRawElement` can be of type `R` or `BTNKeyOrNodeOrEntry<K, V, NODE>`.
12282
12391
  * @returns a boolean value indicating whether the input parameter `keyOrNodeOrEntryOrRawElement` is
12283
12392
  * an instance of the `TreeMultiMapNode` class.
12284
12393
  */
@@ -12295,7 +12404,7 @@ var dataStructureTyped = (() => {
12295
12404
  *
12296
12405
  * The function overrides the add method of a class and adds a new node to a data structure, updating
12297
12406
  * the count and returning a boolean indicating success.
12298
- * @param {R | KeyOrNodeOrEntry<K, V, NODE>} keyOrNodeOrEntryOrRawElement - The
12407
+ * @param {R | BTNKeyOrNodeOrEntry<K, V, NODE>} keyOrNodeOrEntryOrRawElement - The
12299
12408
  * `keyOrNodeOrEntryOrRawElement` parameter can accept one of the following types:
12300
12409
  * @param {V} [value] - The `value` parameter represents the value associated with the key in the
12301
12410
  * data structure. It is an optional parameter, so it can be omitted if not needed.
@@ -12562,11 +12671,11 @@ var dataStructureTyped = (() => {
12562
12671
  };
12563
12672
 
12564
12673
  // src/data-structures/priority-queue/priority-queue.ts
12565
- var PriorityQueue = class extends Heap {
12674
+ var PriorityQueue = class _PriorityQueue extends Heap {
12566
12675
  /**
12567
12676
  * The constructor initializes a priority queue with optional elements and options.
12568
12677
  * @param elements - The `elements` parameter is an iterable object that contains the initial
12569
- * elements to be added to the priority queue. It is an optional parameter and if not provided, the
12678
+ * elements to be added to the priority queue. It is an optional parameter, and if not provided, the
12570
12679
  * priority queue will be initialized as empty.
12571
12680
  * @param [options] - The `options` parameter is an optional object that can be used to customize the
12572
12681
  * behavior of the priority queue. It can contain the following properties:
@@ -12574,10 +12683,79 @@ var dataStructureTyped = (() => {
12574
12683
  constructor(elements = [], options) {
12575
12684
  super(elements, options);
12576
12685
  }
12686
+ /**
12687
+ * The `clone` function returns a new instance of the `PriorityQueue` class with the same comparator
12688
+ * and toElementFn as the original instance.
12689
+ * @returns The method is returning a new instance of the `PriorityQueue` class with the same
12690
+ * elements and properties as the current instance.
12691
+ */
12692
+ clone() {
12693
+ return new _PriorityQueue(this, { comparator: this.comparator, toElementFn: this.toElementFn });
12694
+ }
12695
+ /**
12696
+ * Time Complexity: O(n)
12697
+ * Space Complexity: O(n)
12698
+ *
12699
+ * The `filter` function creates a new PriorityQueue object containing elements that pass a given callback
12700
+ * function.
12701
+ * @param callback - The `callback` parameter is a function that will be called for each element in
12702
+ * the heap. It takes three arguments: the current element, the index of the current element, and the
12703
+ * heap itself. The callback function should return a boolean value indicating whether the current
12704
+ * element should be included in the filtered list
12705
+ * @param {any} [thisArg] - The `thisArg` parameter is an optional argument that specifies the value
12706
+ * to be used as `this` when executing the `callback` function. If `thisArg` is provided, it will be
12707
+ * passed as the `this` value to the `callback` function. If `thisArg` is
12708
+ * @returns The `filter` method is returning a new `PriorityQueue` object that contains the elements that pass
12709
+ * the filter condition specified by the `callback` function.
12710
+ */
12711
+ filter(callback, thisArg) {
12712
+ const filteredPriorityQueue = new _PriorityQueue([], {
12713
+ toElementFn: this.toElementFn,
12714
+ comparator: this.comparator
12715
+ });
12716
+ let index = 0;
12717
+ for (const current of this) {
12718
+ if (callback.call(thisArg, current, index, this)) {
12719
+ filteredPriorityQueue.add(current);
12720
+ }
12721
+ index++;
12722
+ }
12723
+ return filteredPriorityQueue;
12724
+ }
12725
+ /**
12726
+ * Time Complexity: O(n log n)
12727
+ * Space Complexity: O(n)
12728
+ *
12729
+ * The `map` function creates a new heap by applying a callback function to each element of the
12730
+ * original heap.
12731
+ * @param callback - The `callback` parameter is a function that will be called for each element in
12732
+ * the heap. It takes three arguments: `el` (the current element), `index` (the index of the current
12733
+ * element), and `this` (the heap itself). The callback function should return a value of
12734
+ * @param comparator - The `comparator` parameter is a function that defines the order of the
12735
+ * elements in the heap. It takes two elements `a` and `b` as arguments and returns a negative number
12736
+ * if `a` should be placed before `b`, a positive number if `a` should be placed after
12737
+ * @param [toElementFn] - The `toElementFn` parameter is an optional function that converts the raw
12738
+ * element `RR` to the desired type `T`. It takes a single argument `rawElement` of type `RR` and
12739
+ * returns a value of type `T`. This function is used to transform the elements of the original
12740
+ * @param {any} [thisArg] - The `thisArg` parameter is an optional argument that allows you to
12741
+ * specify the value of `this` within the callback function. It is used to set the context or scope
12742
+ * in which the callback function will be executed. If `thisArg` is provided, it will be used as the
12743
+ * value of
12744
+ * @returns a new instance of the `PriorityQueue` class with the mapped elements.
12745
+ */
12746
+ map(callback, comparator, toElementFn, thisArg) {
12747
+ const mappedPriorityQueue = new _PriorityQueue([], { comparator, toElementFn });
12748
+ let index = 0;
12749
+ for (const el of this) {
12750
+ mappedPriorityQueue.add(callback.call(thisArg, el, index, this));
12751
+ index++;
12752
+ }
12753
+ return mappedPriorityQueue;
12754
+ }
12577
12755
  };
12578
12756
 
12579
12757
  // src/data-structures/priority-queue/min-priority-queue.ts
12580
- var MinPriorityQueue = class extends PriorityQueue {
12758
+ var MinPriorityQueue = class _MinPriorityQueue extends PriorityQueue {
12581
12759
  /**
12582
12760
  * The constructor initializes a PriorityQueue with optional elements and options, including a
12583
12761
  * comparator function.
@@ -12585,25 +12763,86 @@ var dataStructureTyped = (() => {
12585
12763
  * elements to be added to the priority queue. It is optional and defaults to an empty array if not
12586
12764
  * provided.
12587
12765
  * @param options - The `options` parameter is an object that contains additional configuration
12588
- * options for the priority queue. In this case, it has a property called `comparator` which is a
12766
+ * options for the priority queue. In this case, it has a property called `comparator,` which is a
12589
12767
  * function used to compare elements in the priority queue. The `comparator` function takes two
12590
- * parameters `a` and `b`,
12768
+ * parameters `a` and `b`
12591
12769
  */
12592
- constructor(elements = [], options = {
12593
- comparator: (a, b) => {
12594
- if (!(typeof a === "number" && typeof b === "number")) {
12595
- throw new Error("The a, b params of compare function must be number");
12596
- } else {
12597
- return a - b;
12770
+ constructor(elements = [], options) {
12771
+ super(elements, options);
12772
+ }
12773
+ /**
12774
+ * The `clone` function returns a new instance of the `MinPriorityQueue` class with the same
12775
+ * comparator and toElementFn as the original instance.
12776
+ * @returns The method is returning a new instance of the `MinPriorityQueue` class with the same
12777
+ * properties as the current instance.
12778
+ */
12779
+ clone() {
12780
+ return new _MinPriorityQueue(this, { comparator: this.comparator, toElementFn: this.toElementFn });
12781
+ }
12782
+ /**
12783
+ * Time Complexity: O(n)
12784
+ * Space Complexity: O(n)
12785
+ *
12786
+ * The `filter` function creates a new MinPriorityQueue object containing elements that pass a given callback
12787
+ * function.
12788
+ * @param callback - The `callback` parameter is a function that will be called for each element in
12789
+ * the heap. It takes three arguments: the current element, the index of the current element, and the
12790
+ * heap itself. The callback function should return a boolean value indicating whether the current
12791
+ * element should be included in the filtered list
12792
+ * @param {any} [thisArg] - The `thisArg` parameter is an optional argument that specifies the value
12793
+ * to be used as `this` when executing the `callback` function. If `thisArg` is provided, it will be
12794
+ * passed as the `this` value to the `callback` function. If `thisArg` is
12795
+ * @returns The `filter` method is returning a new `MinPriorityQueue` object that contains the elements that pass
12796
+ * the filter condition specified by the `callback` function.
12797
+ */
12798
+ filter(callback, thisArg) {
12799
+ const filteredPriorityQueue = new _MinPriorityQueue([], {
12800
+ toElementFn: this.toElementFn,
12801
+ comparator: this.comparator
12802
+ });
12803
+ let index = 0;
12804
+ for (const current of this) {
12805
+ if (callback.call(thisArg, current, index, this)) {
12806
+ filteredPriorityQueue.add(current);
12598
12807
  }
12808
+ index++;
12599
12809
  }
12600
- }) {
12601
- super(elements, options);
12810
+ return filteredPriorityQueue;
12811
+ }
12812
+ /**
12813
+ * Time Complexity: O(n log n)
12814
+ * Space Complexity: O(n)
12815
+ *
12816
+ * The `map` function creates a new heap by applying a callback function to each element of the
12817
+ * original heap.
12818
+ * @param callback - The `callback` parameter is a function that will be called for each element in
12819
+ * the heap. It takes three arguments: `el` (the current element), `index` (the index of the current
12820
+ * element), and `this` (the heap itself). The callback function should return a value of
12821
+ * @param comparator - The `comparator` parameter is a function that defines the order of the
12822
+ * elements in the heap. It takes two elements `a` and `b` as arguments and returns a negative number
12823
+ * if `a` should be placed before `b`, a positive number if `a` should be placed after
12824
+ * @param [toElementFn] - The `toElementFn` parameter is an optional function that converts the raw
12825
+ * element `RR` to the desired type `T`. It takes a single argument `rawElement` of type `RR` and
12826
+ * returns a value of type `T`. This function is used to transform the elements of the original
12827
+ * @param {any} [thisArg] - The `thisArg` parameter is an optional argument that allows you to
12828
+ * specify the value of `this` within the callback function. It is used to set the context or scope
12829
+ * in which the callback function will be executed. If `thisArg` is provided, it will be used as the
12830
+ * value of
12831
+ * @returns a new instance of the `MinPriorityQueue` class with the mapped elements.
12832
+ */
12833
+ map(callback, comparator, toElementFn, thisArg) {
12834
+ const mappedPriorityQueue = new _MinPriorityQueue([], { comparator, toElementFn });
12835
+ let index = 0;
12836
+ for (const el of this) {
12837
+ mappedPriorityQueue.add(callback.call(thisArg, el, index, this));
12838
+ index++;
12839
+ }
12840
+ return mappedPriorityQueue;
12602
12841
  }
12603
12842
  };
12604
12843
 
12605
12844
  // src/data-structures/priority-queue/max-priority-queue.ts
12606
- var MaxPriorityQueue = class extends PriorityQueue {
12845
+ var MaxPriorityQueue = class _MaxPriorityQueue extends PriorityQueue {
12607
12846
  /**
12608
12847
  * The constructor initializes a PriorityQueue with optional elements and options, including a
12609
12848
  * comparator function.
@@ -12611,19 +12850,93 @@ var dataStructureTyped = (() => {
12611
12850
  * elements to be added to the priority queue. It is optional and defaults to an empty array if not
12612
12851
  * provided.
12613
12852
  * @param options - The `options` parameter is an object that contains additional configuration
12614
- * options for the priority queue. In this case, it has a property called `comparator` which is a
12853
+ * options for the priority queue. In this case, it has a property called `comparator,` which is a
12615
12854
  * function used to compare elements in the priority queue.
12616
12855
  */
12617
- constructor(elements = [], options = {
12618
- comparator: (a, b) => {
12619
- if (!(typeof a === "number" && typeof b === "number")) {
12620
- throw new Error("The a, b params of compare function must be number");
12621
- } else {
12622
- return b - a;
12856
+ constructor(elements = [], options) {
12857
+ super(elements, __spreadValues({
12858
+ comparator: (a, b) => {
12859
+ if (typeof a === "object" || typeof b === "object") {
12860
+ throw TypeError(
12861
+ `When comparing object types, a custom comparator must be defined in the constructor's options parameter.`
12862
+ );
12863
+ }
12864
+ if (a < b)
12865
+ return 1;
12866
+ if (a > b)
12867
+ return -1;
12868
+ return 0;
12869
+ }
12870
+ }, options));
12871
+ }
12872
+ /**
12873
+ * The `clone` function returns a new instance of the `MaxPriorityQueue` class with the same
12874
+ * comparator and toElementFn as the current instance.
12875
+ * @returns The method is returning a new instance of the MaxPriorityQueue class with the same
12876
+ * comparator and toElementFn as the current instance.
12877
+ */
12878
+ clone() {
12879
+ return new _MaxPriorityQueue(this, { comparator: this.comparator, toElementFn: this.toElementFn });
12880
+ }
12881
+ /**
12882
+ * Time Complexity: O(n)
12883
+ * Space Complexity: O(n)
12884
+ *
12885
+ * The `filter` function creates a new MaxPriorityQueue object containing elements that pass a given callback
12886
+ * function.
12887
+ * @param callback - The `callback` parameter is a function that will be called for each element in
12888
+ * the heap. It takes three arguments: the current element, the index of the current element, and the
12889
+ * heap itself. The callback function should return a boolean value indicating whether the current
12890
+ * element should be included in the filtered list
12891
+ * @param {any} [thisArg] - The `thisArg` parameter is an optional argument that specifies the value
12892
+ * to be used as `this` when executing the `callback` function. If `thisArg` is provided, it will be
12893
+ * passed as the `this` value to the `callback` function. If `thisArg` is
12894
+ * @returns The `filter` method is returning a new `MaxPriorityQueue` object that contains the elements that pass
12895
+ * the filter condition specified by the `callback` function.
12896
+ */
12897
+ filter(callback, thisArg) {
12898
+ const filteredPriorityQueue = new _MaxPriorityQueue([], {
12899
+ toElementFn: this.toElementFn,
12900
+ comparator: this.comparator
12901
+ });
12902
+ let index = 0;
12903
+ for (const current of this) {
12904
+ if (callback.call(thisArg, current, index, this)) {
12905
+ filteredPriorityQueue.add(current);
12623
12906
  }
12907
+ index++;
12624
12908
  }
12625
- }) {
12626
- super(elements, options);
12909
+ return filteredPriorityQueue;
12910
+ }
12911
+ /**
12912
+ * Time Complexity: O(n log n)
12913
+ * Space Complexity: O(n)
12914
+ *
12915
+ * The `map` function creates a new heap by applying a callback function to each element of the
12916
+ * original heap.
12917
+ * @param callback - The `callback` parameter is a function that will be called for each element in
12918
+ * the heap. It takes three arguments: `el` (the current element), `index` (the index of the current
12919
+ * element), and `this` (the heap itself). The callback function should return a value of
12920
+ * @param comparator - The `comparator` parameter is a function that defines the order of the
12921
+ * elements in the heap. It takes two elements `a` and `b` as arguments and returns a negative number
12922
+ * if `a` should be placed before `b`, a positive number if `a` should be placed after
12923
+ * @param [toElementFn] - The `toElementFn` parameter is an optional function that converts the raw
12924
+ * element `RR` to the desired type `T`. It takes a single argument `rawElement` of type `RR` and
12925
+ * returns a value of type `T`. This function is used to transform the elements of the original
12926
+ * @param {any} [thisArg] - The `thisArg` parameter is an optional argument that allows you to
12927
+ * specify the value of `this` within the callback function. It is used to set the context or scope
12928
+ * in which the callback function will be executed. If `thisArg` is provided, it will be used as the
12929
+ * value of
12930
+ * @returns a new instance of the `MaxPriorityQueue` class with the mapped elements.
12931
+ */
12932
+ map(callback, comparator, toElementFn, thisArg) {
12933
+ const mappedPriorityQueue = new _MaxPriorityQueue([], { comparator, toElementFn });
12934
+ let index = 0;
12935
+ for (const el of this) {
12936
+ mappedPriorityQueue.add(callback.call(thisArg, el, index, this));
12937
+ index++;
12938
+ }
12939
+ return mappedPriorityQueue;
12627
12940
  }
12628
12941
  };
12629
12942
 
@@ -13237,7 +13550,7 @@ var dataStructureTyped = (() => {
13237
13550
  * @return This
13238
13551
  */
13239
13552
  constructor(words = [], options) {
13240
- super();
13553
+ super(options);
13241
13554
  __publicField(this, "_size", 0);
13242
13555
  __publicField(this, "_caseSensitive", true);
13243
13556
  __publicField(this, "_root", new TrieNode(""));
@@ -13247,8 +13560,13 @@ var dataStructureTyped = (() => {
13247
13560
  this._caseSensitive = caseSensitive;
13248
13561
  }
13249
13562
  if (words) {
13250
- for (const word of words)
13251
- this.add(word);
13563
+ for (const word of words) {
13564
+ if (this.toElementFn) {
13565
+ this.add(this.toElementFn(word));
13566
+ } else {
13567
+ this.add(word);
13568
+ }
13569
+ }
13252
13570
  }
13253
13571
  }
13254
13572
  /**
@@ -13586,7 +13904,7 @@ var dataStructureTyped = (() => {
13586
13904
  * @returns A new instance of the Trie class is being returned.
13587
13905
  */
13588
13906
  clone() {
13589
- return new _Trie(this.values(), { caseSensitive: this.caseSensitive });
13907
+ return new _Trie(this, { caseSensitive: this.caseSensitive, toElementFn: this.toElementFn });
13590
13908
  }
13591
13909
  /**
13592
13910
  * Time Complexity: O(n)
@@ -13607,7 +13925,7 @@ var dataStructureTyped = (() => {
13607
13925
  * @returns The `filter` method is returning an array of strings (`string[]`).
13608
13926
  */
13609
13927
  filter(predicate, thisArg) {
13610
- const results = new _Trie();
13928
+ const results = new _Trie([], { toElementFn: this.toElementFn, caseSensitive: this.caseSensitive });
13611
13929
  let index = 0;
13612
13930
  for (const word of this) {
13613
13931
  if (predicate.call(thisArg, word, index, this)) {
@@ -13625,17 +13943,22 @@ var dataStructureTyped = (() => {
13625
13943
  * Time Complexity: O(n)
13626
13944
  * Space Complexity: O(n)
13627
13945
  *
13628
- * The `map` function creates a new Trie by applying a callback function to each element in the Trie.
13946
+ * The `map` function creates a new Trie by applying a callback function to each element in the
13947
+ * current Trie.
13629
13948
  * @param callback - The callback parameter is a function that will be called for each element in the
13630
- * Trie. It takes three arguments: the current element in the Trie, the index of the current element,
13631
- * and the Trie itself. The callback function should return a new value for the element.
13632
- * @param {any} [thisArg] - The `thisArg` parameter is an optional argument that specifies the value
13633
- * to be used as `this` when executing the `callback` function. If `thisArg` is provided, it will be
13634
- * passed as the `this` value to the `callback` function. If `thisArg` is
13635
- * @returns The `map` function is returning a new Trie object.
13949
+ * Trie. It takes four arguments:
13950
+ * @param [toElementFn] - The `toElementFn` parameter is an optional function that can be used to
13951
+ * convert the raw element (`RM`) into a string representation. This can be useful if the raw element
13952
+ * is not already a string or if you want to customize how the element is converted into a string. If
13953
+ * this parameter is
13954
+ * @param {any} [thisArg] - The `thisArg` parameter is an optional argument that allows you to
13955
+ * specify the value of `this` within the callback function. It is used to set the context or scope
13956
+ * in which the callback function will be executed. If `thisArg` is provided, it will be used as the
13957
+ * value of
13958
+ * @returns a new Trie object.
13636
13959
  */
13637
- map(callback, thisArg) {
13638
- const newTrie = new _Trie();
13960
+ map(callback, toElementFn, thisArg) {
13961
+ const newTrie = new _Trie([], { toElementFn, caseSensitive: this.caseSensitive });
13639
13962
  let index = 0;
13640
13963
  for (const word of this) {
13641
13964
  newTrie.add(callback.call(thisArg, word, index, this));