min-heap-typed 1.54.3 → 2.0.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.
- package/dist/data-structures/base/iterable-element-base.d.ts +14 -40
- package/dist/data-structures/base/iterable-element-base.js +14 -11
- package/dist/data-structures/base/linear-base.d.ts +277 -0
- package/dist/data-structures/base/linear-base.js +552 -0
- package/dist/data-structures/binary-tree/avl-tree-multi-map.d.ts +12 -8
- package/dist/data-structures/binary-tree/avl-tree-multi-map.js +50 -37
- package/dist/data-structures/binary-tree/avl-tree.d.ts +64 -0
- package/dist/data-structures/binary-tree/avl-tree.js +64 -0
- package/dist/data-structures/binary-tree/binary-tree.js +5 -5
- package/dist/data-structures/binary-tree/bst.js +11 -11
- package/dist/data-structures/binary-tree/tree-multi-map.d.ts +175 -14
- package/dist/data-structures/binary-tree/tree-multi-map.js +210 -40
- package/dist/data-structures/graph/abstract-graph.js +2 -2
- package/dist/data-structures/heap/heap.d.ts +3 -11
- package/dist/data-structures/heap/heap.js +0 -10
- package/dist/data-structures/heap/max-heap.d.ts +2 -2
- package/dist/data-structures/heap/min-heap.d.ts +2 -2
- package/dist/data-structures/linked-list/doubly-linked-list.d.ts +65 -94
- package/dist/data-structures/linked-list/doubly-linked-list.js +131 -146
- package/dist/data-structures/linked-list/singly-linked-list.d.ts +79 -75
- package/dist/data-structures/linked-list/singly-linked-list.js +217 -169
- package/dist/data-structures/priority-queue/max-priority-queue.d.ts +2 -2
- package/dist/data-structures/priority-queue/min-priority-queue.d.ts +2 -2
- package/dist/data-structures/priority-queue/priority-queue.d.ts +2 -2
- package/dist/data-structures/queue/deque.d.ts +130 -91
- package/dist/data-structures/queue/deque.js +269 -169
- package/dist/data-structures/queue/queue.d.ts +84 -40
- package/dist/data-structures/queue/queue.js +134 -50
- package/dist/data-structures/stack/stack.d.ts +3 -11
- package/dist/data-structures/stack/stack.js +0 -10
- package/dist/data-structures/trie/trie.d.ts +4 -3
- package/dist/data-structures/trie/trie.js +3 -0
- package/dist/types/data-structures/base/base.d.ts +9 -4
- package/dist/types/data-structures/binary-tree/avl-tree-multi-map.d.ts +1 -1
- package/dist/types/data-structures/binary-tree/tree-multi-map.d.ts +1 -1
- package/dist/types/data-structures/linked-list/doubly-linked-list.d.ts +2 -2
- package/dist/types/data-structures/linked-list/singly-linked-list.d.ts +2 -2
- package/dist/types/data-structures/queue/deque.d.ts +2 -3
- package/dist/types/data-structures/queue/queue.d.ts +2 -2
- package/package.json +2 -2
- package/src/data-structures/base/iterable-element-base.ts +29 -20
- package/src/data-structures/base/linear-base.ts +649 -0
- package/src/data-structures/binary-tree/avl-tree-multi-map.ts +51 -36
- package/src/data-structures/binary-tree/avl-tree.ts +64 -0
- package/src/data-structures/binary-tree/binary-tree.ts +5 -5
- package/src/data-structures/binary-tree/bst.ts +9 -9
- package/src/data-structures/binary-tree/tree-multi-map.ts +214 -40
- package/src/data-structures/graph/abstract-graph.ts +2 -2
- package/src/data-structures/heap/heap.ts +3 -14
- package/src/data-structures/heap/max-heap.ts +2 -2
- package/src/data-structures/heap/min-heap.ts +2 -2
- package/src/data-structures/linked-list/doubly-linked-list.ts +144 -160
- package/src/data-structures/linked-list/singly-linked-list.ts +241 -185
- package/src/data-structures/priority-queue/max-priority-queue.ts +2 -5
- package/src/data-structures/priority-queue/min-priority-queue.ts +2 -5
- package/src/data-structures/priority-queue/priority-queue.ts +2 -2
- package/src/data-structures/queue/deque.ts +286 -183
- package/src/data-structures/queue/queue.ts +149 -63
- package/src/data-structures/stack/stack.ts +3 -18
- package/src/data-structures/trie/trie.ts +7 -3
- package/src/types/data-structures/base/base.ts +17 -8
- package/src/types/data-structures/binary-tree/avl-tree-multi-map.ts +1 -1
- package/src/types/data-structures/binary-tree/tree-multi-map.ts +1 -1
- package/src/types/data-structures/linked-list/doubly-linked-list.ts +2 -2
- package/src/types/data-structures/linked-list/singly-linked-list.ts +2 -2
- package/src/types/data-structures/queue/deque.ts +2 -3
- package/src/types/data-structures/queue/queue.ts +2 -2
|
@@ -6,75 +6,36 @@
|
|
|
6
6
|
* @license MIT License
|
|
7
7
|
*/
|
|
8
8
|
import type { ElementCallback, SinglyLinkedListOptions } from '../../types';
|
|
9
|
-
import {
|
|
10
|
-
export declare class SinglyLinkedListNode<E = any> {
|
|
9
|
+
import { LinearLinkedBase, LinkedListNode } from '../base/linear-base';
|
|
10
|
+
export declare class SinglyLinkedListNode<E = any> extends LinkedListNode<E> {
|
|
11
11
|
/**
|
|
12
12
|
* The constructor function initializes an instance of a class with a given value and sets the next property to undefined.
|
|
13
13
|
* @param {E} value - The "value" parameter is of type E, which means it can be any data type. It represents the value that
|
|
14
14
|
* will be stored in the node of a linked list.
|
|
15
15
|
*/
|
|
16
16
|
constructor(value: E);
|
|
17
|
-
protected _value: E;
|
|
18
|
-
/**
|
|
19
|
-
* The function returns the value of a protected variable.
|
|
20
|
-
* @returns The value of the variable `_value` is being returned.
|
|
21
|
-
*/
|
|
22
|
-
get value(): E;
|
|
23
|
-
/**
|
|
24
|
-
* The above function sets the value of a variable.
|
|
25
|
-
* @param {E} value - The parameter "value" is of type E, which means it can be any type.
|
|
26
|
-
*/
|
|
27
|
-
set value(value: E);
|
|
28
17
|
protected _next: SinglyLinkedListNode<E> | undefined;
|
|
29
|
-
/**
|
|
30
|
-
* The `next` function returns the next node in a singly linked list.
|
|
31
|
-
* @returns The `next` property is being returned. It can be either a `SinglyLinkedListNode<E>`
|
|
32
|
-
* object or `undefined`.
|
|
33
|
-
*/
|
|
34
18
|
get next(): SinglyLinkedListNode<E> | undefined;
|
|
35
|
-
/**
|
|
36
|
-
* The "next" property of a SinglyLinkedListNode is set to the provided value.
|
|
37
|
-
* @param {SinglyLinkedListNode<E> | undefined} value - The `value` parameter is of type
|
|
38
|
-
* `SinglyLinkedListNode<E> | undefined`. This means that it can accept either a
|
|
39
|
-
* `SinglyLinkedListNode` object or `undefined` as its value.
|
|
40
|
-
*/
|
|
41
19
|
set next(value: SinglyLinkedListNode<E> | undefined);
|
|
42
20
|
}
|
|
43
21
|
/**
|
|
22
|
+
* 1. Node Structure: Each node contains three parts: a data field, a pointer (or reference) to the previous node, and a pointer to the next node. This structure allows traversal of the linked list in both directions.
|
|
23
|
+
* 2. Bidirectional Traversal: Unlike doubly linked lists, singly linked lists can be easily traversed forwards but not backwards.
|
|
24
|
+
* 3. No Centralized Index: Unlike arrays, elements in a linked list are not stored contiguously, so there is no centralized index. Accessing elements in a linked list typically requires traversing from the head or tail node.
|
|
25
|
+
* 4. High Efficiency in Insertion and Deletion: Adding or removing elements in a linked list does not require moving other elements, making these operations more efficient than in arrays.
|
|
26
|
+
* Caution: Although our linked list classes provide methods such as at, setAt, addAt, and indexOf that are based on array indices, their time complexity, like that of the native Array.lastIndexOf, is 𝑂(𝑛). If you need to use these methods frequently, you might want to consider other data structures, such as Deque or Queue (designed for random access). Similarly, since the native Array.shift method has a time complexity of 𝑂(𝑛), using an array to simulate a queue can be inefficient. In such cases, you should use Queue or Deque, as these data structures leverage deferred array rearrangement, effectively reducing the average time complexity to 𝑂(1).
|
|
44
27
|
*
|
|
45
28
|
*/
|
|
46
|
-
export declare class SinglyLinkedList<E = any, R = any> extends
|
|
29
|
+
export declare class SinglyLinkedList<E = any, R = any> extends LinearLinkedBase<E, R, SinglyLinkedListNode<E>> {
|
|
47
30
|
constructor(elements?: Iterable<E> | Iterable<R> | Iterable<SinglyLinkedListNode<E>>, options?: SinglyLinkedListOptions<E, R>);
|
|
48
31
|
protected _head: SinglyLinkedListNode<E> | undefined;
|
|
49
|
-
/**
|
|
50
|
-
* The `head` function returns the first node of a singly linked list.
|
|
51
|
-
* @returns The method is returning either a SinglyLinkedListNode object or undefined.
|
|
52
|
-
*/
|
|
53
32
|
get head(): SinglyLinkedListNode<E> | undefined;
|
|
54
33
|
protected _tail: SinglyLinkedListNode<E> | undefined;
|
|
55
|
-
/**
|
|
56
|
-
* The `tail` function returns the last node of a singly linked list.
|
|
57
|
-
* @returns The method is returning either a SinglyLinkedListNode object or undefined.
|
|
58
|
-
*/
|
|
59
34
|
get tail(): SinglyLinkedListNode<E> | undefined;
|
|
60
|
-
/**
|
|
61
|
-
* The above function returns the value of the first element in a linked list, or undefined if the
|
|
62
|
-
* list is empty.
|
|
63
|
-
* @returns The value of the first node in the linked list, or undefined if the linked list is empty.
|
|
64
|
-
*/
|
|
65
35
|
get first(): E | undefined;
|
|
66
|
-
/**
|
|
67
|
-
* The function returns the value of the last element in a linked list, or undefined if the list is
|
|
68
|
-
* empty.
|
|
69
|
-
* @returns The value of the last node in the linked list, or undefined if the linked list is empty.
|
|
70
|
-
*/
|
|
71
36
|
get last(): E | undefined;
|
|
72
|
-
protected
|
|
73
|
-
|
|
74
|
-
* The function returns the size of an object.
|
|
75
|
-
* @returns The size of the object, which is a number.
|
|
76
|
-
*/
|
|
77
|
-
get size(): number;
|
|
37
|
+
protected _length: number;
|
|
38
|
+
get length(): number;
|
|
78
39
|
/**
|
|
79
40
|
* Time Complexity: O(n)
|
|
80
41
|
* Space Complexity: O(n)
|
|
@@ -210,7 +171,7 @@ export declare class SinglyLinkedList<E = any, R = any> extends IterableElementB
|
|
|
210
171
|
* @returns The method `deleteAt` returns the value of the node that was deleted, or `undefined` if the index is out of
|
|
211
172
|
* bounds.
|
|
212
173
|
*/
|
|
213
|
-
deleteAt(index: number):
|
|
174
|
+
deleteAt(index: number): E | undefined;
|
|
214
175
|
/**
|
|
215
176
|
* Time Complexity: O(n)
|
|
216
177
|
* Space Complexity: O(1)
|
|
@@ -238,6 +199,21 @@ export declare class SinglyLinkedList<E = any, R = any> extends IterableElementB
|
|
|
238
199
|
* successfully added at the specified index, and `false` if the index is out of bounds.
|
|
239
200
|
*/
|
|
240
201
|
addAt(index: number, newElementOrNode: E | SinglyLinkedListNode<E>): boolean;
|
|
202
|
+
/**
|
|
203
|
+
* Time Complexity: O(n)
|
|
204
|
+
* Space Complexity: O(1)
|
|
205
|
+
*
|
|
206
|
+
* The function setAt(index, value) updates the value at a specified index in a data structure if the
|
|
207
|
+
* index exists.
|
|
208
|
+
* @param {number} index - The `index` parameter in the `setAt` method refers to the position in the
|
|
209
|
+
* data structure where you want to set a new value.
|
|
210
|
+
* @param {E} value - The `value` parameter in the `setAt` method represents the new value that you
|
|
211
|
+
* want to set at the specified index in the data structure.
|
|
212
|
+
* @returns The `setAt` method returns a boolean value - `true` if the value at the specified index
|
|
213
|
+
* is successfully updated, and `false` if the index is out of bounds (i.e., the node at that index
|
|
214
|
+
* does not exist).
|
|
215
|
+
*/
|
|
216
|
+
setAt(index: number, value: E): boolean;
|
|
241
217
|
/**
|
|
242
218
|
* Time Complexity: O(1)
|
|
243
219
|
* Space Complexity: O(1)
|
|
@@ -254,14 +230,6 @@ export declare class SinglyLinkedList<E = any, R = any> extends IterableElementB
|
|
|
254
230
|
* The `clear` function resets the linked list by setting the head, tail, and length to undefined and 0 respectively.
|
|
255
231
|
*/
|
|
256
232
|
clear(): void;
|
|
257
|
-
/**
|
|
258
|
-
* Time Complexity: O(n)
|
|
259
|
-
* Space Complexity: O(n)
|
|
260
|
-
*
|
|
261
|
-
* The `toArray` function converts a linked list into an array.
|
|
262
|
-
* @returns The `toArray()` method is returning an array of type `E[]`.
|
|
263
|
-
*/
|
|
264
|
-
toArray(): E[];
|
|
265
233
|
/**
|
|
266
234
|
* Time Complexity: O(n)
|
|
267
235
|
* Space Complexity: O(1)
|
|
@@ -270,20 +238,6 @@ export declare class SinglyLinkedList<E = any, R = any> extends IterableElementB
|
|
|
270
238
|
* @returns The reverse() method does not return anything. It has a return type of void.
|
|
271
239
|
*/
|
|
272
240
|
reverse(): this;
|
|
273
|
-
/**
|
|
274
|
-
* Time Complexity: O(n)
|
|
275
|
-
* Space Complexity: O(1)
|
|
276
|
-
*
|
|
277
|
-
* The `indexOf` function in TypeScript searches for a specific element or node in a singly linked
|
|
278
|
-
* list and returns its index if found.
|
|
279
|
-
* @param {E | SinglyLinkedListNode<E> | ((node: SinglyLinkedListNode<E>) => boolean)} elementNodeOrPredicate
|
|
280
|
-
* elementNodeOrPredicate - The `elementNodeOrPredicate` parameter in the `indexOf` method can be one
|
|
281
|
-
* of the following types:
|
|
282
|
-
* @returns The `indexOf` method returns the index of the first occurrence of the element that
|
|
283
|
-
* matches the provided predicate in the singly linked list. If no matching element is found, it
|
|
284
|
-
* returns -1.
|
|
285
|
-
*/
|
|
286
|
-
indexOf(elementNodeOrPredicate: E | SinglyLinkedListNode<E> | ((node: SinglyLinkedListNode<E>) => boolean)): number;
|
|
287
241
|
/**
|
|
288
242
|
* Time Complexity: O(n)
|
|
289
243
|
* Space Complexity: O(1)
|
|
@@ -332,6 +286,26 @@ export declare class SinglyLinkedList<E = any, R = any> extends IterableElementB
|
|
|
332
286
|
* was not found.
|
|
333
287
|
*/
|
|
334
288
|
addAfter(existingElementOrNode: E | SinglyLinkedListNode<E>, newElementOrNode: E | SinglyLinkedListNode<E>): boolean;
|
|
289
|
+
/**
|
|
290
|
+
* Time Complexity: O(n)
|
|
291
|
+
* Space Complexity: O(1)
|
|
292
|
+
*
|
|
293
|
+
* The function `splice` in TypeScript overrides the default behavior to remove and insert elements
|
|
294
|
+
* in a singly linked list while handling boundary cases.
|
|
295
|
+
* @param {number} start - The `start` parameter in the `splice` method indicates the index at which
|
|
296
|
+
* to start modifying the list. It specifies the position where elements will be added or removed.
|
|
297
|
+
* @param {number} [deleteCount=0] - The `deleteCount` parameter in the `splice` method specifies the
|
|
298
|
+
* number of elements to remove from the array starting at the specified `start` index. If
|
|
299
|
+
* `deleteCount` is not provided, it defaults to 0, meaning no elements will be removed but new
|
|
300
|
+
* elements can still be inserted at
|
|
301
|
+
* @param {E[]} items - The `items` parameter in the `splice` method represents the elements to be
|
|
302
|
+
* inserted into the list at the specified `start` index. These elements will be inserted in place of
|
|
303
|
+
* the elements that are removed from the list. The `splice` method allows you to add new elements to
|
|
304
|
+
* the list while
|
|
305
|
+
* @returns The `splice` method is returning a `SinglyLinkedList` containing the elements that were
|
|
306
|
+
* removed from the original list during the splice operation.
|
|
307
|
+
*/
|
|
308
|
+
splice(start: number, deleteCount?: number, ...items: E[]): this;
|
|
335
309
|
/**
|
|
336
310
|
* Time Complexity: O(n)
|
|
337
311
|
* Space Complexity: O(1)
|
|
@@ -353,7 +327,7 @@ export declare class SinglyLinkedList<E = any, R = any> extends IterableElementB
|
|
|
353
327
|
* @returns The `clone()` method is returning a new instance of the `SinglyLinkedList` class, which
|
|
354
328
|
* is a clone of the original list.
|
|
355
329
|
*/
|
|
356
|
-
clone():
|
|
330
|
+
clone(): this;
|
|
357
331
|
/**
|
|
358
332
|
* Time Complexity: O(n)
|
|
359
333
|
* Space Complexity: O(n)
|
|
@@ -371,7 +345,7 @@ export declare class SinglyLinkedList<E = any, R = any> extends IterableElementB
|
|
|
371
345
|
* @returns The `filter` method is returning a new `SinglyLinkedList` object that contains the
|
|
372
346
|
* elements that pass the filter condition specified by the `callback` function.
|
|
373
347
|
*/
|
|
374
|
-
filter(callback: ElementCallback<E, R, boolean
|
|
348
|
+
filter(callback: ElementCallback<E, R, boolean>, thisArg?: any): SinglyLinkedList<E, R>;
|
|
375
349
|
/**
|
|
376
350
|
* Time Complexity: O(n)
|
|
377
351
|
* Space Complexity: O(n)
|
|
@@ -392,11 +366,31 @@ export declare class SinglyLinkedList<E = any, R = any> extends IterableElementB
|
|
|
392
366
|
* value of
|
|
393
367
|
* @returns a new instance of the `SinglyLinkedList` class with the mapped elements.
|
|
394
368
|
*/
|
|
395
|
-
map<EM, RM>(callback: ElementCallback<E, R, EM
|
|
369
|
+
map<EM, RM>(callback: ElementCallback<E, R, EM>, toElementFn?: (rawElement: RM) => EM, thisArg?: any): SinglyLinkedList<EM, RM>;
|
|
370
|
+
/**
|
|
371
|
+
* The function `_createInstance` returns a new instance of `SinglyLinkedList` with the specified
|
|
372
|
+
* options.
|
|
373
|
+
* @param [options] - The `options` parameter in the `_createInstance` method is of type
|
|
374
|
+
* `SinglyLinkedListOptions<E, R>`, which is used to configure the behavior of the `SinglyLinkedList`
|
|
375
|
+
* instance being created. It is an optional parameter, meaning it can be omitted when calling the
|
|
376
|
+
* method.
|
|
377
|
+
* @returns An instance of the `SinglyLinkedList` class with an empty array and the provided options
|
|
378
|
+
* is being returned.
|
|
379
|
+
*/
|
|
380
|
+
protected _createInstance(options?: SinglyLinkedListOptions<E, R>): this;
|
|
396
381
|
/**
|
|
397
382
|
* The function `_getIterator` returns an iterable iterator that yields the values of a linked list.
|
|
398
383
|
*/
|
|
399
384
|
protected _getIterator(): IterableIterator<E>;
|
|
385
|
+
/**
|
|
386
|
+
* The function returns an iterator that iterates over the elements of a collection in reverse order.
|
|
387
|
+
*/
|
|
388
|
+
protected _getReverseIterator(): IterableIterator<E>;
|
|
389
|
+
/**
|
|
390
|
+
* The function `_getNodeIterator` returns an iterator that iterates over the nodes of a singly
|
|
391
|
+
* linked list.
|
|
392
|
+
*/
|
|
393
|
+
protected _getNodeIterator(): IterableIterator<SinglyLinkedListNode<E>>;
|
|
400
394
|
/**
|
|
401
395
|
* The _isPredicate function in TypeScript checks if the input is a function that takes a
|
|
402
396
|
* SinglyLinkedListNode as an argument and returns a boolean.
|
|
@@ -427,4 +421,14 @@ export declare class SinglyLinkedList<E = any, R = any> extends IterableElementB
|
|
|
427
421
|
* a function is returned that checks if a given node's value is equal to the input
|
|
428
422
|
*/
|
|
429
423
|
protected _ensurePredicate(elementNodeOrPredicate: E | SinglyLinkedListNode<E> | ((node: SinglyLinkedListNode<E>) => boolean)): (node: SinglyLinkedListNode<E>) => boolean;
|
|
424
|
+
/**
|
|
425
|
+
* The function `_getPrevNode` returns the node before a given node in a singly linked list.
|
|
426
|
+
* @param node - The `node` parameter in the `_getPrevNode` method is a reference to a node in a
|
|
427
|
+
* singly linked list. The method is used to find the node that comes before the given node in the
|
|
428
|
+
* linked list.
|
|
429
|
+
* @returns The `_getPrevNode` method returns either the previous node of the input node in a singly
|
|
430
|
+
* linked list or `undefined` if the input node is the head of the list or if the input node is not
|
|
431
|
+
* found in the list.
|
|
432
|
+
*/
|
|
433
|
+
protected _getPrevNode(node: SinglyLinkedListNode<E>): SinglyLinkedListNode<E> | undefined;
|
|
430
434
|
}
|