heap-typed 1.53.4 → 1.53.6

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.
@@ -72,26 +72,16 @@ export declare class SinglyLinkedList<E = any, R = any> extends IterableElementB
72
72
  * @returns The size of the object, which is a number.
73
73
  */
74
74
  get size(): number;
75
- /**
76
- * Time Complexity: O(n)
77
- * Space Complexity: O(n)
78
- *
79
- * The `fromArray` function creates a new SinglyLinkedList instance and populates it with the elements from the given
80
- * array.
81
- * @param {E[]} data - The `data` parameter is an array of elements of type `E`.
82
- * @returns The `fromArray` function returns a `SinglyLinkedList` object.
83
- */
84
- static fromArray<E>(data: E[]): SinglyLinkedList<E, any>;
85
75
  /**
86
76
  * Time Complexity: O(1)
87
77
  * Space Complexity: O(1)
88
78
  *
89
- * The push function adds a new element to the end of a singly linked list.
90
- * @param {E} element - The "element" parameter represents the value of the element that you want to
91
- * add to the linked list.
92
- * @returns The `push` method is returning a boolean value, `true`.
79
+ * The `push` function adds a new element or node to the end of a singly linked list.
80
+ * @param {E | SinglyLinkedListNode<E>} elementOrNode - The `elementOrNode` parameter in the `push`
81
+ * method can accept either an element of type `E` or a `SinglyLinkedListNode<E>` object.
82
+ * @returns The `push` method is returning a boolean value, specifically `true`.
93
83
  */
94
- push(element: E): boolean;
84
+ push(elementOrNode: E | SinglyLinkedListNode<E>): boolean;
95
85
  /**
96
86
  * Time Complexity: O(n)
97
87
  * Space Complexity: O(1)
@@ -113,12 +103,27 @@ export declare class SinglyLinkedList<E = any, R = any> extends IterableElementB
113
103
  * Time Complexity: O(1)
114
104
  * Space Complexity: O(1)
115
105
  *
116
- * The unshift function adds a new element to the beginning of a singly linked list.
117
- * @param {E} element - The "element" parameter represents the value of the element that you want to
118
- * add to the beginning of the singly linked list.
119
- * @returns The `unshift` method is returning a boolean value, `true`.
106
+ * The unshift function adds a new element or node to the beginning of a singly linked list in
107
+ * TypeScript.
108
+ * @param {E | SinglyLinkedListNode<E>} elementOrNode - The `elementOrNode` parameter in the
109
+ * `unshift` method can be either an element of type `E` or a `SinglyLinkedListNode` containing an
110
+ * element of type `E`.
111
+ * @returns The `unshift` method is returning a boolean value, specifically `true`.
112
+ */
113
+ unshift(elementOrNode: E | SinglyLinkedListNode<E>): boolean;
114
+ /**
115
+ * Time Complexity: O(n)
116
+ * Space Complexity: O(1)
117
+ *
118
+ * This function searches for a specific element in a singly linked list based on a given node or
119
+ * predicate.
120
+ * @param {E | SinglyLinkedListNode<E> | ((node: SinglyLinkedListNode<E>) => boolean)} elementNodeOrPredicate
121
+ * elementNodeOrPredicate - The `elementNodeOrPredicate` parameter in the `get` method can be one of
122
+ * the following types:
123
+ * @returns The `get` method returns the value of the first node in the singly linked list that
124
+ * satisfies the provided predicate function. If no such node is found, it returns `undefined`.
120
125
  */
121
- unshift(element: E): boolean;
126
+ get(elementNodeOrPredicate: E | SinglyLinkedListNode<E> | ((node: SinglyLinkedListNode<E>) => boolean)): E | undefined;
122
127
  /**
123
128
  * Time Complexity: O(n)
124
129
  * Space Complexity: O(1)
@@ -130,6 +135,20 @@ export declare class SinglyLinkedList<E = any, R = any> extends IterableElementB
130
135
  * `undefined` if the index is out of bounds.
131
136
  */
132
137
  at(index: number): E | undefined;
