data-structure-typed 1.50.1 → 1.50.3

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 (196) hide show
  1. package/CHANGELOG.md +2 -1
  2. package/README.md +30 -28
  3. package/README_zh-CN.md +1 -1
  4. package/SPECIFICATION.md +56 -0
  5. package/SPONSOR-zh-CN.md +90 -0
  6. package/SPONSOR.md +54 -0
  7. package/benchmark/report.html +13 -13
  8. package/benchmark/report.json +149 -161
  9. package/dist/cjs/data-structures/base/iterable-base.d.ts +120 -9
  10. package/dist/cjs/data-structures/base/iterable-base.js +143 -7
  11. package/dist/cjs/data-structures/base/iterable-base.js.map +1 -1
  12. package/dist/cjs/data-structures/binary-tree/avl-tree.d.ts +72 -47
  13. package/dist/cjs/data-structures/binary-tree/avl-tree.js +101 -72
  14. package/dist/cjs/data-structures/binary-tree/avl-tree.js.map +1 -1
  15. package/dist/cjs/data-structures/binary-tree/binary-indexed-tree.d.ts +22 -0
  16. package/dist/cjs/data-structures/binary-tree/binary-indexed-tree.js +22 -0
  17. package/dist/cjs/data-structures/binary-tree/binary-indexed-tree.js.map +1 -1
  18. package/dist/cjs/data-structures/binary-tree/binary-tree.d.ts +244 -199
  19. package/dist/cjs/data-structures/binary-tree/binary-tree.js +484 -376
  20. package/dist/cjs/data-structures/binary-tree/binary-tree.js.map +1 -1
  21. package/dist/cjs/data-structures/binary-tree/bst.d.ts +92 -79
  22. package/dist/cjs/data-structures/binary-tree/bst.js +68 -76
  23. package/dist/cjs/data-structures/binary-tree/bst.js.map +1 -1
  24. package/dist/cjs/data-structures/binary-tree/rb-tree.d.ts +127 -57
  25. package/dist/cjs/data-structures/binary-tree/rb-tree.js +152 -99
  26. package/dist/cjs/data-structures/binary-tree/rb-tree.js.map +1 -1
  27. package/dist/cjs/data-structures/binary-tree/segment-tree.d.ts +99 -6
  28. package/dist/cjs/data-structures/binary-tree/segment-tree.js +127 -10
  29. package/dist/cjs/data-structures/binary-tree/segment-tree.js.map +1 -1
  30. package/dist/cjs/data-structures/binary-tree/tree-multimap.d.ts +72 -58
  31. package/dist/cjs/data-structures/binary-tree/tree-multimap.js +102 -85
  32. package/dist/cjs/data-structures/binary-tree/tree-multimap.js.map +1 -1
  33. package/dist/cjs/data-structures/graph/abstract-graph.d.ts +1 -78
  34. package/dist/cjs/data-structures/graph/abstract-graph.js +3 -189
  35. package/dist/cjs/data-structures/graph/abstract-graph.js.map +1 -1
  36. package/dist/cjs/data-structures/graph/directed-graph.d.ts +73 -0
  37. package/dist/cjs/data-structures/graph/directed-graph.js +131 -0
  38. package/dist/cjs/data-structures/graph/directed-graph.js.map +1 -1
  39. package/dist/cjs/data-structures/graph/map-graph.d.ts +8 -0
  40. package/dist/cjs/data-structures/graph/map-graph.js +14 -0
  41. package/dist/cjs/data-structures/graph/map-graph.js.map +1 -1
  42. package/dist/cjs/data-structures/graph/undirected-graph.d.ts +76 -7
  43. package/dist/cjs/data-structures/graph/undirected-graph.js +151 -18
  44. package/dist/cjs/data-structures/graph/undirected-graph.js.map +1 -1
  45. package/dist/cjs/data-structures/hash/hash-map.d.ts +254 -28
  46. package/dist/cjs/data-structures/hash/hash-map.js +347 -78
  47. package/dist/cjs/data-structures/hash/hash-map.js.map +1 -1
  48. package/dist/cjs/data-structures/heap/heap.d.ts +95 -25
  49. package/dist/cjs/data-structures/heap/heap.js +95 -26
  50. package/dist/cjs/data-structures/heap/heap.js.map +1 -1
  51. package/dist/cjs/data-structures/linked-list/doubly-linked-list.d.ts +126 -63
  52. package/dist/cjs/data-structures/linked-list/doubly-linked-list.js +141 -77
  53. package/dist/cjs/data-structures/linked-list/doubly-linked-list.js.map +1 -1
  54. package/dist/cjs/data-structures/linked-list/singly-linked-list.d.ts +154 -106
  55. package/dist/cjs/data-structures/linked-list/singly-linked-list.js +164 -115
  56. package/dist/cjs/data-structures/linked-list/singly-linked-list.js.map +1 -1
  57. package/dist/cjs/data-structures/linked-list/skip-linked-list.d.ts +63 -36
  58. package/dist/cjs/data-structures/linked-list/skip-linked-list.js +63 -36
  59. package/dist/cjs/data-structures/linked-list/skip-linked-list.js.map +1 -1
  60. package/dist/cjs/data-structures/matrix/matrix.d.ts +35 -4
  61. package/dist/cjs/data-structures/matrix/matrix.js +50 -11
  62. package/dist/cjs/data-structures/matrix/matrix.js.map +1 -1
  63. package/dist/cjs/data-structures/priority-queue/max-priority-queue.d.ts +10 -0
  64. package/dist/cjs/data-structures/priority-queue/max-priority-queue.js +10 -0
  65. package/dist/cjs/data-structures/priority-queue/max-priority-queue.js.map +1 -1
  66. package/dist/cjs/data-structures/priority-queue/min-priority-queue.d.ts +11 -0
  67. package/dist/cjs/data-structures/priority-queue/min-priority-queue.js +11 -0
  68. package/dist/cjs/data-structures/priority-queue/min-priority-queue.js.map +1 -1
  69. package/dist/cjs/data-structures/priority-queue/priority-queue.d.ts +8 -0
  70. package/dist/cjs/data-structures/priority-queue/priority-queue.js +8 -0
  71. package/dist/cjs/data-structures/priority-queue/priority-queue.js.map +1 -1
  72. package/dist/cjs/data-structures/queue/deque.d.ts +139 -35
  73. package/dist/cjs/data-structures/queue/deque.js +200 -62
  74. package/dist/cjs/data-structures/queue/deque.js.map +1 -1
  75. package/dist/cjs/data-structures/queue/queue.d.ts +103 -49
  76. package/dist/cjs/data-structures/queue/queue.js +111 -49
  77. package/dist/cjs/data-structures/queue/queue.js.map +1 -1
  78. package/dist/cjs/data-structures/stack/stack.d.ts +51 -21
  79. package/dist/cjs/data-structures/stack/stack.js +58 -22
  80. package/dist/cjs/data-structures/stack/stack.js.map +1 -1
  81. package/dist/cjs/data-structures/tree/tree.d.ts +57 -3
  82. package/dist/cjs/data-structures/tree/tree.js +77 -11
  83. package/dist/cjs/data-structures/tree/tree.js.map +1 -1
  84. package/dist/cjs/data-structures/trie/trie.d.ts +135 -34
  85. package/dist/cjs/data-structures/trie/trie.js +153 -33
  86. package/dist/cjs/data-structures/trie/trie.js.map +1 -1
  87. package/dist/cjs/types/data-structures/binary-tree/binary-tree.d.ts +1 -1
  88. package/dist/cjs/types/data-structures/hash/hash-map.d.ts +4 -3
  89. package/dist/cjs/types/utils/utils.d.ts +1 -0
  90. package/dist/mjs/data-structures/base/iterable-base.d.ts +120 -9
  91. package/dist/mjs/data-structures/base/iterable-base.js +143 -7
  92. package/dist/mjs/data-structures/binary-tree/avl-tree.d.ts +72 -47
  93. package/dist/mjs/data-structures/binary-tree/avl-tree.js +102 -73
  94. package/dist/mjs/data-structures/binary-tree/binary-indexed-tree.d.ts +22 -0
  95. package/dist/mjs/data-structures/binary-tree/binary-indexed-tree.js +22 -0
  96. package/dist/mjs/data-structures/binary-tree/binary-tree.d.ts +244 -199
  97. package/dist/mjs/data-structures/binary-tree/binary-tree.js +483 -375
  98. package/dist/mjs/data-structures/binary-tree/bst.d.ts +92 -79
  99. package/dist/mjs/data-structures/binary-tree/bst.js +68 -76
  100. package/dist/mjs/data-structures/binary-tree/rb-tree.d.ts +127 -57
  101. package/dist/mjs/data-structures/binary-tree/rb-tree.js +153 -100
  102. package/dist/mjs/data-structures/binary-tree/segment-tree.d.ts +99 -6
  103. package/dist/mjs/data-structures/binary-tree/segment-tree.js +127 -10
  104. package/dist/mjs/data-structures/binary-tree/tree-multimap.d.ts +72 -58
  105. package/dist/mjs/data-structures/binary-tree/tree-multimap.js +102 -86
  106. package/dist/mjs/data-structures/graph/abstract-graph.d.ts +1 -78
  107. package/dist/mjs/data-structures/graph/abstract-graph.js +3 -188
  108. package/dist/mjs/data-structures/graph/directed-graph.d.ts +73 -0
  109. package/dist/mjs/data-structures/graph/directed-graph.js +131 -0
  110. package/dist/mjs/data-structures/graph/map-graph.d.ts +8 -0
  111. package/dist/mjs/data-structures/graph/map-graph.js +14 -0
  112. package/dist/mjs/data-structures/graph/undirected-graph.d.ts +76 -7
  113. package/dist/mjs/data-structures/graph/undirected-graph.js +152 -19
  114. package/dist/mjs/data-structures/hash/hash-map.d.ts +254 -28
  115. package/dist/mjs/data-structures/hash/hash-map.js +353 -84
  116. package/dist/mjs/data-structures/heap/heap.d.ts +95 -25
  117. package/dist/mjs/data-structures/heap/heap.js +95 -26
  118. package/dist/mjs/data-structures/linked-list/doubly-linked-list.d.ts +126 -63
  119. package/dist/mjs/data-structures/linked-list/doubly-linked-list.js +144 -80
  120. package/dist/mjs/data-structures/linked-list/singly-linked-list.d.ts +154 -106
  121. package/dist/mjs/data-structures/linked-list/singly-linked-list.js +166 -117
  122. package/dist/mjs/data-structures/linked-list/skip-linked-list.d.ts +63 -36
  123. package/dist/mjs/data-structures/linked-list/skip-linked-list.js +63 -36
  124. package/dist/mjs/data-structures/matrix/matrix.d.ts +35 -4
  125. package/dist/mjs/data-structures/matrix/matrix.js +50 -11
  126. package/dist/mjs/data-structures/priority-queue/max-priority-queue.d.ts +10 -0
  127. package/dist/mjs/data-structures/priority-queue/max-priority-queue.js +10 -0
  128. package/dist/mjs/data-structures/priority-queue/min-priority-queue.d.ts +11 -0
  129. package/dist/mjs/data-structures/priority-queue/min-priority-queue.js +11 -0
  130. package/dist/mjs/data-structures/priority-queue/priority-queue.d.ts +8 -0
  131. package/dist/mjs/data-structures/priority-queue/priority-queue.js +8 -0
  132. package/dist/mjs/data-structures/queue/deque.d.ts +139 -35
  133. package/dist/mjs/data-structures/queue/deque.js +205 -67
  134. package/dist/mjs/data-structures/queue/queue.d.ts +103 -49
  135. package/dist/mjs/data-structures/queue/queue.js +111 -49
  136. package/dist/mjs/data-structures/stack/stack.d.ts +51 -21
  137. package/dist/mjs/data-structures/stack/stack.js +58 -22
  138. package/dist/mjs/data-structures/tree/tree.d.ts +57 -3
  139. package/dist/mjs/data-structures/tree/tree.js +80 -14
  140. package/dist/mjs/data-structures/trie/trie.d.ts +135 -34
  141. package/dist/mjs/data-structures/trie/trie.js +156 -36
  142. package/dist/mjs/types/data-structures/binary-tree/binary-tree.d.ts +1 -1
  143. package/dist/mjs/types/data-structures/hash/hash-map.d.ts +4 -3
  144. package/dist/mjs/types/utils/utils.d.ts +1 -0
  145. package/dist/umd/data-structure-typed.js +3121 -1583
  146. package/dist/umd/data-structure-typed.min.js +3 -3
  147. package/dist/umd/data-structure-typed.min.js.map +1 -1
  148. package/package.json +61 -55
  149. package/src/data-structures/base/iterable-base.ts +184 -19
  150. package/src/data-structures/binary-tree/avl-tree.ts +134 -100
  151. package/src/data-structures/binary-tree/binary-indexed-tree.ts +22 -0
  152. package/src/data-structures/binary-tree/binary-tree.ts +674 -671
  153. package/src/data-structures/binary-tree/bst.ts +127 -136
  154. package/src/data-structures/binary-tree/rb-tree.ts +199 -166
  155. package/src/data-structures/binary-tree/segment-tree.ts +145 -11
  156. package/src/data-structures/binary-tree/tree-multimap.ts +138 -115
  157. package/src/data-structures/graph/abstract-graph.ts +4 -211
  158. package/src/data-structures/graph/directed-graph.ts +152 -0
  159. package/src/data-structures/graph/map-graph.ts +15 -0
  160. package/src/data-structures/graph/undirected-graph.ts +171 -19
  161. package/src/data-structures/hash/hash-map.ts +389 -96
  162. package/src/data-structures/heap/heap.ts +97 -26
  163. package/src/data-structures/linked-list/doubly-linked-list.ts +156 -83
  164. package/src/data-structures/linked-list/singly-linked-list.ts +174 -120
  165. package/src/data-structures/linked-list/skip-linked-list.ts +63 -37
  166. package/src/data-structures/matrix/matrix.ts +52 -12
  167. package/src/data-structures/priority-queue/max-priority-queue.ts +10 -0
  168. package/src/data-structures/priority-queue/min-priority-queue.ts +11 -0
  169. package/src/data-structures/priority-queue/priority-queue.ts +8 -0
  170. package/src/data-structures/queue/deque.ts +225 -70
  171. package/src/data-structures/queue/queue.ts +118 -49
  172. package/src/data-structures/stack/stack.ts +63 -23
  173. package/src/data-structures/tree/tree.ts +89 -15
  174. package/src/data-structures/trie/trie.ts +173 -38
  175. package/src/types/data-structures/binary-tree/binary-tree.ts +1 -1
  176. package/src/types/data-structures/hash/hash-map.ts +4 -3
  177. package/src/types/utils/utils.ts +2 -0
  178. package/test/performance/data-structures/graph/directed-graph.test.ts +4 -4
  179. package/test/performance/data-structures/queue/deque.test.ts +26 -25
  180. package/test/unit/data-structures/binary-tree/avl-tree.test.ts +37 -0
  181. package/test/unit/data-structures/binary-tree/binary-tree.test.ts +46 -17
  182. package/test/unit/data-structures/binary-tree/bst.test.ts +65 -1
  183. package/test/unit/data-structures/binary-tree/rb-tree.test.ts +38 -1
  184. package/test/unit/data-structures/binary-tree/tree-multimap.test.ts +37 -32
  185. package/test/unit/data-structures/graph/abstract-graph.test.ts +11 -0
  186. package/test/unit/data-structures/graph/directed-graph.test.ts +190 -5
  187. package/test/unit/data-structures/graph/undirected-graph.test.ts +263 -18
  188. package/test/unit/data-structures/hash/hash-map.test.ts +376 -353
  189. package/test/unit/data-structures/heap/heap.test.ts +18 -1
  190. package/test/unit/data-structures/linked-list/doubly-linked-list.test.ts +24 -5
  191. package/test/unit/data-structures/linked-list/singly-linked-list.test.ts +20 -2
  192. package/test/unit/data-structures/linked-list/skip-list.test.ts +1 -1
  193. package/test/unit/data-structures/queue/deque.test.ts +65 -5
  194. package/test/unit/data-structures/queue/queue.test.ts +24 -5
  195. package/test/unit/data-structures/stack/stack.test.ts +17 -0
  196. package/test/unit/data-structures/trie/trie.test.ts +17 -0
