graph-typed 1.46.1 → 1.46.3

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.
@@ -5,25 +5,13 @@
5
5
  * @copyright Copyright (c) 2022 Tyler Zeng <zrwusa@gmail.com>
6
6
  * @license MIT License
7
7
  */
8
- import { IterableWithSizeOrLength, IterateDirection } from "../../types";
8
+ import { IterableWithSizeOrLength } from "../../types";
9
9
  /**
10
10
  * Deque can provide random access with O(1) time complexity
11
11
  * Deque is usually more compact and efficient in memory usage because it does not require additional space to store pointers.
12
12
  * Deque may experience performance jitter, but DoublyLinkedList will not
13
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
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
15
  export declare class Deque<E> {
28
16
  protected _bucketFirst: number;
29
17
  protected _firstInBucket: number;
@@ -31,18 +19,27 @@ export declare class Deque<E> {
31
19
  protected _lastInBucket: number;
32
20
  protected _bucketCount: number;
33
21
  protected readonly _bucketSize: number;
22
+ /**
23
+ * The constructor initializes a data structure with a specified bucket size and populates it with
24
+ * elements from an iterable.
25
+ * @param elements - The `elements` parameter is an iterable object (such as an array or a Set) that
26
+ * contains the initial elements to be stored in the data structure. It can also be an object with a
27
+ * `length` property or a `size` property, which represents the number of elements in the iterable.
28
+ * @param bucketSize - The `bucketSize` parameter is the maximum number of elements that can be
29
+ * stored in each bucket. It determines the size of each bucket in the data structure.
30
+ */
34
31
  constructor(elements?: IterableWithSizeOrLength<E>, bucketSize?: number);
35
32
  protected _buckets: E[][];
36
33
  get buckets(): E[][];
37
34
  protected _size: number;
38
35
  get size(): number;
39
- get first(): E | undefined;
40
- get last(): E | undefined;
41
36
  /**
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.
37
+ * The function returns the first element in a collection if it exists, otherwise it returns
38
+ * undefined.
39
+ * @returns The first element of the collection, of type E, is being returned.
44
40
  */
45
- empty(): boolean;
41
+ get first(): E | undefined;
42
+ get last(): E | undefined;
46
43
  /**
47
44
  * Time Complexity: O(1) - Removes the last element.
48
45
  * Space Complexity: O(1) - Operates in-place.
@@ -91,36 +88,373 @@ export declare class Deque<E> {
91
88
  * from the beginning. If the array is empty, it will return `undefined`.
92
89
  */
93
90
  popFirst(): E | undefined;
91
+ /**
92
+ * The clear() function resets the state of the object by initializing all variables to their default
93
+ * values.
94
+ */
94
95
  clear(): void;
95
- begin(): DequeIterator<E>;
96
- end(): DequeIterator<E>;
97
- reverseBegin(): DequeIterator<E>;
98
- reverseEnd(): DequeIterator<E>;
96
+ /**
97
+ * The below function is a generator that yields elements from a collection one by one.
98
+ */
99
+ begin(): Generator<E>;
100
+ /**
101
+ * The function `reverseBegin()` is a generator that yields elements in reverse order starting from
102
+ * the last element.
103
+ */
104
+ reverseBegin(): Generator<E>;
105
+ /**
106
+ * Time Complexity - Amortized O(1) (possible reallocation)
107
+ * Space Complexity - O(n) (due to potential resizing).
108
+ */
109
+ /**
110
+ * Time Complexity - Amortized O(1) (possible reallocation),
111
+ * Space Complexity - O(n) (due to potential resizing).
112
+ *
113
+ * The push function adds an element to a data structure and reallocates memory if necessary.
114
+ * @param {E} element - The `element` parameter represents the value that you want to add to the data
115
+ * structure.
116
+ * @returns The size of the data structure after the element has been pushed.
117
+ */
99
118
  push(element: E): number;
119
+ /**
120
+ * Time Complexity: O(1)
121
+ * Space Complexity: O(1)
122
+ */
123
+ /**
124
+ * Time Complexity: O(1)
125
+ * Space Complexity: O(1)
126
+ *
127
+ * The `pop()` function removes and returns the last element from a data structure, updating the
128
+ * internal state variables accordingly.
129
+ * @returns The element that was removed from the data structure is being returned.
130
+ */
100
131
  pop(): E | undefined;
