min-heap-typed 1.38.4 → 1.38.5

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.
@@ -123,7 +123,7 @@ export declare class DoublyLinkedList<E = any> {
123
123
  * @returns The function `findNodeByValue` returns a `DoublyLinkedListNode<E>` if a node with the specified value `val`
124
124
  * is found in the linked list. If no such node is found, it returns `null`.
125
125
  */
126
- findNode(val: E): DoublyLinkedListNode<E> | null;
126
+ findNode(val: E | null): DoublyLinkedListNode<E> | null;
127
127
  /**
128
128
  * The `insert` function inserts a value at a specified index in a doubly linked list.
129
129
  * @param {number} index - The index parameter represents the position at which the new value should be inserted in the
@@ -229,6 +229,15 @@ export declare class DoublyLinkedList<E = any> {
229
229
  reduce<U>(callback: (accumulator: U, val: E) => U, initialValue: U): U;
230
230
  insertAfter(existingValueOrNode: E, newValue: E): boolean;
231
231
  insertAfter(existingValueOrNode: DoublyLinkedListNode<E>, newValue: E): boolean;
232
- insertBefore(existingValueOrNode: E, newValue: E): boolean;
233
- insertBefore(existingValueOrNode: DoublyLinkedListNode<E>, newValue: E): boolean;
232
+ /**
233
+ * The `insertBefore` function inserts a new value before an existing value or node in a doubly linked list.
234
+ * @param {E | DoublyLinkedListNode<E>} existingValueOrNode - The existing value or node in the doubly linked list
235
+ * before which the new value will be inserted. It can be either the value of the existing node or the existing node
236
+ * itself.
237
+ * @param {E} newValue - The `newValue` parameter represents the value that you want to insert into the doubly linked
238
+ * list.
239
+ * @returns The method returns a boolean value. It returns `true` if the insertion is successful, and `false` if the
240
+ * insertion fails.
241
+ */
242
+ insertBefore(existingValueOrNode: E | DoublyLinkedListNode<E>, newValue: E): boolean;
234
243
  }