@@ -4,13 +4,14 @@ export type HashMapLinkedNode<K, V> = {
4
4
  next: HashMapLinkedNode<K, V>;
5
5
  prev: HashMapLinkedNode<K, V>;
6
6
  };
7
- export type LinkedHashMapOptions<K> = {
7
+ export type LinkedHashMapOptions<K, V, R> = {
8
8
  hashFn?: (key: K) => string;
9
9
  objHashFn?: (key: K) => object;
10
+ toEntryFn?: (rawElement: R) => [K, V];
10
11
  };
11
- export type HashMapOptions<K, V, T> = {
12
+ export type HashMapOptions<K, V, R> = {
12
13
  hashFn?: (key: K) => string;
13
- toEntryFn?: (rawElement: T) => [K, V];
14
+ toEntryFn?: (rawElement: R) => [K, V];
14
15
  };
15
16
  export type HashMapStoreItem<K, V> = {
16
17
  key: K;
@@ -5,3 +5,4 @@ export type Thunk = () => ReturnType<ToThunkFn> & {
5
5
  export type TrlFn = (...args: any[]) => any;
6
6
  export type TrlAsyncFn = (...args: any[]) => any;
7
7
  export type SpecifyOptional<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>;
8
+ export type Any = string | number | boolean | object | null | undefined | symbol;
@@ -105,6 +105,72 @@ export declare abstract class IterableEntryBase<K = any, V = any> {
105
105
  * used as the `this` value when calling the callback function. If `thisArg` is not provided, `
106
106
  */
107
107
  forEach(callbackfn: EntryCallback<K, V, void>, thisArg?: any): void;
108
+ /**
109
+ * Time Complexity: O(n)
110
+ * Space Complexity: O(1)
111
+ */
112
+ /**
113
+ * Time Complexity: O(n)
114
+ * Space Complexity: O(1)
115
+ *
116
+ * The `find` function iterates over the entries of a collection and returns the first value for
117
+ * which the callback function returns true.
118
+ * @param callbackfn - The callback function that will be called for each entry in the collection. It
119
+ * takes three arguments: the value of the entry, the key of the entry, and the index of the entry in
120
+ * the collection. It should return a boolean value indicating whether the current entry matches the
121
+ * desired condition.
122
+ * @param {any} [thisArg] - The `thisArg` parameter is an optional argument that specifies the value
123
+ * to be used as `this` when executing the `callbackfn` function. If `thisArg` is provided, it will
124
+ * be passed as the `this` value to the `callbackfn` function. If `thisArg
125
+ * @returns The method `find` returns the value of the first element in the iterable that satisfies
126
+ * the provided callback function. If no element satisfies the callback function, `undefined` is
127
+ * returned.
128
+ */
129
+ find(callbackfn: EntryCallback<K, V, [K, V]>, thisArg?: any): [K, V] | undefined;
130
+ /**
131
+ * Time Complexity: O(n)
132
+ * Space Complexity: O(1)
133
+ */
134
+ /**
135
+ * Time Complexity: O(n)
136
+ * Space Complexity: O(1)
137
+ *
138
+ * The function checks if a given key exists in a collection.
139
+ * @param {K} key - The parameter "key" is of type K, which means it can be any type. It represents
140
+ * the key that we want to check for existence in the data structure.
141
+ * @returns a boolean value. It returns true if the key is found in the collection, and false
142
+ * otherwise.
143
+ */
144
+ has(key: K): boolean;
145
+ /**
146
+ * Time Complexity: O(n)
147
+ * Space Complexity: O(1)
148
+ */
149
+ /**
150
+ * Time Complexity: O(n)
151
+ * Space Complexity: O(1)
152
+ *
153
+ * The function checks if a given value exists in a collection.
154
+ * @param {V} value - The parameter "value" is the value that we want to check if it exists in the
155
+ * collection.
156
+ * @returns a boolean value, either true or false.
157
+ */
158
+ hasValue(value: V): boolean;
159
+ /**
160
+ * Time Complexity: O(n)
161
+ * Space Complexity: O(1)
162
+ */
163
+ /**
164
+ * Time Complexity: O(n)
165
+ * Space Complexity: O(1)
166
+ *
167
+ * The `get` function retrieves the value associated with a given key from a collection.
168
+ * @param {K} key - K (the type of the key) - This parameter represents the key that is being
169
+ * searched for in the collection.
170
+ * @returns The `get` method returns the value associated with the specified key if it exists in the
171
+ * collection, otherwise it returns `undefined`.
172
+ */
173
+ get(key: K): V | undefined;
108
174
  /**
109
175
  * Time Complexity: O(n)
110
176
  * Space Complexity: O(1)
@@ -126,15 +192,19 @@ export declare abstract class IterableEntryBase<K = any, V = any> {
126
192
  * all the elements in the collection.
127
193
  */
128
194
  reduce<U>(callbackfn: ReduceEntryCallback<K, V, U>, initialValue: U): U;
129
- hasValue(value: V): boolean;
130
195
  /**
131
196
  * Time Complexity: O(n)
132
197
  * Space Complexity: O(n)
133
198
  */
134
199
  print(): void;
200
+ abstract isEmpty(): boolean;
201
+ abstract clear(): void;
202
+ abstract clone(): any;
203
+ abstract map(...args: any[]): any;
204
+ abstract filter(...args: any[]): any;
135
205
  protected abstract _getIterator(...args: any[]): IterableIterator<[K, V]>;
136
206
  }
137
- export declare abstract class IterableElementBase<V> {
207
+ export declare abstract class IterableElementBase<E = any, C = any> {
138
208
  /**
139
209
  * Time Complexity: O(n)
140
210
  * Space Complexity: O(1)
@@ -148,7 +218,7 @@ export declare abstract class IterableElementBase<V> {
148
218
  * allows the function to accept any number of arguments as an array. In this case, the `args`
149
219
  * parameter is used to pass any number of arguments to the `_getIterator` method.
150
220
  */
151
- [Symbol.iterator](...args: any[]): IterableIterator<V>;
221
+ [Symbol.iterator](...args: any[]): IterableIterator<E>;
152
222
  /**
153
223
  * Time Complexity: O(n)
154
224
  * Space Complexity: O(n)
@@ -159,7 +229,7 @@ export declare abstract class IterableElementBase<V> {
159
229
  *
160
230
  * The function returns an iterator that yields all the values in the object.
161
231
  */
162
- values(): IterableIterator<V>;
232
+ values(): IterableIterator<E>;
163
233
  /**
164
234
  * Time Complexity: O(n)
165
235
  * Space Complexity: O(1)
@@ -178,7 +248,7 @@ export declare abstract class IterableElementBase<V> {
178
248
  * @returns The `every` method is returning a boolean value. It returns `true` if every element in
179
249
  * the array satisfies the provided predicate function, and `false` otherwise.
180
250
  */
181
- every(predicate: ElementCallback<V, boolean>, thisArg?: any): boolean;
251
+ every(predicate: ElementCallback<E, boolean>, thisArg?: any): boolean;
182
252
  /**
183
253
  * Time Complexity: O(n)
184
254
  * Space Complexity: O(1)
@@ -197,7 +267,7 @@ export declare abstract class IterableElementBase<V> {
197
267
  * @returns a boolean value. It returns true if the predicate function returns true for any element
198
268
  * in the collection, and false otherwise.
199
269
  */
200
- some(predicate: ElementCallback<V, boolean>, thisArg?: any): boolean;
270
+ some(predicate: ElementCallback<E, boolean>, thisArg?: any): boolean;
201
271
  /**
202
272
  * Time Complexity: O(n)
203
273
  * Space Complexity: O(1)
@@ -215,7 +285,43 @@ export declare abstract class IterableElementBase<V> {
215
285
  * to be used as `this` when executing the `callbackfn` function. If `thisArg` is provided, it will
216
286
  * be passed as the `this` value to the `callbackfn` function. If `thisArg
217
287
  */
218
- forEach(callbackfn: ElementCallback<V, void>, thisArg?: any): void;
288
+ forEach(callbackfn: ElementCallback<E, void>, thisArg?: any): void;
289
+ /**
290
+ * Time Complexity: O(n)
291
+ * Space Complexity: O(1)
292
+ */
293
+ /**
294
+ * Time Complexity: O(n)
295
+ * Space Complexity: O(1)
296
+ *
297
+ * The `find` function iterates over the elements of an array-like object and returns the first
298
+ * element that satisfies the provided callback function.
299
+ * @param callbackfn - The callbackfn parameter is a function that will be called for each element in
300
+ * the array. It takes three arguments: the current element being processed, the index of the current
301
+ * element, and the array itself. The function should return a boolean value indicating whether the
302
+ * current element matches the desired condition.
303
+ * @param {any} [thisArg] - The `thisArg` parameter is an optional argument that specifies the value
304
+ * to be used as `this` when executing the `callbackfn` function. If `thisArg` is provided, it will
305
+ * be passed as the `this` value to the `callbackfn` function. If `thisArg
306
+ * @returns The `find` method returns the first element in the array that satisfies the provided
307
+ * callback function. If no element satisfies the callback function, `undefined` is returned.
308
+ */
309
+ find(callbackfn: ElementCallback<E, boolean>, thisArg?: any): E | undefined;
310
+ /**
311
+ * Time Complexity: O(n)
312
+ * Space Complexity: O(1)
313
+ */
314
+ /**
315
+ * Time Complexity: O(n)
316
+ * Space Complexity: O(1)
317
+ *
318
+ * The function checks if a given element exists in a collection.
319
+ * @param {E} element - The parameter "element" is of type E, which means it can be any type. It
320
+ * represents the element that we want to check for existence in the collection.
321
+ * @returns a boolean value. It returns true if the element is found in the collection, and false
322
+ * otherwise.
323
+ */
324
+ has(element: E): boolean;
219
325
  /**
220
326
  * Time Complexity: O(n)
221
327
  * Space Complexity: O(1)
@@ -233,11 +339,16 @@ export declare abstract class IterableElementBase<V> {
233
339
  * @returns The `reduce` method is returning the final value of the accumulator after iterating over
234
340
  * all the elements in the array and applying the callback function to each element.
235
341
  */
236
- reduce<U>(callbackfn: ReduceElementCallback<V, U>, initialValue: U): U;
342
+ reduce<U>(callbackfn: ReduceElementCallback<E, U>, initialValue: U): U;
237
343
  /**
238
344
  * Time Complexity: O(n)
239
345
  * Space Complexity: O(n)
240
346
  */
241
347
  print(): void;
242
- protected abstract _getIterator(...args: any[]): IterableIterator<V>;
348
+ abstract isEmpty(): boolean;
349
+ abstract clear(): void;
350
+ abstract clone(): C;
351
+ abstract map(...args: any[]): any;
352
+ abstract filter(...args: any[]): any;
353
+ protected abstract _getIterator(...args: any[]): IterableIterator<E>;
243
354
  }
@@ -140,6 +140,100 @@ export class IterableEntryBase {
140
140
  callbackfn.call(thisArg, value, key, index++, this);
141
141
  }
142
142
  }
143
+ /**
144
+ * Time Complexity: O(n)
145
+ * Space Complexity: O(1)
146
+ */
147
+ /**
148
+ * Time Complexity: O(n)
149
+ * Space Complexity: O(1)
150
+ *
151
+ * The `find` function iterates over the entries of a collection and returns the first value for
152
+ * which the callback function returns true.
153
+ * @param callbackfn - The callback function that will be called for each entry in the collection. It
154
+ * takes three arguments: the value of the entry, the key of the entry, and the index of the entry in
155
+ * the collection. It should return a boolean value indicating whether the current entry matches the
156
+ * desired condition.
157
+ * @param {any} [thisArg] - The `thisArg` parameter is an optional argument that specifies the value
158
+ * to be used as `this` when executing the `callbackfn` function. If `thisArg` is provided, it will
159
+ * be passed as the `this` value to the `callbackfn` function. If `thisArg
160
+ * @returns The method `find` returns the value of the first element in the iterable that satisfies
161
+ * the provided callback function. If no element satisfies the callback function, `undefined` is
162
+ * returned.
163
+ */
164
+ find(callbackfn, thisArg) {
165
+ let index = 0;
166
+ for (const item of this) {
167
+ const [key, value] = item;
168
+ if (callbackfn.call(thisArg, value, key, index++, this))
169
+ return item;
170
+ }
171
+ return;
172
+ }
173
+ /**
174
+ * Time Complexity: O(n)
175
+ * Space Complexity: O(1)
176
+ */
177
+ /**
178
+ * Time Complexity: O(n)
179
+ * Space Complexity: O(1)
180
+ *
181
+ * The function checks if a given key exists in a collection.
182
+ * @param {K} key - The parameter "key" is of type K, which means it can be any type. It represents
183
+ * the key that we want to check for existence in the data structure.
184
+ * @returns a boolean value. It returns true if the key is found in the collection, and false
185
+ * otherwise.
186
+ */
187
+ has(key) {
188
+ for (const item of this) {
189
+ const [itemKey] = item;
190
+ if (itemKey === key)
191
+ return true;
192
+ }
193
+ return false;
194
+ }
195
+ /**
196
+ * Time Complexity: O(n)
197
+ * Space Complexity: O(1)
198
+ */
199
+ /**
200
+ * Time Complexity: O(n)
201
+ * Space Complexity: O(1)
202
+ *
203
+ * The function checks if a given value exists in a collection.
204
+ * @param {V} value - The parameter "value" is the value that we want to check if it exists in the
205
+ * collection.
206
+ * @returns a boolean value, either true or false.
207
+ */
208
+ hasValue(value) {
209
+ for (const [, elementValue] of this) {
210
+ if (elementValue === value)
211
+ return true;
212
+ }
213
+ return false;
214
+ }
215
+ /**
216
+ * Time Complexity: O(n)
217
+ * Space Complexity: O(1)
218
+ */
219
+ /**
220
+ * Time Complexity: O(n)
221
+ * Space Complexity: O(1)
222
+ *
223
+ * The `get` function retrieves the value associated with a given key from a collection.
224
+ * @param {K} key - K (the type of the key) - This parameter represents the key that is being
225
+ * searched for in the collection.
226
+ * @returns The `get` method returns the value associated with the specified key if it exists in the
227
+ * collection, otherwise it returns `undefined`.
228
+ */
229
+ get(key) {
230
+ for (const item of this) {
231
+ const [itemKey, value] = item;
232
+ if (itemKey === key)
233
+ return value;
234
+ }
235
+ return;
236
+ }
143
237
  /**
144
238
  * Time Complexity: O(n)
145
239
  * Space Complexity: O(1)
@@ -169,13 +263,6 @@ export class IterableEntryBase {
169
263
  }
170
264
  return accumulator;
171
265
  }
172
- hasValue(value) {
173
- for (const [, elementValue] of this) {
174
- if (elementValue === value)
175
- return true;
176
- }
177
- return false;
178
- }
179
266
  /**
180
267
  * Time Complexity: O(n)
181
268
  * Space Complexity: O(n)
@@ -293,6 +380,55 @@ export class IterableElementBase {
293
380
  callbackfn.call(thisArg, item, index++, this);
294
381
  }
295
382
  }
383
+ /**
384
+ * Time Complexity: O(n)
385
+ * Space Complexity: O(1)
386
+ */
387
+ /**
388
+ * Time Complexity: O(n)
389
+ * Space Complexity: O(1)
390
+ *
391
+ * The `find` function iterates over the elements of an array-like object and returns the first
392
+ * element that satisfies the provided callback function.
393
+ * @param callbackfn - The callbackfn parameter is a function that will be called for each element in
394
+ * the array. It takes three arguments: the current element being processed, the index of the current
395
+ * element, and the array itself. The function should return a boolean value indicating whether the
396
+ * current element matches the desired condition.
397
+ * @param {any} [thisArg] - The `thisArg` parameter is an optional argument that specifies the value
398
+ * to be used as `this` when executing the `callbackfn` function. If `thisArg` is provided, it will
399
+ * be passed as the `this` value to the `callbackfn` function. If `thisArg
400
+ * @returns The `find` method returns the first element in the array that satisfies the provided
401
+ * callback function. If no element satisfies the callback function, `undefined` is returned.
402
+ */
403
+ find(callbackfn, thisArg) {
404
+ let index = 0;
405
+ for (const item of this) {
406
+ if (callbackfn.call(thisArg, item, index++, this))
407
+ return item;
408
+ }
409
+ return;
410
+ }
411
+ /**
412
+ * Time Complexity: O(n)
413
+ * Space Complexity: O(1)
414
+ */
415
+ /**
416
+ * Time Complexity: O(n)
417
+ * Space Complexity: O(1)
418
+ *
419
+ * The function checks if a given element exists in a collection.
420
+ * @param {E} element - The parameter "element" is of type E, which means it can be any type. It
421
+ * represents the element that we want to check for existence in the collection.
422
+ * @returns a boolean value. It returns true if the element is found in the collection, and false
423
+ * otherwise.
424
+ */
425
+ has(element) {
426
+ for (const ele of this) {
427
+ if (ele === element)
428
+ return true;
429
+ }
430
+ return false;
431
+ }
296
432
  /**
297
433
  * Time Complexity: O(n)
298
434
  * Space Complexity: O(1)
@@ -8,9 +8,28 @@
8
8
  import { BST, BSTNode } from './bst';
9
9
  import type { AVLTreeNested, AVLTreeNodeNested, AVLTreeOptions, BinaryTreeDeleteResult, BSTNKeyOrNode, BTNCallback, KeyOrNodeOrEntry } from '../../types';
10
10
  import { IBinaryTree } from '../../interfaces';
11
- export declare class AVLTreeNode<K = any, V = any, N extends AVLTreeNode<K, V, N> = AVLTreeNodeNested<K, V>> extends BSTNode<K, V, N> {
12
- height: number;
11
+ export declare class AVLTreeNode<K = any, V = any, NODE extends AVLTreeNode<K, V, NODE> = AVLTreeNodeNested<K, V>> extends BSTNode<K, V, NODE> {
12
+ /**
13
+ * The constructor function initializes a new instance of a class with a key and an optional value,
14
+ * and sets the height property to 0.
15
+ * @param {K} key - The "key" parameter is of type K, which represents the type of the key for the
16
+ * constructor. It is used to initialize the key property of the object being created.
17
+ * @param {V} [value] - The "value" parameter is an optional parameter of type V. It represents the
18
+ * value associated with the key in the constructor.
19
+ */
13
20
  constructor(key: K, value?: V);
21
+ protected _height: number;
22
+ /**
23
+ * The function returns the value of the height property.
24
+ * @returns The height of the object.
25
+ */
26
+ get height(): number;
27
+ /**
28
+ * The above function sets the value of the height property.
29
+ * @param {number} value - The value parameter is a number that represents the new height value to be
30
+ * set.
31
+ */
32
+ set height(value: number);
14
33
  }
15
34
  /**
16
35
  * 1. Height-Balanced: Each node's left and right subtrees differ in height by no more than one.
@@ -21,27 +40,27 @@ export declare class AVLTreeNode<K = any, V = any, N extends AVLTreeNode<K, V, N
21
40
  * 6. Complex Insertions and Deletions: Due to rebalancing, these operations are more complex than in a regular BST.
22
41
  * 7. Path Length: The path length from the root to any leaf is longer compared to an unbalanced BST, but shorter than a linear chain of nodes.
23
42
  */
24
- export declare class AVLTree<K = any, V = any, N extends AVLTreeNode<K, V, N> = AVLTreeNode<K, V, AVLTreeNodeNested<K, V>>, TREE extends AVLTree<K, V, N, TREE> = AVLTree<K, V, N, AVLTreeNested<K, V, N>>> extends BST<K, V, N, TREE> implements IBinaryTree<K, V, N, TREE> {
43
+ export declare class AVLTree<K = any, V = any, NODE extends AVLTreeNode<K, V, NODE> = AVLTreeNode<K, V, AVLTreeNodeNested<K, V>>, TREE extends AVLTree<K, V, NODE, TREE> = AVLTree<K, V, NODE, AVLTreeNested<K, V, NODE>>> extends BST<K, V, NODE, TREE> implements IBinaryTree<K, V, NODE, TREE> {
25
44
  /**
26
45
  * The constructor function initializes an AVLTree object with optional keysOrNodesOrEntries and options.
27
- * @param [keysOrNodesOrEntries] - The `keysOrNodesOrEntries` parameter is an optional iterable of `KeyOrNodeOrEntry<K, V, N>`
46
+ * @param [keysOrNodesOrEntries] - The `keysOrNodesOrEntries` parameter is an optional iterable of `KeyOrNodeOrEntry<K, V, NODE>`
28
47
  * objects. It represents a collection of nodes that will be added to the AVL tree during
29
48
  * initialization.
30
49
  * @param [options] - The `options` parameter is an optional object that allows you to customize the
31
50
  * behavior of the AVL tree. It is of type `Partial<AVLTreeOptions>`, which means that you can
32
51
  * provide only a subset of the properties defined in the `AVLTreeOptions` interface.
33
52
  */
34
- constructor(keysOrNodesOrEntries?: Iterable<KeyOrNodeOrEntry<K, V, N>>, options?: AVLTreeOptions<K>);
53
+ constructor(keysOrNodesOrEntries?: Iterable<KeyOrNodeOrEntry<K, V, NODE>>, options?: AVLTreeOptions<K>);
35
54
  /**
36
55
  * The function creates a new AVL tree node with the specified key and value.
37
56
  * @param {K} key - The key parameter is the key value that will be associated with
38
57
  * the new node. It is used to determine the position of the node in the binary search tree.
39
58
  * @param [value] - The parameter `value` is an optional value that can be assigned to the node. It is of
40
59
  * type `V`, which means it can be any value that is assignable to the `value` property of the
41
- * node type `N`.
60
+ * node type `NODE`.
42
61
  * @returns a new AVLTreeNode object with the specified key and value.
43
62
  */
44
- createNode(key: K, value?: V): N;
63
+ createNode(key: K, value?: V): NODE;
45
64
  /**
46
65
  * The function creates a new AVL tree with the specified options and returns it.
47
66
  * @param {AVLTreeOptions} [options] - The `options` parameter is an optional object that can be
@@ -52,10 +71,10 @@ export declare class AVLTree<K = any, V = any, N extends AVLTreeNode<K, V, N> =
52
71
  createTree(options?: AVLTreeOptions<K>): TREE;
53
72
  /**
54
73
  * The function checks if an keyOrNodeOrEntry is an instance of AVLTreeNode.
55
- * @param keyOrNodeOrEntry - The `keyOrNodeOrEntry` parameter is of type `KeyOrNodeOrEntry<K, V, N>`.
74
+ * @param keyOrNodeOrEntry - The `keyOrNodeOrEntry` parameter is of type `KeyOrNodeOrEntry<K, V, NODE>`.
56
75
  * @returns a boolean value indicating whether the keyOrNodeOrEntry is an instance of the AVLTreeNode class.
57
76
  */
58
- isNode(keyOrNodeOrEntry: KeyOrNodeOrEntry<K, V, N>): keyOrNodeOrEntry is N;
77
+ isNode(keyOrNodeOrEntry: KeyOrNodeOrEntry<K, V, NODE>): keyOrNodeOrEntry is NODE;
59
78
  /**
60
79
  * Time Complexity: O(log n)
61
80
  * Space Complexity: O(1)
@@ -73,7 +92,7 @@ export declare class AVLTree<K = any, V = any, N extends AVLTreeNode<K, V, N> =
73
92
  * being added to the binary tree.
74
93
  * @returns The method is returning either the inserted node or undefined.
75
94
  */
76
- add(keyOrNodeOrEntry: KeyOrNodeOrEntry<K, V, N>, value?: V): boolean;
95
+ add(keyOrNodeOrEntry: KeyOrNodeOrEntry<K, V, NODE>, value?: V): boolean;
77
96
  /**
78
97
  * Time Complexity: O(log n)
79
98
  * Space Complexity: O(1)
@@ -90,40 +109,38 @@ export declare class AVLTree<K = any, V = any, N extends AVLTreeNode<K, V, N> =
90
109
  * @param {C} callback - The `callback` parameter is a function that will be called for each node
91
110
  * that is deleted from the binary tree. It is an optional parameter and if not provided, it will
92
111
  * default to the `_defaultOneParamCallback` function. The `callback` function should have a single
93
- * parameter of type `N
94
- * @returns The method is returning an array of `BinaryTreeDeleteResult<N>`.
112
+ * parameter of type `NODE
113
+ * @returns The method is returning an array of `BinaryTreeDeleteResult<NODE>`.
95
114
  */
96
- delete<C extends BTNCallback<N>>(identifier: ReturnType<C>, callback?: C): BinaryTreeDeleteResult<N>[];
115
+ delete<C extends BTNCallback<NODE>>(identifier: ReturnType<C>, callback?: C): BinaryTreeDeleteResult<NODE>[];
97
116
  /**
98
117
  * The `_swapProperties` function swaps the key, value, and height properties between two nodes in a binary
99
118
  * tree.
100
- * @param {K | N | undefined} srcNode - The `srcNode` parameter represents the source node that
101
- * needs to be swapped with the destination node. It can be of type `K`, `N`, or `undefined`.
102
- * @param {K | N | undefined} destNode - The `destNode` parameter represents the destination
119
+ * @param {K | NODE | undefined} srcNode - The `srcNode` parameter represents the source node that
120
+ * needs to be swapped with the destination node. It can be of type `K`, `NODE`, or `undefined`.
121
+ * @param {K | NODE | undefined} destNode - The `destNode` parameter represents the destination
103
122
  * node where the values from the source node will be swapped to.
104
123
  * @returns either the `destNode` object if both `srcNode` and `destNode` are defined, or `undefined`
105
124
  * if either `srcNode` or `destNode` is undefined.
106
125
  */
107
- protected _swapProperties(srcNode: BSTNKeyOrNode<K, N>, destNode: BSTNKeyOrNode<K, N>): N | undefined;
126
+ protected _swapProperties(srcNode: BSTNKeyOrNode<K, NODE>, destNode: BSTNKeyOrNode<K, NODE>): NODE | undefined;
108
127
  /**
109
128
  * Time Complexity: O(1)
110
129
  * Space Complexity: O(1)
111
- * constant time, as it performs a fixed number of operations. constant space, as it only uses a constant amount of memory.
112
130
  */
113
131
  /**
114
132
  * Time Complexity: O(1)
115
133
  * Space Complexity: O(1)
116
134
  *
117
135
  * The function calculates the balance factor of a node in a binary tree.
118
- * @param {N} node - The parameter "node" represents a node in a binary tree data structure.
136
+ * @param {NODE} node - The parameter "node" represents a node in a binary tree data structure.
119
137
  * @returns the balance factor of a given node. The balance factor is calculated by subtracting the
120
138
  * height of the left subtree from the height of the right subtree.
121
139
  */
122
- protected _balanceFactor(node: N): number;
140
+ protected _balanceFactor(node: NODE): number;
123
141
  /**
124
142
  * Time Complexity: O(1)
125
143
  * Space Complexity: O(1)
126
- * constant time, as it performs a fixed number of operations. constant space, as it only uses a constant amount of memory.
127
144
  */
128
145
  /**
129
146
  * Time Complexity: O(1)
@@ -131,37 +148,33 @@ export declare class AVLTree<K = any, V = any, N extends AVLTreeNode<K, V, N> =
131
148
  *
132
149
  * The function updates the height of a node in a binary tree based on the heights of its left and
133
150
  * right children.
134
- * @param {N} node - The parameter "node" represents a node in a binary tree data structure.
151
+ * @param {NODE} node - The parameter "node" represents a node in a binary tree data structure.
135
152
  */
136
- protected _updateHeight(node: N): void;
153
+ protected _updateHeight(node: NODE): void;
137
154
  /**
138
- * Time Complexity: O(log n)
155
+ * Time Complexity: O(1)
139
156
  * Space Complexity: O(1)
140
- * logarithmic time, where "n" is the number of nodes in the tree. The method traverses the path from the inserted node to the root. constant space, as it doesn't use additional data structures that scale with input size.
141
157
  */
142
158
  /**
143
- * Time Complexity: O(log n)
159
+ * Time Complexity: O(1)
144
160
  * Space Complexity: O(1)
145
161
  *
146
- * The `_balancePath` function is used to update the heights of nodes and perform rotation operations
147
- * to restore balance in an AVL tree after inserting a node.
148
- * @param {N} node - The `node` parameter in the `_balancePath` function represents the node in the
149
- * AVL tree that needs to be balanced.
162
+ * The function `_balanceLL` performs a left-left rotation to balance a binary tree.
163
+ * @param {NODE} A - A is a node in a binary tree.
150
164
  */
151
- protected _balancePath(node: KeyOrNodeOrEntry<K, V, N>): void;
165
+ protected _balanceLL(A: NODE): void;
152
166
  /**
153
167
  * Time Complexity: O(1)
154
168
  * Space Complexity: O(1)
155
- * constant time, as these methods perform a fixed number of operations. constant space, as they only use a constant amount of memory.
156
169
  */
157
170
  /**
158
171
  * Time Complexity: O(1)
159
172
  * Space Complexity: O(1)
160
173
  *
161
- * The function `_balanceLL` performs a left-left rotation to balance a binary tree.
162
- * @param {N} A - A is a node in a binary tree.
174
+ * The `_balanceLR` function performs a left-right rotation to balance a binary tree.
175
+ * @param {NODE} A - A is a node in a binary tree.
163
176
  */
164
- protected _balanceLL(A: N): void;
177
+ protected _balanceLR(A: NODE): void;
165
178
  /**
166
179
  * Time Complexity: O(1)
167
180
  * Space Complexity: O(1)
@@ -170,10 +183,10 @@ export declare class AVLTree<K = any, V = any, N extends AVLTreeNode<K, V, N> =
170
183
  * Time Complexity: O(1)
171
184
  * Space Complexity: O(1)
172
185
  *
173
- * The `_balanceLR` function performs a left-right rotation to balance a binary tree.
174
- * @param {N} A - A is a node in a binary tree.
186
+ * The function `_balanceRR` performs a right-right rotation to balance a binary tree.
187
+ * @param {NODE} A - A is a node in a binary tree.
175
188
  */
176
- protected _balanceLR(A: N): void;
189
+ protected _balanceRR(A: NODE): void;
177
190
  /**
178
191
  * Time Complexity: O(1)
179
192
  * Space Complexity: O(1)
@@ -182,21 +195,33 @@ export declare class AVLTree<K = any, V = any, N extends AVLTreeNode<K, V, N> =
182
195
  * Time Complexity: O(1)
183
196
  * Space Complexity: O(1)
184
197
  *
185
- * The function `_balanceRR` performs a right-right rotation to balance a binary tree.
186
- * @param {N} A - A is a node in a binary tree.
198
+ * The function `_balanceRL` performs a right-left rotation to balance a binary tree.
199
+ * @param {NODE} A - A is a node in a binary tree.
187
200
  */
188
- protected _balanceRR(A: N): void;
201
+ protected _balanceRL(A: NODE): void;
189
202
  /**
190
- * Time Complexity: O(1)
203
+ * Time Complexity: O(log n)
191
204
  * Space Complexity: O(1)
205
+ * logarithmic time, where "n" is the number of nodes in the tree. The method traverses the path from the inserted node to the root. constant space, as it doesn't use additional data structures that scale with input size.
192
206
  */
193
207
  /**
194
- * Time Complexity: O(1)
208
+ * Time Complexity: O(log n)
195
209
  * Space Complexity: O(1)
196
210
  *
197
- * The function `_balanceRL` performs a right-left rotation to balance a binary tree.
198
- * @param {N} A - A is a node in a binary tree.
211
+ * The `_balancePath` function is used to update the heights of nodes and perform rotation operations
212
+ * to restore balance in an AVL tree after inserting a node.
213
+ * @param {NODE} node - The `node` parameter in the `_balancePath` function represents the node in the
214
+ * AVL tree that needs to be balanced.
215
+ */
216
+ protected _balancePath(node: KeyOrNodeOrEntry<K, V, NODE>): void;
217
+ /**
218
+ * The function replaces an old node with a new node while preserving the height of the old node.
219
+ * @param {NODE} oldNode - The `oldNode` parameter is the node that you want to replace with the
220
+ * `newNode`.
221
+ * @param {NODE} newNode - The `newNode` parameter is the new node that will replace the `oldNode` in
222
+ * the data structure.
223
+ * @returns the result of calling the `_replaceNode` method on the superclass, passing in the
224
+ * `oldNode` and `newNode` as arguments.
199
225
  */
200
- protected _balanceRL(A: N): void;
201
- protected _replaceNode(oldNode: N, newNode: N): N;
226
+ protected _replaceNode(oldNode: NODE, newNode: NODE): NODE;
202
227
  }