data-structure-typed 1.53.7 → 1.53.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (164) hide show
  1. package/CHANGELOG.md +1 -1
  2. package/CONTRIBUTING.md +1 -1
  3. package/dist/cjs/common/index.js +5 -0
  4. package/dist/cjs/common/index.js.map +1 -1
  5. package/dist/cjs/data-structures/base/iterable-entry-base.js +4 -4
  6. package/dist/cjs/data-structures/base/iterable-entry-base.js.map +1 -1
  7. package/dist/cjs/data-structures/binary-tree/avl-tree-multi-map.d.ts +36 -17
  8. package/dist/cjs/data-structures/binary-tree/avl-tree-multi-map.js +65 -36
  9. package/dist/cjs/data-structures/binary-tree/avl-tree-multi-map.js.map +1 -1
  10. package/dist/cjs/data-structures/binary-tree/avl-tree.d.ts +12 -8
  11. package/dist/cjs/data-structures/binary-tree/avl-tree.js +19 -6
  12. package/dist/cjs/data-structures/binary-tree/avl-tree.js.map +1 -1
  13. package/dist/cjs/data-structures/binary-tree/binary-tree.d.ts +53 -40
  14. package/dist/cjs/data-structures/binary-tree/binary-tree.js +76 -72
  15. package/dist/cjs/data-structures/binary-tree/binary-tree.js.map +1 -1
  16. package/dist/cjs/data-structures/binary-tree/bst.d.ts +87 -52
  17. package/dist/cjs/data-structures/binary-tree/bst.js +111 -63
  18. package/dist/cjs/data-structures/binary-tree/bst.js.map +1 -1
  19. package/dist/cjs/data-structures/binary-tree/index.d.ts +1 -1
  20. package/dist/cjs/data-structures/binary-tree/index.js +1 -1
  21. package/dist/cjs/data-structures/binary-tree/index.js.map +1 -1
  22. package/dist/cjs/data-structures/binary-tree/{rb-tree.d.ts → red-black-tree.d.ts} +83 -10
  23. package/dist/cjs/data-structures/binary-tree/{rb-tree.js → red-black-tree.js} +92 -45
  24. package/dist/cjs/data-structures/binary-tree/red-black-tree.js.map +1 -0
  25. package/dist/cjs/data-structures/binary-tree/tree-multi-map.d.ts +34 -18
  26. package/dist/cjs/data-structures/binary-tree/tree-multi-map.js +66 -40
  27. package/dist/cjs/data-structures/binary-tree/tree-multi-map.js.map +1 -1
  28. package/dist/cjs/data-structures/graph/abstract-graph.js +2 -2
  29. package/dist/cjs/data-structures/graph/abstract-graph.js.map +1 -1
  30. package/dist/cjs/data-structures/hash/hash-map.d.ts +31 -1
  31. package/dist/cjs/data-structures/hash/hash-map.js +35 -5
  32. package/dist/cjs/data-structures/hash/hash-map.js.map +1 -1
  33. package/dist/cjs/data-structures/heap/heap.d.ts +20 -3
  34. package/dist/cjs/data-structures/heap/heap.js +31 -11
  35. package/dist/cjs/data-structures/heap/heap.js.map +1 -1
  36. package/dist/cjs/data-structures/linked-list/doubly-linked-list.d.ts +46 -11
  37. package/dist/cjs/data-structures/linked-list/doubly-linked-list.js +68 -21
  38. package/dist/cjs/data-structures/linked-list/doubly-linked-list.js.map +1 -1
  39. package/dist/cjs/data-structures/linked-list/singly-linked-list.d.ts +44 -11
  40. package/dist/cjs/data-structures/linked-list/singly-linked-list.js +70 -26
  41. package/dist/cjs/data-structures/linked-list/singly-linked-list.js.map +1 -1
  42. package/dist/cjs/data-structures/queue/deque.d.ts +37 -8
  43. package/dist/cjs/data-structures/queue/deque.js +73 -29
  44. package/dist/cjs/data-structures/queue/deque.js.map +1 -1
  45. package/dist/cjs/data-structures/queue/queue.d.ts +41 -1
  46. package/dist/cjs/data-structures/queue/queue.js +51 -9
  47. package/dist/cjs/data-structures/queue/queue.js.map +1 -1
  48. package/dist/cjs/data-structures/stack/stack.d.ts +27 -10
  49. package/dist/cjs/data-structures/stack/stack.js +39 -20
  50. package/dist/cjs/data-structures/stack/stack.js.map +1 -1
  51. package/dist/cjs/data-structures/trie/trie.d.ts +12 -13
  52. package/dist/cjs/data-structures/trie/trie.js +12 -13
  53. package/dist/cjs/data-structures/trie/trie.js.map +1 -1
  54. package/dist/cjs/interfaces/binary-tree.d.ts +3 -4
  55. package/dist/cjs/types/data-structures/base/base.d.ts +1 -1
  56. package/dist/cjs/types/data-structures/binary-tree/avl-tree-multi-map.d.ts +2 -3
  57. package/dist/cjs/types/data-structures/binary-tree/avl-tree.d.ts +2 -3
  58. package/dist/cjs/types/data-structures/binary-tree/binary-tree.d.ts +2 -3
  59. package/dist/cjs/types/data-structures/binary-tree/bst.d.ts +3 -4
  60. package/dist/cjs/types/data-structures/binary-tree/rb-tree.d.ts +4 -5
  61. package/dist/cjs/types/data-structures/binary-tree/tree-multi-map.d.ts +4 -5
  62. package/dist/mjs/common/index.js +5 -0
  63. package/dist/mjs/common/index.js.map +1 -1
  64. package/dist/mjs/data-structures/base/iterable-entry-base.js +4 -4
  65. package/dist/mjs/data-structures/base/iterable-entry-base.js.map +1 -1
  66. package/dist/mjs/data-structures/binary-tree/avl-tree-multi-map.d.ts +36 -17
  67. package/dist/mjs/data-structures/binary-tree/avl-tree-multi-map.js +65 -36
  68. package/dist/mjs/data-structures/binary-tree/avl-tree-multi-map.js.map +1 -1
  69. package/dist/mjs/data-structures/binary-tree/avl-tree.d.ts +12 -8
  70. package/dist/mjs/data-structures/binary-tree/avl-tree.js +19 -6
  71. package/dist/mjs/data-structures/binary-tree/avl-tree.js.map +1 -1
  72. package/dist/mjs/data-structures/binary-tree/binary-tree.d.ts +53 -40
  73. package/dist/mjs/data-structures/binary-tree/binary-tree.js +76 -72
  74. package/dist/mjs/data-structures/binary-tree/binary-tree.js.map +1 -1
  75. package/dist/mjs/data-structures/binary-tree/bst.d.ts +87 -52
  76. package/dist/mjs/data-structures/binary-tree/bst.js +127 -79
  77. package/dist/mjs/data-structures/binary-tree/bst.js.map +1 -1
  78. package/dist/mjs/data-structures/binary-tree/index.d.ts +1 -1
  79. package/dist/mjs/data-structures/binary-tree/index.js +1 -1
  80. package/dist/mjs/data-structures/binary-tree/index.js.map +1 -1
  81. package/dist/mjs/data-structures/binary-tree/{rb-tree.d.ts → red-black-tree.d.ts} +83 -10
  82. package/dist/mjs/data-structures/binary-tree/{rb-tree.js → red-black-tree.js} +92 -45
  83. package/dist/mjs/data-structures/binary-tree/red-black-tree.js.map +1 -0
  84. package/dist/mjs/data-structures/binary-tree/tree-multi-map.d.ts +34 -18
  85. package/dist/mjs/data-structures/binary-tree/tree-multi-map.js +64 -38
  86. package/dist/mjs/data-structures/binary-tree/tree-multi-map.js.map +1 -1
  87. package/dist/mjs/data-structures/graph/abstract-graph.js +2 -2
  88. package/dist/mjs/data-structures/graph/abstract-graph.js.map +1 -1
  89. package/dist/mjs/data-structures/hash/hash-map.d.ts +31 -1
  90. package/dist/mjs/data-structures/hash/hash-map.js +35 -5
  91. package/dist/mjs/data-structures/hash/hash-map.js.map +1 -1
  92. package/dist/mjs/data-structures/heap/heap.d.ts +20 -3
  93. package/dist/mjs/data-structures/heap/heap.js +31 -11
  94. package/dist/mjs/data-structures/heap/heap.js.map +1 -1
  95. package/dist/mjs/data-structures/linked-list/doubly-linked-list.d.ts +46 -11
  96. package/dist/mjs/data-structures/linked-list/doubly-linked-list.js +68 -21
  97. package/dist/mjs/data-structures/linked-list/doubly-linked-list.js.map +1 -1
  98. package/dist/mjs/data-structures/linked-list/singly-linked-list.d.ts +44 -11
  99. package/dist/mjs/data-structures/linked-list/singly-linked-list.js +70 -26
  100. package/dist/mjs/data-structures/linked-list/singly-linked-list.js.map +1 -1
  101. package/dist/mjs/data-structures/queue/deque.d.ts +37 -8
  102. package/dist/mjs/data-structures/queue/deque.js +73 -29
  103. package/dist/mjs/data-structures/queue/deque.js.map +1 -1
  104. package/dist/mjs/data-structures/queue/queue.d.ts +41 -1
  105. package/dist/mjs/data-structures/queue/queue.js +51 -9
  106. package/dist/mjs/data-structures/queue/queue.js.map +1 -1
  107. package/dist/mjs/data-structures/stack/stack.d.ts +27 -10
  108. package/dist/mjs/data-structures/stack/stack.js +39 -20
  109. package/dist/mjs/data-structures/stack/stack.js.map +1 -1
  110. package/dist/mjs/data-structures/trie/trie.d.ts +12 -13
  111. package/dist/mjs/data-structures/trie/trie.js +12 -13
  112. package/dist/mjs/data-structures/trie/trie.js.map +1 -1
  113. package/dist/mjs/interfaces/binary-tree.d.ts +3 -4
  114. package/dist/mjs/types/data-structures/base/base.d.ts +1 -1
  115. package/dist/mjs/types/data-structures/binary-tree/avl-tree-multi-map.d.ts +2 -3
  116. package/dist/mjs/types/data-structures/binary-tree/avl-tree.d.ts +2 -3
  117. package/dist/mjs/types/data-structures/binary-tree/binary-tree.d.ts +2 -3
  118. package/dist/mjs/types/data-structures/binary-tree/bst.d.ts +3 -4
  119. package/dist/mjs/types/data-structures/binary-tree/rb-tree.d.ts +4 -5
  120. package/dist/mjs/types/data-structures/binary-tree/tree-multi-map.d.ts +4 -5
  121. package/dist/umd/data-structure-typed.js +722 -356
  122. package/dist/umd/data-structure-typed.min.js +3 -3
  123. package/dist/umd/data-structure-typed.min.js.map +1 -1
  124. package/package.json +6 -6
  125. package/src/common/index.ts +7 -1
  126. package/src/data-structures/base/iterable-entry-base.ts +4 -4
  127. package/src/data-structures/binary-tree/avl-tree-multi-map.ts +82 -55
  128. package/src/data-structures/binary-tree/avl-tree.ts +32 -15
  129. package/src/data-structures/binary-tree/binary-tree.ts +89 -84
  130. package/src/data-structures/binary-tree/bst.ts +149 -97
  131. package/src/data-structures/binary-tree/index.ts +1 -1
  132. package/src/data-structures/binary-tree/{rb-tree.ts → red-black-tree.ts} +105 -55
  133. package/src/data-structures/binary-tree/tree-multi-map.ts +81 -51
  134. package/src/data-structures/graph/abstract-graph.ts +2 -2
  135. package/src/data-structures/hash/hash-map.ts +37 -7
  136. package/src/data-structures/heap/heap.ts +33 -10
  137. package/src/data-structures/linked-list/doubly-linked-list.ts +75 -21
  138. package/src/data-structures/linked-list/singly-linked-list.ts +77 -27
  139. package/src/data-structures/queue/deque.ts +72 -28
  140. package/src/data-structures/queue/queue.ts +50 -7
  141. package/src/data-structures/stack/stack.ts +39 -20
  142. package/src/data-structures/trie/trie.ts +8 -3
  143. package/src/interfaces/binary-tree.ts +3 -13
  144. package/src/types/data-structures/base/base.ts +1 -1
  145. package/src/types/data-structures/binary-tree/avl-tree-multi-map.ts +2 -4
  146. package/src/types/data-structures/binary-tree/avl-tree.ts +2 -4
  147. package/src/types/data-structures/binary-tree/binary-tree.ts +3 -3
  148. package/src/types/data-structures/binary-tree/bst.ts +3 -5
  149. package/src/types/data-structures/binary-tree/rb-tree.ts +4 -6
  150. package/src/types/data-structures/binary-tree/tree-multi-map.ts +4 -6
  151. package/test/integration/index.html +3 -3
  152. package/test/performance/data-structures/binary-tree/binary-tree-overall.test.ts +3 -3
  153. package/test/unit/data-structures/binary-tree/avl-tree-multi-map.test.ts +12 -12
  154. package/test/unit/data-structures/binary-tree/avl-tree.test.ts +10 -10
  155. package/test/unit/data-structures/binary-tree/binary-tree.test.ts +45 -45
  156. package/test/unit/data-structures/binary-tree/bst.test.ts +90 -96
  157. package/test/unit/data-structures/binary-tree/data/cost-of-living-by-country.ts +259 -0
  158. package/test/unit/data-structures/binary-tree/overall.test.ts +2 -0
  159. package/test/unit/data-structures/binary-tree/{rb-tree.test.ts → red-black-tree.test.ts} +67 -92
  160. package/test/unit/data-structures/binary-tree/tree-multi-map.test.ts +10 -10
  161. package/test/unit/data-structures/graph/directed-graph.test.ts +4 -4
  162. package/test/unit/data-structures/hash/hash-map.test.ts +12 -12
  163. package/dist/cjs/data-structures/binary-tree/rb-tree.js.map +0 -1
  164. package/dist/mjs/data-structures/binary-tree/rb-tree.js.map +0 -1
