data-structure-typed 1.49.1 → 1.49.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/CHANGELOG.md +1 -1
- package/README.md +16 -16
- package/README_zh-CN.md +2 -2
- package/benchmark/report.html +46 -1
- package/benchmark/report.json +457 -22
- package/dist/cjs/data-structures/base/iterable-base.d.ts +11 -0
- package/dist/cjs/data-structures/base/iterable-base.js +21 -0
- package/dist/cjs/data-structures/base/iterable-base.js.map +1 -1
- package/dist/cjs/data-structures/hash/hash-map.d.ts +9 -9
- package/dist/cjs/data-structures/hash/hash-map.js +16 -15
- package/dist/cjs/data-structures/hash/hash-map.js.map +1 -1
- package/dist/cjs/data-structures/heap/heap.d.ts +6 -35
- package/dist/cjs/data-structures/heap/heap.js +10 -42
- package/dist/cjs/data-structures/heap/heap.js.map +1 -1
- package/dist/cjs/data-structures/linked-list/doubly-linked-list.d.ts +87 -93
- package/dist/cjs/data-structures/linked-list/doubly-linked-list.js +126 -129
- 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 +16 -21
- package/dist/cjs/data-structures/linked-list/singly-linked-list.js +42 -42
- 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/linked-list/skip-linked-list.js.map +1 -1
- package/dist/cjs/data-structures/queue/deque.d.ts +70 -75
- package/dist/cjs/data-structures/queue/deque.js +100 -110
- package/dist/cjs/data-structures/queue/deque.js.map +1 -1
- package/dist/cjs/data-structures/queue/queue.d.ts +13 -14
- package/dist/cjs/data-structures/queue/queue.js +15 -18
- package/dist/cjs/data-structures/queue/queue.js.map +1 -1
- package/dist/cjs/data-structures/stack/stack.d.ts +2 -3
- package/dist/cjs/data-structures/stack/stack.js +2 -5
- package/dist/cjs/data-structures/stack/stack.js.map +1 -1
- package/dist/cjs/data-structures/trie/trie.d.ts +1 -2
- package/dist/cjs/data-structures/trie/trie.js +2 -5
- package/dist/cjs/data-structures/trie/trie.js.map +1 -1
- package/dist/mjs/data-structures/base/iterable-base.d.ts +11 -0
- package/dist/mjs/data-structures/base/iterable-base.js +21 -0
- package/dist/mjs/data-structures/hash/hash-map.d.ts +9 -9
- package/dist/mjs/data-structures/hash/hash-map.js +16 -15
- package/dist/mjs/data-structures/heap/heap.d.ts +6 -35
- package/dist/mjs/data-structures/heap/heap.js +10 -42
- package/dist/mjs/data-structures/linked-list/doubly-linked-list.d.ts +87 -93
- package/dist/mjs/data-structures/linked-list/doubly-linked-list.js +125 -128
- package/dist/mjs/data-structures/linked-list/singly-linked-list.d.ts +16 -21
- package/dist/mjs/data-structures/linked-list/singly-linked-list.js +43 -43
- 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/queue/deque.d.ts +70 -75
- package/dist/mjs/data-structures/queue/deque.js +100 -110
- package/dist/mjs/data-structures/queue/queue.d.ts +13 -14
- package/dist/mjs/data-structures/queue/queue.js +15 -18
- package/dist/mjs/data-structures/stack/stack.d.ts +2 -3
- package/dist/mjs/data-structures/stack/stack.js +2 -5
- package/dist/mjs/data-structures/trie/trie.d.ts +1 -2
- package/dist/mjs/data-structures/trie/trie.js +2 -5
- package/dist/umd/data-structure-typed.js +338 -370
- package/dist/umd/data-structure-typed.min.js +2 -2
- package/dist/umd/data-structure-typed.min.js.map +1 -1
- package/package.json +1 -1
- package/src/data-structures/base/iterable-base.ts +24 -0
- package/src/data-structures/hash/hash-map.ts +27 -28
- package/src/data-structures/heap/heap.ts +19 -57
- package/src/data-structures/linked-list/doubly-linked-list.ts +138 -142
- package/src/data-structures/linked-list/singly-linked-list.ts +49 -49
- package/src/data-structures/linked-list/skip-linked-list.ts +2 -2
- package/src/data-structures/queue/deque.ts +122 -135
- package/src/data-structures/queue/queue.ts +19 -23
- package/src/data-structures/stack/stack.ts +4 -8
- package/src/data-structures/trie/trie.ts +5 -9
- package/test/performance/data-structures/comparison/comparison.test.ts +6 -6
- package/test/performance/data-structures/heap/heap.test.ts +2 -2
- package/test/performance/data-structures/linked-list/doubly-linked-list.test.ts +2 -2
- package/test/performance/data-structures/linked-list/singly-linked-list.test.ts +2 -2
- package/test/performance/data-structures/priority-queue/priority-queue.test.ts +2 -2
- package/test/unit/data-structures/binary-tree/binary-tree.test.ts +2 -2
- package/test/unit/data-structures/hash/hash-map.test.ts +2 -2
- package/test/unit/data-structures/heap/heap.test.ts +1 -1
- package/test/unit/data-structures/heap/min-heap.test.ts +1 -1
- package/test/unit/data-structures/linked-list/doubly-linked-list.test.ts +30 -30
- package/test/unit/data-structures/linked-list/linked-list.test.ts +1 -1
- package/test/unit/data-structures/linked-list/singly-linked-list.test.ts +21 -21
- package/test/unit/data-structures/linked-list/skip-list.test.ts +2 -2
- package/test/unit/data-structures/queue/deque.test.ts +5 -5
- package/test/unit/data-structures/queue/queue.test.ts +4 -4
- package/test/unit/data-structures/trie/trie.test.ts +1 -1
|
@@ -20,7 +20,7 @@ export class SinglyLinkedList extends IterableElementBase {
|
|
|
20
20
|
super();
|
|
21
21
|
this._head = undefined;
|
|
22
22
|
this._tail = undefined;
|
|
23
|
-
this.
|
|
23
|
+
this._size = 0;
|
|
24
24
|
if (elements) {
|
|
25
25
|
for (const el of elements)
|
|
26
26
|
this.push(el);
|
|
@@ -34,9 +34,9 @@ export class SinglyLinkedList extends IterableElementBase {
|
|
|
34
34
|
get tail() {
|
|
35
35
|
return this._tail;
|
|
36
36
|
}
|
|
37
|
-
|
|
38
|
-
get
|
|
39
|
-
return this.
|
|
37
|
+
_size;
|
|
38
|
+
get size() {
|
|
39
|
+
return this._size;
|
|
40
40
|
}
|
|
41
41
|
/**
|
|
42
42
|
* Time Complexity: O(n) - Linear time, where n is the length of the input array, as it performs a loop to push each element into the linked list.
|
|
@@ -80,7 +80,8 @@ export class SinglyLinkedList extends IterableElementBase {
|
|
|
80
80
|
this.tail.next = newNode;
|
|
81
81
|
this._tail = newNode;
|
|
82
82
|
}
|
|
83
|
-
this.
|
|
83
|
+
this._size++;
|
|
84
|
+
return true;
|
|
84
85
|
}
|
|
85
86
|
/**
|
|
86
87
|
* Time Complexity: O(1) - Constant time, as it involves basic pointer adjustments.
|
|
@@ -95,7 +96,7 @@ export class SinglyLinkedList extends IterableElementBase {
|
|
|
95
96
|
* any type (E) as specified in the generic type declaration of the class or function.
|
|
96
97
|
*/
|
|
97
98
|
addLast(value) {
|
|
98
|
-
this.push(value);
|
|
99
|
+
return this.push(value);
|
|
99
100
|
}
|
|
100
101
|
/**
|
|
101
102
|
* Time Complexity: O(n) - Linear time in the worst case, as it may need to traverse the list to find the last element.
|
|
@@ -117,7 +118,7 @@ export class SinglyLinkedList extends IterableElementBase {
|
|
|
117
118
|
const value = this.head.value;
|
|
118
119
|
this._head = undefined;
|
|
119
120
|
this._tail = undefined;
|
|
120
|
-
this.
|
|
121
|
+
this._size--;
|
|
121
122
|
return value;
|
|
122
123
|
}
|
|
123
124
|
let current = this.head;
|
|
@@ -127,7 +128,7 @@ export class SinglyLinkedList extends IterableElementBase {
|
|
|
127
128
|
const value = this.tail.value;
|
|
128
129
|
current.next = undefined;
|
|
129
130
|
this._tail = current;
|
|
130
|
-
this.
|
|
131
|
+
this._size--;
|
|
131
132
|
return value;
|
|
132
133
|
}
|
|
133
134
|
/**
|
|
@@ -162,7 +163,7 @@ export class SinglyLinkedList extends IterableElementBase {
|
|
|
162
163
|
return undefined;
|
|
163
164
|
const removedNode = this.head;
|
|
164
165
|
this._head = this.head.next;
|
|
165
|
-
this.
|
|
166
|
+
this._size--;
|
|
166
167
|
return removedNode.value;
|
|
167
168
|
}
|
|
168
169
|
/**
|
|
@@ -201,7 +202,8 @@ export class SinglyLinkedList extends IterableElementBase {
|
|
|
201
202
|
newNode.next = this.head;
|
|
202
203
|
this._head = newNode;
|
|
203
204
|
}
|
|
204
|
-
this.
|
|
205
|
+
this._size++;
|
|
206
|
+
return true;
|
|
205
207
|
}
|
|
206
208
|
/**
|
|
207
209
|
* Time Complexity: O(1) - Constant time, as it involves adjusting pointers at the head.
|
|
@@ -216,7 +218,7 @@ export class SinglyLinkedList extends IterableElementBase {
|
|
|
216
218
|
* linked list.
|
|
217
219
|
*/
|
|
218
220
|
addFirst(value) {
|
|
219
|
-
this.unshift(value);
|
|
221
|
+
return this.unshift(value);
|
|
220
222
|
}
|
|
221
223
|
/**
|
|
222
224
|
* Time Complexity: O(n) - Linear time, where n is the index, as it may need to traverse the list to find the desired node.
|
|
@@ -233,7 +235,7 @@ export class SinglyLinkedList extends IterableElementBase {
|
|
|
233
235
|
* `undefined` if the index is out of bounds.
|
|
234
236
|
*/
|
|
235
237
|
getAt(index) {
|
|
236
|
-
if (index < 0 || index >= this.
|
|
238
|
+
if (index < 0 || index >= this.size)
|
|
237
239
|
return undefined;
|
|
238
240
|
let current = this.head;
|
|
239
241
|
for (let i = 0; i < index; i++) {
|
|
@@ -277,17 +279,21 @@ export class SinglyLinkedList extends IterableElementBase {
|
|
|
277
279
|
* bounds.
|
|
278
280
|
*/
|
|
279
281
|
deleteAt(index) {
|
|
280
|
-
if (index < 0 || index >= this.
|
|
281
|
-
return
|
|
282
|
-
if (index === 0)
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
282
|
+
if (index < 0 || index >= this.size)
|
|
283
|
+
return false;
|
|
284
|
+
if (index === 0) {
|
|
285
|
+
this.shift();
|
|
286
|
+
return true;
|
|
287
|
+
}
|
|
288
|
+
if (index === this.size - 1) {
|
|
289
|
+
this.pop();
|
|
290
|
+
return true;
|
|
291
|
+
}
|
|
286
292
|
const prevNode = this.getNodeAt(index - 1);
|
|
287
293
|
const removedNode = prevNode.next;
|
|
288
294
|
prevNode.next = removedNode.next;
|
|
289
|
-
this.
|
|
290
|
-
return
|
|
295
|
+
this._size--;
|
|
296
|
+
return true;
|
|
291
297
|
}
|
|
292
298
|
/**
|
|
293
299
|
* Time Complexity: O(n) - Linear time, where n is the index, as it may need to traverse the list to find the desired node.
|
|
@@ -328,7 +334,7 @@ export class SinglyLinkedList extends IterableElementBase {
|
|
|
328
334
|
this._tail = prev;
|
|
329
335
|
}
|
|
330
336
|
}
|
|
331
|
-
this.
|
|
337
|
+
this._size--;
|
|
332
338
|
return true;
|
|
333
339
|
}
|
|
334
340
|
prev = current;
|
|
@@ -344,7 +350,7 @@ export class SinglyLinkedList extends IterableElementBase {
|
|
|
344
350
|
* Time Complexity: O(n) - Linear time, where n is the index, as it may need to traverse the list to find the desired node.
|
|
345
351
|
* Space Complexity: O(1) - Constant space.
|
|
346
352
|
*
|
|
347
|
-
* The `
|
|
353
|
+
* The `addAt` function inserts a value at a specified index in a singly linked list.
|
|
348
354
|
* @param {number} index - The index parameter represents the position at which the new value should be inserted in the
|
|
349
355
|
* linked list. It is of type number.
|
|
350
356
|
* @param {E} value - The `value` parameter represents the value that you want to insert into the linked list at the
|
|
@@ -352,14 +358,14 @@ export class SinglyLinkedList extends IterableElementBase {
|
|
|
352
358
|
* @returns The `insert` method returns a boolean value. It returns `true` if the insertion is successful, and `false`
|
|
353
359
|
* if the index is out of bounds.
|
|
354
360
|
*/
|
|
355
|
-
|
|
356
|
-
if (index < 0 || index > this.
|
|
361
|
+
addAt(index, value) {
|
|
362
|
+
if (index < 0 || index > this.size)
|
|
357
363
|
return false;
|
|
358
364
|
if (index === 0) {
|
|
359
365
|
this.unshift(value);
|
|
360
366
|
return true;
|
|
361
367
|
}
|
|
362
|
-
if (index === this.
|
|
368
|
+
if (index === this.size) {
|
|
363
369
|
this.push(value);
|
|
364
370
|
return true;
|
|
365
371
|
}
|
|
@@ -367,7 +373,7 @@ export class SinglyLinkedList extends IterableElementBase {
|
|
|
367
373
|
const prevNode = this.getNodeAt(index - 1);
|
|
368
374
|
newNode.next = prevNode.next;
|
|
369
375
|
prevNode.next = newNode;
|
|
370
|
-
this.
|
|
376
|
+
this._size++;
|
|
371
377
|
return true;
|
|
372
378
|
}
|
|
373
379
|
/**
|
|
@@ -376,7 +382,7 @@ export class SinglyLinkedList extends IterableElementBase {
|
|
|
376
382
|
* @returns A boolean value indicating whether the length of the object is equal to 0.
|
|
377
383
|
*/
|
|
378
384
|
isEmpty() {
|
|
379
|
-
return this.
|
|
385
|
+
return this.size === 0;
|
|
380
386
|
}
|
|
381
387
|
/**
|
|
382
388
|
* The `clear` function resets the linked list by setting the head, tail, and length to undefined and 0 respectively.
|
|
@@ -384,7 +390,7 @@ export class SinglyLinkedList extends IterableElementBase {
|
|
|
384
390
|
clear() {
|
|
385
391
|
this._head = undefined;
|
|
386
392
|
this._tail = undefined;
|
|
387
|
-
this.
|
|
393
|
+
this._size = 0;
|
|
388
394
|
}
|
|
389
395
|
/**
|
|
390
396
|
* Time Complexity: O(n) - Linear time, where n is the length of the list, as it needs to traverse the entire list to convert it to an array.
|
|
@@ -419,7 +425,7 @@ export class SinglyLinkedList extends IterableElementBase {
|
|
|
419
425
|
*/
|
|
420
426
|
reverse() {
|
|
421
427
|
if (!this.head || this.head === this.tail)
|
|
422
|
-
return;
|
|
428
|
+
return this;
|
|
423
429
|
let prev = undefined;
|
|
424
430
|
let current = this.head;
|
|
425
431
|
let next = undefined;
|
|
@@ -430,6 +436,7 @@ export class SinglyLinkedList extends IterableElementBase {
|
|
|
430
436
|
current = next;
|
|
431
437
|
}
|
|
432
438
|
[this._head, this._tail] = [this.tail, this.head];
|
|
439
|
+
return this;
|
|
433
440
|
}
|
|
434
441
|
/**
|
|
435
442
|
* Time Complexity: O(n) - Linear time, where n is the length of the list, as it needs to reverse the pointers of each node.
|
|
@@ -512,14 +519,14 @@ export class SinglyLinkedList extends IterableElementBase {
|
|
|
512
519
|
* Time Complexity: O(n) - Linear time, where n is the length of the list, as it needs to reverse the pointers of each node.
|
|
513
520
|
* Space Complexity: O(1) - Constant space.
|
|
514
521
|
*
|
|
515
|
-
* The `
|
|
522
|
+
* The `addBefore` function inserts a new value before an existing value in a singly linked list.
|
|
516
523
|
* @param {E | SinglyLinkedListNode<E>} existingValueOrNode - The existing value or node that you want to insert the
|
|
517
524
|
* new value before. It can be either the value itself or a node containing the value in the linked list.
|
|
518
525
|
* @param {E} newValue - The `newValue` parameter represents the value that you want to insert into the linked list.
|
|
519
|
-
* @returns The method `
|
|
526
|
+
* @returns The method `addBefore` returns a boolean value. It returns `true` if the new value was successfully
|
|
520
527
|
* inserted before the existing value, and `false` otherwise.
|
|
521
528
|
*/
|
|
522
|
-
|
|
529
|
+
addBefore(existingValueOrNode, newValue) {
|
|
523
530
|
if (!this.head)
|
|
524
531
|
return false;
|
|
525
532
|
let existingValue;
|
|
@@ -539,7 +546,7 @@ export class SinglyLinkedList extends IterableElementBase {
|
|
|
539
546
|
const newNode = new SinglyLinkedListNode(newValue);
|
|
540
547
|
newNode.next = current.next;
|
|
541
548
|
current.next = newNode;
|
|
542
|
-
this.
|
|
549
|
+
this._size++;
|
|
543
550
|
return true;
|
|
544
551
|
}
|
|
545
552
|
current = current.next;
|
|
@@ -554,14 +561,14 @@ export class SinglyLinkedList extends IterableElementBase {
|
|
|
554
561
|
* Time Complexity: O(n) - Linear time, where n is the length of the list, as it needs to reverse the pointers of each node.
|
|
555
562
|
* Space Complexity: O(1) - Constant space.
|
|
556
563
|
*
|
|
557
|
-
* The `
|
|
564
|
+
* The `addAfter` function inserts a new node with a given value after an existing node in a singly linked list.
|
|
558
565
|
* @param {E | SinglyLinkedListNode<E>} existingValueOrNode - The existing value or node in the linked list after which
|
|
559
566
|
* the new value will be inserted. It can be either the value of the existing node or the existing node itself.
|
|
560
567
|
* @param {E} newValue - The value that you want to insert into the linked list after the existing value or node.
|
|
561
568
|
* @returns The method returns a boolean value. It returns true if the new value was successfully inserted after the
|
|
562
569
|
* existing value or node, and false if the existing value or node was not found in the linked list.
|
|
563
570
|
*/
|
|
564
|
-
|
|
571
|
+
addAfter(existingValueOrNode, newValue) {
|
|
565
572
|
let existingNode;
|
|
566
573
|
if (existingValueOrNode instanceof SinglyLinkedListNode) {
|
|
567
574
|
existingNode = existingValueOrNode;
|
|
@@ -576,7 +583,7 @@ export class SinglyLinkedList extends IterableElementBase {
|
|
|
576
583
|
if (existingNode === this.tail) {
|
|
577
584
|
this._tail = newNode;
|
|
578
585
|
}
|
|
579
|
-
this.
|
|
586
|
+
this._size++;
|
|
580
587
|
return true;
|
|
581
588
|
}
|
|
582
589
|
return false;
|
|
@@ -663,13 +670,6 @@ export class SinglyLinkedList extends IterableElementBase {
|
|
|
663
670
|
}
|
|
664
671
|
return mappedList;
|
|
665
672
|
}
|
|
666
|
-
/**
|
|
667
|
-
* Time Complexity: O(n), where n is the number of elements in the linked list.
|
|
668
|
-
* Space Complexity: O(n)
|
|
669
|
-
*/
|
|
670
|
-
print() {
|
|
671
|
-
console.log([...this]);
|
|
672
|
-
}
|
|
673
673
|
*_getIterator() {
|
|
674
674
|
let current = this.head;
|
|
675
675
|
while (current) {
|
|
@@ -90,7 +90,7 @@ export declare class SkipList<K, V> {
|
|
|
90
90
|
* Get the value of the first element (the smallest element) in the Skip List.
|
|
91
91
|
* @returns The value of the first element, or undefined if the Skip List is empty.
|
|
92
92
|
*/
|
|
93
|
-
|
|
93
|
+
get first(): V | undefined;
|
|
94
94
|
/**
|
|
95
95
|
* Time Complexity: O(log n) - where n is the number of elements in the SkipList, as it traverses the levels of the SkipList.
|
|
96
96
|
* Space Complexity: O(1) - constant space, as it uses a fixed amount of space regardless of the size of the SkipList.
|
|
@@ -102,7 +102,7 @@ export declare class SkipList<K, V> {
|
|
|
102
102
|
* Get the value of the last element (the largest element) in the Skip List.
|
|
103
103
|
* @returns The value of the last element, or undefined if the Skip List is empty.
|
|
104
104
|
*/
|
|
105
|
-
|
|
105
|
+
get last(): V | undefined;
|
|
106
106
|
/**
|
|
107
107
|
* Time Complexity: O(log n) - where n is the number of elements in the SkipList, as it traverses the levels of the SkipList.
|
|
108
108
|
* Space Complexity: O(1) - constant space, as it uses a fixed amount of space regardless of the size of the SkipList.
|
|
@@ -161,7 +161,7 @@ export class SkipList {
|
|
|
161
161
|
* Get the value of the first element (the smallest element) in the Skip List.
|
|
162
162
|
* @returns The value of the first element, or undefined if the Skip List is empty.
|
|
163
163
|
*/
|
|
164
|
-
|
|
164
|
+
get first() {
|
|
165
165
|
const firstNode = this.head.forward[0];
|
|
166
166
|
return firstNode ? firstNode.value : undefined;
|
|
167
167
|
}
|
|
@@ -176,7 +176,7 @@ export class SkipList {
|
|
|
176
176
|
* Get the value of the last element (the largest element) in the Skip List.
|
|
177
177
|
* @returns The value of the last element, or undefined if the Skip List is empty.
|
|
178
178
|
*/
|
|
179
|
-
|
|
179
|
+
get last() {
|
|
180
180
|
let current = this.head;
|
|
181
181
|
for (let i = this.level - 1; i >= 0; i--) {
|
|
182
182
|
while (current.forward[i]) {
|
|
@@ -42,68 +42,6 @@ export declare class Deque<E> extends IterableElementBase<E> {
|
|
|
42
42
|
*/
|
|
43
43
|
get first(): E | undefined;
|
|
44
44
|
get last(): E | undefined;
|
|
45
|
-
/**
|
|
46
|
-
* Time Complexity: O(1) - Removes the last element.
|
|
47
|
-
* Space Complexity: O(1) - Operates in-place.
|
|
48
|
-
*/
|
|
49
|
-
isEmpty(): boolean;
|
|
50
|
-
/**
|
|
51
|
-
* Time Complexity: Amortized O(1) - Similar to push, resizing leads to O(n).
|
|
52
|
-
* Space Complexity: O(n) - Due to potential resizing.
|
|
53
|
-
*/
|
|
54
|
-
/**
|
|
55
|
-
* Time Complexity: O(1)
|
|
56
|
-
* Space Complexity: O(n) - In worst case, resizing doubles the array size.
|
|
57
|
-
*
|
|
58
|
-
* The addLast function adds an element to the end of an array.
|
|
59
|
-
* @param {E} element - The element parameter represents the element that you want to add to the end of the
|
|
60
|
-
* data structure.
|
|
61
|
-
*/
|
|
62
|
-
addLast(element: E): void;
|
|
63
|
-
/**
|
|
64
|
-
* Time Complexity: O(1) - Removes the first element.
|
|
65
|
-
* Space Complexity: O(1) - In-place operation.
|
|
66
|
-
*/
|
|
67
|
-
/**
|
|
68
|
-
* Time Complexity: O(1) - Removes the last element.
|
|
69
|
-
* Space Complexity: O(1) - Operates in-place.
|
|
70
|
-
*
|
|
71
|
-
* The function "pollLast" removes and returns the last element of an array.
|
|
72
|
-
* @returns The last element of the array is being returned.
|
|
73
|
-
*/
|
|
74
|
-
pollLast(): E | undefined;
|
|
75
|
-
/**
|
|
76
|
-
* Time Complexity: O(1).
|
|
77
|
-
* Space Complexity: O(n) - Due to potential resizing.
|
|
78
|
-
*
|
|
79
|
-
* The "addFirst" function adds an element to the beginning of an array.
|
|
80
|
-
* @param {E} element - The parameter "element" represents the element that you want to add to the
|
|
81
|
-
* beginning of the data structure.
|
|
82
|
-
*/
|
|
83
|
-
addFirst(element: E): void;
|
|
84
|
-
/**
|
|
85
|
-
* Time Complexity: O(1) - Removes the first element.
|
|
86
|
-
* Space Complexity: O(1) - In-place operation.
|
|
87
|
-
*
|
|
88
|
-
* The function "pollFirst" removes and returns the first element of an array.
|
|
89
|
-
* @returns The method `pollFirst()` is returning the first element of the array after removing it
|
|
90
|
-
* from the beginning. If the array is empty, it will return `undefined`.
|
|
91
|
-
*/
|
|
92
|
-
pollFirst(): E | undefined;
|
|
93
|
-
/**
|
|
94
|
-
* The clear() function resets the state of the object by initializing all variables to their default
|
|
95
|
-
* values.
|
|
96
|
-
*/
|
|
97
|
-
clear(): void;
|
|
98
|
-
/**
|
|
99
|
-
* The below function is a generator that yields elements from a collection one by one.
|
|
100
|
-
*/
|
|
101
|
-
begin(): Generator<E>;
|
|
102
|
-
/**
|
|
103
|
-
* The function `reverseBegin()` is a generator that yields elements in reverse order starting from
|
|
104
|
-
* the last element.
|
|
105
|
-
*/
|
|
106
|
-
reverseBegin(): Generator<E>;
|
|
107
45
|
/**
|
|
108
46
|
* Time Complexity - Amortized O(1) (possible reallocation)
|
|
109
47
|
* Space Complexity - O(n) (due to potential resizing).
|
|
@@ -117,7 +55,7 @@ export declare class Deque<E> extends IterableElementBase<E> {
|
|
|
117
55
|
* structure.
|
|
118
56
|
* @returns The size of the data structure after the element has been pushed.
|
|
119
57
|
*/
|
|
120
|
-
push(element: E):
|
|
58
|
+
push(element: E): boolean;
|
|
121
59
|
/**
|
|
122
60
|
* Time Complexity: O(1)
|
|
123
61
|
* Space Complexity: O(1)
|
|
@@ -145,7 +83,7 @@ export declare class Deque<E> extends IterableElementBase<E> {
|
|
|
145
83
|
* beginning of the data structure.
|
|
146
84
|
* @returns The size of the data structure after the element has been added.
|
|
147
85
|
*/
|
|
148
|
-
unshift(element: E):
|
|
86
|
+
unshift(element: E): boolean;
|
|
149
87
|
/**
|
|
150
88
|
* Time Complexity: O(1)
|
|
151
89
|
* Space Complexity: O(1)
|
|
@@ -160,6 +98,25 @@ export declare class Deque<E> extends IterableElementBase<E> {
|
|
|
160
98
|
* returned.
|
|
161
99
|
*/
|
|
162
100
|
shift(): E | undefined;
|
|
101
|
+
/**
|
|
102
|
+
* Time Complexity: O(1) - Removes the last element.
|
|
103
|
+
* Space Complexity: O(1) - Operates in-place.
|
|
104
|
+
*/
|
|
105
|
+
isEmpty(): boolean;
|
|
106
|
+
/**
|
|
107
|
+
* The clear() function resets the state of the object by initializing all variables to their default
|
|
108
|
+
* values.
|
|
109
|
+
*/
|
|
110
|
+
clear(): void;
|
|
111
|
+
/**
|
|
112
|
+
* The below function is a generator that yields elements from a collection one by one.
|
|
113
|
+
*/
|
|
114
|
+
begin(): Generator<E>;
|
|
115
|
+
/**
|
|
116
|
+
* The function `reverseBegin()` is a generator that yields elements in reverse order starting from
|
|
117
|
+
* the last element.
|
|
118
|
+
*/
|
|
119
|
+
reverseBegin(): Generator<E>;
|
|
163
120
|
/**
|
|
164
121
|
* Time Complexity: O(1)
|
|
165
122
|
* Space Complexity: O(1)
|
|
@@ -189,7 +146,7 @@ export declare class Deque<E> extends IterableElementBase<E> {
|
|
|
189
146
|
* @param {E} element - The `element` parameter is the value that you want to set at the specified
|
|
190
147
|
* position in the data structure.
|
|
191
148
|
*/
|
|
192
|
-
setAt(pos: number, element: E):
|
|
149
|
+
setAt(pos: number, element: E): boolean;
|
|
193
150
|
/**
|
|
194
151
|
* Time Complexity: O(n)
|
|
195
152
|
* Space Complexity: O(n)
|
|
@@ -198,7 +155,7 @@ export declare class Deque<E> extends IterableElementBase<E> {
|
|
|
198
155
|
* Time Complexity: O(n)
|
|
199
156
|
* Space Complexity: O(n)
|
|
200
157
|
*
|
|
201
|
-
* The `
|
|
158
|
+
* The `addAt` function inserts one or more elements at a specified position in an array-like data
|
|
202
159
|
* structure.
|
|
203
160
|
* @param {number} pos - The `pos` parameter represents the position at which the element(s) should
|
|
204
161
|
* be inserted. It is of type `number`.
|
|
@@ -209,7 +166,7 @@ export declare class Deque<E> extends IterableElementBase<E> {
|
|
|
209
166
|
* will be inserted once. However, you can provide a different value for `num` if you want
|
|
210
167
|
* @returns The size of the array after the insertion is being returned.
|
|
211
168
|
*/
|
|
212
|
-
|
|
169
|
+
addAt(pos: number, element: E, num?: number): boolean;
|
|
213
170
|
/**
|
|
214
171
|
* Time Complexity: O(1)
|
|
215
172
|
* Space Complexity: O(1)
|
|
@@ -240,7 +197,7 @@ export declare class Deque<E> extends IterableElementBase<E> {
|
|
|
240
197
|
* the index of the element to be deleted.
|
|
241
198
|
* @returns The size of the data structure after the deletion operation is performed.
|
|
242
199
|
*/
|
|
243
|
-
deleteAt(pos: number):
|
|
200
|
+
deleteAt(pos: number): boolean;
|
|
244
201
|
/**
|
|
245
202
|
* Time Complexity: O(n)
|
|
246
203
|
* Space Complexity: O(1)
|
|
@@ -255,7 +212,7 @@ export declare class Deque<E> extends IterableElementBase<E> {
|
|
|
255
212
|
* the data structure.
|
|
256
213
|
* @returns The size of the data structure after the element has been deleted.
|
|
257
214
|
*/
|
|
258
|
-
delete(element: E):
|
|
215
|
+
delete(element: E): boolean;
|
|
259
216
|
/**
|
|
260
217
|
* Time Complexity: O(n)
|
|
261
218
|
* Space Complexity: O(1)
|
|
@@ -282,7 +239,7 @@ export declare class Deque<E> extends IterableElementBase<E> {
|
|
|
282
239
|
* the number of unique elements.
|
|
283
240
|
* @returns The size of the modified array is being returned.
|
|
284
241
|
*/
|
|
285
|
-
unique():
|
|
242
|
+
unique(): this;
|
|
286
243
|
/**
|
|
287
244
|
* Time Complexity: O(n log n)
|
|
288
245
|
* Space Complexity: O(n)
|
|
@@ -295,7 +252,7 @@ export declare class Deque<E> extends IterableElementBase<E> {
|
|
|
295
252
|
* @param [comparator] - The `comparator` parameter is a function that takes in two elements `x` and
|
|
296
253
|
* `y` of type `E` and returns a number. The comparator function is used to determine the order of
|
|
297
254
|
* the elements in the sorted array.
|
|
298
|
-
* @returns
|
|
255
|
+
* @returns Deque<E>
|
|
299
256
|
*/
|
|
300
257
|
sort(comparator?: (x: E, y: E) => number): this;
|
|
301
258
|
/**
|
|
@@ -396,10 +353,48 @@ export declare class Deque<E> extends IterableElementBase<E> {
|
|
|
396
353
|
*/
|
|
397
354
|
map<T>(callback: ElementCallback<E, T>, thisArg?: any): Deque<T>;
|
|
398
355
|
/**
|
|
399
|
-
* Time Complexity: O(n)
|
|
400
|
-
* Space Complexity: O(n)
|
|
356
|
+
* Time Complexity: Amortized O(1) - Similar to push, resizing leads to O(n).
|
|
357
|
+
* Space Complexity: O(n) - Due to potential resizing.
|
|
358
|
+
*/
|
|
359
|
+
/**
|
|
360
|
+
* Time Complexity: O(1)
|
|
361
|
+
* Space Complexity: O(n) - In worst case, resizing doubles the array size.
|
|
362
|
+
*
|
|
363
|
+
* The addLast function adds an element to the end of an array.
|
|
364
|
+
* @param {E} element - The element parameter represents the element that you want to add to the end of the
|
|
365
|
+
* data structure.
|
|
366
|
+
*/
|
|
367
|
+
addLast(element: E): boolean;
|
|
368
|
+
/**
|
|
369
|
+
* Time Complexity: O(1) - Removes the first element.
|
|
370
|
+
* Space Complexity: O(1) - In-place operation.
|
|
371
|
+
*/
|
|
372
|
+
/**
|
|
373
|
+
* Time Complexity: O(1) - Removes the last element.
|
|
374
|
+
* Space Complexity: O(1) - Operates in-place.
|
|
375
|
+
*
|
|
376
|
+
* The function "pollLast" removes and returns the last element of an array.
|
|
377
|
+
* @returns The last element of the array is being returned.
|
|
378
|
+
*/
|
|
379
|
+
pollLast(): E | undefined;
|
|
380
|
+
/**
|
|
381
|
+
* Time Complexity: O(1).
|
|
382
|
+
* Space Complexity: O(n) - Due to potential resizing.
|
|
383
|
+
*
|
|
384
|
+
* The "addFirst" function adds an element to the beginning of an array.
|
|
385
|
+
* @param {E} element - The parameter "element" represents the element that you want to add to the
|
|
386
|
+
* beginning of the data structure.
|
|
401
387
|
*/
|
|
402
|
-
|
|
388
|
+
addFirst(element: E): boolean;
|
|
389
|
+
/**
|
|
390
|
+
* Time Complexity: O(1) - Removes the first element.
|
|
391
|
+
* Space Complexity: O(1) - In-place operation.
|
|
392
|
+
*
|
|
393
|
+
* The function "pollFirst" removes and returns the first element of an array.
|
|
394
|
+
* @returns The method `pollFirst()` is returning the first element of the array after removing it
|
|
395
|
+
* from the beginning. If the array is empty, it will return `undefined`.
|
|
396
|
+
*/
|
|
397
|
+
pollFirst(): E | undefined;
|
|
403
398
|
/**
|
|
404
399
|
* Time Complexity: O(n)
|
|
405
400
|
* Space Complexity: O(1)
|
|
@@ -407,7 +402,7 @@ export declare class Deque<E> extends IterableElementBase<E> {
|
|
|
407
402
|
* The above function is an implementation of the iterator protocol in TypeScript, allowing the
|
|
408
403
|
* object to be iterated over using a for...of loop.
|
|
409
404
|
*/
|
|
410
|
-
protected _getIterator():
|
|
405
|
+
protected _getIterator(): IterableIterator<E>;
|
|
411
406
|
/**
|
|
412
407
|
* Time Complexity: O(n)
|
|
413
408
|
* Space Complexity: O(n)
|