data-structure-typed 1.50.2 → 1.50.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.
- package/CHANGELOG.md +1 -1
- package/README.md +17 -15
- package/README_zh-CN.md +1 -1
- package/SPECIFICATION.md +56 -0
- package/SPONSOR-zh-CN.md +90 -0
- package/SPONSOR.md +54 -0
- package/benchmark/report.html +13 -13
- package/benchmark/report.json +149 -155
- package/dist/cjs/data-structures/base/iterable-base.d.ts +6 -0
- package/dist/cjs/data-structures/base/iterable-base.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/avl-tree.d.ts +29 -1
- package/dist/cjs/data-structures/binary-tree/avl-tree.js +33 -1
- package/dist/cjs/data-structures/binary-tree/avl-tree.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/binary-indexed-tree.d.ts +22 -0
- package/dist/cjs/data-structures/binary-tree/binary-indexed-tree.js +22 -0
- package/dist/cjs/data-structures/binary-tree/binary-indexed-tree.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/binary-tree.d.ts +1 -1
- package/dist/cjs/data-structures/binary-tree/binary-tree.js +1 -1
- package/dist/cjs/data-structures/binary-tree/bst.d.ts +46 -13
- package/dist/cjs/data-structures/binary-tree/bst.js +46 -13
- package/dist/cjs/data-structures/binary-tree/bst.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/rb-tree.d.ts +54 -2
- package/dist/cjs/data-structures/binary-tree/rb-tree.js +73 -15
- package/dist/cjs/data-structures/binary-tree/rb-tree.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/segment-tree.d.ts +99 -6
- package/dist/cjs/data-structures/binary-tree/segment-tree.js +127 -10
- package/dist/cjs/data-structures/binary-tree/segment-tree.js.map +1 -1
- package/dist/cjs/data-structures/binary-tree/tree-multimap.d.ts +35 -2
- package/dist/cjs/data-structures/binary-tree/tree-multimap.js +38 -0
- package/dist/cjs/data-structures/binary-tree/tree-multimap.js.map +1 -1
- package/dist/cjs/data-structures/graph/abstract-graph.d.ts +0 -78
- package/dist/cjs/data-structures/graph/abstract-graph.js +0 -189
- package/dist/cjs/data-structures/graph/abstract-graph.js.map +1 -1
- package/dist/cjs/data-structures/graph/directed-graph.d.ts +59 -0
- package/dist/cjs/data-structures/graph/directed-graph.js +105 -0
- package/dist/cjs/data-structures/graph/directed-graph.js.map +1 -1
- package/dist/cjs/data-structures/graph/undirected-graph.d.ts +60 -7
- package/dist/cjs/data-structures/graph/undirected-graph.js +126 -18
- package/dist/cjs/data-structures/graph/undirected-graph.js.map +1 -1
- package/dist/cjs/data-structures/hash/hash-map.d.ts +143 -23
- package/dist/cjs/data-structures/hash/hash-map.js +196 -62
- package/dist/cjs/data-structures/hash/hash-map.js.map +1 -1
- package/dist/cjs/data-structures/heap/heap.d.ts +29 -19
- package/dist/cjs/data-structures/heap/heap.js +29 -20
- package/dist/cjs/data-structures/heap/heap.js.map +1 -1
- package/dist/cjs/data-structures/linked-list/doubly-linked-list.d.ts +71 -25
- package/dist/cjs/data-structures/linked-list/doubly-linked-list.js +83 -25
- 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 +26 -3
- package/dist/cjs/data-structures/linked-list/singly-linked-list.js +34 -3
- 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 +2 -2
- package/dist/cjs/data-structures/linked-list/skip-linked-list.js +2 -2
- package/dist/cjs/data-structures/matrix/matrix.d.ts +1 -1
- package/dist/cjs/data-structures/matrix/matrix.js +1 -1
- package/dist/cjs/data-structures/priority-queue/max-priority-queue.d.ts +10 -0
- package/dist/cjs/data-structures/priority-queue/max-priority-queue.js +10 -0
- package/dist/cjs/data-structures/priority-queue/max-priority-queue.js.map +1 -1
- package/dist/cjs/data-structures/priority-queue/min-priority-queue.d.ts +11 -0
- package/dist/cjs/data-structures/priority-queue/min-priority-queue.js +11 -0
- package/dist/cjs/data-structures/priority-queue/min-priority-queue.js.map +1 -1
- package/dist/cjs/data-structures/priority-queue/priority-queue.d.ts +8 -0
- package/dist/cjs/data-structures/priority-queue/priority-queue.js +8 -0
- package/dist/cjs/data-structures/priority-queue/priority-queue.js.map +1 -1
- package/dist/cjs/data-structures/queue/deque.d.ts +95 -21
- package/dist/cjs/data-structures/queue/deque.js +100 -16
- package/dist/cjs/data-structures/queue/deque.js.map +1 -1
- package/dist/cjs/data-structures/queue/queue.d.ts +65 -45
- package/dist/cjs/data-structures/queue/queue.js +65 -45
- package/dist/cjs/data-structures/queue/queue.js.map +1 -1
- package/dist/cjs/data-structures/stack/stack.d.ts +36 -22
- package/dist/cjs/data-structures/stack/stack.js +36 -22
- package/dist/cjs/data-structures/stack/stack.js.map +1 -1
- package/dist/cjs/data-structures/tree/tree.d.ts +57 -3
- package/dist/cjs/data-structures/tree/tree.js +77 -11
- package/dist/cjs/data-structures/tree/tree.js.map +1 -1
- package/dist/cjs/data-structures/trie/trie.d.ts +100 -36
- package/dist/cjs/data-structures/trie/trie.js +115 -36
- package/dist/cjs/data-structures/trie/trie.js.map +1 -1
- package/dist/mjs/data-structures/base/iterable-base.d.ts +6 -0
- package/dist/mjs/data-structures/binary-tree/avl-tree.d.ts +29 -1
- package/dist/mjs/data-structures/binary-tree/avl-tree.js +34 -2
- package/dist/mjs/data-structures/binary-tree/binary-indexed-tree.d.ts +22 -0
- package/dist/mjs/data-structures/binary-tree/binary-indexed-tree.js +22 -0
- package/dist/mjs/data-structures/binary-tree/binary-tree.d.ts +1 -1
- package/dist/mjs/data-structures/binary-tree/binary-tree.js +1 -1
- package/dist/mjs/data-structures/binary-tree/bst.d.ts +46 -13
- package/dist/mjs/data-structures/binary-tree/bst.js +46 -13
- package/dist/mjs/data-structures/binary-tree/rb-tree.d.ts +54 -2
- package/dist/mjs/data-structures/binary-tree/rb-tree.js +74 -16
- package/dist/mjs/data-structures/binary-tree/segment-tree.d.ts +99 -6
- package/dist/mjs/data-structures/binary-tree/segment-tree.js +127 -10
- package/dist/mjs/data-structures/binary-tree/tree-multimap.d.ts +35 -2
- package/dist/mjs/data-structures/binary-tree/tree-multimap.js +38 -1
- package/dist/mjs/data-structures/graph/abstract-graph.d.ts +0 -78
- package/dist/mjs/data-structures/graph/abstract-graph.js +0 -188
- package/dist/mjs/data-structures/graph/directed-graph.d.ts +59 -0
- package/dist/mjs/data-structures/graph/directed-graph.js +105 -0
- package/dist/mjs/data-structures/graph/undirected-graph.d.ts +60 -7
- package/dist/mjs/data-structures/graph/undirected-graph.js +127 -19
- package/dist/mjs/data-structures/hash/hash-map.d.ts +143 -23
- package/dist/mjs/data-structures/hash/hash-map.js +204 -70
- package/dist/mjs/data-structures/heap/heap.d.ts +29 -19
- package/dist/mjs/data-structures/heap/heap.js +29 -20
- package/dist/mjs/data-structures/linked-list/doubly-linked-list.d.ts +71 -25
- package/dist/mjs/data-structures/linked-list/doubly-linked-list.js +86 -28
- package/dist/mjs/data-structures/linked-list/singly-linked-list.d.ts +26 -3
- package/dist/mjs/data-structures/linked-list/singly-linked-list.js +36 -5
- package/dist/mjs/data-structures/linked-list/skip-linked-list.d.ts +2 -2
- package/dist/mjs/data-structures/linked-list/skip-linked-list.js +2 -2
- package/dist/mjs/data-structures/matrix/matrix.d.ts +1 -1
- package/dist/mjs/data-structures/matrix/matrix.js +1 -1
- package/dist/mjs/data-structures/priority-queue/max-priority-queue.d.ts +10 -0
- package/dist/mjs/data-structures/priority-queue/max-priority-queue.js +10 -0
- package/dist/mjs/data-structures/priority-queue/min-priority-queue.d.ts +11 -0
- package/dist/mjs/data-structures/priority-queue/min-priority-queue.js +11 -0
- package/dist/mjs/data-structures/priority-queue/priority-queue.d.ts +8 -0
- package/dist/mjs/data-structures/priority-queue/priority-queue.js +8 -0
- package/dist/mjs/data-structures/queue/deque.d.ts +95 -21
- package/dist/mjs/data-structures/queue/deque.js +105 -21
- package/dist/mjs/data-structures/queue/queue.d.ts +65 -45
- package/dist/mjs/data-structures/queue/queue.js +65 -45
- package/dist/mjs/data-structures/stack/stack.d.ts +36 -22
- package/dist/mjs/data-structures/stack/stack.js +36 -22
- package/dist/mjs/data-structures/tree/tree.d.ts +57 -3
- package/dist/mjs/data-structures/tree/tree.js +80 -14
- package/dist/mjs/data-structures/trie/trie.d.ts +100 -36
- package/dist/mjs/data-structures/trie/trie.js +118 -39
- package/dist/umd/data-structure-typed.js +1445 -595
- package/dist/umd/data-structure-typed.min.js +2 -2
- package/dist/umd/data-structure-typed.min.js.map +1 -1
- package/package.json +59 -58
- package/src/data-structures/base/iterable-base.ts +12 -0
- package/src/data-structures/binary-tree/avl-tree.ts +37 -3
- package/src/data-structures/binary-tree/binary-indexed-tree.ts +22 -0
- package/src/data-structures/binary-tree/binary-tree.ts +1 -1
- package/src/data-structures/binary-tree/bst.ts +46 -13
- package/src/data-structures/binary-tree/rb-tree.ts +79 -18
- package/src/data-structures/binary-tree/segment-tree.ts +145 -11
- package/src/data-structures/binary-tree/tree-multimap.ts +42 -3
- package/src/data-structures/graph/abstract-graph.ts +0 -211
- package/src/data-structures/graph/directed-graph.ts +122 -0
- package/src/data-structures/graph/undirected-graph.ts +143 -19
- package/src/data-structures/hash/hash-map.ts +228 -76
- package/src/data-structures/heap/heap.ts +31 -20
- package/src/data-structures/linked-list/doubly-linked-list.ts +96 -29
- package/src/data-structures/linked-list/singly-linked-list.ts +42 -6
- package/src/data-structures/linked-list/skip-linked-list.ts +2 -2
- package/src/data-structures/matrix/matrix.ts +1 -1
- package/src/data-structures/priority-queue/max-priority-queue.ts +10 -0
- package/src/data-structures/priority-queue/min-priority-queue.ts +11 -0
- package/src/data-structures/priority-queue/priority-queue.ts +8 -0
- package/src/data-structures/queue/deque.ts +118 -22
- package/src/data-structures/queue/queue.ts +68 -45
- package/src/data-structures/stack/stack.ts +39 -23
- package/src/data-structures/tree/tree.ts +89 -15
- package/src/data-structures/trie/trie.ts +131 -40
- package/test/performance/data-structures/graph/directed-graph.test.ts +1 -1
- package/test/unit/data-structures/graph/abstract-graph.test.ts +3 -0
- package/test/unit/data-structures/graph/directed-graph.test.ts +189 -253
- package/test/unit/data-structures/graph/undirected-graph.test.ts +263 -18
- package/test/unit/data-structures/queue/queue.test.ts +2 -0
|
@@ -15,12 +15,6 @@ import { IterableElementBase } from '../base';
|
|
|
15
15
|
* 5. Performance jitter: Deque may experience performance jitter, but DoublyLinkedList will not
|
|
16
16
|
*/
|
|
17
17
|
export declare class Deque<E> extends IterableElementBase<E> {
|
|
18
|
-
protected _bucketFirst: number;
|
|
19
|
-
protected _firstInBucket: number;
|
|
20
|
-
protected _bucketLast: number;
|
|
21
|
-
protected _lastInBucket: number;
|
|
22
|
-
protected _bucketCount: number;
|
|
23
|
-
protected readonly _bucketSize: number;
|
|
24
18
|
/**
|
|
25
19
|
* The constructor initializes a Deque object with an optional iterable of elements and options.
|
|
26
20
|
* @param elements - An iterable object (such as an array or a Set) that contains the initial
|
|
@@ -33,16 +27,48 @@ export declare class Deque<E> extends IterableElementBase<E> {
|
|
|
33
27
|
* or is not a number
|
|
34
28
|
*/
|
|
35
29
|
constructor(elements?: IterableWithSizeOrLength<E>, options?: DequeOptions);
|
|
30
|
+
protected _bucketSize: number;
|
|
36
31
|
/**
|
|
37
32
|
* The bucketSize function returns the size of the bucket.
|
|
38
33
|
*
|
|
39
34
|
* @return The size of the bucket
|
|
40
35
|
*/
|
|
41
36
|
get bucketSize(): number;
|
|
37
|
+
protected _bucketFirst: number;
|
|
38
|
+
/**
|
|
39
|
+
* The function returns the value of the protected variable `_bucketFirst`.
|
|
40
|
+
* @returns The value of the `_bucketFirst` property.
|
|
41
|
+
*/
|
|
42
|
+
get bucketFirst(): number;
|
|
43
|
+
protected _firstInBucket: number;
|
|
44
|
+
/**
|
|
45
|
+
* The function returns the value of the protected variable _firstInBucket.
|
|
46
|
+
* @returns The method is returning the value of the variable `_firstInBucket`, which is of type
|
|
47
|
+
* `number`.
|
|
48
|
+
*/
|
|
49
|
+
get firstInBucket(): number;
|
|
50
|
+
protected _bucketLast: number;
|
|
51
|
+
/**
|
|
52
|
+
* The function returns the value of the protected variable `_bucketLast`.
|
|
53
|
+
* @returns The value of the `_bucketLast` property, which is a number.
|
|
54
|
+
*/
|
|
55
|
+
get bucketLast(): number;
|
|
56
|
+
protected _lastInBucket: number;
|
|
57
|
+
/**
|
|
58
|
+
* The function returns the value of the protected variable _lastInBucket.
|
|
59
|
+
* @returns The method is returning the value of the variable `_lastInBucket`, which is of type
|
|
60
|
+
* `number`.
|
|
61
|
+
*/
|
|
62
|
+
get lastInBucket(): number;
|
|
63
|
+
protected _bucketCount: number;
|
|
64
|
+
/**
|
|
65
|
+
* The function returns the number of buckets.
|
|
66
|
+
* @returns The number of buckets.
|
|
67
|
+
*/
|
|
68
|
+
get bucketCount(): number;
|
|
42
69
|
protected _buckets: E[][];
|
|
43
70
|
/**
|
|
44
71
|
* The buckets function returns the buckets property of the object.
|
|
45
|
-
*
|
|
46
72
|
* @return The buckets property
|
|
47
73
|
*/
|
|
48
74
|
get buckets(): E[][];
|
|
@@ -120,11 +146,25 @@ export declare class Deque<E> extends IterableElementBase<E> {
|
|
|
120
146
|
*/
|
|
121
147
|
shift(): E | undefined;
|
|
122
148
|
/**
|
|
123
|
-
* Time Complexity: O(1)
|
|
124
|
-
* Space Complexity: O(1)
|
|
149
|
+
* Time Complexity: O(1)
|
|
150
|
+
* Space Complexity: O(1)
|
|
151
|
+
*/
|
|
152
|
+
/**
|
|
153
|
+
* Time Complexity: O(1)
|
|
154
|
+
* Space Complexity: O(1)
|
|
155
|
+
*
|
|
156
|
+
* The function checks if the size of an object is equal to zero and returns a boolean value.
|
|
157
|
+
* @returns A boolean value indicating whether the size of the object is 0 or not.
|
|
125
158
|
*/
|
|
126
159
|
isEmpty(): boolean;
|
|
127
160
|
/**
|
|
161
|
+
* Time Complexity: O(1)
|
|
162
|
+
* Space Complexity: O(1)
|
|
163
|
+
*/
|
|
164
|
+
/**
|
|
165
|
+
* Time Complexity: O(1)
|
|
166
|
+
* Space Complexity: O(1)
|
|
167
|
+
*
|
|
128
168
|
* The clear() function resets the state of the object by initializing all variables to their default
|
|
129
169
|
* values.
|
|
130
170
|
*/
|
|
@@ -204,14 +244,33 @@ export declare class Deque<E> extends IterableElementBase<E> {
|
|
|
204
244
|
* @returns The method is returning the updated size of the data structure.
|
|
205
245
|
*/
|
|
206
246
|
cut(pos: number, isCutSelf?: boolean): Deque<E>;
|
|
247
|
+
/**
|
|
248
|
+
* Time Complexity: O(1)
|
|
249
|
+
* Space Complexity: O(1) or O(n)
|
|
250
|
+
*/
|
|
251
|
+
/**
|
|
252
|
+
* Time Complexity: O(1)
|
|
253
|
+
* Space Complexity: O(1) or O(n)
|
|
254
|
+
*
|
|
255
|
+
* The `cutRest` function cuts the elements from a specified position in a deque and returns a new
|
|
256
|
+
* deque with the cut elements.
|
|
257
|
+
* @param {number} pos - The `pos` parameter represents the position from which to cut the Deque. It
|
|
258
|
+
* is a number that indicates the index of the element in the Deque where the cut should start.
|
|
259
|
+
* @param [isCutSelf=false] - isCutSelf is a boolean parameter that determines whether the original
|
|
260
|
+
* Deque should be modified or a new Deque should be created. If isCutSelf is true, the original
|
|
261
|
+
* Deque will be modified by cutting off elements starting from the specified position. If isCutSelf
|
|
262
|
+
* is false, a new De
|
|
263
|
+
* @returns The function `cutRest` returns either the modified original deque (`this`) or a new deque
|
|
264
|
+
* (`newDeque`) depending on the value of the `isCutSelf` parameter.
|
|
265
|
+
*/
|
|
207
266
|
cutRest(pos: number, isCutSelf?: boolean): Deque<E>;
|
|
208
267
|
/**
|
|
209
268
|
* Time Complexity: O(n)
|
|
210
|
-
* Space Complexity: O(1)
|
|
269
|
+
* Space Complexity: O(1) or O(n)
|
|
211
270
|
*/
|
|
212
271
|
/**
|
|
213
272
|
* Time Complexity: O(n)
|
|
214
|
-
* Space Complexity: O(1)
|
|
273
|
+
* Space Complexity: O(1) or O(n)
|
|
215
274
|
*
|
|
216
275
|
* The `deleteAt` function removes an element at a specified position in an array-like data
|
|
217
276
|
* structure.
|
|
@@ -378,8 +437,8 @@ export declare class Deque<E> extends IterableElementBase<E> {
|
|
|
378
437
|
* Space Complexity: O(n) - Due to potential resizing.
|
|
379
438
|
*/
|
|
380
439
|
/**
|
|
381
|
-
* Time Complexity: O(1)
|
|
382
|
-
* Space Complexity: O(n) -
|
|
440
|
+
* Time Complexity: Amortized O(1) - Similar to push, resizing leads to O(n).
|
|
441
|
+
* Space Complexity: O(n) - Due to potential resizing.
|
|
383
442
|
*
|
|
384
443
|
* The addLast function adds an element to the end of an array.
|
|
385
444
|
* @param {E} element - The element parameter represents the element that you want to add to the end of the
|
|
@@ -387,20 +446,25 @@ export declare class Deque<E> extends IterableElementBase<E> {
|
|
|
387
446
|
*/
|
|
388
447
|
addLast(element: E): boolean;
|
|
389
448
|
/**
|
|
390
|
-
* Time Complexity: O(1)
|
|
391
|
-
* Space Complexity: O(1)
|
|
449
|
+
* Time Complexity: O(1)
|
|
450
|
+
* Space Complexity: O(1)
|
|
392
451
|
*/
|
|
393
452
|
/**
|
|
394
|
-
* Time Complexity: O(1)
|
|
395
|
-
* Space Complexity: O(1)
|
|
453
|
+
* Time Complexity: O(1)
|
|
454
|
+
* Space Complexity: O(1)
|
|
396
455
|
*
|
|
397
456
|
* The function "pollLast" removes and returns the last element of an array.
|
|
398
457
|
* @returns The last element of the array is being returned.
|
|
399
458
|
*/
|
|
400
459
|
pollLast(): E | undefined;
|
|
401
460
|
/**
|
|
402
|
-
* Time Complexity: O(1)
|
|
403
|
-
* Space Complexity: O(
|
|
461
|
+
* Time Complexity: O(1)
|
|
462
|
+
* Space Complexity: O(1)
|
|
463
|
+
* /
|
|
464
|
+
|
|
465
|
+
/**
|
|
466
|
+
* Time Complexity: O(1)
|
|
467
|
+
* Space Complexity: O(1)
|
|
404
468
|
*
|
|
405
469
|
* The "addFirst" function adds an element to the beginning of an array.
|
|
406
470
|
* @param {E} element - The parameter "element" represents the element that you want to add to the
|
|
@@ -408,8 +472,13 @@ export declare class Deque<E> extends IterableElementBase<E> {
|
|
|
408
472
|
*/
|
|
409
473
|
addFirst(element: E): boolean;
|
|
410
474
|
/**
|
|
411
|
-
* Time Complexity: O(1)
|
|
412
|
-
* Space Complexity: O(1)
|
|
475
|
+
* Time Complexity: O(1)
|
|
476
|
+
* Space Complexity: O(1)
|
|
477
|
+
* /
|
|
478
|
+
|
|
479
|
+
/**
|
|
480
|
+
* Time Complexity: O(1)
|
|
481
|
+
* Space Complexity: O(1)
|
|
413
482
|
*
|
|
414
483
|
* The function "pollFirst" removes and returns the first element of an array.
|
|
415
484
|
* @returns The method `pollFirst()` is returning the first element of the array after removing it
|
|
@@ -417,6 +486,11 @@ export declare class Deque<E> extends IterableElementBase<E> {
|
|
|
417
486
|
*/
|
|
418
487
|
pollFirst(): E | undefined;
|
|
419
488
|
/**
|
|
489
|
+
* Time Complexity: O(n)
|
|
490
|
+
* Space Complexity: O(1)
|
|
491
|
+
* /
|
|
492
|
+
|
|
493
|
+
/**
|
|
420
494
|
* Time Complexity: O(n)
|
|
421
495
|
* Space Complexity: O(1)
|
|
422
496
|
*
|
|
@@ -8,12 +8,6 @@ import { calcMinUnitsRequired, rangeCheck } from '../../utils';
|
|
|
8
8
|
* 5. Performance jitter: Deque may experience performance jitter, but DoublyLinkedList will not
|
|
9
9
|
*/
|
|
10
10
|
export class Deque extends IterableElementBase {
|
|
11
|
-
_bucketFirst = 0;
|
|
12
|
-
_firstInBucket = 0;
|
|
13
|
-
_bucketLast = 0;
|
|
14
|
-
_lastInBucket = 0;
|
|
15
|
-
_bucketCount = 0;
|
|
16
|
-
_bucketSize = 1 << 12;
|
|
17
11
|
/**
|
|
18
12
|
* The constructor initializes a Deque object with an optional iterable of elements and options.
|
|
19
13
|
* @param elements - An iterable object (such as an array or a Set) that contains the initial
|
|
@@ -56,6 +50,7 @@ export class Deque extends IterableElementBase {
|
|
|
56
50
|
this.push(element);
|
|
57
51
|
}
|
|
58
52
|
}
|
|
53
|
+
_bucketSize = 1 << 12;
|
|
59
54
|
/**
|
|
60
55
|
* The bucketSize function returns the size of the bucket.
|
|
61
56
|
*
|
|
@@ -64,10 +59,51 @@ export class Deque extends IterableElementBase {
|
|
|
64
59
|
get bucketSize() {
|
|
65
60
|
return this._bucketSize;
|
|
66
61
|
}
|
|
62
|
+
_bucketFirst = 0;
|
|
63
|
+
/**
|
|
64
|
+
* The function returns the value of the protected variable `_bucketFirst`.
|
|
65
|
+
* @returns The value of the `_bucketFirst` property.
|
|
66
|
+
*/
|
|
67
|
+
get bucketFirst() {
|
|
68
|
+
return this._bucketFirst;
|
|
69
|
+
}
|
|
70
|
+
_firstInBucket = 0;
|
|
71
|
+
/**
|
|
72
|
+
* The function returns the value of the protected variable _firstInBucket.
|
|
73
|
+
* @returns The method is returning the value of the variable `_firstInBucket`, which is of type
|
|
74
|
+
* `number`.
|
|
75
|
+
*/
|
|
76
|
+
get firstInBucket() {
|
|
77
|
+
return this._firstInBucket;
|
|
78
|
+
}
|
|
79
|
+
_bucketLast = 0;
|
|
80
|
+
/**
|
|
81
|
+
* The function returns the value of the protected variable `_bucketLast`.
|
|
82
|
+
* @returns The value of the `_bucketLast` property, which is a number.
|
|
83
|
+
*/
|
|
84
|
+
get bucketLast() {
|
|
85
|
+
return this._bucketLast;
|
|
86
|
+
}
|
|
87
|
+
_lastInBucket = 0;
|
|
88
|
+
/**
|
|
89
|
+
* The function returns the value of the protected variable _lastInBucket.
|
|
90
|
+
* @returns The method is returning the value of the variable `_lastInBucket`, which is of type
|
|
91
|
+
* `number`.
|
|
92
|
+
*/
|
|
93
|
+
get lastInBucket() {
|
|
94
|
+
return this._lastInBucket;
|
|
95
|
+
}
|
|
96
|
+
_bucketCount = 0;
|
|
97
|
+
/**
|
|
98
|
+
* The function returns the number of buckets.
|
|
99
|
+
* @returns The number of buckets.
|
|
100
|
+
*/
|
|
101
|
+
get bucketCount() {
|
|
102
|
+
return this._bucketCount;
|
|
103
|
+
}
|
|
67
104
|
_buckets = [];
|
|
68
105
|
/**
|
|
69
106
|
* The buckets function returns the buckets property of the object.
|
|
70
|
-
*
|
|
71
107
|
* @return The buckets property
|
|
72
108
|
*/
|
|
73
109
|
get buckets() {
|
|
@@ -233,13 +269,27 @@ export class Deque extends IterableElementBase {
|
|
|
233
269
|
return element;
|
|
234
270
|
}
|
|
235
271
|
/**
|
|
236
|
-
* Time Complexity: O(1)
|
|
237
|
-
* Space Complexity: O(1)
|
|
272
|
+
* Time Complexity: O(1)
|
|
273
|
+
* Space Complexity: O(1)
|
|
274
|
+
*/
|
|
275
|
+
/**
|
|
276
|
+
* Time Complexity: O(1)
|
|
277
|
+
* Space Complexity: O(1)
|
|
278
|
+
*
|
|
279
|
+
* The function checks if the size of an object is equal to zero and returns a boolean value.
|
|
280
|
+
* @returns A boolean value indicating whether the size of the object is 0 or not.
|
|
238
281
|
*/
|
|
239
282
|
isEmpty() {
|
|
240
283
|
return this.size === 0;
|
|
241
284
|
}
|
|
242
285
|
/**
|
|
286
|
+
* Time Complexity: O(1)
|
|
287
|
+
* Space Complexity: O(1)
|
|
288
|
+
*/
|
|
289
|
+
/**
|
|
290
|
+
* Time Complexity: O(1)
|
|
291
|
+
* Space Complexity: O(1)
|
|
292
|
+
*
|
|
243
293
|
* The clear() function resets the state of the object by initializing all variables to their default
|
|
244
294
|
* values.
|
|
245
295
|
*/
|
|
@@ -387,6 +437,25 @@ export class Deque extends IterableElementBase {
|
|
|
387
437
|
return newDeque;
|
|
388
438
|
}
|
|
389
439
|
}
|
|
440
|
+
/**
|
|
441
|
+
* Time Complexity: O(1)
|
|
442
|
+
* Space Complexity: O(1) or O(n)
|
|
443
|
+
*/
|
|
444
|
+
/**
|
|
445
|
+
* Time Complexity: O(1)
|
|
446
|
+
* Space Complexity: O(1) or O(n)
|
|
447
|
+
*
|
|
448
|
+
* The `cutRest` function cuts the elements from a specified position in a deque and returns a new
|
|
449
|
+
* deque with the cut elements.
|
|
450
|
+
* @param {number} pos - The `pos` parameter represents the position from which to cut the Deque. It
|
|
451
|
+
* is a number that indicates the index of the element in the Deque where the cut should start.
|
|
452
|
+
* @param [isCutSelf=false] - isCutSelf is a boolean parameter that determines whether the original
|
|
453
|
+
* Deque should be modified or a new Deque should be created. If isCutSelf is true, the original
|
|
454
|
+
* Deque will be modified by cutting off elements starting from the specified position. If isCutSelf
|
|
455
|
+
* is false, a new De
|
|
456
|
+
* @returns The function `cutRest` returns either the modified original deque (`this`) or a new deque
|
|
457
|
+
* (`newDeque`) depending on the value of the `isCutSelf` parameter.
|
|
458
|
+
*/
|
|
390
459
|
cutRest(pos, isCutSelf = false) {
|
|
391
460
|
if (isCutSelf) {
|
|
392
461
|
if (pos < 0) {
|
|
@@ -409,11 +478,11 @@ export class Deque extends IterableElementBase {
|
|
|
409
478
|
}
|
|
410
479
|
/**
|
|
411
480
|
* Time Complexity: O(n)
|
|
412
|
-
* Space Complexity: O(1)
|
|
481
|
+
* Space Complexity: O(1) or O(n)
|
|
413
482
|
*/
|
|
414
483
|
/**
|
|
415
484
|
* Time Complexity: O(n)
|
|
416
|
-
* Space Complexity: O(1)
|
|
485
|
+
* Space Complexity: O(1) or O(n)
|
|
417
486
|
*
|
|
418
487
|
* The `deleteAt` function removes an element at a specified position in an array-like data
|
|
419
488
|
* structure.
|
|
@@ -700,8 +769,8 @@ export class Deque extends IterableElementBase {
|
|
|
700
769
|
* Space Complexity: O(n) - Due to potential resizing.
|
|
701
770
|
*/
|
|
702
771
|
/**
|
|
703
|
-
* Time Complexity: O(1)
|
|
704
|
-
* Space Complexity: O(n) -
|
|
772
|
+
* Time Complexity: Amortized O(1) - Similar to push, resizing leads to O(n).
|
|
773
|
+
* Space Complexity: O(n) - Due to potential resizing.
|
|
705
774
|
*
|
|
706
775
|
* The addLast function adds an element to the end of an array.
|
|
707
776
|
* @param {E} element - The element parameter represents the element that you want to add to the end of the
|
|
@@ -711,12 +780,12 @@ export class Deque extends IterableElementBase {
|
|
|
711
780
|
return this.push(element);
|
|
712
781
|
}
|
|
713
782
|
/**
|
|
714
|
-
* Time Complexity: O(1)
|
|
715
|
-
* Space Complexity: O(1)
|
|
783
|
+
* Time Complexity: O(1)
|
|
784
|
+
* Space Complexity: O(1)
|
|
716
785
|
*/
|
|
717
786
|
/**
|
|
718
|
-
* Time Complexity: O(1)
|
|
719
|
-
* Space Complexity: O(1)
|
|
787
|
+
* Time Complexity: O(1)
|
|
788
|
+
* Space Complexity: O(1)
|
|
720
789
|
*
|
|
721
790
|
* The function "pollLast" removes and returns the last element of an array.
|
|
722
791
|
* @returns The last element of the array is being returned.
|
|
@@ -725,8 +794,13 @@ export class Deque extends IterableElementBase {
|
|
|
725
794
|
return this.pop();
|
|
726
795
|
}
|
|
727
796
|
/**
|
|
728
|
-
* Time Complexity: O(1)
|
|
729
|
-
* Space Complexity: O(
|
|
797
|
+
* Time Complexity: O(1)
|
|
798
|
+
* Space Complexity: O(1)
|
|
799
|
+
* /
|
|
800
|
+
|
|
801
|
+
/**
|
|
802
|
+
* Time Complexity: O(1)
|
|
803
|
+
* Space Complexity: O(1)
|
|
730
804
|
*
|
|
731
805
|
* The "addFirst" function adds an element to the beginning of an array.
|
|
732
806
|
* @param {E} element - The parameter "element" represents the element that you want to add to the
|
|
@@ -736,8 +810,13 @@ export class Deque extends IterableElementBase {
|
|
|
736
810
|
return this.unshift(element);
|
|
737
811
|
}
|
|
738
812
|
/**
|
|
739
|
-
* Time Complexity: O(1)
|
|
740
|
-
* Space Complexity: O(1)
|
|
813
|
+
* Time Complexity: O(1)
|
|
814
|
+
* Space Complexity: O(1)
|
|
815
|
+
* /
|
|
816
|
+
|
|
817
|
+
/**
|
|
818
|
+
* Time Complexity: O(1)
|
|
819
|
+
* Space Complexity: O(1)
|
|
741
820
|
*
|
|
742
821
|
* The function "pollFirst" removes and returns the first element of an array.
|
|
743
822
|
* @returns The method `pollFirst()` is returning the first element of the array after removing it
|
|
@@ -747,6 +826,11 @@ export class Deque extends IterableElementBase {
|
|
|
747
826
|
return this.shift();
|
|
748
827
|
}
|
|
749
828
|
/**
|
|
829
|
+
* Time Complexity: O(n)
|
|
830
|
+
* Space Complexity: O(1)
|
|
831
|
+
* /
|
|
832
|
+
|
|
833
|
+
/**
|
|
750
834
|
* Time Complexity: O(n)
|
|
751
835
|
* Space Complexity: O(1)
|
|
752
836
|
*
|
|
@@ -32,7 +32,7 @@ export declare class Queue<E = any> extends IterableElementBase<E> {
|
|
|
32
32
|
protected _offset: number;
|
|
33
33
|
/**
|
|
34
34
|
* The offset function returns the offset of the current page.
|
|
35
|
-
* @return The value of the
|
|
35
|
+
* @return The value of the protected variable _offset
|
|
36
36
|
*/
|
|
37
37
|
get offset(): number;
|
|
38
38
|
/**
|
|
@@ -41,8 +41,12 @@ export declare class Queue<E = any> extends IterableElementBase<E> {
|
|
|
41
41
|
*/
|
|
42
42
|
get size(): number;
|
|
43
43
|
/**
|
|
44
|
-
* Time Complexity: O(1)
|
|
45
|
-
* Space Complexity: O(1)
|
|
44
|
+
* Time Complexity: O(1)
|
|
45
|
+
* Space Complexity: O(1)
|
|
46
|
+
*/
|
|
47
|
+
/**
|
|
48
|
+
* Time Complexity: O(1)
|
|
49
|
+
* Space Complexity: O(1)
|
|
46
50
|
*
|
|
47
51
|
* The `first` function returns the first element of the array `_elements` if it exists, otherwise it returns `undefined`.
|
|
48
52
|
* @returns The `get first()` method returns the first element of the data structure, represented by the `_elements` array at
|
|
@@ -50,12 +54,12 @@ export declare class Queue<E = any> extends IterableElementBase<E> {
|
|
|
50
54
|
*/
|
|
51
55
|
get first(): E | undefined;
|
|
52
56
|
/**
|
|
53
|
-
* Time Complexity: O(1)
|
|
54
|
-
* Space Complexity: O(1)
|
|
57
|
+
* Time Complexity: O(1)
|
|
58
|
+
* Space Complexity: O(1)
|
|
55
59
|
*/
|
|
56
60
|
/**
|
|
57
|
-
* Time Complexity: O(1)
|
|
58
|
-
* Space Complexity: O(1)
|
|
61
|
+
* Time Complexity: O(1)
|
|
62
|
+
* Space Complexity: O(1)
|
|
59
63
|
*
|
|
60
64
|
* The `last` function returns the last element in an array-like data structure, or undefined if the structure is empty.
|
|
61
65
|
* @returns The method `get last()` returns the last element of the `_elements` array if the array is not empty. If the
|
|
@@ -63,10 +67,13 @@ export declare class Queue<E = any> extends IterableElementBase<E> {
|
|
|
63
67
|
*/
|
|
64
68
|
get last(): E | undefined;
|
|
65
69
|
/**
|
|
66
|
-
* Time Complexity: O(n)
|
|
67
|
-
* Space Complexity: O(
|
|
70
|
+
* Time Complexity: O(n)
|
|
71
|
+
* Space Complexity: O(n)
|
|
68
72
|
*/
|
|
69
73
|
/**
|
|
74
|
+
* Time Complexity: O(n)
|
|
75
|
+
* Space Complexity: O(n)
|
|
76
|
+
*
|
|
70
77
|
* The function "fromArray" creates a new Queue object from an array of elements.Creates a queue from an existing array.
|
|
71
78
|
* @public
|
|
72
79
|
* @static
|
|
@@ -76,12 +83,12 @@ export declare class Queue<E = any> extends IterableElementBase<E> {
|
|
|
76
83
|
*/
|
|
77
84
|
static fromArray<E>(elements: E[]): Queue<E>;
|
|
78
85
|
/**
|
|
79
|
-
* Time Complexity: O(1)
|
|
80
|
-
* Space Complexity: O(1)
|
|
86
|
+
* Time Complexity: O(1)
|
|
87
|
+
* Space Complexity: O(1)
|
|
81
88
|
*/
|
|
82
89
|
/**
|
|
83
|
-
* Time Complexity: O(1)
|
|
84
|
-
* Space Complexity: O(1)
|
|
90
|
+
* Time Complexity: O(1)
|
|
91
|
+
* Space Complexity: O(1)
|
|
85
92
|
*
|
|
86
93
|
* The push function adds an element to the end of the queue and returns the updated queue.Adds an element at the back of the queue.
|
|
87
94
|
* @param {E} element - The `element` parameter represents the element that you want to add to the queue.
|
|
@@ -89,12 +96,12 @@ export declare class Queue<E = any> extends IterableElementBase<E> {
|
|
|
89
96
|
*/
|
|
90
97
|
push(element: E): boolean;
|
|
91
98
|
/**
|
|
92
|
-
* Time Complexity: O(1)
|
|
93
|
-
* Space Complexity: O(1)
|
|
99
|
+
* Time Complexity: O(1)
|
|
100
|
+
* Space Complexity: O(1)
|
|
94
101
|
*/
|
|
95
102
|
/**
|
|
96
|
-
* Time Complexity: O(
|
|
97
|
-
* Space Complexity: O(1)
|
|
103
|
+
* Time Complexity: O(1)
|
|
104
|
+
* Space Complexity: O(1)
|
|
98
105
|
*
|
|
99
106
|
* The `shift` function removes and returns the first element in the queue, and adjusts the internal data structure if
|
|
100
107
|
* necessary to optimize performance.
|
|
@@ -114,12 +121,12 @@ export declare class Queue<E = any> extends IterableElementBase<E> {
|
|
|
114
121
|
*/
|
|
115
122
|
deleteAt(index: number): boolean;
|
|
116
123
|
/**
|
|
117
|
-
* Time Complexity: O(1)
|
|
118
|
-
* Space Complexity: O(1)
|
|
124
|
+
* Time Complexity: O(1)
|
|
125
|
+
* Space Complexity: O(1)
|
|
119
126
|
*/
|
|
120
127
|
/**
|
|
121
|
-
* Time Complexity: O(1)
|
|
122
|
-
* Space Complexity: O(1)
|
|
128
|
+
* Time Complexity: O(1)
|
|
129
|
+
* Space Complexity: O(1)
|
|
123
130
|
*
|
|
124
131
|
* The `peek` function returns the first element of the array `_elements` if it exists, otherwise it returns `undefined`.
|
|
125
132
|
* @returns The `peek()` method returns the first element of the data structure, represented by the `_elements` array at
|
|
@@ -127,12 +134,12 @@ export declare class Queue<E = any> extends IterableElementBase<E> {
|
|
|
127
134
|
*/
|
|
128
135
|
peek(): E | undefined;
|
|
129
136
|
/**
|
|
130
|
-
* Time Complexity: O(1)
|
|
131
|
-
* Space Complexity: O(1)
|
|
137
|
+
* Time Complexity: O(1)
|
|
138
|
+
* Space Complexity: O(1)
|
|
132
139
|
*/
|
|
133
140
|
/**
|
|
134
|
-
* Time Complexity: O(1)
|
|
135
|
-
* Space Complexity: O(1)
|
|
141
|
+
* Time Complexity: O(1)
|
|
142
|
+
* Space Complexity: O(1)
|
|
136
143
|
*
|
|
137
144
|
* The `peekLast` function returns the last element in an array-like data structure, or undefined if the structure is empty.
|
|
138
145
|
* @returns The method `peekLast()` returns the last element of the `_elements` array if the array is not empty. If the
|
|
@@ -140,65 +147,72 @@ export declare class Queue<E = any> extends IterableElementBase<E> {
|
|
|
140
147
|
*/
|
|
141
148
|
peekLast(): E | undefined;
|
|
142
149
|
/**
|
|
143
|
-
* Time Complexity: O(1)
|
|
144
|
-
* Space Complexity: O(1)
|
|
150
|
+
* Time Complexity: O(1)
|
|
151
|
+
* Space Complexity: O(1)
|
|
145
152
|
*/
|
|
146
153
|
/**
|
|
147
|
-
* Time Complexity: O(1)
|
|
148
|
-
* Space Complexity: O(1)
|
|
154
|
+
* Time Complexity: O(1)
|
|
155
|
+
* Space Complexity: O(1)
|
|
149
156
|
*
|
|
150
157
|
* The enqueue function adds a value to the end of a queue.
|
|
151
158
|
* @param {E} value - The value parameter represents the value that you want to add to the queue.
|
|
152
159
|
*/
|
|
153
160
|
enqueue(value: E): boolean;
|
|
154
161
|
/**
|
|
155
|
-
* Time Complexity: O(
|
|
156
|
-
* Space Complexity: O(1)
|
|
162
|
+
* Time Complexity: O(1)
|
|
163
|
+
* Space Complexity: O(1)
|
|
157
164
|
*/
|
|
158
165
|
/**
|
|
159
|
-
* Time Complexity: O(
|
|
160
|
-
* Space Complexity: O(1)
|
|
166
|
+
* Time Complexity: O(1)
|
|
167
|
+
* Space Complexity: O(1)
|
|
161
168
|
*
|
|
162
169
|
* The `dequeue` function removes and returns the first element from a queue, or returns undefined if the queue is empty.
|
|
163
170
|
* @returns The method is returning a value of type E or undefined.
|
|
164
171
|
*/
|
|
165
172
|
dequeue(): E | undefined;
|
|
166
173
|
/**
|
|
167
|
-
* Time Complexity: O(1)
|
|
168
|
-
* Space Complexity: O(1)
|
|
174
|
+
* Time Complexity: O(1)
|
|
175
|
+
* Space Complexity: O(1)
|
|
169
176
|
*/
|
|
170
177
|
/**
|
|
171
|
-
* Time Complexity: O(1)
|
|
172
|
-
* Space Complexity: O(1)
|
|
178
|
+
* Time Complexity: O(1)
|
|
179
|
+
* Space Complexity: O(1)
|
|
173
180
|
*
|
|
174
181
|
* @param index
|
|
175
182
|
*/
|
|
176
183
|
at(index: number): E | undefined;
|
|
177
184
|
/**
|
|
178
|
-
* Time Complexity: O(1)
|
|
179
|
-
* Space Complexity: O(1)
|
|
185
|
+
* Time Complexity: O(1)
|
|
186
|
+
* Space Complexity: O(1)
|
|
180
187
|
*/
|
|
181
188
|
/**
|
|
182
|
-
* Time Complexity: O(1)
|
|
183
|
-
* Space Complexity: O(1)
|
|
189
|
+
* Time Complexity: O(1)
|
|
190
|
+
* Space Complexity: O(1)
|
|
184
191
|
*
|
|
185
192
|
* The function checks if a data structure is empty by comparing its size to zero.
|
|
186
193
|
* @returns {boolean} A boolean value indicating whether the size of the object is 0 or not.
|
|
187
194
|
*/
|
|
188
195
|
isEmpty(): boolean;
|
|
189
196
|
/**
|
|
190
|
-
* Time Complexity: O(1)
|
|
191
|
-
* Space Complexity: O(n)
|
|
197
|
+
* Time Complexity: O(1)
|
|
198
|
+
* Space Complexity: O(n)
|
|
192
199
|
*/
|
|
193
200
|
/**
|
|
194
|
-
* Time Complexity: O(1)
|
|
195
|
-
* Space Complexity: O(n)
|
|
201
|
+
* Time Complexity: O(1)
|
|
202
|
+
* Space Complexity: O(n)
|
|
196
203
|
*
|
|
197
204
|
* The toArray() function returns an array of elements from the current offset to the end of the _elements array.
|
|
198
205
|
* @returns An array of type E is being returned.
|
|
199
206
|
*/
|
|
200
207
|
toArray(): E[];
|
|
201
208
|
/**
|
|
209
|
+
* Time Complexity: O(1)
|
|
210
|
+
* Space Complexity: O(1)
|
|
211
|
+
*/
|
|
212
|
+
/**
|
|
213
|
+
* Time Complexity: O(1)
|
|
214
|
+
* Space Complexity: O(1)
|
|
215
|
+
*
|
|
202
216
|
* The clear function resets the elements array and offset to their initial values.
|
|
203
217
|
*/
|
|
204
218
|
clear(): void;
|
|
@@ -259,6 +273,12 @@ export declare class Queue<E = any> extends IterableElementBase<E> {
|
|
|
259
273
|
* Time Complexity: O(n)
|
|
260
274
|
* Space Complexity: O(n)
|
|
261
275
|
*/
|
|
276
|
+
/**
|
|
277
|
+
* Time Complexity: O(n)
|
|
278
|
+
* Space Complexity: O(n)
|
|
279
|
+
*
|
|
280
|
+
* The function `_getIterator` returns an iterable iterator for the elements in the class.
|
|
281
|
+
*/
|
|
262
282
|
protected _getIterator(): IterableIterator<E>;
|
|
263
283
|
}
|
|
264
284
|
/**
|