132
+ /**
133
+ * Time Complexity: Amortized O(1)
134
+ * Space Complexity: O(n)
135
+ */
136
+ /**
137
+ * Time Complexity: Amortized O(1)
138
+ * Space Complexity: O(n)
139
+ *
140
+ * The `unshift` function adds an element to the beginning of an array-like data structure and
141
+ * returns the new size of the structure.
142
+ * @param {E} element - The `element` parameter represents the element that you want to add to the
143
+ * beginning of the data structure.
144
+ * @returns The size of the data structure after the element has been added.
145
+ */
101
146
  unshift(element: E): number;
147
+ /**
148
+ * Time Complexity: O(1)
149
+ * Space Complexity: O(1)
150
+ */
151
+ /**
152
+ * Time Complexity: O(1)
153
+ * Space Complexity: O(1)
154
+ *
155
+ * The `shift()` function removes and returns the first element from a data structure, updating the
156
+ * internal state variables accordingly.
157
+ * @returns The element that is being removed from the beginning of the data structure is being
158
+ * returned.
159
+ */
102
160
  shift(): E | undefined;
161
+ /**
162
+ * Time Complexity: O(1)
163
+ * Space Complexity: O(1)
164
+ */
165
+ /**
166
+ * Time Complexity: O(1)
167
+ * Space Complexity: O(1)
168
+ *
169
+ * The `getAt` function retrieves an element at a specified position in an array-like data structure.
170
+ * @param {number} pos - The `pos` parameter represents the position of the element that you want to
171
+ * retrieve from the data structure. It is of type `number` and should be a valid index within the
172
+ * range of the data structure.
173
+ * @returns The element at the specified position in the data structure is being returned.
174
+ */
103
175
  getAt(pos: number): E;
176
+ /**
177
+ * Time Complexity: O(1)
178
+ * Space Complexity: O(1)
179
+ */
180
+ /**
181
+ * Time Complexity: O(1)
182
+ * Space Complexity: O(1)
183
+ *
184
+ * The `setAt` function sets an element at a specific position in an array-like data structure.
185
+ * @param {number} pos - The `pos` parameter represents the position at which the element needs to be
186
+ * set. It is of type `number`.
187
+ * @param {E} element - The `element` parameter is the value that you want to set at the specified
188
+ * position in the data structure.
189
+ */
104
190
  setAt(pos: number, element: E): void;
191
+ /**
192
+ * Time Complexity: O(n)
193
+ * Space Complexity: O(n)
194
+ */
195
+ /**
196
+ * Time Complexity: O(n)
197
+ * Space Complexity: O(n)
198
+ *
199
+ * The `insertAt` function inserts one or more elements at a specified position in an array-like data
200
+ * structure.
201
+ * @param {number} pos - The `pos` parameter represents the position at which the element(s) should
202
+ * be inserted. It is of type `number`.
203
+ * @param {E} element - The `element` parameter represents the element that you want to insert into
204
+ * the array at the specified position.
205
+ * @param [num=1] - The `num` parameter represents the number of times the `element` should be
206
+ * inserted at the specified position (`pos`). By default, it is set to 1, meaning that the `element`
207
+ * will be inserted once. However, you can provide a different value for `num` if you want
208
+ * @returns The size of the array after the insertion is being returned.
209
+ */
105
210
  insertAt(pos: number, element: E, num?: number): number;
211
+ /**
212
+ * Time Complexity: O(1)
213
+ * Space Complexity: O(1)
214
+ */
215
+ /**
216
+ * Time Complexity: O(1)
217
+ * Space Complexity: O(1)
218
+ *
219
+ * The `cut` function updates the state of the object based on the given position and returns the
220
+ * updated size.
221
+ * @param {number} pos - The `pos` parameter represents the position at which the string should be
222
+ * cut. It is a number that indicates the index of the character where the cut should be made.
223
+ * @returns The method is returning the updated size of the data structure.
224
+ */
106
225
  cut(pos: number): number;
226
+ /**
227
+ * Time Complexity: O(n)
228
+ * Space Complexity: O(1)
229
+ */
230
+ /**
231
+ * Time Complexity: O(n)
232
+ * Space Complexity: O(1)
233
+ *
234
+ * The `deleteAt` function removes an element at a specified position in an array-like data
235
+ * structure.
236
+ * @param {number} pos - The `pos` parameter in the `deleteAt` function represents the position at
237
+ * which an element needs to be deleted from the data structure. It is of type `number` and indicates
238
+ * the index of the element to be deleted.
239
+ * @returns The size of the data structure after the deletion operation is performed.
240
+ */
107
241
  deleteAt(pos: number): number;