138
+ /**
139
+ * Time Complexity: O(1)
140
+ * Space Complexity: O(1)
141
+ *
142
+ * The function `isNode` in TypeScript checks if the input is an instance of `SinglyLinkedListNode`.
143
+ * @param {E | SinglyLinkedListNode<E> | ((node: SinglyLinkedListNode<E>) => boolean)} elementNodeOrPredicate
144
+ * elementNodeOrPredicate - The `elementNodeOrPredicate` parameter in the `isNode` function can be
145
+ * one of the following types:
146
+ * @returns The `isNode` function is checking if the `elementNodeOrPredicate` parameter is an
147
+ * instance of `SinglyLinkedListNode<E>`. If it is, the function returns `true`, indicating that the
148
+ * parameter is a `SinglyLinkedListNode<E>`. If it is not an instance of `SinglyLinkedListNode<E>`,
149
+ * the function returns `false`.
150
+ */
151
+ isNode(elementNodeOrPredicate: E | SinglyLinkedListNode<E> | ((node: SinglyLinkedListNode<E>) => boolean)): elementNodeOrPredicate is SinglyLinkedListNode<E>;
133
152
  /**
134
153
  * Time Complexity: O(n)
135
154
  * Space Complexity: O(1)
@@ -157,25 +176,28 @@ export declare class SinglyLinkedList<E = any, R = any> extends IterableElementB
157
176
  * Space Complexity: O(1)
158
177
  *
159
178
  * The delete function removes a node with a specific value from a singly linked list.
160
- * @param {E | SinglyLinkedListNode<E>} valueOrNode - The `valueOrNode` parameter can accept either a value of type `E`
179
+ * @param {E | SinglyLinkedListNode<E>} elementOrNode - The `elementOrNode` parameter can accept either a value of type `E`
161
180
  * or a `SinglyLinkedListNode<E>` object.
162
181
  * @returns The `delete` method returns a boolean value. It returns `true` if the value or node is found and
163
182
  * successfully deleted from the linked list, and `false` if the value or node is not found in the linked list.
164
183
  */
165
- delete(valueOrNode: E | SinglyLinkedListNode<E> | undefined): boolean;
184
+ delete(elementOrNode: E | SinglyLinkedListNode<E> | undefined): boolean;
166
185
  /**
167
186
  * Time Complexity: O(n)
168
187
  * Space Complexity: O(1)
169
188
  *
170
- * The `addAt` function inserts a value at a specified index in a singly linked list.
171
- * @param {number} index - The index parameter represents the position at which the new value should be inserted in the
172
- * linked list. It is of type number.
173
- * @param {E} value - The `value` parameter represents the value that you want to insert into the linked list at the
174
- * specified index.
175
- * @returns The `insert` method returns a boolean value. It returns `true` if the insertion is successful, and `false`
176
- * if the index is out of bounds.
177
- */
178
- addAt(index: number, value: E): boolean;
189
+ * The `addAt` function inserts a new element or node at a specified index in a singly linked list.
190
+ * @param {number} index - The `index` parameter represents the position at which you want to add a
191
+ * new element or node in the linked list. It is a number that indicates the index where the new
192
+ * element or node should be inserted.
193
+ * @param {E | SinglyLinkedListNode<E>} newElementOrNode - The `newElementOrNode` parameter in the
194
+ * `addAt` method can be either a value of type `E` or a `SinglyLinkedListNode<E>` object. This
195
+ * parameter represents the element or node that you want to add to the linked list at the specified
196
+ * index.
197
+ * @returns The `addAt` method returns a boolean value - `true` if the element or node was
198
+ * successfully added at the specified index, and `false` if the index is out of bounds.
199
+ */
200
+ addAt(index: number, newElementOrNode: E | SinglyLinkedListNode<E>): boolean;
179
201
  /**
180
202
  * The function checks if the length of a data structure is equal to zero and returns a boolean value indicating
181
203
  * whether it is empty or not.
@@ -206,56 +228,76 @@ export declare class SinglyLinkedList<E = any, R = any> extends IterableElementB
206
228
  * Time Complexity: O(n)
207
229
  * Space Complexity: O(1)
208
230
  *
209
- * The `indexOf` function returns the index of the first occurrence of a given value in a linked list.
210
- * @param {E} value - The value parameter is the value that you want to find the index of in the linked list.
211
- * @returns The method is returning the index of the first occurrence of the specified value in the linked list. If the
212
- * value is not found, it returns -1.
231
+ * The `indexOf` function in TypeScript searches for a specific element or node in a singly linked
232
+ * list and returns its index if found.
233
+ * @param {E | SinglyLinkedListNode<E> | ((node: SinglyLinkedListNode<E>) => boolean)} elementNodeOrPredicate
234
+ * elementNodeOrPredicate - The `elementNodeOrPredicate` parameter in the `indexOf` method can be one
235
+ * of the following types:
236
+ * @returns The `indexOf` method returns the index of the first occurrence of the element that
237
+ * matches the provided predicate in the singly linked list. If no matching element is found, it
238
+ * returns -1.
213
239
  */