@@ -231,7 +231,7 @@ var dataStructureTyped = (() => {
231
231
  every(predicate, thisArg) {
232
232
  let index = 0;
233
233
  for (const item of this) {
234
- if (!predicate.call(thisArg, item[1], item[0], index++, this)) {
234
+ if (!predicate.call(thisArg, item[0], item[1], index++, this)) {
235
235
  return false;
236
236
  }
237
237
  }
@@ -255,7 +255,7 @@ var dataStructureTyped = (() => {
255
255
  some(predicate, thisArg) {
256
256
  let index = 0;
257
257
  for (const item of this) {
258
- if (predicate.call(thisArg, item[1], item[0], index++, this)) {
258
+ if (predicate.call(thisArg, item[0], item[1], index++, this)) {
259
259
  return true;
260
260
  }
261
261
  }
@@ -278,7 +278,7 @@ var dataStructureTyped = (() => {
278
278
  let index = 0;
279
279
  for (const item of this) {
280
280
  const [key, value] = item;
281
- callbackfn.call(thisArg, value, key, index++, this);
281
+ callbackfn.call(thisArg, key, value, index++, this);
282
282
  }
283
283
  }
284
284
  /**
@@ -302,7 +302,7 @@ var dataStructureTyped = (() => {
302
302
  let index = 0;
303
303
  for (const item of this) {
304
304
  const [key, value] = item;
305
- if (callbackfn.call(thisArg, value, key, index++, this)) return item;
305
+ if (callbackfn.call(thisArg, key, value, index++, this)) return item;
306
306
  }
307
307
  return;
308
308
  }
@@ -771,6 +771,9 @@ var dataStructureTyped = (() => {
771
771
  return this._hashFn;
772
772
  }
773
773
  /**
774
+ * Time Complexity: O(1)
775
+ * Space Complexity: O(1)
776
+ *
774
777
  * The function checks if a given element is an array with exactly two elements.
775
778
  * @param {any} rawElement - The `rawElement` parameter is of type `any`, which means it can be any
776
779
  * data type.
@@ -780,6 +783,9 @@ var dataStructureTyped = (() => {
780
783
  return Array.isArray(rawElement) && rawElement.length === 2;
781
784
  }
782
785
  /**
786
+ * Time Complexity: O(1)
787
+ * Space Complexity: O(1)
788
+ *
783
789
  * The function checks if the size of an object is equal to zero and returns a boolean value.
784
790
  * @returns A boolean value indicating whether the size of the object is 0 or not.
785
791
  */
@@ -787,6 +793,9 @@ var dataStructureTyped = (() => {
787
793
  return this._size === 0;
788
794
  }
789
795
  /**
796
+ * Time Complexity: O(1)
797
+ * Space Complexity: O(1)
798
+ *
790
799
  * The clear() function resets the state of an object by clearing its internal store, object map, and
791
800
  * size.
792
801
  */
@@ -796,6 +805,9 @@ var dataStructureTyped = (() => {
796
805
  this._size = 0;
797
806
  }
798
807
  /**
808
+ * Time Complexity: O(1)
809
+ * Space Complexity: O(1)
810
+ *
799
811
  * The `set` function adds a key-value pair to a map-like data structure, incrementing the size if
800
812
  * the key is not already present.
801
813
  * @param {K} key - The key parameter is the key used to identify the value in the data structure. It
@@ -820,6 +832,9 @@ var dataStructureTyped = (() => {
820
832
  return true;
821
833
  }
822
834
  /**
835
+ * Time Complexity: O(k)
836
+ * Space Complexity: O(k)
837
+ *
823
838
  * The function `setMany` takes an iterable collection of objects, maps each object to a key-value
824
839
  * pair using a mapping function, and sets each key-value pair in the current object.
825
840
  * @param entryOrRawElements - The `entryOrRawElements` parameter is an iterable collection of elements of a type
@@ -843,6 +858,9 @@ var dataStructureTyped = (() => {
843
858
  return results;
844
859
  }
845
860
  /**
861
+ * Time Complexity: O(1)
862
+ * Space Complexity: O(1)
863
+ *
846
864
  * The `get` function retrieves a value from a map based on a given key, either from an object map or
847
865
  * a string map.
848
866
  * @param {K} key - The `key` parameter is the key used to retrieve a value from the map. It can be
@@ -860,6 +878,9 @@ var dataStructureTyped = (() => {
860
878
  }
861
879
  }
862
880
  /**
881
+ * Time Complexity: O(1)
882
+ * Space Complexity: O(1)
883
+ *
863
884
  * The `has` function checks if a given key exists in the `_objMap` or `_store` based on whether it
864
885
  * is an object key or not.
865
886
  * @param {K} key - The parameter "key" is of type K, which means it can be any type.
@@ -874,6 +895,9 @@ var dataStructureTyped = (() => {
874
895
  }
875
896
  }
876
897
  /**
898
+ * Time Complexity: O(1)
899
+ * Space Complexity: O(1)
900
+ *
877
901
  * The `delete` function removes an element from a map-like data structure based on the provided key.
878
902
  * @param {K} key - The `key` parameter is the key of the element that you want to delete from the
879
903
  * data structure.
@@ -927,7 +951,7 @@ var dataStructureTyped = (() => {
927
951
  const resultMap = new _HashMap();
928
952
  let index = 0;
929
953
  for (const [key, value] of this) {
930
- resultMap.set(key, callbackfn.call(thisArg, value, key, index++, this));
954
+ resultMap.set(key, callbackfn.call(thisArg, key, value, index++, this));
931
955
  }
932
956
  return resultMap;
933
957
  }
@@ -951,7 +975,7 @@ var dataStructureTyped = (() => {
951
975
  const filteredMap = new _HashMap();
952
976
  let index = 0;
953
977
  for (const [key, value] of this) {
954
- if (predicate.call(thisArg, value, key, index++, this)) {
978
+ if (predicate.call(thisArg, key, value, index++, this)) {
955
979
  filteredMap.set(key, value);
956
980
  }
957
981
  }
@@ -1195,6 +1219,9 @@ var dataStructureTyped = (() => {
1195
1219
  return true;
1196
1220
  }
1197
1221
  /**
1222
+ * Time Complexity: O(k)
1223
+ * Space Complexity: O(k)
1224
+ *
1198
1225
  * The function `setMany` takes an iterable collection, converts each element into a key-value pair
1199
1226
  * using a provided function, and sets each key-value pair in the current object, returning an array
1200
1227
  * of booleans indicating the success of each set operation.
@@ -1219,6 +1246,9 @@ var dataStructureTyped = (() => {
1219
1246
  return results;
1220
1247
  }
1221
1248
  /**
1249
+ * Time Complexity: O(1)
1250
+ * Space Complexity: O(1)
1251
+ *
1222
1252
  * The function checks if a given key exists in a map, using different logic depending on whether the
1223
1253
  * key is a weak key or not.
1224
1254
  * @param {K} key - The `key` parameter is the key that is being checked for existence in the map.
@@ -1390,7 +1420,7 @@ var dataStructureTyped = (() => {
1390
1420
  const filteredMap = new _LinkedHashMap();
1391
1421
  let index = 0;
1392
1422
  for (const [key, value] of this) {
1393
- if (predicate.call(thisArg, value, key, index, this)) {
1423
+ if (predicate.call(thisArg, key, value, index, this)) {
1394
1424
  filteredMap.set(key, value);
1395
1425
  }
1396
1426
  index++;
@@ -1418,8 +1448,8 @@ var dataStructureTyped = (() => {
1418
1448
  const mappedMap = new _LinkedHashMap();
1419
1449
  let index = 0;
1420
1450
  for (const [key, value] of this) {
1421
- const newValue = callback.call(thisArg, value, key, index, this);
1422
- mappedMap.set(key, newValue);
1451
+ const [newKey, newValue] = callback.call(thisArg, key, value, index, this);
1452
+ mappedMap.set(newKey, newValue);
1423
1453
  index++;
1424
1454
  }
1425
1455
  return mappedMap;
@@ -1514,15 +1544,7 @@ var dataStructureTyped = (() => {
1514
1544
  __publicField(this, "_head");
1515
1545
  __publicField(this, "_tail");
1516
1546
  __publicField(this, "_size", 0);
1517
- if (elements) {
1518
- for (const el of elements) {
1519
- if (this.toElementFn) {
1520
- this.push(this.toElementFn(el));
1521
- } else {
1522
- this.push(el);
1523
- }
1524
- }
1525
- }
1547
+ this.pushMany(elements);
1526
1548
  }
1527
1549
  /**
1528
1550
  * The `head` function returns the first node of a singly linked list.
@@ -1563,6 +1585,22 @@ var dataStructureTyped = (() => {
1563
1585
  get size() {
1564
1586
  return this._size;
1565
1587
  }
1588
+ /**
1589
+ * Time Complexity: O(n)
1590
+ * Space Complexity: O(n)
1591
+ *
1592
+ * The `fromArray` function creates a new SinglyLinkedList instance and populates it with the elements from the given
1593
+ * array.
1594
+ * @param {E[]} data - The `data` parameter is an array of elements of type `E`.
1595
+ * @returns The `fromArray` function returns a `SinglyLinkedList` object.
1596
+ */
1597
+ static fromArray(data) {
1598
+ const singlyLinkedList = new _SinglyLinkedList();
1599
+ for (const item of data) {
1600
+ singlyLinkedList.push(item);
1601
+ }
1602
+ return singlyLinkedList;
1603
+ }
1566
1604
  /**
1567
1605
  * Time Complexity: O(1)
1568
1606
  * Space Complexity: O(1)
@@ -1648,6 +1686,53 @@ var dataStructureTyped = (() => {
1648
1686
  this._size++;
1649
1687
  return true;
1650
1688
  }
1689
+ /**
1690
+ * Time Complexity: O(k)
1691
+ * Space Complexity: O(k)
1692
+ *
1693
+ * The function `pushMany` iterates over elements and pushes them into a data structure, applying a
1694
+ * transformation function if provided.
1695
+ * @param {Iterable<E> | Iterable<R> | Iterable<SinglyLinkedListNode<E>>} elements - The `elements`
1696
+ * parameter in the `pushMany` function can accept an iterable containing elements of type `E`, `R`,
1697
+ * or `SinglyLinkedListNode<E>`.
1698
+ * @returns The `pushMany` function returns an array of boolean values indicating whether each
1699
+ * element was successfully pushed into the data structure.
1700
+ */
1701
+ pushMany(elements) {
1702
+ const ans = [];
1703
+ for (const el of elements) {
1704
+ if (this.toElementFn) {
1705
+ ans.push(this.push(this.toElementFn(el)));
1706
+ continue;
1707
+ }
1708
+ ans.push(this.push(el));
1709
+ }
1710
+ return ans;
1711
+ }
1712
+ /**
1713
+ * Time Complexity: O(k)
1714
+ * Space Complexity: O(k)
1715
+ *
1716
+ * The function `unshiftMany` iterates over elements and adds them to a data structure, optionally
1717
+ * converting them using a provided function.
1718
+ * @param {Iterable<E> | Iterable<R> | Iterable<SinglyLinkedListNode<E>>} elements - The `elements`
1719
+ * parameter in the `unshiftMany` function can accept an iterable containing elements of type `E`,
1720
+ * `R`, or `SinglyLinkedListNode<E>`. The function iterates over each element in the iterable and
1721
+ * performs an `unshift` operation on the linked list for each
1722
+ * @returns The `unshiftMany` function is returning an array of boolean values, where each value
1723
+ * represents the result of calling the `unshift` method on the current instance of the class.
1724
+ */
1725
+ unshiftMany(elements) {
1726
+ const ans = [];
1727
+ for (const el of elements) {
1728
+ if (this.toElementFn) {
1729
+ ans.push(this.unshift(this.toElementFn(el)));
1730
+ continue;
1731
+ }
1732
+ ans.push(this.unshift(el));
1733
+ }
1734
+ return ans;
1735
+ }
1651
1736
  /**
1652
1737
  * Time Complexity: O(n)
1653
1738
  * Space Complexity: O(1)
@@ -1819,6 +1904,9 @@ var dataStructureTyped = (() => {
1819
1904
  return true;
1820
1905
  }
1821
1906
  /**
1907
+ * Time Complexity: O(1)
1908
+ * Space Complexity: O(1)
1909
+ *
1822
1910
  * The function checks if the length of a data structure is equal to zero and returns a boolean value indicating
1823
1911
  * whether it is empty or not.
1824
1912
  * @returns A boolean value indicating whether the length of the object is equal to 0.
@@ -1827,6 +1915,9 @@ var dataStructureTyped = (() => {
1827
1915
  return this._size === 0;
1828
1916
  }
1829
1917
  /**
1918
+ * Time Complexity: O(1)
1919
+ * Space Complexity: O(1)
1920
+ *
1830
1921
  * The `clear` function resets the linked list by setting the head, tail, and length to undefined and 0 respectively.
1831
1922
  */
1832
1923
  clear() {
@@ -2095,22 +2186,6 @@ var dataStructureTyped = (() => {
2095
2186
  current = current.next;
2096
2187
  }
2097
2188
  }
2098
- /**
2099
- * Time Complexity: O(n)
2100
- * Space Complexity: O(n)
2101
- *
2102
- * The `fromArray` function creates a new SinglyLinkedList instance and populates it with the elements from the given
2103
- * array.
2104
- * @param {E[]} data - The `data` parameter is an array of elements of type `E`.
2105
- * @returns The `fromArray` function returns a `SinglyLinkedList` object.
2106
- */
2107
- static fromArray(data) {
2108
- const singlyLinkedList = new _SinglyLinkedList();
2109
- for (const item of data) {
2110
- singlyLinkedList.push(item);
2111
- }
2112
- return singlyLinkedList;
2113
- }
2114
2189
  /**
2115
2190
  * The _isPredicate function in TypeScript checks if the input is a function that takes a
2116
2191
  * SinglyLinkedListNode as an argument and returns a boolean.
@@ -2235,13 +2310,7 @@ var dataStructureTyped = (() => {
2235
2310
  this._head = void 0;
2236
2311
  this._tail = void 0;
2237
2312
  this._size = 0;
2238
- if (elements) {
2239
- for (const el of elements) {
2240
- if (this.toElementFn) {
2241
- this.push(this.toElementFn(el));
2242
- } else this.push(el);
2243
- }
2244
- }
2313
+ this.pushMany(elements);
2245
2314
  }
2246
2315
  /**
2247
2316
  * The `head` function returns the first node of a doubly linked list.
@@ -2287,6 +2356,18 @@ var dataStructureTyped = (() => {
2287
2356
  var _a;
2288
2357
  return (_a = this.tail) == null ? void 0 : _a.value;
2289
2358
  }
2359
+ /**
2360
+ * Time Complexity: O(n)
2361
+ * Space Complexity: O(n)
2362
+ *
2363
+ * The `fromArray` function creates a new instance of a DoublyLinkedList and populates it with the elements from the
2364
+ * given array.
2365
+ * @param {E[]} data - The `data` parameter is an array of elements of type `E`.
2366
+ * @returns The `fromArray` function returns a DoublyLinkedList object.
2367
+ */
2368
+ static fromArray(data) {
2369
+ return new _DoublyLinkedList(data);
2370
+ }
2290
2371
  /**
2291
2372
  * Time Complexity: O(1)
2292
2373
  * Space Complexity: O(1)
@@ -2389,6 +2470,55 @@ var dataStructureTyped = (() => {
2389
2470
  this._size++;
2390
2471
  return true;
2391
2472
  }
2473
+ /**
2474
+ * Time Complexity: O(k)
2475
+ * Space Complexity: O(k)
2476
+ *
2477
+ * The function `pushMany` iterates over elements and pushes them into a data structure, applying a
2478
+ * transformation function if provided.
2479
+ * @param {Iterable<E> | Iterable<R> | Iterable<DoublyLinkedListNode<E>>} elements - The `elements`
2480
+ * parameter in the `pushMany` function can accept an iterable containing elements of type `E`, `R`,
2481
+ * or `DoublyLinkedListNode<E>`. The function iterates over each element in the iterable and pushes
2482
+ * it onto the linked list. If a transformation function `to
2483
+ * @returns The `pushMany` function is returning an array of boolean values (`ans`) which indicate
2484
+ * the success or failure of pushing each element into the data structure.
2485
+ */
2486
+ pushMany(elements) {
2487
+ const ans = [];
2488
+ for (const el of elements) {
2489
+ if (this.toElementFn) {
2490
+ ans.push(this.push(this.toElementFn(el)));
2491
+ continue;
2492
+ }
2493
+ ans.push(this.push(el));
2494
+ }
2495
+ return ans;
2496
+ }
2497
+ /**
2498
+ * Time Complexity: O(k)
2499
+ * Space Complexity: O(k)
2500
+ *
2501
+ * The function `unshiftMany` iterates through a collection of elements and adds them to the
2502
+ * beginning of a Doubly Linked List, returning an array of boolean values indicating the success of
2503
+ * each insertion.
2504
+ * @param {Iterable<E> | Iterable<R> | Iterable<DoublyLinkedListNode<E>>} elements - The `elements`
2505
+ * parameter in the `unshiftMany` function can accept an iterable containing elements of type `E`,
2506
+ * `R`, or `DoublyLinkedListNode<E>`. The function iterates over each element in the iterable and
2507
+ * performs an `unshift` operation on the doubly linked list
2508
+ * @returns The `unshiftMany` function returns an array of boolean values indicating the success of
2509
+ * each unshift operation performed on the elements passed as input.
2510
+ */
2511
+ unshiftMany(elements) {
2512
+ const ans = [];
2513
+ for (const el of elements) {
2514
+ if (this.toElementFn) {
2515
+ ans.push(this.unshift(this.toElementFn(el)));
2516
+ continue;
2517
+ }
2518
+ ans.push(this.unshift(el));
2519
+ }
2520
+ return ans;
2521
+ }
2392
2522
  /**
2393
2523
  * Time Complexity: O(n)
2394
2524
  * Space Complexity: O(1)
@@ -2825,6 +2955,12 @@ var dataStructureTyped = (() => {
2825
2955
  * Time Complexity: O(n)
2826
2956
  * Space Complexity: O(1)
2827
2957
  *
2958
+ * The function `countOccurrences` iterates through a doubly linked list and counts the occurrences
2959
+ * of a specified element or nodes that satisfy a given predicate.
2960
+ * @param {E | DoublyLinkedListNode<E> | ((node: DoublyLinkedListNode<E>) => boolean)} elementOrNode
2961
+ * - The `elementOrNode` parameter in the `countOccurrences` method can accept three types of values:
2962
+ * @returns The `countOccurrences` method returns the number of occurrences of the specified element,
2963
+ * node, or predicate function in the doubly linked list.
2828
2964
  */
2829
2965
  countOccurrences(elementOrNode) {
2830
2966
  const predicate = this._ensurePredicate(elementOrNode);
@@ -2838,18 +2974,6 @@ var dataStructureTyped = (() => {
2838
2974
  }
2839
2975
  return count;
2840
2976
  }
2841
- /**
2842
- * Time Complexity: O(n)
2843
- * Space Complexity: O(n)
2844
- *
2845
- * The `fromArray` function creates a new instance of a DoublyLinkedList and populates it with the elements from the
2846
- * given array.
2847
- * @param {E[]} data - The `data` parameter is an array of elements of type `E`.
2848
- * @returns The `fromArray` function returns a DoublyLinkedList object.
2849
- */
2850
- static fromArray(data) {
2851
- return new _DoublyLinkedList(data);
2852
- }
2853
2977
  /**
2854
2978
  * The function returns an iterator that iterates over the values of a linked list.
2855
2979
  */
@@ -3144,15 +3268,7 @@ var dataStructureTyped = (() => {
3144
3268
  constructor(elements = [], options) {
3145
3269
  super(options);
3146
3270
  __publicField(this, "_elements", []);
3147
- if (elements) {
3148
- for (const el of elements) {
3149
- if (this.toElementFn) {
3150
- this.push(this.toElementFn(el));
3151
- } else {
3152
- this.push(el);
3153
- }
3154
- }
3155
- }
3271
+ this.pushMany(elements);
3156
3272
  }
3157
3273
  /**
3158
3274
  * The elements function returns the elements of this set.
@@ -3168,10 +3284,6 @@ var dataStructureTyped = (() => {
3168
3284
  get size() {
3169
3285
  return this.elements.length;
3170
3286
  }
3171
- /**
3172
- * Time Complexity: O(n)
3173
- * Space Complexity: O(n)
3174
- */
3175
3287
  /**
3176
3288
  * Time Complexity: O(n)
3177
3289
  * Space Complexity: O(n)
@@ -3185,6 +3297,9 @@ var dataStructureTyped = (() => {
3185
3297
  return new _Stack(elements);
3186
3298
  }
3187
3299
  /**
3300
+ * Time Complexity: O(1)
3301
+ * Space Complexity: O(1)
3302
+ *
3188
3303
  * The function checks if an array is empty and returns a boolean value.
3189
3304
  * @returns A boolean value indicating whether the `_elements` array is empty or not.
3190
3305
  */
@@ -3227,18 +3342,46 @@ var dataStructureTyped = (() => {
3227
3342
  return this.elements.pop();
3228
3343
  }
3229
3344
  /**
3230
- * The delete function removes an element from the stack.
3231
- * @param element: E Specify the element to be deleted
3232
- * @return A boolean value indicating whether the element was successfully deleted or not
3345
+ * Time Complexity: O(k)
3346
+ * Space Complexity: O(1)
3347
+ *
3348
+ * The function `pushMany` iterates over elements and pushes them into an array after applying a
3349
+ * transformation function if provided.
3350
+ * @param {Iterable<E> | Iterable<R>} elements - The `elements` parameter in the `pushMany` function
3351
+ * is an iterable containing elements of type `E` or `R`. The function iterates over each element in
3352
+ * the iterable and pushes it into the data structure. If a transformation function `toElementFn` is
3353
+ * provided, it is used to
3354
+ * @returns The `pushMany` function is returning an array of boolean values indicating whether each
3355
+ * element was successfully pushed into the data structure.
3356
+ */
3357
+ pushMany(elements) {
3358
+ const ans = [];
3359
+ for (const el of elements) {
3360
+ if (this.toElementFn) {
3361
+ ans.push(this.push(this.toElementFn(el)));
3362
+ } else {
3363
+ ans.push(this.push(el));
3364
+ }
3365
+ }
3366
+ return ans;
3367
+ }
3368
+ /**
3369
+ * Time Complexity: O(n)
3370
+ * Space Complexity: O(1)
3371
+ *
3372
+ * The toArray function returns a copy of the elements in an array.
3373
+ * @returns An array of type E.
3233
3374
  */
3234
3375
  delete(element) {
3235
3376
  const index = this.elements.indexOf(element);
3236
3377
  return this.deleteAt(index);
3237
3378
  }
3238
3379
  /**
3239
- * The deleteAt function deletes the element at a given index.
3240
- * @param index: number Determine the index of the element to be deleted
3241
- * @return A boolean value
3380
+ * Time Complexity: O(n)
3381
+ * Space Complexity: O(1)
3382
+ *
3383
+ * The toArray function returns a copy of the elements in an array.
3384
+ * @returns An array of type E.
3242
3385
  */
3243
3386
  deleteAt(index) {
3244
3387
  const spliced = this.elements.splice(index, 1);
@@ -3351,12 +3494,7 @@ var dataStructureTyped = (() => {
3351
3494
  const { autoCompactRatio = 0.5 } = options;
3352
3495
  this._autoCompactRatio = autoCompactRatio;
3353
3496
  }
3354
- if (elements) {
3355
- for (const el of elements) {
3356
- if (this.toElementFn) this.push(this.toElementFn(el));
3357
- else this.push(el);
3358
- }
3359
- }
3497
+ this.pushMany(elements);
3360
3498
  }
3361
3499
  /**
3362
3500
  * The elements function returns the elements of this set.
@@ -3441,6 +3579,25 @@ var dataStructureTyped = (() => {
3441
3579
  this.elements.push(element);
3442
3580
  return true;
3443
3581
  }
3582
+ /**
3583
+ * Time Complexity: O(k)
3584
+ * Space Complexity: O(k)
3585
+ *
3586
+ * The `pushMany` function iterates over elements and pushes them into an array after applying a
3587
+ * transformation function if provided.
3588
+ * @param {Iterable<E> | Iterable<R>} elements - The `elements` parameter in the `pushMany` function
3589
+ * is an iterable containing elements of type `E` or `R`.
3590
+ * @returns The `pushMany` function is returning an array of boolean values indicating whether each
3591
+ * element was successfully pushed into the data structure.
3592
+ */
3593
+ pushMany(elements) {
3594
+ const ans = [];
3595
+ for (const el of elements) {
3596
+ if (this.toElementFn) ans.push(this.push(this.toElementFn(el)));
3597
+ else ans.push(this.push(el));
3598
+ }
3599
+ return ans;
3600
+ }
3444
3601
  /**
3445
3602
  * Time Complexity: O(1)
3446
3603
  * Space Complexity: O(1)
@@ -3457,6 +3614,9 @@ var dataStructureTyped = (() => {
3457
3614
  return first;
3458
3615
  }
3459
3616
  /**
3617
+ * Time Complexity: O(n)
3618
+ * Space Complexity: O(1)
3619
+ *
3460
3620
  * The delete function removes an element from the list.
3461
3621
  * @param {E} element - Specify the element to be deleted
3462
3622
  * @return A boolean value indicating whether the element was successfully deleted or not
@@ -3466,6 +3626,9 @@ var dataStructureTyped = (() => {
3466
3626
  return this.deleteAt(index);
3467
3627
  }
3468
3628
  /**
3629
+ * Time Complexity: O(n)
3630
+ * Space Complexity: O(1)
3631
+ *
3469
3632
  * The deleteAt function deletes the element at a given index.
3470
3633
  * @param {number} index - Determine the index of the element to be deleted
3471
3634
  * @return A boolean value
@@ -3478,7 +3641,12 @@ var dataStructureTyped = (() => {
3478
3641
  * Time Complexity: O(1)
3479
3642
  * Space Complexity: O(1)
3480
3643
  *
3481
- * @param index
3644
+ * The `at` function returns the element at a specified index adjusted by an offset, or `undefined`
3645
+ * if the index is out of bounds.
3646
+ * @param {number} index - The `index` parameter represents the position of the element you want to
3647
+ * retrieve from the data structure.
3648
+ * @returns The `at` method is returning the element at the specified index adjusted by the offset
3649
+ * `_offset`.
3482
3650
  */
3483
3651
  at(index) {
3484
3652
  return this.elements[index + this._offset];
@@ -3514,6 +3682,9 @@ var dataStructureTyped = (() => {
3514
3682
  this._offset = 0;
3515
3683
  }
3516
3684
  /**
3685
+ * Time Complexity: O(n)
3686
+ * Space Complexity: O(1)
3687
+ *
3517
3688
  * The `compact` function in TypeScript slices the elements array based on the offset and resets the
3518
3689
  * offset to zero.
3519
3690
  * @returns The `compact()` method is returning a boolean value of `true`.
@@ -3563,6 +3734,20 @@ var dataStructureTyped = (() => {
3563
3734
  /**
3564
3735
  * Time Complexity: O(n)
3565
3736
  * Space Complexity: O(n)
3737
+ *
3738
+ * The `map` function in TypeScript creates a new Queue by applying a callback function to each
3739
+ * element in the original Queue.
3740
+ * @param callback - The `callback` parameter is a function that will be applied to each element in
3741
+ * the queue. It takes the current element, its index, and the queue itself as arguments, and returns
3742
+ * a new element.
3743
+ * @param [toElementFn] - The `toElementFn` parameter is an optional function that can be provided to
3744
+ * convert a raw element of type `RM` to a new element of type `EM`. This function is used within the
3745
+ * `map` method to transform each raw element before passing it to the `callback` function. If
3746
+ * @param {any} [thisArg] - The `thisArg` parameter in the `map` function is used to specify the
3747
+ * value of `this` when executing the `callback` function. It allows you to set the context (the
3748
+ * value of `this`) within the callback function. If `thisArg` is provided, it will be
3749
+ * @returns A new Queue object containing elements of type EM, which are the result of applying the
3750
+ * callback function to each element in the original Queue object.
3566
3751
  */
3567
3752
  map(callback, toElementFn, thisArg) {
3568
3753
  const newDeque = new _Queue([], { toElementFn });
@@ -3643,13 +3828,7 @@ var dataStructureTyped = (() => {
3643
3828
  const needBucketNum = calcMinUnitsRequired(_size, this._bucketSize);
3644
3829
  this._bucketFirst = this._bucketLast = (this._bucketCount >> 1) - (needBucketNum >> 1);
3645
3830
  this._firstInBucket = this._lastInBucket = this._bucketSize - _size % this._bucketSize >> 1;
3646
- for (const el of elements) {
3647
- if (this.toElementFn) {
3648
- this.push(this.toElementFn(el));
3649
- } else {
3650
- this.push(el);
3651
- }
3652
- }
3831
+ this.pushMany(elements);
3653
3832
  }
3654
3833
  /**
3655
3834
  * The bucketSize function returns the size of the bucket.
@@ -3787,6 +3966,32 @@ var dataStructureTyped = (() => {
3787
3966
  this._size -= 1;
3788
3967
  return element;
3789
3968
  }
3969
+ /**
3970
+ * Time Complexity: O(1)
3971
+ * Space Complexity: O(1)
3972
+ *
3973
+ * The `shift()` function removes and returns the first element from a data structure, updating the
3974
+ * internal state variables accordingly.
3975
+ * @returns The element that is being removed from the beginning of the data structure is being
3976
+ * returned.
3977
+ */
3978
+ shift() {
3979
+ if (this._size === 0) return;
3980
+ const element = this._buckets[this._bucketFirst][this._firstInBucket];
3981
+ if (this._size !== 1) {
3982
+ if (this._firstInBucket < this._bucketSize - 1) {
3983
+ this._firstInBucket += 1;
3984
+ } else if (this._bucketFirst < this._bucketCount - 1) {
3985
+ this._bucketFirst += 1;
3986
+ this._firstInBucket = 0;
3987
+ } else {
3988
+ this._bucketFirst = 0;
3989
+ this._firstInBucket = 0;
3990
+ }
3991
+ }
3992
+ this._size -= 1;
3993
+ return element;
3994
+ }
3790
3995
  /**
3791
3996
  * Time Complexity: Amortized O(1)
3792
3997
  * Space Complexity: O(n)
@@ -3816,30 +4021,53 @@ var dataStructureTyped = (() => {
3816
4021
  return true;
3817
4022
  }
3818
4023
  /**
3819
- * Time Complexity: O(1)
3820
- * Space Complexity: O(1)
4024
+ * Time Complexity: O(k)
4025
+ * Space Complexity: O(k)
3821
4026
  *
3822
- * The `shift()` function removes and returns the first element from a data structure, updating the
3823
- * internal state variables accordingly.
3824
- * @returns The element that is being removed from the beginning of the data structure is being
3825
- * returned.
4027
+ * The function `pushMany` iterates over elements and pushes them into an array after applying a
4028
+ * transformation function if provided.
4029
+ * @param {IterableWithSizeOrLength<E> | IterableWithSizeOrLength<R>} elements - The `elements`
4030
+ * parameter in the `pushMany` function is expected to be an iterable containing elements of type `E`
4031
+ * or `R`. It can be either an `IterableWithSizeOrLength<E>` or an `IterableWithSizeOrLength<R>`. The
4032
+ * function iterates over each element
4033
+ * @returns The `pushMany` function is returning an array of boolean values, where each value
4034
+ * represents the result of calling the `push` method on the current object instance with the
4035
+ * corresponding element from the input `elements` iterable.
3826
4036
  */
3827
- shift() {
3828
- if (this._size === 0) return;
3829
- const element = this._buckets[this._bucketFirst][this._firstInBucket];
3830
- if (this._size !== 1) {
3831
- if (this._firstInBucket < this._bucketSize - 1) {
3832
- this._firstInBucket += 1;
3833
- } else if (this._bucketFirst < this._bucketCount - 1) {
3834
- this._bucketFirst += 1;
3835
- this._firstInBucket = 0;
4037
+ pushMany(elements) {
4038
+ const ans = [];
4039
+ for (const el of elements) {
4040
+ if (this.toElementFn) {
4041
+ ans.push(this.push(this.toElementFn(el)));
3836
4042
  } else {
3837
- this._bucketFirst = 0;
3838
- this._firstInBucket = 0;
4043
+ ans.push(this.push(el));
3839
4044
  }
3840
4045
  }
3841
- this._size -= 1;
3842
- return element;
4046
+ return ans;
4047
+ }
4048
+ /**
4049
+ * Time Complexity: O(k)
4050
+ * Space Complexity: O(k)
4051
+ *
4052
+ * The `unshiftMany` function in TypeScript iterates over elements and adds them to the beginning of
4053
+ * an array, optionally converting them using a provided function.
4054
+ * @param {IterableWithSizeOrLength<E> | IterableWithSizeOrLength<R>} elements - The `elements`
4055
+ * parameter in the `unshiftMany` function is an iterable containing elements of type `E` or `R`. It
4056
+ * can be an array or any other iterable data structure that has a known size or length. The function
4057
+ * iterates over each element in the `elements` iterable and
4058
+ * @returns The `unshiftMany` function returns an array of boolean values indicating whether each
4059
+ * element was successfully added to the beginning of the array.
4060
+ */
4061
+ unshiftMany(elements = []) {
4062
+ const ans = [];
4063
+ for (const el of elements) {
4064
+ if (this.toElementFn) {
4065
+ ans.push(this.unshift(this.toElementFn(el)));
4066
+ } else {
4067
+ ans.push(this.unshift(el));
4068
+ }
4069
+ }
4070
+ return ans;
3843
4071
  }
3844
4072
  /**
3845
4073
  * Time Complexity: O(1)
@@ -4356,12 +4584,7 @@ var dataStructureTyped = (() => {
4356
4584
  const { comparator } = options;
4357
4585
  if (comparator) this._comparator = comparator;
4358
4586
  }
4359
- if (elements) {
4360
- for (const el of elements) {
4361
- if (this.toElementFn) this.add(this.toElementFn(el));
4362
- else this.add(el);
4363
- }
4364
- }
4587
+ this.addMany(elements);
4365
4588
  }
4366
4589
  /**
4367
4590
  * The function returns an array of elements.
@@ -4397,13 +4620,40 @@ var dataStructureTyped = (() => {
4397
4620
  * Time Complexity: O(log n)
4398
4621
  * Space Complexity: O(1)
4399
4622
  *
4400
- * Insert an element into the heap and maintain the heap properties.
4401
- * @param element - The element to be inserted.
4623
+ * The add function pushes an element into an array and then triggers a bubble-up operation.
4624
+ * @param {E} element - The `element` parameter represents the element that you want to add to the
4625
+ * data structure.
4626
+ * @returns The `add` method is returning a boolean value, which is the result of calling the
4627
+ * `_bubbleUp` method with the index `this.elements.length - 1` as an argument.
4402
4628
  */
4403
4629
  add(element) {
4404
4630
  this._elements.push(element);
4405
4631
  return this._bubbleUp(this.elements.length - 1);
4406
4632
  }
4633
+ /**
4634
+ * Time Complexity: O(k log n)
4635
+ * Space Complexity: O(1)
4636
+ *
4637
+ * The `addMany` function iterates over elements and adds them to a collection, returning an array of
4638
+ * boolean values indicating success or failure.
4639
+ * @param {Iterable<E> | Iterable<R>} elements - The `elements` parameter in the `addMany` method is
4640
+ * an iterable containing elements of type `E` or `R`. The method iterates over each element in the
4641
+ * iterable and adds them to the data structure. If a transformation function `_toElementFn` is
4642
+ * provided, it transforms the element
4643
+ * @returns The `addMany` method returns an array of boolean values indicating whether each element
4644
+ * in the input iterable was successfully added to the data structure.
4645
+ */
4646
+ addMany(elements) {
4647
+ const ans = [];
4648
+ for (const el of elements) {
4649
+ if (this._toElementFn) {
4650
+ ans.push(this.add(this._toElementFn(el)));
4651
+ continue;
4652
+ }
4653
+ ans.push(this.add(el));
4654
+ }
4655
+ return ans;
4656
+ }
4407
4657
  /**
4408
4658
  * Time Complexity: O(log n)
4409
4659
  * Space Complexity: O(1)
@@ -4597,7 +4847,7 @@ var dataStructureTyped = (() => {
4597
4847
  return filteredList;
4598
4848
  }
4599
4849
  /**
4600
- * Time Complexity: O(n log n)
4850
+ * Time Complexity: O(n)
4601
4851
  * Space Complexity: O(n)
4602
4852
  *
4603
4853
  * The `map` function creates a new heap by applying a callback function to each element of the
@@ -5942,7 +6192,7 @@ var dataStructureTyped = (() => {
5942
6192
  const filtered = [];
5943
6193
  let index = 0;
5944
6194
  for (const [key, value] of this) {
5945
- if (predicate.call(thisArg, value, key, index, this)) {
6195
+ if (predicate.call(thisArg, key, value, index, this)) {
5946
6196
  filtered.push([key, value]);
5947
6197
  }
5948
6198
  index++;
@@ -5966,7 +6216,7 @@ var dataStructureTyped = (() => {
5966
6216
  const mapped = [];
5967
6217
  let index = 0;
5968
6218
  for (const [key, value] of this) {
5969
- mapped.push(callback.call(thisArg, value, key, index, this));
6219
+ mapped.push(callback.call(thisArg, key, value, index, this));
5970
6220
  index++;
5971
6221
  }
5972
6222
  return mapped;
@@ -7120,6 +7370,8 @@ var dataStructureTyped = (() => {
7120
7370
  this.high = high;
7121
7371
  this.includeLow = includeLow;
7122
7372
  this.includeHigh = includeHigh;
7373
+ if (!(isComparable(low) && isComparable(high))) throw new RangeError("low or high is not comparable");
7374
+ if (low > high) throw new RangeError("low must be less than or equal to high");
7123
7375
  }
7124
7376
  // Determine whether a key is within the range
7125
7377
  isInRange(key, comparator) {
@@ -7219,65 +7471,40 @@ var dataStructureTyped = (() => {
7219
7471
  return this._toEntryFn;
7220
7472
  }
7221
7473
  /**
7474
+ * Time Complexity: O(1)
7475
+ * Space Complexity: O(1)
7476
+ *
7222
7477
  * The function creates a new binary tree node with a specified key and optional value.
7223
7478
  * @param {K} key - The `key` parameter is the key of the node being created in the binary tree.
7224
- * @param {V} [value] - The `value` parameter in the `createNode` function is optional, meaning it is
7225
- * not required to be provided when calling the function. If a `value` is provided, it should be of
7226
- * type `V`, which is the type of the value associated with the node.
7227
- * @returns A new BinaryTreeNode instance with the provided key and value is being returned, casted
7228
- * as NODE.
7229
- */
7230
- createNode(key, value) {
7231
- return new BinaryTreeNode(key, this._isMapMode ? void 0 : value);
7232
- }
7233
- /**
7234
- * The function creates a binary tree with the specified options.
7235
- * @param [options] - The `options` parameter in the `createTree` function is an optional parameter
7236
- * that allows you to provide partial configuration options for creating a binary tree. It is of type
7237
- * `Partial<BinaryTreeOptions<K, V, R>>`, which means you can pass in an object containing a subset
7238
- * of properties
7239
- * @returns A new instance of a binary tree with the specified options is being returned.
7240
- */
7241
- createTree(options) {
7242
- return new _BinaryTree([], __spreadValues({
7243
- iterationType: this.iterationType,
7244
- isMapMode: this._isMapMode,
7245
- toEntryFn: this._toEntryFn
7246
- }, options));
7247
- }
7248
- /**
7249
- * The function `keyValueNodeEntryRawToNodeAndValue` converts various input types into a node object
7250
- * or returns null.
7251
- * @param {BTNRep<K, V, NODE> | R} keyNodeEntryOrRaw - The
7252
- * `keyValueNodeEntryRawToNodeAndValue` function takes in a parameter `keyNodeEntryOrRaw`, which
7253
- * can be of type `BTNRep<K, V, NODE>` or `R`. This parameter represents either a key, a
7254
- * node, an entry
7255
- * @param {V} [value] - The `value` parameter in the `keyValueNodeEntryRawToNodeAndValue` function is
7256
- * an optional parameter of type `V`. It represents the value associated with the key in the node
7257
- * being created. If a `value` is provided, it will be used when creating the node. If
7258
- * @returns The `keyValueNodeEntryRawToNodeAndValue` function returns an optional node
7259
- * (`OptNodeOrNull<NODE>`) based on the input parameters provided. The function checks the type of the
7260
- * input parameter (`keyNodeEntryOrRaw`) and processes it accordingly to return a node or null
7261
- * value.
7262
- */
7263
- keyValueNodeEntryRawToNodeAndValue(keyNodeEntryOrRaw, value) {
7264
- if (keyNodeEntryOrRaw === void 0) return [void 0, void 0];
7265
- if (keyNodeEntryOrRaw === null) return [null, void 0];
7266
- if (this.isNode(keyNodeEntryOrRaw)) return [keyNodeEntryOrRaw, value];
7267
- if (this.isEntry(keyNodeEntryOrRaw)) {
7268
- const [key, entryValue] = keyNodeEntryOrRaw;
7269
- if (key === void 0) return [void 0, void 0];
7270
- else if (key === null) return [null, void 0];
7271
- const finalValue = value != null ? value : entryValue;
7272
- return [this.createNode(key, finalValue), finalValue];
7273
- }
7274
- if (this.isRaw(keyNodeEntryOrRaw)) {
7275
- const [key, entryValue] = this._toEntryFn(keyNodeEntryOrRaw);
7276
- const finalValue = value != null ? value : entryValue;
7277
- if (this.isKey(key)) return [this.createNode(key, finalValue), finalValue];
7278
- }
7279
- if (this.isKey(keyNodeEntryOrRaw)) return [this.createNode(keyNodeEntryOrRaw, value), value];
7280
- return [void 0, void 0];
7479
+ * @param {V} [value] - The `value` parameter in the `createNode` function is optional, meaning it is
7480
+ * not required to be provided when calling the function. If a `value` is provided, it should be of
7481
+ * type `V`, which is the type of the value associated with the node.
7482
+ * @returns A new BinaryTreeNode instance with the provided key and value is being returned, casted
7483
+ * as NODE.
7484
+ */
7485
+ createNode(key, value) {
7486
+ return new BinaryTreeNode(key, this._isMapMode ? void 0 : value);
7487
+ }
7488
+ /**
7489
+ * Time Complexity: O(1)
7490
+ * Space Complexity: O(1)
7491
+ *
7492
+ * The `createTree` function creates a new binary tree based on the provided options.
7493
+ * @param [options] - The `options` parameter in the `createTree` method is of type
7494
+ * `BinaryTreeOptions<K, V, R>`. This type likely contains configuration options for creating a
7495
+ * binary tree, such as the iteration type, whether the tree is in map mode, and functions for
7496
+ * converting entries.
7497
+ * @returns The `createTree` method is returning an instance of the `BinaryTree` class with the
7498
+ * provided options. The method is creating a new `BinaryTree` object with an empty array as the
7499
+ * initial data, and then setting various options such as `iterationType`, `isMapMode`, and
7500
+ * `toEntryFn` based on the current object's properties and the provided `options`. Finally, it
7501
+ */
7502
+ createTree(options) {
7503
+ return new _BinaryTree([], __spreadValues({
7504
+ iterationType: this.iterationType,
7505
+ isMapMode: this._isMapMode,
7506
+ toEntryFn: this._toEntryFn
7507
+ }, options));
7281
7508
  }
7282
7509
  /**
7283
7510
  * Time Complexity: O(n)
@@ -7437,7 +7664,7 @@ var dataStructureTyped = (() => {
7437
7664
  * key was found and the node was replaced instead of inserted.
7438
7665
  */
7439
7666
  add(keyNodeEntryOrRaw, value) {
7440
- const [newNode, newValue] = this.keyValueNodeEntryRawToNodeAndValue(keyNodeEntryOrRaw, value);
7667
+ const [newNode, newValue] = this._keyValueNodeEntryRawToNodeAndValue(keyNodeEntryOrRaw, value);
7441
7668
  if (newNode === void 0) return false;
7442
7669
  if (!this._root) {
7443
7670
  this._setRoot(newNode);
@@ -8481,7 +8708,7 @@ var dataStructureTyped = (() => {
8481
8708
  const newTree = this.createTree();
8482
8709
  let index = 0;
8483
8710
  for (const [key, value] of this) {
8484
- if (predicate.call(thisArg, value, key, index++, this)) {
8711
+ if (predicate.call(thisArg, key, value, index++, this)) {
8485
8712
  newTree.add([key, value]);
8486
8713
  }
8487
8714
  }
@@ -8491,34 +8718,29 @@ var dataStructureTyped = (() => {
8491
8718
  * Time Complexity: O(n)
8492
8719
  * Space Complexity: O(n)
8493
8720
  *
8494
- * The `map` function iterates over key-value pairs in a tree data structure, applies a callback
8495
- * function to each value, and returns a new tree with the updated values.
8496
- * @param callback - The `callback` parameter in the `map` method is a function that will be called
8497
- * on each entry in the tree. It takes four arguments:
8498
- * @param {any} [thisArg] - The `thisArg` parameter in the `map` function is an optional parameter
8499
- * that specifies the value to be passed as `this` when executing the callback function. If provided,
8500
- * the `thisArg` value will be used as the `this` value within the callback function. If `thisArg
8501
- * @returns The `map` method is returning a new tree with the entries modified by the provided
8502
- * callback function. Each entry in the original tree is passed to the callback function, and the
8503
- * result of the callback function is added to the new tree.
8504
- */
8505
- map(callback, thisArg) {
8506
- const newTree = this.createTree();
8721
+ * The `map` function in TypeScript creates a new BinaryTree by applying a callback function to each
8722
+ * entry in the original BinaryTree.
8723
+ * @param callback - A function that will be called for each entry in the current binary tree. It
8724
+ * takes the key, value (which can be undefined), and an array containing the mapped key and value as
8725
+ * arguments.
8726
+ * @param [options] - The `options` parameter in the `map` method is of type `BinaryTreeOptions<MK,
8727
+ * MV, MR>`. It is an optional parameter that allows you to specify additional options for the binary
8728
+ * tree being created during the mapping process. These options could include things like custom
8729
+ * comparators, initial
8730
+ * @param {any} [thisArg] - The `thisArg` parameter in the `map` method is used to specify the value
8731
+ * of `this` when executing the `callback` function. It allows you to set the context (value of
8732
+ * `this`) within the callback function. If `thisArg` is provided, it will be passed
8733
+ * @returns The `map` function is returning a new `BinaryTree` instance filled with entries that are
8734
+ * the result of applying the provided `callback` function to each entry in the original tree.
8735
+ */
8736
+ map(callback, options, thisArg) {
8737
+ const newTree = new _BinaryTree([], options);
8507
8738
  let index = 0;
8508
8739
  for (const [key, value] of this) {
8509
- newTree.add([key, callback.call(thisArg, value, key, index++, this)]);
8740
+ newTree.add(callback.call(thisArg, key, value, index++, this));
8510
8741
  }
8511
8742
  return newTree;
8512
8743
  }
8513
- // // TODO Type error, need to return a TREE<NV> that is a value type only for callback function.
8514
- // // map<NV>(callback: (entry: [K, V | undefined], tree: this) => NV) {
8515
- // // const newTree = this.createTree();
8516
- // // for (const [key, value] of this) {
8517
- // // newTree.add(key, callback([key, value], this));
8518
- // // }
8519
- // // return newTree;
8520
- // // }
8521
- //
8522
8744
  /**
8523
8745
  * Time Complexity: O(n)
8524
8746
  * Space Complexity: O(n)
@@ -8549,7 +8771,7 @@ var dataStructureTyped = (() => {
8549
8771
  if (opts.isShowRedBlackNIL) output += `S for Sentinel Node(NIL)
8550
8772
  `;
8551
8773
  const display = (root) => {
8552
- const [lines, , ,] = this._displayAux(root, opts);
8774
+ const [lines, ,] = this._displayAux(root, opts);
8553
8775
  let paragraph = "";
8554
8776
  for (const line of lines) {
8555
8777
  paragraph += line + "\n";
@@ -8577,6 +8799,40 @@ var dataStructureTyped = (() => {
8577
8799
  print(options, startNode = this._root) {
8578
8800
  console.log(this.toVisual(startNode, options));
8579
8801
  }
8802
+ /**
8803
+ * The function `keyValueNodeEntryRawToNodeAndValue` converts various input types into a node object
8804
+ * or returns null.
8805
+ * @param {BTNRep<K, V, NODE> | R} keyNodeEntryOrRaw - The
8806
+ * `keyValueNodeEntryRawToNodeAndValue` function takes in a parameter `keyNodeEntryOrRaw`, which
8807
+ * can be of type `BTNRep<K, V, NODE>` or `R`. This parameter represents either a key, a
8808
+ * node, an entry
8809
+ * @param {V} [value] - The `value` parameter in the `keyValueNodeEntryRawToNodeAndValue` function is
8810
+ * an optional parameter of type `V`. It represents the value associated with the key in the node
8811
+ * being created. If a `value` is provided, it will be used when creating the node. If
8812
+ * @returns The `keyValueNodeEntryRawToNodeAndValue` function returns an optional node
8813
+ * (`OptNodeOrNull<NODE>`) based on the input parameters provided. The function checks the type of the
8814
+ * input parameter (`keyNodeEntryOrRaw`) and processes it accordingly to return a node or null
8815
+ * value.
8816
+ */
8817
+ _keyValueNodeEntryRawToNodeAndValue(keyNodeEntryOrRaw, value) {
8818
+ if (keyNodeEntryOrRaw === void 0) return [void 0, void 0];
8819
+ if (keyNodeEntryOrRaw === null) return [null, void 0];
8820
+ if (this.isNode(keyNodeEntryOrRaw)) return [keyNodeEntryOrRaw, value];
8821
+ if (this.isEntry(keyNodeEntryOrRaw)) {
8822
+ const [key, entryValue] = keyNodeEntryOrRaw;
8823
+ if (key === void 0) return [void 0, void 0];
8824
+ else if (key === null) return [null, void 0];
8825
+ const finalValue = value != null ? value : entryValue;
8826
+ return [this.createNode(key, finalValue), finalValue];
8827
+ }
8828
+ if (this.isRaw(keyNodeEntryOrRaw)) {
8829
+ const [key, entryValue] = this._toEntryFn(keyNodeEntryOrRaw);
8830
+ const finalValue = value != null ? value : entryValue;
8831
+ if (this.isKey(key)) return [this.createNode(key, finalValue), finalValue];
8832
+ }
8833
+ if (this.isKey(keyNodeEntryOrRaw)) return [this.createNode(keyNodeEntryOrRaw, value), value];
8834
+ return [void 0, void 0];
8835
+ }
8580
8836
  /**
8581
8837
  * Time complexity: O(n)
8582
8838
  * Space complexity: O(n)
@@ -9049,22 +9305,22 @@ var dataStructureTyped = (() => {
9049
9305
  if (a < b) return -1;
9050
9306
  return 0;
9051
9307
  }
9052
- if (this._extractComparable) {
9053
- if (this._extractComparable(a) > this._extractComparable(b)) return 1;
9054
- if (this._extractComparable(a) < this._extractComparable(b)) return -1;
9308
+ if (this._specifyComparable) {
9309
+ if (this._specifyComparable(a) > this._specifyComparable(b)) return 1;
9310
+ if (this._specifyComparable(a) < this._specifyComparable(b)) return -1;
9055
9311
  return 0;
9056
9312
  }
9057
9313
  if (typeof a === "object" || typeof b === "object") {
9058
9314
  throw TypeError(
9059
- `When comparing object types, a custom extractComparable must be defined in the constructor's options parameter.`
9315
+ `When comparing object types, a custom specifyComparable must be defined in the constructor's options parameter.`
9060
9316
  );
9061
9317
  }
9062
9318
  return 0;
9063
9319
  });
9064
- __publicField(this, "_extractComparable");
9320
+ __publicField(this, "_specifyComparable");
9065
9321
  if (options) {
9066
- const { extractComparable, isReverse } = options;
9067
- if (typeof extractComparable === "function") this._extractComparable = extractComparable;
9322
+ const { specifyComparable, isReverse } = options;
9323
+ if (typeof specifyComparable === "function") this._specifyComparable = specifyComparable;
9068
9324
  if (isReverse !== void 0) this._isReverse = isReverse;
9069
9325
  }
9070
9326
  if (keysNodesEntriesOrRaws) this.addMany(keysNodesEntriesOrRaws);
@@ -9084,6 +9340,21 @@ var dataStructureTyped = (() => {
9084
9340
  get isReverse() {
9085
9341
  return this._isReverse;
9086
9342
  }
9343
+ /**
9344
+ * The function returns the value of the _comparator property.
9345
+ * @returns The `_comparator` property is being returned.
9346
+ */
9347
+ get comparator() {
9348
+ return this._comparator;
9349
+ }
9350
+ /**
9351
+ * This function returns the value of the `_specifyComparable` property.
9352
+ * @returns The method `specifyComparable()` is being returned, which is a getter method for the
9353
+ * `_specifyComparable` property.
9354
+ */
9355
+ get specifyComparable() {
9356
+ return this._specifyComparable;
9357
+ }
9087
9358
  /**
9088
9359
  * The function creates a new BSTNode with the given key and value and returns it.
9089
9360
  * @param {K} key - The key parameter is of type K, which represents the type of the key for the node
@@ -9096,35 +9367,26 @@ var dataStructureTyped = (() => {
9096
9367
  return new BSTNode(key, this._isMapMode ? void 0 : value);
9097
9368
  }
9098
9369
  /**
9099
- * The function creates a new binary search tree with the specified options.
9100
- * @param [options] - The `options` parameter is an optional object that allows you to customize the
9101
- * behavior of the `createTree` method. It accepts a partial `BSTOptions` object, which has the
9102
- * following properties:
9103
- * @returns a new instance of the BST class with the provided options.
9370
+ * Time Complexity: O(1)
9371
+ * Space Complexity: O(1)
9372
+ *
9373
+ * The `createTree` function in TypeScript overrides the default options with the provided options to
9374
+ * create a new Binary Search Tree.
9375
+ * @param [options] - The `options` parameter in the `createTree` method is an optional object that
9376
+ * can contain the following properties:
9377
+ * @returns A new instance of a Binary Search Tree (BST) is being returned with the specified options
9378
+ * and properties inherited from the current instance.
9104
9379
  */
9380
+ // @ts-ignore
9105
9381
  createTree(options) {
9106
9382
  return new _BST([], __spreadValues({
9107
9383
  iterationType: this.iterationType,
9108
9384
  isMapMode: this._isMapMode,
9109
- extractComparable: this._extractComparable,
9385
+ specifyComparable: this._specifyComparable,
9110
9386
  toEntryFn: this._toEntryFn,
9111
9387
  isReverse: this._isReverse
9112
9388
  }, options));
9113
9389
  }
9114
- /**
9115
- * The function overrides a method and converts a key, value pair or entry or raw element to a node.
9116
- * @param {BTNRep<K, V, NODE> | R} keyNodeEntryOrRaw - A variable that can be of
9117
- * type R or BTNRep<K, V, NODE>. It represents either a key, a node, an entry, or a raw
9118
- * element.
9119
- * @param {V} [value] - The `value` parameter is an optional value of type `V`. It represents the
9120
- * value associated with a key in a key-value pair.
9121
- * @returns either a NODE object or undefined.
9122
- */
9123
- keyValueNodeEntryRawToNodeAndValue(keyNodeEntryOrRaw, value) {
9124
- const [node, entryValue] = super.keyValueNodeEntryRawToNodeAndValue(keyNodeEntryOrRaw, value);
9125
- if (node === null) return [void 0, void 0];
9126
- return [node, value != null ? value : entryValue];
9127
- }
9128
9390
  /**
9129
9391
  * Time Complexity: O(log n)
9130
9392
  * Space Complexity: O(log n)
@@ -9163,7 +9425,7 @@ var dataStructureTyped = (() => {
9163
9425
  * this._DEFAULT_COMPARATOR`.
9164
9426
  */
9165
9427
  isKey(key) {
9166
- return isComparable(key, this._extractComparable !== void 0);
9428
+ return isComparable(key, this._specifyComparable !== void 0);
9167
9429
  }
9168
9430
  /**
9169
9431
  * Time Complexity: O(log n)
@@ -9177,7 +9439,7 @@ var dataStructureTyped = (() => {
9177
9439
  * @returns a boolean value.
9178
9440
  */
9179
9441
  add(keyNodeEntryOrRaw, value) {
9180
- const [newNode, newValue] = this.keyValueNodeEntryRawToNodeAndValue(keyNodeEntryOrRaw, value);
9442
+ const [newNode, newValue] = this._keyValueNodeEntryRawToNodeAndValue(keyNodeEntryOrRaw, value);
9181
9443
  if (newNode === void 0) return false;
9182
9444
  if (this._root === void 0) {
9183
9445
  this._setRoot(newNode);
@@ -9423,6 +9685,31 @@ var dataStructureTyped = (() => {
9423
9685
  }
9424
9686
  return ans;
9425
9687
  }
9688
+ /**
9689
+ * Time Complexity: O(log n)
9690
+ * Space Complexity: O(n)
9691
+ *
9692
+ * The `rangeSearch` function searches for nodes within a specified range in a binary search tree.
9693
+ * @param {Range<K> | [K, K]} range - The `range` parameter in the `rangeSearch` function can be
9694
+ * either a `Range` object or an array of two elements representing the range boundaries.
9695
+ * @param {C} callback - The `callback` parameter in the `rangeSearch` function is a callback
9696
+ * function that is used to process each node that is found within the specified range during the
9697
+ * search operation. It is of type `NodeCallback<NODE>`, where `NODE` is the type of nodes in the
9698
+ * data structure.
9699
+ * @param {BTNRep<K, V, NODE> | R} startNode - The `startNode` parameter in the `rangeSearch`
9700
+ * function represents the node from which the search for nodes within the specified range will
9701
+ * begin. It is the starting point for the range search operation.
9702
+ * @param {IterationType} iterationType - The `iterationType` parameter in the `rangeSearch` function
9703
+ * is used to specify the type of iteration to be performed during the search operation. It has a
9704
+ * default value of `this.iterationType`, which suggests that it is likely a property of the class or
9705
+ * object that the `rangeSearch`
9706
+ * @returns The `rangeSearch` function is returning the result of calling the `search` method with
9707
+ * the specified parameters.
9708
+ */
9709
+ rangeSearch(range, callback = this._DEFAULT_NODE_CALLBACK, startNode = this._root, iterationType = this.iterationType) {
9710
+ const searchRange = range instanceof Range ? range : new Range(range[0], range[1]);
9711
+ return this.search(searchRange, false, callback, startNode, iterationType);
9712
+ }
9426
9713
  /**
9427
9714
  * Time Complexity: O(log n)
9428
9715
  * Space Complexity: O(1)
@@ -9657,20 +9944,28 @@ var dataStructureTyped = (() => {
9657
9944
  }
9658
9945
  return balanced;
9659
9946
  }
9660
- /**
9661
- * The function returns the value of the _comparator property.
9662
- * @returns The `_comparator` property is being returned.
9663
- */
9664
- get comparator() {
9665
- return this._comparator;
9947
+ // @ts-ignore
9948
+ map(callback, options, thisArg) {
9949
+ const newTree = new _BST([], options);
9950
+ let index = 0;
9951
+ for (const [key, value] of this) {
9952
+ newTree.add(callback.call(thisArg, key, value, index++, this));
9953
+ }
9954
+ return newTree;
9666
9955
  }
9667
9956
  /**
9668
- * This function returns the value of the `_extractComparable` property.
9669
- * @returns The method `extractComparable()` is being returned, which is a getter method for the
9670
- * `_extractComparable` property.
9957
+ * The function overrides a method and converts a key, value pair or entry or raw element to a node.
9958
+ * @param {BTNRep<K, V, NODE> | R} keyNodeEntryOrRaw - A variable that can be of
9959
+ * type R or BTNRep<K, V, NODE>. It represents either a key, a node, an entry, or a raw
9960
+ * element.
9961
+ * @param {V} [value] - The `value` parameter is an optional value of type `V`. It represents the
9962
+ * value associated with a key in a key-value pair.
9963
+ * @returns either a NODE object or undefined.
9671
9964
  */
9672
- get extractComparable() {
9673
- return this._extractComparable;
9965
+ _keyValueNodeEntryRawToNodeAndValue(keyNodeEntryOrRaw, value) {
9966
+ const [node, entryValue] = super._keyValueNodeEntryRawToNodeAndValue(keyNodeEntryOrRaw, value);
9967
+ if (node === null) return [void 0, void 0];
9968
+ return [node, value != null ? value : entryValue];
9674
9969
  }
9675
9970
  /**
9676
9971
  * The function sets the root of a tree-like structure and updates the parent property of the new
@@ -10311,17 +10606,21 @@ var dataStructureTyped = (() => {
10311
10606
  return new AVLTreeNode(key, this._isMapMode ? void 0 : value);
10312
10607
  }
10313
10608
  /**
10314
- * The function creates a new AVL tree with the specified options and returns it.
10315
- * @param {AVLTreeOptions} [options] - The `options` parameter is an optional object that can be
10316
- * passed to the `createTree` function. It is used to customize the behavior of the AVL tree that is
10317
- * being created.
10318
- * @returns a new AVLTree object.
10319
- */
10609
+ * The function `createTree` in TypeScript overrides the default AVLTree creation with the provided
10610
+ * options.
10611
+ * @param [options] - The `options` parameter in the `createTree` function is an object that contains
10612
+ * configuration options for creating an AVL tree. These options can include properties such as
10613
+ * `iterationType`, `isMapMode`, `specifyComparable`, `toEntryFn`, and `isReverse`. The function
10614
+ * creates a
10615
+ * @returns An AVLTree object is being returned with the specified options and properties inherited
10616
+ * from the current object.
10617
+ */
10618
+ // @ts-ignore
10320
10619
  createTree(options) {
10321
10620
  return new _AVLTree([], __spreadValues({
10322
10621
  iterationType: this.iterationType,
10323
10622
  isMapMode: this._isMapMode,
10324
- extractComparable: this._extractComparable,
10623
+ specifyComparable: this._specifyComparable,
10325
10624
  toEntryFn: this._toEntryFn,
10326
10625
  isReverse: this._isReverse
10327
10626
  }, options));
@@ -10377,6 +10676,15 @@ var dataStructureTyped = (() => {
10377
10676
  }
10378
10677
  return deletedResults;
10379
10678
  }
10679
+ // @ts-ignore
10680
+ map(callback, options, thisArg) {
10681
+ const newTree = new _AVLTree([], options);
10682
+ let index = 0;
10683
+ for (const [key, value] of this) {
10684
+ newTree.add(callback.call(thisArg, key, value, index++, this));
10685
+ }
10686
+ return newTree;
10687
+ }
10380
10688
  /**
10381
10689
  * Time Complexity: O(1)
10382
10690
  * Space Complexity: O(1)
@@ -10655,7 +10963,7 @@ var dataStructureTyped = (() => {
10655
10963
  }
10656
10964
  };
10657
10965
 
10658
- // src/data-structures/binary-tree/rb-tree.ts
10966
+ // src/data-structures/binary-tree/red-black-tree.ts
10659
10967
  var RedBlackTreeNode = class extends BSTNode {
10660
10968
  /**
10661
10969
  * The constructor function initializes a Red-Black Tree Node with a key, an optional value, and a
@@ -10693,9 +11001,9 @@ var dataStructureTyped = (() => {
10693
11001
  * This is the constructor function for a Red-Black Tree data structure in TypeScript.
10694
11002
  * @param keysNodesEntriesOrRaws - The `keysNodesEntriesOrRaws` parameter is an
10695
11003
  * iterable object that can contain either keys, nodes, entries, or raw elements. It is used to
10696
- * initialize the RBTree with the provided elements.
11004
+ * initialize the RedBlackTree with the provided elements.
10697
11005
  * @param [options] - The `options` parameter is an optional object that can be passed to the
10698
- * constructor. It is of type `RBTreeOptions<K, V, R>`. This object can contain various options for
11006
+ * constructor. It is of type `RedBlackTreeOptions<K, V, R>`. This object can contain various options for
10699
11007
  * configuring the behavior of the Red-Black Tree. The specific properties and their meanings would
10700
11008
  * depend on the implementation
10701
11009
  */
@@ -10732,16 +11040,20 @@ var dataStructureTyped = (() => {
10732
11040
  return new RedBlackTreeNode(key, this._isMapMode ? void 0 : value, color);
10733
11041
  }
10734
11042
  /**
10735
- * The function creates a new Red-Black Tree with the specified options.
10736
- * @param [options] - The `options` parameter is an optional object that contains additional
10737
- * configuration options for creating the Red-Black Tree. It has the following properties:
10738
- * @returns a new instance of a RedBlackTree object.
11043
+ * The function `createTree` overrides the default implementation to create a Red-Black Tree with
11044
+ * specified options in TypeScript.
11045
+ * @param [options] - The `options` parameter in the `createTree` method is of type `RedBlackTreeOptions<K,
11046
+ * V, R>`, which is a generic type with three type parameters `K`, `V`, and `R`. This parameter
11047
+ * allows you to pass additional configuration options when creating a new Red-
11048
+ * @returns A new instance of a RedBlackTree with the specified options and properties from the
11049
+ * current object is being returned.
10739
11050
  */
11051
+ // @ts-ignore
10740
11052
  createTree(options) {
10741
11053
  return new _RedBlackTree([], __spreadValues({
10742
11054
  iterationType: this.iterationType,
10743
11055
  isMapMode: this._isMapMode,
10744
- extractComparable: this._extractComparable,
11056
+ specifyComparable: this._specifyComparable,
10745
11057
  toEntryFn: this._toEntryFn
10746
11058
  }, options));
10747
11059
  }
@@ -10758,41 +11070,6 @@ var dataStructureTyped = (() => {
10758
11070
  isNode(keyNodeEntryOrRaw) {
10759
11071
  return keyNodeEntryOrRaw instanceof RedBlackTreeNode;
10760
11072
  }
10761
- // /**
10762
- // * Time Complexity: O(1)
10763
- // * Space Complexity: O(1)
10764
- // */
10765
- //
10766
- // /**
10767
- // * Time Complexity: O(1)
10768
- // * Space Complexity: O(1)
10769
- // *
10770
- // * The function `keyValueNodeEntryRawToNodeAndValue` takes a key, value, or entry and returns a node if it is
10771
- // * valid, otherwise it returns undefined.
10772
- // * @param {BTNRep<K, V, NODE>} keyNodeEntryOrRaw - The key, value, or entry to convert.
10773
- // * @param {V} [value] - The value associated with the key (if `keyNodeEntryOrRaw` is a key).
10774
- // * @returns {NODE | undefined} - The corresponding Red-Black Tree node, or `undefined` if conversion fails.
10775
- // */
10776
- // override keyValueNodeEntryRawToNodeAndValue(keyNodeEntryOrRaw: BTNRep<K, V, NODE> | R, value?: V): NODE | undefined {
10777
- //
10778
- // if (keyNodeEntryOrRaw === null || keyNodeEntryOrRaw === undefined) return;
10779
- // if (this.isNode(keyNodeEntryOrRaw)) return keyNodeEntryOrRaw;
10780
- //
10781
- // if (this._toEntryFn) {
10782
- // const [key, entryValue] = this._toEntryFn(keyNodeEntryOrRaw as R);
10783
- // if (this.isKey(key)) return this.createNode(key, value ?? entryValue, 'RED');
10784
- // }
10785
- //
10786
- // if (this.isEntry(keyNodeEntryOrRaw)) {
10787
- // const [key, value] = keyNodeEntryOrRaw;
10788
- // if (key === undefined || key === null) return;
10789
- // else return this.createNode(key, value, 'RED');
10790
- // }
10791
- //
10792
- // if (this.isKey(keyNodeEntryOrRaw)) return this.createNode(keyNodeEntryOrRaw, value, 'RED');
10793
- //
10794
- // return ;
10795
- // }
10796
11073
  /**
10797
11074
  * Time Complexity: O(1)
10798
11075
  * Space Complexity: O(1)
@@ -10820,7 +11097,7 @@ var dataStructureTyped = (() => {
10820
11097
  * returns true. If the node cannot be added or updated, the method returns false.
10821
11098
  */
10822
11099
  add(keyNodeEntryOrRaw, value) {
10823
- const [newNode, newValue] = this.keyValueNodeEntryRawToNodeAndValue(keyNodeEntryOrRaw, value);
11100
+ const [newNode, newValue] = this._keyValueNodeEntryRawToNodeAndValue(keyNodeEntryOrRaw, value);
10824
11101
  if (!this.isRealNode(newNode)) return false;
10825
11102
  const insertStatus = this._insert(newNode);
10826
11103
  if (insertStatus === "CREATED") {
@@ -10902,6 +11179,35 @@ var dataStructureTyped = (() => {
10902
11179
  results.push({ deleted: nodeToDelete, needBalanced: void 0 });
10903
11180
  return results;
10904
11181
  }
11182
+ /**
11183
+ * Time Complexity: O(n)
11184
+ * Space Complexity: O(n)
11185
+ *
11186
+ * The `map` function in TypeScript overrides the default behavior to create a new Red-Black Tree by
11187
+ * applying a callback to each entry in the original tree.
11188
+ * @param callback - A function that will be called for each entry in the tree, with parameters
11189
+ * representing the key, value, index, and the tree itself. It should return an entry for the new
11190
+ * tree.
11191
+ * @param [options] - The `options` parameter in the `map` method is of type `RedBlackTreeOptions<MK, MV,
11192
+ * MR>`. This parameter allows you to specify additional options or configurations for the Red-Black
11193
+ * Tree that will be created during the mapping process. These options could include things like
11194
+ * custom comparators
11195
+ * @param {any} [thisArg] - The `thisArg` parameter in the `override map` function is used to specify
11196
+ * the value of `this` when executing the `callback` function. It allows you to set the context
11197
+ * (value of `this`) for the callback function. This can be useful when you want to access properties
11198
+ * or
11199
+ * @returns A new Red-Black Tree is being returned, where each entry has been transformed using the
11200
+ * provided callback function.
11201
+ */
11202
+ // @ts-ignore
11203
+ map(callback, options, thisArg) {
11204
+ const newTree = new _RedBlackTree([], options);
11205
+ let index = 0;
11206
+ for (const [key, value] of this) {
11207
+ newTree.add(callback.call(thisArg, key, value, index++, this));
11208
+ }
11209
+ return newTree;
11210
+ }
10905
11211
  /**
10906
11212
  * Time Complexity: O(1)
10907
11213
  * Space Complexity: O(1)
@@ -10963,7 +11269,7 @@ var dataStructureTyped = (() => {
10963
11269
  node.parent = parent;
10964
11270
  if (!parent) {
10965
11271
  this._setRoot(node);
10966
- } else if (node.key < parent.key) {
11272
+ } else if (this._compare(node.key, parent.key) < 0) {
10967
11273
  parent.left = node;
10968
11274
  } else {
10969
11275
  parent.right = node;
@@ -11261,11 +11567,12 @@ var dataStructureTyped = (() => {
11261
11567
  * @returns a new instance of the AVLTreeMultiMap class, with the specified options, as a TREE
11262
11568
  * object.
11263
11569
  */
11570
+ // @ts-ignore
11264
11571
  createTree(options) {
11265
11572
  return new _AVLTreeMultiMap([], __spreadValues({
11266
11573
  iterationType: this.iterationType,
11267
11574
  isMapMode: this._isMapMode,
11268
- extractComparable: this._extractComparable,
11575
+ specifyComparable: this._specifyComparable,
11269
11576
  toEntryFn: this._toEntryFn,
11270
11577
  isReverse: this._isReverse
11271
11578
  }, options));
@@ -11280,35 +11587,6 @@ var dataStructureTyped = (() => {
11280
11587
  isNode(keyNodeEntryOrRaw) {
11281
11588
  return keyNodeEntryOrRaw instanceof AVLTreeMultiMapNode;
11282
11589
  }
11283
- /**
11284
- * The function `keyValueNodeEntryRawToNodeAndValue` converts a key, value, entry, or raw element into
11285
- * a node object.
11286
- * @param {BTNRep<K, V, NODE> | R} keyNodeEntryOrRaw - The
11287
- * `keyNodeEntryOrRaw` parameter can be of type `R` or `BTNRep<K, V, NODE>`.
11288
- * @param {V} [value] - The `value` parameter is an optional value that can be passed to the
11289
- * `override` function. It represents the value associated with the key in the data structure. If no
11290
- * value is provided, it will default to `undefined`.
11291
- * @param [count=1] - The `count` parameter is an optional parameter that specifies the number of
11292
- * times the key-value pair should be added to the data structure. If not provided, it defaults to 1.
11293
- * @returns either a NODE object or undefined.
11294
- */
11295
- keyValueNodeEntryRawToNodeAndValue(keyNodeEntryOrRaw, value, count = 1) {
11296
- if (keyNodeEntryOrRaw === void 0 || keyNodeEntryOrRaw === null) return [void 0, void 0];
11297
- if (this.isNode(keyNodeEntryOrRaw)) return [keyNodeEntryOrRaw, value];
11298
- if (this.isEntry(keyNodeEntryOrRaw)) {
11299
- const [key, entryValue] = keyNodeEntryOrRaw;
11300
- if (key === void 0 || key === null) return [void 0, void 0];
11301
- const finalValue = value != null ? value : entryValue;
11302
- return [this.createNode(key, finalValue, count), finalValue];
11303
- }
11304
- if (this.isRaw(keyNodeEntryOrRaw)) {
11305
- const [key, entryValue] = this._toEntryFn(keyNodeEntryOrRaw);
11306
- const finalValue = value != null ? value : entryValue;
11307
- if (this.isKey(key)) return [this.createNode(key, finalValue, count), finalValue];
11308
- }
11309
- if (this.isKey(keyNodeEntryOrRaw)) return [this.createNode(keyNodeEntryOrRaw, value, count), value];
11310
- return [void 0, void 0];
11311
- }
11312
11590
  /**
11313
11591
  * Time Complexity: O(log n)
11314
11592
  * Space Complexity: O(1)
@@ -11327,7 +11605,7 @@ var dataStructureTyped = (() => {
11327
11605
  * @returns a boolean value.
11328
11606
  */
11329
11607
  add(keyNodeEntryOrRaw, value, count = 1) {
11330
- const [newNode, newValue] = this.keyValueNodeEntryRawToNodeAndValue(keyNodeEntryOrRaw, value, count);
11608
+ const [newNode, newValue] = this._keyValueNodeEntryRawToNodeAndValue(keyNodeEntryOrRaw, value, count);
11331
11609
  if (newNode === void 0) return false;
11332
11610
  const orgNodeCount = (newNode == null ? void 0 : newNode.count) || 0;
11333
11611
  const inserted = super.add(newNode, newValue);
@@ -11468,6 +11746,7 @@ var dataStructureTyped = (() => {
11468
11746
  * The function overrides the clone method to create a deep copy of a tree object.
11469
11747
  * @returns The `clone()` method is returning a cloned instance of the `TREE` object.
11470
11748
  */
11749
+ // @ts-ignore
11471
11750
  clone() {
11472
11751
  const cloned = this.createTree();
11473
11752
  if (this._isMapMode) this.bfs((node) => cloned.add(node.key, void 0, node.count));
@@ -11475,6 +11754,62 @@ var dataStructureTyped = (() => {
11475
11754
  if (this._isMapMode) cloned._store = this._store;
11476
11755
  return cloned;
11477
11756
  }
11757
+ /**
11758
+ * The `map` function in TypeScript overrides the default behavior to create a new AVLTreeMultiMap
11759
+ * with modified entries based on a provided callback.
11760
+ * @param callback - The `callback` parameter is a function that will be called for each entry in the
11761
+ * AVLTreeMultiMap. It takes four arguments:
11762
+ * @param [options] - The `options` parameter in the `override map` function is of type
11763
+ * `AVLTreeMultiMapOptions<MK, MV, MR>`. This parameter allows you to provide additional
11764
+ * configuration options when creating a new `AVLTreeMultiMap` instance within the `map` function.
11765
+ * These options
11766
+ * @param {any} [thisArg] - The `thisArg` parameter in the `override map` function is used to specify
11767
+ * the value of `this` when executing the `callback` function. It allows you to set the context
11768
+ * (value of `this`) for the callback function. This can be useful when you want to access properties
11769
+ * or
11770
+ * @returns The `map` method is returning a new `AVLTreeMultiMap` instance with the entries
11771
+ * transformed by the provided `callback` function. Each entry in the original tree is passed to the
11772
+ * `callback` function along with the index and the original tree itself. The transformed entries are
11773
+ * then added to the new `AVLTreeMultiMap` instance, which is returned at the end.
11774
+ */
11775
+ // @ts-ignore
11776
+ map(callback, options, thisArg) {
11777
+ const newTree = new _AVLTreeMultiMap([], options);
11778
+ let index = 0;
11779
+ for (const [key, value] of this) {
11780
+ newTree.add(callback.call(thisArg, key, value, index++, this));
11781
+ }
11782
+ return newTree;
11783
+ }
11784
+ /**
11785
+ * The function `keyValueNodeEntryRawToNodeAndValue` converts a key, value, entry, or raw element into
11786
+ * a node object.
11787
+ * @param {BTNRep<K, V, NODE> | R} keyNodeEntryOrRaw - The
11788
+ * `keyNodeEntryOrRaw` parameter can be of type `R` or `BTNRep<K, V, NODE>`.
11789
+ * @param {V} [value] - The `value` parameter is an optional value that can be passed to the
11790
+ * `override` function. It represents the value associated with the key in the data structure. If no
11791
+ * value is provided, it will default to `undefined`.
11792
+ * @param [count=1] - The `count` parameter is an optional parameter that specifies the number of
11793
+ * times the key-value pair should be added to the data structure. If not provided, it defaults to 1.
11794
+ * @returns either a NODE object or undefined.
11795
+ */
11796
+ _keyValueNodeEntryRawToNodeAndValue(keyNodeEntryOrRaw, value, count = 1) {
11797
+ if (keyNodeEntryOrRaw === void 0 || keyNodeEntryOrRaw === null) return [void 0, void 0];
11798
+ if (this.isNode(keyNodeEntryOrRaw)) return [keyNodeEntryOrRaw, value];
11799
+ if (this.isEntry(keyNodeEntryOrRaw)) {
11800
+ const [key, entryValue] = keyNodeEntryOrRaw;
11801
+ if (key === void 0 || key === null) return [void 0, void 0];
11802
+ const finalValue = value != null ? value : entryValue;
11803
+ return [this.createNode(key, finalValue, count), finalValue];
11804
+ }
11805
+ if (this.isRaw(keyNodeEntryOrRaw)) {
11806
+ const [key, entryValue] = this._toEntryFn(keyNodeEntryOrRaw);
11807
+ const finalValue = value != null ? value : entryValue;
11808
+ if (this.isKey(key)) return [this.createNode(key, finalValue, count), finalValue];
11809
+ }
11810
+ if (this.isKey(keyNodeEntryOrRaw)) return [this.createNode(keyNodeEntryOrRaw, value, count), value];
11811
+ return [void 0, void 0];
11812
+ }
11478
11813
  /**
11479
11814
  * Time Complexity: O(1)
11480
11815
  * Space Complexity: O(1)
@@ -11621,43 +11956,15 @@ var dataStructureTyped = (() => {
11621
11956
  * @returns a new instance of the `TreeMultiMap` class, with the provided options merged with the
11622
11957
  * existing `iterationType` property. The returned value is casted as `TREE`.
11623
11958
  */
11959
+ // @ts-ignore
11624
11960
  createTree(options) {
11625
11961
  return new _TreeMultiMap([], __spreadValues({
11626
11962
  iterationType: this.iterationType,
11627
11963
  isMapMode: this._isMapMode,
11628
- extractComparable: this._extractComparable,
11964
+ specifyComparable: this._specifyComparable,
11629
11965
  toEntryFn: this._toEntryFn
11630
11966
  }, options));
11631
11967
  }
11632
- /**
11633
- * The function `keyValueNodeEntryRawToNodeAndValue` takes in a key, value, and count and returns a
11634
- * node based on the input.
11635
- * @param {BTNRep<K, V, NODE> | R} keyNodeEntryOrRaw - The parameter
11636
- * `keyNodeEntryOrRaw` can be of type `R` or `BTNRep<K, V, NODE>`.
11637
- * @param {V} [value] - The `value` parameter is an optional value that represents the value
11638
- * associated with the key in the node. It is used when creating a new node or updating the value of
11639
- * an existing node.
11640
- * @param [count=1] - The `count` parameter is an optional parameter that specifies the number of
11641
- * times the key-value pair should be added to the data structure. If not provided, it defaults to 1.
11642
- * @returns either a NODE object or undefined.
11643
- */
11644
- keyValueNodeEntryRawToNodeAndValue(keyNodeEntryOrRaw, value, count = 1) {
11645
- if (keyNodeEntryOrRaw === void 0 || keyNodeEntryOrRaw === null) return [void 0, void 0];
11646
- if (this.isNode(keyNodeEntryOrRaw)) return [keyNodeEntryOrRaw, value];
11647
- if (this.isEntry(keyNodeEntryOrRaw)) {
11648
- const [key, entryValue] = keyNodeEntryOrRaw;
11649
- if (key === void 0 || key === null) return [void 0, void 0];
11650
- const finalValue = value != null ? value : entryValue;
11651
- if (this.isKey(key)) return [this.createNode(key, finalValue, "BLACK", count), finalValue];
11652
- }
11653
- if (this.isRaw(keyNodeEntryOrRaw)) {
11654
- const [key, entryValue] = this._toEntryFn(keyNodeEntryOrRaw);
11655
- const finalValue = value != null ? value : entryValue;
11656
- if (this.isKey(key)) return [this.createNode(key, finalValue, "BLACK", count), finalValue];
11657
- }
11658
- if (this.isKey(keyNodeEntryOrRaw)) return [this.createNode(keyNodeEntryOrRaw, value, "BLACK", count), value];
11659
- return [void 0, void 0];
11660
- }
11661
11968
  /**
11662
11969
  * The function checks if the input is an instance of the TreeMultiMapNode class.
11663
11970
  * @param {BTNRep<K, V, NODE> | R} keyNodeEntryOrRaw - The parameter
@@ -11685,7 +11992,7 @@ var dataStructureTyped = (() => {
11685
11992
  * was successful, and false otherwise.
11686
11993
  */
11687
11994
  add(keyNodeEntryOrRaw, value, count = 1) {
11688
- const [newNode, newValue] = this.keyValueNodeEntryRawToNodeAndValue(keyNodeEntryOrRaw, value, count);
11995
+ const [newNode, newValue] = this._keyValueNodeEntryRawToNodeAndValue(keyNodeEntryOrRaw, value, count);
11689
11996
  const orgCount = (newNode == null ? void 0 : newNode.count) || 0;
11690
11997
  const isSuccessAdded = super.add(newNode, newValue);
11691
11998
  if (isSuccessAdded) {
@@ -11856,12 +12163,66 @@ var dataStructureTyped = (() => {
11856
12163
  * The function overrides the clone method to create a deep copy of a tree object.
11857
12164
  * @returns The `clone()` method is returning a cloned instance of the `TREE` object.
11858
12165
  */
12166
+ // @ts-ignore
11859
12167
  clone() {
11860
12168
  const cloned = this.createTree();
11861
12169
  this.bfs((node) => cloned.add(node.key, void 0, node.count));
11862
12170
  if (this._isMapMode) cloned._store = this._store;
11863
12171
  return cloned;
11864
12172
  }
12173
+ /**
12174
+ * The `map` function in TypeScript overrides the default behavior to create a new TreeMultiMap with
12175
+ * modified entries based on a provided callback.
12176
+ * @param callback - The `callback` parameter is a function that will be called for each entry in the
12177
+ * map. It takes four arguments:
12178
+ * @param [options] - The `options` parameter in the `override map` function is of type
12179
+ * `TreeMultiMapOptions<MK, MV, MR>`. This parameter allows you to provide additional configuration
12180
+ * options when creating a new `TreeMultiMap` instance within the `map` function. These options could
12181
+ * include things like
12182
+ * @param {any} [thisArg] - The `thisArg` parameter in the `override map` function is used to specify
12183
+ * the value of `this` when executing the `callback` function. It allows you to set the context
12184
+ * (value of `this`) for the callback function when it is called within the `map` function. This
12185
+ * @returns A new TreeMultiMap instance is being returned, which is populated with entries generated
12186
+ * by the provided callback function.
12187
+ */
12188
+ // @ts-ignore
12189
+ map(callback, options, thisArg) {
12190
+ const newTree = new _TreeMultiMap([], options);
12191
+ let index = 0;
12192
+ for (const [key, value] of this) {
12193
+ newTree.add(callback.call(thisArg, key, value, index++, this));
12194
+ }
12195
+ return newTree;
12196
+ }
12197
+ /**
12198
+ * The function `keyValueNodeEntryRawToNodeAndValue` takes in a key, value, and count and returns a
12199
+ * node based on the input.
12200
+ * @param {BTNRep<K, V, NODE> | R} keyNodeEntryOrRaw - The parameter
12201
+ * `keyNodeEntryOrRaw` can be of type `R` or `BTNRep<K, V, NODE>`.
12202
+ * @param {V} [value] - The `value` parameter is an optional value that represents the value
12203
+ * associated with the key in the node. It is used when creating a new node or updating the value of
12204
+ * an existing node.
12205
+ * @param [count=1] - The `count` parameter is an optional parameter that specifies the number of
12206
+ * times the key-value pair should be added to the data structure. If not provided, it defaults to 1.
12207
+ * @returns either a NODE object or undefined.
12208
+ */
12209
+ _keyValueNodeEntryRawToNodeAndValue(keyNodeEntryOrRaw, value, count = 1) {
12210
+ if (keyNodeEntryOrRaw === void 0 || keyNodeEntryOrRaw === null) return [void 0, void 0];
12211
+ if (this.isNode(keyNodeEntryOrRaw)) return [keyNodeEntryOrRaw, value];
12212
+ if (this.isEntry(keyNodeEntryOrRaw)) {
12213
+ const [key, entryValue] = keyNodeEntryOrRaw;
12214
+ if (key === void 0 || key === null) return [void 0, void 0];
12215
+ const finalValue = value != null ? value : entryValue;
12216
+ if (this.isKey(key)) return [this.createNode(key, finalValue, "BLACK", count), finalValue];
12217
+ }
12218
+ if (this.isRaw(keyNodeEntryOrRaw)) {
12219
+ const [key, entryValue] = this._toEntryFn(keyNodeEntryOrRaw);
12220
+ const finalValue = value != null ? value : entryValue;
12221
+ if (this.isKey(key)) return [this.createNode(key, finalValue, "BLACK", count), finalValue];
12222
+ }
12223
+ if (this.isKey(keyNodeEntryOrRaw)) return [this.createNode(keyNodeEntryOrRaw, value, "BLACK", count), value];
12224
+ return [void 0, void 0];
12225
+ }
11865
12226
  /**
11866
12227
  * Time Complexity: O(1)
11867
12228
  * Space Complexity: O(1)
@@ -12853,7 +13214,7 @@ var dataStructureTyped = (() => {
12853
13214
  * @returns The `addMany` method returns an array of boolean values indicating whether each word in
12854
13215
  * the input iterable was successfully added to the data structure.
12855
13216
  */
12856
- addMany(words = []) {
13217
+ addMany(words) {
12857
13218
  const ans = [];
12858
13219
  for (const word of words) {
12859
13220
  if (this.toElementFn) {
@@ -12945,9 +13306,14 @@ var dataStructureTyped = (() => {
12945
13306
  return isDeleted;
12946
13307
  }
12947
13308
  /**
12948
- * Time Complexity: O(n), where n is the total number of nodes in the trie.
12949
- * Space Complexity: O(1) - Constant space.
13309
+ * Time Complexity: O(n)
13310
+ * Space Complexity: O(1)
12950
13311
  *
13312
+ * The function `getHeight` calculates the height of a trie data structure starting from the root
13313
+ * node.
13314
+ * @returns The `getHeight` method returns the maximum depth or height of the trie tree starting from
13315
+ * the root node. It calculates the depth using a breadth-first search (BFS) traversal of the trie
13316
+ * tree and returns the maximum depth found.
12951
13317
  */
12952
13318
  getHeight() {
12953
13319
  const startNode = this.root;