data-structure-typed 1.54.2 → 2.0.0

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 (213) hide show
  1. package/CHANGELOG.md +1 -1
  2. package/LICENSE +2 -2
  3. package/README.md +14 -1
  4. package/README_zh-CN.md +1 -1
  5. package/benchmark/report.html +28 -1
  6. package/benchmark/report.json +327 -18
  7. package/dist/cjs/data-structures/base/iterable-element-base.d.ts +14 -40
  8. package/dist/cjs/data-structures/base/iterable-element-base.js +14 -11
  9. package/dist/cjs/data-structures/base/iterable-element-base.js.map +1 -1
  10. package/dist/cjs/data-structures/base/linear-base.d.ts +277 -0
  11. package/dist/cjs/data-structures/base/linear-base.js +553 -0
  12. package/dist/cjs/data-structures/base/linear-base.js.map +1 -0
  13. package/dist/cjs/data-structures/binary-tree/avl-tree-counter.d.ts +21 -20
  14. package/dist/cjs/data-structures/binary-tree/avl-tree-counter.js +8 -7
  15. package/dist/cjs/data-structures/binary-tree/avl-tree-counter.js.map +1 -1
  16. package/dist/cjs/data-structures/binary-tree/avl-tree-multi-map.d.ts +23 -19
  17. package/dist/cjs/data-structures/binary-tree/avl-tree-multi-map.js +51 -38
  18. package/dist/cjs/data-structures/binary-tree/avl-tree-multi-map.js.map +1 -1
  19. package/dist/cjs/data-structures/binary-tree/avl-tree.d.ts +89 -21
  20. package/dist/cjs/data-structures/binary-tree/avl-tree.js +76 -8
  21. package/dist/cjs/data-structures/binary-tree/avl-tree.js.map +1 -1
  22. package/dist/cjs/data-structures/binary-tree/binary-tree.d.ts +173 -225
  23. package/dist/cjs/data-structures/binary-tree/binary-tree.js +244 -149
  24. package/dist/cjs/data-structures/binary-tree/binary-tree.js.map +1 -1
  25. package/dist/cjs/data-structures/binary-tree/bst.d.ts +62 -56
  26. package/dist/cjs/data-structures/binary-tree/bst.js +89 -133
  27. package/dist/cjs/data-structures/binary-tree/bst.js.map +1 -1
  28. package/dist/cjs/data-structures/binary-tree/red-black-tree.d.ts +19 -25
  29. package/dist/cjs/data-structures/binary-tree/red-black-tree.js +7 -13
  30. package/dist/cjs/data-structures/binary-tree/red-black-tree.js.map +1 -1
  31. package/dist/cjs/data-structures/binary-tree/tree-counter.d.ts +19 -19
  32. package/dist/cjs/data-structures/binary-tree/tree-counter.js +12 -12
  33. package/dist/cjs/data-structures/binary-tree/tree-counter.js.map +1 -1
  34. package/dist/cjs/data-structures/binary-tree/tree-multi-map.d.ts +186 -25
  35. package/dist/cjs/data-structures/binary-tree/tree-multi-map.js +211 -41
  36. package/dist/cjs/data-structures/binary-tree/tree-multi-map.js.map +1 -1
  37. package/dist/cjs/data-structures/graph/abstract-graph.js +2 -2
  38. package/dist/cjs/data-structures/graph/abstract-graph.js.map +1 -1
  39. package/dist/cjs/data-structures/heap/heap.d.ts +3 -11
  40. package/dist/cjs/data-structures/heap/heap.js +0 -10
  41. package/dist/cjs/data-structures/heap/heap.js.map +1 -1
  42. package/dist/cjs/data-structures/heap/max-heap.d.ts +2 -2
  43. package/dist/cjs/data-structures/heap/max-heap.js.map +1 -1
  44. package/dist/cjs/data-structures/heap/min-heap.d.ts +2 -2
  45. package/dist/cjs/data-structures/heap/min-heap.js.map +1 -1
  46. package/dist/cjs/data-structures/linked-list/doubly-linked-list.d.ts +65 -94
  47. package/dist/cjs/data-structures/linked-list/doubly-linked-list.js +131 -146
  48. package/dist/cjs/data-structures/linked-list/doubly-linked-list.js.map +1 -1
  49. package/dist/cjs/data-structures/linked-list/singly-linked-list.d.ts +79 -75
  50. package/dist/cjs/data-structures/linked-list/singly-linked-list.js +217 -169
  51. package/dist/cjs/data-structures/linked-list/singly-linked-list.js.map +1 -1
  52. package/dist/cjs/data-structures/priority-queue/max-priority-queue.d.ts +2 -2
  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 +2 -2
  55. package/dist/cjs/data-structures/priority-queue/min-priority-queue.js.map +1 -1
  56. package/dist/cjs/data-structures/priority-queue/priority-queue.d.ts +2 -2
  57. package/dist/cjs/data-structures/priority-queue/priority-queue.js.map +1 -1
  58. package/dist/cjs/data-structures/queue/deque.d.ts +130 -91
  59. package/dist/cjs/data-structures/queue/deque.js +269 -169
  60. package/dist/cjs/data-structures/queue/deque.js.map +1 -1
  61. package/dist/cjs/data-structures/queue/queue.d.ts +84 -40
  62. package/dist/cjs/data-structures/queue/queue.js +134 -50
  63. package/dist/cjs/data-structures/queue/queue.js.map +1 -1
  64. package/dist/cjs/data-structures/stack/stack.d.ts +3 -11
  65. package/dist/cjs/data-structures/stack/stack.js +0 -10
  66. package/dist/cjs/data-structures/stack/stack.js.map +1 -1
  67. package/dist/cjs/data-structures/trie/trie.d.ts +4 -3
  68. package/dist/cjs/data-structures/trie/trie.js +3 -0
  69. package/dist/cjs/data-structures/trie/trie.js.map +1 -1
  70. package/dist/cjs/types/data-structures/base/base.d.ts +9 -4
  71. package/dist/cjs/types/data-structures/binary-tree/avl-tree-multi-map.d.ts +1 -1
  72. package/dist/cjs/types/data-structures/binary-tree/binary-tree.d.ts +1 -0
  73. package/dist/cjs/types/data-structures/binary-tree/bst.d.ts +1 -1
  74. package/dist/cjs/types/data-structures/binary-tree/tree-multi-map.d.ts +1 -1
  75. package/dist/cjs/types/data-structures/linked-list/doubly-linked-list.d.ts +2 -2
  76. package/dist/cjs/types/data-structures/linked-list/singly-linked-list.d.ts +2 -2
  77. package/dist/cjs/types/data-structures/queue/deque.d.ts +2 -3
  78. package/dist/cjs/types/data-structures/queue/queue.d.ts +2 -2
  79. package/dist/cjs/utils/utils.d.ts +2 -2
  80. package/dist/esm/data-structures/base/iterable-element-base.d.ts +14 -40
  81. package/dist/esm/data-structures/base/iterable-element-base.js +14 -11
  82. package/dist/esm/data-structures/base/iterable-element-base.js.map +1 -1
  83. package/dist/esm/data-structures/base/linear-base.d.ts +277 -0
  84. package/dist/esm/data-structures/base/linear-base.js +549 -0
  85. package/dist/esm/data-structures/base/linear-base.js.map +1 -0
  86. package/dist/esm/data-structures/binary-tree/avl-tree-counter.d.ts +21 -20
  87. package/dist/esm/data-structures/binary-tree/avl-tree-counter.js +9 -8
  88. package/dist/esm/data-structures/binary-tree/avl-tree-counter.js.map +1 -1
  89. package/dist/esm/data-structures/binary-tree/avl-tree-multi-map.d.ts +23 -19
  90. package/dist/esm/data-structures/binary-tree/avl-tree-multi-map.js +52 -38
  91. package/dist/esm/data-structures/binary-tree/avl-tree-multi-map.js.map +1 -1
  92. package/dist/esm/data-structures/binary-tree/avl-tree.d.ts +89 -21
  93. package/dist/esm/data-structures/binary-tree/avl-tree.js +77 -9
  94. package/dist/esm/data-structures/binary-tree/avl-tree.js.map +1 -1
  95. package/dist/esm/data-structures/binary-tree/binary-tree.d.ts +173 -225
  96. package/dist/esm/data-structures/binary-tree/binary-tree.js +248 -153
  97. package/dist/esm/data-structures/binary-tree/binary-tree.js.map +1 -1
  98. package/dist/esm/data-structures/binary-tree/bst.d.ts +62 -56
  99. package/dist/esm/data-structures/binary-tree/bst.js +90 -132
  100. package/dist/esm/data-structures/binary-tree/bst.js.map +1 -1
  101. package/dist/esm/data-structures/binary-tree/red-black-tree.d.ts +19 -25
  102. package/dist/esm/data-structures/binary-tree/red-black-tree.js +8 -14
  103. package/dist/esm/data-structures/binary-tree/red-black-tree.js.map +1 -1
  104. package/dist/esm/data-structures/binary-tree/tree-counter.d.ts +19 -19
  105. package/dist/esm/data-structures/binary-tree/tree-counter.js +13 -13
  106. package/dist/esm/data-structures/binary-tree/tree-counter.js.map +1 -1
  107. package/dist/esm/data-structures/binary-tree/tree-multi-map.d.ts +186 -25
  108. package/dist/esm/data-structures/binary-tree/tree-multi-map.js +212 -41
  109. package/dist/esm/data-structures/binary-tree/tree-multi-map.js.map +1 -1
  110. package/dist/esm/data-structures/graph/abstract-graph.js +2 -2
  111. package/dist/esm/data-structures/graph/abstract-graph.js.map +1 -1
  112. package/dist/esm/data-structures/heap/heap.d.ts +3 -11
  113. package/dist/esm/data-structures/heap/heap.js +0 -10
  114. package/dist/esm/data-structures/heap/heap.js.map +1 -1
  115. package/dist/esm/data-structures/heap/max-heap.d.ts +2 -2
  116. package/dist/esm/data-structures/heap/max-heap.js.map +1 -1
  117. package/dist/esm/data-structures/heap/min-heap.d.ts +2 -2
  118. package/dist/esm/data-structures/heap/min-heap.js.map +1 -1
  119. package/dist/esm/data-structures/linked-list/doubly-linked-list.d.ts +65 -94
  120. package/dist/esm/data-structures/linked-list/doubly-linked-list.js +132 -148
  121. package/dist/esm/data-structures/linked-list/doubly-linked-list.js.map +1 -1
  122. package/dist/esm/data-structures/linked-list/singly-linked-list.d.ts +79 -75
  123. package/dist/esm/data-structures/linked-list/singly-linked-list.js +217 -170
  124. package/dist/esm/data-structures/linked-list/singly-linked-list.js.map +1 -1
  125. package/dist/esm/data-structures/priority-queue/max-priority-queue.d.ts +2 -2
  126. package/dist/esm/data-structures/priority-queue/max-priority-queue.js.map +1 -1
  127. package/dist/esm/data-structures/priority-queue/min-priority-queue.d.ts +2 -2
  128. package/dist/esm/data-structures/priority-queue/min-priority-queue.js.map +1 -1
  129. package/dist/esm/data-structures/priority-queue/priority-queue.d.ts +2 -2
  130. package/dist/esm/data-structures/priority-queue/priority-queue.js.map +1 -1
  131. package/dist/esm/data-structures/queue/deque.d.ts +130 -91
  132. package/dist/esm/data-structures/queue/deque.js +269 -169
  133. package/dist/esm/data-structures/queue/deque.js.map +1 -1
  134. package/dist/esm/data-structures/queue/queue.d.ts +84 -40
  135. package/dist/esm/data-structures/queue/queue.js +135 -51
  136. package/dist/esm/data-structures/queue/queue.js.map +1 -1
  137. package/dist/esm/data-structures/stack/stack.d.ts +3 -11
  138. package/dist/esm/data-structures/stack/stack.js +0 -10
  139. package/dist/esm/data-structures/stack/stack.js.map +1 -1
  140. package/dist/esm/data-structures/trie/trie.d.ts +4 -3
  141. package/dist/esm/data-structures/trie/trie.js +3 -0
  142. package/dist/esm/data-structures/trie/trie.js.map +1 -1
  143. package/dist/esm/types/data-structures/base/base.d.ts +9 -4
  144. package/dist/esm/types/data-structures/binary-tree/avl-tree-multi-map.d.ts +1 -1
  145. package/dist/esm/types/data-structures/binary-tree/binary-tree.d.ts +1 -0
  146. package/dist/esm/types/data-structures/binary-tree/bst.d.ts +1 -1
  147. package/dist/esm/types/data-structures/binary-tree/tree-multi-map.d.ts +1 -1
  148. package/dist/esm/types/data-structures/linked-list/doubly-linked-list.d.ts +2 -2
  149. package/dist/esm/types/data-structures/linked-list/singly-linked-list.d.ts +2 -2
  150. package/dist/esm/types/data-structures/queue/deque.d.ts +2 -3
  151. package/dist/esm/types/data-structures/queue/queue.d.ts +2 -2
  152. package/dist/esm/utils/utils.d.ts +2 -2
  153. package/dist/umd/data-structure-typed.js +1548 -920
  154. package/dist/umd/data-structure-typed.min.js +5 -12
  155. package/dist/umd/data-structure-typed.min.js.map +1 -1
  156. package/package.json +7 -7
  157. package/src/data-structures/base/iterable-element-base.ts +29 -20
  158. package/src/data-structures/base/linear-base.ts +649 -0
  159. package/src/data-structures/binary-tree/avl-tree-counter.ts +30 -23
  160. package/src/data-structures/binary-tree/avl-tree-multi-map.ts +74 -49
  161. package/src/data-structures/binary-tree/avl-tree.ts +99 -29
  162. package/src/data-structures/binary-tree/binary-tree.ts +474 -257
  163. package/src/data-structures/binary-tree/bst.ts +150 -152
  164. package/src/data-structures/binary-tree/red-black-tree.ts +27 -35
  165. package/src/data-structures/binary-tree/tree-counter.ts +33 -27
  166. package/src/data-structures/binary-tree/tree-multi-map.ts +235 -53
  167. package/src/data-structures/graph/abstract-graph.ts +2 -2
  168. package/src/data-structures/heap/heap.ts +3 -14
  169. package/src/data-structures/heap/max-heap.ts +2 -2
  170. package/src/data-structures/heap/min-heap.ts +2 -2
  171. package/src/data-structures/linked-list/doubly-linked-list.ts +144 -160
  172. package/src/data-structures/linked-list/singly-linked-list.ts +241 -185
  173. package/src/data-structures/priority-queue/max-priority-queue.ts +2 -5
  174. package/src/data-structures/priority-queue/min-priority-queue.ts +2 -5
  175. package/src/data-structures/priority-queue/priority-queue.ts +2 -2
  176. package/src/data-structures/queue/deque.ts +286 -183
  177. package/src/data-structures/queue/queue.ts +149 -63
  178. package/src/data-structures/stack/stack.ts +3 -18
  179. package/src/data-structures/trie/trie.ts +7 -3
  180. package/src/types/data-structures/base/base.ts +17 -8
  181. package/src/types/data-structures/binary-tree/avl-tree-multi-map.ts +1 -1
  182. package/src/types/data-structures/binary-tree/binary-tree.ts +1 -0
  183. package/src/types/data-structures/binary-tree/bst.ts +1 -1
  184. package/src/types/data-structures/binary-tree/tree-multi-map.ts +1 -1
  185. package/src/types/data-structures/linked-list/doubly-linked-list.ts +2 -2
  186. package/src/types/data-structures/linked-list/singly-linked-list.ts +2 -2
  187. package/src/types/data-structures/queue/deque.ts +2 -3
  188. package/src/types/data-structures/queue/queue.ts +2 -2
  189. package/src/utils/utils.ts +2 -2
  190. package/test/integration/all-in-one.test.ts +1 -1
  191. package/test/integration/avl-tree.test.ts +1 -1
  192. package/test/integration/bst.test.ts +2 -2
  193. package/test/integration/compile.mjs +21 -21
  194. package/test/performance/data-structures/binary-tree/avl-tree.test.mjs +71 -0
  195. package/test/performance/data-structures/binary-tree/red-black-tree.test.mjs +81 -0
  196. package/test/performance/{reportor.js → reportor.mjs} +264 -8
  197. package/test/performance/reportor.ts +1 -1
  198. package/test/unit/data-structures/binary-tree/avl-tree-counter.test.ts +7 -7
  199. package/test/unit/data-structures/binary-tree/avl-tree-multi-map.test.ts +172 -5
  200. package/test/unit/data-structures/binary-tree/avl-tree.test.ts +72 -4
  201. package/test/unit/data-structures/binary-tree/binary-tree.test.ts +132 -82
  202. package/test/unit/data-structures/binary-tree/bst.test.ts +12 -12
  203. package/test/unit/data-structures/binary-tree/red-black-tree.test.ts +5 -13
  204. package/test/unit/data-structures/binary-tree/tree-counter.test.ts +4 -4
  205. package/test/unit/data-structures/binary-tree/tree-multi-map.test.ts +168 -10
  206. package/test/unit/data-structures/linked-list/doubly-linked-list.test.ts +135 -27
  207. package/test/unit/data-structures/linked-list/singly-linked-list.test.ts +111 -11
  208. package/test/unit/data-structures/queue/deque.test.ts +241 -60
  209. package/test/unit/data-structures/queue/queue.test.ts +118 -19
  210. package/test/unit/unrestricted-interconversion.test.ts +1 -1
  211. package/test/utils/json2html.ts +0 -154
  212. package/test/performance/data-structures/binary-tree/avl-tree.test.js +0 -45
  213. /package/test/performance/data-structures/binary-tree/{rb-tree.test.ts → red-black-tree.test.ts} +0 -0
@@ -422,13 +422,6 @@ var dataStructureTyped = (() => {
422
422
  else if (toElementFn) throw new TypeError("toElementFn must be a function type");
423
423
  }
424
424
  }
425
- /**
426
- * The function returns the _toElementFn property, which is a function that converts a raw element to
427
- * a specific type.
428
- * @returns The function `get toElementFn()` is returning either a function that takes a raw element
429
- * `rawElement` of type `R` and returns an element `E`, or `undefined` if no function is assigned to
430
- * `_toElementFn`.
431
- */
432
425
  get toElementFn() {
433
426
  return this._toElementFn;
434
427
  }