242
+ /**
243
+ * Time Complexity: O(n)
244
+ * Space Complexity: O(1)
245
+ */
246
+ /**
247
+ * Time Complexity: O(n)
248
+ * Space Complexity: O(1)
249
+ *
250
+ * The `delete` function removes all occurrences of a specified element from an array-like data
251
+ * structure.
252
+ * @param {E} element - The `element` parameter represents the element that you want to delete from
253
+ * the data structure.
254
+ * @returns The size of the data structure after the element has been deleted.
255
+ */
108
256
  delete(element: E): number;
109
- deleteByIterator(iter: DequeIterator<E>): DequeIterator<E>;
110
- findIterator(element: E): DequeIterator<E>;
257
+ /**
258
+ * Time Complexity: O(n)
259
+ * Space Complexity: O(1)
260
+ */
261
+ /**
262
+ * Time Complexity: O(n)
263
+ * Space Complexity: O(1)
264
+ *
265
+ * The reverse() function reverses the order of the buckets and the elements within each bucket in a
266
+ * data structure.
267
+ * @returns The reverse() method is returning the object itself (this) after performing the reverse
268
+ * operation on the buckets and updating the relevant properties.
269
+ */
111
270
  reverse(): this;
271
+ /**
272
+ * Time Complexity: O(n)
273
+ * Space Complexity: O(1)
274
+ */
275
+ /**
276
+ * Time Complexity: O(n)
277
+ * Space Complexity: O(1)
278
+ *
279
+ * The `unique()` function removes duplicate elements from an array-like data structure and returns
280
+ * the number of unique elements.
281
+ * @returns The size of the modified array is being returned.
282
+ */
112
283
  unique(): number;
284
+ /**
285
+ * Time Complexity: O(n log n)
286
+ * Space Complexity: O(n)
287
+ */
288
+ /**
289
+ * Time Complexity: O(n log n)
290
+ * Space Complexity: O(n)
291
+ *
292
+ * The `sort` function sorts the elements in a data structure using a provided comparator function.
293
+ * @param [comparator] - The `comparator` parameter is a function that takes in two elements `x` and
294
+ * `y` of type `E` and returns a number. The comparator function is used to determine the order of
295
+ * the elements in the sorted array.
296
+ * @returns The method is returning the sorted instance of the object on which the method is called.
297
+ */
113
298
  sort(comparator?: (x: E, y: E) => number): this;
299
+ /**
300
+ * Time Complexity: O(n)
301
+ * Space Complexity: O(n)
302
+ */
303
+ /**
304
+ * Time Complexity: O(n)
305
+ * Space Complexity: O(n)
306
+ *
307
+ * The `shrinkToFit` function reorganizes the elements in an array-like data structure to minimize
308
+ * memory usage.
309
+ * @returns Nothing is being returned. The function is using the `return` statement to exit early if
310
+ * `this.size` is 0, but it does not return any value.
311
+ */
114
312
  shrinkToFit(): void;
313
+ /**
314
+ * Time Complexity: O(n)
315
+ * Space Complexity: O(1)
316
+ */
317
+ /**
318
+ * Time Complexity: O(n)
319
+ * Space Complexity: O(1)
320
+ *
321
+ * The `forEach` function iterates over each element in a deque and applies a callback function to
322
+ * each element.
323
+ * @param callback - The callback parameter is a function that will be called for each element in the
324
+ * deque. It takes three parameters:
325
+ */
115
326
  forEach(callback: (element: E, index: number, deque: Deque<E>) => void): void;
327
+ /**
328
+ * Time Complexity: O(n)
329
+ * Space Complexity: O(1)
330
+ */
331
+ /**
332
+ * Time Complexity: O(n)
333
+ * Space Complexity: O(1)
334
+ *
335
+ * The `find` function iterates over the elements in a deque and returns the first element for which
336
+ * the callback function returns true, or undefined if no such element is found.
337
+ * @param callback - A function that takes three parameters: element, index, and deque. It should
338
+ * return a boolean value indicating whether the element satisfies a certain condition.
339
+ * @returns The method `find` returns the first element in the deque that satisfies the condition
340
+ * specified by the callback function. If no element satisfies the condition, it returns `undefined`.
341
+ */
116
342
  find(callback: (element: E, index: number, deque: Deque<E>) => boolean): E | undefined;
343
+ /**
344
+ * Time Complexity: O(n)
345
+ * Space Complexity: O(n)
346
+ */
347
+ /**
348
+ * Time Complexity: O(n)
349
+ * Space Complexity: O(n)
350
+ *
351
+ * The `toArray` function converts the elements of a data structure into an array.
352
+ * @returns The `toArray()` method is returning an array of elements of type `E`.
353
+ */
117
354
  toArray(): E[];