214
- indexOf(value: E): number;
240
+ indexOf(elementNodeOrPredicate: E | SinglyLinkedListNode<E> | ((node: SinglyLinkedListNode<E>) => boolean)): number;
215
241
  /**
216
242
  * Time Complexity: O(n)
217
243
  * Space Complexity: O(1)
218
244
  *
219
- * The function finds a node in a singly linked list by its value and returns the node if found, otherwise returns
220
- * undefined.
221
- * @param {E} value - The value parameter is the value that we want to search for in the linked list.
222
- * @returns a `SinglyLinkedListNode<E>` if a node with the specified value is found in the linked list. If no node with
223
- * the specified value is found, the function returns `undefined`.
245
+ * The function `getNode` in TypeScript searches for a node in a singly linked list based on a given
246
+ * element, node, or predicate.
247
+ * @param {E | SinglyLinkedListNode<E> | ((node: SinglyLinkedListNode<E>) => boolean) | undefined} elementNodeOrPredicate
248
+ * elementNodeOrPredicate - The `elementNodeOrPredicate` parameter in the `getNode` method can be one
249
+ * of the following types:
250
+ * @returns The `getNode` method returns either a `SinglyLinkedListNode<E>` if a matching node is
251
+ * found based on the provided predicate, or it returns `undefined` if no matching node is found or
252
+ * if the input parameter is `undefined`.
224
253
  */
225
- getNode(value: E): SinglyLinkedListNode<E> | undefined;
254
+ getNode(elementNodeOrPredicate: E | SinglyLinkedListNode<E> | ((node: SinglyLinkedListNode<E>) => boolean) | undefined): SinglyLinkedListNode<E> | undefined;
226
255
  /**
227
256
  * Time Complexity: O(n)
228
257
  * Space Complexity: O(1)
229
258
  *
230
- * The `addBefore` function inserts a new value before an existing value in a singly linked list.
231
- * @param {E | SinglyLinkedListNode<E>} existingValueOrNode - The existing value or node that you want to insert the
232
- * new value before. It can be either the value itself or a node containing the value in the linked list.
233
- * @param {E} newValue - The `newValue` parameter represents the value that you want to insert into the linked list.
234
- * @returns The method `addBefore` returns a boolean value. It returns `true` if the new value was successfully
235
- * inserted before the existing value, and `false` otherwise.
236
- */
237
- addBefore(existingValueOrNode: E | SinglyLinkedListNode<E>, newValue: E): boolean;
259
+ * The function `addBefore` in TypeScript adds a new element or node before an existing element or
260
+ * node in a singly linked list.
261
+ * @param {E | SinglyLinkedListNode<E>} existingElementOrNode - existingElementOrNode represents the
262
+ * element or node in the linked list before which you want to add a new element or node.
263
+ * @param {E | SinglyLinkedListNode<E>} newElementOrNode - The `newElementOrNode` parameter in the
264
+ * `addBefore` method represents the element or node that you want to insert before the existing
265
+ * element or node in the linked list. This new element can be of type `E` or a
266
+ * `SinglyLinkedListNode<E>`.
267
+ * @returns The `addBefore` method returns a boolean value - `true` if the new element or node was
268
+ * successfully added before the existing element or node, and `false` if the operation was
269
+ * unsuccessful.
270
+ */
271
+ addBefore(existingElementOrNode: E | SinglyLinkedListNode<E>, newElementOrNode: E | SinglyLinkedListNode<E>): boolean;
238
272
  /**
239
273
  * Time Complexity: O(n)
240
274
  * Space Complexity: O(1)
241
275
  *
242
- * The `addAfter` function inserts a new node with a given value after an existing node in a singly linked list.
243
- * @param {E | SinglyLinkedListNode<E>} existingValueOrNode - The existing value or node in the linked list after which
244
- * the new value will be inserted. It can be either the value of the existing node or the existing node itself.
245
- * @param {E} newValue - The value that you want to insert into the linked list after the existing value or node.
246
- * @returns The method returns a boolean value. It returns true if the new value was successfully inserted after the
247
- * existing value or node, and false if the existing value or node was not found in the linked list.
248
- */
249
- addAfter(existingValueOrNode: E | SinglyLinkedListNode<E>, newValue: E): boolean;
276
+ * The `addAfter` function in TypeScript adds a new element or node after an existing element or node
277
+ * in a singly linked list.
278
+ * @param {E | SinglyLinkedListNode<E>} existingElementOrNode - existingElementOrNode can be either
279
+ * an element of type E or a SinglyLinkedListNode of type E.
280
+ * @param {E | SinglyLinkedListNode<E>} newElementOrNode - The `newElementOrNode` parameter in the
281
+ * `addAfter` method represents the element or node that you want to add after the existing element
282
+ * or node in a singly linked list. This parameter can be either the value of the new element or a
283
+ * reference to a `SinglyLinkedListNode` containing
284
+ * @returns The `addAfter` method returns a boolean value - `true` if the new element or node was
285
+ * successfully added after the existing element or node, and `false` if the existing element or node
286
+ * was not found.
287
+ */
288
+ addAfter(existingElementOrNode: E | SinglyLinkedListNode<E>, newElementOrNode: E | SinglyLinkedListNode<E>): boolean;
250
289
  /**
251
290
  * Time Complexity: O(n)
252
291
  * Space Complexity: O(1)
253
292
  *
254
- * The function counts the number of occurrences of a given value in a linked list.
255
- * @param {E} value - The value parameter is the value that you want to count the occurrences of in the linked list.
256
- * @returns The count of occurrences of the given value in the linked list.
293
+ * The function `countOccurrences` iterates through a singly linked list and counts the occurrences
294
+ * of a specified element or nodes that satisfy a given predicate.
295
+ * @param {E | SinglyLinkedListNode<E> | ((node: SinglyLinkedListNode<E>) => boolean)} elementOrNode
296
+ * - The `elementOrNode` parameter in the `countOccurrences` method can accept three types of values:
297
+ * @returns The `countOccurrences` method returns the number of occurrences of the specified element,
298
+ * node, or predicate function in the singly linked list.
257
299
  */
