deque-typed 1.53.5 → 1.53.7
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/README.md +2 -13
- package/dist/common/index.d.ts +12 -0
- package/dist/common/index.js +23 -0
- package/dist/data-structures/binary-tree/avl-tree-multi-map.js +7 -10
- package/dist/data-structures/binary-tree/avl-tree.js +2 -2
- package/dist/data-structures/binary-tree/binary-tree.d.ts +54 -19
- package/dist/data-structures/binary-tree/binary-tree.js +100 -66
- package/dist/data-structures/binary-tree/bst.d.ts +100 -36
- package/dist/data-structures/binary-tree/bst.js +185 -66
- package/dist/data-structures/binary-tree/rb-tree.d.ts +4 -0
- package/dist/data-structures/binary-tree/rb-tree.js +6 -2
- package/dist/data-structures/binary-tree/tree-multi-map.js +2 -2
- package/dist/data-structures/heap/heap.d.ts +6 -6
- package/dist/data-structures/heap/heap.js +6 -6
- package/dist/data-structures/linked-list/doubly-linked-list.d.ts +31 -19
- package/dist/data-structures/linked-list/doubly-linked-list.js +49 -34
- package/dist/data-structures/linked-list/singly-linked-list.d.ts +144 -62
- package/dist/data-structures/linked-list/singly-linked-list.js +201 -97
- package/dist/data-structures/trie/trie.d.ts +104 -4
- package/dist/data-structures/trie/trie.js +116 -12
- package/dist/index.d.ts +2 -1
- package/dist/index.js +2 -1
- package/dist/types/data-structures/binary-tree/binary-tree.d.ts +1 -1
- package/dist/types/data-structures/binary-tree/bst.d.ts +3 -2
- package/dist/types/data-structures/binary-tree/rb-tree.d.ts +1 -1
- package/dist/types/utils/utils.d.ts +10 -6
- package/dist/utils/utils.js +4 -2
- package/package.json +2 -2
- package/src/common/index.ts +19 -0
- package/src/data-structures/binary-tree/avl-tree-multi-map.ts +7 -9
- package/src/data-structures/binary-tree/avl-tree.ts +3 -2
- package/src/data-structures/binary-tree/binary-tree.ts +108 -64
- package/src/data-structures/binary-tree/bst.ts +190 -69
- package/src/data-structures/binary-tree/rb-tree.ts +6 -2
- package/src/data-structures/binary-tree/tree-multi-map.ts +3 -3
- package/src/data-structures/heap/heap.ts +39 -39
- package/src/data-structures/linked-list/doubly-linked-list.ts +139 -121
- package/src/data-structures/linked-list/singly-linked-list.ts +219 -98
- package/src/data-structures/trie/trie.ts +116 -11
- package/src/index.ts +2 -1
- package/src/types/data-structures/binary-tree/binary-tree.ts +1 -1
- package/src/types/data-structures/binary-tree/bst.ts +3 -2
- package/src/types/data-structures/binary-tree/rb-tree.ts +1 -1
- package/src/types/utils/utils.ts +16 -10
- package/src/utils/utils.ts +4 -2
|
@@ -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}
|
|
91
|
-
*
|
|
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(
|
|
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
|
-
*
|
|
118
|
-
*
|
|
119
|
-
*
|
|
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
|
-
|
|
126
|
+
search(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>}
|
|
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(
|
|
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
|
|
171
|
-
* @param {number} index - The index parameter represents the position at which
|
|
172
|
-
* linked list. It is
|
|
173
|
-
*
|
|
174
|
-
*
|
|
175
|
-
*
|
|
176
|
-
*
|
|
177
|
-
|
|
178
|
-
|
|
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
|
|
210
|
-
*
|
|
211
|
-
* @
|
|
212
|
-
*
|
|
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(
|
|
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
|
|
220
|
-
*
|
|
221
|
-
* @param {E
|
|
222
|
-
*
|
|
223
|
-
*
|
|
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(
|
|
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`
|
|
231
|
-
*
|
|
232
|
-
*
|
|
233
|
-
*
|
|
234
|
-
* @
|
|
235
|
-
*
|
|
236
|
-
|
|
237
|
-
|
|
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
|
|
243
|
-
*
|
|
244
|
-
*
|
|
245
|
-
*
|
|
246
|
-
* @
|
|
247
|
-
*
|
|
248
|
-
|
|
249
|
-
|
|
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
|
|
255
|
-
*
|
|
256
|
-
* @
|
|
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(
|
|
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
|
}
|