@@ -88,8 +88,14 @@ export declare class SinglyLinkedList<E = any> {
88
88
  * bounds.
89
89
  */
90
90
  deleteAt(index: number): E | undefined;
91
- delete(valueOrNode: E): boolean;
92
- delete(valueOrNode: SinglyLinkedListNode<E>): boolean;
91
+ /**
92
+ * The delete function removes a node with a specific value from a singly linked list.
93
+ * @param {E | SinglyLinkedListNode<E>} valueOrNode - The `valueOrNode` parameter can accept either a value of type `E`
94
+ * or a `SinglyLinkedListNode<E>` object.
95
+ * @returns The `delete` method returns a boolean value. It returns `true` if the value or node is found and
96
+ * successfully deleted from the linked list, and `false` if the value or node is not found in the linked list.
97
+ */
98
+ delete(valueOrNode: E | SinglyLinkedListNode<E> | null | undefined): boolean;
93
99
  /**
94
100
  * The `insertAt` function inserts a value at a specified index in a singly linked list.
95
101
  * @param {number} index - The index parameter represents the position at which the new value should be inserted in the
@@ -143,8 +149,15 @@ export declare class SinglyLinkedList<E = any> {
143
149
  * the specified value is found, the function returns `null`.
144
150
  */
145
151
  findNode(value: E): SinglyLinkedListNode<E> | null;
146
- insertBefore(existingValue: E, newValue: E): boolean;
147
- insertBefore(existingValue: SinglyLinkedListNode<E>, newValue: E): boolean;
152
+ /**
153
+ * The `insertBefore` function inserts a new value before an existing value in a singly linked list.
154
+ * @param {E | SinglyLinkedListNode<E>} existingValueOrNode - The existing value or node that you want to insert the
155
+ * new value before. It can be either the value itself or a node containing the value in the linked list.
156
+ * @param {E} newValue - The `newValue` parameter represents the value that you want to insert into the linked list.
157
+ * @returns The method `insertBefore` returns a boolean value. It returns `true` if the new value was successfully
158
+ * inserted before the existing value, and `false` otherwise.
159
+ */
160
+ insertBefore(existingValueOrNode: E | SinglyLinkedListNode<E>, newValue: E): boolean;
148
161
  insertAfter(existingValueOrNode: E, newValue: E): boolean;
149
162
  insertAfter(existingValueOrNode: SinglyLinkedListNode<E>, newValue: E): boolean;
150
163
  /**
@@ -202,6 +202,8 @@ class SinglyLinkedList {
202
202
  * successfully deleted from the linked list, and `false` if the value or node is not found in the linked list.
203
203
  */
204
204
  delete(valueOrNode) {
205
+ if (!valueOrNode)
206
+ return false;
205
207
  let value;
206
208
  if (valueOrNode instanceof SinglyLinkedListNode) {
207
209
  value = valueOrNode.val;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "min-heap-typed",
3
- "version": "1.38.4",
3
+ "version": "1.38.5",
4
4
  "description": "Min Heap. Javascript & Typescript Data Structure.",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
@@ -266,7 +266,7 @@ export class DoublyLinkedList<E = any> {
266
266
  * @returns The function `findNodeByValue` returns a `DoublyLinkedListNode<E>` if a node with the specified value `val`
267
267
  * is found in the linked list. If no such node is found, it returns `null`.
268
268
  */
269
- findNode(val: E): DoublyLinkedListNode<E> | null {
269
+ findNode(val: E | null): DoublyLinkedListNode<E> | null {
270
270
  let current = this.head;
271
271
 
272
272
  while (current) {
@@ -341,7 +341,7 @@ export class DoublyLinkedList<E = any> {
341
341
  * @returns The `delete` method returns a boolean value. It returns `true` if the value or node was successfully
342
342
  * deleted from the doubly linked list, and `false` if the value or node was not found in the list.
343
343
  */
344
- delete(valOrNode: E | DoublyLinkedListNode<E>): boolean {
344
+ delete(valOrNode: E | DoublyLinkedListNode<E> | null): boolean {
345
345
  let node: DoublyLinkedListNode<E> | null;
346
346
 
347
347
  if (valOrNode instanceof DoublyLinkedListNode) {
@@ -594,8 +594,6 @@ export class DoublyLinkedList<E = any> {
594
594
  return false;
595
595
  }
596
596
 
597
- insertBefore(existingValueOrNode: E, newValue: E): boolean;
598
- insertBefore(existingValueOrNode: DoublyLinkedListNode<E>, newValue: E): boolean;
599
597
 
600
598
  /**
601
599
  * The `insertBefore` function inserts a new value before an existing value or node in a doubly linked list.
@@ -214,9 +214,6 @@ export class SinglyLinkedList<E = any> {
214
214
  return removedNode!.val;
215
215
  }
216
216
 
217
- delete(valueOrNode: E): boolean;
218
- delete(valueOrNode: SinglyLinkedListNode<E>): boolean;
219
-
220
217
  /**
221
218
  * The delete function removes a node with a specific value from a singly linked list.
222
219
  * @param {E | SinglyLinkedListNode<E>} valueOrNode - The `valueOrNode` parameter can accept either a value of type `E`
@@ -224,7 +221,8 @@ export class SinglyLinkedList<E = any> {
224
221
  * @returns The `delete` method returns a boolean value. It returns `true` if the value or node is found and
225
222
  * successfully deleted from the linked list, and `false` if the value or node is not found in the linked list.
226
223
  */
227
- delete(valueOrNode: E | SinglyLinkedListNode<E>): boolean {
224
+ delete(valueOrNode: E | SinglyLinkedListNode<E> | null | undefined): boolean {
225
+ if (!valueOrNode) return false;
228
226
  let value: E;
229
227
  if (valueOrNode instanceof SinglyLinkedListNode) {
230
228
  value = valueOrNode.val;
@@ -397,9 +395,6 @@ export class SinglyLinkedList<E = any> {
397
395
  return null;
398
396
  }
399
397
 
400
- insertBefore(existingValue: E, newValue: E): boolean;
401
- insertBefore(existingValue: SinglyLinkedListNode<E>, newValue: E): boolean;
402
-
403
398
  /**
404
399
  * The `insertBefore` function inserts a new value before an existing value in a singly linked list.
405
400
  * @param {E | SinglyLinkedListNode<E>} existingValueOrNode - The existing value or node that you want to insert the