data-structure-typed 1.51.8 → 1.52.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (216) hide show
  1. package/CHANGELOG.md +1 -1
  2. package/README.md +13 -13
  3. package/benchmark/report.html +13 -13
  4. package/benchmark/report.json +152 -152
  5. package/dist/cjs/data-structures/base/index.d.ts +2 -1
  6. package/dist/cjs/data-structures/base/index.js +2 -1
  7. package/dist/cjs/data-structures/base/index.js.map +1 -1
  8. package/dist/cjs/data-structures/base/iterable-element-base.d.ts +171 -0
  9. package/dist/cjs/data-structures/base/iterable-element-base.js +226 -0
  10. package/dist/cjs/data-structures/base/iterable-element-base.js.map +1 -0
  11. package/dist/cjs/data-structures/base/{iterable-base.d.ts → iterable-entry-base.d.ts} +4 -147
  12. package/dist/cjs/data-structures/base/{iterable-base.js → iterable-entry-base.js} +13 -190
  13. package/dist/cjs/data-structures/base/iterable-entry-base.js.map +1 -0
  14. package/dist/cjs/data-structures/binary-tree/avl-tree-multi-map.d.ts +106 -68
  15. package/dist/cjs/data-structures/binary-tree/avl-tree-multi-map.js +119 -87
  16. package/dist/cjs/data-structures/binary-tree/avl-tree-multi-map.js.map +1 -1
  17. package/dist/cjs/data-structures/binary-tree/avl-tree.d.ts +82 -62
  18. package/dist/cjs/data-structures/binary-tree/avl-tree.js +78 -59
  19. package/dist/cjs/data-structures/binary-tree/avl-tree.js.map +1 -1
  20. package/dist/cjs/data-structures/binary-tree/binary-tree.d.ts +318 -226
  21. package/dist/cjs/data-structures/binary-tree/binary-tree.js +475 -363
  22. package/dist/cjs/data-structures/binary-tree/binary-tree.js.map +1 -1
  23. package/dist/cjs/data-structures/binary-tree/bst.d.ts +192 -202
  24. package/dist/cjs/data-structures/binary-tree/bst.js +207 -249
  25. package/dist/cjs/data-structures/binary-tree/bst.js.map +1 -1
  26. package/dist/cjs/data-structures/binary-tree/rb-tree.d.ts +73 -74
  27. package/dist/cjs/data-structures/binary-tree/rb-tree.js +107 -98
  28. package/dist/cjs/data-structures/binary-tree/rb-tree.js.map +1 -1
  29. package/dist/cjs/data-structures/binary-tree/tree-multi-map.d.ts +92 -75
  30. package/dist/cjs/data-structures/binary-tree/tree-multi-map.js +105 -93
  31. package/dist/cjs/data-structures/binary-tree/tree-multi-map.js.map +1 -1
  32. package/dist/cjs/data-structures/graph/abstract-graph.d.ts +10 -15
  33. package/dist/cjs/data-structures/graph/abstract-graph.js +10 -15
  34. package/dist/cjs/data-structures/graph/abstract-graph.js.map +1 -1
  35. package/dist/cjs/data-structures/hash/hash-map.d.ts +33 -40
  36. package/dist/cjs/data-structures/hash/hash-map.js +40 -55
  37. package/dist/cjs/data-structures/hash/hash-map.js.map +1 -1
  38. package/dist/cjs/data-structures/heap/heap.d.ts +43 -114
  39. package/dist/cjs/data-structures/heap/heap.js +59 -127
  40. package/dist/cjs/data-structures/heap/heap.js.map +1 -1
  41. package/dist/cjs/data-structures/heap/max-heap.d.ts +50 -4
  42. package/dist/cjs/data-structures/heap/max-heap.js +76 -10
  43. package/dist/cjs/data-structures/heap/max-heap.js.map +1 -1
  44. package/dist/cjs/data-structures/heap/min-heap.d.ts +51 -5
  45. package/dist/cjs/data-structures/heap/min-heap.js +68 -11
  46. package/dist/cjs/data-structures/heap/min-heap.js.map +1 -1
  47. package/dist/cjs/data-structures/linked-list/doubly-linked-list.d.ts +22 -28
  48. package/dist/cjs/data-structures/linked-list/doubly-linked-list.js +26 -28
  49. package/dist/cjs/data-structures/linked-list/doubly-linked-list.js.map +1 -1
  50. package/dist/cjs/data-structures/linked-list/singly-linked-list.d.ts +22 -25
  51. package/dist/cjs/data-structures/linked-list/singly-linked-list.js +29 -26
  52. package/dist/cjs/data-structures/linked-list/singly-linked-list.js.map +1 -1
  53. package/dist/cjs/data-structures/priority-queue/max-priority-queue.d.ts +50 -4
  54. package/dist/cjs/data-structures/priority-queue/max-priority-queue.js +79 -10
  55. package/dist/cjs/data-structures/priority-queue/max-priority-queue.js.map +1 -1
  56. package/dist/cjs/data-structures/priority-queue/min-priority-queue.d.ts +51 -5
  57. package/dist/cjs/data-structures/priority-queue/min-priority-queue.js +71 -11
  58. package/dist/cjs/data-structures/priority-queue/min-priority-queue.js.map +1 -1
  59. package/dist/cjs/data-structures/priority-queue/priority-queue.d.ts +50 -4
  60. package/dist/cjs/data-structures/priority-queue/priority-queue.js +70 -1
  61. package/dist/cjs/data-structures/priority-queue/priority-queue.js.map +1 -1
  62. package/dist/cjs/data-structures/queue/deque.d.ts +21 -20
  63. package/dist/cjs/data-structures/queue/deque.js +29 -23
  64. package/dist/cjs/data-structures/queue/deque.js.map +1 -1
  65. package/dist/cjs/data-structures/queue/queue.d.ts +8 -28
  66. package/dist/cjs/data-structures/queue/queue.js +15 -31
  67. package/dist/cjs/data-structures/queue/queue.js.map +1 -1
  68. package/dist/cjs/data-structures/stack/stack.d.ts +17 -22
  69. package/dist/cjs/data-structures/stack/stack.js +25 -24
  70. package/dist/cjs/data-structures/stack/stack.js.map +1 -1
  71. package/dist/cjs/data-structures/trie/trie.d.ts +19 -14
  72. package/dist/cjs/data-structures/trie/trie.js +27 -16
  73. package/dist/cjs/data-structures/trie/trie.js.map +1 -1
  74. package/dist/cjs/interfaces/binary-tree.d.ts +7 -7
  75. package/dist/cjs/types/common.d.ts +1 -2
  76. package/dist/cjs/types/data-structures/base/base.d.ts +5 -2
  77. package/dist/cjs/types/data-structures/binary-tree/avl-tree-multi-map.d.ts +3 -4
  78. package/dist/cjs/types/data-structures/binary-tree/avl-tree.d.ts +3 -4
  79. package/dist/cjs/types/data-structures/binary-tree/binary-tree.d.ts +5 -5
  80. package/dist/cjs/types/data-structures/binary-tree/bst.d.ts +4 -5
  81. package/dist/cjs/types/data-structures/binary-tree/rb-tree.d.ts +3 -4
  82. package/dist/cjs/types/data-structures/binary-tree/tree-multi-map.d.ts +3 -4
  83. package/dist/cjs/types/data-structures/heap/heap.d.ts +3 -2
  84. package/dist/cjs/types/data-structures/linked-list/doubly-linked-list.d.ts +2 -1
  85. package/dist/cjs/types/data-structures/linked-list/singly-linked-list.d.ts +2 -1
  86. package/dist/cjs/types/data-structures/priority-queue/priority-queue.d.ts +1 -1
  87. package/dist/cjs/types/data-structures/queue/deque.d.ts +3 -2
  88. package/dist/cjs/types/data-structures/queue/queue.d.ts +2 -1
  89. package/dist/cjs/types/data-structures/stack/stack.d.ts +2 -1
  90. package/dist/cjs/types/data-structures/trie/trie.d.ts +3 -2
  91. package/dist/cjs/utils/utils.js +3 -5
  92. package/dist/cjs/utils/utils.js.map +1 -1
  93. package/dist/mjs/data-structures/base/index.d.ts +2 -1
  94. package/dist/mjs/data-structures/base/index.js +2 -1
  95. package/dist/mjs/data-structures/base/iterable-element-base.d.ts +171 -0
  96. package/dist/mjs/data-structures/base/iterable-element-base.js +222 -0
  97. package/dist/mjs/data-structures/base/{iterable-base.d.ts → iterable-entry-base.d.ts} +4 -147
  98. package/dist/mjs/data-structures/base/{iterable-base.js → iterable-entry-base.js} +10 -186
  99. package/dist/mjs/data-structures/binary-tree/avl-tree-multi-map.d.ts +106 -68
  100. package/dist/mjs/data-structures/binary-tree/avl-tree-multi-map.js +119 -87
  101. package/dist/mjs/data-structures/binary-tree/avl-tree.d.ts +82 -62
  102. package/dist/mjs/data-structures/binary-tree/avl-tree.js +78 -59
  103. package/dist/mjs/data-structures/binary-tree/binary-tree.d.ts +318 -226
  104. package/dist/mjs/data-structures/binary-tree/binary-tree.js +476 -364
  105. package/dist/mjs/data-structures/binary-tree/bst.d.ts +192 -202
  106. package/dist/mjs/data-structures/binary-tree/bst.js +211 -255
  107. package/dist/mjs/data-structures/binary-tree/rb-tree.d.ts +73 -74
  108. package/dist/mjs/data-structures/binary-tree/rb-tree.js +107 -98
  109. package/dist/mjs/data-structures/binary-tree/tree-multi-map.d.ts +92 -75
  110. package/dist/mjs/data-structures/binary-tree/tree-multi-map.js +105 -93
  111. package/dist/mjs/data-structures/graph/abstract-graph.d.ts +10 -15
  112. package/dist/mjs/data-structures/graph/abstract-graph.js +10 -15
  113. package/dist/mjs/data-structures/hash/hash-map.d.ts +33 -40
  114. package/dist/mjs/data-structures/hash/hash-map.js +41 -55
  115. package/dist/mjs/data-structures/heap/heap.d.ts +43 -114
  116. package/dist/mjs/data-structures/heap/heap.js +60 -128
  117. package/dist/mjs/data-structures/heap/max-heap.d.ts +50 -4
  118. package/dist/mjs/data-structures/heap/max-heap.js +79 -10
  119. package/dist/mjs/data-structures/heap/min-heap.d.ts +51 -5
  120. package/dist/mjs/data-structures/heap/min-heap.js +68 -11
  121. package/dist/mjs/data-structures/linked-list/doubly-linked-list.d.ts +22 -28
  122. package/dist/mjs/data-structures/linked-list/doubly-linked-list.js +26 -28
  123. package/dist/mjs/data-structures/linked-list/singly-linked-list.d.ts +22 -25
  124. package/dist/mjs/data-structures/linked-list/singly-linked-list.js +29 -26
  125. package/dist/mjs/data-structures/priority-queue/max-priority-queue.d.ts +50 -4
  126. package/dist/mjs/data-structures/priority-queue/max-priority-queue.js +82 -10
  127. package/dist/mjs/data-structures/priority-queue/min-priority-queue.d.ts +51 -5
  128. package/dist/mjs/data-structures/priority-queue/min-priority-queue.js +71 -11
  129. package/dist/mjs/data-structures/priority-queue/priority-queue.d.ts +50 -4
  130. package/dist/mjs/data-structures/priority-queue/priority-queue.js +70 -1
  131. package/dist/mjs/data-structures/queue/deque.d.ts +21 -20
  132. package/dist/mjs/data-structures/queue/deque.js +29 -23
  133. package/dist/mjs/data-structures/queue/queue.d.ts +8 -28
  134. package/dist/mjs/data-structures/queue/queue.js +15 -31
  135. package/dist/mjs/data-structures/stack/stack.d.ts +17 -22
  136. package/dist/mjs/data-structures/stack/stack.js +25 -24
  137. package/dist/mjs/data-structures/trie/trie.d.ts +19 -14
  138. package/dist/mjs/data-structures/trie/trie.js +27 -16
  139. package/dist/mjs/interfaces/binary-tree.d.ts +7 -7
  140. package/dist/mjs/types/common.d.ts +1 -2
  141. package/dist/mjs/types/data-structures/base/base.d.ts +5 -2
  142. package/dist/mjs/types/data-structures/binary-tree/avl-tree-multi-map.d.ts +3 -4
  143. package/dist/mjs/types/data-structures/binary-tree/avl-tree.d.ts +3 -4
  144. package/dist/mjs/types/data-structures/binary-tree/binary-tree.d.ts +5 -5
  145. package/dist/mjs/types/data-structures/binary-tree/bst.d.ts +4 -5
  146. package/dist/mjs/types/data-structures/binary-tree/rb-tree.d.ts +3 -4
  147. package/dist/mjs/types/data-structures/binary-tree/tree-multi-map.d.ts +3 -4
  148. package/dist/mjs/types/data-structures/heap/heap.d.ts +3 -2
  149. package/dist/mjs/types/data-structures/linked-list/doubly-linked-list.d.ts +2 -1
  150. package/dist/mjs/types/data-structures/linked-list/singly-linked-list.d.ts +2 -1
  151. package/dist/mjs/types/data-structures/priority-queue/priority-queue.d.ts +1 -1
  152. package/dist/mjs/types/data-structures/queue/deque.d.ts +3 -2
  153. package/dist/mjs/types/data-structures/queue/queue.d.ts +2 -1
  154. package/dist/mjs/types/data-structures/stack/stack.d.ts +2 -1
  155. package/dist/mjs/types/data-structures/trie/trie.d.ts +3 -2
  156. package/dist/mjs/utils/utils.js +3 -5
  157. package/dist/umd/data-structure-typed.js +1949 -1481
  158. package/dist/umd/data-structure-typed.min.js +2 -2
  159. package/dist/umd/data-structure-typed.min.js.map +1 -1
  160. package/package.json +6 -6
  161. package/src/data-structures/base/index.ts +2 -1
  162. package/src/data-structures/base/iterable-element-base.ts +250 -0
  163. package/src/data-structures/base/{iterable-base.ts → iterable-entry-base.ts} +22 -213
  164. package/src/data-structures/binary-tree/avl-tree-multi-map.ts +144 -95
  165. package/src/data-structures/binary-tree/avl-tree.ts +96 -69
  166. package/src/data-structures/binary-tree/binary-tree.ts +535 -403
  167. package/src/data-structures/binary-tree/bst.ts +247 -277
  168. package/src/data-structures/binary-tree/rb-tree.ts +123 -103
  169. package/src/data-structures/binary-tree/tree-multi-map.ts +127 -102
  170. package/src/data-structures/graph/abstract-graph.ts +10 -10
  171. package/src/data-structures/hash/hash-map.ts +46 -53
  172. package/src/data-structures/heap/heap.ts +71 -152
  173. package/src/data-structures/heap/max-heap.ts +88 -13
  174. package/src/data-structures/heap/min-heap.ts +78 -15
  175. package/src/data-structures/linked-list/doubly-linked-list.ts +32 -32
  176. package/src/data-structures/linked-list/singly-linked-list.ts +37 -29
  177. package/src/data-structures/priority-queue/max-priority-queue.ts +94 -13
  178. package/src/data-structures/priority-queue/min-priority-queue.ts +84 -15
  179. package/src/data-structures/priority-queue/priority-queue.ts +81 -4
  180. package/src/data-structures/queue/deque.ts +37 -26
  181. package/src/data-structures/queue/queue.ts +23 -36
  182. package/src/data-structures/stack/stack.ts +31 -26
  183. package/src/data-structures/trie/trie.ts +35 -20
  184. package/src/interfaces/binary-tree.ts +9 -9
  185. package/src/types/common.ts +1 -2
  186. package/src/types/data-structures/base/base.ts +14 -6
  187. package/src/types/data-structures/binary-tree/avl-tree-multi-map.ts +3 -4
  188. package/src/types/data-structures/binary-tree/avl-tree.ts +3 -4
  189. package/src/types/data-structures/binary-tree/binary-tree.ts +6 -6
  190. package/src/types/data-structures/binary-tree/bst.ts +4 -5
  191. package/src/types/data-structures/binary-tree/rb-tree.ts +3 -4
  192. package/src/types/data-structures/binary-tree/tree-multi-map.ts +3 -4
  193. package/src/types/data-structures/heap/heap.ts +4 -1
  194. package/src/types/data-structures/linked-list/doubly-linked-list.ts +3 -1
  195. package/src/types/data-structures/linked-list/singly-linked-list.ts +3 -1
  196. package/src/types/data-structures/priority-queue/priority-queue.ts +1 -1
  197. package/src/types/data-structures/queue/deque.ts +3 -1
  198. package/src/types/data-structures/queue/queue.ts +3 -1
  199. package/src/types/data-structures/stack/stack.ts +3 -1
  200. package/src/types/data-structures/trie/trie.ts +3 -1
  201. package/src/utils/utils.ts +3 -3
  202. package/test/integration/avl-tree.test.ts +2 -2
  203. package/test/integration/bst.test.ts +3 -3
  204. package/test/integration/index.html +25 -11
  205. package/test/unit/data-structures/binary-tree/avl-tree-multi-map.test.ts +68 -0
  206. package/test/unit/data-structures/binary-tree/binary-tree.test.ts +56 -0
  207. package/test/unit/data-structures/graph/directed-graph.test.ts +2 -2
  208. package/test/unit/data-structures/heap/heap.test.ts +80 -0
  209. package/test/unit/data-structures/heap/max-heap.test.ts +44 -1
  210. package/test/unit/data-structures/heap/min-heap.test.ts +18 -1
  211. package/test/unit/data-structures/priority-queue/max-priority-queue.test.ts +42 -0
  212. package/test/unit/data-structures/queue/deque.test.ts +30 -0
  213. package/test/unit/data-structures/queue/queue.test.ts +56 -0
  214. package/test/utils/big-o.ts +12 -6
  215. package/tsconfig-base.json +1 -0
  216. package/dist/cjs/data-structures/base/iterable-base.js.map +0 -1
