min-heap-typed 1.45.3 → 1.46.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/dist/data-structures/hash/hash-map.d.ts +6 -5
- package/dist/data-structures/hash/hash-map.js +9 -6
- package/dist/data-structures/heap/heap.d.ts +59 -47
- package/dist/data-structures/heap/heap.js +133 -123
- package/dist/data-structures/queue/deque.d.ts +483 -114
- package/dist/data-structures/queue/deque.js +921 -183
- package/dist/types/data-structures/hash/hash-map.d.ts +0 -9
- package/dist/types/helpers.d.ts +11 -0
- package/dist/utils/utils.d.ts +1 -0
- package/dist/utils/utils.js +3 -1
- package/package.json +2 -2
- package/src/data-structures/hash/hash-map.ts +11 -7
- package/src/data-structures/heap/heap.ts +132 -128
- package/src/data-structures/queue/deque.ts +976 -170
- package/src/types/data-structures/hash/hash-map.ts +0 -11
- package/src/types/helpers.ts +15 -0
- package/src/utils/utils.ts +2 -0
|
@@ -5,38 +5,157 @@
|
|
|
5
5
|
* @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
|
|
6
6
|
* @license MIT License
|
|
7
7
|
*/
|
|
8
|
-
import {
|
|
9
|
-
|
|
8
|
+
import { IterableWithSizeOrLength, IterateDirection } from "../../types";
|
|
9
|
+
/**
|
|
10
|
+
* Deque can provide random access with O(1) time complexity
|
|
11
|
+
* Deque is usually more compact and efficient in memory usage because it does not require additional space to store pointers.
|
|
12
|
+
* Deque may experience performance jitter, but DoublyLinkedList will not
|
|
13
|
+
* Deque is implemented using a dynamic array. Inserting or deleting beyond both ends of the array may require moving elements or reallocating space.
|
|
14
|
+
*/
|
|
15
|
+
export declare class DequeIterator<E> {
|
|
16
|
+
iterateDirection: IterateDirection;
|
|
17
|
+
index: number;
|
|
18
|
+
readonly deque: Deque<E>;
|
|
19
|
+
/**
|
|
20
|
+
* The constructor initializes the index, iterate direction, and prev/next functions for a
|
|
21
|
+
* DequeIterator object.
|
|
22
|
+
* @param {number} index - The index parameter represents the current index position of the iterator
|
|
23
|
+
* within the deque. It is a number that indicates the position of the element that the iterator is
|
|
24
|
+
* currently pointing to.
|
|
25
|
+
* @param deque - The `deque` parameter is an instance of the `Deque` class. It represents a
|
|
26
|
+
* double-ended queue data structure, which allows elements to be added or removed from both ends.
|
|
27
|
+
* @param iterateDirection - The `iterateDirection` parameter is an optional parameter that specifies
|
|
28
|
+
* the direction in which the iterator should iterate over the elements of the `deque`. It has a
|
|
29
|
+
* default value of `IterateDirection.DEFAULT`.
|
|
30
|
+
* @returns The constructor is not returning anything. It is used to initialize the properties of the
|
|
31
|
+
* object being created.
|
|
32
|
+
*/
|
|
33
|
+
constructor(index: number, deque: Deque<E>, iterateDirection?: IterateDirection);
|
|
34
|
+
get current(): E;
|
|
35
|
+
set current(newElement: E);
|
|
36
|
+
isAccessible(): boolean;
|
|
37
|
+
prev(): DequeIterator<E>;
|
|
38
|
+
next(): DequeIterator<E>;
|
|
39
|
+
clone(): DequeIterator<E>;
|
|
10
40
|
}
|
|
11
|
-
export declare class
|
|
12
|
-
|
|
13
|
-
protected
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
41
|
+
export declare class Deque<E> {
|
|
42
|
+
protected _bucketFirst: number;
|
|
43
|
+
protected _firstInBucket: number;
|
|
44
|
+
protected _bucketLast: number;
|
|
45
|
+
protected _lastInBucket: number;
|
|
46
|
+
protected _bucketCount: number;
|
|
47
|
+
protected readonly _bucketSize: number;
|
|
48
|
+
/**
|
|
49
|
+
* The constructor initializes a data structure with a specified bucket size and populates it with
|
|
50
|
+
* elements from an iterable.
|
|
51
|
+
* @param elements - The `elements` parameter is an iterable object (such as an array or a Set) that
|
|
52
|
+
* contains the initial elements to be stored in the data structure. It can also be an object with a
|
|
53
|
+
* `length` property or a `size` property, which represents the number of elements in the iterable.
|
|
54
|
+
* @param bucketSize - The `bucketSize` parameter is the maximum number of elements that can be
|
|
55
|
+
* stored in each bucket. It determines the size of each bucket in the data structure.
|
|
56
|
+
*/
|
|
57
|
+
constructor(elements?: IterableWithSizeOrLength<E>, bucketSize?: number);
|
|
58
|
+
protected _buckets: E[][];
|
|
59
|
+
get buckets(): E[][];
|
|
25
60
|
protected _size: number;
|
|
26
61
|
get size(): number;
|
|
27
62
|
/**
|
|
28
|
-
*
|
|
29
|
-
*
|
|
63
|
+
* The function returns the first element in a collection if it exists, otherwise it returns
|
|
64
|
+
* undefined.
|
|
65
|
+
* @returns The first element of the collection, of type E, is being returned.
|
|
66
|
+
*/
|
|
67
|
+
get first(): E | undefined;
|
|
68
|
+
get last(): E | undefined;
|
|
69
|
+
/**
|
|
70
|
+
* Time Complexity: O(1) - Removes the last element.
|
|
71
|
+
* Space Complexity: O(1) - Operates in-place.
|
|
72
|
+
*/
|
|
73
|
+
isEmpty(): boolean;
|
|
74
|
+
/**
|
|
75
|
+
* Time Complexity: Amortized O(1) - Similar to push, resizing leads to O(n).
|
|
76
|
+
* Space Complexity: O(n) - Due to potential resizing.
|
|
30
77
|
*/
|
|
31
78
|
/**
|
|
32
79
|
* Time Complexity: O(1)
|
|
33
|
-
* Space Complexity: O(
|
|
80
|
+
* Space Complexity: O(n) - In worst case, resizing doubles the array size.
|
|
34
81
|
*
|
|
35
|
-
* The
|
|
36
|
-
* @param {E}
|
|
82
|
+
* The addLast function adds an element to the end of an array.
|
|
83
|
+
* @param {E} element - The element parameter represents the element that you want to add to the end of the
|
|
84
|
+
* data structure.
|
|
85
|
+
*/
|
|
86
|
+
addLast(element: E): void;
|
|
87
|
+
/**
|
|
88
|
+
* Time Complexity: O(1) - Removes the first element.
|
|
89
|
+
* Space Complexity: O(1) - In-place operation.
|
|
90
|
+
*/
|
|
91
|
+
/**
|
|
92
|
+
* Time Complexity: O(1) - Removes the last element.
|
|
93
|
+
* Space Complexity: O(1) - Operates in-place.
|
|
94
|
+
*
|
|
95
|
+
* The function "popLast" removes and returns the last element of an array.
|
|
96
|
+
* @returns The last element of the array is being returned.
|
|
97
|
+
*/
|
|
98
|
+
popLast(): E | undefined;
|
|
99
|
+
/**
|
|
100
|
+
* Time Complexity: O(1).
|
|
101
|
+
* Space Complexity: O(n) - Due to potential resizing.
|
|
102
|
+
*
|
|
103
|
+
* The "addFirst" function adds an element to the beginning of an array.
|
|
104
|
+
* @param {E} element - The parameter "element" represents the element that you want to add to the
|
|
105
|
+
* beginning of the data structure.
|
|
106
|
+
*/
|
|
107
|
+
addFirst(element: E): void;
|
|
108
|
+
/**
|
|
109
|
+
* Time Complexity: O(1) - Removes the first element.
|
|
110
|
+
* Space Complexity: O(1) - In-place operation.
|
|
111
|
+
*
|
|
112
|
+
* The function "popFirst" removes and returns the first element of an array.
|
|
113
|
+
* @returns The method `popFirst()` is returning the first element of the array after removing it
|
|
114
|
+
* from the beginning. If the array is empty, it will return `undefined`.
|
|
115
|
+
*/
|
|
116
|
+
popFirst(): E | undefined;
|
|
117
|
+
/**
|
|
118
|
+
* The clear() function resets the state of the object by initializing all variables to their default
|
|
119
|
+
* values.
|
|
120
|
+
*/
|
|
121
|
+
clear(): void;
|
|
122
|
+
/**
|
|
123
|
+
* The `begin()` function returns a new iterator for a deque starting from the first element.
|
|
124
|
+
* @returns A new instance of the DequeIterator class is being returned.
|
|
125
|
+
*/
|
|
126
|
+
begin(): DequeIterator<E>;
|
|
127
|
+
/**
|
|
128
|
+
* The `end()` function returns a new `DequeIterator` object with the size and reference to the
|
|
129
|
+
* current deque.
|
|
130
|
+
* @returns A new instance of the DequeIterator class is being returned.
|
|
131
|
+
*/
|
|
132
|
+
end(): DequeIterator<E>;
|
|
133
|
+
/**
|
|
134
|
+
* The reverseBegin function returns a new DequeIterator object that starts at the last element of
|
|
135
|
+
* the deque and iterates in reverse direction.
|
|
136
|
+
* @returns A new instance of the DequeIterator class is being returned.
|
|
137
|
+
*/
|
|
138
|
+
reverseBegin(): DequeIterator<E>;
|
|
139
|
+
/**
|
|
140
|
+
* The reverseEnd() function returns a new DequeIterator object that iterates over the elements of a
|
|
141
|
+
* Deque in reverse order.
|
|
142
|
+
* @returns A new instance of the DequeIterator class is being returned.
|
|
143
|
+
*/
|
|
144
|
+
reverseEnd(): DequeIterator<E>;
|
|
145
|
+
/**
|
|
146
|
+
* Time Complexity - Amortized O(1) (possible reallocation)
|
|
147
|
+
* Space Complexity - O(n) (due to potential resizing).
|
|
148
|
+
*/
|
|
149
|
+
/**
|
|
150
|
+
* Time Complexity - Amortized O(1) (possible reallocation),
|
|
151
|
+
* Space Complexity - O(n) (due to potential resizing).
|
|
152
|
+
*
|
|
153
|
+
* The push function adds an element to a data structure and reallocates memory if necessary.
|
|
154
|
+
* @param {E} element - The `element` parameter represents the value that you want to add to the data
|
|
37
155
|
* structure.
|
|
156
|
+
* @returns The size of the data structure after the element has been pushed.
|
|
38
157
|
*/
|
|
39
|
-
|
|
158
|
+
push(element: E): number;
|
|
40
159
|
/**
|
|
41
160
|
* Time Complexity: O(1)
|
|
42
161
|
* Space Complexity: O(1)
|
|
@@ -45,10 +164,26 @@ export declare class ObjectDeque<E = number> {
|
|
|
45
164
|
* Time Complexity: O(1)
|
|
46
165
|
* Space Complexity: O(1)
|
|
47
166
|
*
|
|
48
|
-
* The
|
|
49
|
-
*
|
|
167
|
+
* The `pop()` function removes and returns the last element from a data structure, updating the
|
|
168
|
+
* internal state variables accordingly.
|
|
169
|
+
* @returns The element that was removed from the data structure is being returned.
|
|
50
170
|
*/
|
|
51
|
-
|
|
171
|
+
pop(): E | undefined;
|
|
172
|
+
/**
|
|
173
|
+
* Time Complexity: Amortized O(1)
|
|
174
|
+
* Space Complexity: O(n)
|
|
175
|
+
*/
|
|
176
|
+
/**
|
|
177
|
+
* Time Complexity: Amortized O(1)
|
|
178
|
+
* Space Complexity: O(n)
|
|
179
|
+
*
|
|
180
|
+
* The `unshift` function adds an element to the beginning of an array-like data structure and
|
|
181
|
+
* returns the new size of the structure.
|
|
182
|
+
* @param {E} element - The `element` parameter represents the element that you want to add to the
|
|
183
|
+
* beginning of the data structure.
|
|
184
|
+
* @returns The size of the data structure after the element has been added.
|
|
185
|
+
*/
|
|
186
|
+
unshift(element: E): number;
|
|
52
187
|
/**
|
|
53
188
|
* Time Complexity: O(1)
|
|
54
189
|
* Space Complexity: O(1)
|
|
@@ -57,10 +192,12 @@ export declare class ObjectDeque<E = number> {
|
|
|
57
192
|
* Time Complexity: O(1)
|
|
58
193
|
* Space Complexity: O(1)
|
|
59
194
|
*
|
|
60
|
-
* The
|
|
61
|
-
*
|
|
195
|
+
* The `shift()` function removes and returns the first element from a data structure, updating the
|
|
196
|
+
* internal state variables accordingly.
|
|
197
|
+
* @returns The element that is being removed from the beginning of the data structure is being
|
|
198
|
+
* returned.
|
|
62
199
|
*/
|
|
63
|
-
|
|
200
|
+
shift(): E | undefined;
|
|
64
201
|
/**
|
|
65
202
|
* Time Complexity: O(1)
|
|
66
203
|
* Space Complexity: O(1)
|
|
@@ -69,10 +206,13 @@ export declare class ObjectDeque<E = number> {
|
|
|
69
206
|
* Time Complexity: O(1)
|
|
70
207
|
* Space Complexity: O(1)
|
|
71
208
|
*
|
|
72
|
-
* The `
|
|
73
|
-
* @
|
|
209
|
+
* The `getAt` function retrieves an element at a specified position in an array-like data structure.
|
|
210
|
+
* @param {number} pos - The `pos` parameter represents the position of the element that you want to
|
|
211
|
+
* retrieve from the data structure. It is of type `number` and should be a valid index within the
|
|
212
|
+
* range of the data structure.
|
|
213
|
+
* @returns The element at the specified position in the data structure is being returned.
|
|
74
214
|
*/
|
|
75
|
-
|
|
215
|
+
getAt(pos: number): E;
|
|
76
216
|
/**
|
|
77
217
|
* Time Complexity: O(1)
|
|
78
218
|
* Space Complexity: O(1)
|
|
@@ -81,10 +221,33 @@ export declare class ObjectDeque<E = number> {
|
|
|
81
221
|
* Time Complexity: O(1)
|
|
82
222
|
* Space Complexity: O(1)
|
|
83
223
|
*
|
|
84
|
-
* The `
|
|
85
|
-
* @
|
|
224
|
+
* The `setAt` function sets an element at a specific position in an array-like data structure.
|
|
225
|
+
* @param {number} pos - The `pos` parameter represents the position at which the element needs to be
|
|
226
|
+
* set. It is of type `number`.
|
|
227
|
+
* @param {E} element - The `element` parameter is the value that you want to set at the specified
|
|
228
|
+
* position in the data structure.
|
|
86
229
|
*/
|
|
87
|
-
|
|
230
|
+
setAt(pos: number, element: E): void;
|
|
231
|
+
/**
|
|
232
|
+
* Time Complexity: O(n)
|
|
233
|
+
* Space Complexity: O(n)
|
|
234
|
+
*/
|
|
235
|
+
/**
|
|
236
|
+
* Time Complexity: O(n)
|
|
237
|
+
* Space Complexity: O(n)
|
|
238
|
+
*
|
|
239
|
+
* The `insertAt` function inserts one or more elements at a specified position in an array-like data
|
|
240
|
+
* structure.
|
|
241
|
+
* @param {number} pos - The `pos` parameter represents the position at which the element(s) should
|
|
242
|
+
* be inserted. It is of type `number`.
|
|
243
|
+
* @param {E} element - The `element` parameter represents the element that you want to insert into
|
|
244
|
+
* the array at the specified position.
|
|
245
|
+
* @param [num=1] - The `num` parameter represents the number of times the `element` should be
|
|
246
|
+
* inserted at the specified position (`pos`). By default, it is set to 1, meaning that the `element`
|
|
247
|
+
* will be inserted once. However, you can provide a different value for `num` if you want
|
|
248
|
+
* @returns The size of the array after the insertion is being returned.
|
|
249
|
+
*/
|
|
250
|
+
insertAt(pos: number, element: E, num?: number): number;
|
|
88
251
|
/**
|
|
89
252
|
* Time Complexity: O(1)
|
|
90
253
|
* Space Complexity: O(1)
|
|
@@ -93,60 +256,142 @@ export declare class ObjectDeque<E = number> {
|
|
|
93
256
|
* Time Complexity: O(1)
|
|
94
257
|
* Space Complexity: O(1)
|
|
95
258
|
*
|
|
96
|
-
* The `
|
|
97
|
-
*
|
|
259
|
+
* The `cut` function updates the state of the object based on the given position and returns the
|
|
260
|
+
* updated size.
|
|
261
|
+
* @param {number} pos - The `pos` parameter represents the position at which the string should be
|
|
262
|
+
* cut. It is a number that indicates the index of the character where the cut should be made.
|
|
263
|
+
* @returns The method is returning the updated size of the data structure.
|
|
98
264
|
*/
|
|
99
|
-
|
|
265
|
+
cut(pos: number): number;
|
|
100
266
|
/**
|
|
101
|
-
* Time Complexity: O(
|
|
267
|
+
* Time Complexity: O(n)
|
|
102
268
|
* Space Complexity: O(1)
|
|
103
269
|
*/
|
|
104
270
|
/**
|
|
105
|
-
* Time Complexity: O(
|
|
271
|
+
* Time Complexity: O(n)
|
|
106
272
|
* Space Complexity: O(1)
|
|
107
273
|
*
|
|
108
|
-
* The
|
|
109
|
-
*
|
|
110
|
-
*
|
|
111
|
-
*
|
|
112
|
-
* index
|
|
274
|
+
* The `deleteAt` function removes an element at a specified position in an array-like data
|
|
275
|
+
* structure.
|
|
276
|
+
* @param {number} pos - The `pos` parameter in the `deleteAt` function represents the position at
|
|
277
|
+
* which an element needs to be deleted from the data structure. It is of type `number` and indicates
|
|
278
|
+
* the index of the element to be deleted.
|
|
279
|
+
* @returns The size of the data structure after the deletion operation is performed.
|
|
113
280
|
*/
|
|
114
|
-
|
|
281
|
+
deleteAt(pos: number): number;
|
|
115
282
|
/**
|
|
116
|
-
*
|
|
117
|
-
*
|
|
283
|
+
* Time Complexity: O(n)
|
|
284
|
+
* Space Complexity: O(1)
|
|
118
285
|
*/
|
|
119
|
-
isEmpty(): boolean;
|
|
120
|
-
}
|
|
121
|
-
export declare class ArrayDeque<E> {
|
|
122
|
-
protected _nodes: E[];
|
|
123
|
-
get nodes(): E[];
|
|
124
|
-
get size(): number;
|
|
125
286
|
/**
|
|
126
|
-
* Time Complexity: O(
|
|
287
|
+
* Time Complexity: O(n)
|
|
288
|
+
* Space Complexity: O(1)
|
|
289
|
+
*
|
|
290
|
+
* The `delete` function removes all occurrences of a specified element from an array-like data
|
|
291
|
+
* structure.
|
|
292
|
+
* @param {E} element - The `element` parameter represents the element that you want to delete from
|
|
293
|
+
* the data structure.
|
|
294
|
+
* @returns The size of the data structure after the element has been deleted.
|
|
295
|
+
*/
|
|
296
|
+
delete(element: E): number;
|
|
297
|
+
/**
|
|
298
|
+
* Time Complexity: O(n)
|
|
127
299
|
* Space Complexity: O(1)
|
|
128
300
|
*/
|
|
129
301
|
/**
|
|
130
|
-
* Time Complexity: O(
|
|
302
|
+
* Time Complexity: O(n)
|
|
131
303
|
* Space Complexity: O(1)
|
|
132
304
|
*
|
|
133
|
-
* The function
|
|
134
|
-
* @param
|
|
135
|
-
*
|
|
305
|
+
* The function deletes an element from a deque using an iterator and returns the next iterator.
|
|
306
|
+
* @param iter - The parameter `iter` is of type `DequeIterator<E>`. It represents an iterator object
|
|
307
|
+
* that is used to iterate over elements in a deque (double-ended queue).
|
|
308
|
+
* @returns the updated iterator after deleting an element from the deque.
|
|
136
309
|
*/
|
|
137
|
-
|
|
310
|
+
deleteByIterator(iter: DequeIterator<E>): DequeIterator<E>;
|
|
138
311
|
/**
|
|
139
|
-
* Time Complexity: O(
|
|
312
|
+
* Time Complexity: O(n)
|
|
140
313
|
* Space Complexity: O(1)
|
|
141
314
|
*/
|
|
142
315
|
/**
|
|
143
|
-
* Time Complexity: O(
|
|
316
|
+
* Time Complexity: O(n)
|
|
317
|
+
* Space Complexity: O(1)
|
|
318
|
+
*
|
|
319
|
+
* The function `findIterator` searches for an element in a deque and returns an iterator pointing to
|
|
320
|
+
* the element if found, otherwise it returns an iterator pointing to the end of the deque.
|
|
321
|
+
* @param {E} element - The `element` parameter is the element that you want to find in the deque.
|
|
322
|
+
* @returns The method `findIterator(element: E)` returns a `DequeIterator<E>` object.
|
|
323
|
+
*/
|
|
324
|
+
findIterator(element: E): DequeIterator<E>;
|
|
325
|
+
/**
|
|
326
|
+
* Time Complexity: O(n)
|
|
327
|
+
* Space Complexity: O(1)
|
|
328
|
+
*/
|
|
329
|
+
/**
|
|
330
|
+
* Time Complexity: O(n)
|
|
331
|
+
* Space Complexity: O(1)
|
|
332
|
+
*
|
|
333
|
+
* The reverse() function reverses the order of the buckets and the elements within each bucket in a
|
|
334
|
+
* data structure.
|
|
335
|
+
* @returns The reverse() method is returning the object itself (this) after performing the reverse
|
|
336
|
+
* operation on the buckets and updating the relevant properties.
|
|
337
|
+
*/
|
|
338
|
+
reverse(): this;
|
|
339
|
+
/**
|
|
340
|
+
* Time Complexity: O(n)
|
|
341
|
+
* Space Complexity: O(1)
|
|
342
|
+
*/
|
|
343
|
+
/**
|
|
344
|
+
* Time Complexity: O(n)
|
|
345
|
+
* Space Complexity: O(1)
|
|
346
|
+
*
|
|
347
|
+
* The `unique()` function removes duplicate elements from an array-like data structure and returns
|
|
348
|
+
* the number of unique elements.
|
|
349
|
+
* @returns The size of the modified array is being returned.
|
|
350
|
+
*/
|
|
351
|
+
unique(): number;
|
|
352
|
+
/**
|
|
353
|
+
* Time Complexity: O(n log n)
|
|
354
|
+
* Space Complexity: O(n)
|
|
355
|
+
*/
|
|
356
|
+
/**
|
|
357
|
+
* Time Complexity: O(n log n)
|
|
358
|
+
* Space Complexity: O(n)
|
|
359
|
+
*
|
|
360
|
+
* The `sort` function sorts the elements in a data structure using a provided comparator function.
|
|
361
|
+
* @param [comparator] - The `comparator` parameter is a function that takes in two elements `x` and
|
|
362
|
+
* `y` of type `E` and returns a number. The comparator function is used to determine the order of
|
|
363
|
+
* the elements in the sorted array.
|
|
364
|
+
* @returns The method is returning the sorted instance of the object on which the method is called.
|
|
365
|
+
*/
|
|
366
|
+
sort(comparator?: (x: E, y: E) => number): this;
|
|
367
|
+
/**
|
|
368
|
+
* Time Complexity: O(n)
|
|
369
|
+
* Space Complexity: O(n)
|
|
370
|
+
*/
|
|
371
|
+
/**
|
|
372
|
+
* Time Complexity: O(n)
|
|
373
|
+
* Space Complexity: O(n)
|
|
374
|
+
*
|
|
375
|
+
* The `shrinkToFit` function reorganizes the elements in an array-like data structure to minimize
|
|
376
|
+
* memory usage.
|
|
377
|
+
* @returns Nothing is being returned. The function is using the `return` statement to exit early if
|
|
378
|
+
* `this.size` is 0, but it does not return any value.
|
|
379
|
+
*/
|
|
380
|
+
shrinkToFit(): void;
|
|
381
|
+
/**
|
|
382
|
+
* Time Complexity: O(n)
|
|
383
|
+
* Space Complexity: O(1)
|
|
384
|
+
*/
|
|
385
|
+
/**
|
|
386
|
+
* Time Complexity: O(n)
|
|
144
387
|
* Space Complexity: O(1)
|
|
145
388
|
*
|
|
146
|
-
* The function
|
|
147
|
-
*
|
|
389
|
+
* The `forEach` function iterates over each element in a deque and applies a callback function to
|
|
390
|
+
* each element.
|
|
391
|
+
* @param callback - The callback parameter is a function that will be called for each element in the
|
|
392
|
+
* deque. It takes three parameters:
|
|
148
393
|
*/
|
|
149
|
-
|
|
394
|
+
forEach(callback: (element: E, index: number, deque: Deque<E>) => void): void;
|
|
150
395
|
/**
|
|
151
396
|
* Time Complexity: O(n)
|
|
152
397
|
* Space Complexity: O(1)
|
|
@@ -155,11 +400,74 @@ export declare class ArrayDeque<E> {
|
|
|
155
400
|
* Time Complexity: O(n)
|
|
156
401
|
* Space Complexity: O(1)
|
|
157
402
|
*
|
|
158
|
-
* The `
|
|
159
|
-
*
|
|
160
|
-
*
|
|
403
|
+
* The `find` function iterates over the elements in a deque and returns the first element for which
|
|
404
|
+
* the callback function returns true, or undefined if no such element is found.
|
|
405
|
+
* @param callback - A function that takes three parameters: element, index, and deque. It should
|
|
406
|
+
* return a boolean value indicating whether the element satisfies a certain condition.
|
|
407
|
+
* @returns The method `find` returns the first element in the deque that satisfies the condition
|
|
408
|
+
* specified by the callback function. If no element satisfies the condition, it returns `undefined`.
|
|
409
|
+
*/
|
|
410
|
+
find(callback: (element: E, index: number, deque: Deque<E>) => boolean): E | undefined;
|
|
411
|
+
/**
|
|
412
|
+
* Time Complexity: O(n)
|
|
413
|
+
* Space Complexity: O(n)
|
|
414
|
+
*/
|
|
415
|
+
/**
|
|
416
|
+
* Time Complexity: O(n)
|
|
417
|
+
* Space Complexity: O(n)
|
|
418
|
+
*
|
|
419
|
+
* The `toArray` function converts the elements of a data structure into an array.
|
|
420
|
+
* @returns The `toArray()` method is returning an array of elements of type `E`.
|
|
421
|
+
*/
|
|
422
|
+
toArray(): E[];
|
|
423
|
+
/**
|
|
424
|
+
* Time Complexity: O(n)
|
|
425
|
+
* Space Complexity: O(n)
|
|
426
|
+
*/
|
|
427
|
+
/**
|
|
428
|
+
* Time Complexity: O(n)
|
|
429
|
+
* Space Complexity: O(n)
|
|
430
|
+
*
|
|
431
|
+
* The `map` function takes a callback function and applies it to each element in the deque,
|
|
432
|
+
* returning a new deque with the results.
|
|
433
|
+
* @param callback - The `callback` parameter is a function that takes three arguments:
|
|
434
|
+
* @returns The `map` method is returning a new `Deque` object with the transformed elements.
|
|
161
435
|
*/
|
|
162
|
-
|
|
436
|
+
map<T>(callback: (element: E, index: number, deque: Deque<E>) => T): Deque<T>;
|
|
437
|
+
/**
|
|
438
|
+
* Time Complexity: O(n)
|
|
439
|
+
* Space Complexity: O(n)
|
|
440
|
+
*/
|
|
441
|
+
/**
|
|
442
|
+
* Time Complexity: O(n)
|
|
443
|
+
* Space Complexity: O(n)
|
|
444
|
+
*
|
|
445
|
+
* The `filter` function creates a new deque containing only the elements that satisfy the given
|
|
446
|
+
* predicate function.
|
|
447
|
+
* @param predicate - The `predicate` parameter is a function that takes three arguments: `element`,
|
|
448
|
+
* `index`, and `deque`.
|
|
449
|
+
* @returns The `filter` method is returning a new `Deque` object that contains only the elements
|
|
450
|
+
* that satisfy the given `predicate` function.
|
|
451
|
+
*/
|
|
452
|
+
filter(predicate: (element: E, index: number, deque: Deque<E>) => boolean): Deque<E>;
|
|
453
|
+
/**
|
|
454
|
+
* Time Complexity: O(n)
|
|
455
|
+
* Space Complexity: O(1)
|
|
456
|
+
*/
|
|
457
|
+
/**
|
|
458
|
+
* Time Complexity: O(n)
|
|
459
|
+
* Space Complexity: O(1)
|
|
460
|
+
*
|
|
461
|
+
* The `reduce` function iterates over the elements of a deque and applies a callback function to
|
|
462
|
+
* each element, accumulating a single value.
|
|
463
|
+
* @param callback - The `callback` parameter is a function that takes four arguments:
|
|
464
|
+
* @param {T} initialValue - The `initialValue` parameter is the initial value of the accumulator. It
|
|
465
|
+
* is the value that will be passed as the first argument to the `callback` function when reducing
|
|
466
|
+
* the elements of the deque.
|
|
467
|
+
* @returns the final value of the accumulator after iterating over all elements in the deque and
|
|
468
|
+
* applying the callback function to each element.
|
|
469
|
+
*/
|
|
470
|
+
reduce<T>(callback: (accumulator: T, element: E, index: number, deque: Deque<E>) => T, initialValue: T): T;
|
|
163
471
|
/**
|
|
164
472
|
* Time Complexity: O(n)
|
|
165
473
|
* Space Complexity: O(1)
|
|
@@ -168,12 +476,40 @@ export declare class ArrayDeque<E> {
|
|
|
168
476
|
* Time Complexity: O(n)
|
|
169
477
|
* Space Complexity: O(1)
|
|
170
478
|
*
|
|
171
|
-
* The function "
|
|
172
|
-
*
|
|
173
|
-
* @
|
|
174
|
-
*
|
|
479
|
+
* The function "indexOf" returns the index of the first occurrence of a given element in an array,
|
|
480
|
+
* or -1 if the element is not found.
|
|
481
|
+
* @param {E} element - The "element" parameter represents the element that you want to find the
|
|
482
|
+
* index of in the data structure.
|
|
483
|
+
* @returns The indexOf function returns the index of the first occurrence of the specified element
|
|
484
|
+
* in the data structure. If the element is not found, it returns -1.
|
|
175
485
|
*/
|
|
176
|
-
|
|
486
|
+
indexOf(element: E): number;
|
|
487
|
+
/**
|
|
488
|
+
* Time Complexity: O(n)
|
|
489
|
+
* Space Complexity: O(1)
|
|
490
|
+
*/
|
|
491
|
+
/**
|
|
492
|
+
* Time Complexity: O(n)
|
|
493
|
+
* Space Complexity: O(1)
|
|
494
|
+
*
|
|
495
|
+
* The above function is an implementation of the iterator protocol in TypeScript, allowing the
|
|
496
|
+
* object to be iterated over using a for...of loop.
|
|
497
|
+
*/
|
|
498
|
+
[Symbol.iterator](): Generator<E, void, unknown>;
|
|
499
|
+
/**
|
|
500
|
+
* Time Complexity: O(n)
|
|
501
|
+
* Space Complexity: O(n)
|
|
502
|
+
*/
|
|
503
|
+
/**
|
|
504
|
+
* Time Complexity: O(n)
|
|
505
|
+
* Space Complexity: O(n)
|
|
506
|
+
*
|
|
507
|
+
* The `_reallocate` function reallocates the buckets in an array, adding new buckets if needed.
|
|
508
|
+
* @param {number} [needBucketNum] - The `needBucketNum` parameter is an optional number that
|
|
509
|
+
* specifies the number of new buckets needed. If not provided, it will default to half of the
|
|
510
|
+
* current bucket count (`this._bucketCount >> 1`) or 1 if the current bucket count is less than 2.
|
|
511
|
+
*/
|
|
512
|
+
protected _reallocate(needBucketNum?: number): void;
|
|
177
513
|
/**
|
|
178
514
|
* Time Complexity: O(1)
|
|
179
515
|
* Space Complexity: O(1)
|
|
@@ -182,11 +518,45 @@ export declare class ArrayDeque<E> {
|
|
|
182
518
|
* Time Complexity: O(1)
|
|
183
519
|
* Space Complexity: O(1)
|
|
184
520
|
*
|
|
185
|
-
* The
|
|
186
|
-
* @
|
|
187
|
-
*
|
|
521
|
+
* The function calculates the bucket index and index within the bucket based on the given position.
|
|
522
|
+
* @param {number} pos - The `pos` parameter represents the position within the data structure. It is
|
|
523
|
+
* a number that indicates the index or position of an element within the structure.
|
|
524
|
+
* @returns an object with two properties: "bucketIndex" and "indexInBucket".
|
|
525
|
+
*/
|
|
526
|
+
protected _getBucketAndPosition(pos: number): {
|
|
527
|
+
bucketIndex: number;
|
|
528
|
+
indexInBucket: number;
|
|
529
|
+
};
|
|
530
|
+
}
|
|
531
|
+
export declare class ObjectDeque<E = number> {
|
|
532
|
+
constructor(capacity?: number);
|
|
533
|
+
protected _nodes: {
|
|
534
|
+
[key: number]: E;
|
|
535
|
+
};
|
|
536
|
+
get nodes(): {
|
|
537
|
+
[p: number]: E;
|
|
538
|
+
};
|
|
539
|
+
protected _capacity: number;
|
|
540
|
+
get capacity(): number;
|
|
541
|
+
protected _first: number;
|
|
542
|
+
get first(): number;
|
|
543
|
+
protected _last: number;
|
|
544
|
+
get last(): number;
|
|
545
|
+
protected _size: number;
|
|
546
|
+
get size(): number;
|
|
547
|
+
/**
|
|
548
|
+
* Time Complexity: O(1)
|
|
549
|
+
* Space Complexity: O(1)
|
|
188
550
|
*/
|
|
189
|
-
|
|
551
|
+
/**
|
|
552
|
+
* Time Complexity: O(1)
|
|
553
|
+
* Space Complexity: O(1)
|
|
554
|
+
*
|
|
555
|
+
* The "addFirst" function adds an element to the beginning of an array-like data structure.
|
|
556
|
+
* @param {E} element - The `element` parameter represents the element that you want to add to the beginning of the data
|
|
557
|
+
* structure.
|
|
558
|
+
*/
|
|
559
|
+
addFirst(element: E): void;
|
|
190
560
|
/**
|
|
191
561
|
* Time Complexity: O(1)
|
|
192
562
|
* Space Complexity: O(1)
|
|
@@ -195,10 +565,10 @@ export declare class ArrayDeque<E> {
|
|
|
195
565
|
* Time Complexity: O(1)
|
|
196
566
|
* Space Complexity: O(1)
|
|
197
567
|
*
|
|
198
|
-
* The
|
|
199
|
-
* @
|
|
568
|
+
* The addLast function adds an element to the end of an array-like data structure.
|
|
569
|
+
* @param {E} element - The `element` parameter represents the element that you want to add to the end of the data structure.
|
|
200
570
|
*/
|
|
201
|
-
|
|
571
|
+
addLast(element: E): void;
|
|
202
572
|
/**
|
|
203
573
|
* Time Complexity: O(1)
|
|
204
574
|
* Space Complexity: O(1)
|
|
@@ -207,13 +577,10 @@ export declare class ArrayDeque<E> {
|
|
|
207
577
|
* Time Complexity: O(1)
|
|
208
578
|
* Space Complexity: O(1)
|
|
209
579
|
*
|
|
210
|
-
* The
|
|
211
|
-
* @
|
|
212
|
-
* retrieve from the array.
|
|
213
|
-
* @returns The method is returning the element at the specified index in the `_nodes` array. If the element exists, it
|
|
214
|
-
* will be returned. If the element does not exist (i.e., the index is out of bounds), `null` will be returned.
|
|
580
|
+
* The function `popFirst()` removes and returns the first element in a data structure.
|
|
581
|
+
* @returns The element of the first element in the data structure.
|
|
215
582
|
*/
|
|
216
|
-
|
|
583
|
+
popFirst(): E | undefined;
|
|
217
584
|
/**
|
|
218
585
|
* Time Complexity: O(1)
|
|
219
586
|
* Space Complexity: O(1)
|
|
@@ -222,50 +589,52 @@ export declare class ArrayDeque<E> {
|
|
|
222
589
|
* Time Complexity: O(1)
|
|
223
590
|
* Space Complexity: O(1)
|
|
224
591
|
*
|
|
225
|
-
* The
|
|
226
|
-
* @
|
|
227
|
-
* that you want to set a new value for.
|
|
228
|
-
* @param {E} value - The value parameter represents the new value that you want to set at the specified index in the
|
|
229
|
-
* _nodes array.
|
|
230
|
-
* @returns The value that is being set at the specified index in the `_nodes` array.
|
|
592
|
+
* The `getFirst` function returns the first element in an array-like data structure if it exists.
|
|
593
|
+
* @returns The element at the first position of the `_nodes` array.
|
|
231
594
|
*/
|
|
232
|
-
|
|
595
|
+
getFirst(): E | undefined;
|
|
233
596
|
/**
|
|
234
|
-
* Time Complexity: O(
|
|
597
|
+
* Time Complexity: O(1)
|
|
235
598
|
* Space Complexity: O(1)
|
|
236
599
|
*/
|
|
237
600
|
/**
|
|
238
|
-
* Time Complexity: O(
|
|
601
|
+
* Time Complexity: O(1)
|
|
239
602
|
* Space Complexity: O(1)
|
|
240
603
|
*
|
|
241
|
-
* The
|
|
242
|
-
* @
|
|
243
|
-
* array. It is a number that represents the index of the array where the value should be inserted. The index starts
|
|
244
|
-
* from 0, so the first element of the array has an index of 0, the second element has
|
|
245
|
-
* @param {E} value - The value parameter represents the value that you want to insert into the array at the specified
|
|
246
|
-
* index.
|
|
247
|
-
* @returns The splice method returns an array containing the removed elements, if any. In this case, since no elements
|
|
248
|
-
* are being removed, an empty array will be returned.
|
|
604
|
+
* The `popLast()` function removes and returns the last element in a data structure.
|
|
605
|
+
* @returns The element that was removed from the data structure.
|
|
249
606
|
*/
|
|
250
|
-
|
|
607
|
+
popLast(): E | undefined;
|
|
251
608
|
/**
|
|
252
|
-
* Time Complexity: O(
|
|
609
|
+
* Time Complexity: O(1)
|
|
253
610
|
* Space Complexity: O(1)
|
|
254
611
|
*/
|
|
255
612
|
/**
|
|
256
|
-
* Time Complexity: O(
|
|
613
|
+
* Time Complexity: O(1)
|
|
257
614
|
* Space Complexity: O(1)
|
|
258
615
|
*
|
|
259
|
-
* The
|
|
260
|
-
* @
|
|
261
|
-
|
|
262
|
-
|
|
616
|
+
* The `getLast()` function returns the last element in an array-like data structure.
|
|
617
|
+
* @returns The last element in the array "_nodes" is being returned.
|
|
618
|
+
*/
|
|
619
|
+
getLast(): E | undefined;
|
|
620
|
+
/**
|
|
621
|
+
* Time Complexity: O(1)
|
|
622
|
+
* Space Complexity: O(1)
|
|
263
623
|
*/
|
|
264
|
-
delete(index: number): E[];
|
|
265
624
|
/**
|
|
266
|
-
*
|
|
267
|
-
*
|
|
268
|
-
*
|
|
625
|
+
* Time Complexity: O(1)
|
|
626
|
+
* Space Complexity: O(1)
|
|
627
|
+
*
|
|
628
|
+
* The get function returns the element at the specified index in an array-like data structure.
|
|
629
|
+
* @param {number} index - The index parameter is a number that represents the position of the element you want to
|
|
630
|
+
* retrieve from the array.
|
|
631
|
+
* @returns The element at the specified index in the `_nodes` array is being returned. If there is no element at that
|
|
632
|
+
* index, `undefined` is returned.
|
|
633
|
+
*/
|
|
634
|
+
get(index: number): NonNullable<E> | undefined;
|
|
635
|
+
/**
|
|
636
|
+
* The function checks if the size of a data structure is less than or equal to zero.
|
|
637
|
+
* @returns The method is returning a boolean element indicating whether the size of the object is less than or equal to 0.
|
|
269
638
|
*/
|
|
270
639
|
isEmpty(): boolean;
|
|
271
640
|
}
|