data-structure-typed 1.50.0 → 1.50.2
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/CHANGELOG.md +2 -1
- package/README.md +204 -212
- package/benchmark/report.html +37 -1
- package/benchmark/report.json +370 -22
- package/dist/cjs/data-structures/base/iterable-base.d.ts +114 -9
- package/dist/cjs/data-structures/base/iterable-base.js +143 -7
- package/dist/cjs/data-structures/base/iterable-base.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/avl-tree.d.ts +43 -46
- package/dist/cjs/data-structures/binary-tree/avl-tree.js +68 -71
- package/dist/cjs/data-structures/binary-tree/avl-tree.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/binary-tree.d.ts +244 -199
- package/dist/cjs/data-structures/binary-tree/binary-tree.js +484 -376
- package/dist/cjs/data-structures/binary-tree/binary-tree.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/bst.d.ts +54 -74
- package/dist/cjs/data-structures/binary-tree/bst.js +30 -71
- package/dist/cjs/data-structures/binary-tree/bst.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/rb-tree.d.ts +78 -60
- package/dist/cjs/data-structures/binary-tree/rb-tree.js +84 -89
- package/dist/cjs/data-structures/binary-tree/rb-tree.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/tree-multimap.d.ts +37 -56
- package/dist/cjs/data-structures/binary-tree/tree-multimap.js +64 -85
- package/dist/cjs/data-structures/binary-tree/tree-multimap.js.map +1 -1
- package/dist/cjs/data-structures/graph/abstract-graph.d.ts +1 -0
- package/dist/cjs/data-structures/graph/abstract-graph.js +3 -0
- package/dist/cjs/data-structures/graph/abstract-graph.js.map +1 -1
- package/dist/cjs/data-structures/graph/directed-graph.d.ts +14 -0
- package/dist/cjs/data-structures/graph/directed-graph.js +26 -0
- package/dist/cjs/data-structures/graph/directed-graph.js.map +1 -1
- package/dist/cjs/data-structures/graph/map-graph.d.ts +8 -0
- package/dist/cjs/data-structures/graph/map-graph.js +14 -0
- package/dist/cjs/data-structures/graph/map-graph.js.map +1 -1
- package/dist/cjs/data-structures/graph/undirected-graph.d.ts +16 -0
- package/dist/cjs/data-structures/graph/undirected-graph.js +25 -0
- package/dist/cjs/data-structures/graph/undirected-graph.js.map +1 -1
- package/dist/cjs/data-structures/hash/hash-map.d.ts +121 -15
- package/dist/cjs/data-structures/hash/hash-map.js +160 -25
- package/dist/cjs/data-structures/hash/hash-map.js.map +1 -1
- package/dist/cjs/data-structures/heap/heap.d.ts +66 -6
- package/dist/cjs/data-structures/heap/heap.js +66 -6
- package/dist/cjs/data-structures/heap/heap.js.map +1 -1
- package/dist/cjs/data-structures/linked-list/doubly-linked-list.d.ts +67 -50
- package/dist/cjs/data-structures/linked-list/doubly-linked-list.js +70 -64
- package/dist/cjs/data-structures/linked-list/doubly-linked-list.js.map +1 -1
- package/dist/cjs/data-structures/linked-list/singly-linked-list.d.ts +128 -103
- package/dist/cjs/data-structures/linked-list/singly-linked-list.js +130 -112
- package/dist/cjs/data-structures/linked-list/singly-linked-list.js.map +1 -1
- package/dist/cjs/data-structures/linked-list/skip-linked-list.d.ts +63 -36
- package/dist/cjs/data-structures/linked-list/skip-linked-list.js +63 -36
- package/dist/cjs/data-structures/linked-list/skip-linked-list.js.map +1 -1
- package/dist/cjs/data-structures/matrix/matrix.d.ts +35 -4
- package/dist/cjs/data-structures/matrix/matrix.js +50 -11
- package/dist/cjs/data-structures/matrix/matrix.js.map +1 -1
- package/dist/cjs/data-structures/queue/deque.d.ts +49 -19
- package/dist/cjs/data-structures/queue/deque.js +101 -47
- package/dist/cjs/data-structures/queue/deque.js.map +1 -1
- package/dist/cjs/data-structures/queue/queue.d.ts +39 -5
- package/dist/cjs/data-structures/queue/queue.js +47 -5
- package/dist/cjs/data-structures/queue/queue.js.map +1 -1
- package/dist/cjs/data-structures/stack/stack.d.ts +16 -0
- package/dist/cjs/data-structures/stack/stack.js +22 -0
- package/dist/cjs/data-structures/stack/stack.js.map +1 -1
- package/dist/cjs/data-structures/trie/trie.d.ts +38 -1
- package/dist/cjs/data-structures/trie/trie.js +41 -0
- package/dist/cjs/data-structures/trie/trie.js.map +1 -1
- package/dist/cjs/types/data-structures/binary-tree/binary-tree.d.ts +1 -1
- package/dist/cjs/types/data-structures/hash/hash-map.d.ts +4 -3
- package/dist/cjs/types/utils/utils.d.ts +1 -0
- package/dist/mjs/data-structures/base/iterable-base.d.ts +114 -9
- package/dist/mjs/data-structures/base/iterable-base.js +143 -7
- package/dist/mjs/data-structures/binary-tree/avl-tree.d.ts +43 -46
- package/dist/mjs/data-structures/binary-tree/avl-tree.js +68 -71
- package/dist/mjs/data-structures/binary-tree/binary-tree.d.ts +244 -199
- package/dist/mjs/data-structures/binary-tree/binary-tree.js +483 -375
- package/dist/mjs/data-structures/binary-tree/bst.d.ts +54 -74
- package/dist/mjs/data-structures/binary-tree/bst.js +30 -71
- package/dist/mjs/data-structures/binary-tree/rb-tree.d.ts +78 -60
- package/dist/mjs/data-structures/binary-tree/rb-tree.js +84 -89
- package/dist/mjs/data-structures/binary-tree/tree-multimap.d.ts +37 -56
- package/dist/mjs/data-structures/binary-tree/tree-multimap.js +64 -85
- package/dist/mjs/data-structures/graph/abstract-graph.d.ts +1 -0
- package/dist/mjs/data-structures/graph/abstract-graph.js +3 -0
- package/dist/mjs/data-structures/graph/directed-graph.d.ts +14 -0
- package/dist/mjs/data-structures/graph/directed-graph.js +26 -0
- package/dist/mjs/data-structures/graph/map-graph.d.ts +8 -0
- package/dist/mjs/data-structures/graph/map-graph.js +14 -0
- package/dist/mjs/data-structures/graph/undirected-graph.d.ts +16 -0
- package/dist/mjs/data-structures/graph/undirected-graph.js +25 -0
- package/dist/mjs/data-structures/hash/hash-map.d.ts +121 -15
- package/dist/mjs/data-structures/hash/hash-map.js +160 -25
- package/dist/mjs/data-structures/heap/heap.d.ts +66 -6
- package/dist/mjs/data-structures/heap/heap.js +66 -6
- package/dist/mjs/data-structures/linked-list/doubly-linked-list.d.ts +67 -50
- package/dist/mjs/data-structures/linked-list/doubly-linked-list.js +70 -64
- package/dist/mjs/data-structures/linked-list/singly-linked-list.d.ts +128 -103
- package/dist/mjs/data-structures/linked-list/singly-linked-list.js +130 -112
- package/dist/mjs/data-structures/linked-list/skip-linked-list.d.ts +63 -36
- package/dist/mjs/data-structures/linked-list/skip-linked-list.js +63 -36
- package/dist/mjs/data-structures/matrix/matrix.d.ts +35 -4
- package/dist/mjs/data-structures/matrix/matrix.js +50 -11
- package/dist/mjs/data-structures/queue/deque.d.ts +49 -19
- package/dist/mjs/data-structures/queue/deque.js +101 -47
- package/dist/mjs/data-structures/queue/queue.d.ts +39 -5
- package/dist/mjs/data-structures/queue/queue.js +47 -5
- package/dist/mjs/data-structures/stack/stack.d.ts +16 -0
- package/dist/mjs/data-structures/stack/stack.js +22 -0
- package/dist/mjs/data-structures/trie/trie.d.ts +38 -1
- package/dist/mjs/data-structures/trie/trie.js +41 -0
- package/dist/mjs/types/data-structures/binary-tree/binary-tree.d.ts +1 -1
- package/dist/mjs/types/data-structures/hash/hash-map.d.ts +4 -3
- package/dist/mjs/types/utils/utils.d.ts +1 -0
- package/dist/umd/data-structure-typed.js +1730 -1042
- package/dist/umd/data-structure-typed.min.js +3 -3
- package/dist/umd/data-structure-typed.min.js.map +1 -1
- package/package.json +16 -40
- package/src/data-structures/base/iterable-base.ts +172 -19
- package/src/data-structures/binary-tree/avl-tree.ts +97 -97
- package/src/data-structures/binary-tree/binary-tree.ts +674 -671
- package/src/data-structures/binary-tree/bst.ts +89 -131
- package/src/data-structures/binary-tree/rb-tree.ts +127 -155
- package/src/data-structures/binary-tree/tree-multimap.ts +96 -112
- package/src/data-structures/graph/abstract-graph.ts +4 -0
- package/src/data-structures/graph/directed-graph.ts +30 -0
- package/src/data-structures/graph/map-graph.ts +15 -0
- package/src/data-structures/graph/undirected-graph.ts +28 -0
- package/src/data-structures/hash/hash-map.ts +175 -34
- package/src/data-structures/heap/heap.ts +66 -6
- package/src/data-structures/linked-list/doubly-linked-list.ts +72 -66
- package/src/data-structures/linked-list/singly-linked-list.ts +132 -114
- package/src/data-structures/linked-list/skip-linked-list.ts +63 -37
- package/src/data-structures/matrix/matrix.ts +52 -12
- package/src/data-structures/queue/deque.ts +108 -49
- package/src/data-structures/queue/queue.ts +51 -5
- package/src/data-structures/stack/stack.ts +24 -0
- package/src/data-structures/trie/trie.ts +45 -1
- package/src/types/data-structures/binary-tree/binary-tree.ts +1 -1
- package/src/types/data-structures/hash/hash-map.ts +4 -3
- package/src/types/utils/utils.ts +2 -0
- package/test/performance/data-structures/graph/directed-graph.test.ts +3 -3
- package/test/performance/data-structures/queue/deque.test.ts +26 -25
- package/test/unit/data-structures/binary-tree/avl-tree.test.ts +37 -0
- package/test/unit/data-structures/binary-tree/binary-tree.test.ts +46 -17
- package/test/unit/data-structures/binary-tree/bst.test.ts +65 -1
- package/test/unit/data-structures/binary-tree/rb-tree.test.ts +38 -1
- package/test/unit/data-structures/binary-tree/tree-multimap.test.ts +37 -32
- package/test/unit/data-structures/graph/abstract-graph.test.ts +8 -0
- package/test/unit/data-structures/graph/directed-graph.test.ts +249 -0
- package/test/unit/data-structures/hash/hash-map.test.ts +376 -353
- package/test/unit/data-structures/heap/heap.test.ts +18 -1
- package/test/unit/data-structures/linked-list/doubly-linked-list.test.ts +24 -5
- package/test/unit/data-structures/linked-list/singly-linked-list.test.ts +20 -2
- package/test/unit/data-structures/linked-list/skip-list.test.ts +1 -1
- package/test/unit/data-structures/queue/deque.test.ts +71 -10
- package/test/unit/data-structures/queue/queue.test.ts +23 -6
- package/test/unit/data-structures/stack/stack.test.ts +17 -0
- package/test/unit/data-structures/trie/trie.test.ts +17 -0
- package/test/unit/unrestricted-interconversion.test.ts +143 -10
|
@@ -26,21 +26,38 @@ export declare class DoublyLinkedListNode<E = any> {
|
|
|
26
26
|
*/
|
|
27
27
|
export declare class DoublyLinkedList<E = any> extends IterableElementBase<E> {
|
|
28
28
|
/**
|
|
29
|
-
* The constructor initializes
|
|
29
|
+
* The constructor initializes a linked list with optional elements.
|
|
30
|
+
* @param elements - The `elements` parameter is an optional iterable object that contains the
|
|
31
|
+
* initial elements to be added to the data structure. It defaults to an empty array if no elements
|
|
32
|
+
* are provided.
|
|
30
33
|
*/
|
|
31
34
|
constructor(elements?: Iterable<E>);
|
|
32
35
|
protected _head: DoublyLinkedListNode<E> | undefined;
|
|
36
|
+
/**
|
|
37
|
+
* The `head` function returns the first node of a doubly linked list.
|
|
38
|
+
* @returns The method `getHead()` returns either a `DoublyLinkedListNode<E>` object or `undefined`.
|
|
39
|
+
*/
|
|
33
40
|
get head(): DoublyLinkedListNode<E> | undefined;
|
|
34
41
|
protected _tail: DoublyLinkedListNode<E> | undefined;
|
|
42
|
+
/**
|
|
43
|
+
* The `tail` function returns the last node of a doubly linked list.
|
|
44
|
+
* @returns The `get tail()` method is returning either a `DoublyLinkedListNode<E>` object or
|
|
45
|
+
* `undefined`.
|
|
46
|
+
*/
|
|
35
47
|
get tail(): DoublyLinkedListNode<E> | undefined;
|
|
36
48
|
protected _size: number;
|
|
49
|
+
/**
|
|
50
|
+
* The function returns the size of an object.
|
|
51
|
+
* @returns The size of the object, which is a number.
|
|
52
|
+
*/
|
|
37
53
|
get size(): number;
|
|
38
54
|
/**
|
|
39
|
-
* Time Complexity: O(n)
|
|
55
|
+
* Time Complexity: O(n)
|
|
40
56
|
* Space Complexity: O(n)
|
|
57
|
+
* where n is the number of elements in the linked list.
|
|
41
58
|
*/
|
|
42
59
|
/**
|
|
43
|
-
* Time Complexity: O(n)
|
|
60
|
+
* Time Complexity: O(n)
|
|
44
61
|
* Space Complexity: O(1)
|
|
45
62
|
*
|
|
46
63
|
* The `get first` function returns the first node in a doubly linked list, or undefined if the list is empty.
|
|
@@ -52,7 +69,7 @@ export declare class DoublyLinkedList<E = any> extends IterableElementBase<E> {
|
|
|
52
69
|
* Space Complexity: O(1)
|
|
53
70
|
*/
|
|
54
71
|
/**
|
|
55
|
-
* Time Complexity: O(n)
|
|
72
|
+
* Time Complexity: O(n)
|
|
56
73
|
* Space Complexity: O(1)
|
|
57
74
|
*
|
|
58
75
|
* The `get last` function returns the last node in a doubly linked list, or undefined if the list is empty.
|
|
@@ -99,7 +116,7 @@ export declare class DoublyLinkedList<E = any> extends IterableElementBase<E> {
|
|
|
99
116
|
*/
|
|
100
117
|
pop(): E | undefined;
|
|
101
118
|
/**
|
|
102
|
-
* Time Complexity: O(n)
|
|
119
|
+
* Time Complexity: O(n)
|
|
103
120
|
* Space Complexity: O(1)
|
|
104
121
|
*/
|
|
105
122
|
/**
|
|
@@ -112,7 +129,7 @@ export declare class DoublyLinkedList<E = any> extends IterableElementBase<E> {
|
|
|
112
129
|
*/
|
|
113
130
|
shift(): E | undefined;
|
|
114
131
|
/**
|
|
115
|
-
* Time Complexity: O(n)
|
|
132
|
+
* Time Complexity: O(n)
|
|
116
133
|
* Space Complexity: O(1)
|
|
117
134
|
*/
|
|
118
135
|
/**
|
|
@@ -125,26 +142,26 @@ export declare class DoublyLinkedList<E = any> extends IterableElementBase<E> {
|
|
|
125
142
|
*/
|
|
126
143
|
unshift(value: E): boolean;
|
|
127
144
|
/**
|
|
128
|
-
* Time Complexity: O(n)
|
|
145
|
+
* Time Complexity: O(n)
|
|
129
146
|
* Space Complexity: O(1)
|
|
130
147
|
*/
|
|
131
148
|
/**
|
|
132
|
-
* Time Complexity: O(n)
|
|
149
|
+
* Time Complexity: O(n)
|
|
133
150
|
* Space Complexity: O(1)
|
|
134
151
|
*
|
|
135
|
-
* The `
|
|
152
|
+
* The `at` function returns the value at a specified index in a linked list, or undefined if the index is out of bounds.
|
|
136
153
|
* @param {number} index - The index parameter is a number that represents the position of the element we want to
|
|
137
154
|
* retrieve from the list.
|
|
138
155
|
* @returns The method is returning the value at the specified index in the linked list. If the index is out of bounds
|
|
139
156
|
* or the linked list is empty, it will return undefined.
|
|
140
157
|
*/
|
|
141
|
-
|
|
158
|
+
at(index: number): E | undefined;
|
|
142
159
|
/**
|
|
143
|
-
* Time Complexity: O(n)
|
|
160
|
+
* Time Complexity: O(n)
|
|
144
161
|
* Space Complexity: O(1)
|
|
145
162
|
*/
|
|
146
163
|
/**
|
|
147
|
-
* Time Complexity: O(n)
|
|
164
|
+
* Time Complexity: O(n)
|
|
148
165
|
* Space Complexity: O(1)
|
|
149
166
|
*
|
|
150
167
|
* The function `getNodeAt` returns the node at a given index in a doubly linked list, or undefined if the index is out of
|
|
@@ -156,11 +173,11 @@ export declare class DoublyLinkedList<E = any> extends IterableElementBase<E> {
|
|
|
156
173
|
*/
|
|
157
174
|
getNodeAt(index: number): DoublyLinkedListNode<E> | undefined;
|
|
158
175
|
/**
|
|
159
|
-
* Time Complexity: O(n)
|
|
176
|
+
* Time Complexity: O(n)
|
|
160
177
|
* Space Complexity: O(1)
|
|
161
178
|
*/
|
|
162
179
|
/**
|
|
163
|
-
* Time Complexity: O(n)
|
|
180
|
+
* Time Complexity: O(n)
|
|
164
181
|
* Space Complexity: O(1)
|
|
165
182
|
*
|
|
166
183
|
* The function `findNodeByValue` searches for a node with a specific value in a doubly linked list and returns the
|
|
@@ -171,11 +188,11 @@ export declare class DoublyLinkedList<E = any> extends IterableElementBase<E> {
|
|
|
171
188
|
*/
|
|
172
189
|
getNode(value: E | undefined): DoublyLinkedListNode<E> | undefined;
|
|
173
190
|
/**
|
|
174
|
-
* Time Complexity: O(n)
|
|
191
|
+
* Time Complexity: O(n)
|
|
175
192
|
* Space Complexity: O(1)
|
|
176
193
|
*/
|
|
177
194
|
/**
|
|
178
|
-
* Time Complexity: O(n)
|
|
195
|
+
* Time Complexity: O(n)
|
|
179
196
|
* Space Complexity: O(1)
|
|
180
197
|
*
|
|
181
198
|
* The `insert` function inserts a value at a specified index in a doubly linked list.
|
|
@@ -188,11 +205,12 @@ export declare class DoublyLinkedList<E = any> extends IterableElementBase<E> {
|
|
|
188
205
|
*/
|
|
189
206
|
addAt(index: number, value: E): boolean;
|
|
190
207
|
/**
|
|
191
|
-
* Time Complexity: O(n)
|
|
208
|
+
* Time Complexity: O(n)
|
|
192
209
|
* Space Complexity: O(1)
|
|
210
|
+
* where n is the number of elements in the linked list.
|
|
193
211
|
*/
|
|
194
212
|
/**
|
|
195
|
-
* Time Complexity: O(n)
|
|
213
|
+
* Time Complexity: O(n)
|
|
196
214
|
* Space Complexity: O(1)
|
|
197
215
|
*
|
|
198
216
|
* The `addBefore` function inserts a new value before an existing value or node in a doubly linked list.
|
|
@@ -206,11 +224,11 @@ export declare class DoublyLinkedList<E = any> extends IterableElementBase<E> {
|
|
|
206
224
|
*/
|
|
207
225
|
addBefore(existingValueOrNode: E | DoublyLinkedListNode<E>, newValue: E): boolean;
|
|
208
226
|
/**
|
|
209
|
-
* Time Complexity: O(n)
|
|
227
|
+
* Time Complexity: O(n)
|
|
210
228
|
* Space Complexity: O(1)
|
|
211
229
|
*/
|
|
212
230
|
/**
|
|
213
|
-
* Time Complexity: O(n)
|
|
231
|
+
* Time Complexity: O(n)
|
|
214
232
|
* Space Complexity: O(1)
|
|
215
233
|
*
|
|
216
234
|
* The `addAfter` function inserts a new node with a given value after an existing node in a doubly linked list.
|
|
@@ -223,7 +241,7 @@ export declare class DoublyLinkedList<E = any> extends IterableElementBase<E> {
|
|
|
223
241
|
*/
|
|
224
242
|
addAfter(existingValueOrNode: E | DoublyLinkedListNode<E>, newValue: E): boolean;
|
|
225
243
|
/**
|
|
226
|
-
* Time Complexity: O(n)
|
|
244
|
+
* Time Complexity: O(n)
|
|
227
245
|
* Space Complexity: O(1)
|
|
228
246
|
*
|
|
229
247
|
* The `deleteAt` function removes an element at a specified index from a linked list and returns the removed element.
|
|
@@ -234,7 +252,7 @@ export declare class DoublyLinkedList<E = any> extends IterableElementBase<E> {
|
|
|
234
252
|
*/
|
|
235
253
|
deleteAt(index: number): boolean;
|
|
236
254
|
/**
|
|
237
|
-
* Time Complexity: O(n)
|
|
255
|
+
* Time Complexity: O(n)
|
|
238
256
|
* Space Complexity: O(1)
|
|
239
257
|
*
|
|
240
258
|
* The `delete` function removes a node from a doubly linked list based on either the node itself or its value.
|
|
@@ -245,7 +263,7 @@ export declare class DoublyLinkedList<E = any> extends IterableElementBase<E> {
|
|
|
245
263
|
*/
|
|
246
264
|
delete(valOrNode: E | DoublyLinkedListNode<E> | undefined): boolean;
|
|
247
265
|
/**
|
|
248
|
-
* Time Complexity: O(
|
|
266
|
+
* Time Complexity: O(1)
|
|
249
267
|
* Space Complexity: O(1)
|
|
250
268
|
*/
|
|
251
269
|
/**
|
|
@@ -254,7 +272,7 @@ export declare class DoublyLinkedList<E = any> extends IterableElementBase<E> {
|
|
|
254
272
|
*/
|
|
255
273
|
isEmpty(): boolean;
|
|
256
274
|
/**
|
|
257
|
-
* Time Complexity: O(
|
|
275
|
+
* Time Complexity: O(1)
|
|
258
276
|
* Space Complexity: O(1)
|
|
259
277
|
*/
|
|
260
278
|
/**
|
|
@@ -262,26 +280,11 @@ export declare class DoublyLinkedList<E = any> extends IterableElementBase<E> {
|
|
|
262
280
|
*/
|
|
263
281
|
clear(): void;
|
|
264
282
|
/**
|
|
265
|
-
* Time Complexity: O(n)
|
|
266
|
-
* Space Complexity: O(1)
|
|
267
|
-
*/
|
|
268
|
-
/**
|
|
269
|
-
* Time Complexity: O(n), where n is the number of elements in the linked list.
|
|
270
|
-
* Space Complexity: O(1)
|
|
271
|
-
*
|
|
272
|
-
* The `find` function iterates through a linked list and returns the first element that satisfies a given condition.
|
|
273
|
-
* @param callback - A function that takes a value of type E as its parameter and returns a boolean value. This
|
|
274
|
-
* function is used to determine whether a particular value in the linked list satisfies a certain condition.
|
|
275
|
-
* @returns The method `find` returns the first element in the linked list that satisfies the condition specified by
|
|
276
|
-
* the callback function. If no element satisfies the condition, it returns `undefined`.
|
|
277
|
-
*/
|
|
278
|
-
find(callback: (value: E) => boolean): E | undefined;
|
|
279
|
-
/**
|
|
280
|
-
* Time Complexity: O(n), where n is the number of elements in the linked list.
|
|
283
|
+
* Time Complexity: O(n)
|
|
281
284
|
* Space Complexity: O(1)
|
|
282
285
|
*/
|
|
283
286
|
/**
|
|
284
|
-
* Time Complexity: O(n)
|
|
287
|
+
* Time Complexity: O(n)
|
|
285
288
|
* Space Complexity: O(1)
|
|
286
289
|
*
|
|
287
290
|
* The function returns the index of the first occurrence of a given value in a linked list.
|
|
@@ -292,11 +295,11 @@ export declare class DoublyLinkedList<E = any> extends IterableElementBase<E> {
|
|
|
292
295
|
*/
|
|
293
296
|
indexOf(value: E): number;
|
|
294
297
|
/**
|
|
295
|
-
* Time Complexity: O(n)
|
|
298
|
+
* Time Complexity: O(n)
|
|
296
299
|
* Space Complexity: O(n)
|
|
297
300
|
*/
|
|
298
301
|
/**
|
|
299
|
-
* Time Complexity: O(n)
|
|
302
|
+
* Time Complexity: O(n)
|
|
300
303
|
* Space Complexity: O(1)
|
|
301
304
|
*
|
|
302
305
|
* The `findBackward` function iterates through a linked list from the last node to the first node and returns the last
|
|
@@ -308,11 +311,11 @@ export declare class DoublyLinkedList<E = any> extends IterableElementBase<E> {
|
|
|
308
311
|
*/
|
|
309
312
|
findBackward(callback: (value: E) => boolean): E | undefined;
|
|
310
313
|
/**
|
|
311
|
-
* Time Complexity: O(n)
|
|
314
|
+
* Time Complexity: O(n)
|
|
312
315
|
* Space Complexity: O(n)
|
|
313
316
|
*/
|
|
314
317
|
/**
|
|
315
|
-
* Time Complexity: O(n)
|
|
318
|
+
* Time Complexity: O(n)
|
|
316
319
|
* Space Complexity: O(1)
|
|
317
320
|
*
|
|
318
321
|
* The `reverse` function reverses the order of the elements in a doubly linked list.
|
|
@@ -323,7 +326,7 @@ export declare class DoublyLinkedList<E = any> extends IterableElementBase<E> {
|
|
|
323
326
|
* Space Complexity: O(n)
|
|
324
327
|
*/
|
|
325
328
|
/**
|
|
326
|
-
* Time Complexity: O(n)
|
|
329
|
+
* Time Complexity: O(n)
|
|
327
330
|
* Space Complexity: O(n)
|
|
328
331
|
*
|
|
329
332
|
* The `toArray` function converts a linked list into an array.
|
|
@@ -331,17 +334,31 @@ export declare class DoublyLinkedList<E = any> extends IterableElementBase<E> {
|
|
|
331
334
|
*/
|
|
332
335
|
toArray(): E[];
|
|
333
336
|
/**
|
|
334
|
-
* Time Complexity: O(n)
|
|
337
|
+
* Time Complexity: O(n)
|
|
335
338
|
* Space Complexity: O(n)
|
|
336
339
|
*/
|
|
337
340
|
/**
|
|
338
|
-
* Time Complexity: O(n)
|
|
341
|
+
* Time Complexity: O(n)
|
|
339
342
|
* Space Complexity: O(n)
|
|
340
343
|
*
|
|
341
344
|
* The `toReversedArray` function converts a doubly linked list into an array in reverse order.
|
|
342
345
|
* @returns The `toReversedArray()` function returns an array of type `E[]`.
|
|
343
346
|
*/
|
|
344
347
|
toReversedArray(): E[];
|
|
348
|
+
/**
|
|
349
|
+
* Time Complexity: O(n)
|
|
350
|
+
* Space Complexity: O(n)
|
|
351
|
+
*/
|
|
352
|
+
/**
|
|
353
|
+
* Time Complexity: O(n)
|
|
354
|
+
* Space Complexity: O(n)
|
|
355
|
+
*
|
|
356
|
+
* The `clone` function creates a new instance of the `DoublyLinkedList` class with the same values
|
|
357
|
+
* as the original list.
|
|
358
|
+
* @returns The `clone()` method is returning a new instance of the `DoublyLinkedList` class, which
|
|
359
|
+
* is a copy of the original list.
|
|
360
|
+
*/
|
|
361
|
+
clone(): DoublyLinkedList<E>;
|
|
345
362
|
/**
|
|
346
363
|
* Time Complexity: O(1)
|
|
347
364
|
* Space Complexity: O(1)
|
|
@@ -412,7 +429,7 @@ export declare class DoublyLinkedList<E = any> extends IterableElementBase<E> {
|
|
|
412
429
|
*/
|
|
413
430
|
pollLast(): E | undefined;
|
|
414
431
|
/**
|
|
415
|
-
* Time Complexity: O(n)
|
|
432
|
+
* Time Complexity: O(n)
|
|
416
433
|
* Space Complexity: O(1)
|
|
417
434
|
*/
|
|
418
435
|
/**
|
|
@@ -425,7 +442,7 @@ export declare class DoublyLinkedList<E = any> extends IterableElementBase<E> {
|
|
|
425
442
|
*/
|
|
426
443
|
pollFirst(): E | undefined;
|
|
427
444
|
/**
|
|
428
|
-
* Time Complexity: O(n)
|
|
445
|
+
* Time Complexity: O(n)
|
|
429
446
|
* Space Complexity: O(1)
|
|
430
447
|
*/
|
|
431
448
|
/**
|
|
@@ -23,7 +23,10 @@ exports.DoublyLinkedListNode = DoublyLinkedListNode;
|
|
|
23
23
|
*/
|
|
24
24
|
class DoublyLinkedList extends base_1.IterableElementBase {
|
|
25
25
|
/**
|
|
26
|
-
* The constructor initializes
|
|
26
|
+
* The constructor initializes a linked list with optional elements.
|
|
27
|
+
* @param elements - The `elements` parameter is an optional iterable object that contains the
|
|
28
|
+
* initial elements to be added to the data structure. It defaults to an empty array if no elements
|
|
29
|
+
* are provided.
|
|
27
30
|
*/
|
|
28
31
|
constructor(elements = []) {
|
|
29
32
|
super();
|
|
@@ -36,21 +39,35 @@ class DoublyLinkedList extends base_1.IterableElementBase {
|
|
|
36
39
|
}
|
|
37
40
|
}
|
|
38
41
|
}
|
|
42
|
+
/**
|
|
43
|
+
* The `head` function returns the first node of a doubly linked list.
|
|
44
|
+
* @returns The method `getHead()` returns either a `DoublyLinkedListNode<E>` object or `undefined`.
|
|
45
|
+
*/
|
|
39
46
|
get head() {
|
|
40
47
|
return this._head;
|
|
41
48
|
}
|
|
49
|
+
/**
|
|
50
|
+
* The `tail` function returns the last node of a doubly linked list.
|
|
51
|
+
* @returns The `get tail()` method is returning either a `DoublyLinkedListNode<E>` object or
|
|
52
|
+
* `undefined`.
|
|
53
|
+
*/
|
|
42
54
|
get tail() {
|
|
43
55
|
return this._tail;
|
|
44
56
|
}
|
|
57
|
+
/**
|
|
58
|
+
* The function returns the size of an object.
|
|
59
|
+
* @returns The size of the object, which is a number.
|
|
60
|
+
*/
|
|
45
61
|
get size() {
|
|
46
62
|
return this._size;
|
|
47
63
|
}
|
|
48
64
|
/**
|
|
49
|
-
* Time Complexity: O(n)
|
|
65
|
+
* Time Complexity: O(n)
|
|
50
66
|
* Space Complexity: O(n)
|
|
67
|
+
* where n is the number of elements in the linked list.
|
|
51
68
|
*/
|
|
52
69
|
/**
|
|
53
|
-
* Time Complexity: O(n)
|
|
70
|
+
* Time Complexity: O(n)
|
|
54
71
|
* Space Complexity: O(1)
|
|
55
72
|
*
|
|
56
73
|
* The `get first` function returns the first node in a doubly linked list, or undefined if the list is empty.
|
|
@@ -65,7 +82,7 @@ class DoublyLinkedList extends base_1.IterableElementBase {
|
|
|
65
82
|
* Space Complexity: O(1)
|
|
66
83
|
*/
|
|
67
84
|
/**
|
|
68
|
-
* Time Complexity: O(n)
|
|
85
|
+
* Time Complexity: O(n)
|
|
69
86
|
* Space Complexity: O(1)
|
|
70
87
|
*
|
|
71
88
|
* The `get last` function returns the last node in a doubly linked list, or undefined if the list is empty.
|
|
@@ -89,11 +106,7 @@ class DoublyLinkedList extends base_1.IterableElementBase {
|
|
|
89
106
|
* @returns The `fromArray` function returns a DoublyLinkedList object.
|
|
90
107
|
*/
|
|
91
108
|
static fromArray(data) {
|
|
92
|
-
|
|
93
|
-
for (const item of data) {
|
|
94
|
-
doublyLinkedList.push(item);
|
|
95
|
-
}
|
|
96
|
-
return doublyLinkedList;
|
|
109
|
+
return new DoublyLinkedList(data);
|
|
97
110
|
}
|
|
98
111
|
/**
|
|
99
112
|
* Time Complexity: O(1)
|
|
@@ -148,7 +161,7 @@ class DoublyLinkedList extends base_1.IterableElementBase {
|
|
|
148
161
|
return removedNode.value;
|
|
149
162
|
}
|
|
150
163
|
/**
|
|
151
|
-
* Time Complexity: O(n)
|
|
164
|
+
* Time Complexity: O(n)
|
|
152
165
|
* Space Complexity: O(1)
|
|
153
166
|
*/
|
|
154
167
|
/**
|
|
@@ -175,7 +188,7 @@ class DoublyLinkedList extends base_1.IterableElementBase {
|
|
|
175
188
|
return removedNode.value;
|
|
176
189
|
}
|
|
177
190
|
/**
|
|
178
|
-
* Time Complexity: O(n)
|
|
191
|
+
* Time Complexity: O(n)
|
|
179
192
|
* Space Complexity: O(1)
|
|
180
193
|
*/
|
|
181
194
|
/**
|
|
@@ -201,20 +214,20 @@ class DoublyLinkedList extends base_1.IterableElementBase {
|
|
|
201
214
|
return true;
|
|
202
215
|
}
|
|
203
216
|
/**
|
|
204
|
-
* Time Complexity: O(n)
|
|
217
|
+
* Time Complexity: O(n)
|
|
205
218
|
* Space Complexity: O(1)
|
|
206
219
|
*/
|
|
207
220
|
/**
|
|
208
|
-
* Time Complexity: O(n)
|
|
221
|
+
* Time Complexity: O(n)
|
|
209
222
|
* Space Complexity: O(1)
|
|
210
223
|
*
|
|
211
|
-
* The `
|
|
224
|
+
* The `at` function returns the value at a specified index in a linked list, or undefined if the index is out of bounds.
|
|
212
225
|
* @param {number} index - The index parameter is a number that represents the position of the element we want to
|
|
213
226
|
* retrieve from the list.
|
|
214
227
|
* @returns The method is returning the value at the specified index in the linked list. If the index is out of bounds
|
|
215
228
|
* or the linked list is empty, it will return undefined.
|
|
216
229
|
*/
|
|
217
|
-
|
|
230
|
+
at(index) {
|
|
218
231
|
if (index < 0 || index >= this.size)
|
|
219
232
|
return undefined;
|
|
220
233
|
let current = this.head;
|
|
@@ -224,11 +237,11 @@ class DoublyLinkedList extends base_1.IterableElementBase {
|
|
|
224
237
|
return current.value;
|
|
225
238
|
}
|
|
226
239
|
/**
|
|
227
|
-
* Time Complexity: O(n)
|
|
240
|
+
* Time Complexity: O(n)
|
|
228
241
|
* Space Complexity: O(1)
|
|
229
242
|
*/
|
|
230
243
|
/**
|
|
231
|
-
* Time Complexity: O(n)
|
|
244
|
+
* Time Complexity: O(n)
|
|
232
245
|
* Space Complexity: O(1)
|
|
233
246
|
*
|
|
234
247
|
* The function `getNodeAt` returns the node at a given index in a doubly linked list, or undefined if the index is out of
|
|
@@ -248,11 +261,11 @@ class DoublyLinkedList extends base_1.IterableElementBase {
|
|
|
248
261
|
return current;
|
|
249
262
|
}
|
|
250
263
|
/**
|
|
251
|
-
* Time Complexity: O(n)
|
|
264
|
+
* Time Complexity: O(n)
|
|
252
265
|
* Space Complexity: O(1)
|
|
253
266
|
*/
|
|
254
267
|
/**
|
|
255
|
-
* Time Complexity: O(n)
|
|
268
|
+
* Time Complexity: O(n)
|
|
256
269
|
* Space Complexity: O(1)
|
|
257
270
|
*
|
|
258
271
|
* The function `findNodeByValue` searches for a node with a specific value in a doubly linked list and returns the
|
|
@@ -272,11 +285,11 @@ class DoublyLinkedList extends base_1.IterableElementBase {
|
|
|
272
285
|
return undefined;
|
|
273
286
|
}
|
|
274
287
|
/**
|
|
275
|
-
* Time Complexity: O(n)
|
|
288
|
+
* Time Complexity: O(n)
|
|
276
289
|
* Space Complexity: O(1)
|
|
277
290
|
*/
|
|
278
291
|
/**
|
|
279
|
-
* Time Complexity: O(n)
|
|
292
|
+
* Time Complexity: O(n)
|
|
280
293
|
* Space Complexity: O(1)
|
|
281
294
|
*
|
|
282
295
|
* The `insert` function inserts a value at a specified index in a doubly linked list.
|
|
@@ -309,11 +322,12 @@ class DoublyLinkedList extends base_1.IterableElementBase {
|
|
|
309
322
|
return true;
|
|
310
323
|
}
|
|
311
324
|
/**
|
|
312
|
-
* Time Complexity: O(n)
|
|
325
|
+
* Time Complexity: O(n)
|
|
313
326
|
* Space Complexity: O(1)
|
|
327
|
+
* where n is the number of elements in the linked list.
|
|
314
328
|
*/
|
|
315
329
|
/**
|
|
316
|
-
* Time Complexity: O(n)
|
|
330
|
+
* Time Complexity: O(n)
|
|
317
331
|
* Space Complexity: O(1)
|
|
318
332
|
*
|
|
319
333
|
* The `addBefore` function inserts a new value before an existing value or node in a doubly linked list.
|
|
@@ -350,11 +364,11 @@ class DoublyLinkedList extends base_1.IterableElementBase {
|
|
|
350
364
|
return false;
|
|
351
365
|
}
|
|
352
366
|
/**
|
|
353
|
-
* Time Complexity: O(n)
|
|
367
|
+
* Time Complexity: O(n)
|
|
354
368
|
* Space Complexity: O(1)
|
|
355
369
|
*/
|
|
356
370
|
/**
|
|
357
|
-
* Time Complexity: O(n)
|
|
371
|
+
* Time Complexity: O(n)
|
|
358
372
|
* Space Complexity: O(1)
|
|
359
373
|
*
|
|
360
374
|
* The `addAfter` function inserts a new node with a given value after an existing node in a doubly linked list.
|
|
@@ -390,7 +404,7 @@ class DoublyLinkedList extends base_1.IterableElementBase {
|
|
|
390
404
|
return false;
|
|
391
405
|
}
|
|
392
406
|
/**
|
|
393
|
-
* Time Complexity: O(n)
|
|
407
|
+
* Time Complexity: O(n)
|
|
394
408
|
* Space Complexity: O(1)
|
|
395
409
|
*
|
|
396
410
|
* The `deleteAt` function removes an element at a specified index from a linked list and returns the removed element.
|
|
@@ -419,7 +433,7 @@ class DoublyLinkedList extends base_1.IterableElementBase {
|
|
|
419
433
|
return true;
|
|
420
434
|
}
|
|
421
435
|
/**
|
|
422
|
-
* Time Complexity: O(n)
|
|
436
|
+
* Time Complexity: O(n)
|
|
423
437
|
* Space Complexity: O(1)
|
|
424
438
|
*
|
|
425
439
|
* The `delete` function removes a node from a doubly linked list based on either the node itself or its value.
|
|
@@ -455,7 +469,7 @@ class DoublyLinkedList extends base_1.IterableElementBase {
|
|
|
455
469
|
return false;
|
|
456
470
|
}
|
|
457
471
|
/**
|
|
458
|
-
* Time Complexity: O(
|
|
472
|
+
* Time Complexity: O(1)
|
|
459
473
|
* Space Complexity: O(1)
|
|
460
474
|
*/
|
|
461
475
|
/**
|
|
@@ -466,7 +480,7 @@ class DoublyLinkedList extends base_1.IterableElementBase {
|
|
|
466
480
|
return this.size === 0;
|
|
467
481
|
}
|
|
468
482
|
/**
|
|
469
|
-
* Time Complexity: O(
|
|
483
|
+
* Time Complexity: O(1)
|
|
470
484
|
* Space Complexity: O(1)
|
|
471
485
|
*/
|
|
472
486
|
/**
|
|
@@ -478,35 +492,11 @@ class DoublyLinkedList extends base_1.IterableElementBase {
|
|
|
478
492
|
this._size = 0;
|
|
479
493
|
}
|
|
480
494
|
/**
|
|
481
|
-
* Time Complexity: O(n)
|
|
482
|
-
* Space Complexity: O(1)
|
|
483
|
-
*/
|
|
484
|
-
/**
|
|
485
|
-
* Time Complexity: O(n), where n is the number of elements in the linked list.
|
|
486
|
-
* Space Complexity: O(1)
|
|
487
|
-
*
|
|
488
|
-
* The `find` function iterates through a linked list and returns the first element that satisfies a given condition.
|
|
489
|
-
* @param callback - A function that takes a value of type E as its parameter and returns a boolean value. This
|
|
490
|
-
* function is used to determine whether a particular value in the linked list satisfies a certain condition.
|
|
491
|
-
* @returns The method `find` returns the first element in the linked list that satisfies the condition specified by
|
|
492
|
-
* the callback function. If no element satisfies the condition, it returns `undefined`.
|
|
493
|
-
*/
|
|
494
|
-
find(callback) {
|
|
495
|
-
let current = this.head;
|
|
496
|
-
while (current) {
|
|
497
|
-
if (callback(current.value)) {
|
|
498
|
-
return current.value;
|
|
499
|
-
}
|
|
500
|
-
current = current.next;
|
|
501
|
-
}
|
|
502
|
-
return undefined;
|
|
503
|
-
}
|
|
504
|
-
/**
|
|
505
|
-
* Time Complexity: O(n), where n is the number of elements in the linked list.
|
|
495
|
+
* Time Complexity: O(n)
|
|
506
496
|
* Space Complexity: O(1)
|
|
507
497
|
*/
|
|
508
498
|
/**
|
|
509
|
-
* Time Complexity: O(n)
|
|
499
|
+
* Time Complexity: O(n)
|
|
510
500
|
* Space Complexity: O(1)
|
|
511
501
|
*
|
|
512
502
|
* The function returns the index of the first occurrence of a given value in a linked list.
|
|
@@ -528,11 +518,11 @@ class DoublyLinkedList extends base_1.IterableElementBase {
|
|
|
528
518
|
return -1;
|
|
529
519
|
}
|
|
530
520
|
/**
|
|
531
|
-
* Time Complexity: O(n)
|
|
521
|
+
* Time Complexity: O(n)
|
|
532
522
|
* Space Complexity: O(n)
|
|
533
523
|
*/
|
|
534
524
|
/**
|
|
535
|
-
* Time Complexity: O(n)
|
|
525
|
+
* Time Complexity: O(n)
|
|
536
526
|
* Space Complexity: O(1)
|
|
537
527
|
*
|
|
538
528
|
* The `findBackward` function iterates through a linked list from the last node to the first node and returns the last
|
|
@@ -553,11 +543,11 @@ class DoublyLinkedList extends base_1.IterableElementBase {
|
|
|
553
543
|
return undefined;
|
|
554
544
|
}
|
|
555
545
|
/**
|
|
556
|
-
* Time Complexity: O(n)
|
|
546
|
+
* Time Complexity: O(n)
|
|
557
547
|
* Space Complexity: O(n)
|
|
558
548
|
*/
|
|
559
549
|
/**
|
|
560
|
-
* Time Complexity: O(n)
|
|
550
|
+
* Time Complexity: O(n)
|
|
561
551
|
* Space Complexity: O(1)
|
|
562
552
|
*
|
|
563
553
|
* The `reverse` function reverses the order of the elements in a doubly linked list.
|
|
@@ -577,7 +567,7 @@ class DoublyLinkedList extends base_1.IterableElementBase {
|
|
|
577
567
|
* Space Complexity: O(n)
|
|
578
568
|
*/
|
|
579
569
|
/**
|
|
580
|
-
* Time Complexity: O(n)
|
|
570
|
+
* Time Complexity: O(n)
|
|
581
571
|
* Space Complexity: O(n)
|
|
582
572
|
*
|
|
583
573
|
* The `toArray` function converts a linked list into an array.
|
|
@@ -593,11 +583,11 @@ class DoublyLinkedList extends base_1.IterableElementBase {
|
|
|
593
583
|
return array;
|
|
594
584
|
}
|
|
595
585
|
/**
|
|
596
|
-
* Time Complexity: O(n)
|
|
586
|
+
* Time Complexity: O(n)
|
|
597
587
|
* Space Complexity: O(n)
|
|
598
588
|
*/
|
|
599
589
|
/**
|
|
600
|
-
* Time Complexity: O(n)
|
|
590
|
+
* Time Complexity: O(n)
|
|
601
591
|
* Space Complexity: O(n)
|
|
602
592
|
*
|
|
603
593
|
* The `toReversedArray` function converts a doubly linked list into an array in reverse order.
|
|
@@ -612,6 +602,22 @@ class DoublyLinkedList extends base_1.IterableElementBase {
|
|
|
612
602
|
}
|
|
613
603
|
return array;
|
|
614
604
|
}
|
|
605
|
+
/**
|
|
606
|
+
* Time Complexity: O(n)
|
|
607
|
+
* Space Complexity: O(n)
|
|
608
|
+
*/
|
|
609
|
+
/**
|
|
610
|
+
* Time Complexity: O(n)
|
|
611
|
+
* Space Complexity: O(n)
|
|
612
|
+
*
|
|
613
|
+
* The `clone` function creates a new instance of the `DoublyLinkedList` class with the same values
|
|
614
|
+
* as the original list.
|
|
615
|
+
* @returns The `clone()` method is returning a new instance of the `DoublyLinkedList` class, which
|
|
616
|
+
* is a copy of the original list.
|
|
617
|
+
*/
|
|
618
|
+
clone() {
|
|
619
|
+
return new DoublyLinkedList(this.values());
|
|
620
|
+
}
|
|
615
621
|
/**
|
|
616
622
|
* Time Complexity: O(1)
|
|
617
623
|
* Space Complexity: O(1)
|
|
@@ -704,7 +710,7 @@ class DoublyLinkedList extends base_1.IterableElementBase {
|
|
|
704
710
|
return this.pop();
|
|
705
711
|
}
|
|
706
712
|
/**
|
|
707
|
-
* Time Complexity: O(n)
|
|
713
|
+
* Time Complexity: O(n)
|
|
708
714
|
* Space Complexity: O(1)
|
|
709
715
|
*/
|
|
710
716
|
/**
|
|
@@ -719,7 +725,7 @@ class DoublyLinkedList extends base_1.IterableElementBase {
|
|
|
719
725
|
return this.shift();
|
|
720
726
|
}
|
|
721
727
|
/**
|
|
722
|
-
* Time Complexity: O(n)
|
|
728
|
+
* Time Complexity: O(n)
|
|
723
729
|
* Space Complexity: O(1)
|
|
724
730
|
*/
|
|
725
731
|
/**
|