graph-typed 1.45.3 → 1.46.1
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 +131 -164
- package/dist/data-structures/queue/deque.js +543 -211
- 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 +605 -226
- 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,8 +5,126 @@
|
|
|
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
|
+
constructor(index: number, deque: Deque<E>, iterateDirection?: IterateDirection);
|
|
20
|
+
get current(): E;
|
|
21
|
+
set current(newElement: E);
|
|
22
|
+
isAccessible(): boolean;
|
|
23
|
+
prev(): DequeIterator<E>;
|
|
24
|
+
next(): DequeIterator<E>;
|
|
25
|
+
clone(): DequeIterator<E>;
|
|
26
|
+
}
|
|
27
|
+
export declare class Deque<E> {
|
|
28
|
+
protected _bucketFirst: number;
|
|
29
|
+
protected _firstInBucket: number;
|
|
30
|
+
protected _bucketLast: number;
|
|
31
|
+
protected _lastInBucket: number;
|
|
32
|
+
protected _bucketCount: number;
|
|
33
|
+
protected readonly _bucketSize: number;
|
|
34
|
+
constructor(elements?: IterableWithSizeOrLength<E>, bucketSize?: number);
|
|
35
|
+
protected _buckets: E[][];
|
|
36
|
+
get buckets(): E[][];
|
|
37
|
+
protected _size: number;
|
|
38
|
+
get size(): number;
|
|
39
|
+
get first(): E | undefined;
|
|
40
|
+
get last(): E | undefined;
|
|
41
|
+
/**
|
|
42
|
+
* Time Complexity: Amortized O(1) - Generally constant time, but resizing when the deque is full leads to O(n).
|
|
43
|
+
* Space Complexity: O(n) - In worst case, resizing doubles the array size.
|
|
44
|
+
*/
|
|
45
|
+
empty(): boolean;
|
|
46
|
+
/**
|
|
47
|
+
* Time Complexity: O(1) - Removes the last element.
|
|
48
|
+
* Space Complexity: O(1) - Operates in-place.
|
|
49
|
+
*/
|
|
50
|
+
isEmpty(): boolean;
|
|
51
|
+
/**
|
|
52
|
+
* Time Complexity: Amortized O(1) - Similar to push, resizing leads to O(n).
|
|
53
|
+
* Space Complexity: O(n) - Due to potential resizing.
|
|
54
|
+
*/
|
|
55
|
+
/**
|
|
56
|
+
* Time Complexity: O(1)
|
|
57
|
+
* Space Complexity: O(n) - In worst case, resizing doubles the array size.
|
|
58
|
+
*
|
|
59
|
+
* The addLast function adds an element to the end of an array.
|
|
60
|
+
* @param {E} element - The element parameter represents the element that you want to add to the end of the
|
|
61
|
+
* data structure.
|
|
62
|
+
*/
|
|
63
|
+
addLast(element: E): void;
|
|
64
|
+
/**
|
|
65
|
+
* Time Complexity: O(1) - Removes the first element.
|
|
66
|
+
* Space Complexity: O(1) - In-place operation.
|
|
67
|
+
*/
|
|
68
|
+
/**
|
|
69
|
+
* Time Complexity: O(1) - Removes the last element.
|
|
70
|
+
* Space Complexity: O(1) - Operates in-place.
|
|
71
|
+
*
|
|
72
|
+
* The function "popLast" removes and returns the last element of an array.
|
|
73
|
+
* @returns The last element of the array is being returned.
|
|
74
|
+
*/
|
|
75
|
+
popLast(): E | undefined;
|
|
76
|
+
/**
|
|
77
|
+
* Time Complexity: O(1).
|
|
78
|
+
* Space Complexity: O(n) - Due to potential resizing.
|
|
79
|
+
*
|
|
80
|
+
* The "addFirst" function adds an element to the beginning of an array.
|
|
81
|
+
* @param {E} element - The parameter "element" represents the element that you want to add to the
|
|
82
|
+
* beginning of the data structure.
|
|
83
|
+
*/
|
|
84
|
+
addFirst(element: E): void;
|
|
85
|
+
/**
|
|
86
|
+
* Time Complexity: O(1) - Removes the first element.
|
|
87
|
+
* Space Complexity: O(1) - In-place operation.
|
|
88
|
+
*
|
|
89
|
+
* The function "popFirst" removes and returns the first element of an array.
|
|
90
|
+
* @returns The method `popFirst()` is returning the first element of the array after removing it
|
|
91
|
+
* from the beginning. If the array is empty, it will return `undefined`.
|
|
92
|
+
*/
|
|
93
|
+
popFirst(): E | undefined;
|
|
94
|
+
clear(): void;
|
|
95
|
+
begin(): DequeIterator<E>;
|
|
96
|
+
end(): DequeIterator<E>;
|
|
97
|
+
reverseBegin(): DequeIterator<E>;
|
|
98
|
+
reverseEnd(): DequeIterator<E>;
|
|
99
|
+
push(element: E): number;
|
|
100
|
+
pop(): E | undefined;
|
|
101
|
+
unshift(element: E): number;
|
|
102
|
+
shift(): E | undefined;
|
|
103
|
+
getAt(pos: number): E;
|
|
104
|
+
setAt(pos: number, element: E): void;
|
|
105
|
+
insertAt(pos: number, element: E, num?: number): number;
|
|
106
|
+
cut(pos: number): number;
|
|
107
|
+
deleteAt(pos: number): number;
|
|
108
|
+
delete(element: E): number;
|
|
109
|
+
deleteByIterator(iter: DequeIterator<E>): DequeIterator<E>;
|
|
110
|
+
findIterator(element: E): DequeIterator<E>;
|
|
111
|
+
reverse(): this;
|
|
112
|
+
unique(): number;
|
|
113
|
+
sort(comparator?: (x: E, y: E) => number): this;
|
|
114
|
+
shrinkToFit(): void;
|
|
115
|
+
forEach(callback: (element: E, index: number, deque: Deque<E>) => void): void;
|
|
116
|
+
find(callback: (element: E, index: number, deque: Deque<E>) => boolean): E | undefined;
|
|
117
|
+
toArray(): E[];
|
|
118
|
+
map<T>(callback: (element: E, index: number, deque: Deque<E>) => T): Deque<T>;
|
|
119
|
+
filter(predicate: (element: E, index: number, deque: Deque<E>) => boolean): Deque<E>;
|
|
120
|
+
reduce<T>(callback: (accumulator: T, element: E, index: number, deque: Deque<E>) => T, initialValue: T): T;
|
|
121
|
+
indexOf(element: E): number;
|
|
122
|
+
[Symbol.iterator](): Generator<E, void, unknown>;
|
|
123
|
+
protected _reallocate(needBucketNum?: number): void;
|
|
124
|
+
protected _getBucketAndPosition(pos: number): {
|
|
125
|
+
bucketIndex: number;
|
|
126
|
+
indexInBucket: number;
|
|
127
|
+
};
|
|
10
128
|
}
|
|
11
129
|
export declare class ObjectDeque<E = number> {
|
|
12
130
|
constructor(capacity?: number);
|
|
@@ -32,11 +150,11 @@ export declare class ObjectDeque<E = number> {
|
|
|
32
150
|
* Time Complexity: O(1)
|
|
33
151
|
* Space Complexity: O(1)
|
|
34
152
|
*
|
|
35
|
-
* The "addFirst" function adds
|
|
36
|
-
* @param {E}
|
|
153
|
+
* The "addFirst" function adds an element to the beginning of an array-like data structure.
|
|
154
|
+
* @param {E} element - The `element` parameter represents the element that you want to add to the beginning of the data
|
|
37
155
|
* structure.
|
|
38
156
|
*/
|
|
39
|
-
addFirst(
|
|
157
|
+
addFirst(element: E): void;
|
|
40
158
|
/**
|
|
41
159
|
* Time Complexity: O(1)
|
|
42
160
|
* Space Complexity: O(1)
|
|
@@ -45,10 +163,10 @@ export declare class ObjectDeque<E = number> {
|
|
|
45
163
|
* Time Complexity: O(1)
|
|
46
164
|
* Space Complexity: O(1)
|
|
47
165
|
*
|
|
48
|
-
* The addLast function adds
|
|
49
|
-
* @param {E}
|
|
166
|
+
* The addLast function adds an element to the end of an array-like data structure.
|
|
167
|
+
* @param {E} element - The `element` parameter represents the element that you want to add to the end of the data structure.
|
|
50
168
|
*/
|
|
51
|
-
addLast(
|
|
169
|
+
addLast(element: E): void;
|
|
52
170
|
/**
|
|
53
171
|
* Time Complexity: O(1)
|
|
54
172
|
* Space Complexity: O(1)
|
|
@@ -58,7 +176,7 @@ export declare class ObjectDeque<E = number> {
|
|
|
58
176
|
* Space Complexity: O(1)
|
|
59
177
|
*
|
|
60
178
|
* The function `popFirst()` removes and returns the first element in a data structure.
|
|
61
|
-
* @returns The
|
|
179
|
+
* @returns The element of the first element in the data structure.
|
|
62
180
|
*/
|
|
63
181
|
popFirst(): E | undefined;
|
|
64
182
|
/**
|
|
@@ -82,7 +200,7 @@ export declare class ObjectDeque<E = number> {
|
|
|
82
200
|
* Space Complexity: O(1)
|
|
83
201
|
*
|
|
84
202
|
* The `popLast()` function removes and returns the last element in a data structure.
|
|
85
|
-
* @returns The
|
|
203
|
+
* @returns The element that was removed from the data structure.
|
|
86
204
|
*/
|
|
87
205
|
popLast(): E | undefined;
|
|
88
206
|
/**
|
|
@@ -109,163 +227,12 @@ export declare class ObjectDeque<E = number> {
|
|
|
109
227
|
* @param {number} index - The index parameter is a number that represents the position of the element you want to
|
|
110
228
|
* retrieve from the array.
|
|
111
229
|
* @returns The element at the specified index in the `_nodes` array is being returned. If there is no element at that
|
|
112
|
-
* index, `
|
|
230
|
+
* index, `undefined` is returned.
|
|
113
231
|
*/
|
|
114
|
-
get(index: number): NonNullable<E> |
|
|
232
|
+
get(index: number): NonNullable<E> | undefined;
|
|
115
233
|
/**
|
|
116
234
|
* The function checks if the size of a data structure is less than or equal to zero.
|
|
117
|
-
* @returns The method is returning a boolean
|
|
118
|
-
*/
|
|
119
|
-
isEmpty(): boolean;
|
|
120
|
-
}
|
|
121
|
-
export declare class ArrayDeque<E> {
|
|
122
|
-
protected _nodes: E[];
|
|
123
|
-
get nodes(): E[];
|
|
124
|
-
get size(): number;
|
|
125
|
-
/**
|
|
126
|
-
* Time Complexity: O(1)
|
|
127
|
-
* Space Complexity: O(1)
|
|
128
|
-
*/
|
|
129
|
-
/**
|
|
130
|
-
* Time Complexity: O(1)
|
|
131
|
-
* Space Complexity: O(1)
|
|
132
|
-
*
|
|
133
|
-
* The function "addLast" adds a value to the end of an array.
|
|
134
|
-
* @param {E} value - The value parameter represents the value that you want to add to the end of the array.
|
|
135
|
-
* @returns The return value is the new length of the array after the value has been added.
|
|
136
|
-
*/
|
|
137
|
-
addLast(value: E): number;
|
|
138
|
-
/**
|
|
139
|
-
* Time Complexity: O(1)
|
|
140
|
-
* Space Complexity: O(1)
|
|
141
|
-
*/
|
|
142
|
-
/**
|
|
143
|
-
* Time Complexity: O(1)
|
|
144
|
-
* Space Complexity: O(1)
|
|
145
|
-
*
|
|
146
|
-
* The function "popLast" returns and removes the last element from an array, or returns null if the array is empty.
|
|
147
|
-
* @returns The method `popLast()` returns the last element of the `_nodes` array, or `null` if the array is empty.
|
|
148
|
-
*/
|
|
149
|
-
popLast(): E | null;
|
|
150
|
-
/**
|
|
151
|
-
* Time Complexity: O(n)
|
|
152
|
-
* Space Complexity: O(1)
|
|
153
|
-
*/
|
|
154
|
-
/**
|
|
155
|
-
* Time Complexity: O(n)
|
|
156
|
-
* Space Complexity: O(1)
|
|
157
|
-
*
|
|
158
|
-
* The `popFirst` function removes and returns the first element from an array, or returns null if the array is empty.
|
|
159
|
-
* @returns The `popFirst()` function returns the first element of the `_nodes` array, or `null` if the array is
|
|
160
|
-
* empty.
|
|
161
|
-
*/
|
|
162
|
-
popFirst(): E | null;
|
|
163
|
-
/**
|
|
164
|
-
* Time Complexity: O(n)
|
|
165
|
-
* Space Complexity: O(1)
|
|
166
|
-
*/
|
|
167
|
-
/**
|
|
168
|
-
* Time Complexity: O(n)
|
|
169
|
-
* Space Complexity: O(1)
|
|
170
|
-
*
|
|
171
|
-
* The function "addFirst" adds a value to the beginning of an array.
|
|
172
|
-
* @param {E} value - The value parameter represents the value that you want to add to the beginning of the array.
|
|
173
|
-
* @returns The return value of the `addFirst` function is the new length of the array `_nodes` after adding the
|
|
174
|
-
* `value` at the beginning.
|
|
175
|
-
*/
|
|
176
|
-
addFirst(value: E): number;
|
|
177
|
-
/**
|
|
178
|
-
* Time Complexity: O(1)
|
|
179
|
-
* Space Complexity: O(1)
|
|
180
|
-
*/
|
|
181
|
-
/**
|
|
182
|
-
* Time Complexity: O(1)
|
|
183
|
-
* Space Complexity: O(1)
|
|
184
|
-
*
|
|
185
|
-
* The `getFirst` function returns the first element of an array or null if the array is empty.
|
|
186
|
-
* @returns The function `getFirst()` is returning the first element (`E`) of the `_nodes` array. If the array is
|
|
187
|
-
* empty, it will return `null`.
|
|
188
|
-
*/
|
|
189
|
-
getFirst(): E | null;
|
|
190
|
-
/**
|
|
191
|
-
* Time Complexity: O(1)
|
|
192
|
-
* Space Complexity: O(1)
|
|
193
|
-
*/
|
|
194
|
-
/**
|
|
195
|
-
* Time Complexity: O(1)
|
|
196
|
-
* Space Complexity: O(1)
|
|
197
|
-
*
|
|
198
|
-
* The `getLast` function returns the last element of an array or null if the array is empty.
|
|
199
|
-
* @returns The method `getLast()` returns the last element of the `_nodes` array, or `null` if the array is empty.
|
|
200
|
-
*/
|
|
201
|
-
getLast(): E | null;
|
|
202
|
-
/**
|
|
203
|
-
* Time Complexity: O(1)
|
|
204
|
-
* Space Complexity: O(1)
|
|
205
|
-
*/
|
|
206
|
-
/**
|
|
207
|
-
* Time Complexity: O(1)
|
|
208
|
-
* Space Complexity: O(1)
|
|
209
|
-
*
|
|
210
|
-
* The get function returns the element at the specified index in an array, or null if the index is out of bounds.
|
|
211
|
-
* @param {number} index - The index parameter is a number that represents the position of the element you want to
|
|
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.
|
|
215
|
-
*/
|
|
216
|
-
get(index: number): E | null;
|
|
217
|
-
/**
|
|
218
|
-
* Time Complexity: O(1)
|
|
219
|
-
* Space Complexity: O(1)
|
|
220
|
-
*/
|
|
221
|
-
/**
|
|
222
|
-
* Time Complexity: O(1)
|
|
223
|
-
* Space Complexity: O(1)
|
|
224
|
-
*
|
|
225
|
-
* The set function assigns a value to a specific index in an array.
|
|
226
|
-
* @param {number} index - The index parameter is a number that represents the position of the element in the array
|
|
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.
|
|
231
|
-
*/
|
|
232
|
-
set(index: number, value: E): E;
|
|
233
|
-
/**
|
|
234
|
-
* Time Complexity: O(n)
|
|
235
|
-
* Space Complexity: O(1)
|
|
236
|
-
*/
|
|
237
|
-
/**
|
|
238
|
-
* Time Complexity: O(n)
|
|
239
|
-
* Space Complexity: O(1)
|
|
240
|
-
*
|
|
241
|
-
* The insert function adds a value at a specified index in an array.
|
|
242
|
-
* @param {number} index - The index parameter specifies the position at which the value should be inserted in the
|
|
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.
|
|
249
|
-
*/
|
|
250
|
-
insert(index: number, value: E): E[];
|
|
251
|
-
/**
|
|
252
|
-
* Time Complexity: O(n)
|
|
253
|
-
* Space Complexity: O(1)
|
|
254
|
-
*/
|
|
255
|
-
/**
|
|
256
|
-
* Time Complexity: O(n)
|
|
257
|
-
* Space Complexity: O(1)
|
|
258
|
-
*
|
|
259
|
-
* The delete function removes an element from an array at a specified index.
|
|
260
|
-
* @param {number} index - The index parameter specifies the position of the element to be removed from the array. It
|
|
261
|
-
* is a number that represents the index of the element to be removed.
|
|
262
|
-
* @returns The method is returning an array containing the removed element.
|
|
263
|
-
*/
|
|
264
|
-
delete(index: number): E[];
|
|
265
|
-
/**
|
|
266
|
-
* The function checks if an array called "_nodes" is empty.
|
|
267
|
-
* @returns The method `isEmpty()` is returning a boolean value. It returns `true` if the length of the `_nodes` array
|
|
268
|
-
* is 0, indicating that the array is empty. Otherwise, it returns `false`.
|
|
235
|
+
* @returns The method is returning a boolean element indicating whether the size of the object is less than or equal to 0.
|
|
269
236
|
*/
|
|
270
237
|
isEmpty(): boolean;
|
|
271
238
|
}
|