355
+ /**
356
+ * Time Complexity: O(n)
357
+ * Space Complexity: O(n)
358
+ */
359
+ /**
360
+ * Time Complexity: O(n)
361
+ * Space Complexity: O(n)
362
+ *
363
+ * The `map` function takes a callback function and applies it to each element in the deque,
364
+ * returning a new deque with the results.
365
+ * @param callback - The `callback` parameter is a function that takes three arguments:
366
+ * @returns The `map` method is returning a new `Deque` object with the transformed elements.
367
+ */
118
368
  map<T>(callback: (element: E, index: number, deque: Deque<E>) => T): Deque<T>;
369
+ /**
370
+ * Time Complexity: O(n)
371
+ * Space Complexity: O(n)
372
+ */
373
+ /**
374
+ * Time Complexity: O(n)
375
+ * Space Complexity: O(n)
376
+ *
377
+ * The `filter` function creates a new deque containing only the elements that satisfy the given
378
+ * predicate function.
379
+ * @param predicate - The `predicate` parameter is a function that takes three arguments: `element`,
380
+ * `index`, and `deque`.
381
+ * @returns The `filter` method is returning a new `Deque` object that contains only the elements
382
+ * that satisfy the given `predicate` function.
383
+ */
119
384
  filter(predicate: (element: E, index: number, deque: Deque<E>) => boolean): Deque<E>;
385
+ /**
386
+ * Time Complexity: O(n)
387
+ * Space Complexity: O(1)
388
+ */
389
+ /**
390
+ * Time Complexity: O(n)
391
+ * Space Complexity: O(1)
392
+ *
393
+ * The `reduce` function iterates over the elements of a deque and applies a callback function to
394
+ * each element, accumulating a single value.
395
+ * @param callback - The `callback` parameter is a function that takes four arguments:
396
+ * @param {T} initialValue - The `initialValue` parameter is the initial value of the accumulator. It
397
+ * is the value that will be passed as the first argument to the `callback` function when reducing
398
+ * the elements of the deque.
399
+ * @returns the final value of the accumulator after iterating over all elements in the deque and
400
+ * applying the callback function to each element.
401
+ */
120
402
  reduce<T>(callback: (accumulator: T, element: E, index: number, deque: Deque<E>) => T, initialValue: T): T;
403
+ /**
404
+ * Time Complexity: O(n)
405
+ * Space Complexity: O(1)
406
+ */
407
+ /**
408
+ * Time Complexity: O(n)
409
+ * Space Complexity: O(1)
410
+ *
411
+ * The function "indexOf" returns the index of the first occurrence of a given element in an array,
412
+ * or -1 if the element is not found.
413
+ * @param {E} element - The "element" parameter represents the element that you want to find the
414
+ * index of in the data structure.
415
+ * @returns The indexOf function returns the index of the first occurrence of the specified element
416
+ * in the data structure. If the element is not found, it returns -1.
417
+ */
121
418
  indexOf(element: E): number;
419
+ /**
420
+ * Time Complexity: O(n)
421
+ * Space Complexity: O(1)
422
+ */
423
+ /**
424
+ * Time Complexity: O(n)
425
+ * Space Complexity: O(1)
426
+ *
427
+ * The above function is an implementation of the iterator protocol in TypeScript, allowing the
428
+ * object to be iterated over using a for...of loop.
429
+ */
122
430
  [Symbol.iterator](): Generator<E, void, unknown>;
431
+ /**
432
+ * Time Complexity: O(n)
433
+ * Space Complexity: O(n)
434
+ */
435
+ /**
436
+ * Time Complexity: O(n)
437
+ * Space Complexity: O(n)
438
+ *
439
+ * The `_reallocate` function reallocates the buckets in an array, adding new buckets if needed.
440
+ * @param {number} [needBucketNum] - The `needBucketNum` parameter is an optional number that
441
+ * specifies the number of new buckets needed. If not provided, it will default to half of the
442
+ * current bucket count (`this._bucketCount >> 1`) or 1 if the current bucket count is less than 2.
443
+ */
123
444
  protected _reallocate(needBucketNum?: number): void;
445
+ /**
446
+ * Time Complexity: O(1)
447
+ * Space Complexity: O(1)
448
+ */
449
+ /**
450
+ * Time Complexity: O(1)
451
+ * Space Complexity: O(1)
452
+ *
453
+ * The function calculates the bucket index and index within the bucket based on the given position.
454
+ * @param {number} pos - The `pos` parameter represents the position within the data structure. It is
455
+ * a number that indicates the index or position of an element within the structure.
456
+ * @returns an object with two properties: "bucketIndex" and "indexInBucket".
457
+ */
124
458
  protected _getBucketAndPosition(pos: number): {
125
459
  bucketIndex: number;
126
460
  indexInBucket: number;