@@ -526,7 +519,7 @@ var dataStructureTyped = (() => {
526
519
  *
527
520
  * The `find` function iterates over the elements of an array-like object and returns the first
528
521
  * element that satisfies the provided callback function.
529
- * @param callbackfn - The callbackfn parameter is a function that will be called for each element in
522
+ * @param predicate - The predicate parameter is a function that will be called for each element in
530
523
  * the array. It takes three arguments: the current element being processed, the index of the current
531
524
  * element, and the array itself. The function should return a boolean value indicating whether the
532
525
  * current element matches the desired condition.
@@ -536,10 +529,10 @@ var dataStructureTyped = (() => {
536
529
  * @returns The `find` method returns the first element in the array that satisfies the provided
537
530
  * callback function. If no element satisfies the callback function, `undefined` is returned.
538
531
  */
539
- find(callbackfn, thisArg) {
532
+ find(predicate, thisArg) {
540
533
  let index = 0;
541
534
  for (const item of this) {
542
- if (callbackfn.call(thisArg, item, index++, this)) return item;
535
+ if (predicate.call(thisArg, item, index++, this)) return item;
543
536
  }
544
537
  return;
545
538
  }
@@ -573,13 +566,23 @@ var dataStructureTyped = (() => {
573
566
  * all the elements in the array and applying the callback function to each element.
574
567
  */
575
568
  reduce(callbackfn, initialValue) {
576
- let accumulator = initialValue;
569
+ let accumulator = initialValue != null ? initialValue : 0;
577
570
  let index = 0;
578
571
  for (const item of this) {
579
572
  accumulator = callbackfn(accumulator, item, index++, this);
580
573
  }
581
574
  return accumulator;
582
575
  }
576
+ /**
577
+ * Time Complexity: O(n)
578
+ * Space Complexity: O(n)
579
+ *
580
+ * The `toArray` function converts a linked list into an array.
581
+ * @returns The `toArray()` method is returning an array of type `E[]`.
582
+ */
583
+ toArray() {
584
+ return [...this];
585
+ }
583
586
  /**
584
587
  * Time Complexity: O(n)
585
588
  * Space Complexity: O(n)
@@ -1500,97 +1503,566 @@ var dataStructureTyped = (() => {
1500
1503
  }
1501
1504
  };
1502
1505
 
1503
- // src/data-structures/linked-list/singly-linked-list.ts
1504
- var SinglyLinkedListNode = class {
1505
- /**
1506
- * The constructor function initializes an instance of a class with a given value and sets the next property to undefined.
1507
- * @param {E} value - The "value" parameter is of type E, which means it can be any data type. It represents the value that
1508
- * will be stored in the node of a linked list.
1509
- */
1506
+ // src/data-structures/base/linear-base.ts
1507
+ var LinkedListNode = class {
1510
1508
  constructor(value) {
1511
1509
  __publicField(this, "_value");
1512
1510
  __publicField(this, "_next");
1513
1511
  this._value = value;
1514
1512
  this._next = void 0;
1515
1513
  }
1516
- /**
1517
- * The function returns the value of a protected variable.
1518
- * @returns The value of the variable `_value` is being returned.
1519
- */
1520
1514
  get value() {
1521
1515
  return this._value;
1522
1516
  }
1523
- /**
1524
- * The above function sets the value of a variable.
1525
- * @param {E} value - The parameter "value" is of type E, which means it can be any type.
1526
- */
1527
1517
  set value(value) {
1528
1518
  this._value = value;
1529
1519
  }
1530
- /**
1531
- * The `next` function returns the next node in a singly linked list.
1532
- * @returns The `next` property is being returned. It can be either a `SinglyLinkedListNode<E>`
1533
- * object or `undefined`.
1534
- */
1535
1520
  get next() {
1536
1521
  return this._next;
1537
1522
  }
1523
+ set next(value) {
1524
+ this._next = value;
1525
+ }
1526
+ };
1527
+ var LinearBase = class _LinearBase extends IterableElementBase {
1528
+ /**
1529
+ * The constructor initializes the LinearBase class with optional options, setting the maximum length
1530
+ * if provided.
1531
+ * @param [options] - The `options` parameter is an optional object that can be passed to the
1532
+ * constructor. It is of type `LinearBaseOptions<E, R>`. The constructor checks if the `options`
1533
+ * object is provided and then extracts the `maxLen` property from it. If `maxLen` is a
1534
+ */
1535
+ constructor(options) {
1536
+ super(options);
1537
+ __publicField(this, "_maxLen", -1);
1538
+ if (options) {
1539
+ const { maxLen } = options;
1540
+ if (typeof maxLen === "number" && maxLen > 0 && maxLen % 1 === 0) this._maxLen = maxLen;
1541
+ }
1542
+ }
1543
+ get maxLen() {
1544
+ return this._maxLen;
1545
+ }
1546
+ /**
1547
+ * Time Complexity: O(n)
1548
+ * Space Complexity: O(1)
1549
+ *
1550
+ * The function indexOf searches for a specified element starting from a given index in an array-like
1551
+ * object and returns the index of the first occurrence, or -1 if not found.
1552
+ * @param {E} searchElement - The `searchElement` parameter in the `indexOf` function represents the
1553
+ * element that you want to find within the array. The function will search for this element starting
1554
+ * from the `fromIndex` (if provided) up to the end of the array. If the `searchElement` is found
1555
+ * within the
1556
+ * @param {number} [fromIndex=0] - The `fromIndex` parameter in the `indexOf` function represents the
1557
+ * index at which to start searching for the `searchElement` within the array. If provided, the
1558
+ * search will begin at this index and continue to the end of the array. If `fromIndex` is not
1559
+ * specified, the default
1560
+ * @returns The `indexOf` method is returning the index of the `searchElement` if it is found in the
1561
+ * array starting from the `fromIndex`. If the `searchElement` is not found, it returns -1.
1562
+ */
1563
+ indexOf(searchElement, fromIndex = 0) {
1564
+ if (this.length === 0) return -1;
1565
+ if (fromIndex < 0) fromIndex = this.length + fromIndex;
1566
+ if (fromIndex < 0) fromIndex = 0;
1567
+ for (let i = fromIndex; i < this.length; i++) {
1568
+ const element = this.at(i);
1569
+ if (element === searchElement) return i;
1570
+ }
1571
+ return -1;
1572
+ }
1573
+ /**
1574
+ * Time Complexity: O(n)
1575
+ * Space Complexity: O(1)
1576
+ *
1577
+ * The function `lastIndexOf` in TypeScript returns the index of the last occurrence of a specified
1578
+ * element in an array.
1579
+ * @param {E} searchElement - The `searchElement` parameter is the element that you want to find the
1580
+ * last index of within the array. The `lastIndexOf` method will search the array starting from the
1581
+ * `fromIndex` (or the end of the array if not specified) and return the index of the last occurrence
1582
+ * of the
1583
+ * @param {number} fromIndex - The `fromIndex` parameter in the `lastIndexOf` method specifies the
1584
+ * index at which to start searching for the `searchElement` in the array. By default, it starts
1585
+ * searching from the last element of the array (`this.length - 1`). If a specific `fromIndex` is
1586
+ * provided
1587
+ * @returns The last index of the `searchElement` in the array is being returned. If the
1588
+ * `searchElement` is not found in the array, -1 is returned.
1589
+ */
1590
+ lastIndexOf(searchElement, fromIndex = this.length - 1) {
1591
+ if (this.length === 0) return -1;
1592
+ if (fromIndex >= this.length) fromIndex = this.length - 1;
1593
+ if (fromIndex < 0) fromIndex = this.length + fromIndex;
1594
+ for (let i = fromIndex; i >= 0; i--) {
1595
+ const element = this.at(i);
1596
+ if (element === searchElement) return i;
1597
+ }
1598
+ return -1;
1599
+ }
1600
+ /**
1601
+ * Time Complexity: O(n)
1602
+ * Space Complexity: O(1)
1603
+ *
1604
+ * The `findIndex` function iterates over an array and returns the index of the first element that
1605
+ * satisfies the provided predicate function.
1606
+ * @param predicate - The `predicate` parameter in the `findIndex` function is a callback function
1607
+ * that takes three arguments: `item`, `index`, and the array `this`. It should return a boolean
1608
+ * value indicating whether the current element satisfies the condition being checked for.
1609
+ * @param {any} [thisArg] - The `thisArg` parameter in the `findIndex` function is an optional
1610
+ * parameter that specifies the value to use as `this` when executing the `predicate` function. If
1611
+ * provided, the `predicate` function will be called with `thisArg` as its `this` value. If `
1612
+ * @returns The `findIndex` method is returning the index of the first element in the array that
1613
+ * satisfies the provided predicate function. If no such element is found, it returns -1.
1614
+ */
1615
+ findIndex(predicate, thisArg) {
1616
+ for (let i = 0; i < this.length; i++) {
1617
+ const item = this.at(i);
1618
+ if (item !== void 0 && predicate.call(thisArg, item, i, this)) return i;
1619
+ }
1620
+ return -1;
1621
+ }
1622
+ /**
1623
+ * Time Complexity: O(n + m)
1624
+ * Space Complexity: O(n + m)
1625
+ *
1626
+ * The `concat` function in TypeScript concatenates multiple items into a new list, handling both
1627
+ * individual elements and instances of `LinearBase`.
1628
+ * @param {(E | this)[]} items - The `concat` method takes in an array of items, where
1629
+ * each item can be either of type `E` or an instance of `LinearBase<E, R>`.
1630
+ * @returns The `concat` method is returning a new instance of the class that it belongs to, with the
1631
+ * items passed as arguments concatenated to it.
1632
+ */
1633
+ concat(...items) {
1634
+ const newList = this.clone();
1635
+ for (const item of items) {
1636
+ if (item instanceof _LinearBase) {
1637
+ newList.pushMany(item);
1638
+ } else {
1639
+ newList.push(item);
1640
+ }
1641
+ }
1642
+ return newList;
1643
+ }
1644
+ /**
1645
+ * Time Complexity: O(n log n)
1646
+ * Space Complexity: O(n)
1647
+ *
1648
+ * The `sort` function in TypeScript sorts the elements of a collection using a specified comparison
1649
+ * function.
1650
+ * @param [compareFn] - The `compareFn` parameter is a function that defines the sort order. It takes
1651
+ * two elements `a` and `b` as input and returns a number indicating their relative order. If the
1652
+ * returned value is negative, `a` comes before `b`. If the returned value is positive, `
1653
+ * @returns The `sort` method is returning the instance of the object on which it is called (this),
1654
+ * after sorting the elements based on the provided comparison function (compareFn).
1655
+ */
1656
+ sort(compareFn) {
1657
+ const arr = this.toArray();
1658
+ arr.sort(compareFn);
1659
+ this.clear();
1660
+ for (const item of arr) this.push(item);
1661
+ return this;
1662
+ }
1663
+ /**
1664
+ * Time Complexity: O(n + m)
1665
+ * Space Complexity: O(m)
1666
+ *
1667
+ * The `splice` function in TypeScript removes elements from an array and optionally inserts new
1668
+ * elements at the specified index.
1669
+ * @param {number} start - The `start` parameter in the `splice` method indicates the index at which
1670
+ * to start modifying the array. If `start` is a negative number, it will count from the end of the
1671
+ * array.
1672
+ * @param {number} [deleteCount=0] - The `deleteCount` parameter in the `splice` method specifies the
1673
+ * number of elements to remove from the array starting at the specified `start` index. If
1674
+ * `deleteCount` is not provided or is 0, no elements are removed, and only new elements are inserted
1675
+ * at the `start`
1676
+ * @param {E[]} items - The `items` parameter in the `splice` method represents the elements that
1677
+ * will be inserted into the array at the specified `start` index. These elements can be of any type
1678
+ * and you can pass multiple elements separated by commas. The `splice` method will insert these
1679
+ * items into the array at the
1680
+ * @returns The `splice` method returns a list of elements that were removed from the original list
1681
+ * during the operation.
1682
+ */
1683
+ splice(start, deleteCount = 0, ...items) {
1684
+ const removedList = this._createInstance();
1685
+ start = start < 0 ? this.length + start : start;
1686
+ start = Math.max(0, Math.min(start, this.length));
1687
+ deleteCount = Math.max(0, Math.min(deleteCount, this.length - start));
1688
+ for (let i = 0; i < deleteCount; i++) {
1689
+ const removed = this.deleteAt(start);
1690
+ if (removed !== void 0) {
1691
+ removedList.push(removed);
1692
+ }
1693
+ }
1694
+ for (let i = 0; i < items.length; i++) {
1695
+ this.addAt(start + i, items[i]);
1696
+ }
1697
+ return removedList;
1698
+ }
1699
+ /**
1700
+ * Time Complexity: O(n)
1701
+ * Space Complexity: O(1)
1702
+ *
1703
+ * The `join` function in TypeScript returns a string by joining the elements of an array with a
1704
+ * specified separator.
1705
+ * @param {string} [separator=,] - The `separator` parameter is a string that specifies the character
1706
+ * or characters that will be used to separate each element when joining them into a single string.
1707
+ * By default, the separator is set to a comma (`,`), but you can provide a different separator if
1708
+ * needed.
1709
+ * @returns The `join` method is being returned, which takes an optional `separator` parameter
1710
+ * (defaulting to a comma) and returns a string created by joining all elements of the array after
1711
+ * converting it to an array.
1712
+ */
1713
+ join(separator = ",") {
1714
+ return this.toArray().join(separator);
1715
+ }
1716
+ /**
1717
+ * Time Complexity: O(n)
1718
+ * Space Complexity: O(n)
1719
+ *
1720
+ * The function `toReversedArray` takes an array and returns a new array with its elements in reverse
1721
+ * order.
1722
+ * @returns The `toReversedArray()` function returns an array of elements of type `E` in reverse
1723
+ * order.
1724
+ */
1725
+ toReversedArray() {
1726
+ const array = [];
1727
+ for (let i = this.length - 1; i >= 0; i--) {
1728
+ array.push(this.at(i));
1729
+ }
1730
+ return array;
1731
+ }
1732
+ /**
1733
+ * Time Complexity: O(n)
1734
+ * Space Complexity: O(1)
1735
+ *
1736
+ * The `reduceRight` function in TypeScript iterates over an array from right to left and applies a
1737
+ * callback function to each element, accumulating a single result.
1738
+ * @param callbackfn - The `callbackfn` parameter in the `reduceRight` method is a function that will
1739
+ * be called on each element in the array from right to left. It takes four arguments:
1740
+ * @param {U} [initialValue] - The `initialValue` parameter in the `reduceRight` method is an
1741
+ * optional parameter that specifies the initial value of the accumulator. If provided, the
1742
+ * `accumulator` will start with this initial value before iterating over the elements of the array.
1743
+ * If `initialValue` is not provided, the accumulator will
1744
+ * @returns The `reduceRight` method is returning the final accumulated value after applying the
1745
+ * callback function to each element in the array from right to left.
1746
+ */
1747
+ reduceRight(callbackfn, initialValue) {
1748
+ let accumulator = initialValue != null ? initialValue : 0;
1749
+ for (let i = this.length - 1; i >= 0; i--) {
1750
+ accumulator = callbackfn(accumulator, this.at(i), i, this);
1751
+ }
1752
+ return accumulator;
1753
+ }
1754
+ /**
1755
+ * Time Complexity: O(m)
1756
+ * Space Complexity: O(m)
1757
+ *
1758
+ * The `slice` function in TypeScript creates a new instance by extracting a portion of elements from
1759
+ * the original instance based on the specified start and end indices.
1760
+ * @param {number} [start=0] - The `start` parameter in the `slice` method represents the index at
1761
+ * which to begin extracting elements from an array-like object. If no `start` parameter is provided,
1762
+ * the default value is 0, meaning the extraction will start from the beginning of the array.
1763
+ * @param {number} end - The `end` parameter in the `slice` method represents the index at which to
1764
+ * end the slicing. By default, if no `end` parameter is provided, it will slice until the end of the
1765
+ * array (i.e., `this.length`).
1766
+ * @returns The `slice` method is returning a new instance of the object with elements sliced from
1767
+ * the specified start index (default is 0) to the specified end index (default is the length of the
1768
+ * object).
1769
+ */
1770
+ slice(start = 0, end = this.length) {
1771
+ start = start < 0 ? this.length + start : start;
1772
+ end = end < 0 ? this.length + end : end;
1773
+ const newList = this._createInstance();
1774
+ for (let i = start; i < end; i++) {
1775
+ newList.push(this.at(i));
1776
+ }
1777
+ return newList;
1778
+ }
1779
+ /**
1780
+ * Time Complexity: O(n)
1781
+ * Space Complexity: O(1)
1782
+ *
1783
+ * The `fill` function in TypeScript fills a specified range in an array-like object with a given
1784
+ * value.
1785
+ * @param {E} value - The `value` parameter in the `fill` method represents the element that will be
1786
+ * used to fill the specified range in the array.
1787
+ * @param [start=0] - The `start` parameter specifies the index at which to start filling the array
1788
+ * with the specified value. If not provided, it defaults to 0, indicating the beginning of the
1789
+ * array.
1790
+ * @param end - The `end` parameter in the `fill` function represents the index at which the filling
1791
+ * of values should stop. It specifies the end of the range within the array where the `value` should
1792
+ * be filled.
1793
+ * @returns The `fill` method is returning the modified object (`this`) after filling the specified
1794
+ * range with the provided value.
1795
+ */
1796
+ fill(value, start = 0, end = this.length) {
1797
+ start = start < 0 ? this.length + start : start;
1798
+ end = end < 0 ? this.length + end : end;
1799
+ if (start < 0) start = 0;
1800
+ if (end > this.length) end = this.length;
1801
+ if (start >= end) return this;
1802
+ for (let i = start; i < end; i++) {
1803
+ this.setAt(i, value);
1804
+ }
1805
+ return this;
1806
+ }
1807
+ };
1808
+ var LinearLinkedBase = class extends LinearBase {
1809
+ /**
1810
+ * The constructor initializes the LinearBase class with optional options, setting the maximum length
1811
+ * if provided and valid.
1812
+ * @param [options] - The `options` parameter is an optional object that can be passed to the
1813
+ * constructor. It is of type `LinearBaseOptions<E, R>`. This object may contain properties such as
1814
+ * `maxLen`, which is a number representing the maximum length. If `maxLen` is a positive integer,
1815
+ */
1816
+ constructor(options) {
1817
+ super(options);
1818
+ if (options) {
1819
+ const { maxLen } = options;
1820
+ if (typeof maxLen === "number" && maxLen > 0 && maxLen % 1 === 0) this._maxLen = maxLen;
1821
+ }
1822
+ }
1823
+ /**
1824
+ * Time Complexity: O(n)
1825
+ * Space Complexity: O(1)
1826
+ *
1827
+ * The function overrides the indexOf method to improve performance by searching for an element in a
1828
+ * custom array implementation starting from a specified index.
1829
+ * @param {E} searchElement - The `searchElement` parameter is the element that you are searching for
1830
+ * within the array. The `indexOf` method will return the index of the first occurrence of this
1831
+ * element within the array.
1832
+ * @param {number} [fromIndex=0] - The `fromIndex` parameter in the `indexOf` method specifies the
1833
+ * index in the array at which to start the search for the `searchElement`. If provided, the search
1834
+ * will begin at the specified index and continue to the end of the array. If not provided, the
1835
+ * search will start at index
1836
+ * @returns The `indexOf` method is returning the index of the `searchElement` if it is found in the
1837
+ * array starting from the `fromIndex`. If the `searchElement` is not found, it returns -1.
1838
+ */
1839
+ indexOf(searchElement, fromIndex = 0) {
1840
+ const iterator = this._getIterator();
1841
+ let current = iterator.next();
1842
+ let index = 0;
1843
+ while (index < fromIndex) {
1844
+ current = iterator.next();
1845
+ index++;
1846
+ }
1847
+ while (!current.done) {
1848
+ if (current.value === searchElement) return index;
1849
+ current = iterator.next();
1850
+ index++;
1851
+ }
1852
+ return -1;
1853
+ }
1854
+ /**
1855
+ * Time Complexity: O(n)
1856
+ * Space Complexity: O(1)
1857
+ *
1858
+ * The function overrides the lastIndexOf method in TypeScript to improve performance by searching
1859
+ * for an element in reverse order starting from a specified index.
1860
+ * @param {E} searchElement - The `searchElement` parameter is the element that you want to find
1861
+ * within the array. The `lastIndexOf` method searches the array for this element starting from the
1862
+ * end of the array (or from the specified `fromIndex` if provided) and returns the index of the last
1863
+ * occurrence of the element
1864
+ * @param {number} fromIndex - The `fromIndex` parameter in the `lastIndexOf` method specifies the
1865
+ * index at which to start searching for the `searchElement` in the array. If provided, the search
1866
+ * will begin at this index and move towards the beginning of the array. If not provided, the search
1867
+ * will start at the
1868
+ * @returns The `lastIndexOf` method is being overridden to search for the `searchElement` starting
1869
+ * from the specified `fromIndex` (defaulting to the end of the array). It iterates over the array in
1870
+ * reverse order using a custom iterator `_getReverseIterator` and returns the index of the last
1871
+ * occurrence of the `searchElement` if found, or -1 if not found.
1872
+ */
1873
+ lastIndexOf(searchElement, fromIndex = this.length - 1) {
1874
+ const iterator = this._getReverseIterator();
1875
+ let current = iterator.next();
1876
+ let index = this.length - 1;
1877
+ while (index > fromIndex) {
1878
+ current = iterator.next();
1879
+ index--;
1880
+ }
1881
+ while (!current.done) {
1882
+ if (current.value === searchElement) return index;
1883
+ current = iterator.next();
1884
+ index--;
1885
+ }
1886
+ return -1;
1887
+ }
1888
+ /**
1889
+ * Time Complexity: O(n + m)
1890
+ * Space Complexity: O(n + m)
1891
+ *
1892
+ * The `concat` function in TypeScript overrides the default behavior to concatenate items into a new
1893
+ * list, handling both individual elements and instances of `LinearBase`.
1894
+ * @param {(E | LinearBase<E, R>)[]} items - The `concat` method you provided takes in a variable
1895
+ * number of arguments of type `E` or `LinearBase<E, R>`. The method concatenates these items to the
1896
+ * current list and returns a new list with the concatenated items.
1897
+ * @returns The `concat` method is returning a new instance of the class that it belongs to, with the
1898
+ * items passed as arguments concatenated to it.
1899
+ */
1900
+ concat(...items) {
1901
+ const newList = this.clone();
1902
+ for (const item of items) {
1903
+ if (item instanceof LinearBase) {
1904
+ newList.pushMany(item);
1905
+ } else {
1906
+ newList.push(item);
1907
+ }
1908
+ }
1909
+ return newList;
1910
+ }
1911
+ /**
1912
+ * Time Complexity: O(m)
1913
+ * Space Complexity: O(m)
1914
+ *
1915
+ * The `slice` method is overridden to improve performance by creating a new instance and iterating
1916
+ * through the array to extract a subset based on the specified start and end indices.
1917
+ * @param {number} [start=0] - The `start` parameter in the `slice` method specifies the index at
1918
+ * which to begin extracting elements from the array. If no `start` parameter is provided, the
1919
+ * default value is 0, indicating that extraction should start from the beginning of the array.
1920
+ * @param {number} end - The `end` parameter in the `slice` method represents the index at which to
1921
+ * end the slicing of the array. If not provided, it defaults to the length of the array.
1922
+ * @returns The `slice` method is returning a new instance of the array implementation with elements
1923
+ * sliced from the original array based on the `start` and `end` parameters.
1924
+ */
1925
+ slice(start = 0, end = this.length) {
1926
+ start = start < 0 ? this.length + start : start;
1927
+ end = end < 0 ? this.length + end : end;
1928
+ const newList = this._createInstance();
1929
+ const iterator = this._getIterator();
1930
+ let current = iterator.next();
1931
+ let c = 0;
1932
+ while (c < start) {
1933
+ current = iterator.next();
1934
+ c++;
1935
+ }
1936
+ for (let i = start; i < end; i++) {
1937
+ newList.push(current.value);
1938
+ current = iterator.next();
1939
+ }
1940
+ return newList;
1941
+ }
1942
+ /**
1943
+ * Time Complexity: O(n + m)
1944
+ * Space Complexity: O(m)
1945
+ *
1946
+ * The function overrides the splice method to handle deletion and insertion of elements in a data
1947
+ * structure while returning the removed elements.
1948
+ * @param {number} start - The `start` parameter in the `splice` method indicates the index at which
1949
+ * to start modifying the array.
1950
+ * @param {number} [deleteCount=0] - The `deleteCount` parameter in the `splice` method specifies the
1951
+ * number of elements to remove from the array starting at the specified `start` index. If
1952
+ * `deleteCount` is not provided, it defaults to 0, meaning no elements will be removed but new
1953
+ * elements can still be inserted at
1954
+ * @param {E[]} items - The `items` parameter in the `splice` method represents the elements that
1955
+ * will be inserted into the array at the specified `start` index. These elements can be of any type
1956
+ * and there can be multiple elements passed as arguments to be inserted into the array.
1957
+ * @returns The `splice` method is returning a new instance of the data structure that was modified
1958
+ * by removing elements specified by the `start` and `deleteCount` parameters, and inserting new
1959
+ * elements provided in the `items` array.
1960
+ */
1961
+ splice(start, deleteCount = 0, ...items) {
1962
+ const removedList = this._createInstance();
1963
+ start = start < 0 ? this.length + start : start;
1964
+ start = Math.max(0, Math.min(start, this.length));
1965
+ deleteCount = Math.max(0, deleteCount);
1966
+ let currentIndex = 0;
1967
+ let currentNode = void 0;
1968
+ let previousNode = void 0;
1969
+ const iterator = this._getNodeIterator();
1970
+ for (const node of iterator) {
1971
+ if (currentIndex === start) {
1972
+ currentNode = node;
1973
+ break;
1974
+ }
1975
+ previousNode = node;
1976
+ currentIndex++;
1977
+ }
1978
+ for (let i = 0; i < deleteCount && currentNode; i++) {
1979
+ removedList.push(currentNode.value);
1980
+ const nextNode = currentNode.next;
1981
+ this.delete(currentNode);
1982
+ currentNode = nextNode;
1983
+ }
1984
+ for (let i = 0; i < items.length; i++) {
1985
+ if (previousNode) {
1986
+ this.addAfter(previousNode, items[i]);
1987
+ previousNode = previousNode.next;
1988
+ } else {
1989
+ this.addAt(0, items[i]);
1990
+ previousNode = this._getNodeIterator().next().value;
1991
+ }
1992
+ }
1993
+ return removedList;
1994
+ }
1538
1995
  /**
1539
- * The "next" property of a SinglyLinkedListNode is set to the provided value.
1540
- * @param {SinglyLinkedListNode<E> | undefined} value - The `value` parameter is of type
1541
- * `SinglyLinkedListNode<E> | undefined`. This means that it can accept either a
1542
- * `SinglyLinkedListNode` object or `undefined` as its value.
1996
+ * Time Complexity: O(n)
1997
+ * Space Complexity: O(1)
1998
+ *
1999
+ * The function `reduceRight` iterates over an array in reverse order and applies a callback function
2000
+ * to each element, accumulating a single result.
2001
+ * @param callbackfn - The `callbackfn` parameter is a function that will be called on each element
2002
+ * of the array from right to left. It takes four arguments:
2003
+ * @param {U} [initialValue] - The `initialValue` parameter is an optional value that is used as the
2004
+ * initial accumulator value in the reduce operation. If provided, the reduce operation starts with
2005
+ * this initial value and iterates over the elements of the array, applying the callback function to
2006
+ * each element and the current accumulator value. If `initial
2007
+ * @returns The `reduceRight` method is returning the final accumulated value after applying the
2008
+ * callback function to each element in the array from right to left.
1543
2009
  */
2010
+ reduceRight(callbackfn, initialValue) {
2011
+ let accumulator = initialValue != null ? initialValue : 0;
2012
+ let index = this.length - 1;
2013
+ for (const item of this._getReverseIterator()) {
2014
+ accumulator = callbackfn(accumulator, item, index--, this);
2015
+ }
2016
+ return accumulator;
2017
+ }
2018
+ };
2019
+
2020
+ // src/data-structures/linked-list/singly-linked-list.ts
2021
+ var SinglyLinkedListNode = class extends LinkedListNode {
2022
+ /**
2023
+ * The constructor function initializes an instance of a class with a given value and sets the next property to undefined.
2024
+ * @param {E} value - The "value" parameter is of type E, which means it can be any data type. It represents the value that
2025
+ * will be stored in the node of a linked list.
2026
+ */
2027
+ constructor(value) {
2028
+ super(value);
2029
+ __publicField(this, "_next");
2030
+ this._value = value;
2031
+ this._next = void 0;
2032
+ }
2033
+ get next() {
2034
+ return this._next;
2035
+ }
1544
2036
  set next(value) {
1545
2037
  this._next = value;
1546
2038
  }
1547
2039
  };
1548
- var SinglyLinkedList = class _SinglyLinkedList extends IterableElementBase {
2040
+ var SinglyLinkedList = class _SinglyLinkedList extends LinearLinkedBase {
1549
2041
  constructor(elements = [], options) {
1550
2042
  super(options);
1551
2043
  __publicField(this, "_head");
1552
2044
  __publicField(this, "_tail");
1553
- __publicField(this, "_size", 0);
2045
+ __publicField(this, "_length", 0);
2046
+ if (options) {
2047
+ }
1554
2048
  this.pushMany(elements);
1555
2049
  }
1556
- /**
1557
- * The `head` function returns the first node of a singly linked list.
1558
- * @returns The method is returning either a SinglyLinkedListNode object or undefined.
1559
- */
1560
2050
  get head() {
1561
2051
  return this._head;
1562
2052
  }
1563
- /**
1564
- * The `tail` function returns the last node of a singly linked list.
1565
- * @returns The method is returning either a SinglyLinkedListNode object or undefined.
1566
- */
1567
2053
  get tail() {
1568
2054
  return this._tail;
1569
2055
  }
1570
- /**
1571
- * The above function returns the value of the first element in a linked list, or undefined if the
1572
- * list is empty.
1573
- * @returns The value of the first node in the linked list, or undefined if the linked list is empty.
1574
- */
1575
2056
  get first() {
1576
2057
  var _a;
1577
2058
  return (_a = this.head) == null ? void 0 : _a.value;
1578
2059
  }
1579
- /**
1580
- * The function returns the value of the last element in a linked list, or undefined if the list is
1581
- * empty.
1582
- * @returns The value of the last node in the linked list, or undefined if the linked list is empty.
1583
- */
1584
2060
  get last() {
1585
2061
  var _a;
1586
2062
  return (_a = this.tail) == null ? void 0 : _a.value;
1587
2063
  }
1588
- /**
1589
- * The function returns the size of an object.
1590
- * @returns The size of the object, which is a number.
1591
- */
1592
- get size() {
1593
- return this._size;
2064
+ get length() {
2065
+ return this._length;
1594
2066
  }
1595
2067
  /**
1596
2068
  * Time Complexity: O(n)
@@ -1626,7 +2098,8 @@ var dataStructureTyped = (() => {
1626
2098
  this.tail.next = newNode;
1627
2099
  this._tail = newNode;
1628
2100
  }
1629
- this._size++;
2101
+ this._length++;
2102
+ if (this._maxLen > 0 && this.length > this._maxLen) this.shift();
1630
2103
  return true;
1631
2104
  }
1632
2105
  /**
@@ -1643,7 +2116,7 @@ var dataStructureTyped = (() => {
1643
2116
  const value2 = this.head.value;
1644
2117
  this._head = void 0;
1645
2118
  this._tail = void 0;
1646
- this._size--;
2119
+ this._length--;
1647
2120
  return value2;
1648
2121
  }
1649
2122
  let current = this.head;
@@ -1653,7 +2126,7 @@ var dataStructureTyped = (() => {
1653
2126
  const value = this.tail.value;
1654
2127
  current.next = void 0;
1655
2128
  this._tail = current;
1656
- this._size--;
2129
+ this._length--;
1657
2130
  return value;
1658
2131
  }
1659
2132
  /**
@@ -1667,7 +2140,7 @@ var dataStructureTyped = (() => {
1667
2140
  if (!this.head) return void 0;
1668
2141
  const removedNode = this.head;
1669
2142
  this._head = this.head.next;
1670
- this._size--;
2143
+ this._length--;
1671
2144
  return removedNode.value;
1672
2145
  }
1673
2146
  /**
@@ -1690,7 +2163,7 @@ var dataStructureTyped = (() => {
1690
2163
  newNode.next = this.head;
1691
2164
  this._head = newNode;
1692
2165
  }
1693
- this._size++;
2166
+ this._length++;
1694
2167
  return true;
1695
2168
  }
1696
2169
  /**
@@ -1772,7 +2245,7 @@ var dataStructureTyped = (() => {
1772
2245
  * `undefined` if the index is out of bounds.
1773
2246
  */
1774
2247
  at(index) {
1775
- if (index < 0 || index >= this._size) return void 0;
2248
+ if (index < 0 || index >= this._length) return void 0;
1776
2249
  let current = this.head;
1777
2250
  for (let i = 0; i < index; i++) {
1778
2251
  current = current.next;
@@ -1823,20 +2296,23 @@ var dataStructureTyped = (() => {
1823
2296
  * bounds.
1824
2297
  */
1825
2298
  deleteAt(index) {
1826
- if (index < 0 || index >= this._size) return false;
2299
+ if (index < 0 || index >= this._length) return;
2300
+ let deleted;
1827
2301
  if (index === 0) {
2302
+ deleted = this.first;
1828
2303
  this.shift();
1829
- return true;
2304
+ return deleted;
1830
2305
  }
1831
- if (index === this._size - 1) {
1832
- this.pop();
1833
- return true;
2306
+ const targetNode = this.getNodeAt(index);
2307
+ const prevNode = this._getPrevNode(targetNode);
2308
+ if (prevNode && targetNode) {
2309
+ deleted = targetNode.value;
2310
+ prevNode.next = targetNode.next;
2311
+ if (targetNode === this.tail) this._tail = prevNode;
2312
+ this._length--;
2313
+ return deleted;
1834
2314
  }
1835
- const prevNode = this.getNodeAt(index - 1);
1836
- const removedNode = prevNode.next;
1837
- prevNode.next = removedNode.next;
1838
- this._size--;
1839
- return true;
2315
+ return;
1840
2316
  }
1841
2317
  /**
1842
2318
  * Time Complexity: O(n)
@@ -1849,34 +2325,19 @@ var dataStructureTyped = (() => {
1849
2325
  * successfully deleted from the linked list, and `false` if the value or node is not found in the linked list.
1850
2326
  */
1851
2327
  delete(elementOrNode) {
1852
- if (elementOrNode === void 0) return false;
1853
- let value;
1854
- if (elementOrNode instanceof SinglyLinkedListNode) {
1855
- value = elementOrNode.value;
2328
+ if (elementOrNode === void 0 || !this.head) return false;
2329
+ const node = this.isNode(elementOrNode) ? elementOrNode : this.getNode(elementOrNode);
2330
+ if (!node) return false;
2331
+ const prevNode = this._getPrevNode(node);
2332
+ if (!prevNode) {
2333
+ this._head = node.next;
2334
+ if (node === this.tail) this._tail = void 0;
1856
2335
  } else {
1857
- value = elementOrNode;
2336
+ prevNode.next = node.next;
2337
+ if (node === this.tail) this._tail = prevNode;
1858
2338
  }
1859
- let current = this.head, prev = void 0;
1860
- while (current) {
1861
- if (current.value === value) {
1862
- if (prev === void 0) {
1863
- this._head = current.next;
1864
- if (current === this.tail) {
1865
- this._tail = void 0;
1866
- }
1867
- } else {
1868
- prev.next = current.next;
1869
- if (current === this.tail) {
1870
- this._tail = prev;
1871
- }
1872
- }
1873
- this._size--;
1874
- return true;
1875
- }
1876
- prev = current;
1877
- current = current.next;
1878
- }
1879
- return false;
2339
+ this._length--;
2340
+ return true;
1880
2341
  }
1881
2342
  /**
1882
2343
  * Time Complexity: O(n)
@@ -1894,12 +2355,12 @@ var dataStructureTyped = (() => {
1894
2355
  * successfully added at the specified index, and `false` if the index is out of bounds.
1895
2356
  */
1896
2357
  addAt(index, newElementOrNode) {
1897
- if (index < 0 || index > this._size) return false;
2358
+ if (index < 0 || index > this._length) return false;
1898
2359
  if (index === 0) {
1899
2360
  this.unshift(newElementOrNode);
1900
2361
  return true;
1901
2362
  }
1902
- if (index === this._size) {
2363
+ if (index === this._length) {
1903
2364
  this.push(newElementOrNode);
1904
2365
  return true;
1905
2366
  }
@@ -1907,9 +2368,31 @@ var dataStructureTyped = (() => {
1907
2368
  const prevNode = this.getNodeAt(index - 1);
1908
2369
  newNode.next = prevNode.next;
1909
2370
  prevNode.next = newNode;
1910
- this._size++;
2371
+ this._length++;
1911
2372
  return true;
1912
2373
  }
2374
+ /**
2375
+ * Time Complexity: O(n)
2376
+ * Space Complexity: O(1)
2377
+ *
2378
+ * The function setAt(index, value) updates the value at a specified index in a data structure if the
2379
+ * index exists.
2380
+ * @param {number} index - The `index` parameter in the `setAt` method refers to the position in the
2381
+ * data structure where you want to set a new value.
2382
+ * @param {E} value - The `value` parameter in the `setAt` method represents the new value that you
2383
+ * want to set at the specified index in the data structure.
2384
+ * @returns The `setAt` method returns a boolean value - `true` if the value at the specified index
2385
+ * is successfully updated, and `false` if the index is out of bounds (i.e., the node at that index
2386
+ * does not exist).
2387
+ */
2388
+ setAt(index, value) {
2389
+ const node = this.getNodeAt(index);
2390
+ if (node) {
2391
+ node.value = value;
2392
+ return true;
2393
+ }
2394
+ return false;
2395
+ }
1913
2396
  /**
1914
2397
  * Time Complexity: O(1)
1915
2398
  * Space Complexity: O(1)
@@ -1919,7 +2402,7 @@ var dataStructureTyped = (() => {
1919
2402
  * @returns A boolean value indicating whether the length of the object is equal to 0.
1920
2403
  */
1921
2404
  isEmpty() {
1922
- return this._size === 0;
2405
+ return this._length === 0;
1923
2406
  }
1924
2407
  /**
1925
2408
  * Time Complexity: O(1)
@@ -1930,23 +2413,7 @@ var dataStructureTyped = (() => {
1930
2413
  clear() {
1931
2414
  this._head = void 0;
1932
2415
  this._tail = void 0;
1933
- this._size = 0;
1934
- }
1935
- /**
1936
- * Time Complexity: O(n)
1937
- * Space Complexity: O(n)
1938
- *
1939
- * The `toArray` function converts a linked list into an array.
1940
- * @returns The `toArray()` method is returning an array of type `E[]`.
1941
- */
1942
- toArray() {
1943
- const array = [];
1944
- let current = this.head;
1945
- while (current) {
1946
- array.push(current.value);
1947
- current = current.next;
1948
- }
1949
- return array;
2416
+ this._length = 0;
1950
2417
  }
1951
2418
  /**
1952
2419
  * Time Complexity: O(n)
@@ -1969,32 +2436,6 @@ var dataStructureTyped = (() => {
1969
2436
  [this._head, this._tail] = [this.tail, this.head];
1970
2437
  return this;
1971
2438
  }
1972
- /**
1973
- * Time Complexity: O(n)
1974
- * Space Complexity: O(1)
1975
- *
1976
- * The `indexOf` function in TypeScript searches for a specific element or node in a singly linked
1977
- * list and returns its index if found.
1978
- * @param {E | SinglyLinkedListNode<E> | ((node: SinglyLinkedListNode<E>) => boolean)} elementNodeOrPredicate
1979
- * elementNodeOrPredicate - The `elementNodeOrPredicate` parameter in the `indexOf` method can be one
1980
- * of the following types:
1981
- * @returns The `indexOf` method returns the index of the first occurrence of the element that
1982
- * matches the provided predicate in the singly linked list. If no matching element is found, it
1983
- * returns -1.
1984
- */
1985
- indexOf(elementNodeOrPredicate) {
1986
- const predicate = this._ensurePredicate(elementNodeOrPredicate);
1987
- let index = 0;
1988
- let current = this.head;
1989
- while (current) {
1990
- if (predicate(current)) {
1991
- return index;
1992
- }
1993
- index++;
1994
- current = current.next;
1995
- }
1996
- return -1;
1997
- }
1998
2439
  /**
1999
2440
  * Time Complexity: O(n)
2000
2441
  * Space Complexity: O(1)
@@ -2010,6 +2451,7 @@ var dataStructureTyped = (() => {
2010
2451
  */
2011
2452
  getNode(elementNodeOrPredicate) {
2012
2453
  if (elementNodeOrPredicate === void 0) return;
2454
+ if (this.isNode(elementNodeOrPredicate)) return elementNodeOrPredicate;
2013
2455
  const predicate = this._ensurePredicate(elementNodeOrPredicate);
2014
2456
  let current = this.head;
2015
2457
  while (current) {
@@ -2033,33 +2475,22 @@ var dataStructureTyped = (() => {
2033
2475
  * element or node in the linked list. This new element can be of type `E` or a
2034
2476
  * `SinglyLinkedListNode<E>`.
2035
2477
  * @returns The `addBefore` method returns a boolean value - `true` if the new element or node was
2036
- * successfully added before the existing element or node, and `false` if the operation was
2037
- * unsuccessful.
2038
- */
2039
- addBefore(existingElementOrNode, newElementOrNode) {
2040
- if (!this.head) return false;
2041
- let existingValue;
2042
- if (this.isNode(existingElementOrNode)) {
2043
- existingValue = existingElementOrNode.value;
2044
- } else {
2045
- existingValue = existingElementOrNode;
2046
- }
2047
- if (this.head.value === existingValue) {
2048
- this.unshift(newElementOrNode);
2049
- return true;
2050
- }
2051
- let current = this.head;
2052
- while (current.next) {
2053
- if (current.next.value === existingValue) {
2054
- const newNode = this._ensureNode(newElementOrNode);
2055
- newNode.next = current.next;
2056
- current.next = newNode;
2057
- this._size++;
2058
- return true;
2059
- }
2060
- current = current.next;
2478
+ * successfully added before the existing element or node, and `false` if the operation was
2479
+ * unsuccessful.
2480
+ */
2481
+ addBefore(existingElementOrNode, newElementOrNode) {
2482
+ const existingNode = this.getNode(existingElementOrNode);
2483
+ if (!existingNode) return false;
2484
+ const prevNode = this._getPrevNode(existingNode);
2485
+ const newNode = this._ensureNode(newElementOrNode);
2486
+ if (!prevNode) {
2487
+ this.unshift(newNode);
2488
+ } else {
2489
+ prevNode.next = newNode;
2490
+ newNode.next = existingNode;
2491
+ this._length++;
2061
2492
  }
2062
- return false;
2493
+ return true;
2063
2494
  }
2064
2495
  /**
2065
2496
  * Time Complexity: O(n)
@@ -2086,11 +2517,67 @@ var dataStructureTyped = (() => {
2086
2517
  if (existingNode === this.tail) {
2087
2518
  this._tail = newNode;
2088
2519
  }
2089
- this._size++;
2520
+ this._length++;
2090
2521
  return true;
2091
2522
  }
2092
2523
  return false;
2093
2524
  }
2525
+ /**
2526
+ * Time Complexity: O(n)
2527
+ * Space Complexity: O(1)
2528
+ *
2529
+ * The function `splice` in TypeScript overrides the default behavior to remove and insert elements
2530
+ * in a singly linked list while handling boundary cases.
2531
+ * @param {number} start - The `start` parameter in the `splice` method indicates the index at which
2532
+ * to start modifying the list. It specifies the position where elements will be added or removed.
2533
+ * @param {number} [deleteCount=0] - The `deleteCount` parameter in the `splice` method specifies the
2534
+ * number of elements to remove from the array starting at the specified `start` index. If
2535
+ * `deleteCount` is not provided, it defaults to 0, meaning no elements will be removed but new
2536
+ * elements can still be inserted at
2537
+ * @param {E[]} items - The `items` parameter in the `splice` method represents the elements to be
2538
+ * inserted into the list at the specified `start` index. These elements will be inserted in place of
2539
+ * the elements that are removed from the list. The `splice` method allows you to add new elements to
2540
+ * the list while
2541
+ * @returns The `splice` method is returning a `SinglyLinkedList` containing the elements that were
2542
+ * removed from the original list during the splice operation.
2543
+ */
2544
+ splice(start, deleteCount = 0, ...items) {
2545
+ const removedList = this._createInstance({ toElementFn: this._toElementFn, maxLen: this._maxLen });
2546
+ start = Math.max(0, Math.min(start, this.length));
2547
+ deleteCount = Math.max(0, deleteCount);
2548
+ const prevNode = start === 0 ? void 0 : this.getNodeAt(start - 1);
2549
+ const startNode = prevNode ? prevNode.next : this.head;
2550
+ let current = startNode;
2551
+ for (let i = 0; i < deleteCount && current; i++) {
2552
+ removedList.push(current.value);
2553
+ current = current.next;
2554
+ }
2555
+ const nextNode = current;
2556
+ let lastInsertedNode = void 0;
2557
+ for (const item of items) {
2558
+ const newNode = this._ensureNode(item);
2559
+ if (!lastInsertedNode) {
2560
+ if (prevNode) {
2561
+ prevNode.next = newNode;
2562
+ } else {
2563
+ this._head = newNode;
2564
+ }
2565
+ } else {
2566
+ lastInsertedNode.next = newNode;
2567
+ }
2568
+ lastInsertedNode = newNode;
2569
+ }
2570
+ if (lastInsertedNode) {
2571
+ lastInsertedNode.next = nextNode;
2572
+ } else if (prevNode) {
2573
+ prevNode.next = nextNode;
2574
+ }
2575
+ if (!nextNode) {
2576
+ this._tail = lastInsertedNode || prevNode;
2577
+ }
2578
+ this._length += items.length - removedList.length;
2579
+ return removedList;
2580
+ }
2094
2581
  /**
2095
2582
  * Time Complexity: O(n)
2096
2583
  * Space Complexity: O(1)
@@ -2124,7 +2611,7 @@ var dataStructureTyped = (() => {
2124
2611
  * is a clone of the original list.
2125
2612
  */
2126
2613
  clone() {
2127
- return new _SinglyLinkedList(this, { toElementFn: this.toElementFn });
2614
+ return new _SinglyLinkedList(this, { toElementFn: this.toElementFn, maxLen: this._maxLen });
2128
2615
  }
2129
2616
  /**
2130
2617
  * Time Complexity: O(n)
@@ -2144,7 +2631,7 @@ var dataStructureTyped = (() => {
2144
2631
  * elements that pass the filter condition specified by the `callback` function.
2145
2632
  */
2146
2633
  filter(callback, thisArg) {
2147
- const filteredList = new _SinglyLinkedList([], { toElementFn: this.toElementFn });
2634
+ const filteredList = this._createInstance({ toElementFn: this.toElementFn, maxLen: this._maxLen });
2148
2635
  let index = 0;
2149
2636
  for (const current of this) {
2150
2637
  if (callback.call(thisArg, current, index, this)) {
@@ -2175,7 +2662,7 @@ var dataStructureTyped = (() => {
2175
2662
  * @returns a new instance of the `SinglyLinkedList` class with the mapped elements.
2176
2663
  */
2177
2664
  map(callback, toElementFn, thisArg) {
2178
- const mappedList = new _SinglyLinkedList([], { toElementFn });
2665
+ const mappedList = new _SinglyLinkedList([], { toElementFn, maxLen: this._maxLen });
2179
2666
  let index = 0;
2180
2667
  for (const current of this) {
2181
2668
  mappedList.push(callback.call(thisArg, current, index, this));
@@ -2183,6 +2670,19 @@ var dataStructureTyped = (() => {
2183
2670
  }
2184
2671
  return mappedList;
2185
2672
  }
2673
+ /**
2674
+ * The function `_createInstance` returns a new instance of `SinglyLinkedList` with the specified
2675
+ * options.
2676
+ * @param [options] - The `options` parameter in the `_createInstance` method is of type
2677
+ * `SinglyLinkedListOptions<E, R>`, which is used to configure the behavior of the `SinglyLinkedList`
2678
+ * instance being created. It is an optional parameter, meaning it can be omitted when calling the
2679
+ * method.
2680
+ * @returns An instance of the `SinglyLinkedList` class with an empty array and the provided options
2681
+ * is being returned.
2682
+ */
2683
+ _createInstance(options) {
2684
+ return new _SinglyLinkedList([], options);
2685
+ }
2186
2686
  /**
2187
2687
  * The function `_getIterator` returns an iterable iterator that yields the values of a linked list.
2188
2688
  */
@@ -2193,6 +2693,33 @@ var dataStructureTyped = (() => {
2193
2693
  current = current.next;
2194
2694
  }
2195
2695
  }
2696
+ /**
2697
+ * The function returns an iterator that iterates over the elements of a collection in reverse order.
2698
+ */
2699
+ *_getReverseIterator() {
2700
+ const reversedArr = [...this].reverse();
2701
+ for (const item of reversedArr) {
2702
+ yield item;
2703
+ }
2704
+ }
2705
+ /**
2706
+ * The function `_getNodeIterator` returns an iterator that iterates over the nodes of a singly
2707
+ * linked list.
2708
+ */
2709
+ *_getNodeIterator() {
2710
+ let current = this.head;
2711
+ while (current) {
2712
+ yield current;
2713
+ current = current.next;
2714
+ }
2715
+ }
2716
+ // protected *_getReverseNodeIterator(): IterableIterator<SinglyLinkedListNode<E>> {
2717
+ // const reversedArr = [...this._getNodeIterator()].reverse();
2718
+ //
2719
+ // for (const item of reversedArr) {
2720
+ // yield item;
2721
+ // }
2722
+ // }
2196
2723
  /**
2197
2724
  * The _isPredicate function in TypeScript checks if the input is a function that takes a
2198
2725
  * SinglyLinkedListNode as an argument and returns a boolean.
@@ -2232,73 +2759,54 @@ var dataStructureTyped = (() => {
2232
2759
  if (this._isPredicate(elementNodeOrPredicate)) return elementNodeOrPredicate;
2233
2760
  return (node) => node.value === elementNodeOrPredicate;
2234
2761
  }
2762
+ /**
2763
+ * The function `_getPrevNode` returns the node before a given node in a singly linked list.
2764
+ * @param node - The `node` parameter in the `_getPrevNode` method is a reference to a node in a
2765
+ * singly linked list. The method is used to find the node that comes before the given node in the
2766
+ * linked list.
2767
+ * @returns The `_getPrevNode` method returns either the previous node of the input node in a singly
2768
+ * linked list or `undefined` if the input node is the head of the list or if the input node is not
2769
+ * found in the list.
2770
+ */
2771
+ _getPrevNode(node) {
2772
+ if (!this.head || this.head === node) return void 0;
2773
+ let current = this.head;
2774
+ while (current.next && current.next !== node) {
2775
+ current = current.next;
2776
+ }
2777
+ return current.next === node ? current : void 0;
2778
+ }
2235
2779
  };
2236
2780
 
2237
2781
  // src/data-structures/linked-list/doubly-linked-list.ts
2238
- var DoublyLinkedListNode = class {
2782
+ var DoublyLinkedListNode = class extends LinkedListNode {
2239
2783
  /**
2240
2784
  * The constructor function initializes the value, next, and previous properties of an object.
2241
2785
  * @param {E} value - The "value" parameter is the value that will be stored in the node. It can be of any data type, as it
2242
2786
  * is defined as a generic type "E".
2243
2787
  */
2244
2788
  constructor(value) {
2245
- __publicField(this, "_value");
2789
+ super(value);
2246
2790
  __publicField(this, "_next");
2247
2791
  __publicField(this, "_prev");
2248
2792
  this._value = value;
2249
2793
  this._next = void 0;
2250
2794
  this._prev = void 0;
2251
2795
  }
2252
- /**
2253
- * The function returns the value of a protected variable.
2254
- * @returns The value of the variable `_value` is being returned.
2255
- */
2256
- get value() {
2257
- return this._value;
2258
- }
2259
- /**
2260
- * The above function sets the value of a variable.
2261
- * @param {E} value - The parameter "value" is of type E, which means it can be any type.
2262
- */
2263
- set value(value) {
2264
- this._value = value;
2265
- }
2266
- /**
2267
- * The "next" function returns the next node in a doubly linked list.
2268
- * @returns The `next` property is being returned. It can be either a `DoublyLinkedListNode<E>`
2269
- * object or `undefined`.
2270
- */
2271
2796
  get next() {
2272
2797
  return this._next;
2273
2798
  }
2274
- /**
2275
- * The "next" property of a DoublyLinkedListNode is set to the provided value.
2276
- * @param {DoublyLinkedListNode<E> | undefined} value - The `value` parameter is of type
2277
- * `DoublyLinkedListNode<E> | undefined`. This means that it can accept either a
2278
- * `DoublyLinkedListNode` object or `undefined` as its value.
2279
- */
2280
2799
  set next(value) {
2281
2800
  this._next = value;
2282
2801
  }
2283
- /**
2284
- * The `prev` function returns the previous node in a doubly linked list.
2285
- * @returns The `prev` property of the `DoublyLinkedListNode` class is being returned. It can either
2286
- * be a `DoublyLinkedListNode` object or `undefined`.
2287
- */
2288
2802
  get prev() {
2289
2803
  return this._prev;
2290
2804
  }
2291
- /**
2292
- * The function sets the previous node of a doubly linked list node.
2293
- * @param {DoublyLinkedListNode<E> | undefined} value - The `value` parameter is of type
2294
- * `DoublyLinkedListNode<E> | undefined`. This means that it can accept either a
2295
- * `DoublyLinkedListNode` object or `undefined` as its value.
2296
- */
2297
2805
  set prev(value) {
2298
2806
  this._prev = value;
2299
2807
  }
2300
2808
  };
2301
- var DoublyLinkedList = class _DoublyLinkedList extends IterableElementBase {
2809
+ var DoublyLinkedList = class _DoublyLinkedList extends LinearLinkedBase {
2302
2810
  /**
2303
2811
  * This TypeScript constructor initializes a DoublyLinkedList with optional elements and options.
2304
2812
  * @param {Iterable<E> | Iterable<R>} elements - The `elements` parameter in the constructor is an
@@ -2313,33 +2821,24 @@ var dataStructureTyped = (() => {
2313
2821
  super(options);
2314
2822
  __publicField(this, "_head");
2315
2823
  __publicField(this, "_tail");
2316
- __publicField(this, "_size");
2824
+ __publicField(this, "_length");
2317
2825
  this._head = void 0;
2318
2826
  this._tail = void 0;
2319
- this._size = 0;
2827
+ this._length = 0;
2828
+ if (options) {
2829
+ const { maxLen } = options;
2830
+ if (typeof maxLen === "number" && maxLen > 0 && maxLen % 1 === 0) this._maxLen = maxLen;
2831
+ }
2320
2832
  this.pushMany(elements);
2321
2833
  }
2322
- /**
2323
- * The `head` function returns the first node of a doubly linked list.
2324
- * @returns The method `getHead()` returns either a `DoublyLinkedListNode<E>` object or `undefined`.
2325
- */
2326
2834
  get head() {
2327
2835
  return this._head;
2328
2836
  }
2329
- /**
2330
- * The `tail` function returns the last node of a doubly linked list.
2331
- * @returns The `get tail()` method is returning either a `DoublyLinkedListNode<E>` object or
2332
- * `undefined`.
2333
- */
2334
2837
  get tail() {
2335
2838
  return this._tail;
2336
2839
  }
2337
- /**
2338
- * The function returns the size of an object.
2339
- * @returns The size of the object, which is a number.
2340
- */
2341
- get size() {
2342
- return this._size;
2840
+ get length() {
2841
+ return this._length;
2343
2842
  }
2344
2843
  /**
2345
2844
  * Time Complexity: O(1)
@@ -2411,7 +2910,8 @@ var dataStructureTyped = (() => {
2411
2910
  this.tail.next = newNode;
2412
2911
  this._tail = newNode;
2413
2912
  }
2414
- this._size++;
2913
+ this._length++;
2914
+ if (this._maxLen > 0 && this.length > this._maxLen) this.shift();
2415
2915
  return true;
2416
2916
  }
2417
2917
  /**
@@ -2431,7 +2931,7 @@ var dataStructureTyped = (() => {
2431
2931
  this._tail = removedNode.prev;
2432
2932
  this.tail.next = void 0;
2433
2933
  }
2434
- this._size--;
2934
+ this._length--;
2435
2935
  return removedNode.value;
2436
2936
  }
2437
2937
  /**
@@ -2451,7 +2951,7 @@ var dataStructureTyped = (() => {
2451
2951
  this._head = removedNode.next;
2452
2952
  this.head.prev = void 0;
2453
2953
  }
2454
- this._size--;
2954
+ this._length--;
2455
2955
  return removedNode.value;
2456
2956
  }
2457
2957
  /**
@@ -2474,7 +2974,8 @@ var dataStructureTyped = (() => {
2474
2974
  this.head.prev = newNode;
2475
2975
  this._head = newNode;
2476
2976
  }
2477
- this._size++;
2977
+ this._length++;
2978
+ if (this._maxLen > 0 && this._length > this._maxLen) this.pop();
2478
2979
  return true;
2479
2980
  }
2480
2981
  /**
@@ -2537,7 +3038,7 @@ var dataStructureTyped = (() => {
2537
3038
  * or the linked list is empty, it will return undefined.
2538
3039
  */
2539
3040
  at(index) {
2540
- if (index < 0 || index >= this._size) return void 0;
3041
+ if (index < 0 || index >= this._length) return void 0;
2541
3042
  let current = this.head;
2542
3043
  for (let i = 0; i < index; i++) {
2543
3044
  current = current.next;
@@ -2556,7 +3057,7 @@ var dataStructureTyped = (() => {
2556
3057
  * valid range of the linked list, otherwise it returns `undefined`.
2557
3058
  */
2558
3059
  getNodeAt(index) {
2559
- if (index < 0 || index >= this._size) return void 0;
3060
+ if (index < 0 || index >= this._length) return void 0;
2560
3061
  let current = this.head;
2561
3062
  for (let i = 0; i < index; i++) {
2562
3063
  current = current.next;
@@ -2583,6 +3084,7 @@ var dataStructureTyped = (() => {
2583
3084
  */
2584
3085
  getNode(elementNodeOrPredicate) {
2585
3086
  if (elementNodeOrPredicate === void 0) return;
3087
+ if (this.isNode(elementNodeOrPredicate)) return elementNodeOrPredicate;
2586
3088
  const predicate = this._ensurePredicate(elementNodeOrPredicate);
2587
3089
  let current = this.head;
2588
3090
  while (current) {
@@ -2605,15 +3107,15 @@ var dataStructureTyped = (() => {
2605
3107
  * `addAt` method can be either a value of type `E` or a `DoublyLinkedListNode<E>` object.
2606
3108
  * @returns The `addAt` method returns a boolean value. It returns `true` if the element or node was
2607
3109
  * successfully added at the specified index, and `false` if the index is out of bounds (less than 0
2608
- * or greater than the size of the list).
3110
+ * or greater than the length of the list).
2609
3111
  */
2610
3112
  addAt(index, newElementOrNode) {
2611
- if (index < 0 || index > this._size) return false;
3113
+ if (index < 0 || index > this._length) return false;
2612
3114
  if (index === 0) {
2613
3115
  this.unshift(newElementOrNode);
2614
3116
  return true;
2615
3117
  }
2616
- if (index === this._size) {
3118
+ if (index === this._length) {
2617
3119
  this.push(newElementOrNode);
2618
3120
  return true;
2619
3121
  }
@@ -2624,7 +3126,7 @@ var dataStructureTyped = (() => {
2624
3126
  newNode.next = nextNode;
2625
3127
  prevNode.next = newNode;
2626
3128
  nextNode.prev = newNode;
2627
- this._size++;
3129
+ this._length++;
2628
3130
  return true;
2629
3131
  }
2630
3132
  /**
@@ -2655,7 +3157,7 @@ var dataStructureTyped = (() => {
2655
3157
  if (existingNode === this.head) {
2656
3158
  this._head = newNode;
2657
3159
  }
2658
- this._size++;
3160
+ this._length++;
2659
3161
  return true;
2660
3162
  }
2661
3163
  return false;
@@ -2689,7 +3191,28 @@ var dataStructureTyped = (() => {
2689
3191
  if (existingNode === this.tail) {
2690
3192
  this._tail = newNode;
2691
3193
  }
2692
- this._size++;
3194
+ this._length++;
3195
+ return true;
3196
+ }
3197
+ return false;
3198
+ }
3199
+ /**
3200
+ * Time Complexity: O(n)
3201
+ * Space Complexity: O(1)
3202
+ *
3203
+ * The function `setAt` updates the value at a specified index in a data structure if the index
3204
+ * exists.
3205
+ * @param {number} index - The `index` parameter in the `setAt` method refers to the position in the
3206
+ * data structure where you want to set a new value.
3207
+ * @param {E} value - The `value` parameter in the `setAt` method represents the new value that you
3208
+ * want to set at the specified index in the data structure.
3209
+ * @returns The `setAt` method returns a boolean value - `true` if the value at the specified index
3210
+ * is successfully updated, and `false` if the index is out of bounds.
3211
+ */
3212
+ setAt(index, value) {
3213
+ const node = this.getNodeAt(index);
3214
+ if (node) {
3215
+ node.value = value;
2693
3216
  return true;
2694
3217
  }
2695
3218
  return false;
@@ -2705,22 +3228,25 @@ var dataStructureTyped = (() => {
2705
3228
  * bounds.
2706
3229
  */
2707
3230
  deleteAt(index) {
2708
- if (index < 0 || index >= this._size) return false;
3231
+ if (index < 0 || index >= this._length) return;
3232
+ let deleted;
2709
3233
  if (index === 0) {
3234
+ deleted = this.first;
2710
3235
  this.shift();
2711
- return true;
3236
+ return deleted;
2712
3237
  }
2713
- if (index === this._size - 1) {
3238
+ if (index === this._length - 1) {
3239
+ deleted = this.last;
2714
3240
  this.pop();
2715
- return true;
3241
+ return deleted;
2716
3242
  }
2717
3243
  const removedNode = this.getNodeAt(index);
2718
3244
  const prevNode = removedNode.prev;
2719
3245
  const nextNode = removedNode.next;
2720
3246
  prevNode.next = nextNode;
2721
3247
  nextNode.prev = prevNode;
2722
- this._size--;
2723
- return true;
3248
+ this._length--;
3249
+ return removedNode == null ? void 0 : removedNode.value;
2724
3250
  }
2725
3251
  /**
2726
3252
  * Time Complexity: O(1) or O(n)
@@ -2747,7 +3273,7 @@ var dataStructureTyped = (() => {
2747
3273
  const nextNode = node.next;
2748
3274
  if (prevNode) prevNode.next = nextNode;
2749
3275
  if (nextNode) nextNode.prev = prevNode;
2750
- this._size--;
3276
+ this._length--;
2751
3277
  }
2752
3278
  return true;
2753
3279
  }
@@ -2757,46 +3283,22 @@ var dataStructureTyped = (() => {
2757
3283
  * Time Complexity: O(1)
2758
3284
  * Space Complexity: O(1)
2759
3285
  *
2760
- * The function checks if a variable has a size greater than zero and returns a boolean value.
3286
+ * The function checks if a variable has a length greater than zero and returns a boolean value.
2761
3287
  * @returns A boolean value is being returned.
2762
3288
  */
2763
3289
  isEmpty() {
2764
- return this._size === 0;
3290
+ return this._length === 0;
2765
3291
  }
2766
3292
  /**
2767
3293
  * Time Complexity: O(1)
2768
3294
  * Space Complexity: O(1)
2769
3295
  *
2770
- * The `clear` function resets the linked list by setting the head, tail, and size to undefined and 0 respectively.
3296
+ * The `clear` function resets the linked list by setting the head, tail, and length to undefined and 0 respectively.
2771
3297
  */
2772
3298
  clear() {
2773
3299
  this._head = void 0;
2774
3300
  this._tail = void 0;
2775
- this._size = 0;
2776
- }
2777
- /**
2778
- * Time Complexity: O(n)
2779
- * Space Complexity: O(1)
2780
- *
2781
- * This function finds the index of a specified element, node, or predicate in a doubly linked list.
2782
- * @param {E | DoublyLinkedListNode<E> | ((node: DoublyLinkedListNode<E>) => boolean)} elementNodeOrPredicate
2783
- * elementNodeOrPredicate - The `indexOf` method takes in a parameter `elementNodeOrPredicate`, which
2784
- * can be one of the following:
2785
- * @returns The `indexOf` method returns the index of the element in the doubly linked list that
2786
- * matches the provided element, node, or predicate. If no match is found, it returns -1.
2787
- */
2788
- indexOf(elementNodeOrPredicate) {
2789
- const predicate = this._ensurePredicate(elementNodeOrPredicate);
2790
- let index = 0;
2791
- let current = this.head;
2792
- while (current) {
2793
- if (predicate(current)) {
2794
- return index;
2795
- }
2796
- index++;
2797
- current = current.next;
2798
- }
2799
- return -1;
3301
+ this._length = 0;
2800
3302
  }
2801
3303
  /**
2802
3304
  * Time Complexity: O(n)
@@ -2857,38 +3359,6 @@ var dataStructureTyped = (() => {
2857
3359
  }
2858
3360
  return this;
2859
3361
  }
2860
- /**
2861
- * Time Complexity: O(n)
2862
- * Space Complexity: O(n)
2863
- *
2864
- * The `toArray` function converts a linked list into an array.
2865
- * @returns The `toArray()` method is returning an array of type `E[]`.
2866
- */
2867
- toArray() {
2868
- const array = [];
2869
- let current = this.head;
2870
- while (current) {
2871
- array.push(current.value);
2872
- current = current.next;
2873
- }
2874
- return array;
2875
- }
2876
- /**
2877
- * Time Complexity: O(n)
2878
- * Space Complexity: O(n)
2879
- *
2880
- * The `toReversedArray` function converts a doubly linked list into an array in reverse order.
2881
- * @returns The `toReversedArray()` function returns an array of type `E[]`.
2882
- */
2883
- toReversedArray() {
2884
- const array = [];
2885
- let current = this.tail;
2886
- while (current) {
2887
- array.push(current.value);
2888
- current = current.prev;
2889
- }
2890
- return array;
2891
- }
2892
3362
  /**
2893
3363
  * Time Complexity: O(n)
2894
3364
  * Space Complexity: O(n)
@@ -2899,7 +3369,7 @@ var dataStructureTyped = (() => {
2899
3369
  * is a copy of the original list.
2900
3370
  */
2901
3371
  clone() {
2902
- return new _DoublyLinkedList(this);
3372
+ return new _DoublyLinkedList(this, { toElementFn: this._toElementFn, maxLen: this._maxLen });
2903
3373
  }
2904
3374
  /**
2905
3375
  * Time Complexity: O(n)
@@ -2919,7 +3389,7 @@ var dataStructureTyped = (() => {
2919
3389
  * elements that pass the filter condition specified by the `callback` function.
2920
3390
  */
2921
3391
  filter(callback, thisArg) {
2922
- const filteredList = new _DoublyLinkedList([], { toElementFn: this.toElementFn });
3392
+ const filteredList = this._createInstance({ toElementFn: this.toElementFn, maxLen: this._maxLen });
2923
3393
  let index = 0;
2924
3394
  for (const current of this) {
2925
3395
  if (callback.call(thisArg, current, index, this)) {
@@ -2950,7 +3420,7 @@ var dataStructureTyped = (() => {
2950
3420
  * @returns a new instance of the `DoublyLinkedList` class with elements of type `T` and `RR`.
2951
3421
  */
2952
3422
  map(callback, toElementFn, thisArg) {
2953
- const mappedList = new _DoublyLinkedList([], { toElementFn });
3423
+ const mappedList = new _DoublyLinkedList([], { toElementFn, maxLen: this._maxLen });
2954
3424
  let index = 0;
2955
3425
  for (const current of this) {
2956
3426
  mappedList.push(callback.call(thisArg, current, index, this));
@@ -2991,6 +3461,35 @@ var dataStructureTyped = (() => {
2991
3461
  current = current.next;
2992
3462
  }
2993
3463
  }
3464
+ /**
3465
+ * The function returns an iterator that iterates over the elements of a data structure in reverse
3466
+ * order.
3467
+ */
3468
+ *_getReverseIterator() {
3469
+ let current = this.tail;
3470
+ while (current) {
3471
+ yield current.value;
3472
+ current = current.prev;
3473
+ }
3474
+ }
3475
+ /**
3476
+ * The function returns an iterator that iterates over the nodes of a doubly linked list starting
3477
+ * from the head.
3478
+ */
3479
+ *_getNodeIterator() {
3480
+ let current = this.head;
3481
+ while (current) {
3482
+ yield current;
3483
+ current = current.next;
3484
+ }
3485
+ }
3486
+ // protected *_getReverseNodeIterator(): IterableIterator<DoublyLinkedListNode<E>> {
3487
+ // const reversedArr = [...this._getNodeIterator()].reverse();
3488
+ //
3489
+ // for (const item of reversedArr) {
3490
+ // yield item;
3491
+ // }
3492
+ // }
2994
3493
  /**
2995
3494
  * The function `_isPredicate` checks if the input is a function that takes a `DoublyLinkedListNode`
2996
3495
  * as an argument and returns a boolean.
@@ -3030,6 +3529,30 @@ var dataStructureTyped = (() => {
3030
3529
  if (this._isPredicate(elementNodeOrPredicate)) return elementNodeOrPredicate;
3031
3530
  return (node) => node.value === elementNodeOrPredicate;
3032
3531
  }
3532
+ /**
3533
+ * The function `_createInstance` returns a new instance of `DoublyLinkedList` with the specified
3534
+ * options.
3535
+ * @param [options] - The `options` parameter in the `_createInstance` method is of type
3536
+ * `DoublyLinkedListOptions<E, R>`. It is an optional parameter that allows you to pass additional
3537
+ * configuration options when creating a new instance of the `DoublyLinkedList` class.
3538
+ * @returns An instance of the `DoublyLinkedList` class with an empty array and the provided options
3539
+ * is being returned, cast as the current class type.
3540
+ */
3541
+ _createInstance(options) {
3542
+ return new _DoublyLinkedList([], options);
3543
+ }
3544
+ /**
3545
+ * The function `_getPrevNode` returns the previous node of a given node in a doubly linked list.
3546
+ * @param node - The parameter `node` in the `_getPrevNode` method is of type
3547
+ * `DoublyLinkedListNode<E>`, which represents a node in a doubly linked list containing an element
3548
+ * of type `E`.
3549
+ * @returns The `_getPrevNode` method is returning the previous node of the input `node` in a doubly
3550
+ * linked list. If the input node has a previous node, it will return that node. Otherwise, it will
3551
+ * return `undefined`.
3552
+ */
3553
+ _getPrevNode(node) {
3554
+ return node.prev;
3555
+ }
3033
3556
  };
3034
3557
 
3035
3558
  // src/data-structures/linked-list/skip-linked-list.ts
@@ -3394,16 +3917,6 @@ var dataStructureTyped = (() => {
3394
3917
  const spliced = this.elements.splice(index, 1);
3395
3918
  return spliced.length === 1;
3396
3919
  }
3397
- /**
3398
- * Time Complexity: O(n)
3399
- * Space Complexity: O(n)
3400
- *
3401
- * The toArray function returns a copy of the elements in an array.
3402
- * @returns An array of type E.
3403
- */
3404
- toArray() {
3405
- return this.elements.slice();
3406
- }
3407
3920
  /**
3408
3921
  * Time Complexity: O(1)
3409
3922
  * Space Complexity: O(1)
@@ -3491,7 +4004,7 @@ var dataStructureTyped = (() => {
3491
4004
  };
3492
4005
 
3493
4006
  // src/data-structures/queue/queue.ts
3494
- var Queue = class _Queue extends IterableElementBase {
4007
+ var Queue = class _Queue extends LinearBase {
3495
4008
  constructor(elements = [], options) {
3496
4009
  super(options);
3497
4010
  __publicField(this, "_elements", []);
@@ -3503,37 +4016,31 @@ var dataStructureTyped = (() => {
3503
4016
  }
3504
4017
  this.pushMany(elements);
3505
4018
  }
3506
- /**
3507
- * The elements function returns the elements of this set.
3508
- * @return An array of the elements in the stack
3509
- */
3510
4019
  get elements() {
3511
4020
  return this._elements;
3512
4021
  }
3513
- /**
3514
- * The offset function returns the offset of the current page.
3515
- * @return The value of the protected variable _offset
3516
- */
3517
4022
  get offset() {
3518
4023
  return this._offset;
3519
4024
  }
3520
- /**
3521
- * The size function returns the number of elements in an array.
3522
- * @returns {number} The size of the array, which is the difference between the length of the array and the offset.
3523
- */
3524
- get size() {
4025
+ get length() {
3525
4026
  return this.elements.length - this.offset;
3526
4027
  }
4028
+ get autoCompactRatio() {
4029
+ return this._autoCompactRatio;
4030
+ }
4031
+ set autoCompactRatio(v) {
4032
+ this._autoCompactRatio = v;
4033
+ }
3527
4034
  /**
3528
4035
  * Time Complexity: O(1)
3529
4036
  * Space Complexity: O(1)
3530
4037
  *
3531
4038
  * The `first` function returns the first element of the array `_elements` if it exists, otherwise it returns `undefined`.
3532
4039
  * @returns The `get first()` method returns the first element of the data structure, represented by the `_elements` array at
3533
- * the `_offset` index. If the data structure is empty (size is 0), it returns `undefined`.
4040
+ * the `_offset` index. If the data structure is empty (length is 0), it returns `undefined`.
3534
4041
  */
3535
4042
  get first() {
3536
- return this.size > 0 ? this.elements[this.offset] : void 0;
4043
+ return this.length > 0 ? this.elements[this.offset] : void 0;
3537
4044
  }
3538
4045
  /**
3539
4046
  * Time Complexity: O(1)
@@ -3544,22 +4051,7 @@ var dataStructureTyped = (() => {
3544
4051
  * array is empty, it returns `undefined`.
3545
4052
  */
3546
4053
  get last() {
3547
- return this.size > 0 ? this.elements[this.elements.length - 1] : void 0;
3548
- }
3549
- /**
3550
- * This function returns the value of the autoCompactRatio property.
3551
- * @returns The `autoCompactRatio` property of the object, which is a number.
3552
- */
3553
- get autoCompactRatio() {
3554
- return this._autoCompactRatio;
3555
- }
3556
- /**
3557
- * The above function sets the autoCompactRatio property to a specified number in TypeScript.
3558
- * @param {number} v - The parameter `v` represents the value that will be assigned to the
3559
- * `_autoCompactRatio` property.
3560
- */
3561
- set autoCompactRatio(v) {
3562
- this._autoCompactRatio = v;
4054
+ return this.length > 0 ? this.elements[this.elements.length - 1] : void 0;
3563
4055
  }
3564
4056
  /**
3565
4057
  * Time Complexity: O(n)
@@ -3584,6 +4076,7 @@ var dataStructureTyped = (() => {
3584
4076
  */
3585
4077
  push(element) {
3586
4078
  this.elements.push(element);
4079
+ if (this._maxLen > 0 && this.length > this._maxLen) this.shift();
3587
4080
  return true;
3588
4081
  }
3589
4082
  /**
@@ -3614,7 +4107,7 @@ var dataStructureTyped = (() => {
3614
4107
  * @returns The function `shift()` returns either the first element in the queue or `undefined` if the queue is empty.
3615
4108
  */
3616
4109
  shift() {
3617
- if (this.size === 0) return void 0;
4110
+ if (this.length === 0) return void 0;
3618
4111
  const first = this.first;
3619
4112
  this._offset += 1;
3620
4113
  if (this.offset / this.elements.length > this.autoCompactRatio) this.compact();
@@ -3630,7 +4123,7 @@ var dataStructureTyped = (() => {
3630
4123
  */
3631
4124
  delete(element) {
3632
4125
  const index = this.elements.indexOf(element);
3633
- return this.deleteAt(index);
4126
+ return !!this.deleteAt(index);
3634
4127
  }
3635
4128
  /**
3636
4129
  * Time Complexity: O(n)
@@ -3641,8 +4134,9 @@ var dataStructureTyped = (() => {
3641
4134
  * @return A boolean value
3642
4135
  */
3643
4136
  deleteAt(index) {
3644
- const spliced = this.elements.splice(index, 1);
3645
- return spliced.length === 1;
4137
+ const deleted = this.elements[index];
4138
+ this.elements.splice(index, 1);
4139
+ return deleted;
3646
4140
  }
3647
4141
  /**
3648
4142
  * Time Complexity: O(1)
@@ -3658,25 +4152,66 @@ var dataStructureTyped = (() => {
3658
4152
  at(index) {
3659
4153
  return this.elements[index + this._offset];
3660
4154
  }
4155
+ /**
4156
+ * Time Complexity: O(n)
4157
+ * Space Complexity: O(1)
4158
+ *
4159
+ * The `reverse` function in TypeScript reverses the elements of an array starting from a specified
4160
+ * offset.
4161
+ * @returns The `reverse()` method is returning the modified object itself (`this`) after reversing
4162
+ * the elements in the array and resetting the offset to 0.
4163
+ */
4164
+ reverse() {
4165
+ this._elements = this.elements.slice(this.offset).reverse();
4166
+ this._offset = 0;
4167
+ return this;
4168
+ }
4169
+ /**
4170
+ * Time Complexity: O(n)
4171
+ * Space Complexity: O(1)
4172
+ *
4173
+ * The function `addAt` inserts a new element at a specified index in an array, returning true if
4174
+ * successful and false if the index is out of bounds.
4175
+ * @param {number} index - The `index` parameter represents the position at which the `newElement`
4176
+ * should be added in the array.
4177
+ * @param {E} newElement - The `newElement` parameter represents the element that you want to insert
4178
+ * into the array at the specified index.
4179
+ * @returns The `addAt` method returns a boolean value - `true` if the new element was successfully
4180
+ * added at the specified index, and `false` if the index is out of bounds (less than 0 or greater
4181
+ * than the length of the array).
4182
+ */
4183
+ addAt(index, newElement) {
4184
+ if (index < 0 || index > this.length) return false;
4185
+ this._elements.splice(this.offset + index, 0, newElement);
4186
+ return true;
4187
+ }
3661
4188
  /**
3662
4189
  * Time Complexity: O(1)
3663
4190
  * Space Complexity: O(1)
3664
4191
  *
3665
- * The function checks if a data structure is empty by comparing its size to zero.
3666
- * @returns {boolean} A boolean value indicating whether the size of the object is 0 or not.
4192
+ * The function `setAt` updates an element at a specified index in an array-like data structure.
4193
+ * @param {number} index - The `index` parameter is a number that represents the position in the
4194
+ * array where the new element will be set.
4195
+ * @param {E} newElement - The `newElement` parameter represents the new value that you want to set
4196
+ * at the specified index in the array.
4197
+ * @returns The `setAt` method returns a boolean value - `true` if the element was successfully set
4198
+ * at the specified index, and `false` if the index is out of bounds (less than 0 or greater than the
4199
+ * length of the array).
3667
4200
  */
3668
- isEmpty() {
3669
- return this.size === 0;
4201
+ setAt(index, newElement) {
4202
+ if (index < 0 || index > this.length) return false;
4203
+ this._elements[this.offset + index] = newElement;
4204
+ return true;
3670
4205
  }
3671
4206
  /**
3672
4207
  * Time Complexity: O(1)
3673
- * Space Complexity: O(n)
4208
+ * Space Complexity: O(1)
3674
4209
  *
3675
- * The toArray() function returns an array of elements from the current offset to the end of the _elements array.
3676
- * @returns An array of type E is being returned.
4210
+ * The function checks if a data structure is empty by comparing its length to zero.
4211
+ * @returns {boolean} A boolean value indicating whether the length of the object is 0 or not.
3677
4212
  */
3678
- toArray() {
3679
- return this.elements.slice(this.offset);
4213
+ isEmpty() {
4214
+ return this.length === 0;
3680
4215
  }
3681
4216
  /**
3682
4217
  * Time Complexity: O(1)
@@ -3701,6 +4236,34 @@ var dataStructureTyped = (() => {
3701
4236
  this._offset = 0;
3702
4237
  return true;
3703
4238
  }
4239
+ /**
4240
+ * Time Complexity: O(n)
4241
+ * Space Complexity: O(n)
4242
+ *
4243
+ * The function overrides the splice method to remove and insert elements in a queue-like data
4244
+ * structure.
4245
+ * @param {number} start - The `start` parameter in the `splice` method specifies the index at which
4246
+ * to start changing the array. Items will be added or removed starting from this index.
4247
+ * @param {number} [deleteCount=0] - The `deleteCount` parameter in the `splice` method specifies the
4248
+ * number of elements to remove from the array starting at the specified `start` index. If
4249
+ * `deleteCount` is not provided, it defaults to 0, meaning no elements will be removed but new
4250
+ * elements can still be inserted at
4251
+ * @param {E[]} items - The `items` parameter in the `splice` method represents the elements that
4252
+ * will be added to the array at the specified `start` index. These elements will replace the
4253
+ * existing elements starting from the `start` index for the `deleteCount` number of elements.
4254
+ * @returns The `splice` method is returning the `removedQueue`, which is an instance of the same
4255
+ * class as the original object.
4256
+ */
4257
+ splice(start, deleteCount = 0, ...items) {
4258
+ const removedQueue = this._createInstance();
4259
+ start = Math.max(0, Math.min(start, this.length));
4260
+ deleteCount = Math.max(0, Math.min(deleteCount, this.length - start));
4261
+ const globalStartIndex = this.offset + start;
4262
+ const removedElements = this._elements.splice(globalStartIndex, deleteCount, ...items);
4263
+ removedQueue.pushMany(removedElements);
4264
+ this.compact();
4265
+ return removedQueue;
4266
+ }
3704
4267
  /**
3705
4268
  * Time Complexity: O(n)
3706
4269
  * Space Complexity: O(n)
@@ -3709,7 +4272,7 @@ var dataStructureTyped = (() => {
3709
4272
  * @returns The `clone()` method is returning a new instance of the `Queue` class.
3710
4273
  */
3711
4274
  clone() {
3712
- return new _Queue(this.elements.slice(this.offset), { toElementFn: this.toElementFn });
4275
+ return new _Queue(this.elements.slice(this.offset), { toElementFn: this.toElementFn, maxLen: this._maxLen });
3713
4276
  }
3714
4277
  /**
3715
4278
  * Time Complexity: O(n)
@@ -3728,7 +4291,11 @@ var dataStructureTyped = (() => {
3728
4291
  * satisfy the given predicate function.
3729
4292
  */
3730
4293
  filter(predicate, thisArg) {
3731
- const newDeque = new _Queue([], { toElementFn: this.toElementFn });
4294
+ const newDeque = this._createInstance({
4295
+ toElementFn: this._toElementFn,
4296
+ autoCompactRatio: this._autoCompactRatio,
4297
+ maxLen: this._maxLen
4298
+ });
3732
4299
  let index = 0;
3733
4300
  for (const el of this) {
3734
4301
  if (predicate.call(thisArg, el, index, this)) {
@@ -3757,7 +4324,11 @@ var dataStructureTyped = (() => {
3757
4324
  * callback function to each element in the original Queue object.
3758
4325
  */
3759
4326
  map(callback, toElementFn, thisArg) {
3760
- const newDeque = new _Queue([], { toElementFn });
4327
+ const newDeque = new _Queue([], {
4328
+ toElementFn,
4329
+ autoCompactRatio: this._autoCompactRatio,
4330
+ maxLen: this._maxLen
4331
+ });
3761
4332
  let index = 0;
3762
4333
  for (const el of this) {
3763
4334
  newDeque.push(callback.call(thisArg, el, index, this));
@@ -3771,9 +4342,31 @@ var dataStructureTyped = (() => {
3771
4342
  *
3772
4343
  * The function `_getIterator` returns an iterable iterator for the elements in the class.
3773
4344
  */
3774
- *_getIterator() {
3775
- for (const item of this.elements.slice(this.offset)) {
3776
- yield item;
4345
+ *_getIterator() {
4346
+ for (const item of this.elements.slice(this.offset)) {
4347
+ yield item;
4348
+ }
4349
+ }
4350
+ /**
4351
+ * The function `_createInstance` returns a new instance of the `Queue` class with the specified
4352
+ * options.
4353
+ * @param [options] - The `options` parameter in the `_createInstance` method is of type
4354
+ * `QueueOptions<E, R>`, which is used to configure the behavior of the queue being created. It
4355
+ * allows you to specify settings or properties that can influence how the queue operates.
4356
+ * @returns An instance of the `Queue` class with an empty array and the provided options is being
4357
+ * returned.
4358
+ */
4359
+ _createInstance(options) {
4360
+ return new _Queue([], options);
4361
+ }
4362
+ /**
4363
+ * The function `_getReverseIterator` returns an iterator that iterates over elements in reverse
4364
+ * order.
4365
+ */
4366
+ *_getReverseIterator() {
4367
+ for (let i = this.length - 1; i >= 0; i--) {
4368
+ const cur = this.at(i);
4369
+ if (cur !== void 0) yield cur;
3777
4370
  }
3778
4371
  }
3779
4372
  };
@@ -3787,12 +4380,12 @@ var dataStructureTyped = (() => {
3787
4380
  * values as the original `LinkedListQueue`.
3788
4381
  */
3789
4382
  clone() {
3790
- return new _LinkedListQueue(this, { toElementFn: this.toElementFn });
4383
+ return new _LinkedListQueue(this, { toElementFn: this.toElementFn, maxLen: this._maxLen });
3791
4384
  }
3792
4385
  };
3793
4386
 
3794
4387
  // src/data-structures/queue/deque.ts
3795
- var Deque = class _Deque extends IterableElementBase {
4388
+ var Deque = class _Deque extends LinearBase {
3796
4389
  /**
3797
4390
  * The constructor initializes a Deque object with optional iterable of elements and options.
3798
4391
  * @param elements - An iterable object (such as an array or a Set) that contains the initial
@@ -3807,18 +4400,16 @@ var dataStructureTyped = (() => {
3807
4400
  constructor(elements = [], options) {
3808
4401
  super(options);
3809
4402
  __publicField(this, "_bucketSize", 1 << 12);
3810
- __publicField(this, "_maxLen", -1);
3811
4403
  __publicField(this, "_bucketFirst", 0);
3812
4404
  __publicField(this, "_firstInBucket", 0);
3813
4405
  __publicField(this, "_bucketLast", 0);
3814
4406
  __publicField(this, "_lastInBucket", 0);
3815
4407
  __publicField(this, "_bucketCount", 0);
3816
4408
  __publicField(this, "_buckets", []);
3817
- __publicField(this, "_size", 0);
4409
+ __publicField(this, "_length", 0);
3818
4410
  if (options) {
3819
- const { bucketSize, maxLen } = options;
4411
+ const { bucketSize } = options;
3820
4412
  if (typeof bucketSize === "number") this._bucketSize = bucketSize;
3821
- if (typeof maxLen === "number" && maxLen > 0 && maxLen % 1 === 0) this._maxLen = maxLen;
3822
4413
  }
3823
4414
  let _size;
3824
4415
  if ("length" in elements) {
@@ -3837,72 +4428,29 @@ var dataStructureTyped = (() => {
3837
4428
  this._firstInBucket = this._lastInBucket = this._bucketSize - _size % this._bucketSize >> 1;
3838
4429
  this.pushMany(elements);
3839
4430
  }
3840
- /**
3841
- * The bucketSize function returns the size of the bucket.
3842
- *
3843
- * @return The size of the bucket
3844
- */
3845
4431
  get bucketSize() {
3846
4432
  return this._bucketSize;
3847
4433
  }
3848
- /**
3849
- * The maxLen function returns the max length of the deque.
3850
- *
3851
- * @return The max length of the deque
3852
- */
3853
- get maxLen() {
3854
- return this._maxLen;
3855
- }
3856
- /**
3857
- * The function returns the value of the protected variable `_bucketFirst`.
3858
- * @returns The value of the `_bucketFirst` property.
3859
- */
3860
4434
  get bucketFirst() {
3861
4435
  return this._bucketFirst;
3862
4436
  }
3863
- /**
3864
- * The function returns the value of the protected variable _firstInBucket.
3865
- * @returns The method is returning the value of the variable `_firstInBucket`, which is of type
3866
- * `number`.
3867
- */
3868
4437
  get firstInBucket() {
3869
4438
  return this._firstInBucket;
3870
4439
  }
3871
- /**
3872
- * The function returns the value of the protected variable `_bucketLast`.
3873
- * @returns The value of the `_bucketLast` property, which is a number.
3874
- */
3875
4440
  get bucketLast() {
3876
4441
  return this._bucketLast;
3877
4442
  }
3878
- /**
3879
- * The function returns the value of the protected variable _lastInBucket.
3880
- * @returns The method is returning the value of the variable `_lastInBucket`, which is of type
3881
- * `number`.
3882
- */
3883
4443
  get lastInBucket() {
3884
4444
  return this._lastInBucket;
3885
4445
  }
3886
- /**
3887
- * The function returns the number of buckets.
3888
- * @returns The number of buckets.
3889
- */
3890
4446
  get bucketCount() {
3891
4447
  return this._bucketCount;
3892
4448
  }
3893
- /**
3894
- * The buckets function returns the buckets property of the object.
3895
- * @return The buckets property
3896
- */
3897
4449
  get buckets() {
3898
4450
  return this._buckets;
3899
4451
  }
3900
- /**
3901
- * The size function returns the number of items in the stack.
3902
- * @return The number of values in the set
3903
- */
3904
- get size() {
3905
- return this._size;
4452
+ get length() {
4453
+ return this._length;
3906
4454
  }
3907
4455
  /**
3908
4456
  * The function returns the first element in a collection if it exists, otherwise it returns
@@ -3910,7 +4458,7 @@ var dataStructureTyped = (() => {
3910
4458
  * @returns The first element of the collection, of type E, is being returned.
3911
4459
  */
3912
4460
  get first() {
3913
- if (this._size === 0) return;
4461
+ if (this._length === 0) return;
3914
4462
  return this._buckets[this._bucketFirst][this._firstInBucket];
3915
4463
  }
3916
4464
  /**
@@ -3918,7 +4466,7 @@ var dataStructureTyped = (() => {
3918
4466
  * @return The last element in the array
3919
4467
  */
3920
4468
  get last() {
3921
- if (this._size === 0) return;
4469
+ if (this._length === 0) return;
3922
4470
  return this._buckets[this._bucketLast][this._lastInBucket];
3923
4471
  }
3924
4472
  /**
@@ -3931,7 +4479,7 @@ var dataStructureTyped = (() => {
3931
4479
  * @returns The size of the data structure after the element has been pushed.
3932
4480
  */
3933
4481
  push(element) {
3934
- if (this._size) {
4482
+ if (this._length) {
3935
4483
  if (this._lastInBucket < this._bucketSize - 1) {
3936
4484
  this._lastInBucket += 1;
3937
4485
  } else if (this._bucketLast < this._bucketCount - 1) {
@@ -3943,9 +4491,9 @@ var dataStructureTyped = (() => {
3943
4491
  }
3944
4492
  if (this._bucketLast === this._bucketFirst && this._lastInBucket === this._firstInBucket) this._reallocate();
3945
4493
  }
3946
- this._size += 1;
4494
+ this._length += 1;
3947
4495
  this._buckets[this._bucketLast][this._lastInBucket] = element;
3948
- if (this._maxLen > 0 && this._size > this._maxLen) this.shift();
4496
+ if (this._maxLen > 0 && this._length > this._maxLen) this.shift();
3949
4497
  return true;
3950
4498
  }
3951
4499
  /**
@@ -3957,9 +4505,9 @@ var dataStructureTyped = (() => {
3957
4505
  * @returns The element that was removed from the data structure is being returned.
3958
4506
  */
3959
4507
  pop() {
3960
- if (this._size === 0) return;
4508
+ if (this._length === 0) return;
3961
4509
  const element = this._buckets[this._bucketLast][this._lastInBucket];
3962
- if (this._size !== 1) {
4510
+ if (this._length !== 1) {
3963
4511
  if (this._lastInBucket > 0) {
3964
4512
  this._lastInBucket -= 1;
3965
4513
  } else if (this._bucketLast > 0) {
@@ -3970,7 +4518,7 @@ var dataStructureTyped = (() => {
3970
4518
  this._lastInBucket = this._bucketSize - 1;
3971
4519
  }
3972
4520
  }
3973
- this._size -= 1;
4521
+ this._length -= 1;
3974
4522
  return element;
3975
4523
  }
3976
4524
  /**
@@ -3983,9 +4531,9 @@ var dataStructureTyped = (() => {
3983
4531
  * returned.
3984
4532
  */
3985
4533
  shift() {
3986
- if (this._size === 0) return;
4534
+ if (this._length === 0) return;
3987
4535
  const element = this._buckets[this._bucketFirst][this._firstInBucket];
3988
- if (this._size !== 1) {
4536
+ if (this._length !== 1) {
3989
4537
  if (this._firstInBucket < this._bucketSize - 1) {
3990
4538
  this._firstInBucket += 1;
3991
4539
  } else if (this._bucketFirst < this._bucketCount - 1) {
@@ -3996,7 +4544,7 @@ var dataStructureTyped = (() => {
3996
4544
  this._firstInBucket = 0;
3997
4545
  }
3998
4546
  }
3999
- this._size -= 1;
4547
+ this._length -= 1;
4000
4548
  return element;
4001
4549
  }
4002
4550
  /**
@@ -4010,7 +4558,7 @@ var dataStructureTyped = (() => {
4010
4558
  * @returns The size of the data structure after the element has been added.
4011
4559
  */
4012
4560
  unshift(element) {
4013
- if (this._size) {
4561
+ if (this._length) {
4014
4562
  if (this._firstInBucket > 0) {
4015
4563
  this._firstInBucket -= 1;
4016
4564
  } else if (this._bucketFirst > 0) {
@@ -4022,9 +4570,9 @@ var dataStructureTyped = (() => {
4022
4570
  }
4023
4571
  if (this._bucketFirst === this._bucketLast && this._firstInBucket === this._lastInBucket) this._reallocate();
4024
4572
  }
4025
- this._size += 1;
4573
+ this._length += 1;
4026
4574
  this._buckets[this._bucketFirst][this._firstInBucket] = element;
4027
- if (this._maxLen > 0 && this._size > this._maxLen) this.pop();
4575
+ if (this._maxLen > 0 && this._length > this._maxLen) this.pop();
4028
4576
  return true;
4029
4577
  }
4030
4578
  /**
@@ -4084,7 +4632,7 @@ var dataStructureTyped = (() => {
4084
4632
  * @returns A boolean value indicating whether the size of the object is 0 or not.
4085
4633
  */
4086
4634
  isEmpty() {
4087
- return this._size === 0;
4635
+ return this._length === 0;
4088
4636
  }
4089
4637
  /**
4090
4638
  * Time Complexity: O(1)
@@ -4096,30 +4644,9 @@ var dataStructureTyped = (() => {
4096
4644
  clear() {
4097
4645
  this._buckets = [new Array(this._bucketSize)];
4098
4646
  this._bucketCount = 1;
4099
- this._bucketFirst = this._bucketLast = this._size = 0;
4647
+ this._bucketFirst = this._bucketLast = this._length = 0;
4100
4648
  this._firstInBucket = this._lastInBucket = this._bucketSize >> 1;
4101
4649
  }
4102
- /**
4103
- * The below function is a generator that yields elements from a collection one by one.
4104
- */
4105
- *begin() {
4106
- let index = 0;
4107
- while (index < this._size) {
4108
- yield this.at(index);
4109
- index++;
4110
- }
4111
- }
4112
- /**
4113
- * The function `reverseBegin()` is a generator that yields elements in reverse order starting from
4114
- * the last element.
4115
- */
4116
- *reverseBegin() {
4117
- let index = this._size - 1;
4118
- while (index >= 0) {
4119
- yield this.at(index);
4120
- index--;
4121
- }
4122
- }
4123
4650
  /**
4124
4651
  * Time Complexity: O(1)
4125
4652
  * Space Complexity: O(1)
@@ -4131,7 +4658,7 @@ var dataStructureTyped = (() => {
4131
4658
  * @returns The element at the specified position in the data structure is being returned.
4132
4659
  */
4133
4660
  at(pos) {
4134
- rangeCheck(pos, 0, this._size - 1);
4661
+ rangeCheck(pos, 0, this._length - 1);
4135
4662
  const { bucketIndex, indexInBucket } = this._getBucketAndPosition(pos);
4136
4663
  return this._buckets[bucketIndex][indexInBucket];
4137
4664
  }
@@ -4146,7 +4673,7 @@ var dataStructureTyped = (() => {
4146
4673
  * position in the data structure.
4147
4674
  */
4148
4675
  setAt(pos, element) {
4149
- rangeCheck(pos, 0, this._size - 1);
4676
+ rangeCheck(pos, 0, this._length - 1);
4150
4677
  const { bucketIndex, indexInBucket } = this._getBucketAndPosition(pos);
4151
4678
  this._buckets[bucketIndex][indexInBucket] = element;
4152
4679
  return true;
@@ -4167,15 +4694,15 @@ var dataStructureTyped = (() => {
4167
4694
  * @returns The size of the array after the insertion is being returned.
4168
4695
  */
4169
4696
  addAt(pos, element, num = 1) {
4170
- const length = this._size;
4697
+ const length = this._length;
4171
4698
  rangeCheck(pos, 0, length);
4172
4699
  if (pos === 0) {
4173
4700
  while (num--) this.unshift(element);
4174
- } else if (pos === this._size) {
4701
+ } else if (pos === this._length) {
4175
4702
  while (num--) this.push(element);
4176
4703
  } else {
4177
4704
  const arr = [];
4178
- for (let i = pos; i < this._size; ++i) {
4705
+ for (let i = pos; i < this._length; ++i) {
4179
4706
  arr.push(this.at(i));
4180
4707
  }
4181
4708
  this.cut(pos - 1, true);
@@ -4204,16 +4731,59 @@ var dataStructureTyped = (() => {
4204
4731
  const { bucketIndex, indexInBucket } = this._getBucketAndPosition(pos);
4205
4732
  this._bucketLast = bucketIndex;
4206
4733
  this._lastInBucket = indexInBucket;
4207
- this._size = pos + 1;
4734
+ this._length = pos + 1;
4208
4735
  return this;
4209
4736
  } else {
4210
- const newDeque = new _Deque([], { bucketSize: this._bucketSize });
4737
+ const newDeque = this._createInstance({
4738
+ bucketSize: this._bucketSize,
4739
+ toElementFn: this._toElementFn,
4740
+ maxLen: this._maxLen
4741
+ });
4211
4742
  for (let i = 0; i <= pos; i++) {
4212
4743
  newDeque.push(this.at(i));
4213
4744
  }
4214
4745
  return newDeque;
4215
4746
  }
4216
4747
  }
4748
+ /**
4749
+ * Time Complexity: O(n)
4750
+ * Space Complexity: O(1)
4751
+ *
4752
+ * The `splice` function in TypeScript overrides the default behavior to remove and insert elements
4753
+ * in a Deque data structure while ensuring the starting position and delete count are within bounds.
4754
+ * @param {number} start - The `start` parameter in the `splice` method represents the index at which
4755
+ * to start changing the array. Items will be removed or added starting from this index.
4756
+ * @param {number} deleteCount - The `deleteCount` parameter in the `splice` method represents the
4757
+ * number of elements to remove from the array starting at the specified `start` index. If
4758
+ * `deleteCount` is not provided, it defaults to the number of elements from the `start` index to the
4759
+ * end of the array (`
4760
+ * @param {E[]} items - The `items` parameter in the `splice` method represents the elements that
4761
+ * will be inserted into the deque at the specified `start` index. These elements will be inserted in
4762
+ * place of the elements that are removed based on the `start` and `deleteCount` parameters.
4763
+ * @returns The `splice` method is returning the array `deletedElements` which contains the elements
4764
+ * that were removed from the Deque during the splice operation.
4765
+ */
4766
+ splice(start, deleteCount = this._length - start, ...items) {
4767
+ rangeCheck(start, 0, this._length);
4768
+ if (deleteCount < 0) deleteCount = 0;
4769
+ if (start + deleteCount > this._length) deleteCount = this._length - start;
4770
+ const deletedElements = this._createInstance();
4771
+ for (let i = 0; i < deleteCount; i++) {
4772
+ deletedElements.push(this.at(start + i));
4773
+ }
4774
+ const elementsAfter = [];
4775
+ for (let i = start + deleteCount; i < this._length; i++) {
4776
+ elementsAfter.push(this.at(i));
4777
+ }
4778
+ this.cut(start - 1, true);
4779
+ for (const item of items) {
4780
+ this.push(item);
4781
+ }
4782
+ for (const element of elementsAfter) {
4783
+ this.push(element);
4784
+ }
4785
+ return deletedElements;
4786
+ }
4217
4787
  /**
4218
4788
  * Time Complexity: O(1)
4219
4789
  * Space Complexity: O(1) or O(n)
@@ -4237,12 +4807,16 @@ var dataStructureTyped = (() => {
4237
4807
  const { bucketIndex, indexInBucket } = this._getBucketAndPosition(pos);
4238
4808
  this._bucketFirst = bucketIndex;
4239
4809
  this._firstInBucket = indexInBucket;
4240
- this._size = this._size - pos;
4810
+ this._length = this._length - pos;
4241
4811
  return this;
4242
4812
  } else {
4243
- const newDeque = new _Deque([], { bucketSize: this._bucketSize });
4813
+ const newDeque = this._createInstance({
4814
+ bucketSize: this._bucketSize,
4815
+ toElementFn: this._toElementFn,
4816
+ maxLen: this._maxLen
4817
+ });
4244
4818
  if (pos < 0) pos = 0;
4245
- for (let i = pos; i < this._size; i++) {
4819
+ for (let i = pos; i < this._length; i++) {
4246
4820
  newDeque.push(this.at(i));
4247
4821
  }
4248
4822
  return newDeque;
@@ -4260,21 +4834,26 @@ var dataStructureTyped = (() => {
4260
4834
  * @returns The size of the data structure after the deletion operation is performed.
4261
4835
  */
4262
4836
  deleteAt(pos) {
4263
- rangeCheck(pos, 0, this._size - 1);
4264
- if (pos === 0) this.shift();
4265
- else if (pos === this._size - 1) this.pop();
4266
- else {
4267
- const length = this._size - 1;
4268
- let { bucketIndex: curBucket, indexInBucket: curPointer } = this._getBucketAndPosition(pos);
4269
- for (let i = pos; i < length; ++i) {
4270
- const { bucketIndex: nextBucket, indexInBucket: nextPointer } = this._getBucketAndPosition(pos + 1);
4837
+ rangeCheck(pos, 0, this._length - 1);
4838
+ let deleted;
4839
+ if (pos === 0) {
4840
+ return this.shift();
4841
+ } else if (pos === this._length - 1) {
4842
+ deleted = this.last;
4843
+ this.pop();
4844
+ return deleted;
4845
+ } else {
4846
+ const length = this._length - 1;
4847
+ const { bucketIndex: targetBucket, indexInBucket: targetPointer } = this._getBucketAndPosition(pos);
4848
+ deleted = this._buckets[targetBucket][targetPointer];
4849
+ for (let i = pos; i < length; i++) {
4850
+ const { bucketIndex: curBucket, indexInBucket: curPointer } = this._getBucketAndPosition(i);
4851
+ const { bucketIndex: nextBucket, indexInBucket: nextPointer } = this._getBucketAndPosition(i + 1);
4271
4852
  this._buckets[curBucket][curPointer] = this._buckets[nextBucket][nextPointer];
4272
- curBucket = nextBucket;
4273
- curPointer = nextPointer;
4274
4853
  }
4275
4854
  this.pop();
4855
+ return deleted;
4276
4856
  }
4277
- return true;
4278
4857
  }
4279
4858
  /**
4280
4859
  * Time Complexity: O(n)
@@ -4287,7 +4866,7 @@ var dataStructureTyped = (() => {
4287
4866
  * @returns The size of the data structure after the element has been deleted.
4288
4867
  */
4289
4868
  delete(element) {
4290
- const size = this._size;
4869
+ const size = this._length;
4291
4870
  if (size === 0) return false;
4292
4871
  let i = 0;
4293
4872
  let index = 0;
@@ -4302,6 +4881,42 @@ var dataStructureTyped = (() => {
4302
4881
  this.cut(index - 1, true);
4303
4882
  return true;
4304
4883
  }
4884
+ // /**
4885
+ // * Time Complexity: O(n)
4886
+ // * Space Complexity: O(1)
4887
+ // *
4888
+ // * This function overrides the indexOf method to search for an element within a custom data
4889
+ // * structure.
4890
+ // * @param {E} searchElement - The `searchElement` parameter is the element that you are searching for
4891
+ // * within the data structure. The `indexOf` method will return the index of the first occurrence of
4892
+ // * this element within the data structure.
4893
+ // * @param {number} [fromIndex=0] - The `fromIndex` parameter in the `indexOf` method specifies the
4894
+ // * index at which to start searching for the `searchElement` within the data structure. If provided,
4895
+ // * the search will begin at this index instead of the beginning of the data structure.
4896
+ // * @returns The indexOf method is returning the index of the searchElement if it is found in the data
4897
+ // * structure, or -1 if the searchElement is not found.
4898
+ // */
4899
+ // override indexOf(searchElement: E, fromIndex: number = 0): number {
4900
+ // let index = fromIndex;
4901
+ // let bucketIndex = this._bucketFirst;
4902
+ // let indexInBucket = this._firstInBucket + fromIndex;
4903
+ //
4904
+ // for (let i = 0; i < this._length; i++) {
4905
+ // if (this._buckets[bucketIndex][indexInBucket] === searchElement) {
4906
+ // return index;
4907
+ // }
4908
+ // index++;
4909
+ // indexInBucket++;
4910
+ // if (indexInBucket >= this._bucketSize) {
4911
+ // bucketIndex++;
4912
+ // indexInBucket = 0;
4913
+ // }
4914
+ // if (bucketIndex >= this._bucketCount) {
4915
+ // bucketIndex = 0;
4916
+ // }
4917
+ // }
4918
+ // return -1;
4919
+ // }
4305
4920
  /**
4306
4921
  * Time Complexity: O(n)
4307
4922
  * Space Complexity: O(1)
@@ -4331,12 +4946,12 @@ var dataStructureTyped = (() => {
4331
4946
  * @returns The size of the modified array is being returned.
4332
4947
  */
4333
4948
  unique() {
4334
- if (this._size <= 1) {
4949
+ if (this._length <= 1) {
4335
4950
  return this;
4336
4951
  }
4337
4952
  let index = 1;
4338
4953
  let prev = this.at(0);
4339
- for (let i = 1; i < this._size; ++i) {
4954
+ for (let i = 1; i < this._length; ++i) {
4340
4955
  const cur = this.at(i);
4341
4956
  if (cur !== prev) {
4342
4957
  prev = cur;
@@ -4346,27 +4961,6 @@ var dataStructureTyped = (() => {
4346
4961
  this.cut(index - 1, true);
4347
4962
  return this;
4348
4963
  }
4349
- /**
4350
- * Time Complexity: O(n log n)
4351
- * Space Complexity: O(n)
4352
- *
4353
- * The `sort` function sorts the elements in a data structure using a provided comparator function.
4354
- * @param [comparator] - The `comparator` parameter is a function that takes in two elements `x` and
4355
- * `y` of type `E` and returns a number. The comparator function is used to determine the order of
4356
- * the elements in the sorted array.
4357
- * @returns Deque<E>
4358
- */
4359
- sort(comparator) {
4360
- const arr = [];
4361
- for (let i = 0; i < this._size; ++i) {
4362
- arr.push(this.at(i));
4363
- }
4364
- arr.sort(comparator);
4365
- for (let i = 0; i < this._size; ++i) {
4366
- this.setAt(i, arr[i]);
4367
- }
4368
- return this;
4369
- }
4370
4964
  /**
4371
4965
  * Time Complexity: O(n)
4372
4966
  * Space Complexity: O(n)
@@ -4374,10 +4968,10 @@ var dataStructureTyped = (() => {
4374
4968
  * The `shrinkToFit` function reorganizes the elements in an array-like data structure to minimize
4375
4969
  * memory usage.
4376
4970
  * @returns Nothing is being returned. The function is using the `return` statement to exit early if
4377
- * `this._size` is 0, but it does not return any value.
4971
+ * `this._length` is 0, but it does not return any value.
4378
4972
  */
4379
4973
  shrinkToFit() {
4380
- if (this._size === 0) return;
4974
+ if (this._length === 0) return;
4381
4975
  const newBuckets = [];
4382
4976
  if (this._bucketFirst === this._bucketLast) return;
4383
4977
  else if (this._bucketFirst < this._bucketLast) {
@@ -4396,35 +4990,6 @@ var dataStructureTyped = (() => {
4396
4990
  this._bucketLast = newBuckets.length - 1;
4397
4991
  this._buckets = newBuckets;
4398
4992
  }
4399
- /**
4400
- * Time Complexity: O(n)
4401
- * Space Complexity: O(1)
4402
- *
4403
- * The function "indexOf" returns the index of the first occurrence of a given element in an array,
4404
- * or -1 if the element is not found.
4405
- * @param {E} element - The "element" parameter represents the element that you want to find the
4406
- * index of in the data structure.
4407
- * @returns The indexOf function returns the index of the first occurrence of the specified element
4408
- * in the data structure. If the element is not found, it returns -1.
4409
- */
4410
- indexOf(element) {
4411
- for (let i = 0; i < this._size; ++i) {
4412
- if (this.at(i) === element) {
4413
- return i;
4414
- }
4415
- }
4416
- return -1;
4417
- }
4418
- /**
4419
- * Time Complexity: O(n)
4420
- * Space Complexity: O(n)
4421
- *
4422
- * The `toArray` function converts the elements of a data structure into an array.
4423
- * @returns The `toArray()` method is returning an array of elements of type `E`.
4424
- */
4425
- toArray() {
4426
- return [...this];
4427
- }
4428
4993
  /**
4429
4994
  * Time Complexity: O(n)
4430
4995
  * Space Complexity: O(n)
@@ -4435,7 +5000,11 @@ var dataStructureTyped = (() => {
4435
5000
  * elements as the original deque (`this`) and the same bucket size.
4436
5001
  */
4437
5002
  clone() {
4438
- return new _Deque(this, { bucketSize: this.bucketSize, toElementFn: this.toElementFn });
5003
+ return new _Deque(this, {
5004
+ bucketSize: this.bucketSize,
5005
+ toElementFn: this.toElementFn,
5006
+ maxLen: this._maxLen
5007
+ });
4439
5008
  }
4440
5009
  /**
4441
5010
  * Time Complexity: O(n)
@@ -4454,7 +5023,11 @@ var dataStructureTyped = (() => {
4454
5023
  * satisfy the given predicate function.
4455
5024
  */
4456
5025
  filter(predicate, thisArg) {
4457
- const newDeque = new _Deque([], { bucketSize: this._bucketSize, toElementFn: this.toElementFn });
5026
+ const newDeque = this._createInstance({
5027
+ bucketSize: this._bucketSize,
5028
+ toElementFn: this.toElementFn,
5029
+ maxLen: this._maxLen
5030
+ });
4458
5031
  let index = 0;
4459
5032
  for (const el of this) {
4460
5033
  if (predicate.call(thisArg, el, index, this)) {
@@ -4483,7 +5056,7 @@ var dataStructureTyped = (() => {
4483
5056
  * @returns a new Deque object with elements of type EM and raw elements of type RM.
4484
5057
  */
4485
5058
  map(callback, toElementFn, thisArg) {
4486
- const newDeque = new _Deque([], { bucketSize: this._bucketSize, toElementFn });
5059
+ const newDeque = new _Deque([], { bucketSize: this._bucketSize, toElementFn, maxLen: this._maxLen });
4487
5060
  let index = 0;
4488
5061
  for (const el of this) {
4489
5062
  newDeque.push(callback.call(thisArg, el, index, this));
@@ -4499,7 +5072,7 @@ var dataStructureTyped = (() => {
4499
5072
  * object to be iterated over using a for...of loop.
4500
5073
  */
4501
5074
  *_getIterator() {
4502
- for (let i = 0; i < this._size; ++i) {
5075
+ for (let i = 0; i < this._length; ++i) {
4503
5076
  yield this.at(i);
4504
5077
  }
4505
5078
  }
@@ -4556,6 +5129,26 @@ var dataStructureTyped = (() => {
4556
5129
  }
4557
5130
  return { bucketIndex, indexInBucket };
4558
5131
  }
5132
+ /**
5133
+ * The function `_createInstance` returns a new instance of the `Deque` class with the specified
5134
+ * options.
5135
+ * @param [options] - The `options` parameter in the `_createInstance` method is of type
5136
+ * `DequeOptions<E, R>`, which is an optional parameter that allows you to pass additional
5137
+ * configuration options when creating a new instance of the `Deque` class.
5138
+ * @returns An instance of the `Deque` class with an empty array and the provided options, casted as
5139
+ * `this`.
5140
+ */
5141
+ _createInstance(options) {
5142
+ return new _Deque([], options);
5143
+ }
5144
+ /**
5145
+ * This function returns an iterator that iterates over elements in reverse order.
5146
+ */
5147
+ *_getReverseIterator() {
5148
+ for (let i = this._length - 1; i > -1; i--) {
5149
+ yield this.at(i);
5150
+ }
5151
+ }
4559
5152
  };
4560
5153
 
4561
5154
  // src/data-structures/heap/heap.ts
@@ -4779,16 +5372,6 @@ var dataStructureTyped = (() => {
4779
5372
  _dfs(0);
4780
5373
  return result;
4781
5374
  }
4782
- /**
4783
- * Time Complexity: O(n)
4784
- * Space Complexity: O(n)
4785
- *
4786
- * Convert the heap to an array.
4787
- * @returns An array containing the elements of the heap.
4788
- */
4789
- toArray() {
4790
- return [...this.elements];
4791
- }
4792
5375
  /**
4793
5376
  * Time Complexity: O(n)
4794
5377
  * Space Complexity: O(n)
@@ -5688,8 +6271,8 @@ var dataStructureTyped = (() => {
5688
6271
  const queue = new Queue([vertex1]);
5689
6272
  visited.set(vertex1, true);
5690
6273
  let cost = 0;
5691
- while (queue.size > 0) {
5692
- for (let i = 0; i < queue.size; i++) {
6274
+ while (queue.length > 0) {
6275
+ for (let i = 0; i < queue.length; i++) {
5693
6276
  const cur = queue.shift();
5694
6277
  if (cur === vertex2) {
5695
6278
  return cost;
@@ -7463,7 +8046,7 @@ var dataStructureTyped = (() => {
7463
8046
  * This TypeScript constructor function initializes a binary tree with optional options and adds
7464
8047
  * elements based on the provided input.
7465
8048
  * @param keysNodesEntriesOrRaws - The `keysNodesEntriesOrRaws` parameter in the constructor is an
7466
- * iterable that can contain either objects of type `BTNRep<K, V, BinaryTreeNode<K, V>>` or `R`. It
8049
+ * iterable that can contain either objects of type `K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined ` or `R`. It
7467
8050
  * is used to initialize the binary tree with keys, nodes, entries, or raw data.
7468
8051
  * @param [options] - The `options` parameter in the constructor is an optional object that can
7469
8052
  * contain the following properties:
@@ -7472,6 +8055,7 @@ var dataStructureTyped = (() => {
7472
8055
  super();
7473
8056
  __publicField(this, "iterationType", "ITERATIVE");
7474
8057
  __publicField(this, "_isMapMode", true);
8058
+ __publicField(this, "_isDuplicate", false);
7475
8059
  __publicField(this, "_store", /* @__PURE__ */ new Map());
7476
8060
  __publicField(this, "_root");
7477
8061
  __publicField(this, "_size", 0);
@@ -7479,9 +8063,10 @@ var dataStructureTyped = (() => {
7479
8063
  __publicField(this, "_toEntryFn");
7480
8064
  __publicField(this, "_DEFAULT_NODE_CALLBACK", (node) => node ? node.key : void 0);
7481
8065
  if (options) {
7482
- const { iterationType, toEntryFn, isMapMode } = options;
8066
+ const { iterationType, toEntryFn, isMapMode, isDuplicate } = options;
7483
8067
  if (iterationType) this.iterationType = iterationType;
7484
8068
  if (isMapMode !== void 0) this._isMapMode = isMapMode;
8069
+ if (isDuplicate !== void 0) this._isDuplicate = isDuplicate;
7485
8070
  if (typeof toEntryFn === "function") this._toEntryFn = toEntryFn;
7486
8071
  else if (toEntryFn) throw TypeError("toEntryFn must be a function type");
7487
8072
  }
@@ -7490,6 +8075,9 @@ var dataStructureTyped = (() => {
7490
8075
  get isMapMode() {
7491
8076
  return this._isMapMode;
7492
8077
  }
8078
+ get isDuplicate() {
8079
+ return this._isDuplicate;
8080
+ }
7493
8081
  get store() {
7494
8082
  return this._store;
7495
8083
  }
@@ -7544,8 +8132,8 @@ var dataStructureTyped = (() => {
7544
8132
  *
7545
8133
  * The function `ensureNode` in TypeScript checks if a given input is a node, entry, key, or raw
7546
8134
  * value and returns the corresponding node or null.
7547
- * @param {BTNRep<K, V, BinaryTreeNode<K, V>>} keyNodeOrEntry - The `keyNodeOrEntry`
7548
- * parameter in the `ensureNode` function can be of type `BTNRep<K, V, BinaryTreeNode<K, V>>` or `R`. It
8135
+ * @param {K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined } keyNodeOrEntry - The `keyNodeOrEntry`
8136
+ * parameter in the `ensureNode` function can be of type `K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined ` or `R`. It
7549
8137
  * is used to determine whether the input is a key, node, entry, or raw data. The
7550
8138
  * @param {IterationType} iterationType - The `iterationType` parameter in the `ensureNode` function
7551
8139
  * is used to specify the type of iteration to be performed. It has a default value of
@@ -7571,7 +8159,7 @@ var dataStructureTyped = (() => {
7571
8159
  * Space Complexity: O(1)
7572
8160
  *
7573
8161
  * The function isNode checks if the input is an instance of BinaryTreeNode.
7574
- * @param {BTNRep<K, V, BinaryTreeNode<K, V>>} keyNodeOrEntry - The parameter
8162
+ * @param {K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined } keyNodeOrEntry - The parameter
7575
8163
  * `keyNodeOrEntry` can be either a key, a node, an entry, or raw data. The function is
7576
8164
  * checking if the input is an instance of a `BinaryTreeNode` and returning a boolean value
7577
8165
  * accordingly.
@@ -7588,7 +8176,7 @@ var dataStructureTyped = (() => {
7588
8176
  * Space Complexity: O(1)
7589
8177
  *
7590
8178
  * The function `isRaw` checks if the input parameter is of type `R` by verifying if it is an object.
7591
- * @param {BTNRep<K, V, BinaryTreeNode<K, V>> | R} keyNodeEntryOrRaw - BTNRep<K, V, BinaryTreeNode<K, V>>
8179
+ * @param {K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined | R} keyNodeEntryOrRaw - K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined
7592
8180
  * @returns The function `isRaw` is checking if the `keyNodeEntryOrRaw` parameter is of type `R` by
7593
8181
  * checking if it is an object. If the parameter is an object, the function will return `true`,
7594
8182
  * indicating that it is of type `R`.
@@ -7601,8 +8189,8 @@ var dataStructureTyped = (() => {
7601
8189
  * Space Complexity: O(1)
7602
8190
  *
7603
8191
  * The function `isRealNode` checks if a given input is a valid node in a binary tree.
7604
- * @param {BTNRep<K, V, BinaryTreeNode<K, V>>} keyNodeOrEntry - The `keyNodeOrEntry`
7605
- * parameter in the `isRealNode` function can be of type `BTNRep<K, V, BinaryTreeNode<K, V>>` or `R`.
8192
+ * @param {K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined } keyNodeOrEntry - The `keyNodeOrEntry`
8193
+ * parameter in the `isRealNode` function can be of type `K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined ` or `R`.
7606
8194
  * The function checks if the input parameter is a `BinaryTreeNode<K, V>` type by verifying if it is not equal
7607
8195
  * @returns The function `isRealNode` is checking if the input `keyNodeOrEntry` is a valid
7608
8196
  * node by comparing it to `this._NIL`, `null`, and `undefined`. If the input is not one of these
@@ -7618,7 +8206,7 @@ var dataStructureTyped = (() => {
7618
8206
  * Space Complexity: O(1)
7619
8207
  *
7620
8208
  * The function checks if a given input is a valid node or null.
7621
- * @param {BTNRep<K, V, BinaryTreeNode<K, V>>} keyNodeOrEntry - The parameter
8209
+ * @param {K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined } keyNodeOrEntry - The parameter
7622
8210
  * `keyNodeOrEntry` in the `isRealNodeOrNull` function can be of type `BTNRep<K,
7623
8211
  * V, BinaryTreeNode<K, V>>` or `R`. It is a union type that can either be a key, a node, an entry, or
7624
8212
  * @returns The function `isRealNodeOrNull` is returning a boolean value. It checks if the input
@@ -7633,7 +8221,7 @@ var dataStructureTyped = (() => {
7633
8221
  * Space Complexity: O(1)
7634
8222
  *
7635
8223
  * The function isNIL checks if a given key, node, entry, or raw value is equal to the _NIL value.
7636
- * @param {BTNRep<K, V, BinaryTreeNode<K, V>>} keyNodeOrEntry - BTNRep<K, V,
8224
+ * @param {K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined } keyNodeOrEntry - BTNRep<K, V,
7637
8225
  * BinaryTreeNode<K, V>>
7638
8226
  * @returns The function is checking if the `keyNodeOrEntry` parameter is equal to the `_NIL`
7639
8227
  * property of the current object and returning a boolean value based on that comparison.
@@ -7646,9 +8234,9 @@ var dataStructureTyped = (() => {
7646
8234
  * Space Complexity: O(1)
7647
8235
  *
7648
8236
  * The function `isRange` checks if the input parameter is an instance of the `Range` class.
7649
- * @param {BTNRep<K, V, BinaryTreeNode<K, V>> | NodePredicate<BinaryTreeNode<K, V>> | Range<K>}
7650
- * keyNodeEntryOrPredicate - The `keyNodeEntryOrPredicate` parameter in the `isRange` function can be
7651
- * of type `BTNRep<K, V, BinaryTreeNode<K, V>>`, `NodePredicate<BinaryTreeNode<K, V>>`, or
8237
+ * @param {K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined | NodePredicate<BinaryTreeNode<K, V>> | Range<K>} keyNodeEntryOrPredicate
8238
+ * - The `keyNodeEntryOrPredicate` parameter in the `isRange` function can be
8239
+ * of type `K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined `, `NodePredicate<BinaryTreeNode<K, V>>`, or
7652
8240
  * `Range<K>`. The function checks if the `keyNodeEntry
7653
8241
  * @returns The `isRange` function is checking if the `keyNodeEntryOrPredicate` parameter is an
7654
8242
  * instance of the `Range` class. If it is an instance of `Range`, the function will return `true`,
@@ -7664,8 +8252,8 @@ var dataStructureTyped = (() => {
7664
8252
  *
7665
8253
  * The function determines whether a given key, node, entry, or raw data is a leaf node in a binary
7666
8254
  * tree.
7667
- * @param {BTNRep<K, V, BinaryTreeNode<K, V>>} keyNodeOrEntry - The parameter
7668
- * `keyNodeOrEntry` can be of type `BTNRep<K, V, BinaryTreeNode<K, V>>` or `R`. It represents a
8255
+ * @param {K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined } keyNodeOrEntry - The parameter
8256
+ * `keyNodeOrEntry` can be of type `K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined ` or `R`. It represents a
7669
8257
  * key, node, entry, or raw data in a binary tree structure. The function `isLeaf` checks whether the
7670
8258
  * provided
7671
8259
  * @returns The function `isLeaf` returns a boolean value indicating whether the input
@@ -7683,8 +8271,8 @@ var dataStructureTyped = (() => {
7683
8271
  *
7684
8272
  * The function `isEntry` checks if the input is a BTNEntry object by verifying if it is an array
7685
8273
  * with a length of 2.
7686
- * @param {BTNRep<K, V, BinaryTreeNode<K, V>>} keyNodeOrEntry - The `keyNodeOrEntry`
7687
- * parameter in the `isEntry` function can be of type `BTNRep<K, V, BinaryTreeNode<K, V>>` or type `R`.
8274
+ * @param {K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined } keyNodeOrEntry - The `keyNodeOrEntry`
8275
+ * parameter in the `isEntry` function can be of type `K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined ` or type `R`.
7688
8276
  * The function checks if the provided `keyNodeOrEntry` is of type `BTN
7689
8277
  * @returns The `isEntry` function is checking if the `keyNodeOrEntry` parameter is an array
7690
8278
  * with a length of 2. If it is, then it returns `true`, indicating that the parameter is of type
@@ -7714,7 +8302,7 @@ var dataStructureTyped = (() => {
7714
8302
  *
7715
8303
  * The `add` function in TypeScript adds a new node to a binary tree while handling duplicate keys
7716
8304
  * and finding the correct insertion position.
7717
- * @param {BTNRep<K, V, BinaryTreeNode<K, V>>} keyNodeOrEntry - The `add` method you provided
8305
+ * @param {K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined } keyNodeOrEntry - The `add` method you provided
7718
8306
  * seems to be for adding a new node to a binary tree structure. The `keyNodeOrEntry`
7719
8307
  * parameter in the method can accept different types of values:
7720
8308
  * @param {V} [value] - The `value` parameter in the `add` method represents the value associated
@@ -7736,13 +8324,15 @@ var dataStructureTyped = (() => {
7736
8324
  }
7737
8325
  const queue = new Queue([this._root]);
7738
8326
  let potentialParent;
7739
- while (queue.size > 0) {
8327
+ while (queue.length > 0) {
7740
8328
  const cur = queue.shift();
7741
8329
  if (!cur) continue;
7742
- if (newNode !== null && cur.key === newNode.key) {
7743
- this._replaceNode(cur, newNode);
7744
- if (this._isMapMode) this._setValue(cur.key, newValue);
7745
- return true;
8330
+ if (!this._isDuplicate) {
8331
+ if (newNode !== null && cur.key === newNode.key) {
8332
+ this._replaceNode(cur, newNode);
8333
+ if (this._isMapMode) this._setValue(cur.key, newValue);
8334
+ return true;
8335
+ }
7746
8336
  }
7747
8337
  if (potentialParent === void 0 && (cur.left === void 0 || cur.right === void 0)) {
7748
8338
  potentialParent = cur;
@@ -7775,7 +8365,7 @@ var dataStructureTyped = (() => {
7775
8365
  * each insertion was successful.
7776
8366
  * @param keysNodesEntriesOrRaws - `keysNodesEntriesOrRaws` is an iterable that can contain a
7777
8367
  * mix of keys, nodes, entries, or raw values. Each element in this iterable can be of type
7778
- * `BTNRep<K, V, BinaryTreeNode<K, V>>` or `R`.
8368
+ * `K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined ` or `R`.
7779
8369
  * @param [values] - The `values` parameter in the `addMany` function is an optional parameter that
7780
8370
  * accepts an iterable of values. These values correspond to the keys or nodes being added in the
7781
8371
  * `keysNodesEntriesOrRaws` parameter. If provided, the function will iterate over the values and
@@ -7821,7 +8411,7 @@ var dataStructureTyped = (() => {
7821
8411
  * The `refill` function clears the existing data structure and then adds new key-value pairs based
7822
8412
  * on the provided input.
7823
8413
  * @param keysNodesEntriesOrRaws - The `keysNodesEntriesOrRaws` parameter in the `refill`
7824
- * method can accept an iterable containing a mix of `BTNRep<K, V, BinaryTreeNode<K, V>>` objects or `R`
8414
+ * method can accept an iterable containing a mix of `K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined ` objects or `R`
7825
8415
  * objects.
7826
8416
  * @param [values] - The `values` parameter in the `refill` method is an optional parameter that
7827
8417
  * accepts an iterable of values of type `V` or `undefined`.
@@ -7836,7 +8426,7 @@ var dataStructureTyped = (() => {
7836
8426
  *
7837
8427
  * The function `delete` in TypeScript implements the deletion of a node in a binary tree and returns
7838
8428
  * the deleted node along with information for tree balancing.
7839
- * @param {BTNRep<K, V, BinaryTreeNode<K, V>>} keyNodeOrEntry
8429
+ * @param {K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined } keyNodeOrEntry
7840
8430
  * - The `delete` method you provided is used to delete a node from a binary tree based on the key,
7841
8431
  * node, entry or raw data. The method returns an array of
7842
8432
  * `BinaryTreeDeleteResult` objects containing information about the deleted node and whether
@@ -7890,15 +8480,15 @@ var dataStructureTyped = (() => {
7890
8480
  *
7891
8481
  * The `search` function in TypeScript performs a depth-first or breadth-first search on a tree
7892
8482
  * structure based on a given predicate or key, with options to return multiple results or just one.
7893
- * @param {BTNRep<K, V, BinaryTreeNode<K, V>> | NodePredicate<BinaryTreeNode<K, V>>} keyNodeEntryOrPredicate - The
8483
+ * @param {K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined | NodePredicate<BinaryTreeNode<K, V>>} keyNodeEntryOrPredicate - The
7894
8484
  * `keyNodeEntryOrPredicate` parameter in the `search` function can accept three types of values:
7895
8485
  * @param [onlyOne=false] - The `onlyOne` parameter in the `search` function is a boolean flag that
7896
8486
  * determines whether the search should stop after finding the first matching node. If `onlyOne` is
7897
8487
  * set to `true`, the search will return as soon as a matching node is found. If `onlyOne` is
7898
8488
  * @param {C} callback - The `callback` parameter in the `search` function is a callback function
7899
8489
  * that will be called on each node that matches the search criteria. It is of type `C`, which
7900
- * extends `NodeCallback<BinaryTreeNode<K, V>>`. The default value for `callback` is `this._DEFAULT_NODE_CALLBACK` if
7901
- * @param {BTNRep<K, V, BinaryTreeNode<K, V>>} startNode - The `startNode` parameter in the `search` function is
8490
+ * extends `NodeCallback<BinaryTreeNode<K, V> | null>`. The default value for `callback` is `this._DEFAULT_NODE_CALLBACK` if
8491
+ * @param {K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined } startNode - The `startNode` parameter in the `search` function is
7902
8492
  * used to specify the node from which the search operation should begin. It represents the starting
7903
8493
  * point in the binary tree where the search will be performed. If no specific `startNode` is
7904
8494
  * provided, the search operation will start from the root
@@ -7948,12 +8538,12 @@ var dataStructureTyped = (() => {
7948
8538
  *
7949
8539
  * The function `getNodes` retrieves nodes from a binary tree based on a key, node, entry, raw data,
7950
8540
  * or predicate, with options for recursive or iterative traversal.
7951
- * @param {BTNRep<K, V, BinaryTreeNode<K, V>> | NodePredicate<BinaryTreeNode<K, V>>} keyNodeEntryOrPredicate
8541
+ * @param {K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined | NodePredicate<BinaryTreeNode<K, V>>} keyNodeEntryOrPredicate
7952
8542
  * - The `getNodes` function you provided takes several parameters:
7953
8543
  * @param [onlyOne=false] - The `onlyOne` parameter in the `getNodes` function is a boolean flag that
7954
8544
  * determines whether to return only the first node that matches the criteria specified by the
7955
8545
  * `keyNodeEntryOrPredicate` parameter. If `onlyOne` is set to `true`, the function will
7956
- * @param {BTNRep<K, V, BinaryTreeNode<K, V>>} startNode - The `startNode` parameter in the
8546
+ * @param {K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined } startNode - The `startNode` parameter in the
7957
8547
  * `getNodes` function is used to specify the starting point for traversing the binary tree. It
7958
8548
  * represents the root node of the binary tree or the node from which the traversal should begin. If
7959
8549
  * not provided, the default value is set to `this._root
@@ -7972,10 +8562,10 @@ var dataStructureTyped = (() => {
7972
8562
  *
7973
8563
  * The `getNode` function retrieves a node based on the provided key, node, entry, raw data, or
7974
8564
  * predicate.
7975
- * @param {BTNRep<K, V, BinaryTreeNode<K, V>> | NodePredicate<BinaryTreeNode<K, V>>} keyNodeEntryOrPredicate
8565
+ * @param {K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined | NodePredicate<BinaryTreeNode<K, V>>} keyNodeEntryOrPredicate
7976
8566
  * - The `keyNodeEntryOrPredicate` parameter in the `getNode` function can accept a key,
7977
8567
  * node, entry, raw data, or a predicate function.
7978
- * @param {BTNRep<K, V, BinaryTreeNode<K, V>>} startNode - The `startNode` parameter in the
8568
+ * @param {K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined } startNode - The `startNode` parameter in the
7979
8569
  * `getNode` function is used to specify the starting point for searching for a node in a binary
7980
8570
  * tree. If no specific starting point is provided, the default value is set to `this._root`, which
7981
8571
  * is typically the root node of the binary tree.
@@ -7995,10 +8585,10 @@ var dataStructureTyped = (() => {
7995
8585
  *
7996
8586
  * This function overrides the `get` method to retrieve the value associated with a specified key,
7997
8587
  * node, entry, raw data, or predicate in a data structure.
7998
- * @param {BTNRep<K, V, BinaryTreeNode<K, V>> | NodePredicate<BinaryTreeNode<K, V>>} keyNodeEntryOrPredicate
8588
+ * @param {K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined | NodePredicate<BinaryTreeNode<K, V>>} keyNodeEntryOrPredicate
7999
8589
  * - The `keyNodeEntryOrPredicate` parameter in the `get` method can accept one of the
8000
8590
  * following types:
8001
- * @param {BTNRep<K, V, BinaryTreeNode<K, V>>} startNode - The `startNode` parameter in the `get`
8591
+ * @param {K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined } startNode - The `startNode` parameter in the `get`
8002
8592
  * method is used to specify the starting point for searching for a key or node in the binary tree.
8003
8593
  * If no specific starting point is provided, the default starting point is the root of the binary
8004
8594
  * tree (`this._root`).
@@ -8026,10 +8616,10 @@ var dataStructureTyped = (() => {
8026
8616
  *
8027
8617
  * The `has` function in TypeScript checks if a specified key, node, entry, raw data, or predicate
8028
8618
  * exists in the data structure.
8029
- * @param {BTNRep<K, V, BinaryTreeNode<K, V>> | NodePredicate<BinaryTreeNode<K, V>>} keyNodeEntryOrPredicate
8619
+ * @param {K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined | NodePredicate<BinaryTreeNode<K, V>>} keyNodeEntryOrPredicate
8030
8620
  * - The `keyNodeEntryOrPredicate` parameter in the `override has` method can accept one of
8031
8621
  * the following types:
8032
- * @param {BTNRep<K, V, BinaryTreeNode<K, V>>} startNode - The `startNode` parameter in the
8622
+ * @param {K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined } startNode - The `startNode` parameter in the
8033
8623
  * `override` method is used to specify the starting point for the search operation within the data
8034
8624
  * structure. It defaults to `this._root` if not provided explicitly.
8035
8625
  * @param {IterationType} iterationType - The `iterationType` parameter in the `override has` method
@@ -8072,7 +8662,7 @@ var dataStructureTyped = (() => {
8072
8662
  *
8073
8663
  * The function checks if a binary tree is perfectly balanced by comparing its minimum height with
8074
8664
  * its height.
8075
- * @param {BTNRep<K, V, BinaryTreeNode<K, V>>} startNode - The `startNode` parameter is the starting
8665
+ * @param {K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined } startNode - The `startNode` parameter is the starting
8076
8666
  * point for checking if the binary tree is perfectly balanced. It represents the root node of the
8077
8667
  * binary tree or a specific node from which the balance check should begin.
8078
8668
  * @returns The method `isPerfectlyBalanced` is returning a boolean value, which indicates whether
@@ -8090,7 +8680,7 @@ var dataStructureTyped = (() => {
8090
8680
  *
8091
8681
  * The function `isBST` in TypeScript checks if a binary search tree is valid using either recursive
8092
8682
  * or iterative methods.
8093
- * @param {BTNRep<K, V, BinaryTreeNode<K, V>>} startNode - The `startNode` parameter in the `isBST`
8683
+ * @param {K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined } startNode - The `startNode` parameter in the `isBST`
8094
8684
  * function represents the starting point for checking whether a binary search tree (BST) is valid.
8095
8685
  * It can be a node in the BST or a reference to the root of the BST. If no specific node is
8096
8686
  * provided, the function will default to
@@ -8142,10 +8732,10 @@ var dataStructureTyped = (() => {
8142
8732
  * Space Complexity: O(log n)
8143
8733
  *
8144
8734
  * The `getDepth` function calculates the depth between two nodes in a binary tree.
8145
- * @param {BTNRep<K, V, BinaryTreeNode<K, V>>} dist - The `dist` parameter in the `getDepth`
8735
+ * @param {K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined } dist - The `dist` parameter in the `getDepth`
8146
8736
  * function represents the node or entry in a binary tree map, or a reference to a node in the tree.
8147
8737
  * It is the target node for which you want to calculate the depth from the `startNode` node.
8148
- * @param {BTNRep<K, V, BinaryTreeNode<K, V>>} startNode - The `startNode` parameter in the
8738
+ * @param {K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined } startNode - The `startNode` parameter in the
8149
8739
  * `getDepth` function represents the starting point from which you want to calculate the depth of a
8150
8740
  * given node or entry in a binary tree. If no specific starting point is provided, the default value
8151
8741
  * for `startNode` is set to the root of the binary
@@ -8172,7 +8762,7 @@ var dataStructureTyped = (() => {
8172
8762
  *
8173
8763
  * The `getHeight` function calculates the maximum height of a binary tree using either a recursive
8174
8764
  * or iterative approach in TypeScript.
8175
- * @param {BTNRep<K, V, BinaryTreeNode<K, V>>} startNode - The `startNode` parameter is the starting
8765
+ * @param {K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined } startNode - The `startNode` parameter is the starting
8176
8766
  * point from which the height of the binary tree will be calculated. It can be a node in the binary
8177
8767
  * tree or a reference to the root of the tree. If not provided, it defaults to the root of the
8178
8768
  * binary tree data structure.
@@ -8212,7 +8802,7 @@ var dataStructureTyped = (() => {
8212
8802
  *
8213
8803
  * The `getMinHeight` function calculates the minimum height of a binary tree using either a
8214
8804
  * recursive or iterative approach in TypeScript.
8215
- * @param {BTNRep<K, V, BinaryTreeNode<K, V>>} startNode - The `startNode` parameter in the
8805
+ * @param {K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined } startNode - The `startNode` parameter in the
8216
8806
  * `getMinHeight` function represents the starting node from which the minimum height of the binary
8217
8807
  * tree will be calculated. It is either a node in the binary tree or a reference to the root of the
8218
8808
  * tree. If not provided, the default value is the root
@@ -8271,7 +8861,7 @@ var dataStructureTyped = (() => {
8271
8861
  * the path to the root. It is expected to be a function that takes a node as an argument and returns
8272
8862
  * a value based on that node. The return type of the callback function is determined by the generic
8273
8863
  * type `C
8274
- * @param {BTNRep<K, V, BinaryTreeNode<K, V>>} beginNode - The `beginNode` parameter in the
8864
+ * @param {K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined } beginNode - The `beginNode` parameter in the
8275
8865
  * `getPathToRoot` function can be either a key, a node, an entry, or any other value of type `R`.
8276
8866
  * @param [isReverse=true] - The `isReverse` parameter in the `getPathToRoot` function determines
8277
8867
  * whether the resulting path from the given `beginNode` to the root should be in reverse order or
@@ -8301,7 +8891,7 @@ var dataStructureTyped = (() => {
8301
8891
  * @param {C} callback - The `callback` parameter is a function that will be called with the leftmost
8302
8892
  * node of a binary tree or with `undefined` if the tree is empty. It is provided with a default
8303
8893
  * value of `_DEFAULT_NODE_CALLBACK` if not specified.
8304
- * @param {BTNRep<K, V, BinaryTreeNode<K, V>>} startNode - The `startNode` parameter in the
8894
+ * @param {K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined } startNode - The `startNode` parameter in the
8305
8895
  * `getLeftMost` function represents the starting point for finding the leftmost node in a binary
8306
8896
  * tree. It can be either a key, a node, or an entry in the binary tree structure. If no specific
8307
8897
  * starting point is provided, the function will default
@@ -8341,7 +8931,7 @@ var dataStructureTyped = (() => {
8341
8931
  * of finding the rightmost node in a binary tree. It is of type `NodeCallback<OptNodeOrNull<BinaryTreeNode<K, V>>>`,
8342
8932
  * which means it is a callback function that can accept either an optional binary tree node or null
8343
8933
  * as
8344
- * @param {BTNRep<K, V, BinaryTreeNode<K, V>>} startNode - The `startNode` parameter in the
8934
+ * @param {K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined } startNode - The `startNode` parameter in the
8345
8935
  * `getRightMost` function represents the starting point for finding the rightmost node in a binary
8346
8936
  * tree. It can be either a key, a node, or an entry in the binary tree structure. If no specific
8347
8937
  * starting point is provided, the function will default
@@ -8427,32 +9017,34 @@ var dataStructureTyped = (() => {
8427
9017
  * Time complexity: O(n)
8428
9018
  * Space complexity: O(n)
8429
9019
  *
8430
- * The function `dfs` performs a depth-first search traversal on a binary tree structure based on the
8431
- * specified parameters.
8432
- * @param {C} callback - The `callback` parameter is a generic type `C` that extends the
8433
- * `NodeCallback` interface with a type parameter of `OptNodeOrNull<BinaryTreeNode<K, V>>`. It has a default value of
8434
- * `this._DEFAULT_NODE_CALLBACK as C`.
8435
- * @param {DFSOrderPattern} [pattern=IN] - The `pattern` parameter in the `dfs` method specifies the
8436
- * order in which the Depth-First Search (DFS) algorithm should traverse the nodes in the tree. The
8437
- * possible values for the `pattern` parameter are:
8438
- * @param {BTNRep<K, V, BinaryTreeNode<K, V>>} startNode - The `startNode` parameter in the `dfs`
8439
- * method is used to specify the starting point for the Depth-First Search traversal. It can be
8440
- * either a `BTNRep` object representing a key, node, or entry in the binary tree map,
8441
- * or it can be a
8442
- * @param {IterationType} iterationType - The `iterationType` parameter in the `dfs` method specifies
8443
- * the type of iteration to be performed during the depth-first search traversal. It is used to
8444
- * determine the order in which nodes are visited during the traversal.
8445
- * @param [includeNull=false] - The `includeNull` parameter in the `dfs` method is a boolean flag
8446
- * that determines whether null values should be included in the traversal or not. If `includeNull`
8447
- * is set to `true`, then null values will be included in the traversal process. If it is set to
8448
- * `false`,
8449
- * @returns The `dfs` method is returning an array of the return type specified by the generic type
8450
- * parameter `C`. The return type is determined by the callback function provided to the method.
8451
- */
8452
- dfs(callback = this._DEFAULT_NODE_CALLBACK, pattern = "IN", startNode = this._root, iterationType = this.iterationType, includeNull = false) {
9020
+ * The function performs a depth-first search on a binary tree structure based on the specified
9021
+ * parameters.
9022
+ * @param {C} callback - The `callback` parameter is a function that will be called for each node
9023
+ * visited during the depth-first search. It should accept a `BinaryTreeNode` as an argument and
9024
+ * return an optional node or null. The default value for this parameter is `_DEFAULT_NODE_CALLBACK`.
9025
+ * @param {DFSOrderPattern} [pattern=IN] - The `pattern` parameter in the `dfs` function specifies
9026
+ * the order in which the nodes are visited during a depth-first search traversal. The possible
9027
+ * values for the `pattern` parameter are:
9028
+ * @param {boolean} [onlyOne=false] - The `onlyOne` parameter in the `dfs` function is a boolean flag
9029
+ * that determines whether the depth-first search should stop after finding the first matching node
9030
+ * or continue searching for all matching nodes. If `onlyOne` is set to `true`, the search will stop
9031
+ * after finding the first matching node
9032
+ * @param {K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined}
9033
+ * startNode - The `startNode` parameter in the `dfs` function can be one of the following types:
9034
+ * @param {IterationType} iterationType - The `iterationType` parameter in the `dfs` function
9035
+ * specifies the type of iteration to be performed during the Depth-First Search traversal. It is
9036
+ * used to determine the order in which nodes are visited during the traversal. The possible values
9037
+ * for `iterationType` are typically defined as an enum or a
9038
+ * @param [includeNull=false] - The `includeNull` parameter in the `dfs` function determines whether
9039
+ * null nodes should be included in the depth-first search traversal. If `includeNull` is set to
9040
+ * `true`, null nodes will be included in the traversal process. If it is set to `false`, null nodes
9041
+ * will be skipped
9042
+ * @returns The `dfs` method is returning an array of the return type of the callback function `C`.
9043
+ */
9044
+ dfs(callback = this._DEFAULT_NODE_CALLBACK, pattern = "IN", onlyOne = false, startNode = this._root, iterationType = this.iterationType, includeNull = false) {
8453
9045
  startNode = this.ensureNode(startNode);
8454
9046
  if (!startNode) return [];
8455
- return this._dfs(callback, pattern, startNode, iterationType, includeNull);
9047
+ return this._dfs(callback, pattern, onlyOne, startNode, iterationType, includeNull);
8456
9048
  }
8457
9049
  /**
8458
9050
  * Time complexity: O(n)
@@ -8463,7 +9055,7 @@ var dataStructureTyped = (() => {
8463
9055
  * @param {C} callback - The `callback` parameter in the `bfs` function is a function that will be
8464
9056
  * called on each node visited during the breadth-first search traversal. It is a generic type `C`
8465
9057
  * that extends the `NodeCallback` type, which takes a parameter of type `BinaryTreeNode<K, V>` or `null`.
8466
- * @param {BTNRep<K, V, BinaryTreeNode<K, V>>} startNode - The `startNode` parameter in the `bfs`
9058
+ * @param {K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined } startNode - The `startNode` parameter in the `bfs`
8467
9059
  * function represents the starting point for the breadth-first search traversal in a binary tree. It
8468
9060
  * can be specified as a key, node, or entry in the binary tree structure. If not provided, the
8469
9061
  * default value is the root node of the binary
@@ -8486,7 +9078,7 @@ var dataStructureTyped = (() => {
8486
9078
  startNode
8487
9079
  ]);
8488
9080
  const dfs = (level) => {
8489
- if (queue.size === 0) return;
9081
+ if (queue.length === 0) return;
8490
9082
  const current = queue.shift();
8491
9083
  ans.push(callback(current));
8492
9084
  if (includeNull) {
@@ -8501,8 +9093,8 @@ var dataStructureTyped = (() => {
8501
9093
  dfs(0);
8502
9094
  } else {
8503
9095
  const queue = new Queue([startNode]);
8504
- while (queue.size > 0) {
8505
- const levelSize = queue.size;
9096
+ while (queue.length > 0) {
9097
+ const levelSize = queue.length;
8506
9098
  for (let i = 0; i < levelSize; i++) {
8507
9099
  const current = queue.shift();
8508
9100
  ans.push(callback(current));
@@ -8526,7 +9118,7 @@ var dataStructureTyped = (() => {
8526
9118
  * structure based on a specified callback and iteration type.
8527
9119
  * @param {C} callback - The `callback` parameter is a function that will be called on each leaf node
8528
9120
  * in the binary tree. It is optional and defaults to a default callback function if not provided.
8529
- * @param {BTNRep<K, V, BinaryTreeNode<K, V>>} startNode - The `startNode` parameter in the `leaves`
9121
+ * @param {K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined } startNode - The `startNode` parameter in the `leaves`
8530
9122
  * method is used to specify the starting point for finding and processing the leaves of a binary
8531
9123
  * tree. It can be provided as either a key, a node, or an entry in the binary tree structure. If not
8532
9124
  * explicitly provided, the default value
@@ -8552,7 +9144,7 @@ var dataStructureTyped = (() => {
8552
9144
  dfs(startNode);
8553
9145
  } else {
8554
9146
  const queue = new Queue([startNode]);
8555
- while (queue.size > 0) {
9147
+ while (queue.length > 0) {
8556
9148
  const cur = queue.shift();
8557
9149
  if (this.isRealNode(cur)) {
8558
9150
  if (this.isLeaf(cur)) {
@@ -8574,7 +9166,7 @@ var dataStructureTyped = (() => {
8574
9166
  * @param {C} callback - The `callback` parameter is a function that will be applied to each node in
8575
9167
  * the binary tree during the traversal. It is used to process each node and determine what
8576
9168
  * information to include in the output for each level of the tree.
8577
- * @param {BTNRep<K, V, BinaryTreeNode<K, V>>} startNode - The `startNode` parameter in the
9169
+ * @param {K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined } startNode - The `startNode` parameter in the
8578
9170
  * `listLevels` function represents the starting point for traversing the binary tree. It can be
8579
9171
  * either a key, a node, or an entry in the binary tree. If not provided, the default value is the
8580
9172
  * root of the binary tree.
@@ -8632,11 +9224,11 @@ var dataStructureTyped = (() => {
8632
9224
  * Morris Traversal algorithm with different order patterns.
8633
9225
  * @param {C} callback - The `callback` parameter in the `morris` function is a function that will be
8634
9226
  * called on each node in the binary tree during the traversal. It is of type `C`, which extends the
8635
- * `NodeCallback<BinaryTreeNode<K, V>>` type. The default value for `callback` is `this._DEFAULT
9227
+ * `NodeCallback<BinaryTreeNode<K, V> | null>` type. The default value for `callback` is `this._DEFAULT
8636
9228
  * @param {DFSOrderPattern} [pattern=IN] - The `pattern` parameter in the `morris` function specifies
8637
9229
  * the type of Depth-First Search (DFS) order pattern to traverse the binary tree. The possible
8638
9230
  * values for the `pattern` parameter are:
8639
- * @param {BTNRep<K, V, BinaryTreeNode<K, V>>} startNode - The `startNode` parameter in the `morris`
9231
+ * @param {K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined } startNode - The `startNode` parameter in the `morris`
8640
9232
  * function is the starting point for the Morris traversal algorithm. It represents the root node of
8641
9233
  * the binary tree or the node from which the traversal should begin. It can be provided as either a
8642
9234
  * key, a node, an entry, or a reference
@@ -8740,21 +9332,6 @@ var dataStructureTyped = (() => {
8740
9332
  this._clone(cloned);
8741
9333
  return cloned;
8742
9334
  }
8743
- _clone(cloned) {
8744
- this.bfs(
8745
- (node) => {
8746
- if (node === null) cloned.add(null);
8747
- else {
8748
- if (this._isMapMode) cloned.add([node.key, this._store.get(node.key)]);
8749
- else cloned.add([node.key, node.value]);
8750
- }
8751
- },
8752
- this._root,
8753
- this.iterationType,
8754
- true
8755
- );
8756
- if (this._isMapMode) cloned._store = this._store;
8757
- }
8758
9335
  /**
8759
9336
  * Time Complexity: O(n)
8760
9337
  * Space Complexity: O(n)
@@ -8814,7 +9391,7 @@ var dataStructureTyped = (() => {
8814
9391
  *
8815
9392
  * The function `toVisual` in TypeScript overrides the visual representation of a binary tree with
8816
9393
  * customizable options for displaying undefined, null, and sentinel nodes.
8817
- * @param {BTNRep<K, V, BinaryTreeNode<K, V>>} startNode - The `startNode` parameter in the
9394
+ * @param {K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined } startNode - The `startNode` parameter in the
8818
9395
  * `toVisual` method is used to specify the starting point for visualizing the binary tree structure.
8819
9396
  * It can be a node, key, entry, or the root of the tree. If no specific starting point is provided,
8820
9397
  * the default is set to the root
@@ -8858,7 +9435,7 @@ var dataStructureTyped = (() => {
8858
9435
  * printing options for the binary tree. It is an optional parameter that allows you to customize how
8859
9436
  * the binary tree is printed, such as choosing between different traversal orders or formatting
8860
9437
  * options.
8861
- * @param {BTNRep<K, V, BinaryTreeNode<K, V>>} startNode - The `startNode` parameter in the
9438
+ * @param {K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined } startNode - The `startNode` parameter in the
8862
9439
  * `override print` method is used to specify the starting point for printing the binary tree. It can
8863
9440
  * be either a key, a node, an entry, or the root of the tree. If no specific starting point is
8864
9441
  * provided, the default value is set to
@@ -8866,21 +9443,36 @@ var dataStructureTyped = (() => {
8866
9443
  print(options, startNode = this._root) {
8867
9444
  console.log(this.toVisual(startNode, options));
8868
9445
  }
9446
+ _clone(cloned) {
9447
+ this.bfs(
9448
+ (node) => {
9449
+ if (node === null) cloned.add(null);
9450
+ else {
9451
+ if (this._isMapMode) cloned.add([node.key, this._store.get(node.key)]);
9452
+ else cloned.add([node.key, node.value]);
9453
+ }
9454
+ },
9455
+ this._root,
9456
+ this.iterationType,
9457
+ true
9458
+ );
9459
+ if (this._isMapMode) cloned._store = this._store;
9460
+ }
8869
9461
  /**
8870
9462
  * Time Complexity: O(1)
8871
9463
  * Space Complexity: O(1)
8872
9464
  *
8873
9465
  * The function `keyValueNodeEntryRawToNodeAndValue` converts various input types into a node object
8874
9466
  * or returns null.
8875
- * @param {BTNRep<K, V, BinaryTreeNode<K, V>>} keyNodeOrEntry - The
9467
+ * @param {K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined } keyNodeOrEntry - The
8876
9468
  * `keyValueNodeEntryRawToNodeAndValue` function takes in a parameter `keyNodeOrEntry`, which
8877
- * can be of type `BTNRep<K, V, BinaryTreeNode<K, V>>` or `R`. This parameter represents either a key, a
9469
+ * can be of type `K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined ` or `R`. This parameter represents either a key, a
8878
9470
  * node, an entry
8879
9471
  * @param {V} [value] - The `value` parameter in the `keyValueNodeEntryRawToNodeAndValue` function is
8880
9472
  * an optional parameter of type `V`. It represents the value associated with the key in the node
8881
9473
  * being created. If a `value` is provided, it will be used when creating the node. If
8882
9474
  * @returns The `keyValueNodeEntryRawToNodeAndValue` function returns an optional node
8883
- * (`OptNodeOrNull<BinaryTreeNode<K, V>>`) based on the input parameters provided. The function checks the type of the
9475
+ * (`BinaryTreeNode<K, V> | null | undefined`) based on the input parameters provided. The function checks the type of the
8884
9476
  * input parameter (`keyNodeOrEntry`) and processes it accordingly to return a node or null
8885
9477
  * value.
8886
9478
  */
@@ -8901,45 +9493,48 @@ var dataStructureTyped = (() => {
8901
9493
  * Time complexity: O(n)
8902
9494
  * Space complexity: O(n)
8903
9495
  *
8904
- * The `_dfs` function performs a depth-first search traversal on a binary tree structure based on
8905
- * the specified order pattern and callback function.
9496
+ * The `_dfs` function performs a depth-first search traversal on a binary tree, with customizable
9497
+ * options for traversal order and node processing.
8906
9498
  * @param {C} callback - The `callback` parameter in the `_dfs` method is a function that will be
8907
- * called on each node visited during the depth-first search traversal. It is of type `C`, which
8908
- * extends `NodeCallback<OptNodeOrNull<BinaryTreeNode<K, V>>>`. The default value for this parameter is `this._DEFAULT
9499
+ * called on each node visited during the depth-first search traversal. It is a generic type `C` that
9500
+ * extends `NodeCallback<BinaryTreeNode<K, V> | null>`. The default value for `callback`
8909
9501
  * @param {DFSOrderPattern} [pattern=IN] - The `pattern` parameter in the `_dfs` method specifies the
8910
- * order in which the nodes are visited during the Depth-First Search traversal. It can have one of
8911
- * the following values:
8912
- * @param {BTNRep<K, V, BinaryTreeNode<K, V>>} startNode - The `startNode` parameter in the `_dfs`
8913
- * method is used to specify the starting point for the depth-first search traversal in a binary
8914
- * tree. It can be provided as either a `BTNRep` object or a reference to the root node
8915
- * of the tree. If no specific
9502
+ * order in which the nodes are visited during a depth-first search traversal. It can have one of the
9503
+ * following values:
9504
+ * @param {boolean} [onlyOne=false] - The `onlyOne` parameter in the `_dfs` method is a boolean flag
9505
+ * that determines whether the traversal should stop after processing a single node. If `onlyOne` is
9506
+ * set to `true`, the traversal will return as soon as a single node is processed. If it is set to
9507
+ * `false
9508
+ * @param {K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined}
9509
+ * startNode - The `startNode` parameter in the `_dfs` method is used to specify the starting node
9510
+ * for the depth-first search traversal. It can be provided in different forms:
8916
9511
  * @param {IterationType} iterationType - The `iterationType` parameter in the `_dfs` method
8917
- * specifies the type of iteration to be performed during the Depth-First Search (DFS) traversal of a
8918
- * binary tree. It can have two possible values:
8919
- * @param [includeNull=false] - The `includeNull` parameter in the `_dfs` method is a boolean flag
8920
- * that determines whether null nodes should be included in the depth-first search traversal. If
8921
- * `includeNull` is set to `true`, null nodes will be considered during the traversal process. If it
8922
- * is set to `false`,
8923
- * @param shouldVisitLeft - The `shouldVisitLeft` parameter is a function that takes a node as input
8924
- * and returns a boolean value. It is used to determine whether the left child of a node should be
8925
- * visited during the depth-first search traversal. By default, it checks if the node is truthy (not
8926
- * null or undefined
8927
- * @param shouldVisitRight - The `shouldVisitRight` parameter is a function that takes a node as an
8928
- * argument and returns a boolean value. It is used to determine whether the right child of a node
8929
- * should be visited during the depth-first search traversal. The default implementation checks if
8930
- * the node is truthy before visiting the right child
8931
- * @param shouldVisitRoot - The `shouldVisitRoot` parameter is a function that takes a node as an
8932
- * argument and returns a boolean value. It is used to determine whether the root node should be
8933
- * visited during the depth-first search traversal based on certain conditions. The default
8934
- * implementation checks if the node is a real node or null based
8935
- * @param shouldProcessRoot - The `shouldProcessRoot` parameter is a function that takes a node as an
8936
- * argument and returns a boolean value indicating whether the node should be processed during the
8937
- * depth-first search traversal. The default implementation checks if the node is a real node or null
8938
- * based on the `includeNull` flag. If `
8939
- * @returns The function `_dfs` returns an array of the return type of the callback function provided
8940
- * as input.
8941
- */
8942
- _dfs(callback = this._DEFAULT_NODE_CALLBACK, pattern = "IN", startNode = this._root, iterationType = this.iterationType, includeNull = false, shouldVisitLeft = (node) => !!node, shouldVisitRight = (node) => !!node, shouldVisitRoot = (node) => {
9512
+ * specifies whether the traversal should be done recursively or iteratively. It can have two
9513
+ * possible values:
9514
+ * @param [includeNull=false] - The `includeNull` parameter in the `_dfs` method determines whether
9515
+ * null nodes should be included in the traversal process. If `includeNull` is set to `true`, the
9516
+ * method will consider null nodes as valid nodes to visit or process. If `includeNull` is set to
9517
+ * `false`,
9518
+ * @param shouldVisitLeft - The `shouldVisitLeft` parameter in the `_dfs` method is a function that
9519
+ * determines whether the left child of a node should be visited during the Depth-First Search
9520
+ * traversal. By default, it checks if the node is not null or undefined before visiting the left
9521
+ * child. You can customize this behavior
9522
+ * @param shouldVisitRight - The `shouldVisitRight` parameter in the `_dfs` method is a function that
9523
+ * determines whether to visit the right child node of the current node during a depth-first search
9524
+ * traversal. The default implementation of this function checks if the node is not null or undefined
9525
+ * before deciding to visit it.
9526
+ * @param shouldVisitRoot - The `shouldVisitRoot` parameter in the `_dfs` method is a function that
9527
+ * determines whether a given node should be visited during the depth-first search traversal. The
9528
+ * function takes a node as an argument and returns a boolean value indicating whether the node
9529
+ * should be visited.
9530
+ * @param shouldProcessRoot - The `shouldProcessRoot` parameter in the `_dfs` method is a function
9531
+ * that determines whether the root node should be processed during the Depth-First Search traversal.
9532
+ * It takes a node (BinaryTreeNode<K, V> | null | undefined) as input and returns a boolean value. If
9533
+ * the function
9534
+ * @returns The `_dfs` method returns an array of the return type of the provided callback function
9535
+ * `C`.
9536
+ */
9537
+ _dfs(callback = this._DEFAULT_NODE_CALLBACK, pattern = "IN", onlyOne = false, startNode = this._root, iterationType = this.iterationType, includeNull = false, shouldVisitLeft = (node) => !!node, shouldVisitRight = (node) => !!node, shouldVisitRoot = (node) => {
8943
9538
  if (includeNull) return this.isRealNodeOrNull(node);
8944
9539
  return this.isRealNode(node);
8945
9540
  }, shouldProcessRoot = (node) => this.isRealNodeOrNull(node)) {
@@ -8950,26 +9545,35 @@ var dataStructureTyped = (() => {
8950
9545
  const dfs = (node) => {
8951
9546
  if (!shouldVisitRoot(node)) return;
8952
9547
  const visitLeft = () => {
8953
- if (shouldVisitLeft(node)) dfs(node == null ? void 0 : node.left);
9548
+ if (shouldVisitLeft(node) && (node == null ? void 0 : node.left) !== void 0) dfs(node == null ? void 0 : node.left);
8954
9549
  };
8955
9550
  const visitRight = () => {
8956
- if (shouldVisitRight(node)) dfs(node == null ? void 0 : node.right);
9551
+ if (shouldVisitRight(node) && (node == null ? void 0 : node.right) !== void 0) dfs(node == null ? void 0 : node.right);
8957
9552
  };
8958
9553
  switch (pattern) {
8959
9554
  case "IN":
8960
9555
  visitLeft();
8961
- if (shouldProcessRoot(node)) ans.push(callback(node));
9556
+ if (shouldProcessRoot(node)) {
9557
+ ans.push(callback(node));
9558
+ if (onlyOne) return;
9559
+ }
8962
9560
  visitRight();
8963
9561
  break;
8964
9562
  case "PRE":
8965
- if (shouldProcessRoot(node)) ans.push(callback(node));
9563
+ if (shouldProcessRoot(node)) {
9564
+ ans.push(callback(node));
9565
+ if (onlyOne) return;
9566
+ }
8966
9567
  visitLeft();
8967
9568
  visitRight();
8968
9569
  break;
8969
9570
  case "POST":
8970
9571
  visitLeft();
8971
9572
  visitRight();
8972
- if (shouldProcessRoot(node)) ans.push(callback(node));
9573
+ if (shouldProcessRoot(node)) {
9574
+ ans.push(callback(node));
9575
+ if (onlyOne) return;
9576
+ }
8973
9577
  break;
8974
9578
  }
8975
9579
  };
@@ -8992,7 +9596,10 @@ var dataStructureTyped = (() => {
8992
9596
  if (cur === void 0) continue;
8993
9597
  if (!shouldVisitRoot(cur.node)) continue;
8994
9598
  if (cur.opt === 1 /* PROCESS */) {
8995
- if (shouldProcessRoot(cur.node)) ans.push(callback(cur.node));
9599
+ if (shouldProcessRoot(cur.node) && cur.node !== void 0) {
9600
+ ans.push(callback(cur.node));
9601
+ if (onlyOne) return ans;
9602
+ }
8996
9603
  } else {
8997
9604
  switch (pattern) {
8998
9605
  case "IN":
@@ -9119,12 +9726,12 @@ var dataStructureTyped = (() => {
9119
9726
  * Space Complexity: O(1)
9120
9727
  *
9121
9728
  * The _swapProperties function swaps key and value properties between two nodes in a binary tree.
9122
- * @param {BTNRep<K, V, BinaryTreeNode<K, V>>} srcNode - The `srcNode` parameter in the
9729
+ * @param {K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined } srcNode - The `srcNode` parameter in the
9123
9730
  * `_swapProperties` method can be either a BTNRep object containing key and value
9124
9731
  * properties, or it can be of type R.
9125
- * @param {BTNRep<K, V, BinaryTreeNode<K, V>>} destNode - The `destNode` parameter in the
9732
+ * @param {K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined } destNode - The `destNode` parameter in the
9126
9733
  * `_swapProperties` method represents the node or entry where the properties will be swapped with
9127
- * the `srcNode`. It can be of type `BTNRep<K, V, BinaryTreeNode<K, V>>` or `R`. The method ensures that
9734
+ * the `srcNode`. It can be of type `K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined ` or `R`. The method ensures that
9128
9735
  * both `srcNode
9129
9736
  * @returns The `_swapProperties` method returns either the `destNode` with its key and value swapped
9130
9737
  * with the `srcNode`, or `undefined` if either `srcNode` or `destNode` is falsy.
@@ -9181,7 +9788,7 @@ var dataStructureTyped = (() => {
9181
9788
  *
9182
9789
  * The function _setRoot sets the root node of a data structure while updating the parent reference
9183
9790
  * of the previous root node.
9184
- * @param v - The parameter `v` in the `_setRoot` method is of type `OptNodeOrNull<BinaryTreeNode<K, V>>`, which means
9791
+ * @param v - The parameter `v` in the `_setRoot` method is of type `BinaryTreeNode<K, V> | null | undefined`, which means
9185
9792
  * it can either be an optional `BinaryTreeNode<K, V>` type or `null`.
9186
9793
  */
9187
9794
  _setRoot(v) {
@@ -9196,7 +9803,7 @@ var dataStructureTyped = (() => {
9196
9803
  *
9197
9804
  * The function `_ensurePredicate` in TypeScript ensures that the input is converted into a valid
9198
9805
  * predicate function for a binary tree node.
9199
- * @param {BTNRep<K, V, BinaryTreeNode<K, V>> | NodePredicate<BinaryTreeNode<K, V>>} keyNodeEntryOrPredicate - The
9806
+ * @param {K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined | NodePredicate<BinaryTreeNode<K, V>>} keyNodeEntryOrPredicate - The
9200
9807
  * `_ensurePredicate` method in the provided code snippet is responsible for ensuring that the input
9201
9808
  * parameter `keyNodeEntryOrPredicate` is transformed into a valid predicate function that can be
9202
9809
  * used for filtering nodes in a binary tree.
@@ -9210,9 +9817,15 @@ var dataStructureTyped = (() => {
9210
9817
  return (node) => node === keyNodeEntryOrPredicate;
9211
9818
  if (this.isEntry(keyNodeEntryOrPredicate)) {
9212
9819
  const [key] = keyNodeEntryOrPredicate;
9213
- return (node) => node.key === key;
9820
+ return (node) => {
9821
+ if (!node) return false;
9822
+ return node.key === key;
9823
+ };
9214
9824
  }
9215
- return (node) => node.key === keyNodeEntryOrPredicate;
9825
+ return (node) => {
9826
+ if (!node) return false;
9827
+ return node.key === keyNodeEntryOrPredicate;
9828
+ };
9216
9829
  }
9217
9830
  /**
9218
9831
  * Time Complexity: O(1)
@@ -9235,8 +9848,8 @@ var dataStructureTyped = (() => {
9235
9848
  *
9236
9849
  * The function `_extractKey` in TypeScript returns the key from a given input, which can be a node,
9237
9850
  * entry, raw data, or null/undefined.
9238
- * @param {BTNRep<K, V, BinaryTreeNode<K, V>>} keyNodeOrEntry - The `_extractKey` method you provided is a
9239
- * TypeScript method that takes in a parameter `keyNodeOrEntry` of type `BTNRep<K, V, BinaryTreeNode<K, V>>`,
9851
+ * @param {K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined } keyNodeOrEntry - The `_extractKey` method you provided is a
9852
+ * TypeScript method that takes in a parameter `keyNodeOrEntry` of type `K | BinaryTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined `,
9240
9853
  * where `BTNRep` is a generic type with keys `K`, `V`, and `BinaryTreeNode<K, V>`, and `
9241
9854
  * @returns The `_extractKey` method returns the key value extracted from the `keyNodeOrEntry`
9242
9855
  * parameter. The return value can be a key value of type `K`, `null`, or `undefined`, depending on
@@ -9331,7 +9944,7 @@ var dataStructureTyped = (() => {
9331
9944
  * This TypeScript constructor initializes a binary search tree with optional options and adds
9332
9945
  * elements if provided.
9333
9946
  * @param keysNodesEntriesOrRaws - The `keysNodesEntriesOrRaws` parameter in the constructor is an
9334
- * iterable that can contain elements of type `BTNRep<K, V, BSTNode<K, V>>` or `R`. It is used to
9947
+ * iterable that can contain elements of type `K | BSTNode<K, V> | [K | null | undefined, V | undefined] | null | undefined ` or `R`. It is used to
9335
9948
  * initialize the binary search tree with keys, nodes, entries, or raw data.
9336
9949
  * @param [options] - The `options` parameter is an optional object that can contain the following
9337
9950
  * properties:
@@ -9417,7 +10030,7 @@ var dataStructureTyped = (() => {
9417
10030
  *
9418
10031
  * The function ensures the existence of a node in a data structure and returns it, or undefined if
9419
10032
  * it doesn't exist.
9420
- * @param {BTNRep<K, V, BSTNode<K, V>>} keyNodeOrEntry - The parameter
10033
+ * @param {K | BSTNode<K, V> | [K | null | undefined, V | undefined] | null | undefined } keyNodeOrEntry - The parameter
9421
10034
  * `keyNodeOrEntry` can accept a value of type `R`, which represents the key, node,
9422
10035
  * entry, or raw element that needs to be ensured in the tree.
9423
10036
  * @param {IterationType} [iterationType=ITERATIVE] - The `iterationType` parameter is an optional
@@ -9435,8 +10048,8 @@ var dataStructureTyped = (() => {
9435
10048
  * Space Complexity: O(1)
9436
10049
  *
9437
10050
  * The function checks if the input is an instance of the BSTNode class.
9438
- * @param {BTNRep<K, V, BSTNode<K, V>>} keyNodeOrEntry - The parameter
9439
- * `keyNodeOrEntry` can be of type `R` or `BTNRep<K, V, BSTNode<K, V>>`.
10051
+ * @param {K | BSTNode<K, V> | [K | null | undefined, V | undefined] | null | undefined } keyNodeOrEntry - The parameter
10052
+ * `keyNodeOrEntry` can be of type `R` or `K | BSTNode<K, V> | [K | null | undefined, V | undefined] | null | undefined `.
9440
10053
  * @returns a boolean value indicating whether the input parameter `keyNodeOrEntry` is
9441
10054
  * an instance of the `BSTNode` class.
9442
10055
  */
@@ -9462,8 +10075,8 @@ var dataStructureTyped = (() => {
9462
10075
  * Space Complexity: O(log n)
9463
10076
  *
9464
10077
  * The `add` function in TypeScript adds a new node to a binary search tree based on the key value.
9465
- * @param {BTNRep<K, V, BSTNode<K, V>>} keyNodeOrEntry - The parameter
9466
- * `keyNodeOrEntry` can accept a value of type `R` or `BTNRep<K, V, BSTNode<K, V>>`.
10078
+ * @param {K | BSTNode<K, V> | [K | null | undefined, V | undefined] | null | undefined } keyNodeOrEntry - The parameter
10079
+ * `keyNodeOrEntry` can accept a value of type `R` or `K | BSTNode<K, V> | [K | null | undefined, V | undefined] | null | undefined `.
9467
10080
  * @param {V} [value] - The `value` parameter is an optional value that can be associated with the
9468
10081
  * key in the binary search tree. If provided, it will be stored in the node along with the key.
9469
10082
  * @returns a boolean value.
@@ -9565,22 +10178,20 @@ var dataStructureTyped = (() => {
9565
10178
  return 0;
9566
10179
  });
9567
10180
  const _dfs = (arr) => {
9568
- var _a;
9569
10181
  if (arr.length === 0) return;
9570
10182
  const mid = Math.floor((arr.length - 1) / 2);
9571
- let { key, value } = arr[mid];
10183
+ const { key, value } = arr[mid];
9572
10184
  const { orgIndex } = arr[mid];
9573
10185
  if (this.isRaw(key)) {
9574
10186
  const entry = this._toEntryFn(key);
9575
- key = entry[0];
9576
- value = (_a = entry[1]) != null ? _a : value;
10187
+ inserted[orgIndex] = this.add(entry);
10188
+ } else {
10189
+ inserted[orgIndex] = this.add(key, value);
9577
10190
  }
9578
- inserted[orgIndex] = this.add(key, value);
9579
10191
  _dfs(arr.slice(0, mid));
9580
10192
  _dfs(arr.slice(mid + 1));
9581
10193
  };
9582
10194
  const _iterate = () => {
9583
- var _a;
9584
10195
  const n = sorted.length;
9585
10196
  const stack = [[0, n - 1]];
9586
10197
  while (stack.length > 0) {
@@ -9589,14 +10200,14 @@ var dataStructureTyped = (() => {
9589
10200
  const [l, r] = popped;
9590
10201
  if (l <= r) {
9591
10202
  const m = l + Math.floor((r - l) / 2);
9592
- let { key, value } = sorted[m];
10203
+ const { key, value } = sorted[m];
9593
10204
  const { orgIndex } = sorted[m];
9594
10205
  if (this.isRaw(key)) {
9595
10206
  const entry = this._toEntryFn(key);
9596
- key = entry[0];
9597
- value = (_a = entry[1]) != null ? _a : value;
10207
+ inserted[orgIndex] = this.add(entry);
10208
+ } else {
10209
+ inserted[orgIndex] = this.add(key, value);
9598
10210
  }
9599
- inserted[orgIndex] = this.add(key, value);
9600
10211
  stack.push([m + 1, r]);
9601
10212
  stack.push([l, m - 1]);
9602
10213
  }
@@ -9616,7 +10227,7 @@ var dataStructureTyped = (() => {
9616
10227
  *
9617
10228
  * The function `search` in TypeScript overrides the search behavior in a binary tree structure based
9618
10229
  * on specified criteria.
9619
- * @param {BTNRep<K, V, BSTNode<K, V>> | NodePredicate<BSTNode<K, V>>} keyNodeEntryOrPredicate - The
10230
+ * @param {K | BSTNode<K, V> | [K | null | undefined, V | undefined] | null | undefined | NodePredicate<BSTNode<K, V>>} keyNodeEntryOrPredicate - The
9620
10231
  * `keyNodeEntryOrPredicate` parameter in the `override search` method can accept one of the
9621
10232
  * following types:
9622
10233
  * @param [onlyOne=false] - The `onlyOne` parameter is a boolean flag that determines whether the
@@ -9624,9 +10235,9 @@ var dataStructureTyped = (() => {
9624
10235
  * search will return as soon as a matching node is found. If `onlyOne` is set to `false`, the
9625
10236
  * @param {C} callback - The `callback` parameter in the `override search` function is a function
9626
10237
  * that will be called on each node that matches the search criteria. It is of type `C`, which
9627
- * extends `NodeCallback<BSTNode<K, V>>`. The callback function should accept a node of type `BSTNode<K, V>` as its
10238
+ * extends `NodeCallback<BSTNode<K, V> | null>`. The callback function should accept a node of type `BSTNode<K, V>` as its
9628
10239
  * argument and
9629
- * @param {BTNRep<K, V, BSTNode<K, V>>} startNode - The `startNode` parameter in the `override search`
10240
+ * @param {K | BSTNode<K, V> | [K | null | undefined, V | undefined] | null | undefined } startNode - The `startNode` parameter in the `override search`
9630
10241
  * method represents the node from which the search operation will begin. It is the starting point
9631
10242
  * for searching within the tree data structure. The method ensures that the `startNode` is a valid
9632
10243
  * node before proceeding with the search operation. If the `
@@ -9646,75 +10257,58 @@ var dataStructureTyped = (() => {
9646
10257
  let predicate;
9647
10258
  const isRange = this.isRange(keyNodeEntryOrPredicate);
9648
10259
  if (isRange) {
9649
- predicate = (node) => keyNodeEntryOrPredicate.isInRange(node.key, this._comparator);
10260
+ predicate = (node) => {
10261
+ if (!node) return false;
10262
+ return keyNodeEntryOrPredicate.isInRange(node.key, this._comparator);
10263
+ };
9650
10264
  } else {
9651
10265
  predicate = this._ensurePredicate(keyNodeEntryOrPredicate);
9652
10266
  }
9653
- const isToLeftByRange = (cur) => {
10267
+ const shouldVisitLeft = (cur) => {
10268
+ if (!cur) return false;
10269
+ if (!this.isRealNode(cur.left)) return false;
9654
10270
  if (isRange) {
9655
10271
  const range = keyNodeEntryOrPredicate;
9656
10272
  const leftS = this.isReverse ? range.high : range.low;
9657
10273
  const leftI = this.isReverse ? range.includeHigh : range.includeLow;
9658
10274
  return leftI && this._compare(cur.key, leftS) >= 0 || !leftI && this._compare(cur.key, leftS) > 0;
9659
10275
  }
9660
- return false;
10276
+ if (!isRange && !this._isPredicate(keyNodeEntryOrPredicate)) {
10277
+ const benchmarkKey = this._extractKey(keyNodeEntryOrPredicate);
10278
+ return benchmarkKey !== null && benchmarkKey !== void 0 && this._compare(cur.key, benchmarkKey) > 0;
10279
+ }
10280
+ return true;
9661
10281
  };
9662
- const isToRightByRange = (cur) => {
10282
+ const shouldVisitRight = (cur) => {
10283
+ if (!cur) return false;
10284
+ if (!this.isRealNode(cur.right)) return false;
9663
10285
  if (isRange) {
9664
10286
  const range = keyNodeEntryOrPredicate;
9665
10287
  const rightS = this.isReverse ? range.low : range.high;
9666
10288
  const rightI = this.isReverse ? range.includeLow : range.includeLow;
9667
10289
  return rightI && this._compare(cur.key, rightS) <= 0 || !rightI && this._compare(cur.key, rightS) < 0;
9668
10290
  }
9669
- return false;
10291
+ if (!isRange && !this._isPredicate(keyNodeEntryOrPredicate)) {
10292
+ const benchmarkKey = this._extractKey(keyNodeEntryOrPredicate);
10293
+ return benchmarkKey !== null && benchmarkKey !== void 0 && this._compare(cur.key, benchmarkKey) < 0;
10294
+ }
10295
+ return true;
9670
10296
  };
9671
- const ans = [];
9672
- if (iterationType === "RECURSIVE") {
9673
- const dfs = (cur) => {
9674
- if (predicate(cur)) {
9675
- ans.push(callback(cur));
9676
- if (onlyOne) return;
9677
- }
9678
- if (!this.isRealNode(cur.left) && !this.isRealNode(cur.right)) return;
9679
- if (isRange) {
9680
- if (this.isRealNode(cur.left) && isToLeftByRange(cur)) dfs(cur.left);
9681
- if (this.isRealNode(cur.right) && isToRightByRange(cur)) dfs(cur.right);
9682
- } else if (!this._isPredicate(keyNodeEntryOrPredicate)) {
9683
- const benchmarkKey = this._extractKey(keyNodeEntryOrPredicate);
9684
- if (this.isRealNode(cur.left) && benchmarkKey !== null && benchmarkKey !== void 0 && this._compare(cur.key, benchmarkKey) > 0)
9685
- dfs(cur.left);
9686
- if (this.isRealNode(cur.right) && benchmarkKey !== null && benchmarkKey !== void 0 && this._compare(cur.key, benchmarkKey) < 0)
9687
- dfs(cur.right);
9688
- } else {
9689
- if (this.isRealNode(cur.left)) dfs(cur.left);
9690
- if (this.isRealNode(cur.right)) dfs(cur.right);
9691
- }
9692
- };
9693
- dfs(startNode);
9694
- } else {
9695
- const stack = [startNode];
9696
- while (stack.length > 0) {
9697
- const cur = stack.pop();
9698
- if (predicate(cur)) {
9699
- ans.push(callback(cur));
9700
- if (onlyOne) return ans;
9701
- }
9702
- if (isRange) {
9703
- if (this.isRealNode(cur.left) && isToLeftByRange(cur)) stack.push(cur.left);
9704
- if (this.isRealNode(cur.right) && isToRightByRange(cur)) stack.push(cur.right);
9705
- } else if (!this._isPredicate(keyNodeEntryOrPredicate)) {
9706
- const benchmarkKey = this._extractKey(keyNodeEntryOrPredicate);
9707
- if (this.isRealNode(cur.right) && benchmarkKey !== null && benchmarkKey !== void 0 && this._compare(cur.key, benchmarkKey) < 0)
9708
- stack.push(cur.right);
9709
- if (this.isRealNode(cur.left) && benchmarkKey !== null && benchmarkKey !== void 0 && this._compare(cur.key, benchmarkKey) > 0)
9710
- stack.push(cur.left);
9711
- } else {
9712
- if (this.isRealNode(cur.right)) stack.push(cur.right);
9713
- if (this.isRealNode(cur.left)) stack.push(cur.left);
9714
- }
10297
+ return super._dfs(
10298
+ callback,
10299
+ "IN",
10300
+ onlyOne,
10301
+ startNode,
10302
+ iterationType,
10303
+ false,
10304
+ shouldVisitLeft,
10305
+ shouldVisitRight,
10306
+ () => true,
10307
+ (cur) => {
10308
+ if (cur) return predicate(cur);
10309
+ return false;
9715
10310
  }
9716
- }
9717
- return ans;
10311
+ );
9718
10312
  }
9719
10313
  /**
9720
10314
  * Time Complexity: O(log n)
@@ -9725,9 +10319,9 @@ var dataStructureTyped = (() => {
9725
10319
  * either a `Range` object or an array of two elements representing the range boundaries.
9726
10320
  * @param {C} callback - The `callback` parameter in the `rangeSearch` function is a callback
9727
10321
  * function that is used to process each node that is found within the specified range during the
9728
- * search operation. It is of type `NodeCallback<BSTNode<K, V>>`, where `BSTNode<K, V>` is the type of nodes in the
10322
+ * search operation. It is of type `NodeCallback<BSTNode<K, V> | null>`, where `BSTNode<K, V>` is the type of nodes in the
9729
10323
  * data structure.
9730
- * @param {BTNRep<K, V, BSTNode<K, V>>} startNode - The `startNode` parameter in the `rangeSearch`
10324
+ * @param {K | BSTNode<K, V> | [K | null | undefined, V | undefined] | null | undefined } startNode - The `startNode` parameter in the `rangeSearch`
9731
10325
  * function represents the node from which the search for nodes within the specified range will
9732
10326
  * begin. It is the starting point for the range search operation.
9733
10327
  * @param {IterationType} iterationType - The `iterationType` parameter in the `rangeSearch` function
@@ -9746,8 +10340,8 @@ var dataStructureTyped = (() => {
9746
10340
  * Space Complexity: O(log n)
9747
10341
  *
9748
10342
  * This function retrieves a node based on a given keyNodeEntryOrPredicate within a binary search tree structure.
9749
- * @param {BTNRep<K, V, BSTNode<K, V>> | NodePredicate<BSTNode<K, V>>} keyNodeEntryOrPredicate - The `keyNodeEntryOrPredicate`
9750
- * parameter can be of type `BTNRep<K, V, BSTNode<K, V>>`, `R`, or `NodePredicate<BSTNode<K, V>>`.
10343
+ * @param {K | BSTNode<K, V> | [K | null | undefined, V | undefined] | null | undefined | NodePredicate<BSTNode<K, V>>} keyNodeEntryOrPredicate - The `keyNodeEntryOrPredicate`
10344
+ * parameter can be of type `K | BSTNode<K, V> | [K | null | undefined, V | undefined] | null | undefined `, `R`, or `NodePredicate<BSTNode<K, V>>`.
9751
10345
  * @param {BSTNOptKeyOrNode<K, BSTNode<K, V>>} startNode - The `startNode` parameter in the `getNode` method
9752
10346
  * is used to specify the starting point for searching nodes in the binary search tree. If no
9753
10347
  * specific starting point is provided, the default value is set to `this._root`, which is the root
@@ -9769,24 +10363,30 @@ var dataStructureTyped = (() => {
9769
10363
  * Time complexity: O(n)
9770
10364
  * Space complexity: O(n)
9771
10365
  *
9772
- * The function overrides the depth-first search method and returns an array of the return types of
9773
- * the callback function.
10366
+ * The function `dfs` in TypeScript overrides the base class method with default parameters and
10367
+ * returns the result of the super class `dfs` method.
9774
10368
  * @param {C} callback - The `callback` parameter is a function that will be called for each node
9775
- * during the depth-first search traversal. It is an optional parameter and defaults to
9776
- * `this._DEFAULT_NODE_CALLBACK`. The type `C` represents the type of the callback function.
9777
- * @param {DFSOrderPattern} [pattern=IN] - The "pattern" parameter in the code snippet refers to the
9778
- * order in which the Depth-First Search (DFS) algorithm visits the nodes in a tree or graph. It can
9779
- * take one of the following values:
9780
- * @param {BTNRep<K, V, BSTNode<K, V>>} startNode - The `startNode` parameter is the starting
9781
- * point for the depth-first search traversal. It can be either a root node, a key-value pair, or a
9782
- * node entry. If not specified, the default value is the root of the tree.
9783
- * @param {IterationType} [iterationType=ITERATIVE] - The `iterationType` parameter specifies the
9784
- * type of iteration to be used during the Depth-First Search (DFS) traversal. It can have one of the
9785
- * following values:
9786
- * @returns The method is returning an array of the return type of the callback function.
10369
+ * visited during the Depth-First Search traversal. It is a generic type `C` that extends the
10370
+ * `NodeCallback` interface for `BSTNode<K, V>`. The default value for `callback` is `this._
10371
+ * @param {DFSOrderPattern} [pattern=IN] - The `pattern` parameter in the `override dfs` method
10372
+ * specifies the order in which the Depth-First Search (DFS) traversal should be performed on the
10373
+ * Binary Search Tree (BST). The possible values for the `pattern` parameter are:
10374
+ * @param {boolean} [onlyOne=false] - The `onlyOne` parameter in the `override dfs` method is a
10375
+ * boolean flag that indicates whether you want to stop the depth-first search traversal after
10376
+ * finding the first matching node or continue searching for all matching nodes. If `onlyOne` is set
10377
+ * to `true`, the traversal will stop after finding
10378
+ * @param {K | BSTNode<K, V> | [K | null | undefined, V | undefined] | null | undefined} startNode -
10379
+ * The `startNode` parameter in the `override dfs` method can be one of the following types:
10380
+ * @param {IterationType} iterationType - The `iterationType` parameter in the `override dfs` method
10381
+ * specifies the type of iteration to be performed during the Depth-First Search (DFS) traversal of a
10382
+ * Binary Search Tree (BST). It is used to determine the order in which nodes are visited during the
10383
+ * traversal. The possible values for `
10384
+ * @returns The `override` function is returning the result of calling the `dfs` method from the
10385
+ * superclass, with the provided arguments `callback`, `pattern`, `onlyOne`, `startNode`, and
10386
+ * `iterationType`. The return type is an array of the return type of the callback function `C`.
9787
10387
  */
9788
- dfs(callback = this._DEFAULT_NODE_CALLBACK, pattern = "IN", startNode = this._root, iterationType = this.iterationType) {
9789
- return super.dfs(callback, pattern, startNode, iterationType);
10388
+ dfs(callback = this._DEFAULT_NODE_CALLBACK, pattern = "IN", onlyOne = false, startNode = this._root, iterationType = this.iterationType) {
10389
+ return super.dfs(callback, pattern, onlyOne, startNode, iterationType);
9790
10390
  }
9791
10391
  /**
9792
10392
  * Time complexity: O(n)
@@ -9797,7 +10397,7 @@ var dataStructureTyped = (() => {
9797
10397
  * @param {C} callback - The `callback` parameter is a function that will be called for each node
9798
10398
  * visited during the breadth-first search. It should take a single argument, which is the current
9799
10399
  * node being visited, and it can return a value of any type.
9800
- * @param {BTNRep<K, V, BSTNode<K, V>>} startNode - The `startNode` parameter is the starting
10400
+ * @param {K | BSTNode<K, V> | [K | null | undefined, V | undefined] | null | undefined } startNode - The `startNode` parameter is the starting
9801
10401
  * point for the breadth-first search. It can be either a root node, a key-value pair, or an entry
9802
10402
  * object. If no value is provided, the default value is the root of the tree.
9803
10403
  * @param {IterationType} iterationType - The `iterationType` parameter is used to specify the type
@@ -9815,9 +10415,9 @@ var dataStructureTyped = (() => {
9815
10415
  * The function overrides the listLevels method from the superclass and returns an array of arrays
9816
10416
  * containing the results of the callback function applied to each level of the tree.
9817
10417
  * @param {C} callback - The `callback` parameter is a generic type `C` that extends
9818
- * `NodeCallback<BSTNode<K, V>>`. It represents a callback function that will be called for each node in the
10418
+ * `NodeCallback<BSTNode<K, V> | null>`. It represents a callback function that will be called for each node in the
9819
10419
  * tree during the iteration process.
9820
- * @param {BTNRep<K, V, BSTNode<K, V>>} startNode - The `startNode` parameter is the starting
10420
+ * @param {K | BSTNode<K, V> | [K | null | undefined, V | undefined] | null | undefined } startNode - The `startNode` parameter is the starting
9821
10421
  * point for listing the levels of the binary tree. It can be either a root node of the tree, a
9822
10422
  * key-value pair representing a node in the tree, or a key representing a node in the tree. If no
9823
10423
  * value is provided, the root of
@@ -9841,7 +10441,7 @@ var dataStructureTyped = (() => {
9841
10441
  * @param {CP} lesserOrGreater - The `lesserOrGreater` parameter is used to determine whether to
9842
10442
  * traverse nodes that are lesser, greater, or both than the `targetNode`. It accepts the values -1,
9843
10443
  * 0, or 1, where:
9844
- * @param {BTNRep<K, V, BSTNode<K, V>>} targetNode - The `targetNode` parameter is the node in
10444
+ * @param {K | BSTNode<K, V> | [K | null | undefined, V | undefined] | null | undefined } targetNode - The `targetNode` parameter is the node in
9845
10445
  * the binary tree that you want to start traversing from. It can be specified either by providing
9846
10446
  * the key of the node, the node itself, or an entry containing the key and value of the node. If no
9847
10447
  * `targetNode` is provided,
@@ -9867,7 +10467,7 @@ var dataStructureTyped = (() => {
9867
10467
  return ans;
9868
10468
  } else {
9869
10469
  const queue = new Queue([this._root]);
9870
- while (queue.size > 0) {
10470
+ while (queue.length > 0) {
9871
10471
  const cur = queue.shift();
9872
10472
  if (this.isRealNode(cur)) {
9873
10473
  const compared = this._compare(cur.key, targetKey);
@@ -9900,8 +10500,8 @@ var dataStructureTyped = (() => {
9900
10500
  if (l > r) return;
9901
10501
  const m = l + Math.floor((r - l) / 2);
9902
10502
  const midNode = sorted[m];
9903
- if (this._isMapMode) this.add(midNode.key);
9904
- else this.add([midNode.key, midNode.value]);
10503
+ if (this._isMapMode && midNode !== null) this.add(midNode.key);
10504
+ else if (midNode !== null) this.add([midNode.key, midNode.value]);
9905
10505
  buildBalanceBST(l, m - 1);
9906
10506
  buildBalanceBST(m + 1, r);
9907
10507
  };
@@ -9916,8 +10516,8 @@ var dataStructureTyped = (() => {
9916
10516
  if (l <= r) {
9917
10517
  const m = l + Math.floor((r - l) / 2);
9918
10518
  const midNode = sorted[m];
9919
- if (this._isMapMode) this.add(midNode.key);
9920
- else this.add([midNode.key, midNode.value]);
10519
+ if (this._isMapMode && midNode !== null) this.add(midNode.key);
10520
+ else if (midNode !== null) this.add([midNode.key, midNode.value]);
9921
10521
  stack.push([m + 1, r]);
9922
10522
  stack.push([l, m - 1]);
9923
10523
  }
@@ -10020,8 +10620,8 @@ var dataStructureTyped = (() => {
10020
10620
  * Space Complexity: O(1)
10021
10621
  *
10022
10622
  * The function overrides a method and converts a key, value pair or entry or raw element to a node.
10023
- * @param {BTNRep<K, V, BSTNode<K, V>>} keyNodeOrEntry - A variable that can be of
10024
- * type R or BTNRep<K, V, BSTNode<K, V>>. It represents either a key, a node, an entry, or a raw
10623
+ * @param {K | BSTNode<K, V> | [K | null | undefined, V | undefined] | null | undefined } keyNodeOrEntry - A variable that can be of
10624
+ * type R or K | BSTNode<K, V> | [K | null | undefined, V | undefined] | null | undefined . It represents either a key, a node, an entry, or a raw
10025
10625
  * element.
10026
10626
  * @param {V} [value] - The `value` parameter is an optional value of type `V`. It represents the
10027
10627
  * value associated with a key in a key-value pair.
@@ -10669,7 +11269,8 @@ var dataStructureTyped = (() => {
10669
11269
  * This TypeScript constructor initializes an AVLTree with keys, nodes, entries, or raw data provided
10670
11270
  * in an iterable format.
10671
11271
  * @param keysNodesEntriesOrRaws - The `keysNodesEntriesOrRaws` parameter in the constructor is an
10672
- * iterable that can contain either `BTNRep<K, V, AVLTreeNode<K, V>>` objects or `R` objects. It is
11272
+ * iterable that can contain either `
11273
+ K | AVLTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined ` objects or `R` objects. It is
10673
11274
  * used to initialize the AVLTree with key-value pairs or raw data entries. If provided
10674
11275
  * @param [options] - The `options` parameter in the constructor is of type `AVLTreeOptions<K, V,
10675
11276
  * R>`. It is an optional parameter that allows you to specify additional options for configuring the
@@ -10719,8 +11320,9 @@ var dataStructureTyped = (() => {
10719
11320
  * Space Complexity: O(1)
10720
11321
  *
10721
11322
  * The function checks if the input is an instance of AVLTreeNode.
10722
- * @param {BTNRep<K, V, AVLTreeNode<K, V>>} keyNodeOrEntry - The parameter
10723
- * `keyNodeOrEntry` can be of type `R` or `BTNRep<K, V, AVLTreeNode<K, V>>`.
11323
+ * @param {K | AVLTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined } keyNodeOrEntry - The parameter
11324
+ * `keyNodeOrEntry` can be of type `R` or `
11325
+ K | AVLTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined `.
10724
11326
  * @returns a boolean value indicating whether the input parameter `keyNodeOrEntry` is
10725
11327
  * an instance of the `AVLTreeNode` class.
10726
11328
  */
@@ -10733,8 +11335,9 @@ var dataStructureTyped = (() => {
10733
11335
  *
10734
11336
  * The function overrides the add method of a class and inserts a key-value pair into a data
10735
11337
  * structure, then balances the path.
10736
- * @param {BTNRep<K, V, AVLTreeNode<K, V>>} keyNodeOrEntry - The parameter
10737
- * `keyNodeOrEntry` can accept values of type `R`, `BTNRep<K, V, AVLTreeNode<K, V>>`
11338
+ * @param { K | AVLTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined } keyNodeOrEntry - The parameter
11339
+ * `keyNodeOrEntry` can accept values of type `R`, `
11340
+ K | AVLTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined `
10738
11341
  * @param {V} [value] - The `value` parameter is an optional value that you want to associate with
10739
11342
  * the key or node being added to the data structure.
10740
11343
  * @returns The method is returning a boolean value.
@@ -10751,7 +11354,7 @@ var dataStructureTyped = (() => {
10751
11354
  *
10752
11355
  * The function overrides the delete method in a TypeScript class, performs deletion, and then
10753
11356
  * balances the tree if necessary.
10754
- * @param {BTNRep<K, V, AVLTreeNode<K, V>>} keyNodeOrEntry - The `keyNodeOrEntry`
11357
+ * @param { K | AVLTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined } keyNodeOrEntry - The `keyNodeOrEntry`
10755
11358
  * parameter in the `override delete` method can be one of the following types:
10756
11359
  * @returns The `delete` method is being overridden in this code snippet. It first calls the `delete`
10757
11360
  * method from the superclass (presumably a parent class) with the provided `predicate`, which could
@@ -11035,8 +11638,9 @@ var dataStructureTyped = (() => {
11035
11638
  *
11036
11639
  * The `_balancePath` function is used to update the heights of nodes and perform rotation operations
11037
11640
  * to restore balance in an AVL tree after inserting a node.
11038
- * @param {BTNRep<K, V, AVLTreeNode<K, V>>} node - The `node` parameter can be of type `R` or
11039
- * `BTNRep<K, V, AVLTreeNode<K, V>>`.
11641
+ * @param { K | AVLTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined } node - The `node` parameter can be of type `R` or
11642
+ * `
11643
+ K | AVLTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined `.
11040
11644
  */
11041
11645
  _balancePath(node) {
11042
11646
  node = this.ensureNode(node);
@@ -11129,7 +11733,7 @@ var dataStructureTyped = (() => {
11129
11733
  * This TypeScript constructor initializes a Red-Black Tree with optional keys, nodes, entries, or
11130
11734
  * raw data.
11131
11735
  * @param keysNodesEntriesOrRaws - The `keysNodesEntriesOrRaws` parameter in the constructor is an
11132
- * iterable that can contain either `BTNRep<K, V, RedBlackTreeNode<K, V>>` objects or `R` objects. It
11736
+ * iterable that can contain either `K | RedBlackTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined` objects or `R` objects. It
11133
11737
  * is used to initialize the Red-Black Tree with keys, nodes, entries, or
11134
11738
  * @param [options] - The `options` parameter in the constructor is of type `RedBlackTreeOptions<K,
11135
11739
  * V, R>`. It is an optional parameter that allows you to specify additional options for the
@@ -11189,8 +11793,8 @@ var dataStructureTyped = (() => {
11189
11793
  * Space Complexity: O(1)
11190
11794
  *
11191
11795
  * The function checks if the input is an instance of the RedBlackTreeNode class.
11192
- * @param {BTNRep<K, V, RedBlackTreeNode<K, V>>} keyNodeOrEntry - The parameter
11193
- * `keyNodeOrEntry` can be of type `R` or `BTNRep<K, V, RedBlackTreeNode<K, V>>`.
11796
+ * @param {K | RedBlackTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined} keyNodeOrEntry - The parameter
11797
+ * `keyNodeOrEntry` can be of type `R` or `K | RedBlackTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined`.
11194
11798
  * @returns a boolean value indicating whether the input parameter `keyNodeOrEntry` is
11195
11799
  * an instance of the `RedBlackTreeNode` class.
11196
11800
  */
@@ -11214,8 +11818,8 @@ var dataStructureTyped = (() => {
11214
11818
  *
11215
11819
  * The function adds a new node to a binary search tree and returns true if the node was successfully
11216
11820
  * added.
11217
- * @param {BTNRep<K, V, RedBlackTreeNode<K, V>>} keyNodeOrEntry - The parameter
11218
- * `keyNodeOrEntry` can accept a value of type `R` or `BTNRep<K, V, RedBlackTreeNode<K, V>>`.
11821
+ * @param {K | RedBlackTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined} keyNodeOrEntry - The parameter
11822
+ * `keyNodeOrEntry` can accept a value of type `R` or `K | RedBlackTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined`.
11219
11823
  * @param {V} [value] - The `value` parameter is an optional value that you want to associate with
11220
11824
  * the key in the data structure. It represents the value that you want to add or update in the data
11221
11825
  * structure.
@@ -11249,7 +11853,7 @@ var dataStructureTyped = (() => {
11249
11853
  *
11250
11854
  * The function overrides the delete method in a binary tree data structure to remove a node based on
11251
11855
  * a given predicate and maintain the binary search tree properties.
11252
- * @param {BTNRep<K, V, RedBlackTreeNode<K, V>>} keyNodeOrEntry - The `keyNodeOrEntry`
11856
+ * @param {K | RedBlackTreeNode<K, V> | [K | null | undefined, V | undefined] | null | undefined} keyNodeOrEntry - The `keyNodeOrEntry`
11253
11857
  * parameter in the `override delete` method is used to specify the condition or key based on which a
11254
11858
  * node should be deleted from the binary tree. It can be a key, a node, an entry, or a predicate
11255
11859
  * function that determines which node(s) should be deleted.
@@ -11692,63 +12296,77 @@ var dataStructureTyped = (() => {
11692
12296
  iterationType: this.iterationType,
11693
12297
  specifyComparable: this._specifyComparable,
11694
12298
  toEntryFn: this._toEntryFn,
11695
- isReverse: this._isReverse
12299
+ isReverse: this._isReverse,
12300
+ isMapMode: this._isMapMode
11696
12301
  }, options));
11697
12302
  }
11698
12303
  /**
11699
12304
  * Time Complexity: O(1)
11700
12305
  * Space Complexity: O(1)
11701
12306
  *
11702
- * The function `createNode` overrides the method to create a new AVLTreeMultiMapNode with a
11703
- * specified key and an empty array of values.
11704
- * @param {K} key - The `key` parameter in the `createNode` method represents the key of the node
11705
- * that will be created in the AVLTreeMultiMap.
11706
- * @returns An AVLTreeMultiMapNode object is being returned, initialized with the provided key and an
11707
- * empty array.
12307
+ * The `createNode` function in TypeScript overrides the default implementation to create a new
12308
+ * AVLTreeMultiMapNode with a specified key and value array.
12309
+ * @param {K} key - The `key` parameter represents the key of the node being created in the
12310
+ * AVLTreeMultiMap.
12311
+ * @param {V[]} value - The `value` parameter in the `createNode` method represents an array of
12312
+ * values associated with a specific key in the AVLTreeMultiMapNode. If no value is provided when
12313
+ * calling the method, an empty array `[]` is used as the default value.
12314
+ * @returns An AVLTreeMultiMapNode object is being returned, with the specified key and value. If the
12315
+ * AVLTreeMultiMap is in map mode, an empty array is used as the value, otherwise the provided value
12316
+ * array is used.
11708
12317
  */
11709
- createNode(key) {
11710
- return new AVLTreeMultiMapNode(key, []);
12318
+ createNode(key, value = []) {
12319
+ return new AVLTreeMultiMapNode(key, this._isMapMode ? [] : value);
11711
12320
  }
11712
12321
  /**
11713
12322
  * Time Complexity: O(log n)
11714
12323
  * Space Complexity: O(log n)
11715
12324
  *
11716
- * The function `add` in TypeScript overrides the superclass method to add key-value pairs to an AVL
11717
- * tree multi-map.
11718
- * @param {BTNRep<K, V[], AVLTreeMultiMapNode<K, V>> | K} keyNodeOrEntry - The `keyNodeOrEntry`
11719
- * parameter in the `override add` method can be either a key-value pair entry or just a key. If it
11720
- * is a key-value pair entry, it will be in the format `[key, values]`, where `key` is the key and
11721
- * `values`
11722
- * @param {V} [value] - The `value` parameter in the `override add` method represents the value that
11723
- * you want to add to the AVLTreeMultiMap. It can be a single value or an array of values associated
11724
- * with a specific key.
11725
- * @returns The `override add` method is returning a boolean value, which indicates whether the
11726
- * addition operation was successful or not.
12325
+ * The function `add` in this TypeScript code overrides the superclass method to add key-value pairs
12326
+ * to an AVLTreeMultiMap, handling different input types and scenarios.
12327
+ * @param [key] - The `key` parameter in the `override add` method represents the key of the entry to
12328
+ * be added to the AVLTreeMultiMap. It can be of type `K`, which is the key type of the map. The key
12329
+ * can be a single key value, a node of the AVLTree
12330
+ * @param {V[]} [values] - The `values` parameter in the `add` method represents an array of values
12331
+ * that you want to add to the AVLTreeMultiMap. It can contain one or more values associated with a
12332
+ * specific key.
12333
+ * @returns The `add` method is returning a boolean value, which indicates whether the operation was
12334
+ * successful or not.
11727
12335
  */
11728
12336
  add(keyNodeOrEntry, value) {
11729
12337
  if (this.isRealNode(keyNodeOrEntry)) return super.add(keyNodeOrEntry);
11730
12338
  const _commonAdd = (key, values) => {
11731
12339
  if (key === void 0 || key === null) return false;
11732
- const existingValues = this.get(key);
11733
- if (existingValues !== void 0 && values !== void 0) {
11734
- for (const value2 of values) existingValues.push(value2);
11735
- return true;
11736
- }
11737
- const existingNode = this.getNode(key);
11738
- if (this.isRealNode(existingNode)) {
11739
- if (existingValues === void 0) {
11740
- super.add(key, values);
11741
- return true;
11742
- }
11743
- if (values !== void 0) {
12340
+ const _addToValues = () => {
12341
+ const existingValues = this.get(key);
12342
+ if (existingValues !== void 0 && values !== void 0) {
11744
12343
  for (const value2 of values) existingValues.push(value2);
11745
12344
  return true;
12345
+ }
12346
+ return false;
12347
+ };
12348
+ const _addByNode = () => {
12349
+ const existingNode = this.getNode(key);
12350
+ if (this.isRealNode(existingNode)) {
12351
+ const existingValues = this.get(existingNode);
12352
+ if (existingValues === void 0) {
12353
+ super.add(key, values);
12354
+ return true;
12355
+ }
12356
+ if (values !== void 0) {
12357
+ for (const value2 of values) existingValues.push(value2);
12358
+ return true;
12359
+ } else {
12360
+ return false;
12361
+ }
11746
12362
  } else {
11747
- return false;
12363
+ return super.add(key, values);
11748
12364
  }
11749
- } else {
11750
- return super.add(key, values);
12365
+ };
12366
+ if (this._isMapMode) {
12367
+ return _addByNode() || _addToValues();
11751
12368
  }
12369
+ return _addToValues() || _addByNode();
11752
12370
  };
11753
12371
  if (this.isEntry(keyNodeOrEntry)) {
11754
12372
  const [key, values] = keyNodeOrEntry;
@@ -11762,7 +12380,7 @@ var dataStructureTyped = (() => {
11762
12380
  *
11763
12381
  * The function `deleteValue` removes a specific value from a key in an AVLTreeMultiMap data
11764
12382
  * structure and deletes the entire node if no values are left for that key.
11765
- * @param {BTNRep<K, V[], AVLTreeMultiMapNode<K, V>> | K} keyNodeOrEntry - The `keyNodeOrEntry`
12383
+ * @param {K | AVLTreeMultiMapNode<K, V> | [K | null | undefined, V[] | undefined] | null | undefined | K} keyNodeOrEntry - The `keyNodeOrEntry`
11766
12384
  * parameter in the `deleteValue` function can be either a `BTNRep` object representing a key-value
11767
12385
  * pair in the AVLTreeMultiMapNode, or just the key itself.
11768
12386
  * @param {V} value - The `value` parameter in the `deleteValue` function represents the specific
@@ -11848,7 +12466,7 @@ var dataStructureTyped = (() => {
11848
12466
  * additional options for configuring the TreeMultiMap instance.
11849
12467
  */
11850
12468
  constructor(keysNodesEntriesOrRaws = [], options) {
11851
- super([], __spreadProps(__spreadValues({}, options), { isMapMode: true }));
12469
+ super([], __spreadValues({}, options));
11852
12470
  if (keysNodesEntriesOrRaws) {
11853
12471
  this.addMany(keysNodesEntriesOrRaws);
11854
12472
  }
@@ -11871,35 +12489,38 @@ var dataStructureTyped = (() => {
11871
12489
  iterationType: this.iterationType,
11872
12490
  specifyComparable: this._specifyComparable,
11873
12491
  toEntryFn: this._toEntryFn,
11874
- isReverse: this._isReverse
12492
+ isReverse: this._isReverse,
12493
+ isMapMode: this._isMapMode
11875
12494
  }, options));
11876
12495
  }
11877
12496
  /**
11878
12497
  * Time Complexity: O(1)
11879
12498
  * Space Complexity: O(1)
11880
12499
  *
11881
- * The function `createNode` overrides the method to create a new `TreeMultiMapNode` with a specified
11882
- * key and an empty array of values.
11883
- * @param {K} key - The `key` parameter in the `createNode` method represents the key of the node
11884
- * that will be created in the TreeMultiMap data structure.
11885
- * @returns A new instance of `TreeMultiMapNode<K, V>` is being returned, with the specified key and
11886
- * an empty array as its value.
12500
+ * The function `createNode` overrides the creation of a new TreeMultiMapNode with a specified key
12501
+ * and value array.
12502
+ * @param {K} key - The `key` parameter represents the key of the node being created in the
12503
+ * `TreeMultiMap`.
12504
+ * @param {V[]} value - The `value` parameter in the `createNode` method represents an array of
12505
+ * values associated with a specific key in the TreeMultiMap data structure.
12506
+ * @returns A new instance of `TreeMultiMapNode<K, V>` is being returned with the specified key and
12507
+ * value. If `_isMapMode` is true, an empty array is passed as the value, otherwise the provided
12508
+ * value is used.
11887
12509
  */
11888
- createNode(key) {
11889
- return new TreeMultiMapNode(key, []);
12510
+ createNode(key, value = []) {
12511
+ return new TreeMultiMapNode(key, this._isMapMode ? [] : value);
11890
12512
  }
11891
12513
  /**
11892
12514
  * Time Complexity: O(log n)
11893
12515
  * Space Complexity: O(log n)
11894
12516
  *
11895
- * The function `add` in TypeScript overrides the superclass method to add key-value pairs to a
11896
- * TreeMultiMapNode, handling different input types and scenarios.
11897
- * @param {BTNRep<K, V[], TreeMultiMapNode<K, V>> | K} keyNodeOrEntry - The `keyNodeOrEntry`
11898
- * parameter in the `override add` method can be either a `BTNRep` object containing a key, an array
11899
- * of values, and a `TreeMultiMapNode`, or just a key.
11900
- * @param {V} [value] - The `value` parameter in the `override add` method represents the value that
11901
- * you want to add to the TreeMultiMap. If the key is already present in the map, the new value will
11902
- * be added to the existing list of values associated with that key. If the key is not present,
12517
+ * The function overrides the add method to handle different types of input for a TreeMultiMap data
12518
+ * structure.
12519
+ * @param [key] - The `key` parameter in the `override add` method represents the key of the entry to
12520
+ * be added to the TreeMultiMap. It can be of type `K`, which is the key type of the TreeMultiMap, or
12521
+ * it can be a TreeMultiMapNode containing the key and its
12522
+ * @param {V[]} [values] - The `values` parameter in the `add` method represents an array of values
12523
+ * that you want to add to the TreeMultiMap. It can contain one or more values of type `V`.
11903
12524
  * @returns The `add` method is returning a boolean value, which indicates whether the operation was
11904
12525
  * successful or not.
11905
12526
  */
@@ -11907,26 +12528,36 @@ var dataStructureTyped = (() => {
11907
12528
  if (this.isRealNode(keyNodeOrEntry)) return super.add(keyNodeOrEntry);
11908
12529
  const _commonAdd = (key, values) => {
11909
12530
  if (key === void 0 || key === null) return false;
11910
- const existingValues = this.get(key);
11911
- if (existingValues !== void 0 && values !== void 0) {
11912
- for (const value2 of values) existingValues.push(value2);
11913
- return true;
11914
- }
11915
- const existingNode = this.getNode(key);
11916
- if (this.isRealNode(existingNode)) {
11917
- if (existingValues === void 0) {
11918
- super.add(key, values);
11919
- return true;
11920
- }
11921
- if (values !== void 0) {
12531
+ const _addToValues = () => {
12532
+ const existingValues = this.get(key);
12533
+ if (existingValues !== void 0 && values !== void 0) {
11922
12534
  for (const value2 of values) existingValues.push(value2);
11923
12535
  return true;
12536
+ }
12537
+ return false;
12538
+ };
12539
+ const _addByNode = () => {
12540
+ const existingNode = this.getNode(key);
12541
+ if (this.isRealNode(existingNode)) {
12542
+ const existingValues = this.get(existingNode);
12543
+ if (existingValues === void 0) {
12544
+ super.add(key, values);
12545
+ return true;
12546
+ }
12547
+ if (values !== void 0) {
12548
+ for (const value2 of values) existingValues.push(value2);
12549
+ return true;
12550
+ } else {
12551
+ return false;
12552
+ }
11924
12553
  } else {
11925
- return false;
12554
+ return super.add(key, values);
11926
12555
  }
11927
- } else {
11928
- return super.add(key, values);
12556
+ };
12557
+ if (this._isMapMode) {
12558
+ return _addByNode() || _addToValues();
11929
12559
  }
12560
+ return _addToValues() || _addByNode();
11930
12561
  };
11931
12562
  if (this.isEntry(keyNodeOrEntry)) {
11932
12563
  const [key, values] = keyNodeOrEntry;
@@ -11940,7 +12571,7 @@ var dataStructureTyped = (() => {
11940
12571
  *
11941
12572
  * The function `deleteValue` removes a specific value from a key in a TreeMultiMap data structure
11942
12573
  * and deletes the entire node if no values are left for that key.
11943
- * @param {BTNRep<K, V[], TreeMultiMapNode<K, V>> | K} keyNodeOrEntry - The `keyNodeOrEntry`
12574
+ * @param {K | TreeMultiMapNode<K, V> | [K | null | undefined, V[] | undefined] | null | undefined} keyNodeOrEntry - The `keyNodeOrEntry`
11944
12575
  * parameter in the `deleteValue` function can be either a `BTNRep` object containing a key and an
11945
12576
  * array of values, or just a key itself.
11946
12577
  * @param {V} value - The `value` parameter in the `deleteValue` function represents the specific
@@ -12049,7 +12680,7 @@ var dataStructureTyped = (() => {
12049
12680
  */
12050
12681
  getComputedCount() {
12051
12682
  let sum = 0;
12052
- this.dfs((node) => sum += node.count);
12683
+ this.dfs((node) => sum += node ? node.count : 0);
12053
12684
  return sum;
12054
12685
  }
12055
12686
  /**
@@ -12086,8 +12717,8 @@ var dataStructureTyped = (() => {
12086
12717
  }
12087
12718
  /**
12088
12719
  * The function checks if the input is an instance of the TreeCounterNode class.
12089
- * @param {BTNRep<K, V, TreeCounterNode<K, V>>} keyNodeOrEntry - The parameter
12090
- * `keyNodeOrEntry` can be of type `R` or `BTNRep<K, V, TreeCounterNode<K, V>>`.
12720
+ * @param {K | TreeCounterNode<K, V> | [K | null | undefined, V | undefined] | null | undefined} keyNodeOrEntry - The parameter
12721
+ * `keyNodeOrEntry` can be of type `R` or `K | TreeCounterNode<K, V> | [K | null | undefined, V | undefined] | null | undefined`.
12091
12722
  * @returns a boolean value indicating whether the input parameter `keyNodeOrEntry` is
12092
12723
  * an instance of the `TreeCounterNode` class.
12093
12724
  */
@@ -12100,7 +12731,7 @@ var dataStructureTyped = (() => {
12100
12731
  *
12101
12732
  * The function overrides the add method of a class and adds a new node to a data structure, updating
12102
12733
  * the count and returning a boolean indicating success.
12103
- * @param {BTNRep<K, V, TreeCounterNode<K, V>>} keyNodeOrEntry - The
12734
+ * @param {K | TreeCounterNode<K, V> | [K | null | undefined, V | undefined] | null | undefined} keyNodeOrEntry - The
12104
12735
  * `keyNodeOrEntry` parameter can accept one of the following types:
12105
12736
  * @param {V} [value] - The `value` parameter represents the value associated with the key in the
12106
12737
  * data structure. It is an optional parameter, so it can be omitted if not needed.
@@ -12127,7 +12758,7 @@ var dataStructureTyped = (() => {
12127
12758
  *
12128
12759
  * The function `delete` in TypeScript overrides the deletion operation in a binary tree data
12129
12760
  * structure, handling cases where nodes have children and maintaining balance in the tree.
12130
- * @param {BTNRep<K, V, TreeCounterNode<K, V>>} keyNodeOrEntry - The `predicate`
12761
+ * @param {K | TreeCounterNode<K, V> | [K | null | undefined, V | undefined] | null | undefined} keyNodeOrEntry - The `predicate`
12131
12762
  * parameter in the `delete` method is used to specify the condition or key based on which a node
12132
12763
  * should be deleted from the binary tree. It can be a key, a node, or an entry.
12133
12764
  * @param [ignoreCount=false] - The `ignoreCount` parameter in the `override delete` method is a
@@ -12253,8 +12884,8 @@ var dataStructureTyped = (() => {
12253
12884
  if (l > r) return;
12254
12885
  const m = l + Math.floor((r - l) / 2);
12255
12886
  const midNode = sorted[m];
12256
- if (this._isMapMode) this.add(midNode.key, void 0, midNode.count);
12257
- else this.add(midNode.key, midNode.value, midNode.count);
12887
+ if (this._isMapMode && midNode !== null) this.add(midNode.key, void 0, midNode.count);
12888
+ else if (midNode !== null) this.add(midNode.key, midNode.value, midNode.count);
12258
12889
  buildBalanceBST(l, m - 1);
12259
12890
  buildBalanceBST(m + 1, r);
12260
12891
  };
@@ -12269,8 +12900,8 @@ var dataStructureTyped = (() => {
12269
12900
  if (l <= r) {
12270
12901
  const m = l + Math.floor((r - l) / 2);
12271
12902
  const midNode = sorted[m];
12272
- if (this._isMapMode) this.add(midNode.key, void 0, midNode.count);
12273
- else this.add(midNode.key, midNode.value, midNode.count);
12903
+ if (this._isMapMode && midNode !== null) this.add(midNode.key, void 0, midNode.count);
12904
+ else if (midNode !== null) this.add(midNode.key, midNode.value, midNode.count);
12274
12905
  stack.push([m + 1, r]);
12275
12906
  stack.push([l, m - 1]);
12276
12907
  }
@@ -12288,7 +12919,7 @@ var dataStructureTyped = (() => {
12288
12919
  */
12289
12920
  clone() {
12290
12921
  const cloned = this.createTree();
12291
- this.bfs((node) => cloned.add(node.key, void 0, node.count));
12922
+ this.bfs((node) => cloned.add(node === null ? null : node.key, void 0, node === null ? 0 : node.count));
12292
12923
  if (this._isMapMode) cloned._store = this._store;
12293
12924
  return cloned;
12294
12925
  }
@@ -12318,8 +12949,8 @@ var dataStructureTyped = (() => {
12318
12949
  /**
12319
12950
  * The function `keyValueNodeEntryRawToNodeAndValue` takes in a key, value, and count and returns a
12320
12951
  * node based on the input.
12321
- * @param {BTNRep<K, V, TreeCounterNode<K, V>>} keyNodeOrEntry - The parameter
12322
- * `keyNodeOrEntry` can be of type `R` or `BTNRep<K, V, TreeCounterNode<K, V>>`.
12952
+ * @param {K | TreeCounterNode<K, V> | [K | null | undefined, V | undefined] | null | undefined} keyNodeOrEntry - The parameter
12953
+ * `keyNodeOrEntry` can be of type `R` or `K | TreeCounterNode<K, V> | [K | null | undefined, V | undefined] | null | undefined`.
12323
12954
  * @param {V} [value] - The `value` parameter is an optional value that represents the value
12324
12955
  * associated with the key in the node. It is used when creating a new node or updating the value of
12325
12956
  * an existing node.
@@ -12495,8 +13126,8 @@ var dataStructureTyped = (() => {
12495
13126
  }
12496
13127
  /**
12497
13128
  * The function checks if the input is an instance of AVLTreeCounterNode.
12498
- * @param {BTNRep<K, V, AVLTreeCounterNode<K, V>>} keyNodeOrEntry - The parameter
12499
- * `keyNodeOrEntry` can be of type `R` or `BTNRep<K, V, AVLTreeCounterNode<K, V>>`.
13129
+ * @param {K | AVLTreeCounterNode<K, V> | [K | null | undefined, V | undefined] | null | undefined} keyNodeOrEntry - The parameter
13130
+ * `keyNodeOrEntry` can be of type `R` or `K | AVLTreeCounterNode<K, V> | [K | null | undefined, V | undefined] | null | undefined`.
12500
13131
  * @returns a boolean value indicating whether the input parameter `keyNodeOrEntry` is
12501
13132
  * an instance of the `AVLTreeCounterNode` class.
12502
13133
  */
@@ -12509,9 +13140,9 @@ var dataStructureTyped = (() => {
12509
13140
  *
12510
13141
  * The function overrides the add method of a TypeScript class to add a new node to a data structure
12511
13142
  * and update the count.
12512
- * @param {BTNRep<K, V, AVLTreeCounterNode<K, V>>} keyNodeOrEntry - The
13143
+ * @param {K | AVLTreeCounterNode<K, V> | [K | null | undefined, V | undefined] | null | undefined} keyNodeOrEntry - The
12513
13144
  * `keyNodeOrEntry` parameter can accept a value of type `R`, which can be any type. It
12514
- * can also accept a value of type `BTNRep<K, V, AVLTreeCounterNode<K, V>>`, which represents a key, node,
13145
+ * can also accept a value of type `K | AVLTreeCounterNode<K, V> | [K | null | undefined, V | undefined] | null | undefined`, which represents a key, node,
12515
13146
  * entry, or raw element
12516
13147
  * @param {V} [value] - The `value` parameter represents the value associated with the key in the
12517
13148
  * data structure. It is an optional parameter, so it can be omitted if not needed.
@@ -12536,7 +13167,7 @@ var dataStructureTyped = (() => {
12536
13167
  *
12537
13168
  * The function overrides the delete method in a binary tree data structure, handling deletion of
12538
13169
  * nodes and maintaining balance in the tree.
12539
- * @param {BTNRep<K, V, AVLTreeCounterNode<K, V>>} keyNodeOrEntry - The `predicate`
13170
+ * @param {K | AVLTreeCounterNode<K, V> | [K | null | undefined, V | undefined] | null | undefined} keyNodeOrEntry - The `predicate`
12540
13171
  * parameter in the `delete` method is used to specify the condition for deleting a node from the
12541
13172
  * binary tree. It can be a key, node, or entry that determines which
12542
13173
  * node(s) should be deleted.
@@ -12611,6 +13242,7 @@ var dataStructureTyped = (() => {
12611
13242
  /**
12612
13243
  * Time Complexity: O(n log n)
12613
13244
  * Space Complexity: O(log n)
13245
+ *
12614
13246
  * The `perfectlyBalance` function takes a sorted array of nodes and builds a balanced binary search
12615
13247
  * tree using either a recursive or iterative approach.
12616
13248
  * @param {IterationType} iterationType - The `iterationType` parameter is an optional parameter that
@@ -12698,8 +13330,8 @@ var dataStructureTyped = (() => {
12698
13330
  /**
12699
13331
  * The function `keyValueNodeEntryRawToNodeAndValue` converts a key, value, entry, or raw element into
12700
13332
  * a node object.
12701
- * @param {BTNRep<K, V, AVLTreeCounterNode<K, V>>} keyNodeOrEntry - The
12702
- * `keyNodeOrEntry` parameter can be of type `R` or `BTNRep<K, V, AVLTreeCounterNode<K, V>>`.
13333
+ * @param {K | AVLTreeCounterNode<K, V> | [K | null | undefined, V | undefined] | null | undefined} keyNodeOrEntry - The
13334
+ * `keyNodeOrEntry` parameter can be of type `R` or `K | AVLTreeCounterNode<K, V> | [K | null | undefined, V | undefined] | null | undefined`.
12703
13335
  * @param {V} [value] - The `value` parameter is an optional value that can be passed to the
12704
13336
  * `override` function. It represents the value associated with the key in the data structure. If no
12705
13337
  * value is provided, it will default to `undefined`.
@@ -14026,6 +14658,9 @@ var dataStructureTyped = (() => {
14026
14658
  }
14027
14659
  yield* __yieldStar(_dfs(this.root, ""));
14028
14660
  }
14661
+ get _total() {
14662
+ return this._size;
14663
+ }
14029
14664
  /**
14030
14665
  * Time Complexity: O(l), where l is the length of the input string.
14031
14666
  * Space Complexity: O(1) - Constant space.
@@ -14148,13 +14783,6 @@ var dataStructureTyped = (() => {
14148
14783
  };
14149
14784
  return __toCommonJS(src_exports);
14150
14785
  })();
14151
- /**
14152
- * data-structure-typed
14153
- *
14154
- * @author Tyler Zeng
14155
- * @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
14156
- * @license MIT License
14157
- */
14158
14786
  /**
14159
14787
  * data-structure-typed
14160
14788
  *