@@ -0,0 +1,171 @@
1
+ import { ElementCallback, IterableElementBaseOptions, ReduceElementCallback } from '../../types';
2
+ export declare abstract class IterableElementBase<E, R, C> {
3
+ /**
4
+ * The protected constructor initializes the options for the IterableElementBase class, including the
5
+ * toElementFn function.
6
+ * @param [options] - An optional object that contains the following properties:
7
+ */
8
+ protected constructor(options?: IterableElementBaseOptions<E, R>);
9
+ abstract get size(): number;
10
+ protected _toElementFn?: (rawElement: R) => E;
11
+ /**
12
+ * The function returns the _toElementFn property, which is a function that converts a raw element to
13
+ * a specific type.
14
+ * @returns The function `get toElementFn()` is returning either a function that takes a raw element
15
+ * `rawElement` of type `R` and returns an element `E`, or `undefined` if no function is assigned to
16
+ * `_toElementFn`.
17
+ */
18
+ get toElementFn(): ((rawElement: R) => E) | undefined;
19
+ /**
20
+ * Time Complexity: O(n)
21
+ * Space Complexity: O(1)
22
+ */
23
+ /**
24
+ * Time Complexity: O(n)
25
+ * Space Complexity: O(1)
26
+ *
27
+ * The function is an implementation of the Symbol.iterator method that returns an IterableIterator.
28
+ * @param {any[]} args - The `args` parameter in the code snippet represents a rest parameter. It
29
+ * allows the function to accept any number of arguments as an array. In this case, the `args`
30
+ * parameter is used to pass any number of arguments to the `_getIterator` method.
31
+ */
32
+ [Symbol.iterator](...args: any[]): IterableIterator<E>;
33
+ /**
34
+ * Time Complexity: O(n)
35
+ * Space Complexity: O(n)
36
+ */
37
+ /**
38
+ * Time Complexity: O(n)
39
+ * Space Complexity: O(n)
40
+ *
41
+ * The function returns an iterator that yields all the values in the object.
42
+ */
43
+ values(): IterableIterator<E>;
44
+ /**
45
+ * Time Complexity: O(n)
46
+ * Space Complexity: O(1)
47
+ */
48
+ /**
49
+ * Time Complexity: O(n)
50
+ * Space Complexity: O(1)
51
+ *
52
+ * The `every` function checks if every element in the array satisfies a given predicate.
53
+ * @param predicate - The `predicate` parameter is a callback function that takes three arguments:
54
+ * the current element being processed, its index, and the array it belongs to. It should return a
55
+ * boolean value indicating whether the element satisfies a certain condition or not.
56
+ * @param {any} [thisArg] - The `thisArg` parameter is an optional argument that specifies the value
57
+ * to be used as `this` when executing the `predicate` function. If `thisArg` is provided, it will be
58
+ * passed as the `this` value to the `predicate` function. If `thisArg` is
59
+ * @returns The `every` method is returning a boolean value. It returns `true` if every element in
60
+ * the array satisfies the provided predicate function, and `false` otherwise.
61
+ */
62
+ every(predicate: ElementCallback<E, R, boolean, C>, thisArg?: any): boolean;
63
+ /**
64
+ * Time Complexity: O(n)
65
+ * Space Complexity: O(1)
66
+ */
67
+ /**
68
+ * Time Complexity: O(n)
69
+ * Space Complexity: O(1)
70
+ */
71
+ /**
72
+ * Time Complexity: O(n)
73
+ * Space Complexity: O(1)
74
+ *
75
+ * The "some" function checks if at least one element in a collection satisfies a given predicate.
76
+ * @param predicate - The `predicate` parameter is a callback function that takes three arguments:
77
+ * `value`, `index`, and `array`. It should return a boolean value indicating whether the current
78
+ * element satisfies the condition.
79
+ * @param {any} [thisArg] - The `thisArg` parameter is an optional argument that specifies the value
80
+ * to be used as the `this` value when executing the `predicate` function. If `thisArg` is provided,
81
+ * it will be passed as the `this` value to the `predicate` function. If `thisArg
82
+ * @returns a boolean value. It returns true if the predicate function returns true for any element
83
+ * in the collection, and false otherwise.
84
+ */
85
+ some(predicate: ElementCallback<E, R, boolean, C>, thisArg?: any): boolean;
86
+ /**
87
+ * Time Complexity: O(n)
88
+ * Space Complexity: O(1)
89
+ */
90
+ /**
91
+ * Time Complexity: O(n)
92
+ * Space Complexity: O(1)
93
+ *
94
+ * The `forEach` function iterates over each element in an array-like object and calls a callback
95
+ * function for each element.
96
+ * @param callbackfn - The callbackfn parameter is a function that will be called for each element in
97
+ * the array. It takes three arguments: the current element being processed, the index of the current
98
+ * element, and the array that forEach was called upon.
99
+ * @param {any} [thisArg] - The `thisArg` parameter is an optional argument that specifies the value
100
+ * to be used as `this` when executing the `callbackfn` function. If `thisArg` is provided, it will
101
+ * be passed as the `this` value to the `callbackfn` function. If `thisArg
102
+ */
103
+ forEach(callbackfn: ElementCallback<E, R, void, C>, thisArg?: any): void;
104
+ /**
105
+ * Time Complexity: O(n)
106
+ * Space Complexity: O(1)
107
+ */
108
+ /**
109
+ * Time Complexity: O(n)
110
+ * Space Complexity: O(1)
111
+ *
112
+ * The `find` function iterates over the elements of an array-like object and returns the first
113
+ * element that satisfies the provided callback function.
114
+ * @param callbackfn - The callbackfn parameter is a function that will be called for each element in
115
+ * the array. It takes three arguments: the current element being processed, the index of the current
116
+ * element, and the array itself. The function should return a boolean value indicating whether the
117
+ * current element matches the desired condition.
118
+ * @param {any} [thisArg] - The `thisArg` parameter is an optional argument that specifies the value
119
+ * to be used as `this` when executing the `callbackfn` function. If `thisArg` is provided, it will
120
+ * be passed as the `this` value to the `callbackfn` function. If `thisArg
121
+ * @returns The `find` method returns the first element in the array that satisfies the provided
122
+ * callback function. If no element satisfies the callback function, `undefined` is returned.
123
+ */
124
+ find(callbackfn: ElementCallback<E, R, boolean, C>, thisArg?: any): E | undefined;
125
+ /**
126
+ * Time Complexity: O(n)
127
+ * Space Complexity: O(1)
128
+ *
129
+ * The function checks if a given element exists in a collection.
130
+ * @param {E} element - The parameter "element" is of type E, which means it can be any type. It
131
+ * represents the element that we want to check for existence in the collection.
132
+ * @returns a boolean value. It returns true if the element is found in the collection, and false
133
+ * otherwise.
134
+ */
135
+ has(element: E): boolean;
136
+ /**
137
+ * Time Complexity: O(n)
138
+ * Space Complexity: O(1)
139
+ */
140
+ /**
141
+ * Time Complexity: O(n)
142
+ * Space Complexity: O(1)
143
+ *
144
+ * The `reduce` function iterates over the elements of an array-like object and applies a callback
145
+ * function to reduce them into a single value.
146
+ * @param callbackfn - The callbackfn parameter is a function that will be called for each element in
147
+ * the array. It takes four arguments:
148
+ * @param {U} initialValue - The initialValue parameter is the initial value of the accumulator. It
149
+ * is the value that the accumulator starts with before the reduction operation begins.
150
+ * @returns The `reduce` method is returning the final value of the accumulator after iterating over
151
+ * all the elements in the array and applying the callback function to each element.
152
+ */
153
+ reduce<U>(callbackfn: ReduceElementCallback<E, R, U, C>, initialValue: U): U;
154
+ /**
155
+ * Time Complexity: O(n)
156
+ * Space Complexity: O(n)
157
+ */
158
+ /**
159
+ * Time Complexity: O(n)
160
+ * Space Complexity: O(n)
161
+ *
162
+ * The print function logs the elements of an array to the console.
163
+ */
164
+ print(): void;
165
+ abstract isEmpty(): boolean;
166
+ abstract clear(): void;
167
+ abstract clone(): C;
168
+ abstract map(...args: any[]): any;
169
+ abstract filter(...args: any[]): any;
170
+ protected abstract _getIterator(...args: any[]): IterableIterator<E>;
171
+ }
@@ -0,0 +1,222 @@
1
+ export class IterableElementBase {
2
+ /**
3
+ * The protected constructor initializes the options for the IterableElementBase class, including the
4
+ * toElementFn function.
5
+ * @param [options] - An optional object that contains the following properties:
6
+ */
7
+ constructor(options) {
8
+ if (options) {
9
+ const { toElementFn } = options;
10
+ if (typeof toElementFn === 'function')
11
+ this._toElementFn = toElementFn;
12
+ else if (toElementFn)
13
+ throw new TypeError('toElementFn must be a function type');
14
+ }
15
+ }
16
+ _toElementFn;
17
+ /**
18
+ * The function returns the _toElementFn property, which is a function that converts a raw element to
19
+ * a specific type.
20
+ * @returns The function `get toElementFn()` is returning either a function that takes a raw element
21
+ * `rawElement` of type `R` and returns an element `E`, or `undefined` if no function is assigned to
22
+ * `_toElementFn`.
23
+ */
24
+ get toElementFn() {
25
+ return this._toElementFn;
26
+ }
27
+ /**
28
+ * Time Complexity: O(n)
29
+ * Space Complexity: O(1)
30
+ */
31
+ /**
32
+ * Time Complexity: O(n)
33
+ * Space Complexity: O(1)
34
+ *
35
+ * The function is an implementation of the Symbol.iterator method that returns an IterableIterator.
36
+ * @param {any[]} args - The `args` parameter in the code snippet represents a rest parameter. It
37
+ * allows the function to accept any number of arguments as an array. In this case, the `args`
38
+ * parameter is used to pass any number of arguments to the `_getIterator` method.
39
+ */
40
+ *[Symbol.iterator](...args) {
41
+ yield* this._getIterator(...args);
42
+ }
43
+ /**
44
+ * Time Complexity: O(n)
45
+ * Space Complexity: O(n)
46
+ */
47
+ /**
48
+ * Time Complexity: O(n)
49
+ * Space Complexity: O(n)
50
+ *
51
+ * The function returns an iterator that yields all the values in the object.
52
+ */
53
+ *values() {
54
+ for (const item of this) {
55
+ yield item;
56
+ }
57
+ }
58
+ /**
59
+ * Time Complexity: O(n)
60
+ * Space Complexity: O(1)
61
+ */
62
+ /**
63
+ * Time Complexity: O(n)
64
+ * Space Complexity: O(1)
65
+ *
66
+ * The `every` function checks if every element in the array satisfies a given predicate.
67
+ * @param predicate - The `predicate` parameter is a callback function that takes three arguments:
68
+ * the current element being processed, its index, and the array it belongs to. It should return a
69
+ * boolean value indicating whether the element satisfies a certain condition or not.
70
+ * @param {any} [thisArg] - The `thisArg` parameter is an optional argument that specifies the value
71
+ * to be used as `this` when executing the `predicate` function. If `thisArg` is provided, it will be
72
+ * passed as the `this` value to the `predicate` function. If `thisArg` is
73
+ * @returns The `every` method is returning a boolean value. It returns `true` if every element in
74
+ * the array satisfies the provided predicate function, and `false` otherwise.
75
+ */
76
+ every(predicate, thisArg) {
77
+ let index = 0;
78
+ for (const item of this) {
79
+ if (!predicate.call(thisArg, item, index++, this)) {
80
+ return false;
81
+ }
82
+ }
83
+ return true;
84
+ }
85
+ /**
86
+ * Time Complexity: O(n)
87
+ * Space Complexity: O(1)
88
+ */
89
+ /**
90
+ * Time Complexity: O(n)
91
+ * Space Complexity: O(1)
92
+ */
93
+ /**
94
+ * Time Complexity: O(n)
95
+ * Space Complexity: O(1)
96
+ *
97
+ * The "some" function checks if at least one element in a collection satisfies a given predicate.
98
+ * @param predicate - The `predicate` parameter is a callback function that takes three arguments:
99
+ * `value`, `index`, and `array`. It should return a boolean value indicating whether the current
100
+ * element satisfies the condition.
101
+ * @param {any} [thisArg] - The `thisArg` parameter is an optional argument that specifies the value
102
+ * to be used as the `this` value when executing the `predicate` function. If `thisArg` is provided,
103
+ * it will be passed as the `this` value to the `predicate` function. If `thisArg
104
+ * @returns a boolean value. It returns true if the predicate function returns true for any element
105
+ * in the collection, and false otherwise.
106
+ */
107
+ some(predicate, thisArg) {
108
+ let index = 0;
109
+ for (const item of this) {
110
+ if (predicate.call(thisArg, item, index++, this)) {
111
+ return true;
112
+ }
113
+ }
114
+ return false;
115
+ }
116
+ /**
117
+ * Time Complexity: O(n)
118
+ * Space Complexity: O(1)
119
+ */
120
+ /**
121
+ * Time Complexity: O(n)
122
+ * Space Complexity: O(1)
123
+ *
124
+ * The `forEach` function iterates over each element in an array-like object and calls a callback
125
+ * function for each element.
126
+ * @param callbackfn - The callbackfn parameter is a function that will be called for each element in
127
+ * the array. It takes three arguments: the current element being processed, the index of the current
128
+ * element, and the array that forEach was called upon.
129
+ * @param {any} [thisArg] - The `thisArg` parameter is an optional argument that specifies the value
130
+ * to be used as `this` when executing the `callbackfn` function. If `thisArg` is provided, it will
131
+ * be passed as the `this` value to the `callbackfn` function. If `thisArg
132
+ */
133
+ forEach(callbackfn, thisArg) {
134
+ let index = 0;
135
+ for (const item of this) {
136
+ callbackfn.call(thisArg, item, index++, this);
137
+ }
138
+ }
139
+ /**
140
+ * Time Complexity: O(n)
141
+ * Space Complexity: O(1)
142
+ */
143
+ /**
144
+ * Time Complexity: O(n)
145
+ * Space Complexity: O(1)
146
+ *
147
+ * The `find` function iterates over the elements of an array-like object and returns the first
148
+ * element that satisfies the provided callback function.
149
+ * @param callbackfn - The callbackfn parameter is a function that will be called for each element in
150
+ * the array. It takes three arguments: the current element being processed, the index of the current
151
+ * element, and the array itself. The function should return a boolean value indicating whether the
152
+ * current element matches the desired condition.
153
+ * @param {any} [thisArg] - The `thisArg` parameter is an optional argument that specifies the value
154
+ * to be used as `this` when executing the `callbackfn` function. If `thisArg` is provided, it will
155
+ * be passed as the `this` value to the `callbackfn` function. If `thisArg
156
+ * @returns The `find` method returns the first element in the array that satisfies the provided
157
+ * callback function. If no element satisfies the callback function, `undefined` is returned.
158
+ */
159
+ find(callbackfn, thisArg) {
160
+ let index = 0;
161
+ for (const item of this) {
162
+ if (callbackfn.call(thisArg, item, index++, this))
163
+ return item;
164
+ }
165
+ return;
166
+ }
167
+ /**
168
+ * Time Complexity: O(n)
169
+ * Space Complexity: O(1)
170
+ *
171
+ * The function checks if a given element exists in a collection.
172
+ * @param {E} element - The parameter "element" is of type E, which means it can be any type. It
173
+ * represents the element that we want to check for existence in the collection.
174
+ * @returns a boolean value. It returns true if the element is found in the collection, and false
175
+ * otherwise.
176
+ */
177
+ has(element) {
178
+ for (const ele of this) {
179
+ if (ele === element)
180
+ return true;
181
+ }
182
+ return false;
183
+ }
184
+ /**
185
+ * Time Complexity: O(n)
186
+ * Space Complexity: O(1)
187
+ */
188
+ /**
189
+ * Time Complexity: O(n)
190
+ * Space Complexity: O(1)
191
+ *
192
+ * The `reduce` function iterates over the elements of an array-like object and applies a callback
193
+ * function to reduce them into a single value.
194
+ * @param callbackfn - The callbackfn parameter is a function that will be called for each element in
195
+ * the array. It takes four arguments:
196
+ * @param {U} initialValue - The initialValue parameter is the initial value of the accumulator. It
197
+ * is the value that the accumulator starts with before the reduction operation begins.
198
+ * @returns The `reduce` method is returning the final value of the accumulator after iterating over
199
+ * all the elements in the array and applying the callback function to each element.
200
+ */
201
+ reduce(callbackfn, initialValue) {
202
+ let accumulator = initialValue;
203
+ let index = 0;
204
+ for (const item of this) {
205
+ accumulator = callbackfn(accumulator, item, index++, this);
206
+ }
207
+ return accumulator;
208
+ }
209
+ /**
210
+ * Time Complexity: O(n)
211
+ * Space Complexity: O(n)
212
+ */
213
+ /**
214
+ * Time Complexity: O(n)
215
+ * Space Complexity: O(n)
216
+ *
217
+ * The print function logs the elements of an array to the console.
218
+ */
219
+ print() {
220
+ console.log([...this]);
221
+ }
222
+ }
@@ -1,4 +1,4 @@
1
- import { ElementCallback, EntryCallback, ReduceElementCallback, ReduceEntryCallback } from '../../types';
1
+ import { EntryCallback, ReduceEntryCallback } from '../../types';
2
2
  export declare abstract class IterableEntryBase<K = any, V = any> {
3
3
  /**
4
4
  * Time Complexity: O(n)
@@ -193,34 +193,6 @@ export declare abstract class IterableEntryBase<K = any, V = any> {
193
193
  * all the elements in the collection.
194
194
  */
195
195
  reduce<U>(callbackfn: ReduceEntryCallback<K, V, U>, initialValue: U): U;
196
- /**
197
- * Time Complexity: O(n)
198
- * Space Complexity: O(n)
199
- */
200
- print(): void;
201
- abstract isEmpty(): boolean;
202
- abstract clear(): void;
203
- abstract clone(): any;
204
- abstract map(...args: any[]): any;
205
- abstract filter(...args: any[]): any;
206
- protected abstract _getIterator(...args: any[]): IterableIterator<[K, V]>;
207
- }
208
- export declare abstract class IterableElementBase<E = any, C = any> {
209
- abstract get size(): number;
210
- /**
211
- * Time Complexity: O(n)
212
- * Space Complexity: O(1)
213
- */
214
- /**
215
- * Time Complexity: O(n)
216
- * Space Complexity: O(1)
217
- *
218
- * The function is an implementation of the Symbol.iterator method that returns an IterableIterator.
219
- * @param {any[]} args - The `args` parameter in the code snippet represents a rest parameter. It
220
- * allows the function to accept any number of arguments as an array. In this case, the `args`
221
- * parameter is used to pass any number of arguments to the `_getIterator` method.
222
- */
223
- [Symbol.iterator](...args: any[]): IterableIterator<E>;
224
196
  /**
225
197
  * Time Complexity: O(n)
226
198
  * Space Complexity: O(n)
@@ -229,128 +201,13 @@ export declare abstract class IterableElementBase<E = any, C = any> {
229
201
  * Time Complexity: O(n)
230
202
  * Space Complexity: O(n)
231
203
  *
232
- * The function returns an iterator that yields all the values in the object.
233
- */
234
- values(): IterableIterator<E>;
235
- /**
236
- * Time Complexity: O(n)
237
- * Space Complexity: O(1)
238
- */
239
- /**
240
- * Time Complexity: O(n)
241
- * Space Complexity: O(1)
242
- *
243
- * The `every` function checks if every element in the array satisfies a given predicate.
244
- * @param predicate - The `predicate` parameter is a callback function that takes three arguments:
245
- * the current element being processed, its index, and the array it belongs to. It should return a
246
- * boolean value indicating whether the element satisfies a certain condition or not.
247
- * @param {any} [thisArg] - The `thisArg` parameter is an optional argument that specifies the value
248
- * to be used as `this` when executing the `predicate` function. If `thisArg` is provided, it will be
249
- * passed as the `this` value to the `predicate` function. If `thisArg` is
250
- * @returns The `every` method is returning a boolean value. It returns `true` if every element in
251
- * the array satisfies the provided predicate function, and `false` otherwise.
252
- */
253
- every(predicate: ElementCallback<E, boolean>, thisArg?: any): boolean;
254
- /**
255
- * Time Complexity: O(n)
256
- * Space Complexity: O(1)
257
- */
258
- /**
259
- * Time Complexity: O(n)
260
- * Space Complexity: O(1)
261
- */
262
- /**
263
- * Time Complexity: O(n)
264
- * Space Complexity: O(1)
265
- *
266
- * The "some" function checks if at least one element in a collection satisfies a given predicate.
267
- * @param predicate - The `predicate` parameter is a callback function that takes three arguments:
268
- * `value`, `index`, and `array`. It should return a boolean value indicating whether the current
269
- * element satisfies the condition.
270
- * @param {any} [thisArg] - The `thisArg` parameter is an optional argument that specifies the value
271
- * to be used as the `this` value when executing the `predicate` function. If `thisArg` is provided,
272
- * it will be passed as the `this` value to the `predicate` function. If `thisArg
273
- * @returns a boolean value. It returns true if the predicate function returns true for any element
274
- * in the collection, and false otherwise.
275
- */
276
- some(predicate: ElementCallback<E, boolean>, thisArg?: any): boolean;
277
- /**
278
- * Time Complexity: O(n)
279
- * Space Complexity: O(1)
280
- */
281
- /**
282
- * Time Complexity: O(n)
283
- * Space Complexity: O(1)
284
- *
285
- * The `forEach` function iterates over each element in an array-like object and calls a callback
286
- * function for each element.
287
- * @param callbackfn - The callbackfn parameter is a function that will be called for each element in
288
- * the array. It takes three arguments: the current element being processed, the index of the current
289
- * element, and the array that forEach was called upon.
290
- * @param {any} [thisArg] - The `thisArg` parameter is an optional argument that specifies the value
291
- * to be used as `this` when executing the `callbackfn` function. If `thisArg` is provided, it will
292
- * be passed as the `this` value to the `callbackfn` function. If `thisArg
293
- */
294
- forEach(callbackfn: ElementCallback<E, void>, thisArg?: any): void;
295
- /**
296
- * Time Complexity: O(n)
297
- * Space Complexity: O(1)
298
- */
299
- /**
300
- * Time Complexity: O(n)
301
- * Space Complexity: O(1)
302
- *
303
- * The `find` function iterates over the elements of an array-like object and returns the first
304
- * element that satisfies the provided callback function.
305
- * @param callbackfn - The callbackfn parameter is a function that will be called for each element in
306
- * the array. It takes three arguments: the current element being processed, the index of the current
307
- * element, and the array itself. The function should return a boolean value indicating whether the
308
- * current element matches the desired condition.
309
- * @param {any} [thisArg] - The `thisArg` parameter is an optional argument that specifies the value
310
- * to be used as `this` when executing the `callbackfn` function. If `thisArg` is provided, it will
311
- * be passed as the `this` value to the `callbackfn` function. If `thisArg
312
- * @returns The `find` method returns the first element in the array that satisfies the provided
313
- * callback function. If no element satisfies the callback function, `undefined` is returned.
314
- */
315
- find(callbackfn: ElementCallback<E, boolean>, thisArg?: any): E | undefined;
316
- /**
317
- * Time Complexity: O(n)
318
- * Space Complexity: O(1)
319
- *
320
- * The function checks if a given element exists in a collection.
321
- * @param {E} element - The parameter "element" is of type E, which means it can be any type. It
322
- * represents the element that we want to check for existence in the collection.
323
- * @returns a boolean value. It returns true if the element is found in the collection, and false
324
- * otherwise.
325
- */
326
- has(element: E): boolean;
327
- /**
328
- * Time Complexity: O(n)
329
- * Space Complexity: O(1)
330
- */
331
- /**
332
- * Time Complexity: O(n)
333
- * Space Complexity: O(1)
334
- *
335
- * The `reduce` function iterates over the elements of an array-like object and applies a callback
336
- * function to reduce them into a single value.
337
- * @param callbackfn - The callbackfn parameter is a function that will be called for each element in
338
- * the array. It takes four arguments:
339
- * @param {U} initialValue - The initialValue parameter is the initial value of the accumulator. It
340
- * is the value that the accumulator starts with before the reduction operation begins.
341
- * @returns The `reduce` method is returning the final value of the accumulator after iterating over
342
- * all the elements in the array and applying the callback function to each element.
343
- */
344
- reduce<U>(callbackfn: ReduceElementCallback<E, U>, initialValue: U): U;
345
- /**
346
- * Time Complexity: O(n)
347
- * Space Complexity: O(n)
204
+ * The print function logs the elements of an array to the console.
348
205
  */
349
206
  print(): void;
350
207
  abstract isEmpty(): boolean;
351
208
  abstract clear(): void;
352
- abstract clone(): C;
209
+ abstract clone(): any;
353
210
  abstract map(...args: any[]): any;
354
211
  abstract filter(...args: any[]): any;
355
- protected abstract _getIterator(...args: any[]): IterableIterator<E>;
212
+ protected abstract _getIterator(...args: any[]): IterableIterator<[K, V]>;
356
213
  }