258
- countOccurrences(value: E): number;
300
+ countOccurrences(elementOrNode: E | SinglyLinkedListNode<E> | ((node: SinglyLinkedListNode<E>) => boolean)): number;
259
301
  /**
260
302
  * Time Complexity: O(n)
261
303
  * Space Complexity: O(n)
@@ -309,4 +351,44 @@ export declare class SinglyLinkedList<E = any, R = any> extends IterableElementB
309
351
  * The function `_getIterator` returns an iterable iterator that yields the values of a linked list.
310
352
  */
311
353
  protected _getIterator(): IterableIterator<E>;
354
+ /**
355
+ * Time Complexity: O(n)
356
+ * Space Complexity: O(n)
357
+ *
358
+ * The `fromArray` function creates a new SinglyLinkedList instance and populates it with the elements from the given
359
+ * array.
360
+ * @param {E[]} data - The `data` parameter is an array of elements of type `E`.
361
+ * @returns The `fromArray` function returns a `SinglyLinkedList` object.
362
+ */
363
+ static fromArray<E>(data: E[]): SinglyLinkedList<E, any>;
364
+ /**
365
+ * The _isPredicate function in TypeScript checks if the input is a function that takes a
366
+ * SinglyLinkedListNode as an argument and returns a boolean.
367
+ * @param {E | SinglyLinkedListNode<E> | ((node: SinglyLinkedListNode<E>) => boolean)} elementNodeOrPredicate
368
+ * elementNodeOrPredicate - The `elementNodeOrPredicate` parameter can be one of the following types:
369
+ * @returns The _isPredicate method is returning a boolean value based on whether the
370
+ * elementNodeOrPredicate parameter is a function or not. If the elementNodeOrPredicate is a
371
+ * function, the method will return true, indicating that it is a predicate function. If it is not a
372
+ * function, the method will return false.
373
+ */
374
+ protected _isPredicate(elementNodeOrPredicate: E | SinglyLinkedListNode<E> | ((node: SinglyLinkedListNode<E>) => boolean)): elementNodeOrPredicate is (node: SinglyLinkedListNode<E>) => boolean;
375
+ /**
376
+ * The function `_ensureNode` ensures that the input is a valid node and returns it, creating a new
377
+ * node if necessary.
378
+ * @param {E | SinglyLinkedListNode<E>} elementOrNode - The `elementOrNode` parameter can be either
379
+ * an element of type `E` or a `SinglyLinkedListNode` containing an element of type `E`.
380
+ * @returns A SinglyLinkedListNode<E> object is being returned.
381
+ */
382
+ protected _ensureNode(elementOrNode: E | SinglyLinkedListNode<E>): SinglyLinkedListNode<E>;
383
+ /**
384
+ * The function `_ensurePredicate` in TypeScript ensures that the input is either a node, a predicate
385
+ * function, or a value to compare with the node's value.
386
+ * @param {E | SinglyLinkedListNode<E> | ((node: SinglyLinkedListNode<E>) => boolean)} elementNodeOrPredicate
387
+ * elementNodeOrPredicate - The `elementNodeOrPredicate` parameter can be one of the following types:
388
+ * @returns A function is being returned. If the input `elementNodeOrPredicate` is already a node, a
389
+ * function is returned that checks if a given node is equal to the input node. If the input is a
390
+ * predicate function, it is returned as is. If the input is neither a node nor a predicate function,
391
+ * a function is returned that checks if a given node's value is equal to the input
392
+ */
393
+ protected _ensurePredicate(elementNodeOrPredicate: E | SinglyLinkedListNode<E> | ((node: SinglyLinkedListNode<E>) => boolean)): (node: SinglyLinkedListNode<E>) => boolean;
312
394
  }